aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-22 19:34:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-22 19:34:21 -0400
commitfb09bafda67041b74a668dc9d77735e36bd33d3b (patch)
tree2dd32b65062a95045468fdcab366ecdb8e4fcac6
parent94b5aff4c6f72fee6b0f49d49e4fa8b204e8ded9 (diff)
parentc3c6cc91b0ae7b3d598488ad0b593bafba4a0817 (diff)
Merge tag 'staging-3.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging tree changes from Greg Kroah-Hartman: "Here is the big staging tree pull request for the 3.5-rc1 merge window. Loads of changes here, and we just narrowly added more lines than we added: 622 files changed, 28356 insertions(+), 26059 deletions(-) But, good news is that there is a number of subsystems that moved out of the staging tree, to their respective "real" portions of the kernel. Code that moved out was: - iio core code - mei driver - vme core and bridge drivers There was one broken network driver that moved into staging as a step before it is removed from the tree (pc300), and there was a few new drivers added to the tree: - new iio drivers - gdm72xx wimax USB driver - ipack subsystem and 2 drivers All of the movements around have acks from the various subsystem maintainers, and all of this has been in the linux-next tree for a while. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>" Fixed up various trivial conflicts, along with a non-trivial one found in -next and pointed out by Olof Johanssen: a clean - but incorrect - merge of the arch/arm/boot/dts/at91sam9g20.dtsi file. Fix up manually as per Stephen Rothwell. * tag 'staging-3.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (536 commits) Staging: bcm: Remove two unused variables from Adapter.h Staging: bcm: Removes the volatile type definition from Adapter.h Staging: bcm: Rename all "INT" to "int" in Adapter.h Staging: bcm: Fix warning: __packed vs. __attribute__((packed)) in Adapter.h Staging: bcm: Correctly format all comments in Adapter.h Staging: bcm: Fix all whitespace issues in Adapter.h Staging: bcm: Properly format braces in Adapter.h Staging: ipack/bridges/tpci200: remove unneeded casts Staging: ipack/bridges/tpci200: remove TPCI200_SHORTNAME constant Staging: ipack: remove board_name and bus_name fields from struct ipack_device Staging: ipack: improve the register of a bus and a device in the bus. staging: comedi: cleanup all the comedi_driver 'detach' functions staging: comedi: remove all 'default N' in Kconfig staging: line6/config.h: Delete unused header staging: gdm72xx depends on NET staging: gdm72xx: Set up parent link in sysfs for gdm72xx devices staging: drm/omap: initial dmabuf/prime import support staging: drm/omap: dmabuf/prime mmap support pstore/ram: Add ECC support pstore/ram: Switch to persistent_ram routines ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio (renamed from drivers/staging/iio/Documentation/sysfs-bus-iio)52
-rw-r--r--Documentation/Makefile2
-rw-r--r--Documentation/devicetree/bindings/arm/atmel-adc.txt65
-rw-r--r--Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt16
-rw-r--r--Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt26
-rw-r--r--Documentation/ioctl/ioctl-number.txt1
-rw-r--r--Documentation/misc-devices/mei/.gitignore1
-rw-r--r--Documentation/misc-devices/mei/Makefile8
-rw-r--r--Documentation/misc-devices/mei/TODO2
-rw-r--r--Documentation/misc-devices/mei/mei-amt-version.c (renamed from drivers/staging/mei/mei-amt-version.c)2
-rw-r--r--Documentation/misc-devices/mei/mei.txt (renamed from drivers/staging/mei/mei.txt)0
-rw-r--r--Documentation/ramoops.txt16
-rw-r--r--Documentation/vme_api.txt (renamed from drivers/staging/vme/vme_api.txt)0
-rw-r--r--MAINTAINERS21
-rw-r--r--arch/arm/boot/dts/at91sam9g45.dtsi37
-rw-r--r--arch/arm/boot/dts/at91sam9x5.dtsi38
-rw-r--r--arch/arm/mach-at91/at91sam9260.c8
-rw-r--r--arch/arm/mach-at91/at91sam9260_devices.c90
-rw-r--r--arch/arm/mach-at91/at91sam9g45.c9
-rw-r--r--arch/arm/mach-at91/at91sam9g45_devices.c101
-rw-r--r--arch/arm/mach-at91/at91sam9x5.c6
-rw-r--r--arch/arm/mach-at91/board-sam9g20ek.c14
-rw-r--r--arch/arm/mach-at91/board-sam9m10g45ek.c12
-rw-r--r--drivers/Kconfig4
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/char/Kconfig8
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/ramoops.c250
-rw-r--r--drivers/iio/Kconfig54
-rw-r--r--drivers/iio/Makefile13
-rw-r--r--drivers/iio/adc/Kconfig16
-rw-r--r--drivers/iio/adc/Makefile5
-rw-r--r--drivers/iio/adc/at91_adc.c802
-rw-r--r--drivers/iio/amplifiers/Kconfig17
-rw-r--r--drivers/iio/amplifiers/Makefile5
-rw-r--r--drivers/iio/amplifiers/ad8366.c222
-rw-r--r--drivers/iio/iio_core.h (renamed from drivers/staging/iio/iio_core.h)6
-rw-r--r--drivers/iio/iio_core_trigger.h (renamed from drivers/staging/iio/iio_core_trigger.h)0
-rw-r--r--drivers/iio/industrialio-buffer.c (renamed from drivers/staging/iio/industrialio-buffer.c)91
-rw-r--r--drivers/iio/industrialio-core.c (renamed from drivers/staging/iio/industrialio-core.c)94
-rw-r--r--drivers/iio/industrialio-event.c (renamed from drivers/staging/iio/industrialio-event.c)14
-rw-r--r--drivers/iio/industrialio-trigger.c (renamed from drivers/staging/iio/industrialio-trigger.c)24
-rw-r--r--drivers/iio/inkern.c (renamed from drivers/staging/iio/inkern.c)8
-rw-r--r--drivers/iio/kfifo_buf.c (renamed from drivers/staging/iio/kfifo_buf.c)3
-rw-r--r--drivers/misc/Kconfig1
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/mei/Kconfig (renamed from drivers/staging/mei/Kconfig)0
-rw-r--r--drivers/misc/mei/Makefile (renamed from drivers/staging/mei/Makefile)0
-rw-r--r--drivers/misc/mei/hw.h (renamed from drivers/staging/mei/hw.h)0
-rw-r--r--drivers/misc/mei/init.c (renamed from drivers/staging/mei/init.c)4
-rw-r--r--drivers/misc/mei/interface.c (renamed from drivers/staging/mei/interface.c)2
-rw-r--r--drivers/misc/mei/interface.h (renamed from drivers/staging/mei/interface.h)5
-rw-r--r--drivers/misc/mei/interrupt.c (renamed from drivers/staging/mei/interrupt.c)2
-rw-r--r--drivers/misc/mei/iorw.c (renamed from drivers/staging/mei/iorw.c)2
-rw-r--r--drivers/misc/mei/main.c (renamed from drivers/staging/mei/main.c)41
-rw-r--r--drivers/misc/mei/mei_dev.h (renamed from drivers/staging/mei/mei_dev.h)2
-rw-r--r--drivers/misc/mei/wd.c (renamed from drivers/staging/mei/wd.c)76
-rw-r--r--drivers/net/wan/Kconfig31
-rw-r--r--drivers/net/wan/Makefile5
-rw-r--r--drivers/staging/Kconfig12
-rw-r--r--drivers/staging/Makefile5
-rw-r--r--drivers/staging/android/Kconfig30
-rw-r--r--drivers/staging/android/Makefile2
-rw-r--r--drivers/staging/android/alarm-dev.c137
-rw-r--r--drivers/staging/android/alarm.c601
-rw-r--r--drivers/staging/android/android_alarm.h59
-rw-r--r--drivers/staging/android/binder.h10
-rw-r--r--drivers/staging/android/logger.c113
-rw-r--r--drivers/staging/android/ram_console.c2
-rw-r--r--drivers/staging/android/timed_output.c1
-rw-r--r--drivers/staging/bcm/Adapter.h883
-rw-r--r--drivers/staging/bcm/DDRInit.c26
-rw-r--r--drivers/staging/bcm/IPv6Protocol.c409
-rw-r--r--drivers/staging/bcm/Misc.c2
-rw-r--r--drivers/staging/comedi/Kconfig253
-rw-r--r--drivers/staging/comedi/comedi.h2
-rw-r--r--drivers/staging/comedi/comedi_fops.c729
-rw-r--r--drivers/staging/comedi/comedidev.h72
-rw-r--r--drivers/staging/comedi/drivers.c326
-rw-r--r--drivers/staging/comedi/drivers/8255.c73
-rw-r--r--drivers/staging/comedi/drivers/acl7225b.c55
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.c3556
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.h145
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c18
-rw-r--r--drivers/staging/comedi/drivers/adl_pci6208.c263
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7230.c133
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7296.c77
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7432.c149
-rw-r--r--drivers/staging/comedi/drivers/adl_pci8164.c301
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9111.c106
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c182
-rw-r--r--drivers/staging/comedi/drivers/adq12b.c250
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c223
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1723.c103
-rw-r--r--drivers/staging/comedi/drivers/adv_pci_dio.c130
-rw-r--r--drivers/staging/comedi/drivers/aio_aio12_8.c33
-rw-r--r--drivers/staging/comedi/drivers/aio_iiro_16.c113
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200.c99
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236.c85
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc263.c87
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci224.c256
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c120
-rw-r--r--drivers/staging/comedi/drivers/c6xdigio.c44
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c9
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas.c109
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c142
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidda.c175
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidio.c131
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c123
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdda.c132
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c216
-rw-r--r--drivers/staging/comedi/drivers/comedi_parport.c38
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c373
-rw-r--r--drivers/staging/comedi/drivers/contec_pci_dio.c163
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c87
-rw-r--r--drivers/staging/comedi/drivers/das08.c132
-rw-r--r--drivers/staging/comedi/drivers/das08.h2
-rw-r--r--drivers/staging/comedi/drivers/das16.c891
-rw-r--r--drivers/staging/comedi/drivers/das16m1.c219
-rw-r--r--drivers/staging/comedi/drivers/das1800.c61
-rw-r--r--drivers/staging/comedi/drivers/das6402.c68
-rw-r--r--drivers/staging/comedi/drivers/das800.c8
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c15
-rw-r--r--drivers/staging/comedi/drivers/dt2801.c283
-rw-r--r--drivers/staging/comedi/drivers/dt2811.c309
-rw-r--r--drivers/staging/comedi/drivers/dt2814.c116
-rw-r--r--drivers/staging/comedi/drivers/dt2815.c42
-rw-r--r--drivers/staging/comedi/drivers/dt2817.c37
-rw-r--r--drivers/staging/comedi/drivers/dt282x.c397
-rw-r--r--drivers/staging/comedi/drivers/dt3000.c234
-rw-r--r--drivers/staging/comedi/drivers/dt9812.c27
-rw-r--r--drivers/staging/comedi/drivers/dyna_pci10xx.c79
-rw-r--r--drivers/staging/comedi/drivers/fl512.c47
-rw-r--r--drivers/staging/comedi/drivers/gsc_hpdi.c98
-rw-r--r--drivers/staging/comedi/drivers/icp_multi.c289
-rw-r--r--drivers/staging/comedi/drivers/ii_pci20kc.c36
-rw-r--r--drivers/staging/comedi/drivers/jr3_pci.c84
-rw-r--r--drivers/staging/comedi/drivers/ke_counter.c98
-rw-r--r--drivers/staging/comedi/drivers/me4000.c432
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c101
-rw-r--r--drivers/staging/comedi/drivers/mite.h4
-rw-r--r--drivers/staging/comedi/drivers/mpc624.c236
-rw-r--r--drivers/staging/comedi/drivers/mpc8260cpm.c114
-rw-r--r--drivers/staging/comedi/drivers/multiq3.c37
-rw-r--r--drivers/staging/comedi/drivers/ni_6527.c10
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c15
-rw-r--r--drivers/staging/comedi/drivers/ni_670x.c12
-rw-r--r--drivers/staging/comedi/drivers/ni_at_a2150.c360
-rw-r--r--drivers/staging/comedi/drivers/ni_at_ao.c238
-rw-r--r--drivers/staging/comedi/drivers/ni_atmio.c94
-rw-r--r--drivers/staging/comedi/drivers/ni_atmio16d.c82
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_700.c17
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_dio24.c17
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.h2
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_cs.c10
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_cs.c13
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c142
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c198
-rw-r--r--drivers/staging/comedi/drivers/ni_tio_internal.h36
-rw-r--r--drivers/staging/comedi/drivers/pcl711.c75
-rw-r--r--drivers/staging/comedi/drivers/pcl724.c65
-rw-r--r--drivers/staging/comedi/drivers/pcl725.c37
-rw-r--r--drivers/staging/comedi/drivers/pcl726.c46
-rw-r--r--drivers/staging/comedi/drivers/pcl730.c57
-rw-r--r--drivers/staging/comedi/drivers/pcl812.c166
-rw-r--r--drivers/staging/comedi/drivers/pcl816.c153
-rw-r--r--drivers/staging/comedi/drivers/pcl818.c166
-rw-r--r--drivers/staging/comedi/drivers/pcm3724.c51
-rw-r--r--drivers/staging/comedi/drivers/pcm3730.c37
-rw-r--r--drivers/staging/comedi/drivers/pcmad.c63
-rw-r--r--drivers/staging/comedi/drivers/pcmda12.c224
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c661
-rw-r--r--drivers/staging/comedi/drivers/pcmuio.c542
-rw-r--r--drivers/staging/comedi/drivers/poc.c205
-rw-r--r--drivers/staging/comedi/drivers/quatech_daqp_cs.c16
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c188
-rw-r--r--drivers/staging/comedi/drivers/rti800.c54
-rw-r--r--drivers/staging/comedi/drivers/rti802.c37
-rw-r--r--drivers/staging/comedi/drivers/s526.c495
-rw-r--r--drivers/staging/comedi/drivers/s626.c137
-rw-r--r--drivers/staging/comedi/drivers/serial2002.c69
-rw-r--r--drivers/staging/comedi/drivers/skel.c9
-rw-r--r--drivers/staging/comedi/drivers/ssv_dnp.c223
-rw-r--r--drivers/staging/comedi/drivers/unioxx5.c453
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c149
-rw-r--r--drivers/staging/comedi/drivers/usbduxfast.c93
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c48
-rw-r--r--drivers/staging/comedi/drivers/vmk80xx.c109
-rw-r--r--drivers/staging/comedi/internal.h6
-rw-r--r--drivers/staging/et131x/et131x.c10
-rw-r--r--drivers/staging/gdm72xx/Kconfig46
-rw-r--r--drivers/staging/gdm72xx/Makefile6
-rw-r--r--drivers/staging/gdm72xx/TODO5
-rw-r--r--drivers/staging/gdm72xx/gdm_qos.c460
-rw-r--r--drivers/staging/gdm72xx/gdm_qos.h93
-rw-r--r--drivers/staging/gdm72xx/gdm_sdio.c754
-rw-r--r--drivers/staging/gdm72xx/gdm_sdio.h72
-rw-r--r--drivers/staging/gdm72xx/gdm_usb.c798
-rw-r--r--drivers/staging/gdm72xx/gdm_usb.h85
-rw-r--r--drivers/staging/gdm72xx/gdm_wimax.c1026
-rw-r--r--drivers/staging/gdm72xx/gdm_wimax.h92
-rw-r--r--drivers/staging/gdm72xx/hci.h218
-rw-r--r--drivers/staging/gdm72xx/netlink_k.c150
-rw-r--r--drivers/staging/gdm72xx/netlink_k.h24
-rw-r--r--drivers/staging/gdm72xx/sdio_boot.c159
-rw-r--r--drivers/staging/gdm72xx/sdio_boot.h21
-rw-r--r--drivers/staging/gdm72xx/usb_boot.c404
-rw-r--r--drivers/staging/gdm72xx/usb_boot.h22
-rw-r--r--drivers/staging/gdm72xx/usb_ids.h82
-rw-r--r--drivers/staging/gdm72xx/wm_ioctl.h97
-rw-r--r--drivers/staging/iio/Documentation/device.txt4
-rw-r--r--drivers/staging/iio/Documentation/generic_buffer.c4
-rw-r--r--drivers/staging/iio/Documentation/iio_event_monitor.c2
-rwxr-xr-xdrivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl25836
-rwxr-xr-xdrivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x13
-rw-r--r--drivers/staging/iio/Documentation/sysfs-bus-iio-ad719220
-rw-r--r--drivers/staging/iio/Documentation/sysfs-bus-iio-dds81
-rw-r--r--drivers/staging/iio/Documentation/sysfs-bus-iio-light15
-rw-r--r--drivers/staging/iio/Documentation/trigger.txt2
-rw-r--r--drivers/staging/iio/Kconfig46
-rw-r--r--drivers/staging/iio/Makefile8
-rw-r--r--drivers/staging/iio/TODO2
-rw-r--r--drivers/staging/iio/accel/adis16201_core.c123
-rw-r--r--drivers/staging/iio/accel/adis16201_ring.c9
-rw-r--r--drivers/staging/iio/accel/adis16201_trigger.c10
-rw-r--r--drivers/staging/iio/accel/adis16203_core.c108
-rw-r--r--drivers/staging/iio/accel/adis16203_ring.c16
-rw-r--r--drivers/staging/iio/accel/adis16203_trigger.c10
-rw-r--r--drivers/staging/iio/accel/adis16204_core.c115
-rw-r--r--drivers/staging/iio/accel/adis16204_ring.c16
-rw-r--r--drivers/staging/iio/accel/adis16204_trigger.c10
-rw-r--r--drivers/staging/iio/accel/adis16209_core.c159
-rw-r--r--drivers/staging/iio/accel/adis16209_ring.c17
-rw-r--r--drivers/staging/iio/accel/adis16209_trigger.c10
-rw-r--r--drivers/staging/iio/accel/adis16220_core.c39
-rw-r--r--drivers/staging/iio/accel/adis16240_core.c129
-rw-r--r--drivers/staging/iio/accel/adis16240_ring.c16
-rw-r--r--drivers/staging/iio/accel/adis16240_trigger.c10
-rw-r--r--drivers/staging/iio/accel/kxsd9.c16
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_core.c50
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c25
-rw-r--r--drivers/staging/iio/accel/sca3000_core.c66
-rw-r--r--drivers/staging/iio/accel/sca3000_ring.c12
-rw-r--r--drivers/staging/iio/adc/Kconfig27
-rw-r--r--drivers/staging/iio/adc/Makefile1
-rw-r--r--drivers/staging/iio/adc/ad7192.c81
-rw-r--r--drivers/staging/iio/adc/ad7280a.c31
-rw-r--r--drivers/staging/iio/adc/ad7291.c26
-rw-r--r--drivers/staging/iio/adc/ad7298.h1
-rw-r--r--drivers/staging/iio/adc/ad7298_core.c79
-rw-r--r--drivers/staging/iio/adc/ad7298_ring.c46
-rw-r--r--drivers/staging/iio/adc/ad7476.h1
-rw-r--r--drivers/staging/iio/adc/ad7476_core.c60
-rw-r--r--drivers/staging/iio/adc/ad7476_ring.c58
-rw-r--r--drivers/staging/iio/adc/ad7606_core.c39
-rw-r--r--drivers/staging/iio/adc/ad7606_par.c2
-rw-r--r--drivers/staging/iio/adc/ad7606_ring.c30
-rw-r--r--drivers/staging/iio/adc/ad7606_spi.c2
-rw-r--r--drivers/staging/iio/adc/ad7780.c44
-rw-r--r--drivers/staging/iio/adc/ad7793.c103
-rw-r--r--drivers/staging/iio/adc/ad7816.c26
-rw-r--r--drivers/staging/iio/adc/ad7887.h1
-rw-r--r--drivers/staging/iio/adc/ad7887_core.c20
-rw-r--r--drivers/staging/iio/adc/ad7887_ring.c46
-rw-r--r--drivers/staging/iio/adc/ad799x.h1
-rw-r--r--drivers/staging/iio/adc/ad799x_core.c62
-rw-r--r--drivers/staging/iio/adc/ad799x_ring.c44
-rw-r--r--drivers/staging/iio/adc/adt7310.c40
-rw-r--r--drivers/staging/iio/adc/adt7410.c40
-rw-r--r--drivers/staging/iio/adc/lpc32xx_adc.c35
-rw-r--r--drivers/staging/iio/adc/max1363_core.c33
-rw-r--r--drivers/staging/iio/adc/max1363_ring.c10
-rw-r--r--drivers/staging/iio/adc/spear_adc.c448
-rw-r--r--drivers/staging/iio/addac/adt7316.c152
-rw-r--r--drivers/staging/iio/cdc/ad7150.c24
-rw-r--r--drivers/staging/iio/cdc/ad7152.c30
-rw-r--r--drivers/staging/iio/cdc/ad7746.c49
-rw-r--r--drivers/staging/iio/dac/Kconfig6
-rw-r--r--drivers/staging/iio/dac/ad5064.c29
-rw-r--r--drivers/staging/iio/dac/ad5360.c21
-rw-r--r--drivers/staging/iio/dac/ad5380.c25
-rw-r--r--drivers/staging/iio/dac/ad5421.c19
-rw-r--r--drivers/staging/iio/dac/ad5446.c293
-rw-r--r--drivers/staging/iio/dac/ad5446.h20
-rw-r--r--drivers/staging/iio/dac/ad5504.c27
-rw-r--r--drivers/staging/iio/dac/ad5624r_spi.c23
-rw-r--r--drivers/staging/iio/dac/ad5686.c25
-rw-r--r--drivers/staging/iio/dac/ad5764.c17
-rw-r--r--drivers/staging/iio/dac/ad5791.c25
-rw-r--r--drivers/staging/iio/dac/max517.c15
-rw-r--r--drivers/staging/iio/dds/dds.h110
-rw-r--r--drivers/staging/iio/frequency/Kconfig (renamed from drivers/staging/iio/dds/Kconfig)0
-rw-r--r--drivers/staging/iio/frequency/Makefile (renamed from drivers/staging/iio/dds/Makefile)0
-rw-r--r--drivers/staging/iio/frequency/ad5930.c (renamed from drivers/staging/iio/dds/ad5930.c)12
-rw-r--r--drivers/staging/iio/frequency/ad9832.c (renamed from drivers/staging/iio/dds/ad9832.c)36
-rw-r--r--drivers/staging/iio/frequency/ad9832.h (renamed from drivers/staging/iio/dds/ad9832.h)0
-rw-r--r--drivers/staging/iio/frequency/ad9834.c (renamed from drivers/staging/iio/dds/ad9834.c)74
-rw-r--r--drivers/staging/iio/frequency/ad9834.h (renamed from drivers/staging/iio/dds/ad9834.h)0
-rw-r--r--drivers/staging/iio/frequency/ad9850.c (renamed from drivers/staging/iio/dds/ad9850.c)12
-rw-r--r--drivers/staging/iio/frequency/ad9852.c (renamed from drivers/staging/iio/dds/ad9852.c)12
-rw-r--r--drivers/staging/iio/frequency/ad9910.c (renamed from drivers/staging/iio/dds/ad9910.c)12
-rw-r--r--drivers/staging/iio/frequency/ad9951.c (renamed from drivers/staging/iio/dds/ad9951.c)12
-rw-r--r--drivers/staging/iio/frequency/dds.h110
-rw-r--r--drivers/staging/iio/gyro/adis16060_core.c18
-rw-r--r--drivers/staging/iio/gyro/adis16080_core.c16
-rw-r--r--drivers/staging/iio/gyro/adis16130_core.c12
-rw-r--r--drivers/staging/iio/gyro/adis16260_core.c116
-rw-r--r--drivers/staging/iio/gyro/adis16260_ring.c16
-rw-r--r--drivers/staging/iio/gyro/adis16260_trigger.c10
-rw-r--r--drivers/staging/iio/gyro/adxrs450.h2
-rw-r--r--drivers/staging/iio/gyro/adxrs450_core.c24
-rw-r--r--drivers/staging/iio/iio_dummy_evgen.c4
-rw-r--r--drivers/staging/iio/iio_hwmon.c4
-rw-r--r--drivers/staging/iio/iio_simple_dummy.c35
-rw-r--r--drivers/staging/iio/iio_simple_dummy_buffer.c21
-rw-r--r--drivers/staging/iio/iio_simple_dummy_events.c8
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c83
-rw-r--r--drivers/staging/iio/imu/adis16400_core.c141
-rw-r--r--drivers/staging/iio/imu/adis16400_ring.c20
-rw-r--r--drivers/staging/iio/imu/adis16400_trigger.c10
-rw-r--r--drivers/staging/iio/light/Kconfig37
-rw-r--r--drivers/staging/iio/light/Makefile2
-rw-r--r--drivers/staging/iio/light/isl29018.c211
-rw-r--r--drivers/staging/iio/light/isl29028.c566
-rw-r--r--drivers/staging/iio/light/tsl2563.c24
-rw-r--r--drivers/staging/iio/light/tsl2583.c34
-rwxr-xr-xdrivers/staging/iio/light/tsl2x7x.h100
-rwxr-xr-xdrivers/staging/iio/light/tsl2x7x_core.c2082
-rw-r--r--drivers/staging/iio/magnetometer/Kconfig8
-rw-r--r--drivers/staging/iio/magnetometer/ak8975.c19
-rw-r--r--drivers/staging/iio/magnetometer/hmc5843.c522
-rw-r--r--drivers/staging/iio/meter/ade7753.c22
-rw-r--r--drivers/staging/iio/meter/ade7754.c22
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c299
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c33
-rw-r--r--drivers/staging/iio/meter/ade7758_trigger.c10
-rw-r--r--drivers/staging/iio/meter/ade7759.c22
-rw-r--r--drivers/staging/iio/meter/ade7854-i2c.c22
-rw-r--r--drivers/staging/iio/meter/ade7854-spi.c22
-rw-r--r--drivers/staging/iio/meter/ade7854.c28
-rw-r--r--drivers/staging/iio/meter/meter.h2
-rw-r--r--drivers/staging/iio/resolver/ad2s1200.c12
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c38
-rw-r--r--drivers/staging/iio/resolver/ad2s90.c11
-rw-r--r--drivers/staging/iio/ring_sw.c2
-rw-r--r--drivers/staging/iio/ring_sw.h2
-rw-r--r--drivers/staging/iio/trigger/iio-trig-bfin-timer.c10
-rw-r--r--drivers/staging/iio/trigger/iio-trig-gpio.c10
-rw-r--r--drivers/staging/iio/trigger/iio-trig-periodic-rtc.c8
-rw-r--r--drivers/staging/iio/trigger/iio-trig-sysfs.c10
-rw-r--r--drivers/staging/ipack/Kconfig20
-rw-r--r--drivers/staging/ipack/Makefile6
-rw-r--r--drivers/staging/ipack/TODO46
-rw-r--r--drivers/staging/ipack/bridges/Kconfig8
-rw-r--r--drivers/staging/ipack/bridges/Makefile1
-rw-r--r--drivers/staging/ipack/bridges/tpci200.c1141
-rw-r--r--drivers/staging/ipack/bridges/tpci200.h162
-rw-r--r--drivers/staging/ipack/devices/Kconfig7
-rw-r--r--drivers/staging/ipack/devices/Makefile1
-rw-r--r--drivers/staging/ipack/devices/ipoctal.c901
-rw-r--r--drivers/staging/ipack/devices/ipoctal.h80
-rw-r--r--drivers/staging/ipack/devices/scc2698.h228
-rw-r--r--drivers/staging/ipack/ipack.c205
-rw-r--r--drivers/staging/ipack/ipack.h183
-rw-r--r--drivers/staging/line6/config.h48
-rw-r--r--drivers/staging/line6/driver.c89
-rw-r--r--drivers/staging/line6/midi.c2
-rw-r--r--drivers/staging/line6/midibuf.c2
-rw-r--r--drivers/staging/line6/pcm.c2
-rw-r--r--drivers/staging/media/as102/as102_fe.c2
-rw-r--r--drivers/staging/media/as102/as102_fw.c5
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.c5
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.h2
-rw-r--r--drivers/staging/media/easycap/easycap_ioctl.c1
-rw-r--r--drivers/staging/media/go7007/README2
-rw-r--r--drivers/staging/media/go7007/s2250-loader.c26
-rw-r--r--drivers/staging/mei/TODO10
-rw-r--r--drivers/staging/net/Kconfig38
-rw-r--r--drivers/staging/net/Makefile5
-rw-r--r--drivers/staging/net/TODO5
-rw-r--r--drivers/staging/net/pc300-falc-lh.h (renamed from drivers/net/wan/pc300-falc-lh.h)0
-rw-r--r--drivers/staging/net/pc300.h (renamed from drivers/net/wan/pc300.h)0
-rw-r--r--drivers/staging/net/pc300_drv.c (renamed from drivers/net/wan/pc300_drv.c)0
-rw-r--r--drivers/staging/net/pc300_tty.c (renamed from drivers/net/wan/pc300_tty.c)0
-rw-r--r--drivers/staging/nvec/nvec.h2
-rw-r--r--drivers/staging/octeon/ethernet-rx.c2
-rw-r--r--drivers/staging/octeon/ethernet-tx.c10
-rw-r--r--drivers/staging/octeon/ethernet-util.h2
-rw-r--r--drivers/staging/octeon/ethernet.c2
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c29
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1.c2
-rw-r--r--drivers/staging/omapdrm/Makefile1
-rw-r--r--drivers/staging/omapdrm/omap_dmm_tiler.c4
-rw-r--r--drivers/staging/omapdrm/omap_drv.c6
-rw-r--r--drivers/staging/omapdrm/omap_drv.h14
-rw-r--r--drivers/staging/omapdrm/omap_fb.c7
-rw-r--r--drivers/staging/omapdrm/omap_gem.c130
-rw-r--r--drivers/staging/omapdrm/omap_gem_dmabuf.c220
-rw-r--r--drivers/staging/omapdrm/tcm-sita.c2
-rw-r--r--drivers/staging/ozwpan/README2
-rw-r--r--drivers/staging/ozwpan/ozappif.h12
-rw-r--r--drivers/staging/ozwpan/ozcdev.c17
-rw-r--r--drivers/staging/ozwpan/ozevent.c195
-rw-r--r--drivers/staging/ozwpan/ozevent.h11
-rw-r--r--drivers/staging/ozwpan/ozeventdef.h19
-rw-r--r--drivers/staging/ozwpan/ozhcd.c6
-rw-r--r--drivers/staging/ozwpan/ozmain.c8
-rw-r--r--drivers/staging/ozwpan/ozusbsvc.c2
-rw-r--r--drivers/staging/panel/panel.c2
-rw-r--r--drivers/staging/ramster/Kconfig2
-rw-r--r--drivers/staging/ramster/cluster/tcp.c4
-rw-r--r--drivers/staging/ramster/xvmalloc.c2
-rw-r--r--drivers/staging/ramster/zcache-main.c6
-rw-r--r--drivers/staging/rtl8187se/Makefile2
-rw-r--r--drivers/staging/rtl8187se/ieee80211/dot11d.c2
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211.h14
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c26
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c2
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c7
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c2
-rw-r--r--drivers/staging/rtl8187se/r8180.h10
-rw-r--r--drivers/staging/rtl8187se/r8180_core.c33
-rw-r--r--drivers/staging/rtl8187se/r8180_dm.c16
-rw-r--r--drivers/staging/rtl8187se/r8180_rtl8225z2.c4
-rw-r--r--drivers/staging/rtl8187se/r8180_wx.c6
-rw-r--r--drivers/staging/rtl8187se/r8180_wx.h2
-rw-r--r--drivers/staging/rtl8187se/r8185b_init.c1329
-rw-r--r--drivers/staging/rtl8192e/Kconfig4
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c3
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r819xE_phyreg.h4
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_core.c13
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_core.h3
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_dm.c22
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_wx.c4
-rw-r--r--drivers/staging/rtl8192e/rtl819x_TSProc.c2
-rw-r--r--drivers/staging/rtl8192e/rtllib.h18
-rw-r--r--drivers/staging/rtl8192e/rtllib_rx.c10
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c35
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac_wx.c4
-rw-r--r--drivers/staging/rtl8192e/rtllib_tx.c14
-rw-r--r--drivers/staging/rtl8192e/rtllib_wx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_module.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c7
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c2
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.c2
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.h2
-rw-r--r--drivers/staging/rtl8192u/r8192U.h9
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c60
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c74
-rw-r--r--drivers/staging/rtl8192u/r8192U_hw.h2
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c12
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.h2
-rw-r--r--drivers/staging/rtl8192u/r819xU_HTType.h2
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.c12
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c4
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c16
-rw-r--r--drivers/staging/rtl8192u/r819xU_phyreg.h2
-rw-r--r--drivers/staging/rtl8712/big_endian.h94
-rw-r--r--drivers/staging/rtl8712/drv_types.h2
-rw-r--r--drivers/staging/rtl8712/generic.h178
-rw-r--r--drivers/staging/rtl8712/hal_init.c1
-rw-r--r--drivers/staging/rtl8712/ieee80211.h2
-rw-r--r--drivers/staging/rtl8712/if_ether.h141
-rw-r--r--drivers/staging/rtl8712/ip.h137
-rw-r--r--drivers/staging/rtl8712/little_endian.h94
-rw-r--r--drivers/staging/rtl8712/os_intfs.c4
-rw-r--r--drivers/staging/rtl8712/osdep_service.h3
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c7
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.h2
-rw-r--r--drivers/staging/rtl8712/rtl8712_efuse.c2
-rw-r--r--drivers/staging/rtl8712/rtl8712_gp_bitdef.h2
-rw-r--r--drivers/staging/rtl8712/rtl8712_hal.h4
-rw-r--r--drivers/staging/rtl8712/rtl8712_led.c6
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c9
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c1
-rw-r--r--drivers/staging/rtl8712/rtl871x_byteorder.h32
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c1
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_io.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c19
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c2
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c8
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.h6
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h4
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.c4
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c3
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.h2
-rw-r--r--drivers/staging/rtl8712/swab.h131
-rw-r--r--drivers/staging/rtl8712/usb_halinit.c4
-rw-r--r--drivers/staging/rtl8712/usb_intf.c36
-rw-r--r--drivers/staging/rtl8712/usb_ops.c1
-rw-r--r--drivers/staging/rtl8712/wifi.h1
-rw-r--r--drivers/staging/rtl8712/xmit_linux.c6
-rw-r--r--drivers/staging/rts5139/ms.c11
-rw-r--r--drivers/staging/rts5139/ms.h2
-rw-r--r--drivers/staging/rts5139/ms_mg.c4
-rw-r--r--drivers/staging/rts5139/rts51x.c83
-rw-r--r--drivers/staging/rts5139/rts51x.h10
-rw-r--r--drivers/staging/rts5139/rts51x_card.c52
-rw-r--r--drivers/staging/rts5139/rts51x_card.h11
-rw-r--r--drivers/staging/rts5139/rts51x_chip.c178
-rw-r--r--drivers/staging/rts5139/rts51x_chip.h95
-rw-r--r--drivers/staging/rts5139/rts51x_fop.c5
-rw-r--r--drivers/staging/rts5139/rts51x_fop.h5
-rw-r--r--drivers/staging/rts5139/rts51x_scsi.c93
-rw-r--r--drivers/staging/rts5139/rts51x_scsi.h5
-rw-r--r--drivers/staging/rts5139/rts51x_sys.h54
-rw-r--r--drivers/staging/rts5139/rts51x_transport.c282
-rw-r--r--drivers/staging/rts5139/rts51x_transport.h12
-rw-r--r--drivers/staging/rts5139/sd.c142
-rw-r--r--drivers/staging/rts5139/sd.h29
-rw-r--r--drivers/staging/rts5139/sd_cprm.c166
-rw-r--r--drivers/staging/rts5139/xd.c122
-rw-r--r--drivers/staging/rts5139/xd.h2
-rw-r--r--drivers/staging/rts_pstor/ms.c2
-rw-r--r--drivers/staging/rts_pstor/rtsx_transport.c4
-rw-r--r--drivers/staging/sep/sep_driver_config.h6
-rw-r--r--drivers/staging/sep/sep_main.c12
-rw-r--r--drivers/staging/serial/68360serial.c2979
-rw-r--r--drivers/staging/serial/Kconfig16
-rw-r--r--drivers/staging/serial/Makefile1
-rw-r--r--drivers/staging/serial/TODO6
-rw-r--r--drivers/staging/sm7xx/smtcfb.c232
-rw-r--r--drivers/staging/sm7xx/smtcfb.h8
-rw-r--r--drivers/staging/telephony/ixj.c228
-rw-r--r--drivers/staging/tidspbridge/core/io_sm.c2
-rw-r--r--drivers/staging/tidspbridge/core/ue_deh.c2
-rw-r--r--drivers/staging/usbip/stub_dev.c12
-rw-r--r--drivers/staging/usbip/usbip_common.h17
-rw-r--r--drivers/staging/usbip/usbip_protocol.txt2
-rw-r--r--drivers/staging/usbip/userspace/libsrc/vhci_driver.c20
-rw-r--r--drivers/staging/usbip/vhci_hcd.c8
-rw-r--r--drivers/staging/usbip/vhci_rx.c2
-rw-r--r--drivers/staging/usbip/vhci_sysfs.c4
-rw-r--r--drivers/staging/vme/Makefile7
-rw-r--r--drivers/staging/vme/TODO5
-rw-r--r--drivers/staging/vme/devices/Kconfig3
-rw-r--r--drivers/staging/vme/devices/vme_pio2_cntr.c2
-rw-r--r--drivers/staging/vme/devices/vme_pio2_core.c3
-rw-r--r--drivers/staging/vme/devices/vme_pio2_gpio.c5
-rw-r--r--drivers/staging/vme/devices/vme_user.c45
-rw-r--r--drivers/staging/vt6655/wpa.c4
-rw-r--r--drivers/staging/vt6656/dpc.c2
-rw-r--r--drivers/staging/vt6656/ioctl.c24
-rw-r--r--drivers/staging/vt6656/main_usb.c4
-rw-r--r--drivers/staging/vt6656/wpa.c4
-rw-r--r--drivers/staging/wlags49_h2/README.ubuntu2
-rw-r--r--drivers/staging/wlags49_h2/hcf.c10
-rw-r--r--drivers/staging/wlags49_h2/hcf.h12
-rw-r--r--drivers/staging/wlags49_h2/mmd.c12
-rw-r--r--drivers/staging/wlags49_h2/wl_cs.c3
-rw-r--r--drivers/staging/wlags49_h2/wl_netdev.c9
-rw-r--r--drivers/staging/wlags49_h2/wl_pci.c4
-rw-r--r--drivers/staging/wlags49_h2/wl_profile.c8
-rw-r--r--drivers/staging/wlags49_h2/wl_util.c11
-rw-r--r--drivers/staging/wlan-ng/cfg80211.c10
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.c4
-rw-r--r--drivers/staging/xgifb/XGI_main.h221
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c101
-rw-r--r--drivers/staging/xgifb/XGIfb.h6
-rw-r--r--drivers/staging/xgifb/vb_init.c78
-rw-r--r--drivers/staging/xgifb/vb_setmode.c1457
-rw-r--r--drivers/staging/xgifb/vb_struct.h27
-rw-r--r--drivers/staging/xgifb/vb_table.h725
-rw-r--r--drivers/staging/xgifb/vgatypes.h2
-rw-r--r--drivers/staging/zsmalloc/zsmalloc-main.c40
-rw-r--r--drivers/staging/zsmalloc/zsmalloc_int.h2
-rw-r--r--drivers/vme/Kconfig (renamed from drivers/staging/vme/Kconfig)6
-rw-r--r--drivers/vme/Makefile7
-rw-r--r--drivers/vme/boards/Kconfig (renamed from drivers/staging/vme/boards/Kconfig)0
-rw-r--r--drivers/vme/boards/Makefile (renamed from drivers/staging/vme/boards/Makefile)0
-rw-r--r--drivers/vme/boards/vme_vmivme7805.c (renamed from drivers/staging/vme/boards/vme_vmivme7805.c)0
-rw-r--r--drivers/vme/boards/vme_vmivme7805.h (renamed from drivers/staging/vme/boards/vme_vmivme7805.h)0
-rw-r--r--drivers/vme/bridges/Kconfig (renamed from drivers/staging/vme/bridges/Kconfig)0
-rw-r--r--drivers/vme/bridges/Makefile (renamed from drivers/staging/vme/bridges/Makefile)0
-rw-r--r--drivers/vme/bridges/vme_ca91cx42.c (renamed from drivers/staging/vme/bridges/vme_ca91cx42.c)8
-rw-r--r--drivers/vme/bridges/vme_ca91cx42.h (renamed from drivers/staging/vme/bridges/vme_ca91cx42.h)0
-rw-r--r--drivers/vme/bridges/vme_tsi148.c (renamed from drivers/staging/vme/bridges/vme_tsi148.c)189
-rw-r--r--drivers/vme/bridges/vme_tsi148.h (renamed from drivers/staging/vme/bridges/vme_tsi148.h)21
-rw-r--r--drivers/vme/vme.c (renamed from drivers/staging/vme/vme.c)41
-rw-r--r--drivers/vme/vme_bridge.h (renamed from drivers/staging/vme/vme_bridge.h)0
-rw-r--r--fs/pstore/Kconfig17
-rw-r--r--fs/pstore/Makefile3
-rw-r--r--fs/pstore/ram.c383
-rw-r--r--fs/pstore/ram_core.c (renamed from drivers/staging/android/persistent_ram.c)161
-rw-r--r--include/linux/Kbuild2
-rw-r--r--include/linux/alarmtimer.h3
-rw-r--r--include/linux/iio/buffer.h (renamed from drivers/staging/iio/buffer.h)4
-rw-r--r--include/linux/iio/consumer.h (renamed from drivers/staging/iio/consumer.h)2
-rw-r--r--include/linux/iio/driver.h (renamed from drivers/staging/iio/driver.h)0
-rw-r--r--include/linux/iio/events.h (renamed from drivers/staging/iio/events.h)2
-rw-r--r--include/linux/iio/iio.h (renamed from drivers/staging/iio/iio.h)101
-rw-r--r--include/linux/iio/kfifo_buf.h (renamed from drivers/staging/iio/kfifo_buf.h)4
-rw-r--r--include/linux/iio/machine.h (renamed from drivers/staging/iio/machine.h)0
-rw-r--r--include/linux/iio/sysfs.h (renamed from drivers/staging/iio/sysfs.h)0
-rw-r--r--include/linux/iio/trigger.h (renamed from drivers/staging/iio/trigger.h)8
-rw-r--r--include/linux/iio/trigger_consumer.h (renamed from drivers/staging/iio/trigger_consumer.h)0
-rw-r--r--include/linux/iio/types.h (renamed from drivers/staging/iio/types.h)2
-rw-r--r--include/linux/mei.h (renamed from drivers/staging/mei/mei.h)0
-rw-r--r--include/linux/platform_data/at91_adc.h61
-rw-r--r--include/linux/pstore_ram.h (renamed from drivers/staging/android/persistent_ram.h)30
-rw-r--r--include/linux/ramoops.h17
-rw-r--r--include/linux/uuid.h4
-rw-r--r--include/linux/vme.h (renamed from drivers/staging/vme/vme.h)0
-rw-r--r--kernel/time/alarmtimer.c4
611 files changed, 27821 insertions, 25614 deletions
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 46a995d6d261..5bc8a476c15e 100644
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -108,7 +108,7 @@ Description:
108 physically equivalent inputs when non differential readings are 108 physically equivalent inputs when non differential readings are
109 separately available. In differential only parts, then all that 109 separately available. In differential only parts, then all that
110 is required is a consistent labeling. Units after application 110 is required is a consistent labeling. Units after application
111 of scale and offset are nanofarads.. 111 of scale and offset are nanofarads.
112 112
113What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw 113What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw
114What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw 114What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw
@@ -119,7 +119,7 @@ KernelVersion: 2.6.35
119Contact: linux-iio@vger.kernel.org 119Contact: linux-iio@vger.kernel.org
120Description: 120Description:
121 Raw (unscaled no bias removal etc) temperature measurement. 121 Raw (unscaled no bias removal etc) temperature measurement.
122 It an axis is specified it generally means that the temperature 122 If an axis is specified it generally means that the temperature
123 sensor is associated with one part of a compound device (e.g. 123 sensor is associated with one part of a compound device (e.g.
124 a gyroscope axis). Units after application of scale and offset 124 a gyroscope axis). Units after application of scale and offset
125 are milli degrees Celsuis. 125 are milli degrees Celsuis.
@@ -232,7 +232,7 @@ Description:
232 If known for a device, scale to be applied to <type>Y[_name]_raw 232 If known for a device, scale to be applied to <type>Y[_name]_raw
233 post addition of <type>[Y][_name]_offset in order to obtain the 233 post addition of <type>[Y][_name]_offset in order to obtain the
234 measured value in <type> units as specified in 234 measured value in <type> units as specified in
235 <type>[Y][_name]_raw documentation.. If shared across all in 235 <type>[Y][_name]_raw documentation. If shared across all in
236 channels then Y and <x|y|z> are not present and the value is 236 channels then Y and <x|y|z> are not present and the value is
237 called <type>[Y][_name]_scale. The peak modifier means this 237 called <type>[Y][_name]_scale. The peak modifier means this
238 value is applied to <type>Y[_name]_peak_raw values. 238 value is applied to <type>Y[_name]_peak_raw values.
@@ -243,6 +243,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibbias
243What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibbias 243What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibbias
244What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibbias 244What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibbias
245What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibbias 245What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibbias
246What: /sys/bus/iio/devices/iio:deviceX/in_illuminance0_calibbias
247What: /sys/bus/iio/devices/iio:deviceX/in_proximity0_calibbias
246KernelVersion: 2.6.35 248KernelVersion: 2.6.35
247Contact: linux-iio@vger.kernel.org 249Contact: linux-iio@vger.kernel.org
248Description: 250Description:
@@ -258,6 +260,8 @@ What /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibscale
258What /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibscale 260What /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibscale
259What /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibscale 261What /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibscale
260What /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibscale 262What /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibscale
263what /sys/bus/iio/devices/iio:deviceX/in_illuminance0_calibscale
264what /sys/bus/iio/devices/iio:deviceX/in_proximity0_calibscale
261KernelVersion: 2.6.35 265KernelVersion: 2.6.35
262Contact: linux-iio@vger.kernel.org 266Contact: linux-iio@vger.kernel.org
263Description: 267Description:
@@ -276,6 +280,13 @@ Description:
276 If a discrete set of scale values are available, they 280 If a discrete set of scale values are available, they
277 are listed in this attribute. 281 are listed in this attribute.
278 282
283What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain
284KernelVersion: 2.6.35
285Contact: linux-iio@vger.kernel.org
286Description:
287 Hardware applied gain factor. If shared across all channels,
288 <type>_hardwaregain is used.
289
279What: /sys/.../in_accel_filter_low_pass_3db_frequency 290What: /sys/.../in_accel_filter_low_pass_3db_frequency
280What: /sys/.../in_magn_filter_low_pass_3db_frequency 291What: /sys/.../in_magn_filter_low_pass_3db_frequency
281What: /sys/.../in_anglvel_filter_low_pass_3db_frequency 292What: /sys/.../in_anglvel_filter_low_pass_3db_frequency
@@ -453,10 +464,14 @@ What: /sys/.../events/in_magn_z_raw_thresh_rising_value
453What: /sys/.../events/in_magn_z_raw_thresh_falling_value 464What: /sys/.../events/in_magn_z_raw_thresh_falling_value
454What: /sys/.../events/in_voltageY_supply_raw_thresh_rising_value 465What: /sys/.../events/in_voltageY_supply_raw_thresh_rising_value
455What: /sys/.../events/in_voltageY_supply_raw_thresh_falling_value 466What: /sys/.../events/in_voltageY_supply_raw_thresh_falling_value
467What: /sys/.../events/in_voltageY_raw_thresh_rising_value
456What: /sys/.../events/in_voltageY_raw_thresh_falling_value 468What: /sys/.../events/in_voltageY_raw_thresh_falling_value
457What: /sys/.../events/in_voltageY_raw_thresh_falling_value 469What: /sys/.../events/in_tempY_raw_thresh_rising_value
458What: /sys/.../events/in_tempY_raw_thresh_falling_value
459What: /sys/.../events/in_tempY_raw_thresh_falling_value 470What: /sys/.../events/in_tempY_raw_thresh_falling_value
471What: /sys/.../events/in_illuminance0_thresh_falling_value
472what: /sys/.../events/in_illuminance0_thresh_rising_value
473what: /sys/.../events/in_proximity0_thresh_falling_value
474what: /sys/.../events/in_proximity0_thresh_rising_value
460KernelVersion: 2.6.37 475KernelVersion: 2.6.37
461Contact: linux-iio@vger.kernel.org 476Contact: linux-iio@vger.kernel.org
462Description: 477Description:
@@ -490,9 +505,9 @@ What: /sys/.../events/in_magn_z_raw_roc_rising_value
490What: /sys/.../events/in_magn_z_raw_roc_falling_value 505What: /sys/.../events/in_magn_z_raw_roc_falling_value
491What: /sys/.../events/in_voltageY_supply_raw_roc_rising_value 506What: /sys/.../events/in_voltageY_supply_raw_roc_rising_value
492What: /sys/.../events/in_voltageY_supply_raw_roc_falling_value 507What: /sys/.../events/in_voltageY_supply_raw_roc_falling_value
508What: /sys/.../events/in_voltageY_raw_roc_rising_value
493What: /sys/.../events/in_voltageY_raw_roc_falling_value 509What: /sys/.../events/in_voltageY_raw_roc_falling_value
494What: /sys/.../events/in_voltageY_raw_roc_falling_value 510What: /sys/.../events/in_tempY_raw_roc_rising_value
495What: /sys/.../events/in_tempY_raw_roc_falling_value
496What: /sys/.../events/in_tempY_raw_roc_falling_value 511What: /sys/.../events/in_tempY_raw_roc_falling_value
497KernelVersion: 2.6.37 512KernelVersion: 2.6.37
498Contact: linux-iio@vger.kernel.org 513Contact: linux-iio@vger.kernel.org
@@ -556,6 +571,8 @@ What: /sys/.../events/in_tempY_thresh_falling_period
556What: /sys/.../events/in_tempY_roc_rising_period 571What: /sys/.../events/in_tempY_roc_rising_period
557What: /sys/.../events/in_tempY_roc_falling_period 572What: /sys/.../events/in_tempY_roc_falling_period
558What: /sys/.../events/in_accel_x&y&z_mag_falling_period 573What: /sys/.../events/in_accel_x&y&z_mag_falling_period
574What: /sys/.../events/in_intensity0_thresh_period
575What: /sys/.../events/in_proximity0_thresh_period
559KernelVersion: 2.6.37 576KernelVersion: 2.6.37
560Contact: linux-iio@vger.kernel.org 577Contact: linux-iio@vger.kernel.org
561Description: 578Description:
@@ -718,24 +735,3 @@ Contact: linux-iio@vger.kernel.org
718Description: 735Description:
719 This attribute is used to read the amount of quadrature error 736 This attribute is used to read the amount of quadrature error
720 present in the device at a given time. 737 present in the device at a given time.
721
722What: /sys/.../iio:deviceX/ac_excitation_en
723KernelVersion: 3.1.0
724Contact: linux-iio@vger.kernel.org
725Description:
726 This attribute, if available, is used to enable the AC
727 excitation mode found on some converters. In ac excitation mode,
728 the polarity of the excitation voltage is reversed on
729 alternate cycles, to eliminate DC errors.
730
731What: /sys/.../iio:deviceX/bridge_switch_en
732KernelVersion: 3.1.0
733Contact: linux-iio@vger.kernel.org
734Description:
735 This attribute, if available, is used to close or open the
736 bridge power down switch found on some converters.
737 In bridge applications, such as strain gauges and load cells,
738 the bridge itself consumes the majority of the current in the
739 system. To minimize the current consumption of the system,
740 the bridge can be disconnected (when it is not being used
741 using the bridge_switch_en attribute.
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 30b656ece7aa..31d302bc5863 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -1,3 +1,3 @@
1obj-m := DocBook/ accounting/ auxdisplay/ connector/ \ 1obj-m := DocBook/ accounting/ auxdisplay/ connector/ \
2 filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \ 2 filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \
3 pcmcia/ spi/ timers/ watchdog/src/ 3 pcmcia/ spi/ timers/ watchdog/src/ misc-devices/mei/
diff --git a/Documentation/devicetree/bindings/arm/atmel-adc.txt b/Documentation/devicetree/bindings/arm/atmel-adc.txt
new file mode 100644
index 000000000000..c63097d6afeb
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/atmel-adc.txt
@@ -0,0 +1,65 @@
1* AT91's Analog to Digital Converter (ADC)
2
3Required properties:
4 - compatible: Should be "atmel,at91sam9260-adc"
5 - reg: Should contain ADC registers location and length
6 - interrupts: Should contain the IRQ line for the ADC
7 - atmel,adc-channel-base: Offset of the first channel data register
8 - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this
9 device
10 - atmel,adc-drdy-mask: Mask of the DRDY interruption in the ADC
11 - atmel,adc-num-channels: Number of channels available in the ADC
12 - atmel,adc-startup-time: Startup Time of the ADC in microseconds as
13 defined in the datasheet
14 - atmel,adc-status-register: Offset of the Interrupt Status Register
15 - atmel,adc-trigger-register: Offset of the Trigger Register
16 - atmel,adc-vref: Reference voltage in millivolts for the conversions
17
18Optional properties:
19 - atmel,adc-use-external: Boolean to enable of external triggers
20
21Optional trigger Nodes:
22 - Required properties:
23 * trigger-name: Name of the trigger exposed to the user
24 * trigger-value: Value to put in the Trigger register
25 to activate this trigger
26 - Optional properties:
27 * trigger-external: Is the trigger an external trigger?
28
29Examples:
30adc0: adc@fffb0000 {
31 compatible = "atmel,at91sam9260-adc";
32 reg = <0xfffb0000 0x100>;
33 interrupts = <20 4>;
34 atmel,adc-channel-base = <0x30>;
35 atmel,adc-channels-used = <0xff>;
36 atmel,adc-drdy-mask = <0x10000>;
37 atmel,adc-num-channels = <8>;
38 atmel,adc-startup-time = <40>;
39 atmel,adc-status-register = <0x1c>;
40 atmel,adc-trigger-register = <0x08>;
41 atmel,adc-use-external;
42 atmel,adc-vref = <3300>;
43
44 trigger@0 {
45 trigger-name = "external-rising";
46 trigger-value = <0x1>;
47 trigger-external;
48 };
49 trigger@1 {
50 trigger-name = "external-falling";
51 trigger-value = <0x2>;
52 trigger-external;
53 };
54
55 trigger@2 {
56 trigger-name = "external-any";
57 trigger-value = <0x3>;
58 trigger-external;
59 };
60
61 trigger@3 {
62 trigger-name = "continuous";
63 trigger-value = <0x6>;
64 };
65};
diff --git a/Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt b/Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt
new file mode 100644
index 000000000000..b3629d3a9adf
--- /dev/null
+++ b/Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt
@@ -0,0 +1,16 @@
1* NXP LPC32xx SoC ADC controller
2
3Required properties:
4- compatible: must be "nxp,lpc3220-adc"
5- reg: physical base address of the controller and length of memory mapped
6 region.
7- interrupts: The ADC interrupt
8
9Example:
10
11 adc@40048000 {
12 compatible = "nxp,lpc3220-adc";
13 reg = <0x40048000 0x1000>;
14 interrupt-parent = <&mic>;
15 interrupts = <39 0>;
16 };
diff --git a/Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt b/Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt
new file mode 100644
index 000000000000..02ea23a63f20
--- /dev/null
+++ b/Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt
@@ -0,0 +1,26 @@
1* ST SPEAr ADC device driver
2
3Required properties:
4- compatible: Should be "st,spear600-adc"
5- reg: Address and length of the register set for the device
6- interrupt-parent: Should be the phandle for the interrupt controller
7 that services interrupts for this device
8- interrupts: Should contain the ADC interrupt
9- sampling-frequency: Default sampling frequency
10
11Optional properties:
12- vref-external: External voltage reference in milli-volts. If omitted
13 the internal voltage reference will be used.
14- average-samples: Number of samples to generate an average value. If
15 omitted, single data conversion will be used.
16
17Examples:
18
19 adc: adc@d8200000 {
20 compatible = "st,spear600-adc";
21 reg = <0xd8200000 0x1000>;
22 interrupt-parent = <&vic1>;
23 interrupts = <6>;
24 sampling-frequency = <5000000>;
25 vref-external = <2500>; /* 2.5V VRef */
26 };
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index e34b531dc316..915f28c470e9 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -120,6 +120,7 @@ Code Seq#(hex) Include File Comments
120'G' 00-0F linux/gigaset_dev.h conflict! 120'G' 00-0F linux/gigaset_dev.h conflict!
121'H' 00-7F linux/hiddev.h conflict! 121'H' 00-7F linux/hiddev.h conflict!
122'H' 00-0F linux/hidraw.h conflict! 122'H' 00-0F linux/hidraw.h conflict!
123'H' 01 linux/mei.h conflict!
123'H' 00-0F sound/asound.h conflict! 124'H' 00-0F sound/asound.h conflict!
124'H' 20-40 sound/asound_fm.h conflict! 125'H' 20-40 sound/asound_fm.h conflict!
125'H' 80-8F sound/sfnt_info.h conflict! 126'H' 80-8F sound/sfnt_info.h conflict!
diff --git a/Documentation/misc-devices/mei/.gitignore b/Documentation/misc-devices/mei/.gitignore
new file mode 100644
index 000000000000..f356b81ca1ec
--- /dev/null
+++ b/Documentation/misc-devices/mei/.gitignore
@@ -0,0 +1 @@
mei-amt-version
diff --git a/Documentation/misc-devices/mei/Makefile b/Documentation/misc-devices/mei/Makefile
new file mode 100644
index 000000000000..00e8c3e836ff
--- /dev/null
+++ b/Documentation/misc-devices/mei/Makefile
@@ -0,0 +1,8 @@
1# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
5hostprogs-y := mei-amt-version
6HOSTCFLAGS_mei-amt-version.o += -I$(objtree)/usr/include
7# Tell kbuild to always build the programs
8always := $(hostprogs-y)
diff --git a/Documentation/misc-devices/mei/TODO b/Documentation/misc-devices/mei/TODO
new file mode 100644
index 000000000000..6b3625d3058c
--- /dev/null
+++ b/Documentation/misc-devices/mei/TODO
@@ -0,0 +1,2 @@
1TODO:
2 - Cleanup and split the timer function
diff --git a/drivers/staging/mei/mei-amt-version.c b/Documentation/misc-devices/mei/mei-amt-version.c
index ac2a507be253..01804f216312 100644
--- a/drivers/staging/mei/mei-amt-version.c
+++ b/Documentation/misc-devices/mei/mei-amt-version.c
@@ -74,7 +74,7 @@
74#include <stdint.h> 74#include <stdint.h>
75#include <stdbool.h> 75#include <stdbool.h>
76#include <bits/wordsize.h> 76#include <bits/wordsize.h>
77#include "mei.h" 77#include <linux/mei.h>
78 78
79/***************************************************************************** 79/*****************************************************************************
80 * Intel Management Engine Interface 80 * Intel Management Engine Interface
diff --git a/drivers/staging/mei/mei.txt b/Documentation/misc-devices/mei/mei.txt
index 2785697da59d..2785697da59d 100644
--- a/drivers/staging/mei/mei.txt
+++ b/Documentation/misc-devices/mei/mei.txt
diff --git a/Documentation/ramoops.txt b/Documentation/ramoops.txt
index 8fb1ba7fe7bf..4ba7db231cb2 100644
--- a/Documentation/ramoops.txt
+++ b/Documentation/ramoops.txt
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
3 3
4Sergiu Iordache <sergiu@chromium.org> 4Sergiu Iordache <sergiu@chromium.org>
5 5
6Updated: 8 August 2011 6Updated: 17 November 2011
7 7
80. Introduction 80. Introduction
9 9
@@ -30,6 +30,11 @@ variable while setting 0 in that variable dumps only the panics.
30The module uses a counter to record multiple dumps but the counter gets reset 30The module uses a counter to record multiple dumps but the counter gets reset
31on restart (i.e. new dumps after the restart will overwrite old ones). 31on restart (i.e. new dumps after the restart will overwrite old ones).
32 32
33Ramoops also supports software ECC protection of persistent memory regions.
34This might be useful when a hardware reset was used to bring the machine back
35to life (i.e. a watchdog triggered). In such cases, RAM may be somewhat
36corrupt, but usually it is restorable.
37
332. Setting the parameters 382. Setting the parameters
34 39
35Setting the ramoops parameters can be done in 2 different manners: 40Setting the ramoops parameters can be done in 2 different manners:
@@ -38,7 +43,7 @@ Setting the ramoops parameters can be done in 2 different manners:
38 2. Use a platform device and set the platform data. The parameters can then 43 2. Use a platform device and set the platform data. The parameters can then
39 be set through that platform data. An example of doing that is: 44 be set through that platform data. An example of doing that is:
40 45
41#include <linux/ramoops.h> 46#include <linux/pstore_ram.h>
42[...] 47[...]
43 48
44static struct ramoops_platform_data ramoops_data = { 49static struct ramoops_platform_data ramoops_data = {
@@ -46,6 +51,7 @@ static struct ramoops_platform_data ramoops_data = {
46 .mem_address = <...>, 51 .mem_address = <...>,
47 .record_size = <...>, 52 .record_size = <...>,
48 .dump_oops = <...>, 53 .dump_oops = <...>,
54 .ecc = <...>,
49}; 55};
50 56
51static struct platform_device ramoops_dev = { 57static struct platform_device ramoops_dev = {
@@ -71,6 +77,6 @@ timestamp and a new line. The dump then continues with the actual data.
71 77
724. Reading the data 784. Reading the data
73 79
74The dump data can be read from memory (through /dev/mem or other means). 80The dump data can be read from the pstore filesystem. The format for these
75Getting the module parameters, which are needed in order to parse the data, can 81files is "dmesg-ramoops-N", where N is the record number in memory. To delete
76be done through /sys/module/ramoops/parameters/* . 82a stored record from RAM, simply unlink the respective pstore file.
diff --git a/drivers/staging/vme/vme_api.txt b/Documentation/vme_api.txt
index 856efa35f6e3..856efa35f6e3 100644
--- a/drivers/staging/vme/vme_api.txt
+++ b/Documentation/vme_api.txt
diff --git a/MAINTAINERS b/MAINTAINERS
index a8e609855995..aa067a95ce11 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3406,6 +3406,7 @@ IIO SUBSYSTEM AND DRIVERS
3406M: Jonathan Cameron <jic23@cam.ac.uk> 3406M: Jonathan Cameron <jic23@cam.ac.uk>
3407L: linux-iio@vger.kernel.org 3407L: linux-iio@vger.kernel.org
3408S: Maintained 3408S: Maintained
3409F: drivers/iio/
3409F: drivers/staging/iio/ 3410F: drivers/staging/iio/
3410 3411
3411IKANOS/ADI EAGLE ADSL USB DRIVER 3412IKANOS/ADI EAGLE ADSL USB DRIVER
@@ -3625,6 +3626,14 @@ S: Supported
3625W: http://wireless.kernel.org/en/users/Drivers/iwmc3200wifi 3626W: http://wireless.kernel.org/en/users/Drivers/iwmc3200wifi
3626F: drivers/net/wireless/iwmc3200wifi/ 3627F: drivers/net/wireless/iwmc3200wifi/
3627 3628
3629INTEL MANAGEMENT ENGINE (mei)
3630M: Tomas Winkler <tomas.winkler@intel.com>
3631L: linux-kernel@vger.kernel.org
3632S: Supported
3633F: include/linux/mei.h
3634F: drivers/misc/mei/*
3635F: Documentation/mei/*
3636
3628IOC3 ETHERNET DRIVER 3637IOC3 ETHERNET DRIVER
3629M: Ralf Baechle <ralf@linux-mips.org> 3638M: Ralf Baechle <ralf@linux-mips.org>
3630L: linux-mips@linux-mips.org 3639L: linux-mips@linux-mips.org
@@ -7350,6 +7359,18 @@ S: Maintained
7350F: drivers/vlynq/vlynq.c 7359F: drivers/vlynq/vlynq.c
7351F: include/linux/vlynq.h 7360F: include/linux/vlynq.h
7352 7361
7362VME SUBSYSTEM
7363M: Martyn Welch <martyn.welch@ge.com>
7364M: Manohar Vanga <manohar.vanga@cern.ch>
7365M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
7366L: devel@driverdev.osuosl.org
7367S: Maintained
7368T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
7369F: Documentation/vme_api.txt
7370F: drivers/staging/vme/
7371F: drivers/vme/
7372F: include/linux/vme*
7373
7353VMWARE VMXNET3 ETHERNET DRIVER 7374VMWARE VMXNET3 ETHERNET DRIVER
7354M: Shreyas Bhatewara <sbhatewara@vmware.com> 7375M: Shreyas Bhatewara <sbhatewara@vmware.com>
7355M: "VMware, Inc." <pv-drivers@vmware.com> 7376M: "VMware, Inc." <pv-drivers@vmware.com>
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index c8042147eaa2..7dbccaf199f7 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -199,6 +199,43 @@
199 interrupts = <25 4>; 199 interrupts = <25 4>;
200 status = "disabled"; 200 status = "disabled";
201 }; 201 };
202
203 adc0: adc@fffb0000 {
204 compatible = "atmel,at91sam9260-adc";
205 reg = <0xfffb0000 0x100>;
206 interrupts = <20 4>;
207 atmel,adc-use-external-triggers;
208 atmel,adc-channels-used = <0xff>;
209 atmel,adc-vref = <3300>;
210 atmel,adc-num-channels = <8>;
211 atmel,adc-startup-time = <40>;
212 atmel,adc-channel-base = <0x30>;
213 atmel,adc-drdy-mask = <0x10000>;
214 atmel,adc-status-register = <0x1c>;
215 atmel,adc-trigger-register = <0x08>;
216
217 trigger@0 {
218 trigger-name = "external-rising";
219 trigger-value = <0x1>;
220 trigger-external;
221 };
222 trigger@1 {
223 trigger-name = "external-falling";
224 trigger-value = <0x2>;
225 trigger-external;
226 };
227
228 trigger@2 {
229 trigger-name = "external-any";
230 trigger-value = <0x3>;
231 trigger-external;
232 };
233
234 trigger@3 {
235 trigger-name = "continuous";
236 trigger-value = <0x6>;
237 };
238 };
202 }; 239 };
203 240
204 nand0: nand@40000000 { 241 nand0: nand@40000000 {
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi b/arch/arm/boot/dts/at91sam9x5.dtsi
index dd4ed748469a..6b3ef4339ae7 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -190,6 +190,44 @@
190 interrupts = <27 4>; 190 interrupts = <27 4>;
191 status = "disabled"; 191 status = "disabled";
192 }; 192 };
193
194 adc0: adc@f804c000 {
195 compatible = "atmel,at91sam9260-adc";
196 reg = <0xf804c000 0x100>;
197 interrupts = <19 4>;
198 atmel,adc-use-external;
199 atmel,adc-channels-used = <0xffff>;
200 atmel,adc-vref = <3300>;
201 atmel,adc-num-channels = <12>;
202 atmel,adc-startup-time = <40>;
203 atmel,adc-channel-base = <0x50>;
204 atmel,adc-drdy-mask = <0x1000000>;
205 atmel,adc-status-register = <0x30>;
206 atmel,adc-trigger-register = <0xc0>;
207
208 trigger@0 {
209 trigger-name = "external-rising";
210 trigger-value = <0x1>;
211 trigger-external;
212 };
213
214 trigger@1 {
215 trigger-name = "external-falling";
216 trigger-value = <0x2>;
217 trigger-external;
218 };
219
220 trigger@2 {
221 trigger-name = "external-any";
222 trigger-value = <0x3>;
223 trigger-external;
224 };
225
226 trigger@3 {
227 trigger-name = "continuous";
228 trigger-value = <0x6>;
229 };
230 };
193 }; 231 };
194 232
195 nand0: nand@40000000 { 233 nand0: nand@40000000 {
diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index a27bbec50ca3..2b1e438ed878 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -55,6 +55,13 @@ static struct clk adc_clk = {
55 .pmc_mask = 1 << AT91SAM9260_ID_ADC, 55 .pmc_mask = 1 << AT91SAM9260_ID_ADC,
56 .type = CLK_TYPE_PERIPHERAL, 56 .type = CLK_TYPE_PERIPHERAL,
57}; 57};
58
59static struct clk adc_op_clk = {
60 .name = "adc_op_clk",
61 .type = CLK_TYPE_PERIPHERAL,
62 .rate_hz = 5000000,
63};
64
58static struct clk usart0_clk = { 65static struct clk usart0_clk = {
59 .name = "usart0_clk", 66 .name = "usart0_clk",
60 .pmc_mask = 1 << AT91SAM9260_ID_US0, 67 .pmc_mask = 1 << AT91SAM9260_ID_US0,
@@ -166,6 +173,7 @@ static struct clk *periph_clocks[] __initdata = {
166 &pioB_clk, 173 &pioB_clk,
167 &pioC_clk, 174 &pioC_clk,
168 &adc_clk, 175 &adc_clk,
176 &adc_op_clk,
169 &usart0_clk, 177 &usart0_clk,
170 &usart1_clk, 178 &usart1_clk,
171 &usart2_clk, 179 &usart2_clk,
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index d556de141114..0ded951f785a 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -17,12 +17,15 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/i2c-gpio.h> 18#include <linux/i2c-gpio.h>
19 19
20#include <linux/platform_data/at91_adc.h>
21
20#include <mach/board.h> 22#include <mach/board.h>
21#include <mach/cpu.h> 23#include <mach/cpu.h>
22#include <mach/at91sam9260.h> 24#include <mach/at91sam9260.h>
23#include <mach/at91sam9260_matrix.h> 25#include <mach/at91sam9260_matrix.h>
24#include <mach/at91_matrix.h> 26#include <mach/at91_matrix.h>
25#include <mach/at91sam9_smc.h> 27#include <mach/at91sam9_smc.h>
28#include <mach/at91_adc.h>
26 29
27#include "generic.h" 30#include "generic.h"
28 31
@@ -1340,6 +1343,93 @@ void __init at91_add_device_cf(struct at91_cf_data *data)
1340void __init at91_add_device_cf(struct at91_cf_data * data) {} 1343void __init at91_add_device_cf(struct at91_cf_data * data) {}
1341#endif 1344#endif
1342 1345
1346/* --------------------------------------------------------------------
1347 * ADCs
1348 * -------------------------------------------------------------------- */
1349
1350#if IS_ENABLED(CONFIG_AT91_ADC)
1351static struct at91_adc_data adc_data;
1352
1353static struct resource adc_resources[] = {
1354 [0] = {
1355 .start = AT91SAM9260_BASE_ADC,
1356 .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
1357 .flags = IORESOURCE_MEM,
1358 },
1359 [1] = {
1360 .start = AT91SAM9260_ID_ADC,
1361 .end = AT91SAM9260_ID_ADC,
1362 .flags = IORESOURCE_IRQ,
1363 },
1364};
1365
1366static struct platform_device at91_adc_device = {
1367 .name = "at91_adc",
1368 .id = -1,
1369 .dev = {
1370 .platform_data = &adc_data,
1371 },
1372 .resource = adc_resources,
1373 .num_resources = ARRAY_SIZE(adc_resources),
1374};
1375
1376static struct at91_adc_trigger at91_adc_triggers[] = {
1377 [0] = {
1378 .name = "timer-counter-0",
1379 .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
1380 },
1381 [1] = {
1382 .name = "timer-counter-1",
1383 .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
1384 },
1385 [2] = {
1386 .name = "timer-counter-2",
1387 .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
1388 },
1389 [3] = {
1390 .name = "external",
1391 .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
1392 .is_external = true,
1393 },
1394};
1395
1396static struct at91_adc_reg_desc at91_adc_register_g20 = {
1397 .channel_base = AT91_ADC_CHR(0),
1398 .drdy_mask = AT91_ADC_DRDY,
1399 .status_register = AT91_ADC_SR,
1400 .trigger_register = AT91_ADC_MR,
1401};
1402
1403void __init at91_add_device_adc(struct at91_adc_data *data)
1404{
1405 if (!data)
1406 return;
1407
1408 if (test_bit(0, &data->channels_used))
1409 at91_set_A_periph(AT91_PIN_PC0, 0);
1410 if (test_bit(1, &data->channels_used))
1411 at91_set_A_periph(AT91_PIN_PC1, 0);
1412 if (test_bit(2, &data->channels_used))
1413 at91_set_A_periph(AT91_PIN_PC2, 0);
1414 if (test_bit(3, &data->channels_used))
1415 at91_set_A_periph(AT91_PIN_PC3, 0);
1416
1417 if (data->use_external_triggers)
1418 at91_set_A_periph(AT91_PIN_PA22, 0);
1419
1420 data->num_channels = 4;
1421 data->startup_time = 10;
1422 data->registers = &at91_adc_register_g20;
1423 data->trigger_number = 4;
1424 data->trigger_list = at91_adc_triggers;
1425
1426 adc_data = *data;
1427 platform_device_register(&at91_adc_device);
1428}
1429#else
1430void __init at91_add_device_adc(struct at91_adc_data *data) {}
1431#endif
1432
1343/* -------------------------------------------------------------------- */ 1433/* -------------------------------------------------------------------- */
1344/* 1434/*
1345 * These devices are always present and don't need any board-specific 1435 * These devices are always present and don't need any board-specific
diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index f2054495a655..4792682d52b9 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -176,6 +176,12 @@ static struct clk vdec_clk = {
176 .type = CLK_TYPE_PERIPHERAL, 176 .type = CLK_TYPE_PERIPHERAL,
177}; 177};
178 178
179static struct clk adc_op_clk = {
180 .name = "adc_op_clk",
181 .type = CLK_TYPE_PERIPHERAL,
182 .rate_hz = 13200000,
183};
184
179static struct clk *periph_clocks[] __initdata = { 185static struct clk *periph_clocks[] __initdata = {
180 &pioA_clk, 186 &pioA_clk,
181 &pioB_clk, 187 &pioB_clk,
@@ -204,6 +210,7 @@ static struct clk *periph_clocks[] __initdata = {
204 &isi_clk, 210 &isi_clk,
205 &udphs_clk, 211 &udphs_clk,
206 &mmc1_clk, 212 &mmc1_clk,
213 &adc_op_clk,
207 // irq0 214 // irq0
208}; 215};
209 216
@@ -242,6 +249,8 @@ static struct clk_lookup periph_clocks_lookups[] = {
242 CLKDEV_CON_ID("pioC", &pioC_clk), 249 CLKDEV_CON_ID("pioC", &pioC_clk),
243 CLKDEV_CON_ID("pioD", &pioDE_clk), 250 CLKDEV_CON_ID("pioD", &pioDE_clk),
244 CLKDEV_CON_ID("pioE", &pioDE_clk), 251 CLKDEV_CON_ID("pioE", &pioDE_clk),
252 /* Fake adc clock */
253 CLKDEV_CON_ID("adc_clk", &tsc_clk),
245}; 254};
246 255
247static struct clk_lookup usart_clocks_lookups[] = { 256static struct clk_lookup usart_clocks_lookups[] = {
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
index 35bd42d02195..f6747246d649 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -19,9 +19,12 @@
19#include <linux/i2c-gpio.h> 19#include <linux/i2c-gpio.h>
20#include <linux/atmel-mci.h> 20#include <linux/atmel-mci.h>
21 21
22#include <linux/platform_data/at91_adc.h>
23
22#include <linux/fb.h> 24#include <linux/fb.h>
23#include <video/atmel_lcdc.h> 25#include <video/atmel_lcdc.h>
24 26
27#include <mach/at91_adc.h>
25#include <mach/board.h> 28#include <mach/board.h>
26#include <mach/at91sam9g45.h> 29#include <mach/at91sam9g45.h>
27#include <mach/at91sam9g45_matrix.h> 30#include <mach/at91sam9g45_matrix.h>
@@ -1182,6 +1185,104 @@ void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {}
1182 1185
1183 1186
1184/* -------------------------------------------------------------------- 1187/* --------------------------------------------------------------------
1188 * ADC
1189 * -------------------------------------------------------------------- */
1190
1191#if IS_ENABLED(CONFIG_AT91_ADC)
1192static struct at91_adc_data adc_data;
1193
1194static struct resource adc_resources[] = {
1195 [0] = {
1196 .start = AT91SAM9G45_BASE_TSC,
1197 .end = AT91SAM9G45_BASE_TSC + SZ_16K - 1,
1198 .flags = IORESOURCE_MEM,
1199 },
1200 [1] = {
1201 .start = AT91SAM9G45_ID_TSC,
1202 .end = AT91SAM9G45_ID_TSC,
1203 .flags = IORESOURCE_IRQ,
1204 }
1205};
1206
1207static struct platform_device at91_adc_device = {
1208 .name = "at91_adc",
1209 .id = -1,
1210 .dev = {
1211 .platform_data = &adc_data,
1212 },
1213 .resource = adc_resources,
1214 .num_resources = ARRAY_SIZE(adc_resources),
1215};
1216
1217static struct at91_adc_trigger at91_adc_triggers[] = {
1218 [0] = {
1219 .name = "external-rising",
1220 .value = 1,
1221 .is_external = true,
1222 },
1223 [1] = {
1224 .name = "external-falling",
1225 .value = 2,
1226 .is_external = true,
1227 },
1228 [2] = {
1229 .name = "external-any",
1230 .value = 3,
1231 .is_external = true,
1232 },
1233 [3] = {
1234 .name = "continuous",
1235 .value = 6,
1236 .is_external = false,
1237 },
1238};
1239
1240static struct at91_adc_reg_desc at91_adc_register_g45 = {
1241 .channel_base = AT91_ADC_CHR(0),
1242 .drdy_mask = AT91_ADC_DRDY,
1243 .status_register = AT91_ADC_SR,
1244 .trigger_register = 0x08,
1245};
1246
1247void __init at91_add_device_adc(struct at91_adc_data *data)
1248{
1249 if (!data)
1250 return;
1251
1252 if (test_bit(0, &data->channels_used))
1253 at91_set_gpio_input(AT91_PIN_PD20, 0);
1254 if (test_bit(1, &data->channels_used))
1255 at91_set_gpio_input(AT91_PIN_PD21, 0);
1256 if (test_bit(2, &data->channels_used))
1257 at91_set_gpio_input(AT91_PIN_PD22, 0);
1258 if (test_bit(3, &data->channels_used))
1259 at91_set_gpio_input(AT91_PIN_PD23, 0);
1260 if (test_bit(4, &data->channels_used))
1261 at91_set_gpio_input(AT91_PIN_PD24, 0);
1262 if (test_bit(5, &data->channels_used))
1263 at91_set_gpio_input(AT91_PIN_PD25, 0);
1264 if (test_bit(6, &data->channels_used))
1265 at91_set_gpio_input(AT91_PIN_PD26, 0);
1266 if (test_bit(7, &data->channels_used))
1267 at91_set_gpio_input(AT91_PIN_PD27, 0);
1268
1269 if (data->use_external_triggers)
1270 at91_set_A_periph(AT91_PIN_PD28, 0);
1271
1272 data->num_channels = 8;
1273 data->startup_time = 40;
1274 data->registers = &at91_adc_register_g45;
1275 data->trigger_number = 4;
1276 data->trigger_list = at91_adc_triggers;
1277
1278 adc_data = *data;
1279 platform_device_register(&at91_adc_device);
1280}
1281#else
1282void __init at91_add_device_adc(struct at91_adc_data *data) {}
1283#endif
1284
1285/* --------------------------------------------------------------------
1185 * RTT 1286 * RTT
1186 * -------------------------------------------------------------------- */ 1287 * -------------------------------------------------------------------- */
1187 1288
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index 13c8cae60462..1b144b4d3ce1 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -120,6 +120,11 @@ static struct clk adc_clk = {
120 .pmc_mask = 1 << AT91SAM9X5_ID_ADC, 120 .pmc_mask = 1 << AT91SAM9X5_ID_ADC,
121 .type = CLK_TYPE_PERIPHERAL, 121 .type = CLK_TYPE_PERIPHERAL,
122}; 122};
123static struct clk adc_op_clk = {
124 .name = "adc_op_clk",
125 .type = CLK_TYPE_PERIPHERAL,
126 .rate_hz = 5000000,
127};
123static struct clk dma0_clk = { 128static struct clk dma0_clk = {
124 .name = "dma0_clk", 129 .name = "dma0_clk",
125 .pmc_mask = 1 << AT91SAM9X5_ID_DMA0, 130 .pmc_mask = 1 << AT91SAM9X5_ID_DMA0,
@@ -205,6 +210,7 @@ static struct clk *periph_clocks[] __initdata = {
205 &tcb0_clk, 210 &tcb0_clk,
206 &pwm_clk, 211 &pwm_clk,
207 &adc_clk, 212 &adc_clk,
213 &adc_op_clk,
208 &dma0_clk, 214 &dma0_clk,
209 &dma1_clk, 215 &dma1_clk,
210 &uhphs_clk, 216 &uhphs_clk,
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
index 3d615532ae5c..6860d3451100 100644
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ b/arch/arm/mach-at91/board-sam9g20ek.c
@@ -32,6 +32,8 @@
32#include <linux/regulator/fixed.h> 32#include <linux/regulator/fixed.h>
33#include <linux/regulator/consumer.h> 33#include <linux/regulator/consumer.h>
34 34
35#include <linux/platform_data/at91_adc.h>
36
35#include <mach/hardware.h> 37#include <mach/hardware.h>
36#include <asm/setup.h> 38#include <asm/setup.h>
37#include <asm/mach-types.h> 39#include <asm/mach-types.h>
@@ -304,6 +306,16 @@ static void __init ek_add_device_buttons(void)
304static void __init ek_add_device_buttons(void) {} 306static void __init ek_add_device_buttons(void) {}
305#endif 307#endif
306 308
309/*
310 * ADCs
311 */
312
313static struct at91_adc_data ek_adc_data = {
314 .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3),
315 .use_external_triggers = true,
316 .vref = 3300,
317};
318
307#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE) 319#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE)
308static struct regulator_consumer_supply ek_audio_consumer_supplies[] = { 320static struct regulator_consumer_supply ek_audio_consumer_supplies[] = {
309 REGULATOR_SUPPLY("AVDD", "0-001b"), 321 REGULATOR_SUPPLY("AVDD", "0-001b"),
@@ -389,6 +401,8 @@ static void __init ek_board_init(void)
389 ek_add_device_gpio_leds(); 401 ek_add_device_gpio_leds();
390 /* Push Buttons */ 402 /* Push Buttons */
391 ek_add_device_buttons(); 403 ek_add_device_buttons();
404 /* ADCs */
405 at91_add_device_adc(&ek_adc_data);
392 /* PCK0 provides MCLK to the WM8731 */ 406 /* PCK0 provides MCLK to the WM8731 */
393 at91_set_B_periph(AT91_PIN_PC1, 0); 407 at91_set_B_periph(AT91_PIN_PC1, 0);
394 /* SSC (for WM8731) */ 408 /* SSC (for WM8731) */
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
index 9a87f0b072f8..63163dc7df46 100644
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ b/arch/arm/mach-at91/board-sam9m10g45ek.c
@@ -27,6 +27,8 @@
27#include <linux/atmel-mci.h> 27#include <linux/atmel-mci.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29 29
30#include <linux/platform_data/at91_adc.h>
31
30#include <mach/hardware.h> 32#include <mach/hardware.h>
31#include <video/atmel_lcdc.h> 33#include <video/atmel_lcdc.h>
32#include <media/soc_camera.h> 34#include <media/soc_camera.h>
@@ -305,6 +307,14 @@ static struct at91_tsadcc_data ek_tsadcc_data = {
305 .ts_sample_hold_time = 0x0a, 307 .ts_sample_hold_time = 0x0a,
306}; 308};
307 309
310/*
311 * ADCs
312 */
313static struct at91_adc_data ek_adc_data = {
314 .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7),
315 .use_external_triggers = true,
316 .vref = 3300,
317};
308 318
309/* 319/*
310 * GPIO Buttons 320 * GPIO Buttons
@@ -476,6 +486,8 @@ static void __init ek_board_init(void)
476 at91_add_device_lcdc(&ek_lcdc_data); 486 at91_add_device_lcdc(&ek_lcdc_data);
477 /* Touch Screen */ 487 /* Touch Screen */
478 at91_add_device_tsadcc(&ek_tsadcc_data); 488 at91_add_device_tsadcc(&ek_tsadcc_data);
489 /* ADC */
490 at91_add_device_adc(&ek_adc_data);
479 /* Push Buttons */ 491 /* Push Buttons */
480 ek_add_device_buttons(); 492 ek_add_device_buttons();
481 /* AC97 */ 493 /* AC97 */
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 63b81826cb55..bfc918633fd9 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -144,4 +144,8 @@ source "drivers/extcon/Kconfig"
144 144
145source "drivers/memory/Kconfig" 145source "drivers/memory/Kconfig"
146 146
147source "drivers/iio/Kconfig"
148
149source "drivers/vme/Kconfig"
150
147endmenu 151endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 265b506a15be..35d5181c8ef2 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -136,3 +136,5 @@ obj-$(CONFIG_HYPERV) += hv/
136obj-$(CONFIG_PM_DEVFREQ) += devfreq/ 136obj-$(CONFIG_PM_DEVFREQ) += devfreq/
137obj-$(CONFIG_EXTCON) += extcon/ 137obj-$(CONFIG_EXTCON) += extcon/
138obj-$(CONFIG_MEMORY) += memory/ 138obj-$(CONFIG_MEMORY) += memory/
139obj-$(CONFIG_IIO) += iio/
140obj-$(CONFIG_VME_BUS) += vme/
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index ee946865d6cb..ea6f6325f9ba 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -585,14 +585,6 @@ config DEVPORT
585 585
586source "drivers/s390/char/Kconfig" 586source "drivers/s390/char/Kconfig"
587 587
588config RAMOOPS
589 tristate "Log panic/oops to a RAM buffer"
590 depends on HAS_IOMEM
591 default n
592 help
593 This enables panic and oops messages to be logged to a circular
594 buffer in RAM where it can be read back at some later point.
595
596config MSM_SMD_PKT 588config MSM_SMD_PKT
597 bool "Enable device interface for some SMD packet ports" 589 bool "Enable device interface for some SMD packet ports"
598 default n 590 default n
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 0dc5d7ce4864..d0b27a39f1d4 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -58,7 +58,6 @@ obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
58obj-$(CONFIG_TCG_TPM) += tpm/ 58obj-$(CONFIG_TCG_TPM) += tpm/
59 59
60obj-$(CONFIG_PS3_FLASH) += ps3flash.o 60obj-$(CONFIG_PS3_FLASH) += ps3flash.o
61obj-$(CONFIG_RAMOOPS) += ramoops.o
62 61
63obj-$(CONFIG_JS_RTC) += js-rtc.o 62obj-$(CONFIG_JS_RTC) += js-rtc.o
64js-rtc-y = rtc.o 63js-rtc-y = rtc.o
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
deleted file mode 100644
index 2a5e45d2a9f8..000000000000
--- a/drivers/char/ramoops.c
+++ /dev/null
@@ -1,250 +0,0 @@
1/*
2 * RAM Oops/Panic logger
3 *
4 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
24#include <linux/kernel.h>
25#include <linux/err.h>
26#include <linux/module.h>
27#include <linux/kmsg_dump.h>
28#include <linux/time.h>
29#include <linux/io.h>
30#include <linux/ioport.h>
31#include <linux/platform_device.h>
32#include <linux/slab.h>
33#include <linux/ramoops.h>
34
35#define RAMOOPS_KERNMSG_HDR "===="
36#define MIN_MEM_SIZE 4096UL
37
38static ulong record_size = MIN_MEM_SIZE;
39module_param(record_size, ulong, 0400);
40MODULE_PARM_DESC(record_size,
41 "size of each dump done on oops/panic");
42
43static ulong mem_address;
44module_param(mem_address, ulong, 0400);
45MODULE_PARM_DESC(mem_address,
46 "start of reserved RAM used to store oops/panic logs");
47
48static ulong mem_size;
49module_param(mem_size, ulong, 0400);
50MODULE_PARM_DESC(mem_size,
51 "size of reserved RAM used to store oops/panic logs");
52
53static int dump_oops = 1;
54module_param(dump_oops, int, 0600);
55MODULE_PARM_DESC(dump_oops,
56 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
57
58static struct ramoops_context {
59 struct kmsg_dumper dump;
60 void *virt_addr;
61 phys_addr_t phys_addr;
62 unsigned long size;
63 unsigned long record_size;
64 int dump_oops;
65 int count;
66 int max_count;
67} oops_cxt;
68
69static struct platform_device *dummy;
70static struct ramoops_platform_data *dummy_data;
71
72static void ramoops_do_dump(struct kmsg_dumper *dumper,
73 enum kmsg_dump_reason reason, const char *s1, unsigned long l1,
74 const char *s2, unsigned long l2)
75{
76 struct ramoops_context *cxt = container_of(dumper,
77 struct ramoops_context, dump);
78 unsigned long s1_start, s2_start;
79 unsigned long l1_cpy, l2_cpy;
80 int res, hdr_size;
81 char *buf, *buf_orig;
82 struct timeval timestamp;
83
84 if (reason != KMSG_DUMP_OOPS &&
85 reason != KMSG_DUMP_PANIC)
86 return;
87
88 /* Only dump oopses if dump_oops is set */
89 if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
90 return;
91
92 buf = cxt->virt_addr + (cxt->count * cxt->record_size);
93 buf_orig = buf;
94
95 memset(buf, '\0', cxt->record_size);
96 res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR);
97 buf += res;
98 do_gettimeofday(&timestamp);
99 res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec);
100 buf += res;
101
102 hdr_size = buf - buf_orig;
103 l2_cpy = min(l2, cxt->record_size - hdr_size);
104 l1_cpy = min(l1, cxt->record_size - hdr_size - l2_cpy);
105
106 s2_start = l2 - l2_cpy;
107 s1_start = l1 - l1_cpy;
108
109 memcpy(buf, s1 + s1_start, l1_cpy);
110 memcpy(buf + l1_cpy, s2 + s2_start, l2_cpy);
111
112 cxt->count = (cxt->count + 1) % cxt->max_count;
113}
114
115static int __init ramoops_probe(struct platform_device *pdev)
116{
117 struct ramoops_platform_data *pdata = pdev->dev.platform_data;
118 struct ramoops_context *cxt = &oops_cxt;
119 int err = -EINVAL;
120
121 if (!pdata->mem_size || !pdata->record_size) {
122 pr_err("The memory size and the record size must be "
123 "non-zero\n");
124 goto fail3;
125 }
126
127 pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
128 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
129
130 /* Check for the minimum memory size */
131 if (pdata->mem_size < MIN_MEM_SIZE &&
132 pdata->record_size < MIN_MEM_SIZE) {
133 pr_err("memory size too small, minium is %lu\n", MIN_MEM_SIZE);
134 goto fail3;
135 }
136
137 if (pdata->mem_size < pdata->record_size) {
138 pr_err("The memory size must be larger than the "
139 "records size\n");
140 goto fail3;
141 }
142
143 cxt->max_count = pdata->mem_size / pdata->record_size;
144 cxt->count = 0;
145 cxt->size = pdata->mem_size;
146 cxt->phys_addr = pdata->mem_address;
147 cxt->record_size = pdata->record_size;
148 cxt->dump_oops = pdata->dump_oops;
149
150 if (!request_mem_region(cxt->phys_addr, cxt->size, "ramoops")) {
151 pr_err("request mem region failed\n");
152 err = -EINVAL;
153 goto fail3;
154 }
155
156 cxt->virt_addr = ioremap(cxt->phys_addr, cxt->size);
157 if (!cxt->virt_addr) {
158 pr_err("ioremap failed\n");
159 goto fail2;
160 }
161
162 cxt->dump.dump = ramoops_do_dump;
163 err = kmsg_dump_register(&cxt->dump);
164 if (err) {
165 pr_err("registering kmsg dumper failed\n");
166 goto fail1;
167 }
168
169 /*
170 * Update the module parameter variables as well so they are visible
171 * through /sys/module/ramoops/parameters/
172 */
173 mem_size = pdata->mem_size;
174 mem_address = pdata->mem_address;
175 record_size = pdata->record_size;
176 dump_oops = pdata->dump_oops;
177
178 return 0;
179
180fail1:
181 iounmap(cxt->virt_addr);
182fail2:
183 release_mem_region(cxt->phys_addr, cxt->size);
184fail3:
185 return err;
186}
187
188static int __exit ramoops_remove(struct platform_device *pdev)
189{
190 struct ramoops_context *cxt = &oops_cxt;
191
192 if (kmsg_dump_unregister(&cxt->dump) < 0)
193 pr_warn("could not unregister kmsg_dumper\n");
194
195 iounmap(cxt->virt_addr);
196 release_mem_region(cxt->phys_addr, cxt->size);
197 return 0;
198}
199
200static struct platform_driver ramoops_driver = {
201 .remove = __exit_p(ramoops_remove),
202 .driver = {
203 .name = "ramoops",
204 .owner = THIS_MODULE,
205 },
206};
207
208static int __init ramoops_init(void)
209{
210 int ret;
211 ret = platform_driver_probe(&ramoops_driver, ramoops_probe);
212 if (ret == -ENODEV) {
213 /*
214 * If we didn't find a platform device, we use module parameters
215 * building platform data on the fly.
216 */
217 pr_info("platform device not found, using module parameters\n");
218 dummy_data = kzalloc(sizeof(struct ramoops_platform_data),
219 GFP_KERNEL);
220 if (!dummy_data)
221 return -ENOMEM;
222 dummy_data->mem_size = mem_size;
223 dummy_data->mem_address = mem_address;
224 dummy_data->record_size = record_size;
225 dummy_data->dump_oops = dump_oops;
226 dummy = platform_create_bundle(&ramoops_driver, ramoops_probe,
227 NULL, 0, dummy_data,
228 sizeof(struct ramoops_platform_data));
229
230 if (IS_ERR(dummy))
231 ret = PTR_ERR(dummy);
232 else
233 ret = 0;
234 }
235
236 return ret;
237}
238
239static void __exit ramoops_exit(void)
240{
241 platform_driver_unregister(&ramoops_driver);
242 kfree(dummy_data);
243}
244
245module_init(ramoops_init);
246module_exit(ramoops_exit);
247
248MODULE_LICENSE("GPL");
249MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
250MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
new file mode 100644
index 000000000000..56eecefcec75
--- /dev/null
+++ b/drivers/iio/Kconfig
@@ -0,0 +1,54 @@
1#
2# Industrial I/O subsytem configuration
3#
4
5menuconfig IIO
6 tristate "Industrial I/O support"
7 depends on GENERIC_HARDIRQS
8 help
9 The industrial I/O subsystem provides a unified framework for
10 drivers for many different types of embedded sensors using a
11 number of different physical interfaces (i2c, spi, etc). See
12 Documentation/iio for more information.
13
14if IIO
15
16config IIO_BUFFER
17 bool "Enable buffer support within IIO"
18 help
19 Provide core support for various buffer based data
20 acquisition methods.
21
22if IIO_BUFFER
23
24config IIO_KFIFO_BUF
25 select IIO_TRIGGER
26 tristate "Industrial I/O buffering based on kfifo"
27 help
28 A simple fifo based on kfifo. Use this if you want a fifo
29 rather than a ring buffer. Note that this currently provides
30 no buffer events so it is up to userspace to work out how
31 often to read from the buffer.
32
33endif # IIO_BUFFER
34
35config IIO_TRIGGER
36 boolean "Enable triggered sampling support"
37 help
38 Provides IIO core support for triggers. Currently these
39 are used to initialize capture of samples to push into
40 ring buffers. The triggers are effectively a 'capture
41 data now' interrupt.
42
43config IIO_CONSUMERS_PER_TRIGGER
44 int "Maximum number of consumers per trigger"
45 depends on IIO_TRIGGER
46 default "2"
47 help
48 This value controls the maximum number of consumers that a
49 given trigger may handle. Default is 2.
50
51source "drivers/iio/adc/Kconfig"
52source "drivers/iio/amplifiers/Kconfig"
53
54endif # IIO
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
new file mode 100644
index 000000000000..e425afd1480c
--- /dev/null
+++ b/drivers/iio/Makefile
@@ -0,0 +1,13 @@
1#
2# Makefile for the industrial I/O core.
3#
4
5obj-$(CONFIG_IIO) += industrialio.o
6industrialio-y := industrialio-core.o industrialio-event.o inkern.o
7industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
8industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
9
10obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
11
12obj-y += adc/
13obj-y += amplifiers/
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
new file mode 100644
index 000000000000..9a0df8123cc4
--- /dev/null
+++ b/drivers/iio/adc/Kconfig
@@ -0,0 +1,16 @@
1#
2# ADC drivers
3#
4menu "Analog to digital converters"
5
6config AT91_ADC
7 tristate "Atmel AT91 ADC"
8 depends on ARCH_AT91
9 select IIO_BUFFER
10 select IIO_KFIFO_BUF
11 select IIO_TRIGGER
12 select SYSFS
13 help
14 Say yes here to build support for Atmel AT91 ADC.
15
16endmenu
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
new file mode 100644
index 000000000000..175c8d41ea99
--- /dev/null
+++ b/drivers/iio/adc/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for IIO ADC drivers
3#
4
5obj-$(CONFIG_AT91_ADC) += at91_adc.o
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
new file mode 100644
index 000000000000..f18a95d80255
--- /dev/null
+++ b/drivers/iio/adc/at91_adc.c
@@ -0,0 +1,802 @@
1/*
2 * Driver for the ADC present in the Atmel AT91 evaluation boards.
3 *
4 * Copyright 2011 Free Electrons
5 *
6 * Licensed under the GPLv2 or later.
7 */
8
9#include <linux/bitmap.h>
10#include <linux/bitops.h>
11#include <linux/clk.h>
12#include <linux/err.h>
13#include <linux/io.h>
14#include <linux/interrupt.h>
15#include <linux/jiffies.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_device.h>
20#include <linux/platform_device.h>
21#include <linux/sched.h>
22#include <linux/slab.h>
23#include <linux/wait.h>
24
25#include <linux/platform_data/at91_adc.h>
26
27#include <linux/iio/iio.h>
28#include <linux/iio/buffer.h>
29#include <linux/iio/kfifo_buf.h>
30#include <linux/iio/trigger.h>
31#include <linux/iio/trigger_consumer.h>
32
33#include <mach/at91_adc.h>
34
35#define AT91_ADC_CHAN(st, ch) \
36 (st->registers->channel_base + (ch * 4))
37#define at91_adc_readl(st, reg) \
38 (readl_relaxed(st->reg_base + reg))
39#define at91_adc_writel(st, reg, val) \
40 (writel_relaxed(val, st->reg_base + reg))
41
42struct at91_adc_state {
43 struct clk *adc_clk;
44 u16 *buffer;
45 unsigned long channels_mask;
46 struct clk *clk;
47 bool done;
48 int irq;
49 bool irq_enabled;
50 u16 last_value;
51 struct mutex lock;
52 u8 num_channels;
53 void __iomem *reg_base;
54 struct at91_adc_reg_desc *registers;
55 u8 startup_time;
56 struct iio_trigger **trig;
57 struct at91_adc_trigger *trigger_list;
58 u32 trigger_number;
59 bool use_external;
60 u32 vref_mv;
61 wait_queue_head_t wq_data_avail;
62};
63
64static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
65{
66 struct iio_poll_func *pf = p;
67 struct iio_dev *idev = pf->indio_dev;
68 struct at91_adc_state *st = iio_priv(idev);
69 struct iio_buffer *buffer = idev->buffer;
70 int i, j = 0;
71
72 for (i = 0; i < idev->masklength; i++) {
73 if (!test_bit(i, idev->active_scan_mask))
74 continue;
75 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, i));
76 j++;
77 }
78
79 if (idev->scan_timestamp) {
80 s64 *timestamp = (s64 *)((u8 *)st->buffer +
81 ALIGN(j, sizeof(s64)));
82 *timestamp = pf->timestamp;
83 }
84
85 buffer->access->store_to(buffer, (u8 *)st->buffer, pf->timestamp);
86
87 iio_trigger_notify_done(idev->trig);
88 st->irq_enabled = true;
89
90 /* Needed to ACK the DRDY interruption */
91 at91_adc_readl(st, AT91_ADC_LCDR);
92
93 enable_irq(st->irq);
94
95 return IRQ_HANDLED;
96}
97
98static irqreturn_t at91_adc_eoc_trigger(int irq, void *private)
99{
100 struct iio_dev *idev = private;
101 struct at91_adc_state *st = iio_priv(idev);
102 u32 status = at91_adc_readl(st, st->registers->status_register);
103
104 if (!(status & st->registers->drdy_mask))
105 return IRQ_HANDLED;
106
107 if (iio_buffer_enabled(idev)) {
108 disable_irq_nosync(irq);
109 st->irq_enabled = false;
110 iio_trigger_poll(idev->trig, iio_get_time_ns());
111 } else {
112 st->last_value = at91_adc_readl(st, AT91_ADC_LCDR);
113 st->done = true;
114 wake_up_interruptible(&st->wq_data_avail);
115 }
116
117 return IRQ_HANDLED;
118}
119
120static int at91_adc_channel_init(struct iio_dev *idev)
121{
122 struct at91_adc_state *st = iio_priv(idev);
123 struct iio_chan_spec *chan_array, *timestamp;
124 int bit, idx = 0;
125
126 idev->num_channels = bitmap_weight(&st->channels_mask,
127 st->num_channels) + 1;
128
129 chan_array = devm_kzalloc(&idev->dev,
130 ((idev->num_channels + 1) *
131 sizeof(struct iio_chan_spec)),
132 GFP_KERNEL);
133
134 if (!chan_array)
135 return -ENOMEM;
136
137 for_each_set_bit(bit, &st->channels_mask, st->num_channels) {
138 struct iio_chan_spec *chan = chan_array + idx;
139
140 chan->type = IIO_VOLTAGE;
141 chan->indexed = 1;
142 chan->channel = bit;
143 chan->scan_index = idx;
144 chan->scan_type.sign = 'u';
145 chan->scan_type.realbits = 10;
146 chan->scan_type.storagebits = 16;
147 chan->info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT |
148 IIO_CHAN_INFO_RAW_SEPARATE_BIT;
149 idx++;
150 }
151 timestamp = chan_array + idx;
152
153 timestamp->type = IIO_TIMESTAMP;
154 timestamp->channel = -1;
155 timestamp->scan_index = idx;
156 timestamp->scan_type.sign = 's';
157 timestamp->scan_type.realbits = 64;
158 timestamp->scan_type.storagebits = 64;
159
160 idev->channels = chan_array;
161 return idev->num_channels;
162}
163
164static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
165 struct at91_adc_trigger *triggers,
166 const char *trigger_name)
167{
168 struct at91_adc_state *st = iio_priv(idev);
169 u8 value = 0;
170 int i;
171
172 for (i = 0; i < st->trigger_number; i++) {
173 char *name = kasprintf(GFP_KERNEL,
174 "%s-dev%d-%s",
175 idev->name,
176 idev->id,
177 triggers[i].name);
178 if (!name)
179 return -ENOMEM;
180
181 if (strcmp(trigger_name, name) == 0) {
182 value = triggers[i].value;
183 kfree(name);
184 break;
185 }
186
187 kfree(name);
188 }
189
190 return value;
191}
192
193static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
194{
195 struct iio_dev *idev = trig->private_data;
196 struct at91_adc_state *st = iio_priv(idev);
197 struct iio_buffer *buffer = idev->buffer;
198 struct at91_adc_reg_desc *reg = st->registers;
199 u32 status = at91_adc_readl(st, reg->trigger_register);
200 u8 value;
201 u8 bit;
202
203 value = at91_adc_get_trigger_value_by_name(idev,
204 st->trigger_list,
205 idev->trig->name);
206 if (value == 0)
207 return -EINVAL;
208
209 if (state) {
210 st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL);
211 if (st->buffer == NULL)
212 return -ENOMEM;
213
214 at91_adc_writel(st, reg->trigger_register,
215 status | value);
216
217 for_each_set_bit(bit, buffer->scan_mask,
218 st->num_channels) {
219 struct iio_chan_spec const *chan = idev->channels + bit;
220 at91_adc_writel(st, AT91_ADC_CHER,
221 AT91_ADC_CH(chan->channel));
222 }
223
224 at91_adc_writel(st, AT91_ADC_IER, reg->drdy_mask);
225
226 } else {
227 at91_adc_writel(st, AT91_ADC_IDR, reg->drdy_mask);
228
229 at91_adc_writel(st, reg->trigger_register,
230 status & ~value);
231
232 for_each_set_bit(bit, buffer->scan_mask,
233 st->num_channels) {
234 struct iio_chan_spec const *chan = idev->channels + bit;
235 at91_adc_writel(st, AT91_ADC_CHDR,
236 AT91_ADC_CH(chan->channel));
237 }
238 kfree(st->buffer);
239 }
240
241 return 0;
242}
243
244static const struct iio_trigger_ops at91_adc_trigger_ops = {
245 .owner = THIS_MODULE,
246 .set_trigger_state = &at91_adc_configure_trigger,
247};
248
249static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
250 struct at91_adc_trigger *trigger)
251{
252 struct iio_trigger *trig;
253 int ret;
254
255 trig = iio_trigger_alloc("%s-dev%d-%s", idev->name,
256 idev->id, trigger->name);
257 if (trig == NULL)
258 return NULL;
259
260 trig->dev.parent = idev->dev.parent;
261 trig->private_data = idev;
262 trig->ops = &at91_adc_trigger_ops;
263
264 ret = iio_trigger_register(trig);
265 if (ret)
266 return NULL;
267
268 return trig;
269}
270
271static int at91_adc_trigger_init(struct iio_dev *idev)
272{
273 struct at91_adc_state *st = iio_priv(idev);
274 int i, ret;
275
276 st->trig = devm_kzalloc(&idev->dev,
277 st->trigger_number * sizeof(st->trig),
278 GFP_KERNEL);
279
280 if (st->trig == NULL) {
281 ret = -ENOMEM;
282 goto error_ret;
283 }
284
285 for (i = 0; i < st->trigger_number; i++) {
286 if (st->trigger_list[i].is_external && !(st->use_external))
287 continue;
288
289 st->trig[i] = at91_adc_allocate_trigger(idev,
290 st->trigger_list + i);
291 if (st->trig[i] == NULL) {
292 dev_err(&idev->dev,
293 "Could not allocate trigger %d\n", i);
294 ret = -ENOMEM;
295 goto error_trigger;
296 }
297 }
298
299 return 0;
300
301error_trigger:
302 for (i--; i >= 0; i--) {
303 iio_trigger_unregister(st->trig[i]);
304 iio_trigger_free(st->trig[i]);
305 }
306error_ret:
307 return ret;
308}
309
310static void at91_adc_trigger_remove(struct iio_dev *idev)
311{
312 struct at91_adc_state *st = iio_priv(idev);
313 int i;
314
315 for (i = 0; i < st->trigger_number; i++) {
316 iio_trigger_unregister(st->trig[i]);
317 iio_trigger_free(st->trig[i]);
318 }
319}
320
321static const struct iio_buffer_setup_ops at91_adc_buffer_ops = {
322 .preenable = &iio_sw_buffer_preenable,
323 .postenable = &iio_triggered_buffer_postenable,
324 .predisable = &iio_triggered_buffer_predisable,
325};
326
327static int at91_adc_buffer_init(struct iio_dev *idev)
328{
329 int ret;
330
331 idev->buffer = iio_kfifo_allocate(idev);
332 if (!idev->buffer) {
333 ret = -ENOMEM;
334 goto error_ret;
335 }
336
337 idev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
338 &at91_adc_trigger_handler,
339 IRQF_ONESHOT,
340 idev,
341 "%s-consumer%d",
342 idev->name,
343 idev->id);
344 if (idev->pollfunc == NULL) {
345 ret = -ENOMEM;
346 goto error_pollfunc;
347 }
348
349 idev->setup_ops = &at91_adc_buffer_ops;
350 idev->modes |= INDIO_BUFFER_TRIGGERED;
351
352 ret = iio_buffer_register(idev,
353 idev->channels,
354 idev->num_channels);
355 if (ret)
356 goto error_register;
357
358 return 0;
359
360error_register:
361 iio_dealloc_pollfunc(idev->pollfunc);
362error_pollfunc:
363 iio_kfifo_free(idev->buffer);
364error_ret:
365 return ret;
366}
367
368static void at91_adc_buffer_remove(struct iio_dev *idev)
369{
370 iio_buffer_unregister(idev);
371 iio_dealloc_pollfunc(idev->pollfunc);
372 iio_kfifo_free(idev->buffer);
373}
374
375static int at91_adc_read_raw(struct iio_dev *idev,
376 struct iio_chan_spec const *chan,
377 int *val, int *val2, long mask)
378{
379 struct at91_adc_state *st = iio_priv(idev);
380 int ret;
381
382 switch (mask) {
383 case IIO_CHAN_INFO_RAW:
384 mutex_lock(&st->lock);
385
386 at91_adc_writel(st, AT91_ADC_CHER,
387 AT91_ADC_CH(chan->channel));
388 at91_adc_writel(st, AT91_ADC_IER, st->registers->drdy_mask);
389 at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_START);
390
391 ret = wait_event_interruptible_timeout(st->wq_data_avail,
392 st->done,
393 msecs_to_jiffies(1000));
394 if (ret == 0)
395 return -ETIMEDOUT;
396 else if (ret < 0)
397 return ret;
398
399 *val = st->last_value;
400
401 at91_adc_writel(st, AT91_ADC_CHDR,
402 AT91_ADC_CH(chan->channel));
403 at91_adc_writel(st, AT91_ADC_IDR, st->registers->drdy_mask);
404
405 st->last_value = 0;
406 st->done = false;
407 mutex_unlock(&st->lock);
408 return IIO_VAL_INT;
409
410 case IIO_CHAN_INFO_SCALE:
411 *val = (st->vref_mv * 1000) >> chan->scan_type.realbits;
412 *val2 = 0;
413 return IIO_VAL_INT_PLUS_MICRO;
414 default:
415 break;
416 }
417 return -EINVAL;
418}
419
420static int at91_adc_probe_dt(struct at91_adc_state *st,
421 struct platform_device *pdev)
422{
423 struct iio_dev *idev = iio_priv_to_dev(st);
424 struct device_node *node = pdev->dev.of_node;
425 struct device_node *trig_node;
426 int i = 0, ret;
427 u32 prop;
428
429 if (!node)
430 return -EINVAL;
431
432 st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers");
433
434 if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) {
435 dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n");
436 ret = -EINVAL;
437 goto error_ret;
438 }
439 st->channels_mask = prop;
440
441 if (of_property_read_u32(node, "atmel,adc-num-channels", &prop)) {
442 dev_err(&idev->dev, "Missing adc-num-channels property in the DT.\n");
443 ret = -EINVAL;
444 goto error_ret;
445 }
446 st->num_channels = prop;
447
448 if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) {
449 dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n");
450 ret = -EINVAL;
451 goto error_ret;
452 }
453 st->startup_time = prop;
454
455
456 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) {
457 dev_err(&idev->dev, "Missing adc-vref property in the DT.\n");
458 ret = -EINVAL;
459 goto error_ret;
460 }
461 st->vref_mv = prop;
462
463 st->registers = devm_kzalloc(&idev->dev,
464 sizeof(struct at91_adc_reg_desc),
465 GFP_KERNEL);
466 if (!st->registers) {
467 dev_err(&idev->dev, "Could not allocate register memory.\n");
468 ret = -ENOMEM;
469 goto error_ret;
470 }
471
472 if (of_property_read_u32(node, "atmel,adc-channel-base", &prop)) {
473 dev_err(&idev->dev, "Missing adc-channel-base property in the DT.\n");
474 ret = -EINVAL;
475 goto error_ret;
476 }
477 st->registers->channel_base = prop;
478
479 if (of_property_read_u32(node, "atmel,adc-drdy-mask", &prop)) {
480 dev_err(&idev->dev, "Missing adc-drdy-mask property in the DT.\n");
481 ret = -EINVAL;
482 goto error_ret;
483 }
484 st->registers->drdy_mask = prop;
485
486 if (of_property_read_u32(node, "atmel,adc-status-register", &prop)) {
487 dev_err(&idev->dev, "Missing adc-status-register property in the DT.\n");
488 ret = -EINVAL;
489 goto error_ret;
490 }
491 st->registers->status_register = prop;
492
493 if (of_property_read_u32(node, "atmel,adc-trigger-register", &prop)) {
494 dev_err(&idev->dev, "Missing adc-trigger-register property in the DT.\n");
495 ret = -EINVAL;
496 goto error_ret;
497 }
498 st->registers->trigger_register = prop;
499
500 st->trigger_number = of_get_child_count(node);
501 st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number *
502 sizeof(struct at91_adc_trigger),
503 GFP_KERNEL);
504 if (!st->trigger_list) {
505 dev_err(&idev->dev, "Could not allocate trigger list memory.\n");
506 ret = -ENOMEM;
507 goto error_ret;
508 }
509
510 for_each_child_of_node(node, trig_node) {
511 struct at91_adc_trigger *trig = st->trigger_list + i;
512 const char *name;
513
514 if (of_property_read_string(trig_node, "trigger-name", &name)) {
515 dev_err(&idev->dev, "Missing trigger-name property in the DT.\n");
516 ret = -EINVAL;
517 goto error_ret;
518 }
519 trig->name = name;
520
521 if (of_property_read_u32(trig_node, "trigger-value", &prop)) {
522 dev_err(&idev->dev, "Missing trigger-value property in the DT.\n");
523 ret = -EINVAL;
524 goto error_ret;
525 }
526 trig->value = prop;
527 trig->is_external = of_property_read_bool(trig_node, "trigger-external");
528 i++;
529 }
530
531 return 0;
532
533error_ret:
534 return ret;
535}
536
537static int at91_adc_probe_pdata(struct at91_adc_state *st,
538 struct platform_device *pdev)
539{
540 struct at91_adc_data *pdata = pdev->dev.platform_data;
541
542 if (!pdata)
543 return -EINVAL;
544
545 st->use_external = pdata->use_external_triggers;
546 st->vref_mv = pdata->vref;
547 st->channels_mask = pdata->channels_used;
548 st->num_channels = pdata->num_channels;
549 st->startup_time = pdata->startup_time;
550 st->trigger_number = pdata->trigger_number;
551 st->trigger_list = pdata->trigger_list;
552 st->registers = pdata->registers;
553
554 return 0;
555}
556
557static const struct iio_info at91_adc_info = {
558 .driver_module = THIS_MODULE,
559 .read_raw = &at91_adc_read_raw,
560};
561
562static int __devinit at91_adc_probe(struct platform_device *pdev)
563{
564 unsigned int prsc, mstrclk, ticks, adc_clk;
565 int ret;
566 struct iio_dev *idev;
567 struct at91_adc_state *st;
568 struct resource *res;
569
570 idev = iio_device_alloc(sizeof(struct at91_adc_state));
571 if (idev == NULL) {
572 ret = -ENOMEM;
573 goto error_ret;
574 }
575
576 st = iio_priv(idev);
577
578 if (pdev->dev.of_node)
579 ret = at91_adc_probe_dt(st, pdev);
580 else
581 ret = at91_adc_probe_pdata(st, pdev);
582
583 if (ret) {
584 dev_err(&pdev->dev, "No platform data available.\n");
585 ret = -EINVAL;
586 goto error_free_device;
587 }
588
589 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
590 if (!res) {
591 dev_err(&pdev->dev, "No resource defined\n");
592 ret = -ENXIO;
593 goto error_ret;
594 }
595
596 platform_set_drvdata(pdev, idev);
597
598 idev->dev.parent = &pdev->dev;
599 idev->name = dev_name(&pdev->dev);
600 idev->modes = INDIO_DIRECT_MODE;
601 idev->info = &at91_adc_info;
602
603 st->irq = platform_get_irq(pdev, 0);
604 if (st->irq < 0) {
605 dev_err(&pdev->dev, "No IRQ ID is designated\n");
606 ret = -ENODEV;
607 goto error_free_device;
608 }
609
610 if (!request_mem_region(res->start, resource_size(res),
611 "AT91 adc registers")) {
612 dev_err(&pdev->dev, "Resources are unavailable.\n");
613 ret = -EBUSY;
614 goto error_free_device;
615 }
616
617 st->reg_base = ioremap(res->start, resource_size(res));
618 if (!st->reg_base) {
619 dev_err(&pdev->dev, "Failed to map registers.\n");
620 ret = -ENOMEM;
621 goto error_release_mem;
622 }
623
624 /*
625 * Disable all IRQs before setting up the handler
626 */
627 at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_SWRST);
628 at91_adc_writel(st, AT91_ADC_IDR, 0xFFFFFFFF);
629 ret = request_irq(st->irq,
630 at91_adc_eoc_trigger,
631 0,
632 pdev->dev.driver->name,
633 idev);
634 if (ret) {
635 dev_err(&pdev->dev, "Failed to allocate IRQ.\n");
636 goto error_unmap_reg;
637 }
638
639 st->clk = clk_get(&pdev->dev, "adc_clk");
640 if (IS_ERR(st->clk)) {
641 dev_err(&pdev->dev, "Failed to get the clock.\n");
642 ret = PTR_ERR(st->clk);
643 goto error_free_irq;
644 }
645
646 ret = clk_prepare(st->clk);
647 if (ret) {
648 dev_err(&pdev->dev, "Could not prepare the clock.\n");
649 goto error_free_clk;
650 }
651
652 ret = clk_enable(st->clk);
653 if (ret) {
654 dev_err(&pdev->dev, "Could not enable the clock.\n");
655 goto error_unprepare_clk;
656 }
657
658 st->adc_clk = clk_get(&pdev->dev, "adc_op_clk");
659 if (IS_ERR(st->adc_clk)) {
660 dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
661 ret = PTR_ERR(st->clk);
662 goto error_disable_clk;
663 }
664
665 ret = clk_prepare(st->adc_clk);
666 if (ret) {
667 dev_err(&pdev->dev, "Could not prepare the ADC clock.\n");
668 goto error_free_adc_clk;
669 }
670
671 ret = clk_enable(st->adc_clk);
672 if (ret) {
673 dev_err(&pdev->dev, "Could not enable the ADC clock.\n");
674 goto error_unprepare_adc_clk;
675 }
676
677 /*
678 * Prescaler rate computation using the formula from the Atmel's
679 * datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being
680 * specified by the electrical characteristics of the board.
681 */
682 mstrclk = clk_get_rate(st->clk);
683 adc_clk = clk_get_rate(st->adc_clk);
684 prsc = (mstrclk / (2 * adc_clk)) - 1;
685
686 if (!st->startup_time) {
687 dev_err(&pdev->dev, "No startup time available.\n");
688 ret = -EINVAL;
689 goto error_disable_adc_clk;
690 }
691
692 /*
693 * Number of ticks needed to cover the startup time of the ADC as
694 * defined in the electrical characteristics of the board, divided by 8.
695 * The formula thus is : Startup Time = (ticks + 1) * 8 / ADC Clock
696 */
697 ticks = round_up((st->startup_time * adc_clk /
698 1000000) - 1, 8) / 8;
699 at91_adc_writel(st, AT91_ADC_MR,
700 (AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL) |
701 (AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP));
702
703 /* Setup the ADC channels available on the board */
704 ret = at91_adc_channel_init(idev);
705 if (ret < 0) {
706 dev_err(&pdev->dev, "Couldn't initialize the channels.\n");
707 goto error_disable_adc_clk;
708 }
709
710 init_waitqueue_head(&st->wq_data_avail);
711 mutex_init(&st->lock);
712
713 ret = at91_adc_buffer_init(idev);
714 if (ret < 0) {
715 dev_err(&pdev->dev, "Couldn't initialize the buffer.\n");
716 goto error_disable_adc_clk;
717 }
718
719 ret = at91_adc_trigger_init(idev);
720 if (ret < 0) {
721 dev_err(&pdev->dev, "Couldn't setup the triggers.\n");
722 goto error_unregister_buffer;
723 }
724
725 ret = iio_device_register(idev);
726 if (ret < 0) {
727 dev_err(&pdev->dev, "Couldn't register the device.\n");
728 goto error_remove_triggers;
729 }
730
731 return 0;
732
733error_remove_triggers:
734 at91_adc_trigger_remove(idev);
735error_unregister_buffer:
736 at91_adc_buffer_remove(idev);
737error_disable_adc_clk:
738 clk_disable(st->adc_clk);
739error_unprepare_adc_clk:
740 clk_unprepare(st->adc_clk);
741error_free_adc_clk:
742 clk_put(st->adc_clk);
743error_disable_clk:
744 clk_disable(st->clk);
745error_unprepare_clk:
746 clk_unprepare(st->clk);
747error_free_clk:
748 clk_put(st->clk);
749error_free_irq:
750 free_irq(st->irq, idev);
751error_unmap_reg:
752 iounmap(st->reg_base);
753error_release_mem:
754 release_mem_region(res->start, resource_size(res));
755error_free_device:
756 iio_device_free(idev);
757error_ret:
758 return ret;
759}
760
761static int __devexit at91_adc_remove(struct platform_device *pdev)
762{
763 struct iio_dev *idev = platform_get_drvdata(pdev);
764 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
765 struct at91_adc_state *st = iio_priv(idev);
766
767 iio_device_unregister(idev);
768 at91_adc_trigger_remove(idev);
769 at91_adc_buffer_remove(idev);
770 clk_disable_unprepare(st->adc_clk);
771 clk_put(st->adc_clk);
772 clk_disable(st->clk);
773 clk_unprepare(st->clk);
774 clk_put(st->clk);
775 free_irq(st->irq, idev);
776 iounmap(st->reg_base);
777 release_mem_region(res->start, resource_size(res));
778 iio_device_free(idev);
779
780 return 0;
781}
782
783static const struct of_device_id at91_adc_dt_ids[] = {
784 { .compatible = "atmel,at91sam9260-adc" },
785 {},
786};
787MODULE_DEVICE_TABLE(of, at91_adc_dt_ids);
788
789static struct platform_driver at91_adc_driver = {
790 .probe = at91_adc_probe,
791 .remove = __devexit_p(at91_adc_remove),
792 .driver = {
793 .name = "at91_adc",
794 .of_match_table = of_match_ptr(at91_adc_dt_ids),
795 },
796};
797
798module_platform_driver(at91_adc_driver);
799
800MODULE_LICENSE("GPL");
801MODULE_DESCRIPTION("Atmel AT91 ADC Driver");
802MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig
new file mode 100644
index 000000000000..05d707ed7d4f
--- /dev/null
+++ b/drivers/iio/amplifiers/Kconfig
@@ -0,0 +1,17 @@
1#
2# Gain Amplifiers, etc.
3#
4menu "Amplifiers"
5
6config AD8366
7 tristate "Analog Devices AD8366 VGA"
8 depends on SPI
9 select BITREVERSE
10 help
11 Say yes here to build support for Analog Devices AD8366
12 SPI Dual-Digital Variable Gain Amplifier (VGA).
13
14 To compile this driver as a module, choose M here: the
15 module will be called ad8366.
16
17endmenu
diff --git a/drivers/iio/amplifiers/Makefile b/drivers/iio/amplifiers/Makefile
new file mode 100644
index 000000000000..a6ca366908e0
--- /dev/null
+++ b/drivers/iio/amplifiers/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile iio/amplifiers
3#
4
5obj-$(CONFIG_AD8366) += ad8366.o
diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
new file mode 100644
index 000000000000..d8281cdbfc4a
--- /dev/null
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -0,0 +1,222 @@
1/*
2 * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA)
3 *
4 * Copyright 2012 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/device.h>
10#include <linux/kernel.h>
11#include <linux/slab.h>
12#include <linux/sysfs.h>
13#include <linux/spi/spi.h>
14#include <linux/regulator/consumer.h>
15#include <linux/err.h>
16#include <linux/module.h>
17#include <linux/bitrev.h>
18
19#include <linux/iio/iio.h>
20#include <linux/iio/sysfs.h>
21
22struct ad8366_state {
23 struct spi_device *spi;
24 struct regulator *reg;
25 unsigned char ch[2];
26 /*
27 * DMA (thus cache coherency maintenance) requires the
28 * transfer buffers to live in their own cache lines.
29 */
30 unsigned char data[2] ____cacheline_aligned;
31};
32
33static int ad8366_write(struct iio_dev *indio_dev,
34 unsigned char ch_a, char unsigned ch_b)
35{
36 struct ad8366_state *st = iio_priv(indio_dev);
37 int ret;
38
39 ch_a = bitrev8(ch_a & 0x3F);
40 ch_b = bitrev8(ch_b & 0x3F);
41
42 st->data[0] = ch_b >> 4;
43 st->data[1] = (ch_b << 4) | (ch_a >> 2);
44
45 ret = spi_write(st->spi, st->data, ARRAY_SIZE(st->data));
46 if (ret < 0)
47 dev_err(&indio_dev->dev, "write failed (%d)", ret);
48
49 return ret;
50}
51
52static int ad8366_read_raw(struct iio_dev *indio_dev,
53 struct iio_chan_spec const *chan,
54 int *val,
55 int *val2,
56 long m)
57{
58 struct ad8366_state *st = iio_priv(indio_dev);
59 int ret;
60 unsigned code;
61
62 mutex_lock(&indio_dev->mlock);
63 switch (m) {
64 case IIO_CHAN_INFO_HARDWAREGAIN:
65 code = st->ch[chan->channel];
66
67 /* Values in dB */
68 code = code * 253 + 4500;
69 *val = code / 1000;
70 *val2 = (code % 1000) * 1000;
71
72 ret = IIO_VAL_INT_PLUS_MICRO_DB;
73 break;
74 default:
75 ret = -EINVAL;
76 }
77 mutex_unlock(&indio_dev->mlock);
78
79 return ret;
80};
81
82static int ad8366_write_raw(struct iio_dev *indio_dev,
83 struct iio_chan_spec const *chan,
84 int val,
85 int val2,
86 long mask)
87{
88 struct ad8366_state *st = iio_priv(indio_dev);
89 unsigned code;
90 int ret;
91
92 if (val < 0 || val2 < 0)
93 return -EINVAL;
94
95 /* Values in dB */
96 code = (((u8)val * 1000) + ((u32)val2 / 1000));
97
98 if (code > 20500 || code < 4500)
99 return -EINVAL;
100
101 code = (code - 4500) / 253;
102
103 mutex_lock(&indio_dev->mlock);
104 switch (mask) {
105 case IIO_CHAN_INFO_HARDWAREGAIN:
106 st->ch[chan->channel] = code;
107 ret = ad8366_write(indio_dev, st->ch[0], st->ch[1]);
108 break;
109 default:
110 ret = -EINVAL;
111 }
112 mutex_unlock(&indio_dev->mlock);
113
114 return ret;
115}
116
117static const struct iio_info ad8366_info = {
118 .read_raw = &ad8366_read_raw,
119 .write_raw = &ad8366_write_raw,
120 .driver_module = THIS_MODULE,
121};
122
123#define AD8366_CHAN(_channel) { \
124 .type = IIO_VOLTAGE, \
125 .output = 1, \
126 .indexed = 1, \
127 .channel = _channel, \
128 .info_mask = IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT,\
129}
130
131static const struct iio_chan_spec ad8366_channels[] = {
132 AD8366_CHAN(0),
133 AD8366_CHAN(1),
134};
135
136static int __devinit ad8366_probe(struct spi_device *spi)
137{
138 struct iio_dev *indio_dev;
139 struct ad8366_state *st;
140 int ret;
141
142 indio_dev = iio_device_alloc(sizeof(*st));
143 if (indio_dev == NULL)
144 return -ENOMEM;
145
146 st = iio_priv(indio_dev);
147
148 st->reg = regulator_get(&spi->dev, "vcc");
149 if (!IS_ERR(st->reg)) {
150 ret = regulator_enable(st->reg);
151 if (ret)
152 goto error_put_reg;
153 }
154
155 spi_set_drvdata(spi, indio_dev);
156 st->spi = spi;
157
158 indio_dev->dev.parent = &spi->dev;
159 indio_dev->name = spi_get_device_id(spi)->name;
160 indio_dev->info = &ad8366_info;
161 indio_dev->modes = INDIO_DIRECT_MODE;
162 indio_dev->channels = ad8366_channels;
163 indio_dev->num_channels = ARRAY_SIZE(ad8366_channels);
164
165 ret = iio_device_register(indio_dev);
166 if (ret)
167 goto error_disable_reg;
168
169 ad8366_write(indio_dev, 0 , 0);
170
171 return 0;
172
173error_disable_reg:
174 if (!IS_ERR(st->reg))
175 regulator_disable(st->reg);
176error_put_reg:
177 if (!IS_ERR(st->reg))
178 regulator_put(st->reg);
179
180 iio_device_free(indio_dev);
181
182 return ret;
183}
184
185static int __devexit ad8366_remove(struct spi_device *spi)
186{
187 struct iio_dev *indio_dev = spi_get_drvdata(spi);
188 struct ad8366_state *st = iio_priv(indio_dev);
189 struct regulator *reg = st->reg;
190
191 iio_device_unregister(indio_dev);
192
193 if (!IS_ERR(reg)) {
194 regulator_disable(reg);
195 regulator_put(reg);
196 }
197
198 iio_device_free(indio_dev);
199
200 return 0;
201}
202
203static const struct spi_device_id ad8366_id[] = {
204 {"ad8366", 0},
205 {}
206};
207
208static struct spi_driver ad8366_driver = {
209 .driver = {
210 .name = KBUILD_MODNAME,
211 .owner = THIS_MODULE,
212 },
213 .probe = ad8366_probe,
214 .remove = __devexit_p(ad8366_remove),
215 .id_table = ad8366_id,
216};
217
218module_spi_driver(ad8366_driver);
219
220MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
221MODULE_DESCRIPTION("Analog Devices AD8366 VGA");
222MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/iio_core.h b/drivers/iio/iio_core.h
index c9dfcba0bac8..f652e6ae5a35 100644
--- a/drivers/staging/iio/iio_core.h
+++ b/drivers/iio/iio_core.h
@@ -12,6 +12,12 @@
12 12
13#ifndef _IIO_CORE_H_ 13#ifndef _IIO_CORE_H_
14#define _IIO_CORE_H_ 14#define _IIO_CORE_H_
15#include <linux/kernel.h>
16#include <linux/device.h>
17
18struct iio_chan_spec;
19struct iio_dev;
20
15 21
16int __iio_add_chan_devattr(const char *postfix, 22int __iio_add_chan_devattr(const char *postfix,
17 struct iio_chan_spec const *chan, 23 struct iio_chan_spec const *chan,
diff --git a/drivers/staging/iio/iio_core_trigger.h b/drivers/iio/iio_core_trigger.h
index 6f7c56fcbe78..6f7c56fcbe78 100644
--- a/drivers/staging/iio/iio_core_trigger.h
+++ b/drivers/iio/iio_core_trigger.h
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 386ba760f3f1..ac185b8694bd 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -21,10 +21,10 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/poll.h> 22#include <linux/poll.h>
23 23
24#include "iio.h" 24#include <linux/iio/iio.h>
25#include "iio_core.h" 25#include "iio_core.h"
26#include "sysfs.h" 26#include <linux/iio/sysfs.h>
27#include "buffer.h" 27#include <linux/iio/buffer.h>
28 28
29static const char * const iio_endian_prefix[] = { 29static const char * const iio_endian_prefix[] = {
30 [IIO_BE] = "be", 30 [IIO_BE] = "be",
@@ -105,7 +105,7 @@ static ssize_t iio_scan_el_show(struct device *dev,
105 char *buf) 105 char *buf)
106{ 106{
107 int ret; 107 int ret;
108 struct iio_dev *indio_dev = dev_get_drvdata(dev); 108 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
109 109
110 ret = test_bit(to_iio_dev_attr(attr)->address, 110 ret = test_bit(to_iio_dev_attr(attr)->address,
111 indio_dev->buffer->scan_mask); 111 indio_dev->buffer->scan_mask);
@@ -124,13 +124,15 @@ static ssize_t iio_scan_el_store(struct device *dev,
124 const char *buf, 124 const char *buf,
125 size_t len) 125 size_t len)
126{ 126{
127 int ret = 0; 127 int ret;
128 bool state; 128 bool state;
129 struct iio_dev *indio_dev = dev_get_drvdata(dev); 129 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
130 struct iio_buffer *buffer = indio_dev->buffer; 130 struct iio_buffer *buffer = indio_dev->buffer;
131 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 131 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
132 132
133 state = !(buf[0] == '0'); 133 ret = strtobool(buf, &state);
134 if (ret < 0)
135 return ret;
134 mutex_lock(&indio_dev->mlock); 136 mutex_lock(&indio_dev->mlock);
135 if (iio_buffer_enabled(indio_dev)) { 137 if (iio_buffer_enabled(indio_dev)) {
136 ret = -EBUSY; 138 ret = -EBUSY;
@@ -160,7 +162,7 @@ static ssize_t iio_scan_el_ts_show(struct device *dev,
160 struct device_attribute *attr, 162 struct device_attribute *attr,
161 char *buf) 163 char *buf)
162{ 164{
163 struct iio_dev *indio_dev = dev_get_drvdata(dev); 165 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
164 return sprintf(buf, "%d\n", indio_dev->buffer->scan_timestamp); 166 return sprintf(buf, "%d\n", indio_dev->buffer->scan_timestamp);
165} 167}
166 168
@@ -169,17 +171,21 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
169 const char *buf, 171 const char *buf,
170 size_t len) 172 size_t len)
171{ 173{
172 int ret = 0; 174 int ret;
173 struct iio_dev *indio_dev = dev_get_drvdata(dev); 175 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
174 bool state; 176 bool state;
175 177
176 state = !(buf[0] == '0'); 178 ret = strtobool(buf, &state);
179 if (ret < 0)
180 return ret;
181
177 mutex_lock(&indio_dev->mlock); 182 mutex_lock(&indio_dev->mlock);
178 if (iio_buffer_enabled(indio_dev)) { 183 if (iio_buffer_enabled(indio_dev)) {
179 ret = -EBUSY; 184 ret = -EBUSY;
180 goto error_ret; 185 goto error_ret;
181 } 186 }
182 indio_dev->buffer->scan_timestamp = state; 187 indio_dev->buffer->scan_timestamp = state;
188 indio_dev->scan_timestamp = state;
183error_ret: 189error_ret:
184 mutex_unlock(&indio_dev->mlock); 190 mutex_unlock(&indio_dev->mlock);
185 191
@@ -291,7 +297,7 @@ int iio_buffer_register(struct iio_dev *indio_dev,
291 goto error_cleanup_dynamic; 297 goto error_cleanup_dynamic;
292 attrcount += ret; 298 attrcount += ret;
293 if (channels[i].type == IIO_TIMESTAMP) 299 if (channels[i].type == IIO_TIMESTAMP)
294 buffer->scan_index_timestamp = 300 indio_dev->scan_index_timestamp =
295 channels[i].scan_index; 301 channels[i].scan_index;
296 } 302 }
297 if (indio_dev->masklength && buffer->scan_mask == NULL) { 303 if (indio_dev->masklength && buffer->scan_mask == NULL) {
@@ -346,7 +352,7 @@ ssize_t iio_buffer_read_length(struct device *dev,
346 struct device_attribute *attr, 352 struct device_attribute *attr,
347 char *buf) 353 char *buf)
348{ 354{
349 struct iio_dev *indio_dev = dev_get_drvdata(dev); 355 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
350 struct iio_buffer *buffer = indio_dev->buffer; 356 struct iio_buffer *buffer = indio_dev->buffer;
351 357
352 if (buffer->access->get_length) 358 if (buffer->access->get_length)
@@ -364,7 +370,7 @@ ssize_t iio_buffer_write_length(struct device *dev,
364{ 370{
365 int ret; 371 int ret;
366 ulong val; 372 ulong val;
367 struct iio_dev *indio_dev = dev_get_drvdata(dev); 373 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
368 struct iio_buffer *buffer = indio_dev->buffer; 374 struct iio_buffer *buffer = indio_dev->buffer;
369 375
370 ret = strict_strtoul(buf, 10, &val); 376 ret = strict_strtoul(buf, 10, &val);
@@ -397,7 +403,7 @@ ssize_t iio_buffer_store_enable(struct device *dev,
397 int ret; 403 int ret;
398 bool requested_state, current_state; 404 bool requested_state, current_state;
399 int previous_mode; 405 int previous_mode;
400 struct iio_dev *indio_dev = dev_get_drvdata(dev); 406 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
401 struct iio_buffer *buffer = indio_dev->buffer; 407 struct iio_buffer *buffer = indio_dev->buffer;
402 408
403 mutex_lock(&indio_dev->mlock); 409 mutex_lock(&indio_dev->mlock);
@@ -483,7 +489,7 @@ ssize_t iio_buffer_show_enable(struct device *dev,
483 struct device_attribute *attr, 489 struct device_attribute *attr,
484 char *buf) 490 char *buf)
485{ 491{
486 struct iio_dev *indio_dev = dev_get_drvdata(dev); 492 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
487 return sprintf(buf, "%d\n", iio_buffer_enabled(indio_dev)); 493 return sprintf(buf, "%d\n", iio_buffer_enabled(indio_dev));
488} 494}
489EXPORT_SYMBOL(iio_buffer_show_enable); 495EXPORT_SYMBOL(iio_buffer_show_enable);
@@ -503,30 +509,41 @@ static const unsigned long *iio_scan_mask_match(const unsigned long *av_masks,
503 return NULL; 509 return NULL;
504} 510}
505 511
506int iio_sw_buffer_preenable(struct iio_dev *indio_dev) 512static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
513 bool timestamp)
507{ 514{
508 struct iio_buffer *buffer = indio_dev->buffer;
509 const struct iio_chan_spec *ch; 515 const struct iio_chan_spec *ch;
510 unsigned bytes = 0; 516 unsigned bytes = 0;
511 int length, i; 517 int length, i;
512 dev_dbg(&indio_dev->dev, "%s\n", __func__);
513 518
514 /* How much space will the demuxed element take? */ 519 /* How much space will the demuxed element take? */
515 for_each_set_bit(i, buffer->scan_mask, 520 for_each_set_bit(i, mask,
516 indio_dev->masklength) { 521 indio_dev->masklength) {
517 ch = iio_find_channel_from_si(indio_dev, i); 522 ch = iio_find_channel_from_si(indio_dev, i);
518 length = ch->scan_type.storagebits/8; 523 length = ch->scan_type.storagebits / 8;
519 bytes = ALIGN(bytes, length); 524 bytes = ALIGN(bytes, length);
520 bytes += length; 525 bytes += length;
521 } 526 }
522 if (buffer->scan_timestamp) { 527 if (timestamp) {
523 ch = iio_find_channel_from_si(indio_dev, 528 ch = iio_find_channel_from_si(indio_dev,
524 buffer->scan_index_timestamp); 529 indio_dev->scan_index_timestamp);
525 length = ch->scan_type.storagebits/8; 530 length = ch->scan_type.storagebits / 8;
526 bytes = ALIGN(bytes, length); 531 bytes = ALIGN(bytes, length);
527 bytes += length; 532 bytes += length;
528 } 533 }
529 buffer->access->set_bytes_per_datum(buffer, bytes); 534 return bytes;
535}
536
537int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
538{
539 struct iio_buffer *buffer = indio_dev->buffer;
540 dev_dbg(&indio_dev->dev, "%s\n", __func__);
541
542 /* How much space will the demuxed element take? */
543 indio_dev->scan_bytes =
544 iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
545 buffer->scan_timestamp);
546 buffer->access->set_bytes_per_datum(buffer, indio_dev->scan_bytes);
530 547
531 /* What scan mask do we actually have ?*/ 548 /* What scan mask do we actually have ?*/
532 if (indio_dev->available_scan_masks) 549 if (indio_dev->available_scan_masks)
@@ -638,19 +655,25 @@ int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data,
638} 655}
639EXPORT_SYMBOL_GPL(iio_push_to_buffer); 656EXPORT_SYMBOL_GPL(iio_push_to_buffer);
640 657
658static void iio_buffer_demux_free(struct iio_buffer *buffer)
659{
660 struct iio_demux_table *p, *q;
661 list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
662 list_del(&p->l);
663 kfree(p);
664 }
665}
666
641int iio_update_demux(struct iio_dev *indio_dev) 667int iio_update_demux(struct iio_dev *indio_dev)
642{ 668{
643 const struct iio_chan_spec *ch; 669 const struct iio_chan_spec *ch;
644 struct iio_buffer *buffer = indio_dev->buffer; 670 struct iio_buffer *buffer = indio_dev->buffer;
645 int ret, in_ind = -1, out_ind, length; 671 int ret, in_ind = -1, out_ind, length;
646 unsigned in_loc = 0, out_loc = 0; 672 unsigned in_loc = 0, out_loc = 0;
647 struct iio_demux_table *p, *q; 673 struct iio_demux_table *p;
648 674
649 /* Clear out any old demux */ 675 /* Clear out any old demux */
650 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 676 iio_buffer_demux_free(buffer);
651 list_del(&p->l);
652 kfree(p);
653 }
654 kfree(buffer->demux_bounce); 677 kfree(buffer->demux_bounce);
655 buffer->demux_bounce = NULL; 678 buffer->demux_bounce = NULL;
656 679
@@ -704,7 +727,7 @@ int iio_update_demux(struct iio_dev *indio_dev)
704 goto error_clear_mux_table; 727 goto error_clear_mux_table;
705 } 728 }
706 ch = iio_find_channel_from_si(indio_dev, 729 ch = iio_find_channel_from_si(indio_dev,
707 buffer->scan_index_timestamp); 730 indio_dev->scan_index_timestamp);
708 length = ch->scan_type.storagebits/8; 731 length = ch->scan_type.storagebits/8;
709 if (out_loc % length) 732 if (out_loc % length)
710 out_loc += length - out_loc % length; 733 out_loc += length - out_loc % length;
@@ -725,10 +748,8 @@ int iio_update_demux(struct iio_dev *indio_dev)
725 return 0; 748 return 0;
726 749
727error_clear_mux_table: 750error_clear_mux_table:
728 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 751 iio_buffer_demux_free(buffer);
729 list_del(&p->l); 752
730 kfree(p);
731 }
732 return ret; 753 return ret;
733} 754}
734EXPORT_SYMBOL_GPL(iio_update_demux); 755EXPORT_SYMBOL_GPL(iio_update_demux);
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d303bfbff27f..1ddd8861c71b 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -23,11 +23,11 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/anon_inodes.h> 24#include <linux/anon_inodes.h>
25#include <linux/debugfs.h> 25#include <linux/debugfs.h>
26#include "iio.h" 26#include <linux/iio/iio.h>
27#include "iio_core.h" 27#include "iio_core.h"
28#include "iio_core_trigger.h" 28#include "iio_core_trigger.h"
29#include "sysfs.h" 29#include <linux/iio/sysfs.h>
30#include "events.h" 30#include <linux/iio/events.h>
31 31
32/* IDA to assign each registered device a unique id*/ 32/* IDA to assign each registered device a unique id*/
33static DEFINE_IDA(iio_ida); 33static DEFINE_IDA(iio_ida);
@@ -42,11 +42,6 @@ EXPORT_SYMBOL(iio_bus_type);
42 42
43static struct dentry *iio_debugfs_dentry; 43static struct dentry *iio_debugfs_dentry;
44 44
45static const char * const iio_data_type_name[] = {
46 [IIO_RAW] = "raw",
47 [IIO_PROCESSED] = "input",
48};
49
50static const char * const iio_direction[] = { 45static const char * const iio_direction[] = {
51 [0] = "in", 46 [0] = "in",
52 [1] = "out", 47 [1] = "out",
@@ -68,6 +63,7 @@ static const char * const iio_chan_type_name_spec[] = {
68 [IIO_ANGL] = "angl", 63 [IIO_ANGL] = "angl",
69 [IIO_TIMESTAMP] = "timestamp", 64 [IIO_TIMESTAMP] = "timestamp",
70 [IIO_CAPACITANCE] = "capacitance", 65 [IIO_CAPACITANCE] = "capacitance",
66 [IIO_ALTVOLTAGE] = "altvoltage",
71}; 67};
72 68
73static const char * const iio_modifier_names[] = { 69static const char * const iio_modifier_names[] = {
@@ -80,6 +76,8 @@ static const char * const iio_modifier_names[] = {
80 76
81/* relies on pairs of these shared then separate */ 77/* relies on pairs of these shared then separate */
82static const char * const iio_chan_info_postfix[] = { 78static const char * const iio_chan_info_postfix[] = {
79 [IIO_CHAN_INFO_RAW] = "raw",
80 [IIO_CHAN_INFO_PROCESSED] = "input",
83 [IIO_CHAN_INFO_SCALE] = "scale", 81 [IIO_CHAN_INFO_SCALE] = "scale",
84 [IIO_CHAN_INFO_OFFSET] = "offset", 82 [IIO_CHAN_INFO_OFFSET] = "offset",
85 [IIO_CHAN_INFO_CALIBSCALE] = "calibscale", 83 [IIO_CHAN_INFO_CALIBSCALE] = "calibscale",
@@ -90,6 +88,10 @@ static const char * const iio_chan_info_postfix[] = {
90 [IIO_CHAN_INFO_AVERAGE_RAW] = "mean_raw", 88 [IIO_CHAN_INFO_AVERAGE_RAW] = "mean_raw",
91 [IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY] 89 [IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY]
92 = "filter_low_pass_3db_frequency", 90 = "filter_low_pass_3db_frequency",
91 [IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
92 [IIO_CHAN_INFO_FREQUENCY] = "frequency",
93 [IIO_CHAN_INFO_PHASE] = "phase",
94 [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
93}; 95};
94 96
95const struct iio_chan_spec 97const struct iio_chan_spec
@@ -151,14 +153,6 @@ static void __exit iio_exit(void)
151} 153}
152 154
153#if defined(CONFIG_DEBUG_FS) 155#if defined(CONFIG_DEBUG_FS)
154static int iio_debugfs_open(struct inode *inode, struct file *file)
155{
156 if (inode->i_private)
157 file->private_data = inode->i_private;
158
159 return 0;
160}
161
162static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, 156static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
163 size_t count, loff_t *ppos) 157 size_t count, loff_t *ppos)
164{ 158{
@@ -217,7 +211,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
217} 211}
218 212
219static const struct file_operations iio_debugfs_reg_fops = { 213static const struct file_operations iio_debugfs_reg_fops = {
220 .open = iio_debugfs_open, 214 .open = simple_open,
221 .read = iio_debugfs_read_reg, 215 .read = iio_debugfs_read_reg,
222 .write = iio_debugfs_write_reg, 216 .write = iio_debugfs_write_reg,
223}; 217};
@@ -234,15 +228,12 @@ static int iio_device_register_debugfs(struct iio_dev *indio_dev)
234 if (indio_dev->info->debugfs_reg_access == NULL) 228 if (indio_dev->info->debugfs_reg_access == NULL)
235 return 0; 229 return 0;
236 230
237 if (IS_ERR(iio_debugfs_dentry)) 231 if (!iio_debugfs_dentry)
238 return 0; 232 return 0;
239 233
240 indio_dev->debugfs_dentry = 234 indio_dev->debugfs_dentry =
241 debugfs_create_dir(dev_name(&indio_dev->dev), 235 debugfs_create_dir(dev_name(&indio_dev->dev),
242 iio_debugfs_dentry); 236 iio_debugfs_dentry);
243 if (IS_ERR(indio_dev->debugfs_dentry))
244 return PTR_ERR(indio_dev->debugfs_dentry);
245
246 if (indio_dev->debugfs_dentry == NULL) { 237 if (indio_dev->debugfs_dentry == NULL) {
247 dev_warn(indio_dev->dev.parent, 238 dev_warn(indio_dev->dev.parent,
248 "Failed to create debugfs directory\n"); 239 "Failed to create debugfs directory\n");
@@ -274,13 +265,13 @@ static ssize_t iio_read_channel_ext_info(struct device *dev,
274 struct device_attribute *attr, 265 struct device_attribute *attr,
275 char *buf) 266 char *buf)
276{ 267{
277 struct iio_dev *indio_dev = dev_get_drvdata(dev); 268 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
278 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 269 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
279 const struct iio_chan_spec_ext_info *ext_info; 270 const struct iio_chan_spec_ext_info *ext_info;
280 271
281 ext_info = &this_attr->c->ext_info[this_attr->address]; 272 ext_info = &this_attr->c->ext_info[this_attr->address];
282 273
283 return ext_info->read(indio_dev, this_attr->c, buf); 274 return ext_info->read(indio_dev, ext_info->private, this_attr->c, buf);
284} 275}
285 276
286static ssize_t iio_write_channel_ext_info(struct device *dev, 277static ssize_t iio_write_channel_ext_info(struct device *dev,
@@ -288,42 +279,50 @@ static ssize_t iio_write_channel_ext_info(struct device *dev,
288 const char *buf, 279 const char *buf,
289 size_t len) 280 size_t len)
290{ 281{
291 struct iio_dev *indio_dev = dev_get_drvdata(dev); 282 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
292 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 283 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
293 const struct iio_chan_spec_ext_info *ext_info; 284 const struct iio_chan_spec_ext_info *ext_info;
294 285
295 ext_info = &this_attr->c->ext_info[this_attr->address]; 286 ext_info = &this_attr->c->ext_info[this_attr->address];
296 287
297 return ext_info->write(indio_dev, this_attr->c, buf, len); 288 return ext_info->write(indio_dev, ext_info->private,
289 this_attr->c, buf, len);
298} 290}
299 291
300static ssize_t iio_read_channel_info(struct device *dev, 292static ssize_t iio_read_channel_info(struct device *dev,
301 struct device_attribute *attr, 293 struct device_attribute *attr,
302 char *buf) 294 char *buf)
303{ 295{
304 struct iio_dev *indio_dev = dev_get_drvdata(dev); 296 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
305 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 297 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
306 int val, val2; 298 int val, val2;
299 bool scale_db = false;
307 int ret = indio_dev->info->read_raw(indio_dev, this_attr->c, 300 int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
308 &val, &val2, this_attr->address); 301 &val, &val2, this_attr->address);
309 302
310 if (ret < 0) 303 if (ret < 0)
311 return ret; 304 return ret;
312 305
313 if (ret == IIO_VAL_INT) 306 switch (ret) {
307 case IIO_VAL_INT:
314 return sprintf(buf, "%d\n", val); 308 return sprintf(buf, "%d\n", val);
315 else if (ret == IIO_VAL_INT_PLUS_MICRO) { 309 case IIO_VAL_INT_PLUS_MICRO_DB:
310 scale_db = true;
311 case IIO_VAL_INT_PLUS_MICRO:
316 if (val2 < 0) 312 if (val2 < 0)
317 return sprintf(buf, "-%d.%06u\n", val, -val2); 313 return sprintf(buf, "-%d.%06u%s\n", val, -val2,
314 scale_db ? " dB" : "");
318 else 315 else
319 return sprintf(buf, "%d.%06u\n", val, val2); 316 return sprintf(buf, "%d.%06u%s\n", val, val2,
320 } else if (ret == IIO_VAL_INT_PLUS_NANO) { 317 scale_db ? " dB" : "");
318 case IIO_VAL_INT_PLUS_NANO:
321 if (val2 < 0) 319 if (val2 < 0)
322 return sprintf(buf, "-%d.%09u\n", val, -val2); 320 return sprintf(buf, "-%d.%09u\n", val, -val2);
323 else 321 else
324 return sprintf(buf, "%d.%09u\n", val, val2); 322 return sprintf(buf, "%d.%09u\n", val, val2);
325 } else 323 default:
326 return 0; 324 return 0;
325 }
327} 326}
328 327
329static ssize_t iio_write_channel_info(struct device *dev, 328static ssize_t iio_write_channel_info(struct device *dev,
@@ -331,7 +330,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
331 const char *buf, 330 const char *buf,
332 size_t len) 331 size_t len)
333{ 332{
334 struct iio_dev *indio_dev = dev_get_drvdata(dev); 333 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
335 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 334 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
336 int ret, integer = 0, fract = 0, fract_mult = 100000; 335 int ret, integer = 0, fract = 0, fract_mult = 100000;
337 bool integer_part = true, negative = false; 336 bool integer_part = true, negative = false;
@@ -575,25 +574,12 @@ error_ret:
575static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, 574static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
576 struct iio_chan_spec const *chan) 575 struct iio_chan_spec const *chan)
577{ 576{
578 int ret, i, attrcount = 0; 577 int ret, attrcount = 0;
578 int i;
579 const struct iio_chan_spec_ext_info *ext_info; 579 const struct iio_chan_spec_ext_info *ext_info;
580 580
581 if (chan->channel < 0) 581 if (chan->channel < 0)
582 return 0; 582 return 0;
583
584 ret = __iio_add_chan_devattr(iio_data_type_name[chan->processed_val],
585 chan,
586 &iio_read_channel_info,
587 (chan->output ?
588 &iio_write_channel_info : NULL),
589 0,
590 0,
591 &indio_dev->dev,
592 &indio_dev->channel_attr_list);
593 if (ret)
594 goto error_ret;
595 attrcount++;
596
597 for_each_set_bit(i, &chan->info_mask, sizeof(long)*8) { 583 for_each_set_bit(i, &chan->info_mask, sizeof(long)*8) {
598 ret = __iio_add_chan_devattr(iio_chan_info_postfix[i/2], 584 ret = __iio_add_chan_devattr(iio_chan_info_postfix[i/2],
599 chan, 585 chan,
@@ -652,7 +638,7 @@ static ssize_t iio_show_dev_name(struct device *dev,
652 struct device_attribute *attr, 638 struct device_attribute *attr,
653 char *buf) 639 char *buf)
654{ 640{
655 struct iio_dev *indio_dev = dev_get_drvdata(dev); 641 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
656 return sprintf(buf, "%s\n", indio_dev->name); 642 return sprintf(buf, "%s\n", indio_dev->name);
657} 643}
658 644
@@ -738,7 +724,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
738 724
739static void iio_dev_release(struct device *device) 725static void iio_dev_release(struct device *device)
740{ 726{
741 struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev); 727 struct iio_dev *indio_dev = dev_to_iio_dev(device);
742 cdev_del(&indio_dev->chrdev); 728 cdev_del(&indio_dev->chrdev);
743 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) 729 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
744 iio_device_unregister_trigger_consumer(indio_dev); 730 iio_device_unregister_trigger_consumer(indio_dev);
@@ -752,7 +738,7 @@ static struct device_type iio_dev_type = {
752 .release = iio_dev_release, 738 .release = iio_dev_release,
753}; 739};
754 740
755struct iio_dev *iio_allocate_device(int sizeof_priv) 741struct iio_dev *iio_device_alloc(int sizeof_priv)
756{ 742{
757 struct iio_dev *dev; 743 struct iio_dev *dev;
758 size_t alloc_size; 744 size_t alloc_size;
@@ -788,16 +774,16 @@ struct iio_dev *iio_allocate_device(int sizeof_priv)
788 774
789 return dev; 775 return dev;
790} 776}
791EXPORT_SYMBOL(iio_allocate_device); 777EXPORT_SYMBOL(iio_device_alloc);
792 778
793void iio_free_device(struct iio_dev *dev) 779void iio_device_free(struct iio_dev *dev)
794{ 780{
795 if (dev) { 781 if (dev) {
796 ida_simple_remove(&iio_ida, dev->id); 782 ida_simple_remove(&iio_ida, dev->id);
797 kfree(dev); 783 kfree(dev);
798 } 784 }
799} 785}
800EXPORT_SYMBOL(iio_free_device); 786EXPORT_SYMBOL(iio_device_free);
801 787
802/** 788/**
803 * iio_chrdev_open() - chrdev file open for buffer access and ioctls 789 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
diff --git a/drivers/staging/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 5fdf739e38f9..b49059de5d02 100644
--- a/drivers/staging/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -20,10 +20,10 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23#include "iio.h" 23#include <linux/iio/iio.h>
24#include "iio_core.h" 24#include "iio_core.h"
25#include "sysfs.h" 25#include <linux/iio/sysfs.h>
26#include "events.h" 26#include <linux/iio/events.h>
27 27
28/** 28/**
29 * struct iio_event_interface - chrdev interface for an event line 29 * struct iio_event_interface - chrdev interface for an event line
@@ -186,7 +186,7 @@ static ssize_t iio_ev_state_store(struct device *dev,
186 const char *buf, 186 const char *buf,
187 size_t len) 187 size_t len)
188{ 188{
189 struct iio_dev *indio_dev = dev_get_drvdata(dev); 189 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
190 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 190 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
191 int ret; 191 int ret;
192 bool val; 192 bool val;
@@ -205,7 +205,7 @@ static ssize_t iio_ev_state_show(struct device *dev,
205 struct device_attribute *attr, 205 struct device_attribute *attr,
206 char *buf) 206 char *buf)
207{ 207{
208 struct iio_dev *indio_dev = dev_get_drvdata(dev); 208 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
209 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 209 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
210 int val = indio_dev->info->read_event_config(indio_dev, 210 int val = indio_dev->info->read_event_config(indio_dev,
211 this_attr->address); 211 this_attr->address);
@@ -220,7 +220,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
220 struct device_attribute *attr, 220 struct device_attribute *attr,
221 char *buf) 221 char *buf)
222{ 222{
223 struct iio_dev *indio_dev = dev_get_drvdata(dev); 223 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
224 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 224 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
225 int val, ret; 225 int val, ret;
226 226
@@ -237,7 +237,7 @@ static ssize_t iio_ev_value_store(struct device *dev,
237 const char *buf, 237 const char *buf,
238 size_t len) 238 size_t len)
239{ 239{
240 struct iio_dev *indio_dev = dev_get_drvdata(dev); 240 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
241 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 241 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
242 unsigned long val; 242 unsigned long val;
243 int ret; 243 int ret;
diff --git a/drivers/staging/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 47ecadd4818d..0f582df75a19 100644
--- a/drivers/staging/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -15,11 +15,11 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18#include "iio.h" 18#include <linux/iio/iio.h>
19#include "trigger.h" 19#include <linux/iio/trigger.h>
20#include "iio_core.h" 20#include "iio_core.h"
21#include "iio_core_trigger.h" 21#include "iio_core_trigger.h"
22#include "trigger_consumer.h" 22#include <linux/iio/trigger_consumer.h>
23 23
24/* RFC - Question of approach 24/* RFC - Question of approach
25 * Make the common case (single sensor single trigger) 25 * Make the common case (single sensor single trigger)
@@ -310,7 +310,7 @@ static ssize_t iio_trigger_read_current(struct device *dev,
310 struct device_attribute *attr, 310 struct device_attribute *attr,
311 char *buf) 311 char *buf)
312{ 312{
313 struct iio_dev *indio_dev = dev_get_drvdata(dev); 313 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
314 314
315 if (indio_dev->trig) 315 if (indio_dev->trig)
316 return sprintf(buf, "%s\n", indio_dev->trig->name); 316 return sprintf(buf, "%s\n", indio_dev->trig->name);
@@ -329,7 +329,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
329 const char *buf, 329 const char *buf,
330 size_t len) 330 size_t len)
331{ 331{
332 struct iio_dev *indio_dev = dev_get_drvdata(dev); 332 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
333 struct iio_trigger *oldtrig = indio_dev->trig; 333 struct iio_trigger *oldtrig = indio_dev->trig;
334 struct iio_trigger *trig; 334 struct iio_trigger *trig;
335 int ret; 335 int ret;
@@ -360,9 +360,9 @@ static ssize_t iio_trigger_write_current(struct device *dev,
360 indio_dev->trig = trig; 360 indio_dev->trig = trig;
361 361
362 if (oldtrig && indio_dev->trig != oldtrig) 362 if (oldtrig && indio_dev->trig != oldtrig)
363 iio_put_trigger(oldtrig); 363 iio_trigger_put(oldtrig);
364 if (indio_dev->trig) 364 if (indio_dev->trig)
365 iio_get_trigger(indio_dev->trig); 365 iio_trigger_get(indio_dev->trig);
366 366
367 return len; 367 return len;
368} 368}
@@ -426,7 +426,7 @@ static void iio_trig_subirqunmask(struct irq_data *d)
426 trig->subirqs[d->irq - trig->subirq_base].enabled = true; 426 trig->subirqs[d->irq - trig->subirq_base].enabled = true;
427} 427}
428 428
429struct iio_trigger *iio_allocate_trigger(const char *fmt, ...) 429struct iio_trigger *iio_trigger_alloc(const char *fmt, ...)
430{ 430{
431 va_list vargs; 431 va_list vargs;
432 struct iio_trigger *trig; 432 struct iio_trigger *trig;
@@ -472,14 +472,14 @@ struct iio_trigger *iio_allocate_trigger(const char *fmt, ...)
472 } 472 }
473 return trig; 473 return trig;
474} 474}
475EXPORT_SYMBOL(iio_allocate_trigger); 475EXPORT_SYMBOL(iio_trigger_alloc);
476 476
477void iio_free_trigger(struct iio_trigger *trig) 477void iio_trigger_free(struct iio_trigger *trig)
478{ 478{
479 if (trig) 479 if (trig)
480 put_device(&trig->dev); 480 put_device(&trig->dev);
481} 481}
482EXPORT_SYMBOL(iio_free_trigger); 482EXPORT_SYMBOL(iio_trigger_free);
483 483
484void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) 484void iio_device_register_trigger_consumer(struct iio_dev *indio_dev)
485{ 485{
@@ -491,7 +491,7 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev)
491{ 491{
492 /* Clean up and associated but not attached triggers references */ 492 /* Clean up and associated but not attached triggers references */
493 if (indio_dev->trig) 493 if (indio_dev->trig)
494 iio_put_trigger(indio_dev->trig); 494 iio_trigger_put(indio_dev->trig);
495} 495}
496 496
497int iio_triggered_buffer_postenable(struct iio_dev *indio_dev) 497int iio_triggered_buffer_postenable(struct iio_dev *indio_dev)
diff --git a/drivers/staging/iio/inkern.c b/drivers/iio/inkern.c
index ef07a02bf542..922645893dc8 100644
--- a/drivers/staging/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -11,11 +11,11 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/mutex.h> 12#include <linux/mutex.h>
13 13
14#include "iio.h" 14#include <linux/iio/iio.h>
15#include "iio_core.h" 15#include "iio_core.h"
16#include "machine.h" 16#include <linux/iio/machine.h>
17#include "driver.h" 17#include <linux/iio/driver.h>
18#include "consumer.h" 18#include <linux/iio/consumer.h>
19 19
20struct iio_map_internal { 20struct iio_map_internal {
21 struct iio_dev *indio_dev; 21 struct iio_dev *indio_dev;
diff --git a/drivers/staging/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 9f3bd59c0e72..6bf9d05f4841 100644
--- a/drivers/staging/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -5,8 +5,7 @@
5#include <linux/workqueue.h> 5#include <linux/workqueue.h>
6#include <linux/kfifo.h> 6#include <linux/kfifo.h>
7#include <linux/mutex.h> 7#include <linux/mutex.h>
8 8#include <linux/iio/kfifo_buf.h>
9#include "kfifo_buf.h"
10 9
11struct iio_kfifo { 10struct iio_kfifo {
12 struct iio_buffer buffer; 11 struct iio_buffer buffer;
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 757fbd0f2a14..2661f6e366f9 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -516,4 +516,5 @@ source "drivers/misc/ti-st/Kconfig"
516source "drivers/misc/lis3lv02d/Kconfig" 516source "drivers/misc/lis3lv02d/Kconfig"
517source "drivers/misc/carma/Kconfig" 517source "drivers/misc/carma/Kconfig"
518source "drivers/misc/altera-stapl/Kconfig" 518source "drivers/misc/altera-stapl/Kconfig"
519source "drivers/misc/mei/Kconfig"
519endmenu 520endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 162861788c6d..456972faaeb3 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -50,3 +50,4 @@ obj-y += lis3lv02d/
50obj-y += carma/ 50obj-y += carma/
51obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o 51obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
52obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ 52obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
53obj-$(CONFIG_INTEL_MEI) += mei/
diff --git a/drivers/staging/mei/Kconfig b/drivers/misc/mei/Kconfig
index 47d78a72db2e..47d78a72db2e 100644
--- a/drivers/staging/mei/Kconfig
+++ b/drivers/misc/mei/Kconfig
diff --git a/drivers/staging/mei/Makefile b/drivers/misc/mei/Makefile
index 57168db6c7e5..57168db6c7e5 100644
--- a/drivers/staging/mei/Makefile
+++ b/drivers/misc/mei/Makefile
diff --git a/drivers/staging/mei/hw.h b/drivers/misc/mei/hw.h
index 24c4c962819e..24c4c962819e 100644
--- a/drivers/staging/mei/hw.h
+++ b/drivers/misc/mei/hw.h
diff --git a/drivers/staging/mei/init.c b/drivers/misc/mei/init.c
index eab711fb5fc4..a7d0bb0880ec 100644
--- a/drivers/staging/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -22,7 +22,7 @@
22#include "mei_dev.h" 22#include "mei_dev.h"
23#include "hw.h" 23#include "hw.h"
24#include "interface.h" 24#include "interface.h"
25#include "mei.h" 25#include <linux/mei.h>
26 26
27const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac, 27const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac,
28 0xa8, 0x46, 0xe0, 0xff, 0x65, 28 0xa8, 0x46, 0xe0, 0xff, 0x65,
@@ -200,7 +200,7 @@ int mei_hw_init(struct mei_device *dev)
200 if (!(dev->me_hw_state & ME_RDY_HRA)) 200 if (!(dev->me_hw_state & ME_RDY_HRA))
201 dev_dbg(&dev->pdev->dev, "ME turn off ME_RDY.\n"); 201 dev_dbg(&dev->pdev->dev, "ME turn off ME_RDY.\n");
202 202
203 printk(KERN_ERR "mei: link layer initialization failed.\n"); 203 dev_err(&dev->pdev->dev, "link layer initialization failed.\n");
204 ret = -ENODEV; 204 ret = -ENODEV;
205 goto out; 205 goto out;
206 } 206 }
diff --git a/drivers/staging/mei/interface.c b/drivers/misc/mei/interface.c
index 9a2cfafc52a6..428d21e36416 100644
--- a/drivers/staging/mei/interface.c
+++ b/drivers/misc/mei/interface.c
@@ -16,7 +16,7 @@
16 16
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include "mei_dev.h" 18#include "mei_dev.h"
19#include "mei.h" 19#include <linux/mei.h>
20#include "interface.h" 20#include "interface.h"
21 21
22 22
diff --git a/drivers/staging/mei/interface.h b/drivers/misc/mei/interface.h
index fb90c6f8a759..ddff5d16616f 100644
--- a/drivers/staging/mei/interface.h
+++ b/drivers/misc/mei/interface.h
@@ -19,7 +19,7 @@
19#ifndef _MEI_INTERFACE_H_ 19#ifndef _MEI_INTERFACE_H_
20#define _MEI_INTERFACE_H_ 20#define _MEI_INTERFACE_H_
21 21
22#include "mei.h" 22#include <linux/mei.h>
23#include "mei_dev.h" 23#include "mei_dev.h"
24 24
25 25
@@ -51,8 +51,7 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl);
51 51
52int mei_wd_send(struct mei_device *dev); 52int mei_wd_send(struct mei_device *dev);
53int mei_wd_stop(struct mei_device *dev, bool preserve); 53int mei_wd_stop(struct mei_device *dev, bool preserve);
54bool mei_wd_host_init(struct mei_device *dev); 54int mei_wd_host_init(struct mei_device *dev);
55void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout);
56/* 55/*
57 * mei_watchdog_register - Registering watchdog interface 56 * mei_watchdog_register - Registering watchdog interface
58 * once we got connection to the WD Client 57 * once we got connection to the WD Client
diff --git a/drivers/staging/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index 2007d2447b1c..93936f1b75eb 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -22,7 +22,7 @@
22#include <linux/jiffies.h> 22#include <linux/jiffies.h>
23 23
24#include "mei_dev.h" 24#include "mei_dev.h"
25#include "mei.h" 25#include <linux/mei.h>
26#include "hw.h" 26#include "hw.h"
27#include "interface.h" 27#include "interface.h"
28 28
diff --git a/drivers/staging/mei/iorw.c b/drivers/misc/mei/iorw.c
index 0a80dc4e62f3..f9cced69b65e 100644
--- a/drivers/staging/mei/iorw.c
+++ b/drivers/misc/mei/iorw.c
@@ -35,7 +35,7 @@
35 35
36#include "mei_dev.h" 36#include "mei_dev.h"
37#include "hw.h" 37#include "hw.h"
38#include "mei.h" 38#include <linux/mei.h>
39#include "interface.h" 39#include "interface.h"
40 40
41 41
diff --git a/drivers/staging/mei/main.c b/drivers/misc/mei/main.c
index 7c9321fa7bb1..c70333228337 100644
--- a/drivers/staging/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -14,6 +14,8 @@
14 * 14 *
15 */ 15 */
16 16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
17#include <linux/module.h> 19#include <linux/module.h>
18#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
19#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -36,19 +38,10 @@
36#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
37 39
38#include "mei_dev.h" 40#include "mei_dev.h"
39#include "mei.h" 41#include <linux/mei.h>
40#include "interface.h" 42#include "interface.h"
41 43
42 44static const char mei_driver_name[] = "mei";
43#define MEI_READ_TIMEOUT 45
44#define MEI_DRIVER_NAME "mei"
45#define MEI_DEV_NAME "mei"
46
47/*
48 * mei driver strings
49 */
50static char mei_driver_name[] = MEI_DRIVER_NAME;
51static const char mei_driver_string[] = "Intel(R) Management Engine Interface";
52 45
53/* The device pointer */ 46/* The device pointer */
54/* Currently this driver works as long as there is only a single AMT device. */ 47/* Currently this driver works as long as there is only a single AMT device. */
@@ -931,7 +924,7 @@ static const struct file_operations mei_fops = {
931 * Misc Device Struct 924 * Misc Device Struct
932 */ 925 */
933static struct miscdevice mei_misc_device = { 926static struct miscdevice mei_misc_device = {
934 .name = MEI_DRIVER_NAME, 927 .name = "mei",
935 .fops = &mei_fops, 928 .fops = &mei_fops,
936 .minor = MISC_DYNAMIC_MINOR, 929 .minor = MISC_DYNAMIC_MINOR,
937}; 930};
@@ -958,7 +951,7 @@ static int __devinit mei_probe(struct pci_dev *pdev,
958 /* enable pci dev */ 951 /* enable pci dev */
959 err = pci_enable_device(pdev); 952 err = pci_enable_device(pdev);
960 if (err) { 953 if (err) {
961 printk(KERN_ERR "mei: Failed to enable pci device.\n"); 954 dev_err(&pdev->dev, "failed to enable pci device.\n");
962 goto end; 955 goto end;
963 } 956 }
964 /* set PCI host mastering */ 957 /* set PCI host mastering */
@@ -966,7 +959,7 @@ static int __devinit mei_probe(struct pci_dev *pdev,
966 /* pci request regions for mei driver */ 959 /* pci request regions for mei driver */
967 err = pci_request_regions(pdev, mei_driver_name); 960 err = pci_request_regions(pdev, mei_driver_name);
968 if (err) { 961 if (err) {
969 printk(KERN_ERR "mei: Failed to get pci regions.\n"); 962 dev_err(&pdev->dev, "failed to get pci regions.\n");
970 goto disable_device; 963 goto disable_device;
971 } 964 }
972 /* allocates and initializes the mei dev structure */ 965 /* allocates and initializes the mei dev structure */
@@ -978,7 +971,7 @@ static int __devinit mei_probe(struct pci_dev *pdev,
978 /* mapping IO device memory */ 971 /* mapping IO device memory */
979 dev->mem_addr = pci_iomap(pdev, 0, 0); 972 dev->mem_addr = pci_iomap(pdev, 0, 0);
980 if (!dev->mem_addr) { 973 if (!dev->mem_addr) {
981 printk(KERN_ERR "mei: mapping I/O device memory failure.\n"); 974 dev_err(&pdev->dev, "mapping I/O device memory failure.\n");
982 err = -ENOMEM; 975 err = -ENOMEM;
983 goto free_device; 976 goto free_device;
984 } 977 }
@@ -997,13 +990,13 @@ static int __devinit mei_probe(struct pci_dev *pdev,
997 IRQF_SHARED, mei_driver_name, dev); 990 IRQF_SHARED, mei_driver_name, dev);
998 991
999 if (err) { 992 if (err) {
1000 printk(KERN_ERR "mei: request_threaded_irq failure. irq = %d\n", 993 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
1001 pdev->irq); 994 pdev->irq);
1002 goto unmap_memory; 995 goto unmap_memory;
1003 } 996 }
1004 INIT_DELAYED_WORK(&dev->timer_work, mei_timer); 997 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
1005 if (mei_hw_init(dev)) { 998 if (mei_hw_init(dev)) {
1006 printk(KERN_ERR "mei: Init hw failure.\n"); 999 dev_err(&pdev->dev, "init hw failure.\n");
1007 err = -ENODEV; 1000 err = -ENODEV;
1008 goto release_irq; 1001 goto release_irq;
1009 } 1002 }
@@ -1020,7 +1013,7 @@ static int __devinit mei_probe(struct pci_dev *pdev,
1020 1013
1021 mutex_unlock(&mei_mutex); 1014 mutex_unlock(&mei_mutex);
1022 1015
1023 pr_debug("mei: Driver initialization successful.\n"); 1016 pr_debug("initialization successful.\n");
1024 1017
1025 return 0; 1018 return 0;
1026 1019
@@ -1041,7 +1034,7 @@ disable_device:
1041 pci_disable_device(pdev); 1034 pci_disable_device(pdev);
1042end: 1035end:
1043 mutex_unlock(&mei_mutex); 1036 mutex_unlock(&mei_mutex);
1044 printk(KERN_ERR "mei: Driver initialization failed.\n"); 1037 dev_err(&pdev->dev, "initialization failed.\n");
1045 return err; 1038 return err;
1046} 1039}
1047 1040
@@ -1160,8 +1153,8 @@ static int mei_pci_resume(struct device *device)
1160 IRQF_SHARED, mei_driver_name, dev); 1153 IRQF_SHARED, mei_driver_name, dev);
1161 1154
1162 if (err) { 1155 if (err) {
1163 printk(KERN_ERR "mei: Request_irq failure. irq = %d\n", 1156 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
1164 pdev->irq); 1157 pdev->irq);
1165 return err; 1158 return err;
1166 } 1159 }
1167 1160
@@ -1204,11 +1197,11 @@ static int __init mei_init_module(void)
1204{ 1197{
1205 int ret; 1198 int ret;
1206 1199
1207 pr_debug("mei: %s\n", mei_driver_string); 1200 pr_debug("loading.\n");
1208 /* init pci module */ 1201 /* init pci module */
1209 ret = pci_register_driver(&mei_driver); 1202 ret = pci_register_driver(&mei_driver);
1210 if (ret < 0) 1203 if (ret < 0)
1211 printk(KERN_ERR "mei: Error registering driver.\n"); 1204 pr_err("error registering driver.\n");
1212 1205
1213 return ret; 1206 return ret;
1214} 1207}
@@ -1226,7 +1219,7 @@ static void __exit mei_exit_module(void)
1226 misc_deregister(&mei_misc_device); 1219 misc_deregister(&mei_misc_device);
1227 pci_unregister_driver(&mei_driver); 1220 pci_unregister_driver(&mei_driver);
1228 1221
1229 pr_debug("mei: Driver unloaded successfully.\n"); 1222 pr_debug("unloaded successfully.\n");
1230} 1223}
1231 1224
1232module_exit(mei_exit_module); 1225module_exit(mei_exit_module);
diff --git a/drivers/staging/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 10b1b4e2f8ac..63d7ee97c5fb 100644
--- a/drivers/staging/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -19,7 +19,7 @@
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include "mei.h" 22#include <linux/mei.h>
23#include "hw.h" 23#include "hw.h"
24 24
25/* 25/*
diff --git a/drivers/staging/mei/wd.c b/drivers/misc/mei/wd.c
index cf4c29d10e7f..6be5605707b4 100644
--- a/drivers/staging/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -24,7 +24,7 @@
24#include "mei_dev.h" 24#include "mei_dev.h"
25#include "hw.h" 25#include "hw.h"
26#include "interface.h" 26#include "interface.h"
27#include "mei.h" 27#include <linux/mei.h>
28 28
29static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 }; 29static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
30static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 }; 30static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
@@ -45,23 +45,22 @@ const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
45 0x9D, 0xA9, 0x15, 0x14, 0xCB, 45 0x9D, 0xA9, 0x15, 0x14, 0xCB,
46 0x32, 0xAB); 46 0x32, 0xAB);
47 47
48void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout) 48static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)
49{ 49{
50 dev_dbg(&dev->pdev->dev, "timeout=%d.\n", timeout); 50 dev_dbg(&dev->pdev->dev, "wd: set timeout=%d.\n", timeout);
51 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE); 51 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE);
52 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE, 52 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE, &timeout, sizeof(u16));
53 &timeout, sizeof(u16));
54} 53}
55 54
56/** 55/**
57 * host_init_wd - mei initialization wd. 56 * host_init_wd - mei initialization wd.
58 * 57 *
59 * @dev: the device structure 58 * @dev: the device structure
59 * returns -ENENT if wd client cannot be found
60 * -EIO if write has failed
60 */ 61 */
61bool mei_wd_host_init(struct mei_device *dev) 62int mei_wd_host_init(struct mei_device *dev)
62{ 63{
63 bool ret = false;
64
65 mei_cl_init(&dev->wd_cl, dev); 64 mei_cl_init(&dev->wd_cl, dev);
66 65
67 /* look for WD client and connect to it */ 66 /* look for WD client and connect to it */
@@ -72,25 +71,21 @@ bool mei_wd_host_init(struct mei_device *dev)
72 mei_find_me_client_update_filext(dev, &dev->wd_cl, 71 mei_find_me_client_update_filext(dev, &dev->wd_cl,
73 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID); 72 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
74 73
75 dev_dbg(&dev->pdev->dev, "check wd_cl\n"); 74 dev_dbg(&dev->pdev->dev, "wd: check client\n");
76 if (MEI_FILE_CONNECTING == dev->wd_cl.state) { 75 if (MEI_FILE_CONNECTING != dev->wd_cl.state) {
77 if (mei_connect(dev, &dev->wd_cl)) { 76 dev_info(&dev->pdev->dev, "wd: failed to find the client\n");
78 dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n"); 77 return -ENOENT;
79 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
80 dev->wd_cl.host_client_id = 0;
81 ret = false;
82 goto end;
83 } else {
84 dev->wd_cl.timer_count = CONNECT_TIMEOUT;
85 }
86 } else {
87 dev_dbg(&dev->pdev->dev, "Failed to find WD client\n");
88 ret = false;
89 goto end;
90 } 78 }
91 79
92end: 80 if (mei_connect(dev, &dev->wd_cl)) {
93 return ret; 81 dev_err(&dev->pdev->dev, "wd: failed to connect to the client\n");
82 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
83 dev->wd_cl.host_client_id = 0;
84 return -EIO;
85 }
86 dev->wd_cl.timer_count = CONNECT_TIMEOUT;
87
88 return 0;
94} 89}
95 90
96/** 91/**
@@ -159,7 +154,7 @@ int mei_wd_stop(struct mei_device *dev, bool preserve)
159 if (ret) 154 if (ret)
160 goto out; 155 goto out;
161 } else { 156 } else {
162 dev_dbg(&dev->pdev->dev, "send stop WD failed\n"); 157 dev_err(&dev->pdev->dev, "wd: send stop failed\n");
163 } 158 }
164 159
165 dev->wd_pending = false; 160 dev->wd_pending = false;
@@ -173,13 +168,13 @@ int mei_wd_stop(struct mei_device *dev, bool preserve)
173 dev->wd_stopped, 10 * HZ); 168 dev->wd_stopped, 10 * HZ);
174 mutex_lock(&dev->device_lock); 169 mutex_lock(&dev->device_lock);
175 if (dev->wd_stopped) { 170 if (dev->wd_stopped) {
176 dev_dbg(&dev->pdev->dev, "stop wd complete ret=%d.\n", ret); 171 dev_dbg(&dev->pdev->dev, "wd: stop completed ret=%d.\n", ret);
177 ret = 0; 172 ret = 0;
178 } else { 173 } else {
179 if (!ret) 174 if (!ret)
180 ret = -ETIMEDOUT; 175 ret = -ETIMEDOUT;
181 dev_warn(&dev->pdev->dev, 176 dev_warn(&dev->pdev->dev,
182 "stop wd failed to complete ret=%d.\n", ret); 177 "wd: stop failed to complete ret=%d.\n", ret);
183 } 178 }
184 179
185 if (preserve) 180 if (preserve)
@@ -208,13 +203,15 @@ static int mei_wd_ops_start(struct watchdog_device *wd_dev)
208 mutex_lock(&dev->device_lock); 203 mutex_lock(&dev->device_lock);
209 204
210 if (dev->mei_state != MEI_ENABLED) { 205 if (dev->mei_state != MEI_ENABLED) {
211 dev_dbg(&dev->pdev->dev, "mei_state != MEI_ENABLED mei_state= %d\n", 206 dev_dbg(&dev->pdev->dev,
212 dev->mei_state); 207 "wd: mei_state != MEI_ENABLED mei_state = %d\n",
208 dev->mei_state);
213 goto end_unlock; 209 goto end_unlock;
214 } 210 }
215 211
216 if (dev->wd_cl.state != MEI_FILE_CONNECTED) { 212 if (dev->wd_cl.state != MEI_FILE_CONNECTED) {
217 dev_dbg(&dev->pdev->dev, "MEI Driver is not connected to Watchdog Client\n"); 213 dev_dbg(&dev->pdev->dev,
214 "MEI Driver is not connected to Watchdog Client\n");
218 goto end_unlock; 215 goto end_unlock;
219 } 216 }
220 217
@@ -267,7 +264,7 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
267 mutex_lock(&dev->device_lock); 264 mutex_lock(&dev->device_lock);
268 265
269 if (dev->wd_cl.state != MEI_FILE_CONNECTED) { 266 if (dev->wd_cl.state != MEI_FILE_CONNECTED) {
270 dev_dbg(&dev->pdev->dev, "wd is not connected.\n"); 267 dev_err(&dev->pdev->dev, "wd: not connected.\n");
271 ret = -ENODEV; 268 ret = -ENODEV;
272 goto end; 269 goto end;
273 } 270 }
@@ -277,16 +274,17 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
277 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 274 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
278 275
279 dev->mei_host_buffer_is_empty = false; 276 dev->mei_host_buffer_is_empty = false;
280 dev_dbg(&dev->pdev->dev, "sending watchdog ping\n"); 277 dev_dbg(&dev->pdev->dev, "wd: sending ping\n");
281 278
282 if (mei_wd_send(dev)) { 279 if (mei_wd_send(dev)) {
283 dev_dbg(&dev->pdev->dev, "wd send failed.\n"); 280 dev_err(&dev->pdev->dev, "wd: send failed.\n");
284 ret = -EIO; 281 ret = -EIO;
285 goto end; 282 goto end;
286 } 283 }
287 284
288 if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) { 285 if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) {
289 dev_dbg(&dev->pdev->dev, "mei_flow_ctrl_reduce() failed.\n"); 286 dev_err(&dev->pdev->dev,
287 "wd: mei_flow_ctrl_reduce() failed.\n");
290 ret = -EIO; 288 ret = -EIO;
291 goto end; 289 goto end;
292 } 290 }
@@ -346,7 +344,7 @@ static const struct watchdog_info wd_info = {
346 .options = WDIOF_KEEPALIVEPING, 344 .options = WDIOF_KEEPALIVEPING,
347}; 345};
348 346
349struct watchdog_device amt_wd_dev = { 347static struct watchdog_device amt_wd_dev = {
350 .info = &wd_info, 348 .info = &wd_info,
351 .ops = &wd_ops, 349 .ops = &wd_ops,
352 .timeout = AMT_WD_DEFAULT_TIMEOUT, 350 .timeout = AMT_WD_DEFAULT_TIMEOUT,
@@ -362,10 +360,12 @@ void mei_watchdog_register(struct mei_device *dev)
362 dev->wd_due_counter = !!dev->wd_timeout; 360 dev->wd_due_counter = !!dev->wd_timeout;
363 361
364 if (watchdog_register_device(&amt_wd_dev)) { 362 if (watchdog_register_device(&amt_wd_dev)) {
365 dev_err(&dev->pdev->dev, "unable to register watchdog device.\n"); 363 dev_err(&dev->pdev->dev,
364 "wd: unable to register watchdog device.\n");
366 dev->wd_interface_reg = false; 365 dev->wd_interface_reg = false;
367 } else { 366 } else {
368 dev_dbg(&dev->pdev->dev, "successfully register watchdog interface.\n"); 367 dev_dbg(&dev->pdev->dev,
368 "wd: successfully register watchdog interface.\n");
369 dev->wd_interface_reg = true; 369 dev->wd_interface_reg = true;
370 } 370 }
371} 371}
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index d70ede7a7f96..d58431e99f73 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -203,37 +203,6 @@ config WANXL_BUILD_FIRMWARE
203 203
204 You should never need this option, say N. 204 You should never need this option, say N.
205 205
206config PC300
207 tristate "Cyclades-PC300 support (RS-232/V.35, X.21, T1/E1 boards)"
208 depends on HDLC && PCI && BROKEN
209 ---help---
210 This driver is broken because of struct tty_driver change.
211
212 Driver for the Cyclades-PC300 synchronous communication boards.
213
214 These boards provide synchronous serial interfaces to your
215 Linux box (interfaces currently available are RS-232/V.35, X.21 and
216 T1/E1). If you wish to support Multilink PPP, please select the
217 option later and read the file README.mlppp provided by PC300
218 package.
219
220 To compile this as a module, choose M here: the module
221 will be called pc300.
222
223 If unsure, say N.
224
225config PC300_MLPPP
226 bool "Cyclades-PC300 MLPPP support"
227 depends on PC300 && PPP_MULTILINK && PPP_SYNC_TTY && HDLC_PPP
228 help
229 Multilink PPP over the PC300 synchronous communication boards.
230
231comment "Cyclades-PC300 MLPPP support is disabled."
232 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
233
234comment "Refer to the file README.mlppp, provided by PC300 package."
235 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
236
237config PC300TOO 206config PC300TOO
238 tristate "Cyclades PC300 RSV/X21 alternative support" 207 tristate "Cyclades PC300 RSV/X21 alternative support"
239 depends on HDLC && PCI 208 depends on HDLC && PCI
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index 19d14bc28356..eac709bed7ae 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -17,10 +17,6 @@ obj-$(CONFIG_HDLC_FR) += hdlc_fr.o
17obj-$(CONFIG_HDLC_PPP) += hdlc_ppp.o 17obj-$(CONFIG_HDLC_PPP) += hdlc_ppp.o
18obj-$(CONFIG_HDLC_X25) += hdlc_x25.o 18obj-$(CONFIG_HDLC_X25) += hdlc_x25.o
19 19
20pc300-y := pc300_drv.o
21pc300-$(CONFIG_PC300_MLPPP) += pc300_tty.o
22pc300-objs := $(pc300-y)
23
24obj-$(CONFIG_HOSTESS_SV11) += z85230.o hostess_sv11.o 20obj-$(CONFIG_HOSTESS_SV11) += z85230.o hostess_sv11.o
25obj-$(CONFIG_SEALEVEL_4021) += z85230.o sealevel.o 21obj-$(CONFIG_SEALEVEL_4021) += z85230.o sealevel.o
26obj-$(CONFIG_COSA) += cosa.o 22obj-$(CONFIG_COSA) += cosa.o
@@ -35,7 +31,6 @@ obj-$(CONFIG_SDLA) += sdla.o
35obj-$(CONFIG_CYCLADES_SYNC) += cycx_drv.o cyclomx.o 31obj-$(CONFIG_CYCLADES_SYNC) += cycx_drv.o cyclomx.o
36obj-$(CONFIG_LAPBETHER) += lapbether.o 32obj-$(CONFIG_LAPBETHER) += lapbether.o
37obj-$(CONFIG_SBNI) += sbni.o 33obj-$(CONFIG_SBNI) += sbni.o
38obj-$(CONFIG_PC300) += pc300.o
39obj-$(CONFIG_N2) += n2.o 34obj-$(CONFIG_N2) += n2.o
40obj-$(CONFIG_C101) += c101.o 35obj-$(CONFIG_C101) += c101.o
41obj-$(CONFIG_WANXL) += wanxl.o 36obj-$(CONFIG_WANXL) += wanxl.o
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 32bd967f4262..05e33c700750 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -24,8 +24,6 @@ menuconfig STAGING
24 24
25if STAGING 25if STAGING
26 26
27source "drivers/staging/serial/Kconfig"
28
29source "drivers/staging/et131x/Kconfig" 27source "drivers/staging/et131x/Kconfig"
30 28
31source "drivers/staging/slicoss/Kconfig" 29source "drivers/staging/slicoss/Kconfig"
@@ -72,8 +70,6 @@ source "drivers/staging/vt6655/Kconfig"
72 70
73source "drivers/staging/vt6656/Kconfig" 71source "drivers/staging/vt6656/Kconfig"
74 72
75source "drivers/staging/vme/Kconfig"
76
77source "drivers/staging/sep/Kconfig" 73source "drivers/staging/sep/Kconfig"
78 74
79source "drivers/staging/iio/Kconfig" 75source "drivers/staging/iio/Kconfig"
@@ -114,12 +110,12 @@ source "drivers/staging/cptm1217/Kconfig"
114 110
115source "drivers/staging/ste_rmi4/Kconfig" 111source "drivers/staging/ste_rmi4/Kconfig"
116 112
117source "drivers/staging/mei/Kconfig"
118
119source "drivers/staging/nvec/Kconfig" 113source "drivers/staging/nvec/Kconfig"
120 114
121source "drivers/staging/media/Kconfig" 115source "drivers/staging/media/Kconfig"
122 116
117source "drivers/staging/net/Kconfig"
118
123source "drivers/staging/omapdrm/Kconfig" 119source "drivers/staging/omapdrm/Kconfig"
124 120
125source "drivers/staging/android/Kconfig" 121source "drivers/staging/android/Kconfig"
@@ -132,4 +128,8 @@ source "drivers/staging/ozwpan/Kconfig"
132 128
133source "drivers/staging/ccg/Kconfig" 129source "drivers/staging/ccg/Kconfig"
134 130
131source "drivers/staging/ipack/Kconfig"
132
133source "drivers/staging/gdm72xx/Kconfig"
134
135endif # STAGING 135endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index eae8a21f46b8..a987b3ad380b 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -3,8 +3,8 @@
3# fix for build system bug... 3# fix for build system bug...
4obj-$(CONFIG_STAGING) += staging.o 4obj-$(CONFIG_STAGING) += staging.o
5 5
6obj-y += serial/
7obj-y += media/ 6obj-y += media/
7obj-y += net/
8obj-$(CONFIG_ET131X) += et131x/ 8obj-$(CONFIG_ET131X) += et131x/
9obj-$(CONFIG_SLICOSS) += slicoss/ 9obj-$(CONFIG_SLICOSS) += slicoss/
10obj-$(CONFIG_USBIP_CORE) += usbip/ 10obj-$(CONFIG_USBIP_CORE) += usbip/
@@ -29,6 +29,7 @@ obj-$(CONFIG_OCTEON_ETHERNET) += octeon/
29obj-$(CONFIG_VT6655) += vt6655/ 29obj-$(CONFIG_VT6655) += vt6655/
30obj-$(CONFIG_VT6656) += vt6656/ 30obj-$(CONFIG_VT6656) += vt6656/
31obj-$(CONFIG_VME_BUS) += vme/ 31obj-$(CONFIG_VME_BUS) += vme/
32obj-$(CONFIG_IPACK_BUS) += ipack/
32obj-$(CONFIG_DX_SEP) += sep/ 33obj-$(CONFIG_DX_SEP) += sep/
33obj-$(CONFIG_IIO) += iio/ 34obj-$(CONFIG_IIO) += iio/
34obj-$(CONFIG_ZRAM) += zram/ 35obj-$(CONFIG_ZRAM) += zram/
@@ -49,7 +50,6 @@ obj-$(CONFIG_FT1000) += ft1000/
49obj-$(CONFIG_SPEAKUP) += speakup/ 50obj-$(CONFIG_SPEAKUP) += speakup/
50obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += cptm1217/ 51obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += cptm1217/
51obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/ 52obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/
52obj-$(CONFIG_INTEL_MEI) += mei/
53obj-$(CONFIG_MFD_NVEC) += nvec/ 53obj-$(CONFIG_MFD_NVEC) += nvec/
54obj-$(CONFIG_DRM_OMAP) += omapdrm/ 54obj-$(CONFIG_DRM_OMAP) += omapdrm/
55obj-$(CONFIG_ANDROID) += android/ 55obj-$(CONFIG_ANDROID) += android/
@@ -57,3 +57,4 @@ obj-$(CONFIG_PHONE) += telephony/
57obj-$(CONFIG_RAMSTER) += ramster/ 57obj-$(CONFIG_RAMSTER) += ramster/
58obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/ 58obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
59obj-$(CONFIG_USB_G_CCG) += ccg/ 59obj-$(CONFIG_USB_G_CCG) += ccg/
60obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index c706635f3f82..0e16b594460f 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -25,17 +25,9 @@ config ANDROID_LOGGER
25 tristate "Android log driver" 25 tristate "Android log driver"
26 default n 26 default n
27 27
28config ANDROID_PERSISTENT_RAM
29 bool
30 depends on HAVE_MEMBLOCK
31 select REED_SOLOMON
32 select REED_SOLOMON_ENC8
33 select REED_SOLOMON_DEC8
34
35config ANDROID_RAM_CONSOLE 28config ANDROID_RAM_CONSOLE
36 bool "Android RAM buffer console" 29 bool "Android RAM buffer console"
37 depends on !S390 && !UML && HAVE_MEMBLOCK 30 depends on !S390 && !UML && HAVE_MEMBLOCK && PSTORE_RAM=y
38 select ANDROID_PERSISTENT_RAM
39 default n 31 default n
40 32
41config ANDROID_TIMED_OUTPUT 33config ANDROID_TIMED_OUTPUT
@@ -53,31 +45,15 @@ config ANDROID_LOW_MEMORY_KILLER
53 ---help--- 45 ---help---
54 Register processes to be killed when memory is low 46 Register processes to be killed when memory is low
55 47
56config ANDROID_INTF_ALARM 48config ANDROID_INTF_ALARM_DEV
57 bool "Android alarm driver" 49 bool "Android alarm driver"
58 depends on RTC_CLASS 50 depends on RTC_CLASS
59 default n 51 default n
60 help 52 help
61 Provides non-wakeup and rtc backed wakeup alarms based on rtc or 53 Provides non-wakeup and rtc backed wakeup alarms based on rtc or
62 elapsed realtime, and a non-wakeup alarm on the monotonic clock. 54 elapsed realtime, and a non-wakeup alarm on the monotonic clock.
63 Also provides an interface to set the wall time which must be used 55 Also exports the alarm interface to user-space.
64 for elapsed realtime to work.
65
66config ANDROID_INTF_ALARM_DEV
67 bool "Android alarm device"
68 depends on ANDROID_INTF_ALARM
69 default y
70 help
71 Exports the alarm interface to user-space.
72 56
73config ANDROID_ALARM_OLDDRV_COMPAT
74 bool "Android Alarm compatability with old drivers"
75 depends on ANDROID_INTF_ALARM
76 default n
77 help
78 Provides preprocessor alias to aid compatability with
79 older out-of-tree drivers that use the Android Alarm
80 in-kernel API. This will be removed eventually.
81endif # if ANDROID 57endif # if ANDROID
82 58
83endmenu 59endmenu
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 045d17bde524..98711e2b2afa 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -1,10 +1,8 @@
1obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o 1obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o
2obj-$(CONFIG_ASHMEM) += ashmem.o 2obj-$(CONFIG_ASHMEM) += ashmem.o
3obj-$(CONFIG_ANDROID_LOGGER) += logger.o 3obj-$(CONFIG_ANDROID_LOGGER) += logger.o
4obj-$(CONFIG_ANDROID_PERSISTENT_RAM) += persistent_ram.o
5obj-$(CONFIG_ANDROID_RAM_CONSOLE) += ram_console.o 4obj-$(CONFIG_ANDROID_RAM_CONSOLE) += ram_console.o
6obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o 5obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o
7obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o 6obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o
8obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o 7obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o
9obj-$(CONFIG_ANDROID_INTF_ALARM) += alarm.o
10obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o 8obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o
diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c
index 03efb34cbe2e..53ce6ecf390a 100644
--- a/drivers/staging/android/alarm-dev.c
+++ b/drivers/staging/android/alarm-dev.c
@@ -22,19 +22,9 @@
22#include <linux/sched.h> 22#include <linux/sched.h>
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25#include <linux/alarmtimer.h>
25#include "android_alarm.h" 26#include "android_alarm.h"
26 27
27/* XXX - Hack out wakelocks, while they are out of tree */
28struct wake_lock {
29 int i;
30};
31#define wake_lock(x)
32#define wake_lock_timeout(x, y)
33#define wake_unlock(x)
34#define WAKE_LOCK_SUSPEND 0
35#define wake_lock_init(x, y, z) ((x)->i = 1)
36#define wake_lock_destroy(x)
37
38#define ANDROID_ALARM_PRINT_INFO (1U << 0) 28#define ANDROID_ALARM_PRINT_INFO (1U << 0)
39#define ANDROID_ALARM_PRINT_IO (1U << 1) 29#define ANDROID_ALARM_PRINT_IO (1U << 1)
40#define ANDROID_ALARM_PRINT_INT (1U << 2) 30#define ANDROID_ALARM_PRINT_INT (1U << 2)
@@ -54,19 +44,65 @@ module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
54 ANDROID_ALARM_RTC_WAKEUP_MASK | \ 44 ANDROID_ALARM_RTC_WAKEUP_MASK | \
55 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK) 45 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK)
56 46
57/* support old usespace code */ 47/* support old userspace code */
58#define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */ 48#define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */
59#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t) 49#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t)
60 50
61static int alarm_opened; 51static int alarm_opened;
62static DEFINE_SPINLOCK(alarm_slock); 52static DEFINE_SPINLOCK(alarm_slock);
63static struct wake_lock alarm_wake_lock; 53static struct wakeup_source alarm_wake_lock;
64static DECLARE_WAIT_QUEUE_HEAD(alarm_wait_queue); 54static DECLARE_WAIT_QUEUE_HEAD(alarm_wait_queue);
65static uint32_t alarm_pending; 55static uint32_t alarm_pending;
66static uint32_t alarm_enabled; 56static uint32_t alarm_enabled;
67static uint32_t wait_pending; 57static uint32_t wait_pending;
68 58
69static struct android_alarm alarms[ANDROID_ALARM_TYPE_COUNT]; 59struct devalarm {
60 union {
61 struct hrtimer hrt;
62 struct alarm alrm;
63 } u;
64 enum android_alarm_type type;
65};
66
67static struct devalarm alarms[ANDROID_ALARM_TYPE_COUNT];
68
69
70static int is_wakeup(enum android_alarm_type type)
71{
72 if (type == ANDROID_ALARM_RTC_WAKEUP ||
73 type == ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP)
74 return 1;
75 return 0;
76}
77
78
79static void devalarm_start(struct devalarm *alrm, ktime_t exp)
80{
81 if (is_wakeup(alrm->type))
82 alarm_start(&alrm->u.alrm, exp);
83 else
84 hrtimer_start(&alrm->u.hrt, exp, HRTIMER_MODE_ABS);
85}
86
87
88static int devalarm_try_to_cancel(struct devalarm *alrm)
89{
90 int ret;
91 if (is_wakeup(alrm->type))
92 ret = alarm_try_to_cancel(&alrm->u.alrm);
93 else
94 ret = hrtimer_try_to_cancel(&alrm->u.hrt);
95 return ret;
96}
97
98static void devalarm_cancel(struct devalarm *alrm)
99{
100 if (is_wakeup(alrm->type))
101 alarm_cancel(&alrm->u.alrm);
102 else
103 hrtimer_cancel(&alrm->u.hrt);
104}
105
70 106
71static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 107static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
72{ 108{
@@ -75,6 +111,8 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
75 struct timespec new_alarm_time; 111 struct timespec new_alarm_time;
76 struct timespec new_rtc_time; 112 struct timespec new_rtc_time;
77 struct timespec tmp_time; 113 struct timespec tmp_time;
114 struct rtc_time new_rtc_tm;
115 struct rtc_device *rtc_dev;
78 enum android_alarm_type alarm_type = ANDROID_ALARM_IOCTL_TO_TYPE(cmd); 116 enum android_alarm_type alarm_type = ANDROID_ALARM_IOCTL_TO_TYPE(cmd);
79 uint32_t alarm_type_mask = 1U << alarm_type; 117 uint32_t alarm_type_mask = 1U << alarm_type;
80 118
@@ -101,11 +139,11 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
101 case ANDROID_ALARM_CLEAR(0): 139 case ANDROID_ALARM_CLEAR(0):
102 spin_lock_irqsave(&alarm_slock, flags); 140 spin_lock_irqsave(&alarm_slock, flags);
103 pr_alarm(IO, "alarm %d clear\n", alarm_type); 141 pr_alarm(IO, "alarm %d clear\n", alarm_type);
104 android_alarm_try_to_cancel(&alarms[alarm_type]); 142 devalarm_try_to_cancel(&alarms[alarm_type]);
105 if (alarm_pending) { 143 if (alarm_pending) {
106 alarm_pending &= ~alarm_type_mask; 144 alarm_pending &= ~alarm_type_mask;
107 if (!alarm_pending && !wait_pending) 145 if (!alarm_pending && !wait_pending)
108 wake_unlock(&alarm_wake_lock); 146 __pm_relax(&alarm_wake_lock);
109 } 147 }
110 alarm_enabled &= ~alarm_type_mask; 148 alarm_enabled &= ~alarm_type_mask;
111 spin_unlock_irqrestore(&alarm_slock, flags); 149 spin_unlock_irqrestore(&alarm_slock, flags);
@@ -132,8 +170,7 @@ from_old_alarm_set:
132 pr_alarm(IO, "alarm %d set %ld.%09ld\n", alarm_type, 170 pr_alarm(IO, "alarm %d set %ld.%09ld\n", alarm_type,
133 new_alarm_time.tv_sec, new_alarm_time.tv_nsec); 171 new_alarm_time.tv_sec, new_alarm_time.tv_nsec);
134 alarm_enabled |= alarm_type_mask; 172 alarm_enabled |= alarm_type_mask;
135 android_alarm_start_range(&alarms[alarm_type], 173 devalarm_start(&alarms[alarm_type],
136 timespec_to_ktime(new_alarm_time),
137 timespec_to_ktime(new_alarm_time)); 174 timespec_to_ktime(new_alarm_time));
138 spin_unlock_irqrestore(&alarm_slock, flags); 175 spin_unlock_irqrestore(&alarm_slock, flags);
139 if (ANDROID_ALARM_BASE_CMD(cmd) != ANDROID_ALARM_SET_AND_WAIT(0) 176 if (ANDROID_ALARM_BASE_CMD(cmd) != ANDROID_ALARM_SET_AND_WAIT(0)
@@ -144,7 +181,7 @@ from_old_alarm_set:
144 spin_lock_irqsave(&alarm_slock, flags); 181 spin_lock_irqsave(&alarm_slock, flags);
145 pr_alarm(IO, "alarm wait\n"); 182 pr_alarm(IO, "alarm wait\n");
146 if (!alarm_pending && wait_pending) { 183 if (!alarm_pending && wait_pending) {
147 wake_unlock(&alarm_wake_lock); 184 __pm_relax(&alarm_wake_lock);
148 wait_pending = 0; 185 wait_pending = 0;
149 } 186 }
150 spin_unlock_irqrestore(&alarm_slock, flags); 187 spin_unlock_irqrestore(&alarm_slock, flags);
@@ -163,7 +200,13 @@ from_old_alarm_set:
163 rv = -EFAULT; 200 rv = -EFAULT;
164 goto err1; 201 goto err1;
165 } 202 }
166 rv = android_alarm_set_rtc(new_rtc_time); 203 rtc_time_to_tm(new_rtc_time.tv_sec, &new_rtc_tm);
204 rtc_dev = alarmtimer_get_rtcdev();
205 rv = do_settimeofday(&new_rtc_time);
206 if (rv < 0)
207 goto err1;
208 if (rtc_dev)
209 rv = rtc_set_time(rtc_dev, &new_rtc_tm);
167 spin_lock_irqsave(&alarm_slock, flags); 210 spin_lock_irqsave(&alarm_slock, flags);
168 alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK; 211 alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK;
169 wake_up(&alarm_wait_queue); 212 wake_up(&alarm_wait_queue);
@@ -179,8 +222,7 @@ from_old_alarm_set:
179 break; 222 break;
180 case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP: 223 case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP:
181 case ANDROID_ALARM_ELAPSED_REALTIME: 224 case ANDROID_ALARM_ELAPSED_REALTIME:
182 tmp_time = 225 get_monotonic_boottime(&tmp_time);
183 ktime_to_timespec(alarm_get_elapsed_realtime());
184 break; 226 break;
185 case ANDROID_ALARM_TYPE_COUNT: 227 case ANDROID_ALARM_TYPE_COUNT:
186 case ANDROID_ALARM_SYSTEMTIME: 228 case ANDROID_ALARM_SYSTEMTIME:
@@ -224,14 +266,14 @@ static int alarm_release(struct inode *inode, struct file *file)
224 alarm_enabled &= ~alarm_type_mask; 266 alarm_enabled &= ~alarm_type_mask;
225 } 267 }
226 spin_unlock_irqrestore(&alarm_slock, flags); 268 spin_unlock_irqrestore(&alarm_slock, flags);
227 android_alarm_cancel(&alarms[i]); 269 devalarm_cancel(&alarms[i]);
228 spin_lock_irqsave(&alarm_slock, flags); 270 spin_lock_irqsave(&alarm_slock, flags);
229 } 271 }
230 if (alarm_pending | wait_pending) { 272 if (alarm_pending | wait_pending) {
231 if (alarm_pending) 273 if (alarm_pending)
232 pr_alarm(INFO, "alarm_release: clear " 274 pr_alarm(INFO, "alarm_release: clear "
233 "pending alarms %x\n", alarm_pending); 275 "pending alarms %x\n", alarm_pending);
234 wake_unlock(&alarm_wake_lock); 276 __pm_relax(&alarm_wake_lock);
235 wait_pending = 0; 277 wait_pending = 0;
236 alarm_pending = 0; 278 alarm_pending = 0;
237 } 279 }
@@ -241,15 +283,15 @@ static int alarm_release(struct inode *inode, struct file *file)
241 return 0; 283 return 0;
242} 284}
243 285
244static void alarm_triggered(struct android_alarm *alarm) 286static void devalarm_triggered(struct devalarm *alarm)
245{ 287{
246 unsigned long flags; 288 unsigned long flags;
247 uint32_t alarm_type_mask = 1U << alarm->type; 289 uint32_t alarm_type_mask = 1U << alarm->type;
248 290
249 pr_alarm(INT, "alarm_triggered type %d\n", alarm->type); 291 pr_alarm(INT, "devalarm_triggered type %d\n", alarm->type);
250 spin_lock_irqsave(&alarm_slock, flags); 292 spin_lock_irqsave(&alarm_slock, flags);
251 if (alarm_enabled & alarm_type_mask) { 293 if (alarm_enabled & alarm_type_mask) {
252 wake_lock_timeout(&alarm_wake_lock, 5 * HZ); 294 __pm_wakeup_event(&alarm_wake_lock, 5000); /* 5secs */
253 alarm_enabled &= ~alarm_type_mask; 295 alarm_enabled &= ~alarm_type_mask;
254 alarm_pending |= alarm_type_mask; 296 alarm_pending |= alarm_type_mask;
255 wake_up(&alarm_wait_queue); 297 wake_up(&alarm_wait_queue);
@@ -257,6 +299,25 @@ static void alarm_triggered(struct android_alarm *alarm)
257 spin_unlock_irqrestore(&alarm_slock, flags); 299 spin_unlock_irqrestore(&alarm_slock, flags);
258} 300}
259 301
302
303static enum hrtimer_restart devalarm_hrthandler(struct hrtimer *hrt)
304{
305 struct devalarm *devalrm = container_of(hrt, struct devalarm, u.hrt);
306
307 devalarm_triggered(devalrm);
308 return HRTIMER_NORESTART;
309}
310
311static enum alarmtimer_restart devalarm_alarmhandler(struct alarm *alrm,
312 ktime_t now)
313{
314 struct devalarm *devalrm = container_of(alrm, struct devalarm, u.alrm);
315
316 devalarm_triggered(devalrm);
317 return ALARMTIMER_NORESTART;
318}
319
320
260static const struct file_operations alarm_fops = { 321static const struct file_operations alarm_fops = {
261 .owner = THIS_MODULE, 322 .owner = THIS_MODULE,
262 .unlocked_ioctl = alarm_ioctl, 323 .unlocked_ioctl = alarm_ioctl,
@@ -279,17 +340,31 @@ static int __init alarm_dev_init(void)
279 if (err) 340 if (err)
280 return err; 341 return err;
281 342
282 for (i = 0; i < ANDROID_ALARM_TYPE_COUNT; i++) 343 alarm_init(&alarms[ANDROID_ALARM_RTC_WAKEUP].u.alrm,
283 android_alarm_init(&alarms[i], i, alarm_triggered); 344 ALARM_REALTIME, devalarm_alarmhandler);
284 wake_lock_init(&alarm_wake_lock, WAKE_LOCK_SUSPEND, "alarm"); 345 hrtimer_init(&alarms[ANDROID_ALARM_RTC].u.hrt,
346 CLOCK_REALTIME, HRTIMER_MODE_ABS);
347 alarm_init(&alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].u.alrm,
348 ALARM_BOOTTIME, devalarm_alarmhandler);
349 hrtimer_init(&alarms[ANDROID_ALARM_ELAPSED_REALTIME].u.hrt,
350 CLOCK_BOOTTIME, HRTIMER_MODE_ABS);
351 hrtimer_init(&alarms[ANDROID_ALARM_SYSTEMTIME].u.hrt,
352 CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
353
354 for (i = 0; i < ANDROID_ALARM_TYPE_COUNT; i++) {
355 alarms[i].type = i;
356 if (!is_wakeup(i))
357 alarms[i].u.hrt.function = devalarm_hrthandler;
358 }
285 359
360 wakeup_source_init(&alarm_wake_lock, "alarm");
286 return 0; 361 return 0;
287} 362}
288 363
289static void __exit alarm_dev_exit(void) 364static void __exit alarm_dev_exit(void)
290{ 365{
291 misc_deregister(&alarm_device); 366 misc_deregister(&alarm_device);
292 wake_lock_destroy(&alarm_wake_lock); 367 wakeup_source_trash(&alarm_wake_lock);
293} 368}
294 369
295module_init(alarm_dev_init); 370module_init(alarm_dev_init);
diff --git a/drivers/staging/android/alarm.c b/drivers/staging/android/alarm.c
deleted file mode 100644
index c68950b9e08f..000000000000
--- a/drivers/staging/android/alarm.c
+++ /dev/null
@@ -1,601 +0,0 @@
1/* drivers/rtc/alarm.c
2 *
3 * Copyright (C) 2007-2009 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <linux/time.h>
17#include <linux/module.h>
18#include <linux/device.h>
19#include <linux/miscdevice.h>
20#include <linux/platform_device.h>
21#include <linux/rtc.h>
22#include <linux/sched.h>
23#include <linux/spinlock.h>
24#include "android_alarm.h"
25
26/* XXX - Hack out wakelocks, while they are out of tree */
27struct wake_lock {
28 int i;
29};
30#define wake_lock(x)
31#define wake_lock_timeout(x, y)
32#define wake_unlock(x)
33#define WAKE_LOCK_SUSPEND 0
34#define wake_lock_init(x, y, z) ((x)->i = 1)
35#define wake_lock_destroy(x)
36
37#define ANDROID_ALARM_PRINT_ERROR (1U << 0)
38#define ANDROID_ALARM_PRINT_INIT_STATUS (1U << 1)
39#define ANDROID_ALARM_PRINT_TSET (1U << 2)
40#define ANDROID_ALARM_PRINT_CALL (1U << 3)
41#define ANDROID_ALARM_PRINT_SUSPEND (1U << 4)
42#define ANDROID_ALARM_PRINT_INT (1U << 5)
43#define ANDROID_ALARM_PRINT_FLOW (1U << 6)
44
45static int debug_mask = ANDROID_ALARM_PRINT_ERROR | \
46 ANDROID_ALARM_PRINT_INIT_STATUS;
47module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
48
49#define pr_alarm(debug_level_mask, args...) \
50 do { \
51 if (debug_mask & ANDROID_ALARM_PRINT_##debug_level_mask) { \
52 pr_info(args); \
53 } \
54 } while (0)
55
56#define ANDROID_ALARM_WAKEUP_MASK ( \
57 ANDROID_ALARM_RTC_WAKEUP_MASK | \
58 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK)
59
60/* support old usespace code */
61#define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */
62#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t)
63
64struct alarm_queue {
65 struct rb_root alarms;
66 struct rb_node *first;
67 struct hrtimer timer;
68 ktime_t delta;
69 bool stopped;
70 ktime_t stopped_time;
71};
72
73static struct rtc_device *alarm_rtc_dev;
74static DEFINE_SPINLOCK(alarm_slock);
75static DEFINE_MUTEX(alarm_setrtc_mutex);
76static struct wake_lock alarm_rtc_wake_lock;
77static struct platform_device *alarm_platform_dev;
78struct alarm_queue alarms[ANDROID_ALARM_TYPE_COUNT];
79static bool suspended;
80
81static void update_timer_locked(struct alarm_queue *base, bool head_removed)
82{
83 struct android_alarm *alarm;
84 bool is_wakeup = base == &alarms[ANDROID_ALARM_RTC_WAKEUP] ||
85 base == &alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP];
86
87 if (base->stopped) {
88 pr_alarm(FLOW, "changed alarm while setting the wall time\n");
89 return;
90 }
91
92 if (is_wakeup && !suspended && head_removed)
93 wake_unlock(&alarm_rtc_wake_lock);
94
95 if (!base->first)
96 return;
97
98 alarm = container_of(base->first, struct android_alarm, node);
99
100 pr_alarm(FLOW, "selected alarm, type %d, func %pF at %lld\n",
101 alarm->type, alarm->function, ktime_to_ns(alarm->expires));
102
103 if (is_wakeup && suspended) {
104 pr_alarm(FLOW, "changed alarm while suspened\n");
105 wake_lock_timeout(&alarm_rtc_wake_lock, 1 * HZ);
106 return;
107 }
108
109 hrtimer_try_to_cancel(&base->timer);
110 base->timer.node.expires = ktime_add(base->delta, alarm->expires);
111 base->timer._softexpires = ktime_add(base->delta, alarm->softexpires);
112 hrtimer_start_expires(&base->timer, HRTIMER_MODE_ABS);
113}
114
115static void alarm_enqueue_locked(struct android_alarm *alarm)
116{
117 struct alarm_queue *base = &alarms[alarm->type];
118 struct rb_node **link = &base->alarms.rb_node;
119 struct rb_node *parent = NULL;
120 struct android_alarm *entry;
121 int leftmost = 1;
122 bool was_first = false;
123
124 pr_alarm(FLOW, "added alarm, type %d, func %pF at %lld\n",
125 alarm->type, alarm->function, ktime_to_ns(alarm->expires));
126
127 if (base->first == &alarm->node) {
128 base->first = rb_next(&alarm->node);
129 was_first = true;
130 }
131 if (!RB_EMPTY_NODE(&alarm->node)) {
132 rb_erase(&alarm->node, &base->alarms);
133 RB_CLEAR_NODE(&alarm->node);
134 }
135
136 while (*link) {
137 parent = *link;
138 entry = rb_entry(parent, struct android_alarm, node);
139 /*
140 * We dont care about collisions. Nodes with
141 * the same expiry time stay together.
142 */
143 if (alarm->expires.tv64 < entry->expires.tv64) {
144 link = &(*link)->rb_left;
145 } else {
146 link = &(*link)->rb_right;
147 leftmost = 0;
148 }
149 }
150 if (leftmost)
151 base->first = &alarm->node;
152 if (leftmost || was_first)
153 update_timer_locked(base, was_first);
154
155 rb_link_node(&alarm->node, parent, link);
156 rb_insert_color(&alarm->node, &base->alarms);
157}
158
159/**
160 * android_alarm_init - initialize an alarm
161 * @alarm: the alarm to be initialized
162 * @type: the alarm type to be used
163 * @function: alarm callback function
164 */
165void android_alarm_init(struct android_alarm *alarm,
166 enum android_alarm_type type, void (*function)(struct android_alarm *))
167{
168 RB_CLEAR_NODE(&alarm->node);
169 alarm->type = type;
170 alarm->function = function;
171
172 pr_alarm(FLOW, "created alarm, type %d, func %pF\n", type, function);
173}
174
175
176/**
177 * android_alarm_start_range - (re)start an alarm
178 * @alarm: the alarm to be added
179 * @start: earliest expiry time
180 * @end: expiry time
181 */
182void android_alarm_start_range(struct android_alarm *alarm, ktime_t start,
183 ktime_t end)
184{
185 unsigned long flags;
186
187 spin_lock_irqsave(&alarm_slock, flags);
188 alarm->softexpires = start;
189 alarm->expires = end;
190 alarm_enqueue_locked(alarm);
191 spin_unlock_irqrestore(&alarm_slock, flags);
192}
193
194/**
195 * android_alarm_try_to_cancel - try to deactivate an alarm
196 * @alarm: alarm to stop
197 *
198 * Returns:
199 * 0 when the alarm was not active
200 * 1 when the alarm was active
201 * -1 when the alarm may currently be excuting the callback function and
202 * cannot be stopped (it may also be inactive)
203 */
204int android_alarm_try_to_cancel(struct android_alarm *alarm)
205{
206 struct alarm_queue *base = &alarms[alarm->type];
207 unsigned long flags;
208 bool first = false;
209 int ret = 0;
210
211 spin_lock_irqsave(&alarm_slock, flags);
212 if (!RB_EMPTY_NODE(&alarm->node)) {
213 pr_alarm(FLOW, "canceled alarm, type %d, func %pF at %lld\n",
214 alarm->type, alarm->function,
215 ktime_to_ns(alarm->expires));
216 ret = 1;
217 if (base->first == &alarm->node) {
218 base->first = rb_next(&alarm->node);
219 first = true;
220 }
221 rb_erase(&alarm->node, &base->alarms);
222 RB_CLEAR_NODE(&alarm->node);
223 if (first)
224 update_timer_locked(base, true);
225 } else
226 pr_alarm(FLOW, "tried to cancel alarm, type %d, func %pF\n",
227 alarm->type, alarm->function);
228 spin_unlock_irqrestore(&alarm_slock, flags);
229 if (!ret && hrtimer_callback_running(&base->timer))
230 ret = -1;
231 return ret;
232}
233
234/**
235 * android_alarm_cancel - cancel an alarm and wait for the handler to finish.
236 * @alarm: the alarm to be cancelled
237 *
238 * Returns:
239 * 0 when the alarm was not active
240 * 1 when the alarm was active
241 */
242int android_alarm_cancel(struct android_alarm *alarm)
243{
244 for (;;) {
245 int ret = android_alarm_try_to_cancel(alarm);
246 if (ret >= 0)
247 return ret;
248 cpu_relax();
249 }
250}
251
252/**
253 * alarm_set_rtc - set the kernel and rtc walltime
254 * @new_time: timespec value containing the new time
255 */
256int android_alarm_set_rtc(struct timespec new_time)
257{
258 int i;
259 int ret;
260 unsigned long flags;
261 struct rtc_time rtc_new_rtc_time;
262 struct timespec tmp_time;
263
264 rtc_time_to_tm(new_time.tv_sec, &rtc_new_rtc_time);
265
266 pr_alarm(TSET, "set rtc %ld %ld - rtc %02d:%02d:%02d %02d/%02d/%04d\n",
267 new_time.tv_sec, new_time.tv_nsec,
268 rtc_new_rtc_time.tm_hour, rtc_new_rtc_time.tm_min,
269 rtc_new_rtc_time.tm_sec, rtc_new_rtc_time.tm_mon + 1,
270 rtc_new_rtc_time.tm_mday,
271 rtc_new_rtc_time.tm_year + 1900);
272
273 mutex_lock(&alarm_setrtc_mutex);
274 spin_lock_irqsave(&alarm_slock, flags);
275 wake_lock(&alarm_rtc_wake_lock);
276 getnstimeofday(&tmp_time);
277 for (i = 0; i < ANDROID_ALARM_SYSTEMTIME; i++) {
278 hrtimer_try_to_cancel(&alarms[i].timer);
279 alarms[i].stopped = true;
280 alarms[i].stopped_time = timespec_to_ktime(tmp_time);
281 }
282 alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].delta =
283 alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta =
284 ktime_sub(alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta,
285 timespec_to_ktime(timespec_sub(tmp_time, new_time)));
286 spin_unlock_irqrestore(&alarm_slock, flags);
287 ret = do_settimeofday(&new_time);
288 spin_lock_irqsave(&alarm_slock, flags);
289 for (i = 0; i < ANDROID_ALARM_SYSTEMTIME; i++) {
290 alarms[i].stopped = false;
291 update_timer_locked(&alarms[i], false);
292 }
293 spin_unlock_irqrestore(&alarm_slock, flags);
294 if (ret < 0) {
295 pr_alarm(ERROR, "alarm_set_rtc: Failed to set time\n");
296 goto err;
297 }
298 if (!alarm_rtc_dev) {
299 pr_alarm(ERROR,
300 "alarm_set_rtc: no RTC, time will be lost on reboot\n");
301 goto err;
302 }
303 ret = rtc_set_time(alarm_rtc_dev, &rtc_new_rtc_time);
304 if (ret < 0)
305 pr_alarm(ERROR, "alarm_set_rtc: "
306 "Failed to set RTC, time will be lost on reboot\n");
307err:
308 wake_unlock(&alarm_rtc_wake_lock);
309 mutex_unlock(&alarm_setrtc_mutex);
310 return ret;
311}
312
313/**
314 * alarm_get_elapsed_realtime - get the elapsed real time in ktime_t format
315 *
316 * returns the time in ktime_t format
317 */
318ktime_t alarm_get_elapsed_realtime(void)
319{
320 ktime_t now;
321 unsigned long flags;
322 struct alarm_queue *base = &alarms[ANDROID_ALARM_ELAPSED_REALTIME];
323
324 spin_lock_irqsave(&alarm_slock, flags);
325 now = base->stopped ? base->stopped_time : ktime_get_real();
326 now = ktime_sub(now, base->delta);
327 spin_unlock_irqrestore(&alarm_slock, flags);
328 return now;
329}
330
331static enum hrtimer_restart alarm_timer_triggered(struct hrtimer *timer)
332{
333 struct alarm_queue *base;
334 struct android_alarm *alarm;
335 unsigned long flags;
336 ktime_t now;
337
338 spin_lock_irqsave(&alarm_slock, flags);
339
340 base = container_of(timer, struct alarm_queue, timer);
341 now = base->stopped ? base->stopped_time : hrtimer_cb_get_time(timer);
342 now = ktime_sub(now, base->delta);
343
344 pr_alarm(INT, "alarm_timer_triggered type %ld at %lld\n",
345 base - alarms, ktime_to_ns(now));
346
347 while (base->first) {
348 alarm = container_of(base->first, struct android_alarm, node);
349 if (alarm->softexpires.tv64 > now.tv64) {
350 pr_alarm(FLOW, "don't call alarm, %pF, %lld (s %lld)\n",
351 alarm->function, ktime_to_ns(alarm->expires),
352 ktime_to_ns(alarm->softexpires));
353 break;
354 }
355 base->first = rb_next(&alarm->node);
356 rb_erase(&alarm->node, &base->alarms);
357 RB_CLEAR_NODE(&alarm->node);
358 pr_alarm(CALL, "call alarm, type %d, func %pF, %lld (s %lld)\n",
359 alarm->type, alarm->function,
360 ktime_to_ns(alarm->expires),
361 ktime_to_ns(alarm->softexpires));
362 spin_unlock_irqrestore(&alarm_slock, flags);
363 alarm->function(alarm);
364 spin_lock_irqsave(&alarm_slock, flags);
365 }
366 if (!base->first)
367 pr_alarm(FLOW, "no more alarms of type %ld\n", base - alarms);
368 update_timer_locked(base, true);
369 spin_unlock_irqrestore(&alarm_slock, flags);
370 return HRTIMER_NORESTART;
371}
372
373static void alarm_triggered_func(void *p)
374{
375 struct rtc_device *rtc = alarm_rtc_dev;
376 if (!(rtc->irq_data & RTC_AF))
377 return;
378 pr_alarm(INT, "rtc alarm triggered\n");
379 wake_lock_timeout(&alarm_rtc_wake_lock, 1 * HZ);
380}
381
382static int alarm_suspend(struct platform_device *pdev, pm_message_t state)
383{
384 int err = 0;
385 unsigned long flags;
386 struct rtc_wkalrm rtc_alarm;
387 struct rtc_time rtc_current_rtc_time;
388 unsigned long rtc_current_time;
389 unsigned long rtc_alarm_time;
390 struct timespec rtc_delta;
391 struct timespec wall_time;
392 struct alarm_queue *wakeup_queue = NULL;
393 struct alarm_queue *tmp_queue = NULL;
394
395 pr_alarm(SUSPEND, "alarm_suspend(%p, %d)\n", pdev, state.event);
396
397 spin_lock_irqsave(&alarm_slock, flags);
398 suspended = true;
399 spin_unlock_irqrestore(&alarm_slock, flags);
400
401 hrtimer_cancel(&alarms[ANDROID_ALARM_RTC_WAKEUP].timer);
402 hrtimer_cancel(&alarms[
403 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].timer);
404
405 tmp_queue = &alarms[ANDROID_ALARM_RTC_WAKEUP];
406 if (tmp_queue->first)
407 wakeup_queue = tmp_queue;
408 tmp_queue = &alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP];
409 if (tmp_queue->first && (!wakeup_queue ||
410 hrtimer_get_expires(&tmp_queue->timer).tv64 <
411 hrtimer_get_expires(&wakeup_queue->timer).tv64))
412 wakeup_queue = tmp_queue;
413 if (wakeup_queue) {
414 rtc_read_time(alarm_rtc_dev, &rtc_current_rtc_time);
415 getnstimeofday(&wall_time);
416 rtc_tm_to_time(&rtc_current_rtc_time, &rtc_current_time);
417 set_normalized_timespec(&rtc_delta,
418 wall_time.tv_sec - rtc_current_time,
419 wall_time.tv_nsec);
420
421 rtc_alarm_time = timespec_sub(ktime_to_timespec(
422 hrtimer_get_expires(&wakeup_queue->timer)),
423 rtc_delta).tv_sec;
424
425 rtc_time_to_tm(rtc_alarm_time, &rtc_alarm.time);
426 rtc_alarm.enabled = 1;
427 rtc_set_alarm(alarm_rtc_dev, &rtc_alarm);
428 rtc_read_time(alarm_rtc_dev, &rtc_current_rtc_time);
429 rtc_tm_to_time(&rtc_current_rtc_time, &rtc_current_time);
430 pr_alarm(SUSPEND,
431 "rtc alarm set at %ld, now %ld, rtc delta %ld.%09ld\n",
432 rtc_alarm_time, rtc_current_time,
433 rtc_delta.tv_sec, rtc_delta.tv_nsec);
434 if (rtc_current_time + 1 >= rtc_alarm_time) {
435 pr_alarm(SUSPEND, "alarm about to go off\n");
436 memset(&rtc_alarm, 0, sizeof(rtc_alarm));
437 rtc_alarm.enabled = 0;
438 rtc_set_alarm(alarm_rtc_dev, &rtc_alarm);
439
440 spin_lock_irqsave(&alarm_slock, flags);
441 suspended = false;
442 wake_lock_timeout(&alarm_rtc_wake_lock, 2 * HZ);
443 update_timer_locked(&alarms[ANDROID_ALARM_RTC_WAKEUP],
444 false);
445 update_timer_locked(&alarms[
446 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP], false);
447 err = -EBUSY;
448 spin_unlock_irqrestore(&alarm_slock, flags);
449 }
450 }
451 return err;
452}
453
454static int alarm_resume(struct platform_device *pdev)
455{
456 struct rtc_wkalrm alarm;
457 unsigned long flags;
458
459 pr_alarm(SUSPEND, "alarm_resume(%p)\n", pdev);
460
461 memset(&alarm, 0, sizeof(alarm));
462 alarm.enabled = 0;
463 rtc_set_alarm(alarm_rtc_dev, &alarm);
464
465 spin_lock_irqsave(&alarm_slock, flags);
466 suspended = false;
467 update_timer_locked(&alarms[ANDROID_ALARM_RTC_WAKEUP], false);
468 update_timer_locked(&alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP],
469 false);
470 spin_unlock_irqrestore(&alarm_slock, flags);
471
472 return 0;
473}
474
475static struct rtc_task alarm_rtc_task = {
476 .func = alarm_triggered_func
477};
478
479static int rtc_alarm_add_device(struct device *dev,
480 struct class_interface *class_intf)
481{
482 int err;
483 struct rtc_device *rtc = to_rtc_device(dev);
484
485 mutex_lock(&alarm_setrtc_mutex);
486
487 if (alarm_rtc_dev) {
488 err = -EBUSY;
489 goto err1;
490 }
491
492 alarm_platform_dev =
493 platform_device_register_simple("alarm", -1, NULL, 0);
494 if (IS_ERR(alarm_platform_dev)) {
495 err = PTR_ERR(alarm_platform_dev);
496 goto err2;
497 }
498 err = rtc_irq_register(rtc, &alarm_rtc_task);
499 if (err)
500 goto err3;
501 alarm_rtc_dev = rtc;
502 pr_alarm(INIT_STATUS, "using rtc device, %s, for alarms", rtc->name);
503 mutex_unlock(&alarm_setrtc_mutex);
504
505 return 0;
506
507err3:
508 platform_device_unregister(alarm_platform_dev);
509err2:
510err1:
511 mutex_unlock(&alarm_setrtc_mutex);
512 return err;
513}
514
515static void rtc_alarm_remove_device(struct device *dev,
516 struct class_interface *class_intf)
517{
518 if (dev == &alarm_rtc_dev->dev) {
519 pr_alarm(INIT_STATUS, "lost rtc device for alarms");
520 rtc_irq_unregister(alarm_rtc_dev, &alarm_rtc_task);
521 platform_device_unregister(alarm_platform_dev);
522 alarm_rtc_dev = NULL;
523 }
524}
525
526static struct class_interface rtc_alarm_interface = {
527 .add_dev = &rtc_alarm_add_device,
528 .remove_dev = &rtc_alarm_remove_device,
529};
530
531static struct platform_driver alarm_driver = {
532 .suspend = alarm_suspend,
533 .resume = alarm_resume,
534 .driver = {
535 .name = "alarm"
536 }
537};
538
539static int __init alarm_late_init(void)
540{
541 unsigned long flags;
542 struct timespec tmp_time, system_time;
543
544 /* this needs to run after the rtc is read at boot */
545 spin_lock_irqsave(&alarm_slock, flags);
546 /* We read the current rtc and system time so we can later calulate
547 * elasped realtime to be (boot_systemtime + rtc - boot_rtc) ==
548 * (rtc - (boot_rtc - boot_systemtime))
549 */
550 getnstimeofday(&tmp_time);
551 ktime_get_ts(&system_time);
552 alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].delta =
553 alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta =
554 timespec_to_ktime(timespec_sub(tmp_time, system_time));
555
556 spin_unlock_irqrestore(&alarm_slock, flags);
557 return 0;
558}
559
560static int __init alarm_driver_init(void)
561{
562 int err;
563 int i;
564
565 for (i = 0; i < ANDROID_ALARM_SYSTEMTIME; i++) {
566 hrtimer_init(&alarms[i].timer,
567 CLOCK_REALTIME, HRTIMER_MODE_ABS);
568 alarms[i].timer.function = alarm_timer_triggered;
569 }
570 hrtimer_init(&alarms[ANDROID_ALARM_SYSTEMTIME].timer,
571 CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
572 alarms[ANDROID_ALARM_SYSTEMTIME].timer.function = alarm_timer_triggered;
573 err = platform_driver_register(&alarm_driver);
574 if (err < 0)
575 goto err1;
576 wake_lock_init(&alarm_rtc_wake_lock, WAKE_LOCK_SUSPEND, "alarm_rtc");
577 rtc_alarm_interface.class = rtc_class;
578 err = class_interface_register(&rtc_alarm_interface);
579 if (err < 0)
580 goto err2;
581
582 return 0;
583
584err2:
585 wake_lock_destroy(&alarm_rtc_wake_lock);
586 platform_driver_unregister(&alarm_driver);
587err1:
588 return err;
589}
590
591static void __exit alarm_exit(void)
592{
593 class_interface_unregister(&rtc_alarm_interface);
594 wake_lock_destroy(&alarm_rtc_wake_lock);
595 platform_driver_unregister(&alarm_driver);
596}
597
598late_initcall(alarm_late_init);
599module_init(alarm_driver_init);
600module_exit(alarm_exit);
601
diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h
index 6eecbde2ef6f..d0cafd637199 100644
--- a/drivers/staging/android/android_alarm.h
+++ b/drivers/staging/android/android_alarm.h
@@ -33,65 +33,6 @@ enum android_alarm_type {
33 /* ANDROID_ALARM_TIME_CHANGE = 16 */ 33 /* ANDROID_ALARM_TIME_CHANGE = 16 */
34}; 34};
35 35
36#ifdef __KERNEL__
37
38#include <linux/ktime.h>
39#include <linux/rbtree.h>
40
41/*
42 * The alarm interface is similar to the hrtimer interface but adds support
43 * for wakeup from suspend. It also adds an elapsed realtime clock that can
44 * be used for periodic timers that need to keep runing while the system is
45 * suspended and not be disrupted when the wall time is set.
46 */
47
48/**
49 * struct alarm - the basic alarm structure
50 * @node: red black tree node for time ordered insertion
51 * @type: alarm type. rtc/elapsed-realtime/systemtime, wakeup/non-wakeup.
52 * @softexpires: the absolute earliest expiry time of the alarm.
53 * @expires: the absolute expiry time.
54 * @function: alarm expiry callback function
55 *
56 * The alarm structure must be initialized by alarm_init()
57 *
58 */
59
60struct android_alarm {
61 struct rb_node node;
62 enum android_alarm_type type;
63 ktime_t softexpires;
64 ktime_t expires;
65 void (*function)(struct android_alarm *);
66};
67
68void android_alarm_init(struct android_alarm *alarm,
69 enum android_alarm_type type, void (*function)(struct android_alarm *));
70void android_alarm_start_range(struct android_alarm *alarm, ktime_t start,
71 ktime_t end);
72int android_alarm_try_to_cancel(struct android_alarm *alarm);
73int android_alarm_cancel(struct android_alarm *alarm);
74ktime_t alarm_get_elapsed_realtime(void);
75
76/* set rtc while preserving elapsed realtime */
77int android_alarm_set_rtc(const struct timespec ts);
78
79#ifdef CONFIG_ANDROID_ALARM_OLDDRV_COMPAT
80/*
81 * Some older drivers depend on the old API,
82 * so provide compatability macros for now.
83 */
84#define alarm android_alarm
85#define alarm_init(x, y, z) android_alarm_init(x, y, z)
86#define alarm_start_range(x, y, z) android_alarm_start_range(x, y, z)
87#define alarm_try_to_cancel(x) android_alarm_try_to_cancel(x)
88#define alarm_cancel(x) android_alarm_cancel(x)
89#define alarm_set_rtc(x) android_alarm_set_rtc(x)
90#endif
91
92
93#endif
94
95enum android_alarm_return_flags { 36enum android_alarm_return_flags {
96 ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP, 37 ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP,
97 ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC, 38 ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC,
diff --git a/drivers/staging/android/binder.h b/drivers/staging/android/binder.h
index 25ab6f2759e9..2f7d195d8b15 100644
--- a/drivers/staging/android/binder.h
+++ b/drivers/staging/android/binder.h
@@ -53,17 +53,17 @@ struct flat_binder_object {
53 53
54 /* 8 bytes of data. */ 54 /* 8 bytes of data. */
55 union { 55 union {
56 void *binder; /* local object */ 56 void __user *binder; /* local object */
57 signed long handle; /* remote object */ 57 signed long handle; /* remote object */
58 }; 58 };
59 59
60 /* extra data associated with local object */ 60 /* extra data associated with local object */
61 void *cookie; 61 void __user *cookie;
62}; 62};
63 63
64/* 64/*
65 * On 64-bit platforms where user code may run in 32-bits the driver must 65 * On 64-bit platforms where user code may run in 32-bits the driver must
66 * translate the buffer (and local binder) addresses apropriately. 66 * translate the buffer (and local binder) addresses appropriately.
67 */ 67 */
68 68
69struct binder_write_read { 69struct binder_write_read {
@@ -139,9 +139,9 @@ struct binder_transaction_data {
139 union { 139 union {
140 struct { 140 struct {
141 /* transaction data */ 141 /* transaction data */
142 const void *buffer; 142 const void __user *buffer;
143 /* offsets from buffer to flat_binder_object structs */ 143 /* offsets from buffer to flat_binder_object structs */
144 const void *offsets; 144 const void __user *offsets;
145 } ptr; 145 } ptr;
146 uint8_t buf[8]; 146 uint8_t buf[8];
147 } data; 147 } data;
diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c
index ea69b6a77dac..b2e71c6fd175 100644
--- a/drivers/staging/android/logger.c
+++ b/drivers/staging/android/logger.c
@@ -25,6 +25,7 @@
25#include <linux/poll.h> 25#include <linux/poll.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/vmalloc.h>
28#include "logger.h" 29#include "logger.h"
29 30
30#include <asm/ioctls.h> 31#include <asm/ioctls.h>
@@ -45,8 +46,12 @@ struct logger_log {
45 size_t w_off; /* current write head offset */ 46 size_t w_off; /* current write head offset */
46 size_t head; /* new readers start here */ 47 size_t head; /* new readers start here */
47 size_t size; /* size of the log */ 48 size_t size; /* size of the log */
49 struct list_head logs; /* list of log channels (myself)*/
48}; 50};
49 51
52static LIST_HEAD(log_list);
53
54
50/* 55/*
51 * struct logger_reader - a logging device open for reading 56 * struct logger_reader - a logging device open for reading
52 * 57 *
@@ -60,9 +65,9 @@ struct logger_reader {
60}; 65};
61 66
62/* logger_offset - returns index 'n' into the log via (optimized) modulus */ 67/* logger_offset - returns index 'n' into the log via (optimized) modulus */
63size_t logger_offset(struct logger_log *log, size_t n) 68static size_t logger_offset(struct logger_log *log, size_t n)
64{ 69{
65 return n & (log->size-1); 70 return n & (log->size - 1);
66} 71}
67 72
68 73
@@ -348,7 +353,7 @@ static ssize_t do_write_log_from_user(struct logger_log *log,
348 * writev(), and aio_write(). Writes are our fast path, and we try to optimize 353 * writev(), and aio_write(). Writes are our fast path, and we try to optimize
349 * them above all else. 354 * them above all else.
350 */ 355 */
351ssize_t logger_aio_write(struct kiocb *iocb, const struct iovec *iov, 356static ssize_t logger_aio_write(struct kiocb *iocb, const struct iovec *iov,
352 unsigned long nr_segs, loff_t ppos) 357 unsigned long nr_segs, loff_t ppos)
353{ 358{
354 struct logger_log *log = file_get_log(iocb->ki_filp); 359 struct logger_log *log = file_get_log(iocb->ki_filp);
@@ -408,7 +413,15 @@ ssize_t logger_aio_write(struct kiocb *iocb, const struct iovec *iov,
408 return ret; 413 return ret;
409} 414}
410 415
411static struct logger_log *get_log_from_minor(int); 416static struct logger_log *get_log_from_minor(int minor)
417{
418 struct logger_log *log;
419
420 list_for_each_entry(log, &log_list, logs)
421 if (log->misc.minor == minor)
422 return log;
423 return NULL;
424}
412 425
413/* 426/*
414 * logger_open - the log's open() file operation 427 * logger_open - the log's open() file operation
@@ -565,80 +578,84 @@ static const struct file_operations logger_fops = {
565}; 578};
566 579
567/* 580/*
568 * Defines a log structure with name 'NAME' and a size of 'SIZE' bytes, which 581 * Log size must be a power of two, greater than LOGGER_ENTRY_MAX_LEN,
569 * must be a power of two, greater than LOGGER_ENTRY_MAX_LEN, and less than 582 * and less than LONG_MAX minus LOGGER_ENTRY_MAX_LEN.
570 * LONG_MAX minus LOGGER_ENTRY_MAX_LEN.
571 */ 583 */
572#define DEFINE_LOGGER_DEVICE(VAR, NAME, SIZE) \ 584static int __init create_log(char *log_name, int size)
573static unsigned char _buf_ ## VAR[SIZE]; \ 585{
574static struct logger_log VAR = { \ 586 int ret = 0;
575 .buffer = _buf_ ## VAR, \ 587 struct logger_log *log;
576 .misc = { \ 588 unsigned char *buffer;
577 .minor = MISC_DYNAMIC_MINOR, \
578 .name = NAME, \
579 .fops = &logger_fops, \
580 .parent = NULL, \
581 }, \
582 .wq = __WAIT_QUEUE_HEAD_INITIALIZER(VAR .wq), \
583 .readers = LIST_HEAD_INIT(VAR .readers), \
584 .mutex = __MUTEX_INITIALIZER(VAR .mutex), \
585 .w_off = 0, \
586 .head = 0, \
587 .size = SIZE, \
588};
589 589
590DEFINE_LOGGER_DEVICE(log_main, LOGGER_LOG_MAIN, 256*1024) 590 buffer = vmalloc(size);
591DEFINE_LOGGER_DEVICE(log_events, LOGGER_LOG_EVENTS, 256*1024) 591 if (buffer == NULL)
592DEFINE_LOGGER_DEVICE(log_radio, LOGGER_LOG_RADIO, 256*1024) 592 return -ENOMEM;
593DEFINE_LOGGER_DEVICE(log_system, LOGGER_LOG_SYSTEM, 256*1024)
594 593
595static struct logger_log *get_log_from_minor(int minor) 594 log = kzalloc(sizeof(struct logger_log), GFP_KERNEL);
596{ 595 if (log == NULL) {
597 if (log_main.misc.minor == minor) 596 ret = -ENOMEM;
598 return &log_main; 597 goto out_free_buffer;
599 if (log_events.misc.minor == minor) 598 }
600 return &log_events; 599 log->buffer = buffer;
601 if (log_radio.misc.minor == minor)
602 return &log_radio;
603 if (log_system.misc.minor == minor)
604 return &log_system;
605 return NULL;
606}
607 600
608static int __init init_log(struct logger_log *log) 601 log->misc.minor = MISC_DYNAMIC_MINOR;
609{ 602 log->misc.name = kstrdup(log_name, GFP_KERNEL);
610 int ret; 603 if (log->misc.name == NULL) {
604 ret = -ENOMEM;
605 goto out_free_log;
606 }
607
608 log->misc.fops = &logger_fops;
609 log->misc.parent = NULL;
611 610
611 init_waitqueue_head(&log->wq);
612 INIT_LIST_HEAD(&log->readers);
613 mutex_init(&log->mutex);
614 log->w_off = 0;
615 log->head = 0;
616 log->size = size;
617
618 INIT_LIST_HEAD(&log->logs);
619 list_add_tail(&log->logs, &log_list);
620
621 /* finally, initialize the misc device for this log */
612 ret = misc_register(&log->misc); 622 ret = misc_register(&log->misc);
613 if (unlikely(ret)) { 623 if (unlikely(ret)) {
614 printk(KERN_ERR "logger: failed to register misc " 624 printk(KERN_ERR "logger: failed to register misc "
615 "device for log '%s'!\n", log->misc.name); 625 "device for log '%s'!\n", log->misc.name);
616 return ret; 626 goto out_free_log;
617 } 627 }
618 628
619 printk(KERN_INFO "logger: created %luK log '%s'\n", 629 printk(KERN_INFO "logger: created %luK log '%s'\n",
620 (unsigned long) log->size >> 10, log->misc.name); 630 (unsigned long) log->size >> 10, log->misc.name);
621 631
622 return 0; 632 return 0;
633
634out_free_log:
635 kfree(log);
636
637out_free_buffer:
638 vfree(buffer);
639 return ret;
623} 640}
624 641
625static int __init logger_init(void) 642static int __init logger_init(void)
626{ 643{
627 int ret; 644 int ret;
628 645
629 ret = init_log(&log_main); 646 ret = create_log(LOGGER_LOG_MAIN, 256*1024);
630 if (unlikely(ret)) 647 if (unlikely(ret))
631 goto out; 648 goto out;
632 649
633 ret = init_log(&log_events); 650 ret = create_log(LOGGER_LOG_EVENTS, 256*1024);
634 if (unlikely(ret)) 651 if (unlikely(ret))
635 goto out; 652 goto out;
636 653
637 ret = init_log(&log_radio); 654 ret = create_log(LOGGER_LOG_RADIO, 256*1024);
638 if (unlikely(ret)) 655 if (unlikely(ret))
639 goto out; 656 goto out;
640 657
641 ret = init_log(&log_system); 658 ret = create_log(LOGGER_LOG_SYSTEM, 256*1024);
642 if (unlikely(ret)) 659 if (unlikely(ret))
643 goto out; 660 goto out;
644 661
diff --git a/drivers/staging/android/ram_console.c b/drivers/staging/android/ram_console.c
index ce140ffc54ea..82323bb1d1a3 100644
--- a/drivers/staging/android/ram_console.c
+++ b/drivers/staging/android/ram_console.c
@@ -21,7 +21,7 @@
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/uaccess.h> 22#include <linux/uaccess.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include "persistent_ram.h" 24#include <linux/pstore_ram.h>
25#include "ram_console.h" 25#include "ram_console.h"
26 26
27static struct persistent_ram_zone *ram_console_zone; 27static struct persistent_ram_zone *ram_console_zone;
diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
index f373422308e0..38d930cadad3 100644
--- a/drivers/staging/android/timed_output.c
+++ b/drivers/staging/android/timed_output.c
@@ -99,6 +99,7 @@ EXPORT_SYMBOL_GPL(timed_output_dev_register);
99 99
100void timed_output_dev_unregister(struct timed_output_dev *tdev) 100void timed_output_dev_unregister(struct timed_output_dev *tdev)
101{ 101{
102 tdev->enable(tdev, 0);
102 device_remove_file(tdev->dev, &dev_attr_enable); 103 device_remove_file(tdev->dev, &dev_attr_enable);
103 device_destroy(timed_output_class, MKDEV(0, tdev->index)); 104 device_destroy(timed_output_class, MKDEV(0, tdev->index));
104 dev_set_drvdata(tdev->dev, NULL); 105 dev_set_drvdata(tdev->dev, NULL);
diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h
index 20cca24ff5f0..aa51d17be5a1 100644
--- a/drivers/staging/bcm/Adapter.h
+++ b/drivers/staging/bcm/Adapter.h
@@ -7,168 +7,145 @@
7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256 7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256
8#include "Debug.h" 8#include "Debug.h"
9 9
10struct _LEADER 10struct _LEADER {
11{ 11 USHORT Vcid;
12 USHORT Vcid; 12 USHORT PLength;
13 USHORT PLength; 13 UCHAR Status;
14 UCHAR Status;
15 UCHAR Unused[3]; 14 UCHAR Unused[3];
16}__attribute__((packed)); 15} __packed;
17typedef struct _LEADER LEADER,*PLEADER; 16typedef struct _LEADER LEADER, *PLEADER;
18 17
19struct _PACKETTOSEND 18struct _PACKETTOSEND {
20{
21 LEADER Leader; 19 LEADER Leader;
22 UCHAR ucPayload; 20 UCHAR ucPayload;
23}__attribute__((packed)); 21} __packed;
24typedef struct _PACKETTOSEND PACKETTOSEND, *PPACKETTOSEND; 22typedef struct _PACKETTOSEND PACKETTOSEND, *PPACKETTOSEND;
25 23
26 24struct _CONTROL_PACKET {
27struct _CONTROL_PACKET
28{
29 PVOID ControlBuff; 25 PVOID ControlBuff;
30 UINT ControlBuffLen; 26 UINT ControlBuffLen;
31 struct _CONTROL_PACKET* next; 27 struct _CONTROL_PACKET *next;
32}__attribute__((packed)); 28} __packed;
33typedef struct _CONTROL_PACKET CONTROL_PACKET,*PCONTROL_PACKET; 29typedef struct _CONTROL_PACKET CONTROL_PACKET, *PCONTROL_PACKET;
34
35 30
36struct link_request 31struct link_request {
37{
38 LEADER Leader; 32 LEADER Leader;
39 UCHAR szData[4]; 33 UCHAR szData[4];
40}__attribute__((packed)); 34} __packed;
41typedef struct link_request LINK_REQUEST, *PLINK_REQUEST; 35typedef struct link_request LINK_REQUEST, *PLINK_REQUEST;
42 36
43 37/* classification extension is added */
44//classification extension is added 38typedef struct _ADD_CONNECTION {
45typedef struct _ADD_CONNECTION 39 ULONG SrcIpAddressCount;
46{ 40 ULONG SrcIpAddress[MAX_CONNECTIONS];
47 ULONG SrcIpAddressCount; 41 ULONG SrcIpMask[MAX_CONNECTIONS];
48 ULONG SrcIpAddress[MAX_CONNECTIONS]; 42
49 ULONG SrcIpMask[MAX_CONNECTIONS]; 43 ULONG DestIpAddressCount;
50 44 ULONG DestIpAddress[MAX_CONNECTIONS];
51 ULONG DestIpAddressCount; 45 ULONG DestIpMask[MAX_CONNECTIONS];
52 ULONG DestIpAddress[MAX_CONNECTIONS]; 46
53 ULONG DestIpMask[MAX_CONNECTIONS]; 47 USHORT SrcPortBegin;
54 48 USHORT SrcPortEnd;
55 USHORT SrcPortBegin; 49
56 USHORT SrcPortEnd; 50 USHORT DestPortBegin;
57 51 USHORT DestPortEnd;
58 USHORT DestPortBegin; 52
59 USHORT DestPortEnd; 53 UCHAR SrcTOS;
60 54 UCHAR SrcProtocol;
61 UCHAR SrcTOS; 55} ADD_CONNECTION, *PADD_CONNECTION;
62 UCHAR SrcProtocol; 56
63} ADD_CONNECTION,*PADD_CONNECTION; 57typedef struct _CLASSIFICATION_RULE {
64 58 UCHAR ucIPSrcAddrLen;
65 59 UCHAR ucIPSrcAddr[32];
66typedef struct _CLASSIFICATION_RULE 60 UCHAR ucIPDestAddrLen;
67{ 61 UCHAR ucIPDestAddr[32];
68 UCHAR ucIPSrcAddrLen; 62 UCHAR ucSrcPortRangeLen;
69 UCHAR ucIPSrcAddr[32]; 63 UCHAR ucSrcPortRange[4];
70 UCHAR ucIPDestAddrLen; 64 UCHAR ucDestPortRangeLen;
71 UCHAR ucIPDestAddr[32]; 65 UCHAR ucDestPortRange[4];
72 UCHAR ucSrcPortRangeLen; 66 USHORT usVcid;
73 UCHAR ucSrcPortRange[4]; 67} CLASSIFICATION_RULE, *PCLASSIFICATION_RULE;
74 UCHAR ucDestPortRangeLen; 68
75 UCHAR ucDestPortRange[4]; 69typedef struct _CLASSIFICATION_ONLY {
76 USHORT usVcid; 70 USHORT usVcid;
77} CLASSIFICATION_RULE,*PCLASSIFICATION_RULE; 71 ULONG DestIpAddress;
78 72 ULONG DestIpMask;
79typedef struct _CLASSIFICATION_ONLY 73 USHORT usPortLo;
80{ 74 USHORT usPortHi;
81 USHORT usVcid; 75 BOOLEAN bIpVersion;
82 ULONG DestIpAddress; 76 UCHAR ucDestinationAddress[16];
83 ULONG DestIpMask;
84 USHORT usPortLo;
85 USHORT usPortHi;
86 BOOLEAN bIpVersion;
87 UCHAR ucDestinationAddress[16];
88} CLASSIFICATION_ONLY, *PCLASSIFICATION_ONLY; 77} CLASSIFICATION_ONLY, *PCLASSIFICATION_ONLY;
89 78
90
91#define MAX_IP_RANGE_LENGTH 4 79#define MAX_IP_RANGE_LENGTH 4
92#define MAX_PORT_RANGE 4 80#define MAX_PORT_RANGE 4
93#define MAX_PROTOCOL_LENGTH 32 81#define MAX_PROTOCOL_LENGTH 32
94#define IPV6_ADDRESS_SIZEINBYTES 0x10 82#define IPV6_ADDRESS_SIZEINBYTES 0x10
95 83
96typedef union _U_IP_ADDRESS 84typedef union _U_IP_ADDRESS {
97{ 85 struct {
98 struct 86 ULONG ulIpv4Addr[MAX_IP_RANGE_LENGTH]; /* Source Ip Address Range */
99 { 87 ULONG ulIpv4Mask[MAX_IP_RANGE_LENGTH]; /* Source Ip Mask Address Range */
100 ULONG ulIpv4Addr[MAX_IP_RANGE_LENGTH];//Source Ip Address Range
101 ULONG ulIpv4Mask[MAX_IP_RANGE_LENGTH];//Source Ip Mask Address Range
102 }; 88 };
103 struct 89 struct {
104 { 90 ULONG ulIpv6Addr[MAX_IP_RANGE_LENGTH * 4]; /* Source Ip Address Range */
105 ULONG ulIpv6Addr[MAX_IP_RANGE_LENGTH * 4];//Source Ip Address Range 91 ULONG ulIpv6Mask[MAX_IP_RANGE_LENGTH * 4]; /* Source Ip Mask Address Range */
106 ULONG ulIpv6Mask[MAX_IP_RANGE_LENGTH * 4];//Source Ip Mask Address Range
107
108 }; 92 };
109 struct 93 struct {
110 { 94 UCHAR ucIpv4Address[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
111 UCHAR ucIpv4Address[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS]; 95 UCHAR ucIpv4Mask[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
112 UCHAR ucIpv4Mask[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
113 }; 96 };
114 struct 97 struct {
115 { 98 UCHAR ucIpv6Address[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
116 UCHAR ucIpv6Address[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES]; 99 UCHAR ucIpv6Mask[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
117 UCHAR ucIpv6Mask[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
118 }; 100 };
119}U_IP_ADDRESS; 101} U_IP_ADDRESS;
120struct _packet_info; 102struct _packet_info;
121 103
122typedef struct _S_HDR_SUPRESSION_CONTEXTINFO 104typedef struct _S_HDR_SUPRESSION_CONTEXTINFO {
123{ 105 UCHAR ucaHdrSupressionInBuf[MAX_PHS_LENGTHS]; /* Intermediate buffer to accumulate pkt Header for PHS */
106 UCHAR ucaHdrSupressionOutBuf[MAX_PHS_LENGTHS + PHSI_LEN]; /* Intermediate buffer containing pkt Header after PHS */
107} S_HDR_SUPRESSION_CONTEXTINFO;
108
109typedef struct _S_CLASSIFIER_RULE {
110 ULONG ulSFID;
111 UCHAR ucReserved[2];
112 B_UINT16 uiClassifierRuleIndex;
113 BOOLEAN bUsed;
114 USHORT usVCID_Value;
115 B_UINT8 u8ClassifierRulePriority; /* This field detemines the Classifier Priority */
116 U_IP_ADDRESS stSrcIpAddress;
117 UCHAR ucIPSourceAddressLength; /* Ip Source Address Length */
124 118
125 UCHAR ucaHdrSupressionInBuf[MAX_PHS_LENGTHS]; //Intermediate buffer to accumulate pkt Header for PHS 119 U_IP_ADDRESS stDestIpAddress;
126 UCHAR ucaHdrSupressionOutBuf[MAX_PHS_LENGTHS + PHSI_LEN]; //Intermediate buffer containing pkt Header after PHS 120 UCHAR ucIPDestinationAddressLength; /* Ip Destination Address Length */
121 UCHAR ucIPTypeOfServiceLength; /* Type of service Length */
122 UCHAR ucTosLow; /* Tos Low */
123 UCHAR ucTosHigh; /* Tos High */
124 UCHAR ucTosMask; /* Tos Mask */
127 125
128}S_HDR_SUPRESSION_CONTEXTINFO; 126 UCHAR ucProtocolLength; /* protocol Length */
127 UCHAR ucProtocol[MAX_PROTOCOL_LENGTH]; /* protocol Length */
128 USHORT usSrcPortRangeLo[MAX_PORT_RANGE];
129 USHORT usSrcPortRangeHi[MAX_PORT_RANGE];
130 UCHAR ucSrcPortRangeLength;
129 131
132 USHORT usDestPortRangeLo[MAX_PORT_RANGE];
133 USHORT usDestPortRangeHi[MAX_PORT_RANGE];
134 UCHAR ucDestPortRangeLength;
130 135
131typedef struct _S_CLASSIFIER_RULE 136 BOOLEAN bProtocolValid;
132{ 137 BOOLEAN bTOSValid;
133 ULONG ulSFID; 138 BOOLEAN bDestIpValid;
134 UCHAR ucReserved[2]; 139 BOOLEAN bSrcIpValid;
135 B_UINT16 uiClassifierRuleIndex; 140
136 BOOLEAN bUsed; 141 /* For IPv6 Addressing */
137 USHORT usVCID_Value; 142 UCHAR ucDirection;
138 B_UINT8 u8ClassifierRulePriority; //This field detemines the Classifier Priority 143 BOOLEAN bIpv6Protocol;
139 U_IP_ADDRESS stSrcIpAddress; 144 UINT32 u32PHSRuleID;
140 UCHAR ucIPSourceAddressLength;//Ip Source Address Length 145 S_PHS_RULE sPhsRule;
141 146 UCHAR u8AssociatedPHSI;
142 U_IP_ADDRESS stDestIpAddress; 147
143 UCHAR ucIPDestinationAddressLength;//Ip Destination Address Length 148 /* Classification fields for ETH CS */
144 UCHAR ucIPTypeOfServiceLength;//Type of service Length
145 UCHAR ucTosLow;//Tos Low
146 UCHAR ucTosHigh;//Tos High
147 UCHAR ucTosMask;//Tos Mask
148
149 UCHAR ucProtocolLength;//protocol Length
150 UCHAR ucProtocol[MAX_PROTOCOL_LENGTH];//protocol Length
151 USHORT usSrcPortRangeLo[MAX_PORT_RANGE];
152 USHORT usSrcPortRangeHi[MAX_PORT_RANGE];
153 UCHAR ucSrcPortRangeLength;
154
155 USHORT usDestPortRangeLo[MAX_PORT_RANGE];
156 USHORT usDestPortRangeHi[MAX_PORT_RANGE];
157 UCHAR ucDestPortRangeLength;
158
159 BOOLEAN bProtocolValid;
160 BOOLEAN bTOSValid;
161 BOOLEAN bDestIpValid;
162 BOOLEAN bSrcIpValid;
163
164 //For IPv6 Addressing
165 UCHAR ucDirection;
166 BOOLEAN bIpv6Protocol;
167 UINT32 u32PHSRuleID;
168 S_PHS_RULE sPhsRule;
169 UCHAR u8AssociatedPHSI;
170
171 //Classification fields for ETH CS
172 UCHAR ucEthCSSrcMACLen; 149 UCHAR ucEthCSSrcMACLen;
173 UCHAR au8EThCSSrcMAC[MAC_ADDRESS_SIZE]; 150 UCHAR au8EThCSSrcMAC[MAC_ADDRESS_SIZE];
174 UCHAR au8EThCSSrcMACMask[MAC_ADDRESS_SIZE]; 151 UCHAR au8EThCSSrcMACMask[MAC_ADDRESS_SIZE];
@@ -180,71 +157,67 @@ typedef struct _S_CLASSIFIER_RULE
180 UCHAR usUserPriority[2]; 157 UCHAR usUserPriority[2];
181 USHORT usVLANID; 158 USHORT usVLANID;
182 USHORT usValidityBitMap; 159 USHORT usValidityBitMap;
183}S_CLASSIFIER_RULE; 160} S_CLASSIFIER_RULE;
184//typedef struct _S_CLASSIFIER_RULE S_CLASSIFIER_RULE; 161/* typedef struct _S_CLASSIFIER_RULE S_CLASSIFIER_RULE; */
185 162
186typedef struct _S_FRAGMENTED_PACKET_INFO 163typedef struct _S_FRAGMENTED_PACKET_INFO {
187{ 164 BOOLEAN bUsed;
188 BOOLEAN bUsed; 165 ULONG ulSrcIpAddress;
189 ULONG ulSrcIpAddress; 166 USHORT usIpIdentification;
190 USHORT usIpIdentification; 167 S_CLASSIFIER_RULE *pstMatchedClassifierEntry;
191 S_CLASSIFIER_RULE *pstMatchedClassifierEntry; 168 BOOLEAN bOutOfOrderFragment;
192 BOOLEAN bOutOfOrderFragment; 169} S_FRAGMENTED_PACKET_INFO, *PS_FRAGMENTED_PACKET_INFO;
193}S_FRAGMENTED_PACKET_INFO,*PS_FRAGMENTED_PACKET_INFO; 170
194 171struct _packet_info {
195struct _packet_info 172 /* classification extension Rule */
196{ 173 ULONG ulSFID;
197 //classification extension Rule 174 USHORT usVCID_Value;
198 ULONG ulSFID; 175 UINT uiThreshold;
199 USHORT usVCID_Value; 176 /* This field determines the priority of the SF Queues */
200 UINT uiThreshold; 177 B_UINT8 u8TrafficPriority;
201 // This field determines the priority of the SF Queues 178
202 B_UINT8 u8TrafficPriority; 179 BOOLEAN bValid;
203 180 BOOLEAN bActive;
204 BOOLEAN bValid; 181 BOOLEAN bActivateRequestSent;
205 BOOLEAN bActive; 182
206 BOOLEAN bActivateRequestSent; 183 B_UINT8 u8QueueType; /* BE or rtPS */
207 184
208 B_UINT8 u8QueueType;//BE or rtPS 185 UINT uiMaxBucketSize; /* maximum size of the bucket for the queue */
209 186 UINT uiCurrentQueueDepthOnTarget;
210 UINT uiMaxBucketSize;//maximum size of the bucket for the queue 187 UINT uiCurrentBytesOnHost;
211 UINT uiCurrentQueueDepthOnTarget; 188 UINT uiCurrentPacketsOnHost;
212 UINT uiCurrentBytesOnHost; 189 UINT uiDroppedCountBytes;
213 UINT uiCurrentPacketsOnHost; 190 UINT uiDroppedCountPackets;
214 UINT uiDroppedCountBytes; 191 UINT uiSentBytes;
215 UINT uiDroppedCountPackets; 192 UINT uiSentPackets;
216 UINT uiSentBytes; 193 UINT uiCurrentDrainRate;
217 UINT uiSentPackets; 194 UINT uiThisPeriodSentBytes;
218 UINT uiCurrentDrainRate;
219 UINT uiThisPeriodSentBytes;
220 LARGE_INTEGER liDrainCalculated; 195 LARGE_INTEGER liDrainCalculated;
221 UINT uiCurrentTokenCount; 196 UINT uiCurrentTokenCount;
222 LARGE_INTEGER liLastUpdateTokenAt; 197 LARGE_INTEGER liLastUpdateTokenAt;
223 UINT uiMaxAllowedRate; 198 UINT uiMaxAllowedRate;
224 UINT NumOfPacketsSent; 199 UINT NumOfPacketsSent;
225 UCHAR ucDirection; 200 UCHAR ucDirection;
226 USHORT usCID; 201 USHORT usCID;
227 S_MIBS_EXTSERVICEFLOW_PARAMETERS stMibsExtServiceFlowTable; 202 S_MIBS_EXTSERVICEFLOW_PARAMETERS stMibsExtServiceFlowTable;
228 UINT uiCurrentRxRate; 203 UINT uiCurrentRxRate;
229 UINT uiThisPeriodRxBytes; 204 UINT uiThisPeriodRxBytes;
230 UINT uiTotalRxBytes; 205 UINT uiTotalRxBytes;
231 UINT uiTotalTxBytes; 206 UINT uiTotalTxBytes;
232 UINT uiPendedLast; 207 UINT uiPendedLast;
233 UCHAR ucIpVersion; 208 UCHAR ucIpVersion;
234 209
235 union 210 union {
236 { 211 struct {
237 struct 212 struct sk_buff *FirstTxQueue;
238 { 213 struct sk_buff *LastTxQueue;
239 struct sk_buff* FirstTxQueue;
240 struct sk_buff* LastTxQueue;
241 }; 214 };
242 struct 215 struct {
243 { 216 struct sk_buff *ControlHead;
244 struct sk_buff* ControlHead; 217 struct sk_buff *ControlTail;
245 struct sk_buff* ControlTail;
246 }; 218 };
247 }; 219 };
220
248 BOOLEAN bProtocolValid; 221 BOOLEAN bProtocolValid;
249 BOOLEAN bTOSValid; 222 BOOLEAN bTOSValid;
250 BOOLEAN bDestIpValid; 223 BOOLEAN bDestIpValid;
@@ -255,226 +228,209 @@ struct _packet_info
255 BOOLEAN bAuthorizedSet; 228 BOOLEAN bAuthorizedSet;
256 BOOLEAN bClassifierPriority; 229 BOOLEAN bClassifierPriority;
257 UCHAR ucServiceClassName[MAX_CLASS_NAME_LENGTH]; 230 UCHAR ucServiceClassName[MAX_CLASS_NAME_LENGTH];
258 BOOLEAN bHeaderSuppressionEnabled; 231 BOOLEAN bHeaderSuppressionEnabled;
259 spinlock_t SFQueueLock; 232 spinlock_t SFQueueLock;
260 void *pstSFIndication; 233 void *pstSFIndication;
261 struct timeval stLastUpdateTokenAt; 234 struct timeval stLastUpdateTokenAt;
262 atomic_t uiPerSFTxResourceCount; 235 atomic_t uiPerSFTxResourceCount;
263 UINT uiMaxLatency; 236 UINT uiMaxLatency;
264 UCHAR bIPCSSupport; 237 UCHAR bIPCSSupport;
265 UCHAR bEthCSSupport; 238 UCHAR bEthCSSupport;
266}; 239};
267typedef struct _packet_info PacketInfo; 240typedef struct _packet_info PacketInfo;
268 241
269 242typedef struct _PER_TARANG_DATA {
270typedef struct _PER_TARANG_DATA 243 struct _PER_TARANG_DATA *next;
271{ 244 struct _MINI_ADAPTER *Adapter;
272 struct _PER_TARANG_DATA * next; 245 struct sk_buff *RxAppControlHead;
273 struct _MINI_ADAPTER * Adapter; 246 struct sk_buff *RxAppControlTail;
274 struct sk_buff* RxAppControlHead; 247 int AppCtrlQueueLen;
275 struct sk_buff* RxAppControlTail; 248 BOOLEAN MacTracingEnabled;
276 volatile INT AppCtrlQueueLen; 249 BOOLEAN bApplicationToExit;
277 BOOLEAN MacTracingEnabled; 250 S_MIBS_DROPPED_APP_CNTRL_MESSAGES stDroppedAppCntrlMsgs;
278 BOOLEAN bApplicationToExit; 251 ULONG RxCntrlMsgBitMask;
279 S_MIBS_DROPPED_APP_CNTRL_MESSAGES stDroppedAppCntrlMsgs;
280 ULONG RxCntrlMsgBitMask;
281} PER_TARANG_DATA, *PPER_TARANG_DATA; 252} PER_TARANG_DATA, *PPER_TARANG_DATA;
282 253
283
284#ifdef REL_4_1 254#ifdef REL_4_1
285typedef struct _TARGET_PARAMS 255typedef struct _TARGET_PARAMS {
286{ 256 B_UINT32 m_u32CfgVersion;
287 B_UINT32 m_u32CfgVersion; 257
288 258 /* Scanning Related Params */
289 // Scanning Related Params 259 B_UINT32 m_u32CenterFrequency;
290 B_UINT32 m_u32CenterFrequency; 260 B_UINT32 m_u32BandAScan;
291 B_UINT32 m_u32BandAScan; 261 B_UINT32 m_u32BandBScan;
292 B_UINT32 m_u32BandBScan; 262 B_UINT32 m_u32BandCScan;
293 B_UINT32 m_u32BandCScan; 263
294 264 /* QoS Params */
295 // QoS Params 265 B_UINT32 m_u32minGrantsize; /* size of minimum grant is 0 or 6 */
296 B_UINT32 m_u32minGrantsize; // size of minimum grant is 0 or 6 266 B_UINT32 m_u32PHSEnable;
297 B_UINT32 m_u32PHSEnable; 267
298 268 /* HO Params */
299 // HO Params 269 B_UINT32 m_u32HoEnable;
300 B_UINT32 m_u32HoEnable; 270 B_UINT32 m_u32HoReserved1;
301 B_UINT32 m_u32HoReserved1; 271 B_UINT32 m_u32HoReserved2;
302 B_UINT32 m_u32HoReserved2; 272
303 273 /* Power Control Params */
304 // Power Control Params 274 B_UINT32 m_u32MimoEnable;
305 B_UINT32 m_u32MimoEnable; 275 B_UINT32 m_u32SecurityEnable;
306 B_UINT32 m_u32SecurityEnable;
307 /* 276 /*
308 * bit 1: 1 Idlemode enable; 277 * bit 1: 1 Idlemode enable;
309 * bit 2: 1 Sleepmode Enable 278 * bit 2: 1 Sleepmode Enable
310 */ 279 */
311 B_UINT32 m_u32PowerSavingModesEnable; 280 B_UINT32 m_u32PowerSavingModesEnable;
312 /* PowerSaving Mode Options: 281 /* PowerSaving Mode Options:
313 bit 0 = 1: CPE mode - to keep pcmcia if alive; 282 * bit 0 = 1: CPE mode - to keep pcmcia if alive;
314 bit 1 = 1: CINR reporing in Idlemode Msg 283 * bit 1 = 1: CINR reporing in Idlemode Msg
315 bit 2 = 1: Default PSC Enable in sleepmode*/ 284 * bit 2 = 1: Default PSC Enable in sleepmode
316 B_UINT32 m_u32PowerSavingModeOptions; 285 */
317 286 B_UINT32 m_u32PowerSavingModeOptions;
318 B_UINT32 m_u32ArqEnable; 287
319 288 B_UINT32 m_u32ArqEnable;
320 // From Version #3, the HARQ section renamed as general 289
321 B_UINT32 m_u32HarqEnable; 290 /* From Version #3, the HARQ section renamed as general */
322 // EEPROM Param Location 291 B_UINT32 m_u32HarqEnable;
323 B_UINT32 m_u32EEPROMFlag; 292 /* EEPROM Param Location */
324 /* BINARY TYPE - 4th MSByte: 293 B_UINT32 m_u32EEPROMFlag;
325 * Interface Type - 3rd MSByte: 294 /* BINARY TYPE - 4th MSByte:
326 * Vendor Type - 2nd MSByte 295 * Interface Type - 3rd MSByte:
327 */ 296 * Vendor Type - 2nd MSByte
328 // Unused - LSByte 297 */
329 B_UINT32 m_u32Customize; 298 /* Unused - LSByte */
330 B_UINT32 m_u32ConfigBW; /* In Hz */ 299 B_UINT32 m_u32Customize;
331 B_UINT32 m_u32ShutDownTimer; 300 B_UINT32 m_u32ConfigBW; /* In Hz */
332 301 B_UINT32 m_u32ShutDownTimer;
333 302 B_UINT32 m_u32RadioParameter;
334 B_UINT32 m_u32RadioParameter; 303 B_UINT32 m_u32PhyParameter1;
335 B_UINT32 m_u32PhyParameter1; 304 B_UINT32 m_u32PhyParameter2;
336 B_UINT32 m_u32PhyParameter2; 305 B_UINT32 m_u32PhyParameter3;
337 B_UINT32 m_u32PhyParameter3;
338 306
339 /* in eval mode only; 307 /* in eval mode only;
340 * lower 16bits = basic cid for testing; 308 * lower 16bits = basic cid for testing;
341 * then bit 16 is test cqich, 309 * then bit 16 is test cqich,
342 * bit 17 test init rang; 310 * bit 17 test init rang;
343 * bit 18 test periodic rang 311 * bit 18 test periodic rang
344 * bit 19 is test harq ack/nack 312 * bit 19 is test harq ack/nack
345 */ 313 */
346 B_UINT32 m_u32TestOptions; 314 B_UINT32 m_u32TestOptions;
347
348 B_UINT32 m_u32MaxMACDataperDLFrame; 315 B_UINT32 m_u32MaxMACDataperDLFrame;
349 B_UINT32 m_u32MaxMACDataperULFrame; 316 B_UINT32 m_u32MaxMACDataperULFrame;
350
351 B_UINT32 m_u32Corr2MacFlags; 317 B_UINT32 m_u32Corr2MacFlags;
352 318
353 //adding driver params. 319 /* adding driver params. */
354 B_UINT32 HostDrvrConfig1; 320 B_UINT32 HostDrvrConfig1;
355 B_UINT32 HostDrvrConfig2; 321 B_UINT32 HostDrvrConfig2;
356 B_UINT32 HostDrvrConfig3; 322 B_UINT32 HostDrvrConfig3;
357 B_UINT32 HostDrvrConfig4; 323 B_UINT32 HostDrvrConfig4;
358 B_UINT32 HostDrvrConfig5; 324 B_UINT32 HostDrvrConfig5;
359 B_UINT32 HostDrvrConfig6; 325 B_UINT32 HostDrvrConfig6;
360 B_UINT32 m_u32SegmentedPUSCenable; 326 B_UINT32 m_u32SegmentedPUSCenable;
361 327
362 // BAMC enable - but 4.x does not support this feature 328 /* BAMC enable - but 4.x does not support this feature
363 // This is added just to sync 4.x and 5.x CFGs 329 * This is added just to sync 4.x and 5.x CFGs
330 */
364 B_UINT32 m_u32BandAMCEnable; 331 B_UINT32 m_u32BandAMCEnable;
365} STARGETPARAMS, *PSTARGETPARAMS; 332} STARGETPARAMS, *PSTARGETPARAMS;
366#endif 333#endif
367 334
368typedef struct _STTARGETDSXBUFFER 335typedef struct _STTARGETDSXBUFFER {
369{ 336 ULONG ulTargetDsxBuffer;
370 ULONG ulTargetDsxBuffer; 337 B_UINT16 tid;
371 B_UINT16 tid; 338 BOOLEAN valid;
372 BOOLEAN valid; 339} STTARGETDSXBUFFER, *PSTTARGETDSXBUFFER;
373}STTARGETDSXBUFFER, *PSTTARGETDSXBUFFER;
374 340
375typedef INT (*FP_FLASH_WRITE)(struct _MINI_ADAPTER*,UINT,PVOID); 341typedef int (*FP_FLASH_WRITE)(struct _MINI_ADAPTER *, UINT, PVOID);
376 342
377typedef INT (*FP_FLASH_WRITE_STATUS)(struct _MINI_ADAPTER*,UINT,PVOID); 343typedef int (*FP_FLASH_WRITE_STATUS)(struct _MINI_ADAPTER *, UINT, PVOID);
378 344
379/** 345/*
380Driver adapter data structure 346 * Driver adapter data structure
381*/ 347 */
382struct _MINI_ADAPTER 348struct _MINI_ADAPTER {
383{ 349 struct _MINI_ADAPTER *next;
384 struct _MINI_ADAPTER *next;
385 struct net_device *dev; 350 struct net_device *dev;
386 u32 msg_enable; 351 u32 msg_enable;
387 352 CHAR *caDsxReqResp;
388 CHAR *caDsxReqResp;
389 atomic_t ApplicationRunning; 353 atomic_t ApplicationRunning;
390 volatile INT CtrlQueueLen; 354 BOOLEAN AppCtrlQueueOverFlow;
391 atomic_t AppCtrlQueueLen;
392 BOOLEAN AppCtrlQueueOverFlow;
393 atomic_t CurrentApplicationCount; 355 atomic_t CurrentApplicationCount;
394 atomic_t RegisteredApplicationCount; 356 atomic_t RegisteredApplicationCount;
395 BOOLEAN LinkUpStatus; 357 BOOLEAN LinkUpStatus;
396 BOOLEAN TimerActive; 358 BOOLEAN TimerActive;
397 u32 StatisticsPointer; 359 u32 StatisticsPointer;
398 struct sk_buff *RxControlHead; 360 struct sk_buff *RxControlHead;
399 struct sk_buff *RxControlTail; 361 struct sk_buff *RxControlTail;
400
401 struct semaphore RxAppControlQueuelock; 362 struct semaphore RxAppControlQueuelock;
402 struct semaphore fw_download_sema; 363 struct semaphore fw_download_sema;
403 364 PPER_TARANG_DATA pTarangs;
404 PPER_TARANG_DATA pTarangs; 365 spinlock_t control_queue_lock;
405 spinlock_t control_queue_lock;
406 wait_queue_head_t process_read_wait_queue; 366 wait_queue_head_t process_read_wait_queue;
407 367
408 // the pointer to the first packet we have queued in send 368 /* the pointer to the first packet we have queued in send
409 // deserialized miniport support variables 369 * deserialized miniport support variables
410 atomic_t TotalPacketCount; 370 */
411 atomic_t TxPktAvail; 371 atomic_t TotalPacketCount;
412 372 atomic_t TxPktAvail;
413 // this to keep track of the Tx and Rx MailBox Registers. 373
414 atomic_t CurrNumFreeTxDesc; 374 /* this to keep track of the Tx and Rx MailBox Registers. */
415 // to keep track the no of byte received 375 atomic_t CurrNumFreeTxDesc;
416 USHORT PrevNumRecvDescs; 376 /* to keep track the no of byte received */
417 USHORT CurrNumRecvDescs; 377 USHORT PrevNumRecvDescs;
418 UINT u32TotalDSD; 378 USHORT CurrNumRecvDescs;
419 PacketInfo PackInfo[NO_OF_QUEUES]; 379 UINT u32TotalDSD;
380 PacketInfo PackInfo[NO_OF_QUEUES];
420 S_CLASSIFIER_RULE astClassifierTable[MAX_CLASSIFIERS]; 381 S_CLASSIFIER_RULE astClassifierTable[MAX_CLASSIFIERS];
421 BOOLEAN TransferMode; 382 BOOLEAN TransferMode;
422 383
423 /*************** qos ******************/ 384 /*************** qos ******************/
424 BOOLEAN bETHCSEnabled; 385 BOOLEAN bETHCSEnabled;
425 386 ULONG BEBucketSize;
426 ULONG BEBucketSize; 387 ULONG rtPSBucketSize;
427 ULONG rtPSBucketSize; 388 UCHAR LinkStatus;
428 UCHAR LinkStatus; 389 BOOLEAN AutoLinkUp;
429 BOOLEAN AutoLinkUp; 390 BOOLEAN AutoSyncup;
430 BOOLEAN AutoSyncup; 391
431 392 int major;
432 int major; 393 int minor;
433 int minor; 394 wait_queue_head_t tx_packet_wait_queue;
434 wait_queue_head_t tx_packet_wait_queue; 395 wait_queue_head_t process_rx_cntrlpkt;
435 wait_queue_head_t process_rx_cntrlpkt; 396 atomic_t process_waiting;
436 atomic_t process_waiting; 397 BOOLEAN fw_download_done;
437 BOOLEAN fw_download_done; 398
438 399 char *txctlpacket[MAX_CNTRL_PKTS];
439 char *txctlpacket[MAX_CNTRL_PKTS]; 400 atomic_t cntrlpktCnt ;
440 atomic_t cntrlpktCnt ; 401 atomic_t index_app_read_cntrlpkt;
441 atomic_t index_app_read_cntrlpkt; 402 atomic_t index_wr_txcntrlpkt;
442 atomic_t index_wr_txcntrlpkt; 403 atomic_t index_rd_txcntrlpkt;
443 atomic_t index_rd_txcntrlpkt; 404 UINT index_datpkt;
444 UINT index_datpkt; 405 struct semaphore rdmwrmsync;
445 struct semaphore rdmwrmsync;
446 406
447 STTARGETDSXBUFFER astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS]; 407 STTARGETDSXBUFFER astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS];
448 ULONG ulFreeTargetBufferCnt; 408 ULONG ulFreeTargetBufferCnt;
449 ULONG ulCurrentTargetBuffer; 409 ULONG ulCurrentTargetBuffer;
450 ULONG ulTotalTargetBuffersAvailable; 410 ULONG ulTotalTargetBuffersAvailable;
451 411 unsigned long chip_id;
452 unsigned long chip_id; 412 wait_queue_head_t lowpower_mode_wait_queue;
453
454 wait_queue_head_t lowpower_mode_wait_queue;
455
456 BOOLEAN bFlashBoot; 413 BOOLEAN bFlashBoot;
457 BOOLEAN bBinDownloaded; 414 BOOLEAN bBinDownloaded;
458 BOOLEAN bCfgDownloaded; 415 BOOLEAN bCfgDownloaded;
459 BOOLEAN bSyncUpRequestSent; 416 BOOLEAN bSyncUpRequestSent;
460 USHORT usBestEffortQueueIndex; 417 USHORT usBestEffortQueueIndex;
461 418 wait_queue_head_t ioctl_fw_dnld_wait_queue;
462 wait_queue_head_t ioctl_fw_dnld_wait_queue; 419 BOOLEAN waiting_to_fw_download_done;
463 BOOLEAN waiting_to_fw_download_done; 420 pid_t fw_download_process_pid;
464 pid_t fw_download_process_pid;
465 PSTARGETPARAMS pstargetparams; 421 PSTARGETPARAMS pstargetparams;
466 BOOLEAN device_removed; 422 BOOLEAN device_removed;
467 BOOLEAN DeviceAccess; 423 BOOLEAN DeviceAccess;
468 BOOLEAN bIsAutoCorrectEnabled; 424 BOOLEAN bIsAutoCorrectEnabled;
469 BOOLEAN bDDRInitDone; 425 BOOLEAN bDDRInitDone;
470 INT DDRSetting; 426 int DDRSetting;
471 ULONG ulPowerSaveMode; 427 ULONG ulPowerSaveMode;
472 spinlock_t txtransmitlock; 428 spinlock_t txtransmitlock;
473 B_UINT8 txtransmit_running; 429 B_UINT8 txtransmit_running;
474 /* Thread for control packet handling */ 430 /* Thread for control packet handling */
475 struct task_struct *control_packet_handler; 431 struct task_struct *control_packet_handler;
476 /* thread for transmitting packets. */ 432 /* thread for transmitting packets. */
477 struct task_struct *transmit_packet_thread; 433 struct task_struct *transmit_packet_thread;
478 434
479 /* LED Related Structures */ 435 /* LED Related Structures */
480 LED_INFO_STRUCT LEDInfo; 436 LED_INFO_STRUCT LEDInfo;
@@ -482,39 +438,38 @@ struct _MINI_ADAPTER
482 /* Driver State for LED Blinking */ 438 /* Driver State for LED Blinking */
483 LedEventInfo_t DriverState; 439 LedEventInfo_t DriverState;
484 /* Interface Specific */ 440 /* Interface Specific */
485 PVOID pvInterfaceAdapter; 441 PVOID pvInterfaceAdapter;
486 int (*bcm_file_download)( PVOID, 442 int (*bcm_file_download)(PVOID,
487 struct file *, 443 struct file *,
488 unsigned int); 444 unsigned int);
489 int (*bcm_file_readback_from_chip)( PVOID, 445 int (*bcm_file_readback_from_chip)(PVOID,
490 struct file *, 446 struct file *,
491 unsigned int); 447 unsigned int);
492 INT (*interface_rdm)(PVOID, 448 int (*interface_rdm)(PVOID,
493 UINT , 449 UINT,
494 PVOID , 450 PVOID,
495 INT); 451 int);
496 INT (*interface_wrm)(PVOID, 452 int (*interface_wrm)(PVOID,
497 UINT , 453 UINT,
498 PVOID , 454 PVOID,
499 INT); 455 int);
500 int (*interface_transmit)(PVOID, PVOID , UINT); 456 int (*interface_transmit)(PVOID, PVOID , UINT);
501 BOOLEAN IdleMode; 457 BOOLEAN IdleMode;
502 BOOLEAN bDregRequestSentInIdleMode; 458 BOOLEAN bDregRequestSentInIdleMode;
503 BOOLEAN bTriedToWakeUpFromlowPowerMode; 459 BOOLEAN bTriedToWakeUpFromlowPowerMode;
504 BOOLEAN bShutStatus; 460 BOOLEAN bShutStatus;
505 BOOLEAN bWakeUpDevice; 461 BOOLEAN bWakeUpDevice;
506 unsigned int usIdleModePattern; 462 unsigned int usIdleModePattern;
507 //BOOLEAN bTriedToWakeUpFromShutdown; 463 /* BOOLEAN bTriedToWakeUpFromShutdown; */
508 BOOLEAN bLinkDownRequested; 464 BOOLEAN bLinkDownRequested;
509 465 int downloadDDR;
510 int downloadDDR; 466 PHS_DEVICE_EXTENSION stBCMPhsContext;
511 PHS_DEVICE_EXTENSION stBCMPhsContext; 467 S_HDR_SUPRESSION_CONTEXTINFO stPhsTxContextInfo;
512 S_HDR_SUPRESSION_CONTEXTINFO stPhsTxContextInfo;
513 uint8_t ucaPHSPktRestoreBuf[2048]; 468 uint8_t ucaPHSPktRestoreBuf[2048];
514 uint8_t bPHSEnabled; 469 uint8_t bPHSEnabled;
515 BOOLEAN AutoFirmDld; 470 BOOLEAN AutoFirmDld;
516 BOOLEAN bMipsConfig; 471 BOOLEAN bMipsConfig;
517 BOOLEAN bDPLLConfig; 472 BOOLEAN bDPLLConfig;
518 UINT32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES]; 473 UINT32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
519 UINT32 aRxPktSizeHist[MIBS_MAX_HIST_ENTRIES]; 474 UINT32 aRxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
520 S_FRAGMENTED_PACKET_INFO astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES]; 475 S_FRAGMENTED_PACKET_INFO astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES];
@@ -527,108 +482,101 @@ struct _MINI_ADAPTER
527 BOOLEAN bStatusWrite; 482 BOOLEAN bStatusWrite;
528 UINT uiNVMDSDSize; 483 UINT uiNVMDSDSize;
529 UINT uiVendorExtnFlag; 484 UINT uiVendorExtnFlag;
530 //it will always represent chosen DSD at any point of time. 485 /* it will always represent chosen DSD at any point of time.
531 // Generally it is Active DSD but in case of NVM RD/WR it might be different. 486 * Generally it is Active DSD but in case of NVM RD/WR it might be different.
487 */
532 UINT ulFlashCalStart; 488 UINT ulFlashCalStart;
533 ULONG ulFlashControlSectionStart; 489 ULONG ulFlashControlSectionStart;
534 ULONG ulFlashWriteSize; 490 ULONG ulFlashWriteSize;
535 ULONG ulFlashID; 491 ULONG ulFlashID;
536 FP_FLASH_WRITE fpFlashWrite; 492 FP_FLASH_WRITE fpFlashWrite;
537 FP_FLASH_WRITE_STATUS fpFlashWriteWithStatusCheck; 493 FP_FLASH_WRITE_STATUS fpFlashWriteWithStatusCheck;
538
539 494
540 struct semaphore NVMRdmWrmLock; 495 struct semaphore NVMRdmWrmLock;
496 struct device *pstCreatedClassDevice;
541 497
542 struct device *pstCreatedClassDevice; 498 /* BOOLEAN InterfaceUpStatus; */
543 499 PFLASH2X_CS_INFO psFlash2xCSInfo;
544// BOOLEAN InterfaceUpStatus; 500 PFLASH_CS_INFO psFlashCSInfo;
545 PFLASH2X_CS_INFO psFlash2xCSInfo;
546 PFLASH_CS_INFO psFlashCSInfo ;
547 PFLASH2X_VENDORSPECIFIC_INFO psFlash2xVendorInfo; 501 PFLASH2X_VENDORSPECIFIC_INFO psFlash2xVendorInfo;
548 UINT uiFlashBaseAdd; //Flash start address 502 UINT uiFlashBaseAdd; /* Flash start address */
549 UINT uiActiveISOOffset; //Active ISO offset chosen before f/w download 503 UINT uiActiveISOOffset; /* Active ISO offset chosen before f/w download */
550 FLASH2X_SECTION_VAL eActiveISO; //Active ISO section val 504 FLASH2X_SECTION_VAL eActiveISO; /* Active ISO section val */
551 FLASH2X_SECTION_VAL eActiveDSD; //Active DSD val chosen before f/w download 505 FLASH2X_SECTION_VAL eActiveDSD; /* Active DSD val chosen before f/w download */
552 UINT uiActiveDSDOffsetAtFwDld; //For accessing Active DSD chosen before f/w download 506 UINT uiActiveDSDOffsetAtFwDld; /* For accessing Active DSD chosen before f/w download */
553 UINT uiFlashLayoutMajorVersion ; 507 UINT uiFlashLayoutMajorVersion;
554 UINT uiFlashLayoutMinorVersion; 508 UINT uiFlashLayoutMinorVersion;
555 BOOLEAN bAllDSDWriteAllow ; 509 BOOLEAN bAllDSDWriteAllow;
556 BOOLEAN bSigCorrupted ; 510 BOOLEAN bSigCorrupted;
557 //this should be set who so ever want to change the Headers. after Wrtie it should be reset immediately. 511 /* this should be set who so ever want to change the Headers. after Wrtie it should be reset immediately. */
558 BOOLEAN bHeaderChangeAllowed ; 512 BOOLEAN bHeaderChangeAllowed;
559 INT SelectedChip ; 513 int SelectedChip;
560 BOOLEAN bEndPointHalted; 514 BOOLEAN bEndPointHalted;
561 //while bFlashRawRead will be true, Driver ignore map lay out and consider flash as of without any map. 515 /* while bFlashRawRead will be true, Driver ignore map lay out and consider flash as of without any map. */
562 BOOLEAN bFlashRawRead; 516 BOOLEAN bFlashRawRead;
563 BOOLEAN bPreparingForLowPowerMode ; 517 BOOLEAN bPreparingForLowPowerMode;
564 BOOLEAN bDoSuspend ; 518 BOOLEAN bDoSuspend;
565 UINT syscfgBefFwDld ; 519 UINT syscfgBefFwDld;
566 BOOLEAN StopAllXaction ; 520 BOOLEAN StopAllXaction;
567 UINT32 liTimeSinceLastNetEntry; //Used to Support extended CAPI requirements from 521 UINT32 liTimeSinceLastNetEntry; /* Used to Support extended CAPI requirements from */
568 struct semaphore LowPowerModeSync; 522 struct semaphore LowPowerModeSync;
569 ULONG liDrainCalculated; 523 ULONG liDrainCalculated;
570 UINT gpioBitMap; 524 UINT gpioBitMap;
571 525 S_BCM_DEBUG_STATE stDebugState;
572 S_BCM_DEBUG_STATE stDebugState;
573
574}; 526};
575typedef struct _MINI_ADAPTER MINI_ADAPTER, *PMINI_ADAPTER; 527typedef struct _MINI_ADAPTER MINI_ADAPTER, *PMINI_ADAPTER;
576 528
577#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev) 529#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev)
578 530
579struct _ETH_HEADER_STRUC { 531struct _ETH_HEADER_STRUC {
580 UCHAR au8DestinationAddress[6]; 532 UCHAR au8DestinationAddress[6];
581 UCHAR au8SourceAddress[6]; 533 UCHAR au8SourceAddress[6];
582 USHORT u16Etype; 534 USHORT u16Etype;
583}__attribute__((packed)); 535} __packed;
584typedef struct _ETH_HEADER_STRUC ETH_HEADER_STRUC, *PETH_HEADER_STRUC; 536typedef struct _ETH_HEADER_STRUC ETH_HEADER_STRUC, *PETH_HEADER_STRUC;
585 537
538typedef struct FirmwareInfo {
539 void __user *pvMappedFirmwareAddress;
540 ULONG u32FirmwareLength;
541 ULONG u32StartingAddress;
542} __packed FIRMWARE_INFO, *PFIRMWARE_INFO;
586 543
587typedef struct FirmwareInfo 544/* holds the value of net_device structure.. */
588{
589 void __user * pvMappedFirmwareAddress;
590 ULONG u32FirmwareLength;
591 ULONG u32StartingAddress;
592}__attribute__((packed)) FIRMWARE_INFO, *PFIRMWARE_INFO;
593
594// holds the value of net_device structure..
595extern struct net_device *gblpnetdev; 545extern struct net_device *gblpnetdev;
596typedef struct _cntl_pkt{ 546typedef struct _cntl_pkt {
597 PMINI_ADAPTER Adapter; 547 PMINI_ADAPTER Adapter;
598 PLEADER PLeader; 548 PLEADER PLeader;
599}cntl_pkt; 549} cntl_pkt;
600typedef LINK_REQUEST CONTROL_MESSAGE; 550typedef LINK_REQUEST CONTROL_MESSAGE;
601 551
602typedef struct _DDR_SETTING 552typedef struct _DDR_SETTING {
603{
604 UINT ulRegAddress; 553 UINT ulRegAddress;
605 UINT ulRegValue; 554 UINT ulRegValue;
606}DDR_SETTING, *PDDR_SETTING; 555} DDR_SETTING, *PDDR_SETTING;
607typedef DDR_SETTING DDR_SET_NODE, *PDDR_SET_NODE; 556typedef DDR_SETTING DDR_SET_NODE, *PDDR_SET_NODE;
608INT 557int InitAdapter(PMINI_ADAPTER psAdapter);
609InitAdapter(PMINI_ADAPTER psAdapter);
610
611// =====================================================================
612// Beceem vendor request codes for EP0
613// =====================================================================
614 558
615#define BCM_REQUEST_READ 0x2 559/* =====================================================================
616#define BCM_REQUEST_WRITE 0x1 560 * Beceem vendor request codes for EP0
617#define EP2_MPS_REG 0x0F0110A0 561 * =====================================================================
618#define EP2_MPS 0x40 562 */
619 563
620#define EP2_CFG_REG 0x0F0110A8 564#define BCM_REQUEST_READ 0x2
621#define EP2_CFG_INT 0x27 565#define BCM_REQUEST_WRITE 0x1
622#define EP2_CFG_BULK 0x25 566#define EP2_MPS_REG 0x0F0110A0
567#define EP2_MPS 0x40
623 568
624#define EP4_MPS_REG 0x0F0110F0 569#define EP2_CFG_REG 0x0F0110A8
625#define EP4_MPS 0x8C 570#define EP2_CFG_INT 0x27
571#define EP2_CFG_BULK 0x25
626 572
627#define EP4_CFG_REG 0x0F0110F8 573#define EP4_MPS_REG 0x0F0110F0
574#define EP4_MPS 0x8C
628 575
629#define ISO_MPS_REG 0x0F0110C8 576#define EP4_CFG_REG 0x0F0110F8
630#define ISO_MPS 0x00000000
631 577
578#define ISO_MPS_REG 0x0F0110C8
579#define ISO_MPS 0x00000000
632 580
633#define EP1 0 581#define EP1 0
634#define EP2 1 582#define EP2 1
@@ -637,12 +585,9 @@ InitAdapter(PMINI_ADAPTER psAdapter);
637#define EP5 4 585#define EP5 4
638#define EP6 5 586#define EP6 5
639 587
640 588typedef enum eInterface_setting {
641typedef enum eInterface_setting
642{
643 DEFAULT_SETTING_0 = 0, 589 DEFAULT_SETTING_0 = 0,
644 ALTERNATE_SETTING_1 = 1, 590 ALTERNATE_SETTING_1 = 1,
645}INTERFACE_SETTING; 591} INTERFACE_SETTING;
646
647#endif //__ADAPTER_H__
648 592
593#endif /* __ADAPTER_H__ */
diff --git a/drivers/staging/bcm/DDRInit.c b/drivers/staging/bcm/DDRInit.c
index 1c7db81a1ee8..2b46f4d4ef0e 100644
--- a/drivers/staging/bcm/DDRInit.c
+++ b/drivers/staging/bcm/DDRInit.c
@@ -1115,20 +1115,20 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1115 { 1115 {
1116 case DDR_80_MHZ: 1116 case DDR_80_MHZ:
1117 psDDRSetting = asT3LP_DDRSetting80MHz; 1117 psDDRSetting = asT3LP_DDRSetting80MHz;
1118 RegCount = (sizeof(asT3LP_DDRSetting80MHz)/sizeof(DDR_SET_NODE)); 1118 RegCount = ARRAY_SIZE(asT3LP_DDRSetting80MHz);
1119 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ; 1119 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ;
1120 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ; 1120 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1121 break; 1121 break;
1122 case DDR_100_MHZ: 1122 case DDR_100_MHZ:
1123 psDDRSetting = asT3LP_DDRSetting100MHz; 1123 psDDRSetting = asT3LP_DDRSetting100MHz;
1124 RegCount = (sizeof(asT3LP_DDRSetting100MHz)/sizeof(DDR_SET_NODE)); 1124 RegCount = ARRAY_SIZE(asT3LP_DDRSetting100MHz);
1125 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ; 1125 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ;
1126 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ; 1126 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1127 break; 1127 break;
1128 case DDR_133_MHZ: 1128 case DDR_133_MHZ:
1129 bOverrideSelfRefresh = TRUE; 1129 bOverrideSelfRefresh = TRUE;
1130 psDDRSetting = asT3LP_DDRSetting133MHz; 1130 psDDRSetting = asT3LP_DDRSetting133MHz;
1131 RegCount = (sizeof(asT3LP_DDRSetting133MHz)/sizeof(DDR_SET_NODE)); 1131 RegCount = ARRAY_SIZE(asT3LP_DDRSetting133MHz);
1132 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ; 1132 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ;
1133 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ; 1133 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1134 break; 1134 break;
@@ -1146,20 +1146,20 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1146 { 1146 {
1147 case DDR_80_MHZ: 1147 case DDR_80_MHZ:
1148 psDDRSetting = asT3LPB_DDRSetting80MHz; 1148 psDDRSetting = asT3LPB_DDRSetting80MHz;
1149 RegCount=(sizeof(asT3LPB_DDRSetting80MHz)/sizeof(DDR_SET_NODE)); 1149 RegCount=ARRAY_SIZE(asT3LPB_DDRSetting80MHz);
1150 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ; 1150 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ;
1151 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ; 1151 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1152 break; 1152 break;
1153 case DDR_100_MHZ: 1153 case DDR_100_MHZ:
1154 psDDRSetting = asT3LPB_DDRSetting100MHz; 1154 psDDRSetting = asT3LPB_DDRSetting100MHz;
1155 RegCount = (sizeof(asT3LPB_DDRSetting100MHz)/sizeof(DDR_SET_NODE)); 1155 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting100MHz);
1156 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ; 1156 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ;
1157 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ; 1157 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1158 break; 1158 break;
1159 case DDR_133_MHZ: 1159 case DDR_133_MHZ:
1160 bOverrideSelfRefresh = TRUE; 1160 bOverrideSelfRefresh = TRUE;
1161 psDDRSetting = asT3LPB_DDRSetting133MHz; 1161 psDDRSetting = asT3LPB_DDRSetting133MHz;
1162 RegCount = (sizeof(asT3LPB_DDRSetting133MHz)/sizeof(DDR_SET_NODE)); 1162 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting133MHz);
1163 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ; 1163 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ;
1164 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ; 1164 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1165 break; 1165 break;
@@ -1167,7 +1167,7 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1167 case DDR_160_MHZ: 1167 case DDR_160_MHZ:
1168 bOverrideSelfRefresh = TRUE; 1168 bOverrideSelfRefresh = TRUE;
1169 psDDRSetting = asT3LPB_DDRSetting160MHz; 1169 psDDRSetting = asT3LPB_DDRSetting160MHz;
1170 RegCount = sizeof(asT3LPB_DDRSetting160MHz)/sizeof(DDR_SET_NODE); 1170 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting160MHz);
1171 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ; 1171 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ;
1172 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ; 1172 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ;
1173 1173
@@ -1181,19 +1181,19 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1181 { 1181 {
1182 case DDR_80_MHZ: 1182 case DDR_80_MHZ:
1183 psDDRSetting = asT3_DDRSetting80MHz; 1183 psDDRSetting = asT3_DDRSetting80MHz;
1184 RegCount = (sizeof(asT3_DDRSetting80MHz)/sizeof(DDR_SET_NODE)); 1184 RegCount = ARRAY_SIZE(asT3_DDRSetting80MHz);
1185 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ; 1185 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ;
1186 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ; 1186 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1187 break; 1187 break;
1188 case DDR_100_MHZ: 1188 case DDR_100_MHZ:
1189 psDDRSetting = asT3_DDRSetting100MHz; 1189 psDDRSetting = asT3_DDRSetting100MHz;
1190 RegCount = (sizeof(asT3_DDRSetting100MHz)/sizeof(DDR_SET_NODE)); 1190 RegCount = ARRAY_SIZE(asT3_DDRSetting100MHz);
1191 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ; 1191 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ;
1192 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ; 1192 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1193 break; 1193 break;
1194 case DDR_133_MHZ: 1194 case DDR_133_MHZ:
1195 psDDRSetting = asT3_DDRSetting133MHz; 1195 psDDRSetting = asT3_DDRSetting133MHz;
1196 RegCount = (sizeof(asT3_DDRSetting133MHz)/sizeof(DDR_SET_NODE)); 1196 RegCount = ARRAY_SIZE(asT3_DDRSetting133MHz);
1197 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ; 1197 RegCount-=T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ;
1198 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ; 1198 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ;
1199 break; 1199 break;
@@ -1207,20 +1207,20 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1207 { 1207 {
1208 case DDR_80_MHZ: 1208 case DDR_80_MHZ:
1209 psDDRSetting = asT3B_DDRSetting80MHz; 1209 psDDRSetting = asT3B_DDRSetting80MHz;
1210 RegCount = (sizeof(asT3B_DDRSetting80MHz)/sizeof(DDR_SET_NODE)); 1210 RegCount = ARRAY_SIZE(asT3B_DDRSetting80MHz);
1211 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ; 1211 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ ;
1212 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ; 1212 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1213 break; 1213 break;
1214 case DDR_100_MHZ: 1214 case DDR_100_MHZ:
1215 psDDRSetting = asT3B_DDRSetting100MHz; 1215 psDDRSetting = asT3B_DDRSetting100MHz;
1216 RegCount = (sizeof(asT3B_DDRSetting100MHz)/sizeof(DDR_SET_NODE)); 1216 RegCount = ARRAY_SIZE(asT3B_DDRSetting100MHz);
1217 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ; 1217 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ ;
1218 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ; 1218 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1219 break; 1219 break;
1220 case DDR_133_MHZ: 1220 case DDR_133_MHZ:
1221 bOverrideSelfRefresh = TRUE; 1221 bOverrideSelfRefresh = TRUE;
1222 psDDRSetting = asT3B_DDRSetting133MHz; 1222 psDDRSetting = asT3B_DDRSetting133MHz;
1223 RegCount = (sizeof(asT3B_DDRSetting133MHz)/sizeof(DDR_SET_NODE)); 1223 RegCount = ARRAY_SIZE(asT3B_DDRSetting133MHz);
1224 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ; 1224 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ ;
1225 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ; 1225 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1226 break; 1226 break;
diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c
index 5b4fd372ec36..1da21642c18e 100644
--- a/drivers/staging/bcm/IPv6Protocol.c
+++ b/drivers/staging/bcm/IPv6Protocol.c
@@ -1,51 +1,52 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header); 3static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,
4static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header); 4 IPV6Header *pstIpv6Header);
5static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,
6 IPV6Header *pstIpv6Header);
5static VOID DumpIpv6Header(IPV6Header *pstIpv6Header); 7static VOID DumpIpv6Header(IPV6Header *pstIpv6Header);
6 8
7static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEAN *bParseDone,USHORT *pusPayloadLength) 9static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload,
10 UCHAR *pucNextHeader, BOOLEAN *bParseDone, USHORT *pusPayloadLength)
8{ 11{
9 UCHAR *pucRetHeaderPtr = NULL; 12 UCHAR *pucRetHeaderPtr = NULL;
10 UCHAR *pucPayloadPtr = NULL; 13 UCHAR *pucPayloadPtr = NULL;
11 USHORT usNextHeaderOffset = 0 ; 14 USHORT usNextHeaderOffset = 0 ;
12 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 15 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
13 16
14 if((NULL == ppucPayload) || (*pusPayloadLength == 0) || (*bParseDone)) 17 if ((ppucPayload == NULL) || (*pusPayloadLength == 0) ||
15 { 18 (*bParseDone)) {
16 *bParseDone = TRUE; 19 *bParseDone = TRUE;
17 return NULL; 20 return NULL;
18
19 } 21 }
20 22
21 pucRetHeaderPtr = *ppucPayload; 23 pucRetHeaderPtr = *ppucPayload;
22 pucPayloadPtr = *ppucPayload; 24 pucPayloadPtr = *ppucPayload;
23 25
24 if(!pucRetHeaderPtr || !pucPayloadPtr) 26 if (!pucRetHeaderPtr || !pucPayloadPtr) {
25 {
26 *bParseDone = TRUE; 27 *bParseDone = TRUE;
27 return NULL; 28 return NULL;
28 } 29 }
29 30
30 //Get the Nextt Header Type 31 /* Get the Nextt Header Type */
31 *bParseDone = FALSE; 32 *bParseDone = FALSE;
32 33
33 34
34 35 switch (*pucNextHeader) {
35 switch(*pucNextHeader)
36 {
37 case IPV6HDR_TYPE_HOPBYHOP: 36 case IPV6HDR_TYPE_HOPBYHOP:
38 { 37 {
39 38
40 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 HopByHop Header"); 39 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
41 usNextHeaderOffset+=sizeof(IPV6HopByHopOptionsHeader); 40 DBG_LVL_ALL, "\nIPv6 HopByHop Header");
41 usNextHeaderOffset += sizeof(IPV6HopByHopOptionsHeader);
42 } 42 }
43 break; 43 break;
44 44
45 case IPV6HDR_TYPE_ROUTING: 45 case IPV6HDR_TYPE_ROUTING:
46 { 46 {
47 IPV6RoutingHeader *pstIpv6RoutingHeader; 47 IPV6RoutingHeader *pstIpv6RoutingHeader;
48 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Routing Header"); 48 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
49 DBG_LVL_ALL, "\nIPv6 Routing Header");
49 pstIpv6RoutingHeader = (IPV6RoutingHeader *)pucPayloadPtr; 50 pstIpv6RoutingHeader = (IPV6RoutingHeader *)pucPayloadPtr;
50 usNextHeaderOffset += sizeof(IPV6RoutingHeader); 51 usNextHeaderOffset += sizeof(IPV6RoutingHeader);
51 usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses * IPV6_ADDRESS_SIZEINBYTES; 52 usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses * IPV6_ADDRESS_SIZEINBYTES;
@@ -54,8 +55,10 @@ static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader
54 break; 55 break;
55 case IPV6HDR_TYPE_FRAGMENTATION: 56 case IPV6HDR_TYPE_FRAGMENTATION:
56 { 57 {
57 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Fragmentation Header"); 58 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
58 usNextHeaderOffset+= sizeof(IPV6FragmentHeader); 59 DBG_LVL_ALL,
60 "\nIPv6 Fragmentation Header");
61 usNextHeaderOffset += sizeof(IPV6FragmentHeader);
59 62
60 } 63 }
61 break; 64 break;
@@ -63,9 +66,11 @@ static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader
63 { 66 {
64 IPV6DestOptionsHeader *pstIpv6DestOptsHdr = (IPV6DestOptionsHeader *)pucPayloadPtr; 67 IPV6DestOptionsHeader *pstIpv6DestOptsHdr = (IPV6DestOptionsHeader *)pucPayloadPtr;
65 int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen; 68 int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen;
66 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 DestOpts Header Header"); 69 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
67 usNextHeaderOffset+= sizeof(IPV6DestOptionsHeader); 70 DBG_LVL_ALL,
68 usNextHeaderOffset+= nTotalOptions * IPV6_DESTOPTS_HDR_OPTIONSIZE ; 71 "\nIPv6 DestOpts Header Header");
72 usNextHeaderOffset += sizeof(IPV6DestOptionsHeader);
73 usNextHeaderOffset += nTotalOptions * IPV6_DESTOPTS_HDR_OPTIONSIZE ;
69 74
70 } 75 }
71 break; 76 break;
@@ -73,36 +78,43 @@ static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader
73 { 78 {
74 IPV6AuthenticationHeader *pstIpv6AuthHdr = (IPV6AuthenticationHeader *)pucPayloadPtr; 79 IPV6AuthenticationHeader *pstIpv6AuthHdr = (IPV6AuthenticationHeader *)pucPayloadPtr;
75 int nHdrLen = pstIpv6AuthHdr->ucLength; 80 int nHdrLen = pstIpv6AuthHdr->ucLength;
76 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Authentication Header"); 81 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
77 usNextHeaderOffset+= nHdrLen * 4; 82 DBG_LVL_ALL,
83 "\nIPv6 Authentication Header");
84 usNextHeaderOffset += nHdrLen * 4;
78 } 85 }
79 break; 86 break;
80 case IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD: 87 case IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD:
81 { 88 {
82 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Encrypted Security Payload Header"); 89 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
90 DBG_LVL_ALL,
91 "\nIPv6 Encrypted Security Payload Header");
83 *bParseDone = TRUE; 92 *bParseDone = TRUE;
84 93
85 } 94 }
86 break; 95 break;
87 case IPV6_ICMP_HDR_TYPE: 96 case IPV6_ICMP_HDR_TYPE:
88 { 97 {
89 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, " ICMP Header"); 98 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
99 DBG_LVL_ALL, "\nICMP Header");
90 *bParseDone = TRUE; 100 *bParseDone = TRUE;
91 } 101 }
92 break; 102 break;
93 case TCP_HEADER_TYPE: 103 case TCP_HEADER_TYPE:
94 { 104 {
95 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, " \nTCP Header"); 105 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
106 DBG_LVL_ALL, "\nTCP Header");
96 *bParseDone = TRUE; 107 *bParseDone = TRUE;
97 } 108 }
98 break; 109 break;
99 case UDP_HEADER_TYPE: 110 case UDP_HEADER_TYPE:
100 { 111 {
101 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, " \nUDP Header"); 112 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
113 DBG_LVL_ALL, "\nUDP Header");
102 *bParseDone = TRUE; 114 *bParseDone = TRUE;
103 } 115 }
104 break; 116 break;
105 default : 117 default:
106 { 118 {
107 *bParseDone = TRUE; 119 *bParseDone = TRUE;
108 120
@@ -112,53 +124,49 @@ static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader
112 124
113 } 125 }
114 126
115 if(*bParseDone == FALSE) 127 if (*bParseDone == FALSE) {
116 { 128 if (*pusPayloadLength <= usNextHeaderOffset) {
117 if(*pusPayloadLength <= usNextHeaderOffset)
118 {
119 *bParseDone = TRUE; 129 *bParseDone = TRUE;
120 } 130 } else {
121 else
122 {
123 *pucNextHeader = *pucPayloadPtr; 131 *pucNextHeader = *pucPayloadPtr;
124 pucPayloadPtr+=usNextHeaderOffset; 132 pucPayloadPtr += usNextHeaderOffset;
125 (*pusPayloadLength)-=usNextHeaderOffset; 133 (*pusPayloadLength) -= usNextHeaderOffset;
126 } 134 }
127 135
128 } 136 }
129 137
130
131
132 *ppucPayload = pucPayloadPtr; 138 *ppucPayload = pucPayloadPtr;
133 return pucRetHeaderPtr; 139 return pucRetHeaderPtr;
134} 140}
135 141
136 142
137static UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload,USHORT *pusSrcPort,USHORT *pusDestPort,USHORT usPayloadLength,UCHAR ucNextHeader) 143static UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload, USHORT *pusSrcPort,
144 USHORT *pusDestPort, USHORT usPayloadLength, UCHAR ucNextHeader)
138{ 145{
139 UCHAR *pIpv6HdrScanContext = pucPayload; 146 UCHAR *pIpv6HdrScanContext = pucPayload;
140 BOOLEAN bDone = FALSE; 147 BOOLEAN bDone = FALSE;
141 UCHAR ucHeaderType =0; 148 UCHAR ucHeaderType = 0;
142 UCHAR *pucNextHeader = NULL; 149 UCHAR *pucNextHeader = NULL;
143 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 150 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
144 151
145 if( !pucPayload || (usPayloadLength == 0)) 152 if (!pucPayload || (usPayloadLength == 0))
146 {
147 return 0; 153 return 0;
148 }
149 154
150 *pusSrcPort = *pusDestPort = 0; 155 *pusSrcPort = *pusDestPort = 0;
151 ucHeaderType = ucNextHeader; 156 ucHeaderType = ucNextHeader;
152 while(!bDone) 157 while (!bDone) {
153 { 158 pucNextHeader = GetNextIPV6ChainedHeader(&pIpv6HdrScanContext,
154 pucNextHeader = GetNextIPV6ChainedHeader(&pIpv6HdrScanContext,&ucHeaderType,&bDone,&usPayloadLength); 159 &ucHeaderType, &bDone, &usPayloadLength);
155 if(bDone) 160 if (bDone) {
156 { 161 if ((ucHeaderType == TCP_HEADER_TYPE) ||
157 if((ucHeaderType==TCP_HEADER_TYPE) || (ucHeaderType == UDP_HEADER_TYPE)) 162 (ucHeaderType == UDP_HEADER_TYPE)) {
158 { 163 *pusSrcPort = *((PUSHORT)(pucNextHeader));
159 *pusSrcPort=*((PUSHORT)(pucNextHeader)); 164 *pusDestPort = *((PUSHORT)(pucNextHeader+2));
160 *pusDestPort=*((PUSHORT)(pucNextHeader+2)); 165 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
161 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, " \nProtocol Ports - Src Port :0x%x Dest Port : 0x%x",ntohs(*pusSrcPort),ntohs(*pusDestPort)); 166 DBG_LVL_ALL,
167 "\nProtocol Ports - Src Port :0x%x Dest Port : 0x%x",
168 ntohs(*pusSrcPort),
169 ntohs(*pusDestPort));
162 } 170 }
163 break; 171 break;
164 172
@@ -168,92 +176,111 @@ static UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload,USHORT *pusSrcPort,USHORT *p
168} 176}
169 177
170 178
171 179/*
172USHORT IpVersion6(PMINI_ADAPTER Adapter, /**< Pointer to the driver control structure */ 180 * Arg 1 PMINI_ADAPTER Adapter is a pointer ot the driver contorl structure
173 PVOID pcIpHeader, /**<Pointer to the IP Hdr of the packet*/ 181 * Arg 2 PVOID pcIpHeader is a pointer to the IP header of the packet
174 S_CLASSIFIER_RULE *pstClassifierRule ) 182 */
183USHORT IpVersion6(PMINI_ADAPTER Adapter, PVOID pcIpHeader,
184 S_CLASSIFIER_RULE *pstClassifierRule)
175{ 185{
176 USHORT ushDestPort = 0; 186 USHORT ushDestPort = 0;
177 USHORT ushSrcPort = 0; 187 USHORT ushSrcPort = 0;
178 UCHAR ucNextProtocolAboveIP =0; 188 UCHAR ucNextProtocolAboveIP = 0;
179 IPV6Header *pstIpv6Header = NULL; 189 IPV6Header *pstIpv6Header = NULL;
180 BOOLEAN bClassificationSucceed = FALSE; 190 BOOLEAN bClassificationSucceed = FALSE;
181 191
182 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "IpVersion6 ==========>\n"); 192 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
193 DBG_LVL_ALL, "IpVersion6 ==========>\n");
183 194
184 pstIpv6Header = (IPV6Header *)pcIpHeader; 195 pstIpv6Header = (IPV6Header *)pcIpHeader;
185 196
186 DumpIpv6Header(pstIpv6Header); 197 DumpIpv6Header(pstIpv6Header);
187 198
188 //Try to get the next higher layer protocol and the Ports Nos if TCP or UDP 199 /*
200 * Try to get the next higher layer protocol
201 * and the Ports Nos if TCP or UDP
202 */
189 ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(IPV6Header)), 203 ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(IPV6Header)),
190 &ushSrcPort, 204 &ushSrcPort,
191 &ushDestPort, 205 &ushDestPort,
192 pstIpv6Header->usPayloadLength, 206 pstIpv6Header->usPayloadLength,
193 pstIpv6Header->ucNextHeader); 207 pstIpv6Header->ucNextHeader);
194 208
195 do 209 do {
196 { 210 if (pstClassifierRule->ucDirection == 0) {
197 if(0 == pstClassifierRule->ucDirection) 211 /*
198 { 212 * cannot be processed for classification.
199 //cannot be processed for classification. 213 * it is a down link connection
200 // it is a down link connection 214 */
201 break; 215 break;
202 } 216 }
203 217
204 if(!pstClassifierRule->bIpv6Protocol) 218 if (!pstClassifierRule->bIpv6Protocol) {
205 { 219 /*
206 //We are looking for Ipv6 Classifiers . Lets ignore this classifier and try the next one. 220 * We are looking for Ipv6 Classifiers
221 * Lets ignore this classifier and try the next one
222 */
207 break; 223 break;
208 } 224 }
209 225
210 bClassificationSucceed=MatchSrcIpv6Address(pstClassifierRule,pstIpv6Header); 226 bClassificationSucceed = MatchSrcIpv6Address(pstClassifierRule,
211 if(!bClassificationSucceed) 227 pstIpv6Header);
212 break; 228 if (!bClassificationSucceed)
229 break;
213 230
214 bClassificationSucceed=MatchDestIpv6Address(pstClassifierRule,pstIpv6Header); 231 bClassificationSucceed = MatchDestIpv6Address(pstClassifierRule,
215 if(!bClassificationSucceed) 232 pstIpv6Header);
216 break; 233 if (!bClassificationSucceed)
234 break;
217 235
218 //Match the protocol type.For IPv6 the next protocol at end of Chain of IPv6 prot headers 236 /*
219 bClassificationSucceed=MatchProtocol(pstClassifierRule,ucNextProtocolAboveIP); 237 * Match the protocol type.
220 if(!bClassificationSucceed) 238 * For IPv6 the next protocol at end of
221 break; 239 * Chain of IPv6 prot headers
222 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Protocol Matched"); 240 */
241 bClassificationSucceed = MatchProtocol(pstClassifierRule,
242 ucNextProtocolAboveIP);
243 if (!bClassificationSucceed)
244 break;
223 245
224 if((ucNextProtocolAboveIP == TCP_HEADER_TYPE) || (ucNextProtocolAboveIP == UDP_HEADER_TYPE)) 246 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
225 { 247 DBG_LVL_ALL, "\nIPv6 Protocol Matched");
226 //Match Src Port 248
227 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Source Port:%x\n",ntohs(ushSrcPort)); 249 if ((ucNextProtocolAboveIP == TCP_HEADER_TYPE) ||
228 bClassificationSucceed=MatchSrcPort(pstClassifierRule,ntohs(ushSrcPort)); 250 (ucNextProtocolAboveIP == UDP_HEADER_TYPE)) {
229 if(!bClassificationSucceed) 251 /* Match Src Port */
252 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
253 DBG_LVL_ALL, "\nIPv6 Source Port:%x\n",
254 ntohs(ushSrcPort));
255 bClassificationSucceed = MatchSrcPort(pstClassifierRule,
256 ntohs(ushSrcPort));
257 if (!bClassificationSucceed)
230 break; 258 break;
231 259
232 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Src Port Matched"); 260 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
261 DBG_LVL_ALL, "\nIPv6 Src Port Matched");
233 262
234 //Match Dest Port 263 /* Match Dest Port */
235 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Destination Port:%x\n",ntohs(ushDestPort)); 264 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
236 bClassificationSucceed=MatchDestPort(pstClassifierRule,ntohs(ushDestPort)); 265 DBG_LVL_ALL, "\nIPv6 Destination Port:%x\n",
237 if(!bClassificationSucceed) 266 ntohs(ushDestPort));
267 bClassificationSucceed = MatchDestPort(pstClassifierRule,
268 ntohs(ushDestPort));
269 if (!bClassificationSucceed)
238 break; 270 break;
239 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\nIPv6 Dest Port Matched"); 271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
272 DBG_LVL_ALL, "\nIPv6 Dest Port Matched");
240 } 273 }
241 }while(0); 274 } while (0);
242 275
243 if(TRUE==bClassificationSucceed) 276 if (bClassificationSucceed == TRUE) {
244 {
245 INT iMatchedSFQueueIndex = 0; 277 INT iMatchedSFQueueIndex = 0;
246 iMatchedSFQueueIndex = SearchSfid(Adapter,pstClassifierRule->ulSFID); 278 iMatchedSFQueueIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
247 if(iMatchedSFQueueIndex >= NO_OF_QUEUES) 279 if (iMatchedSFQueueIndex >= NO_OF_QUEUES) {
248 {
249 bClassificationSucceed = FALSE; 280 bClassificationSucceed = FALSE;
250 } 281 } else {
251 else 282 if (Adapter->PackInfo[iMatchedSFQueueIndex].bActive == FALSE)
252 {
253 if(FALSE == Adapter->PackInfo[iMatchedSFQueueIndex].bActive)
254 {
255 bClassificationSucceed = FALSE; 283 bClassificationSucceed = FALSE;
256 }
257 } 284 }
258 } 285 }
259 286
@@ -261,52 +288,55 @@ USHORT IpVersion6(PMINI_ADAPTER Adapter, /**< Pointer to the driver control stru
261} 288}
262 289
263 290
264static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header) 291static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,
292 IPV6Header *pstIpv6Header)
265{ 293{
266 UINT uiLoopIndex=0; 294 UINT uiLoopIndex = 0;
267 UINT uiIpv6AddIndex=0; 295 UINT uiIpv6AddIndex = 0;
268 UINT uiIpv6AddrNoLongWords = 4; 296 UINT uiIpv6AddrNoLongWords = 4;
269 ULONG aulSrcIP[4]; 297 ULONG aulSrcIP[4];
270 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 298 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
271 /* 299 /*
272 //This is the no. of Src Addresses ie Range of IP Addresses contained 300 * This is the no. of Src Addresses ie Range of IP Addresses contained
273 //in the classifier rule for which we need to match 301 * in the classifier rule for which we need to match
274 */ 302 */
275 UINT uiCountIPSrcAddresses = (UINT)pstClassifierRule->ucIPSourceAddressLength; 303 UINT uiCountIPSrcAddresses = (UINT)pstClassifierRule->ucIPSourceAddressLength;
276 304
277 305
278 if(0 == uiCountIPSrcAddresses) 306 if (uiCountIPSrcAddresses == 0)
279 return TRUE; 307 return TRUE;
280 308
281 309
282 //First Convert the Ip Address in the packet to Host Endian order 310 /* First Convert the Ip Address in the packet to Host Endian order */
283 for(uiIpv6AddIndex=0;uiIpv6AddIndex<uiIpv6AddrNoLongWords;uiIpv6AddIndex++) 311 for (uiIpv6AddIndex = 0; uiIpv6AddIndex < uiIpv6AddrNoLongWords; uiIpv6AddIndex++)
284 { 312 aulSrcIP[uiIpv6AddIndex] = ntohl(pstIpv6Header->ulSrcIpAddress[uiIpv6AddIndex]);
285 aulSrcIP[uiIpv6AddIndex]=ntohl(pstIpv6Header->ulSrcIpAddress[uiIpv6AddIndex]);
286 }
287 313
288 for(uiLoopIndex=0;uiLoopIndex<uiCountIPSrcAddresses;uiLoopIndex+=uiIpv6AddrNoLongWords) 314 for (uiLoopIndex = 0; uiLoopIndex < uiCountIPSrcAddresses; uiLoopIndex += uiIpv6AddrNoLongWords) {
289 { 315 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
290 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Src Ipv6 Address In Received Packet : \n "); 316 "\n Src Ipv6 Address In Received Packet :\n ");
291 DumpIpv6Address(aulSrcIP); 317 DumpIpv6Address(aulSrcIP);
292 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Src Ipv6 Mask In Classifier Rule: \n"); 318 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
319 "\n Src Ipv6 Mask In Classifier Rule:\n");
293 DumpIpv6Address(&pstClassifierRule->stSrcIpAddress.ulIpv6Mask[uiLoopIndex]); 320 DumpIpv6Address(&pstClassifierRule->stSrcIpAddress.ulIpv6Mask[uiLoopIndex]);
294 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Src Ipv6 Address In Classifier Rule : \n"); 321 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
322 "\n Src Ipv6 Address In Classifier Rule :\n");
295 DumpIpv6Address(&pstClassifierRule->stSrcIpAddress.ulIpv6Addr[uiLoopIndex]); 323 DumpIpv6Address(&pstClassifierRule->stSrcIpAddress.ulIpv6Addr[uiLoopIndex]);
296 324
297 for(uiIpv6AddIndex=0;uiIpv6AddIndex<uiIpv6AddrNoLongWords;uiIpv6AddIndex++) 325 for (uiIpv6AddIndex = 0; uiIpv6AddIndex < uiIpv6AddrNoLongWords; uiIpv6AddIndex++) {
298 { 326 if ((pstClassifierRule->stSrcIpAddress.ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] & aulSrcIP[uiIpv6AddIndex])
299 if((pstClassifierRule->stSrcIpAddress.ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] & aulSrcIP[uiIpv6AddIndex]) 327 != pstClassifierRule->stSrcIpAddress.ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) {
300 != pstClassifierRule->stSrcIpAddress.ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) 328 /*
301 { 329 * Match failed for current Ipv6 Address
302 //Match failed for current Ipv6 Address.Try next Ipv6 Address 330 * Try next Ipv6 Address
331 */
303 break; 332 break;
304 } 333 }
305 334
306 if(uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) 335 if (uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) {
307 { 336 /* Match Found */
308 //Match Found 337 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
309 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Ipv6 Src Ip Address Matched\n"); 338 DBG_LVL_ALL,
339 "Ipv6 Src Ip Address Matched\n");
310 return TRUE; 340 return TRUE;
311 } 341 }
312 } 342 }
@@ -314,52 +344,56 @@ static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Head
314 return FALSE; 344 return FALSE;
315} 345}
316 346
317static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header) 347static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,
348 IPV6Header *pstIpv6Header)
318{ 349{
319 UINT uiLoopIndex=0; 350 UINT uiLoopIndex = 0;
320 UINT uiIpv6AddIndex=0; 351 UINT uiIpv6AddIndex = 0;
321 UINT uiIpv6AddrNoLongWords = 4; 352 UINT uiIpv6AddrNoLongWords = 4;
322 ULONG aulDestIP[4]; 353 ULONG aulDestIP[4];
323 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 354 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
324 /* 355 /*
325 //This is the no. of Destination Addresses ie Range of IP Addresses contained 356 * This is the no. of Destination Addresses
326 //in the classifier rule for which we need to match 357 * ie Range of IP Addresses contained in the classifier rule
327 */ 358 * for which we need to match
359 */
328 UINT uiCountIPDestinationAddresses = (UINT)pstClassifierRule->ucIPDestinationAddressLength; 360 UINT uiCountIPDestinationAddresses = (UINT)pstClassifierRule->ucIPDestinationAddressLength;
329 361
330 362
331 if(0 == uiCountIPDestinationAddresses) 363 if (uiCountIPDestinationAddresses == 0)
332 return TRUE; 364 return TRUE;
333 365
334 366
335 //First Convert the Ip Address in the packet to Host Endian order 367 /* First Convert the Ip Address in the packet to Host Endian order */
336 for(uiIpv6AddIndex=0;uiIpv6AddIndex<uiIpv6AddrNoLongWords;uiIpv6AddIndex++) 368 for (uiIpv6AddIndex = 0; uiIpv6AddIndex < uiIpv6AddrNoLongWords; uiIpv6AddIndex++)
337 { 369 aulDestIP[uiIpv6AddIndex] = ntohl(pstIpv6Header->ulDestIpAddress[uiIpv6AddIndex]);
338 aulDestIP[uiIpv6AddIndex]=ntohl(pstIpv6Header->ulDestIpAddress[uiIpv6AddIndex]);
339 }
340 370
341 for(uiLoopIndex=0;uiLoopIndex<uiCountIPDestinationAddresses;uiLoopIndex+=uiIpv6AddrNoLongWords) 371 for (uiLoopIndex = 0; uiLoopIndex < uiCountIPDestinationAddresses; uiLoopIndex += uiIpv6AddrNoLongWords) {
342 { 372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
343 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Destination Ipv6 Address In Received Packet : \n "); 373 "\n Destination Ipv6 Address In Received Packet :\n ");
344 DumpIpv6Address(aulDestIP); 374 DumpIpv6Address(aulDestIP);
345 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Destination Ipv6 Mask In Classifier Rule: \n"); 375 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
376 "\n Destination Ipv6 Mask In Classifier Rule :\n");
346 DumpIpv6Address(&pstClassifierRule->stDestIpAddress.ulIpv6Mask[uiLoopIndex]); 377 DumpIpv6Address(&pstClassifierRule->stDestIpAddress.ulIpv6Mask[uiLoopIndex]);
347 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "\n Destination Ipv6 Address In Classifier Rule : \n"); 378 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
379 "\n Destination Ipv6 Address In Classifier Rule :\n");
348 DumpIpv6Address(&pstClassifierRule->stDestIpAddress.ulIpv6Addr[uiLoopIndex]); 380 DumpIpv6Address(&pstClassifierRule->stDestIpAddress.ulIpv6Addr[uiLoopIndex]);
349 381
350 for(uiIpv6AddIndex=0;uiIpv6AddIndex<uiIpv6AddrNoLongWords;uiIpv6AddIndex++) 382 for (uiIpv6AddIndex = 0; uiIpv6AddIndex < uiIpv6AddrNoLongWords; uiIpv6AddIndex++) {
351 { 383 if ((pstClassifierRule->stDestIpAddress.ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] & aulDestIP[uiIpv6AddIndex])
352 if((pstClassifierRule->stDestIpAddress.ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] & aulDestIP[uiIpv6AddIndex]) 384 != pstClassifierRule->stDestIpAddress.ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) {
353 != pstClassifierRule->stDestIpAddress.ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) 385 /*
354 { 386 * Match failed for current Ipv6 Address.
355 //Match failed for current Ipv6 Address.Try next Ipv6 Address 387 * Try next Ipv6 Address
388 */
356 break; 389 break;
357 } 390 }
358 391
359 if(uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) 392 if (uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) {
360 { 393 /* Match Found */
361 //Match Found 394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
362 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Ipv6 Destination Ip Address Matched\n"); 395 DBG_LVL_ALL,
396 "Ipv6 Destination Ip Address Matched\n");
363 return TRUE; 397 return TRUE;
364 } 398 }
365 } 399 }
@@ -371,11 +405,11 @@ static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Hea
371VOID DumpIpv6Address(ULONG *puIpv6Address) 405VOID DumpIpv6Address(ULONG *puIpv6Address)
372{ 406{
373 UINT uiIpv6AddrNoLongWords = 4; 407 UINT uiIpv6AddrNoLongWords = 4;
374 UINT uiIpv6AddIndex=0; 408 UINT uiIpv6AddIndex = 0;
375 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 409 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
376 for(uiIpv6AddIndex=0;uiIpv6AddIndex<uiIpv6AddrNoLongWords;uiIpv6AddIndex++) 410 for (uiIpv6AddIndex = 0; uiIpv6AddIndex < uiIpv6AddrNoLongWords; uiIpv6AddIndex++) {
377 { 411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
378 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, ":%lx",puIpv6Address[uiIpv6AddIndex]); 412 ":%lx", puIpv6Address[uiIpv6AddIndex]);
379 } 413 }
380 414
381} 415}
@@ -383,22 +417,35 @@ VOID DumpIpv6Address(ULONG *puIpv6Address)
383static VOID DumpIpv6Header(IPV6Header *pstIpv6Header) 417static VOID DumpIpv6Header(IPV6Header *pstIpv6Header)
384{ 418{
385 UCHAR ucVersion; 419 UCHAR ucVersion;
386 UCHAR ucPrio ; 420 UCHAR ucPrio;
387 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 421 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
388 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "----Ipv6 Header---"); 422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
423 "----Ipv6 Header---");
389 ucVersion = pstIpv6Header->ucVersionPrio & 0xf0; 424 ucVersion = pstIpv6Header->ucVersionPrio & 0xf0;
390 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Version : %x \n",ucVersion); 425 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
426 "Version : %x\n", ucVersion);
391 ucPrio = pstIpv6Header->ucVersionPrio & 0x0f; 427 ucPrio = pstIpv6Header->ucVersionPrio & 0x0f;
392 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Priority : %x \n",ucPrio); 428 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
393 //BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Flow Label : %x \n",(pstIpv6Header->ucVersionPrio &0xf0); 429 "Priority : %x\n", ucPrio);
394 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Payload Length : %x \n",ntohs(pstIpv6Header->usPayloadLength)); 430 /*
395 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Next Header : %x \n",pstIpv6Header->ucNextHeader); 431 * BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
396 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Hop Limit : %x \n",pstIpv6Header->ucHopLimit); 432 * "Flow Label : %x\n",(pstIpv6Header->ucVersionPrio &0xf0);
397 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Src Address :\n"); 433 */
434 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
435 "Payload Length : %x\n",
436 ntohs(pstIpv6Header->usPayloadLength));
437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
438 "Next Header : %x\n", pstIpv6Header->ucNextHeader);
439 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
440 "Hop Limit : %x\n", pstIpv6Header->ucHopLimit);
441 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
442 "Src Address :\n");
398 DumpIpv6Address(pstIpv6Header->ulSrcIpAddress); 443 DumpIpv6Address(pstIpv6Header->ulSrcIpAddress);
399 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "Dest Address :\n"); 444 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
445 "Dest Address :\n");
400 DumpIpv6Address(pstIpv6Header->ulDestIpAddress); 446 DumpIpv6Address(pstIpv6Header->ulDestIpAddress);
401 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL, "----Ipv6 Header End---"); 447 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
448 "----Ipv6 Header End---");
402 449
403 450
404} 451}
diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c
index c7725e141fd5..8223a6913fc5 100644
--- a/drivers/staging/bcm/Misc.c
+++ b/drivers/staging/bcm/Misc.c
@@ -835,7 +835,7 @@ int reset_card_proc(PMINI_ADAPTER ps_adapter)
835 Bcm_kill_all_URBs(psIntfAdapter); 835 Bcm_kill_all_URBs(psIntfAdapter);
836 /* Reset the UMA-B Device */ 836 /* Reset the UMA-B Device */
837 if (ps_adapter->chip_id >= T3LPB) { 837 if (ps_adapter->chip_id >= T3LPB) {
838 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reseting UMA-B\n"); 838 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
839 retval = usb_reset_device(psIntfAdapter->udev); 839 retval = usb_reset_device(psIntfAdapter->udev);
840 psIntfAdapter->psAdapter->StopAllXaction = FALSE; 840 psIntfAdapter->psAdapter->StopAllXaction = FALSE;
841 841
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 12c691d90900..3bbe3fd103f3 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1,6 +1,5 @@
1config COMEDI 1config COMEDI
2 tristate "Data acquisition support (comedi)" 2 tristate "Data acquisition support (comedi)"
3 default N
4 depends on m 3 depends on m
5 depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || X86 4 depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || X86
6 ---help--- 5 ---help---
@@ -14,10 +13,29 @@ config COMEDI_DEBUG
14 This is an option for use by developers; most people should 13 This is an option for use by developers; most people should
15 say N here. This enables comedi core and driver debugging. 14 say N here. This enables comedi core and driver debugging.
16 15
16config COMEDI_DEFAULT_BUF_SIZE_KB
17 int "Comedi default initial asynchronous buffer size in KiB"
18 default "2048"
19 depends on COMEDI != n
20 ---help---
21 This is the default asynchronous buffer size which is used for
22 commands running in the background in kernel space. This
23 defaults to 2048 KiB of memory so that a 16 channel card
24 running at 10 kHz has of 2-4 seconds of buffer.
25
26config COMEDI_DEFAULT_BUF_MAXSIZE_KB
27 int "Comedi default maximum asynchronous buffer size in KiB"
28 default "20480"
29 depends on COMEDI != n
30 ---help---
31 This is the default maximum asynchronous buffer size which can
32 be requested by a userspace program without root privileges.
33 This is set to 20480 KiB so that a fast I/O card with 16
34 channels running at 100 kHz has 2-4 seconds of buffer.
35
17menuconfig COMEDI_MISC_DRIVERS 36menuconfig COMEDI_MISC_DRIVERS
18 tristate "Comedi misc drivers" 37 tristate "Comedi misc drivers"
19 depends on COMEDI 38 depends on COMEDI
20 default N
21 ---help--- 39 ---help---
22 Enable comedi misc drivers to be built 40 Enable comedi misc drivers to be built
23 41
@@ -35,7 +53,6 @@ config COMEDI_KCOMEDILIB
35config COMEDI_BOND 53config COMEDI_BOND
36 tristate "Device bonding support" 54 tristate "Device bonding support"
37 depends on COMEDI_KCOMEDILIB 55 depends on COMEDI_KCOMEDILIB
38 default N
39 ---help--- 56 ---help---
40 Enable support for a driver to 'bond' (merge) multiple subdevices 57 Enable support for a driver to 'bond' (merge) multiple subdevices
41 from multiple devices together as one. 58 from multiple devices together as one.
@@ -46,7 +63,6 @@ config COMEDI_BOND
46config COMEDI_TEST 63config COMEDI_TEST
47 tristate "Fake waveform generator support" 64 tristate "Fake waveform generator support"
48 select COMEDI_FC 65 select COMEDI_FC
49 default N
50 ---help--- 66 ---help---
51 Enable support for the fake waveform generator. 67 Enable support for the fake waveform generator.
52 This driver is mainly for testing purposes, but can also be used to 68 This driver is mainly for testing purposes, but can also be used to
@@ -58,7 +74,6 @@ config COMEDI_TEST
58 74
59config COMEDI_PARPORT 75config COMEDI_PARPORT
60 tristate "Parallel port support" 76 tristate "Parallel port support"
61 default N
62 ---help--- 77 ---help---
63 Enable support for the standard parallel port. 78 Enable support for the standard parallel port.
64 A cheap and easy way to get a few more digital I/O lines. Steal 79 A cheap and easy way to get a few more digital I/O lines. Steal
@@ -70,7 +85,6 @@ config COMEDI_PARPORT
70 85
71config COMEDI_SERIAL2002 86config COMEDI_SERIAL2002
72 tristate "Driver for serial connected hardware" 87 tristate "Driver for serial connected hardware"
73 default N
74 ---help--- 88 ---help---
75 Enable support for serial connected hardware 89 Enable support for serial connected hardware
76 90
@@ -79,7 +93,6 @@ config COMEDI_SERIAL2002
79 93
80config COMEDI_SKEL 94config COMEDI_SKEL
81 tristate "Comedi skeleton driver" 95 tristate "Comedi skeleton driver"
82 default N
83 ---help--- 96 ---help---
84 Build the Skeleton driver, an example for driver writers 97 Build the Skeleton driver, an example for driver writers
85 98
@@ -91,7 +104,6 @@ endif # COMEDI_MISC_DRIVERS
91menuconfig COMEDI_ISA_DRIVERS 104menuconfig COMEDI_ISA_DRIVERS
92 tristate "Comedi ISA and PC/104 drivers" 105 tristate "Comedi ISA and PC/104 drivers"
93 depends on COMEDI && ISA 106 depends on COMEDI && ISA
94 default N
95 ---help--- 107 ---help---
96 Enable comedi ISA and PC/104 drivers to be built 108 Enable comedi ISA and PC/104 drivers to be built
97 109
@@ -103,7 +115,6 @@ if COMEDI_ISA_DRIVERS && ISA
103 115
104config COMEDI_ACL7225B 116config COMEDI_ACL7225B
105 tristate "ADlink NuDAQ ACL-7225b and compatibles support" 117 tristate "ADlink NuDAQ ACL-7225b and compatibles support"
106 default N
107 ---help--- 118 ---help---
108 Enable support for ADlink NuDAQ ACL-7225b and compatibles, 119 Enable support for ADlink NuDAQ ACL-7225b and compatibles,
109 ADlink ACL-7225b (acl7225b), ICP P16R16DIO (p16r16dio) 120 ADlink ACL-7225b (acl7225b), ICP P16R16DIO (p16r16dio)
@@ -113,7 +124,6 @@ config COMEDI_ACL7225B
113 124
114config COMEDI_PCL711 125config COMEDI_PCL711
115 tristate "Advantech PCL-711/711b and ADlink ACL-8112 ISA card support" 126 tristate "Advantech PCL-711/711b and ADlink ACL-8112 ISA card support"
116 default N
117 ---help--- 127 ---help---
118 Enable support for Advantech PCL-711 and 711b, ADlink ACL-8112 128 Enable support for Advantech PCL-711 and 711b, ADlink ACL-8112
119 129
@@ -123,7 +133,6 @@ config COMEDI_PCL711
123config COMEDI_PCL724 133config COMEDI_PCL724
124 tristate "Advantech PCL-722/724/731 and ADlink ACL-7122/7124/PET-48DIO" 134 tristate "Advantech PCL-722/724/731 and ADlink ACL-7122/7124/PET-48DIO"
125 select COMEDI_8255 135 select COMEDI_8255
126 default N
127 ---help--- 136 ---help---
128 Enable support for Advantech PCL-724, PCL-722, PCL-731 and 137 Enable support for Advantech PCL-724, PCL-722, PCL-731 and
129 ADlink ACL-7122, ACL-7124, PET-48DIO ISA cards 138 ADlink ACL-7122, ACL-7124, PET-48DIO ISA cards
@@ -133,7 +142,6 @@ config COMEDI_PCL724
133 142
134config COMEDI_PCL725 143config COMEDI_PCL725
135 tristate "Advantech PCL-725 and compatible ISA card support" 144 tristate "Advantech PCL-725 and compatible ISA card support"
136 default N
137 ---help--- 145 ---help---
138 Enable support for Advantech PCL-725 and compatible ISA cards. 146 Enable support for Advantech PCL-725 and compatible ISA cards.
139 147
@@ -142,7 +150,6 @@ config COMEDI_PCL725
142 150
143config COMEDI_PCL726 151config COMEDI_PCL726
144 tristate "Advantech PCL-726 and compatible ISA card support" 152 tristate "Advantech PCL-726 and compatible ISA card support"
145 default N
146 ---help--- 153 ---help---
147 Enable support for Advantech PCL-726 and compatible ISA cards. 154 Enable support for Advantech PCL-726 and compatible ISA cards.
148 155
@@ -151,7 +158,6 @@ config COMEDI_PCL726
151 158
152config COMEDI_PCL730 159config COMEDI_PCL730
153 tristate "Advantech PCL-730 and ADlink ACL-7130 ISA card support" 160 tristate "Advantech PCL-730 and ADlink ACL-7130 ISA card support"
154 default N
155 ---help--- 161 ---help---
156 Enable support for Advantech PCL-730, ICP ISO-730 and ADlink 162 Enable support for Advantech PCL-730, ICP ISO-730 and ADlink
157 ACL-7130 ISA cards 163 ACL-7130 ISA cards
@@ -162,7 +168,6 @@ config COMEDI_PCL730
162config COMEDI_PCL812 168config COMEDI_PCL812
163 tristate "Advantech PCL-812/813 and ADlink ACL-8112/8113/8113/8216" 169 tristate "Advantech PCL-812/813 and ADlink ACL-8112/8113/8113/8216"
164 depends on VIRT_TO_BUS 170 depends on VIRT_TO_BUS
165 default N
166 ---help--- 171 ---help---
167 Enable support for Advantech PCL-812/PG, PCL-813/B, ADLink 172 Enable support for Advantech PCL-812/PG, PCL-813/B, ADLink
168 ACL-8112DG/HG/PG, ACL-8113, ACL-8216, ICP DAS A-821PGH/PGL/PGL-NDA, 173 ACL-8112DG/HG/PG, ACL-8113, ACL-8216, ICP DAS A-821PGH/PGL/PGL-NDA,
@@ -174,7 +179,6 @@ config COMEDI_PCL812
174config COMEDI_PCL816 179config COMEDI_PCL816
175 tristate "Advantech PCL-814 and PCL-816 ISA card support" 180 tristate "Advantech PCL-814 and PCL-816 ISA card support"
176 depends on VIRT_TO_BUS 181 depends on VIRT_TO_BUS
177 default N
178 ---help--- 182 ---help---
179 Enable support for Advantech PCL-814 and PCL-816 ISA cards 183 Enable support for Advantech PCL-814 and PCL-816 ISA cards
180 184
@@ -184,7 +188,6 @@ config COMEDI_PCL816
184config COMEDI_PCL818 188config COMEDI_PCL818
185 tristate "Advantech PCL-718 and PCL-818 ISA card support" 189 tristate "Advantech PCL-718 and PCL-818 ISA card support"
186 depends on VIRT_TO_BUS 190 depends on VIRT_TO_BUS
187 default N
188 ---help--- 191 ---help---
189 Enable support for Advantech PCL-818 ISA cards 192 Enable support for Advantech PCL-818 ISA cards
190 PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718 193 PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718
@@ -195,7 +198,6 @@ config COMEDI_PCL818
195config COMEDI_PCM3724 198config COMEDI_PCM3724
196 tristate "Advantech PCM-3724 PC/104 card support" 199 tristate "Advantech PCM-3724 PC/104 card support"
197 select COMEDI_8255 200 select COMEDI_8255
198 default N
199 ---help--- 201 ---help---
200 Enable support for Advantech PCM-3724 PC/104 cards. 202 Enable support for Advantech PCM-3724 PC/104 cards.
201 203
@@ -204,16 +206,43 @@ config COMEDI_PCM3724
204 206
205config COMEDI_PCM3730 207config COMEDI_PCM3730
206 tristate "Advantech PCM-3730 and clone PC/104 board support" 208 tristate "Advantech PCM-3730 and clone PC/104 board support"
207 default N
208 ---help--- 209 ---help---
209 Enable support for Advantech PCM-3730 and clone PC/104 boards 210 Enable support for Advantech PCM-3730 and clone PC/104 boards
210 211
211 To compile this driver as a module, choose M here: the module will be 212 To compile this driver as a module, choose M here: the module will be
212 called pcm3730. 213 called pcm3730.
213 214
215config COMEDI_AMPLC_DIO200_ISA
216 tristate "Amplicon PC212E/PC214E/PC215E/PC218E/PC272E"
217 select COMEDI_AMPLC_DIO200
218 depends on COMEDI_ISA_DRIVERS
219 ---help---
220 Enable support for Amplicon PC212E, PC214E, PC215E, PC218E and
221 PC272E ISA DIO boards
222
223 To compile this driver as a module, choose M here: the module will be
224 called amplc_dio200.
225
226config COMEDI_AMPLC_PC236_ISA
227 tristate "Amplicon PC36AT DIO board support"
228 select COMEDI_AMPLC_PC236
229 ---help---
230 Enable support for Amplicon PC36AT ISA DIO board.
231
232 To compile this driver as a module, choose M here: the module will be
233 called amplc_pc236.
234
235config COMEDI_AMPLC_PC263_ISA
236 tristate "Amplicon PC263 relay board support"
237 select COMEDI_AMPLC_PC263
238 ---help---
239 Enable support for Amplicon PC263 ISA relay board.
240
241 To compile this driver as a module, choose M here: the module will be
242 called amplc_pc263.
243
214config COMEDI_RTI800 244config COMEDI_RTI800
215 tristate "Analog Devices RTI-800/815 ISA card support" 245 tristate "Analog Devices RTI-800/815 ISA card support"
216 default N
217 ---help--- 246 ---help---
218 Enable support for Analog Devices RTI-800/815 ISA cards 247 Enable support for Analog Devices RTI-800/815 ISA cards
219 248
@@ -222,7 +251,6 @@ config COMEDI_RTI800
222 251
223config COMEDI_RTI802 252config COMEDI_RTI802
224 tristate "Analog Devices RTI-802 ISA card support" 253 tristate "Analog Devices RTI-802 ISA card support"
225 default N
226 ---help--- 254 ---help---
227 Enable support for Analog Devices RTI-802 ISA cards 255 Enable support for Analog Devices RTI-802 ISA cards
228 256
@@ -233,18 +261,29 @@ config COMEDI_DAS16M1
233 tristate "MeasurementComputing CIO-DAS16/M1DAS-16 ISA card support" 261 tristate "MeasurementComputing CIO-DAS16/M1DAS-16 ISA card support"
234 select COMEDI_8255 262 select COMEDI_8255
235 select COMEDI_FC 263 select COMEDI_FC
236 default N
237 ---help--- 264 ---help---
238 Enable support for Measurement Computing CIO-DAS16/M1 ISA cards. 265 Enable support for Measurement Computing CIO-DAS16/M1 ISA cards.
239 266
240 To compile this driver as a module, choose M here: the module will be 267 To compile this driver as a module, choose M here: the module will be
241 called das16m1. 268 called das16m1.
242 269
270config COMEDI_DAS08_ISA
271 tristate "DAS-08 compatible ISA and PC/104 card support"
272 select COMEDI_DAS08
273 ---help---
274 Enable support for Keithley Metrabyte/ComputerBoards DAS08
275 and compatible ISA and PC/104 cards:
276 Keithley Metrabyte/ComputerBoards DAS08, DAS08-PGM, DAS08-PGH,
277 DAS08-PGL, DAS08-AOH, DAS08-AOL, DAS08-AOM, DAS08/JR-AO,
278 DAS08/JR-16-AO, PC104-DAS08, DAS08/JR/16.
279
280 To compile this driver as a module, choose M here: the module will be
281 called das08.
282
243config COMEDI_DAS16 283config COMEDI_DAS16
244 tristate "DAS-16 compatible ISA and PC/104 card support" 284 tristate "DAS-16 compatible ISA and PC/104 card support"
245 select COMEDI_8255 285 select COMEDI_8255
246 select COMEDI_FC 286 select COMEDI_FC
247 default N
248 ---help--- 287 ---help---
249 Enable support for Keithley Metrabyte/ComputerBoards DAS16 288 Enable support for Keithley Metrabyte/ComputerBoards DAS16
250 and compatible ISA and PC/104 cards: 289 and compatible ISA and PC/104 cards:
@@ -261,7 +300,6 @@ config COMEDI_DAS16
261config COMEDI_DAS800 300config COMEDI_DAS800
262 tristate "DAS800 and compatible ISA card support" 301 tristate "DAS800 and compatible ISA card support"
263 select COMEDI_FC 302 select COMEDI_FC
264 default N
265 ---help--- 303 ---help---
266 Enable support for Keithley Metrabyte DAS800 and compatible ISA cards 304 Enable support for Keithley Metrabyte DAS800 and compatible ISA cards
267 Keithley Metrabyte DAS-800, DAS-801, DAS-802 305 Keithley Metrabyte DAS-800, DAS-801, DAS-802
@@ -275,7 +313,6 @@ config COMEDI_DAS1800
275 tristate "DAS1800 and compatible ISA card support" 313 tristate "DAS1800 and compatible ISA card support"
276 depends on VIRT_TO_BUS 314 depends on VIRT_TO_BUS
277 select COMEDI_FC 315 select COMEDI_FC
278 default N
279 ---help--- 316 ---help---
280 Enable support for DAS1800 and compatible ISA cards 317 Enable support for DAS1800 and compatible ISA cards
281 Keithley Metrabyte DAS-1701ST, DAS-1701ST-DA, DAS-1701/AO, 318 Keithley Metrabyte DAS-1701ST, DAS-1701ST-DA, DAS-1701/AO,
@@ -289,7 +326,6 @@ config COMEDI_DAS1800
289 326
290config COMEDI_DAS6402 327config COMEDI_DAS6402
291 tristate "DAS6402 and compatible ISA card support" 328 tristate "DAS6402 and compatible ISA card support"
292 default N
293 ---help--- 329 ---help---
294 Enable support for DAS6402 and compatible ISA cards 330 Enable support for DAS6402 and compatible ISA cards
295 Computerboards, Keithley Metrabyte DAS6402 and compatibles 331 Computerboards, Keithley Metrabyte DAS6402 and compatibles
@@ -299,7 +335,6 @@ config COMEDI_DAS6402
299 335
300config COMEDI_DT2801 336config COMEDI_DT2801
301 tristate "Data Translation DT2801 ISA card support" 337 tristate "Data Translation DT2801 ISA card support"
302 default N
303 ---help--- 338 ---help---
304 Enable support for Data Translation DT2801 ISA cards 339 Enable support for Data Translation DT2801 ISA cards
305 340
@@ -308,7 +343,6 @@ config COMEDI_DT2801
308 343
309config COMEDI_DT2811 344config COMEDI_DT2811
310 tristate "Data Translation DT2811 ISA card support" 345 tristate "Data Translation DT2811 ISA card support"
311 default N
312 ---help--- 346 ---help---
313 Enable support for Data Translation DT2811 ISA cards 347 Enable support for Data Translation DT2811 ISA cards
314 348
@@ -317,7 +351,6 @@ config COMEDI_DT2811
317 351
318config COMEDI_DT2814 352config COMEDI_DT2814
319 tristate "Data Translation DT2814 ISA card support" 353 tristate "Data Translation DT2814 ISA card support"
320 default N
321 ---help--- 354 ---help---
322 Enable support for Data Translation DT2814 ISA cards 355 Enable support for Data Translation DT2814 ISA cards
323 356
@@ -326,7 +359,6 @@ config COMEDI_DT2814
326 359
327config COMEDI_DT2815 360config COMEDI_DT2815
328 tristate "Data Translation DT2815 ISA card support" 361 tristate "Data Translation DT2815 ISA card support"
329 default N
330 ---help--- 362 ---help---
331 Enable support for Data Translation DT2815 ISA cards 363 Enable support for Data Translation DT2815 ISA cards
332 364
@@ -335,7 +367,6 @@ config COMEDI_DT2815
335 367
336config COMEDI_DT2817 368config COMEDI_DT2817
337 tristate "Data Translation DT2817 ISA card support" 369 tristate "Data Translation DT2817 ISA card support"
338 default N
339 ---help--- 370 ---help---
340 Enable support for Data Translation DT2817 ISA cards 371 Enable support for Data Translation DT2817 ISA cards
341 372
@@ -346,7 +377,6 @@ config COMEDI_DT282X
346 tristate "Data Translation DT2821 series and DT-EZ ISA card support" 377 tristate "Data Translation DT2821 series and DT-EZ ISA card support"
347 select COMEDI_FC 378 select COMEDI_FC
348 depends on VIRT_TO_BUS 379 depends on VIRT_TO_BUS
349 default N
350 ---help--- 380 ---help---
351 Enable support for Data Translation DT2821 series including DT-EZ 381 Enable support for Data Translation DT2821 series including DT-EZ
352 DT2821, DT2821-F-16SE, DT2821-F-8DI, DT2821-G-16SE, DT2821-G-8DI, 382 DT2821, DT2821-F-16SE, DT2821-F-8DI, DT2821-G-16SE, DT2821-G-8DI,
@@ -358,7 +388,6 @@ config COMEDI_DT282X
358 388
359config COMEDI_DMM32AT 389config COMEDI_DMM32AT
360 tristate "Diamond Systems MM-32-AT PC/104 board support" 390 tristate "Diamond Systems MM-32-AT PC/104 board support"
361 default N
362 ---help--- 391 ---help---
363 Enable support for Diamond Systems MM-32-AT PC/104 boards 392 Enable support for Diamond Systems MM-32-AT PC/104 boards
364 393
@@ -367,7 +396,6 @@ config COMEDI_DMM32AT
367 396
368config COMEDI_FL512 397config COMEDI_FL512
369 tristate "FL512 ISA card support" 398 tristate "FL512 ISA card support"
370 default N
371 ---help--- 399 ---help---
372 Enable support for FL512 ISA card 400 Enable support for FL512 ISA card
373 401
@@ -377,7 +405,6 @@ config COMEDI_FL512
377config COMEDI_AIO_AIO12_8 405config COMEDI_AIO_AIO12_8
378 tristate "I/O Products PC/104 AIO12-8 Analog I/O Board support" 406 tristate "I/O Products PC/104 AIO12-8 Analog I/O Board support"
379 select COMEDI_8255 407 select COMEDI_8255
380 default N
381 ---help--- 408 ---help---
382 Enable support for I/O Products PC/104 AIO12-8 Analog I/O Board 409 Enable support for I/O Products PC/104 AIO12-8 Analog I/O Board
383 410
@@ -386,7 +413,6 @@ config COMEDI_AIO_AIO12_8
386 413
387config COMEDI_AIO_IIRO_16 414config COMEDI_AIO_IIRO_16
388 tristate "I/O Products PC/104 IIRO16 Board support" 415 tristate "I/O Products PC/104 IIRO16 Board support"
389 default N
390 ---help--- 416 ---help---
391 Enable support for I/O Products PC/104 IIRO16 Relay And Isolated 417 Enable support for I/O Products PC/104 IIRO16 Relay And Isolated
392 Input Board 418 Input Board
@@ -396,7 +422,6 @@ config COMEDI_AIO_IIRO_16
396 422
397config COMEDI_C6XDIGIO 423config COMEDI_C6XDIGIO
398 tristate "Mechatronic Systems Inc. C6x_DIGIO DSP daughter card support" 424 tristate "Mechatronic Systems Inc. C6x_DIGIO DSP daughter card support"
399 default N
400 ---help--- 425 ---help---
401 Enable support for Mechatronic Systems Inc. C6x_DIGIO DSP daughter 426 Enable support for Mechatronic Systems Inc. C6x_DIGIO DSP daughter
402 card 427 card
@@ -406,7 +431,6 @@ config COMEDI_C6XDIGIO
406 431
407config COMEDI_MPC624 432config COMEDI_MPC624
408 tristate "Micro/sys MPC-624 PC/104 board support" 433 tristate "Micro/sys MPC-624 PC/104 board support"
409 default N
410 ---help--- 434 ---help---
411 Enable support for Micro/sys MPC-624 PC/104 board 435 Enable support for Micro/sys MPC-624 PC/104 board
412 436
@@ -415,7 +439,6 @@ config COMEDI_MPC624
415 439
416config COMEDI_ADQ12B 440config COMEDI_ADQ12B
417 tristate "MicroAxial ADQ12-B data acquisition and control card support" 441 tristate "MicroAxial ADQ12-B data acquisition and control card support"
418 default N
419 ---help--- 442 ---help---
420 Enable MicroAxial ADQ12-B daq and control card support. 443 Enable MicroAxial ADQ12-B daq and control card support.
421 444
@@ -426,7 +449,6 @@ config COMEDI_NI_AT_A2150
426 tristate "NI AT-A2150 ISA card support" 449 tristate "NI AT-A2150 ISA card support"
427 depends on COMEDI_NI_COMMON 450 depends on COMEDI_NI_COMMON
428 depends on VIRT_TO_BUS 451 depends on VIRT_TO_BUS
429 default N
430 ---help--- 452 ---help---
431 Enable support for National Instruments AT-A2150 cards 453 Enable support for National Instruments AT-A2150 cards
432 454
@@ -436,7 +458,6 @@ config COMEDI_NI_AT_A2150
436config COMEDI_NI_AT_AO 458config COMEDI_NI_AT_AO
437 tristate "NI AT-AO-6/10 EISA card support" 459 tristate "NI AT-AO-6/10 EISA card support"
438 depends on COMEDI_NI_COMMON 460 depends on COMEDI_NI_COMMON
439 default N
440 ---help--- 461 ---help---
441 Enable support for National Instruments AT-AO-6/10 cards 462 Enable support for National Instruments AT-AO-6/10 cards
442 463
@@ -447,7 +468,6 @@ config COMEDI_NI_ATMIO
447 tristate "NI AT-MIO E series ISA-PNP card support" 468 tristate "NI AT-MIO E series ISA-PNP card support"
448 depends on ISAPNP && COMEDI_NI_TIO && COMEDI_NI_COMMON 469 depends on ISAPNP && COMEDI_NI_TIO && COMEDI_NI_COMMON
449 select COMEDI_8255 470 select COMEDI_8255
450 default N
451 ---help--- 471 ---help---
452 Enable support for National Instruments AT-MIO E series cards 472 Enable support for National Instruments AT-MIO E series cards
453 National Instruments AT-MIO-16E-1 (ni_atmio), 473 National Instruments AT-MIO-16E-1 (ni_atmio),
@@ -461,7 +481,6 @@ config COMEDI_NI_ATMIO16D
461 tristate "NI AT-MIO16/AT-MIO16D series ISA-PNP card support" 481 tristate "NI AT-MIO16/AT-MIO16D series ISA-PNP card support"
462 depends on ISAPNP && COMEDI_NI_COMMON 482 depends on ISAPNP && COMEDI_NI_COMMON
463 select COMEDI_8255 483 select COMEDI_8255
464 default N
465 ---help--- 484 ---help---
466 Enable support for National Instruments AT-MIO16/AT-MIO16D cards. 485 Enable support for National Instruments AT-MIO16/AT-MIO16D cards.
467 486
@@ -470,7 +489,6 @@ config COMEDI_NI_ATMIO16D
470 489
471config COMEDI_PCMAD 490config COMEDI_PCMAD
472 tristate "Winsystems PCM-A/D12 and PCM-A/D16 PC/104 board support" 491 tristate "Winsystems PCM-A/D12 and PCM-A/D16 PC/104 board support"
473 default N
474 ---help--- 492 ---help---
475 Enable support for Winsystems PCM-A/D12 and PCM-A/D16 PC/104 boards. 493 Enable support for Winsystems PCM-A/D12 and PCM-A/D16 PC/104 boards.
476 494
@@ -479,7 +497,6 @@ config COMEDI_PCMAD
479 497
480config COMEDI_PCMDA12 498config COMEDI_PCMDA12
481 tristate "Winsystems PCM-D/A-12 8-channel AO PC/104 board support" 499 tristate "Winsystems PCM-D/A-12 8-channel AO PC/104 board support"
482 default N
483 ---help--- 500 ---help---
484 Enable support for Winsystems PCM-D/A-12 8-channel AO PC/104 boards. 501 Enable support for Winsystems PCM-D/A-12 8-channel AO PC/104 boards.
485 Note that the board is not ISA-PNP capable and thus needs the I/O 502 Note that the board is not ISA-PNP capable and thus needs the I/O
@@ -490,7 +507,6 @@ config COMEDI_PCMDA12
490 507
491config COMEDI_PCMMIO 508config COMEDI_PCMMIO
492 tristate "Winsystems PCM-MIO PC/104 board support" 509 tristate "Winsystems PCM-MIO PC/104 board support"
493 default N
494 ---help--- 510 ---help---
495 Enable support for Winsystems PCM-MIO multifunction PC/104 boards. 511 Enable support for Winsystems PCM-MIO multifunction PC/104 boards.
496 512
@@ -499,7 +515,6 @@ config COMEDI_PCMMIO
499 515
500config COMEDI_PCMUIO 516config COMEDI_PCMUIO
501 tristate "Winsystems PCM-UIO48A and PCM-UIO96A PC/104 board support" 517 tristate "Winsystems PCM-UIO48A and PCM-UIO96A PC/104 board support"
502 default N
503 ---help--- 518 ---help---
504 Enable support for PCM-UIO48A and PCM-UIO96A PC/104 boards. 519 Enable support for PCM-UIO48A and PCM-UIO96A PC/104 boards.
505 520
@@ -508,7 +523,6 @@ config COMEDI_PCMUIO
508 523
509config COMEDI_MULTIQ3 524config COMEDI_MULTIQ3
510 tristate "Quanser Consulting MultiQ-3 ISA card support" 525 tristate "Quanser Consulting MultiQ-3 ISA card support"
511 default N
512 ---help--- 526 ---help---
513 Enable support for Quanser Consulting MultiQ-3 ISA cards 527 Enable support for Quanser Consulting MultiQ-3 ISA cards
514 528
@@ -517,7 +531,6 @@ config COMEDI_MULTIQ3
517 531
518config COMEDI_POC 532config COMEDI_POC
519 tristate "Generic driver for very simple devices" 533 tristate "Generic driver for very simple devices"
520 default N
521 ---help--- 534 ---help---
522 Enable generic support for very simple / POC (Piece of Crap) boards, 535 Enable generic support for very simple / POC (Piece of Crap) boards,
523 Keithley Metrabyte DAC-02 (dac02), Advantech PCL-733 (pcl733) and 536 Keithley Metrabyte DAC-02 (dac02), Advantech PCL-733 (pcl733) and
@@ -531,7 +544,6 @@ endif # COMEDI_ISA_DRIVERS
531menuconfig COMEDI_PCI_DRIVERS 544menuconfig COMEDI_PCI_DRIVERS
532 tristate "Comedi PCI drivers" 545 tristate "Comedi PCI drivers"
533 depends on COMEDI && PCI 546 depends on COMEDI && PCI
534 default N
535 ---help--- 547 ---help---
536 Enable comedi PCI drivers to be built 548 Enable comedi PCI drivers to be built
537 549
@@ -544,7 +556,6 @@ if COMEDI_PCI_DRIVERS && PCI
544config COMEDI_ADDI_APCI_035 556config COMEDI_ADDI_APCI_035
545 tristate "ADDI-DATA APCI_035 support" 557 tristate "ADDI-DATA APCI_035 support"
546 depends on VIRT_TO_BUS 558 depends on VIRT_TO_BUS
547 default N
548 ---help--- 559 ---help---
549 Enable support for ADDI-DATA APCI_035 cards 560 Enable support for ADDI-DATA APCI_035 cards
550 561
@@ -554,7 +565,6 @@ config COMEDI_ADDI_APCI_035
554config COMEDI_ADDI_APCI_1032 565config COMEDI_ADDI_APCI_1032
555 tristate "ADDI-DATA APCI_1032 support" 566 tristate "ADDI-DATA APCI_1032 support"
556 depends on VIRT_TO_BUS 567 depends on VIRT_TO_BUS
557 default N
558 ---help--- 568 ---help---
559 Enable support for ADDI-DATA APCI_1032 cards 569 Enable support for ADDI-DATA APCI_1032 cards
560 570
@@ -564,7 +574,6 @@ config COMEDI_ADDI_APCI_1032
564config COMEDI_ADDI_APCI_1500 574config COMEDI_ADDI_APCI_1500
565 tristate "ADDI-DATA APCI_1500 support" 575 tristate "ADDI-DATA APCI_1500 support"
566 depends on VIRT_TO_BUS 576 depends on VIRT_TO_BUS
567 default N
568 ---help--- 577 ---help---
569 Enable support for ADDI-DATA APCI_1500 cards 578 Enable support for ADDI-DATA APCI_1500 cards
570 579
@@ -574,7 +583,6 @@ config COMEDI_ADDI_APCI_1500
574config COMEDI_ADDI_APCI_1516 583config COMEDI_ADDI_APCI_1516
575 tristate "ADDI-DATA APCI_1516 support" 584 tristate "ADDI-DATA APCI_1516 support"
576 depends on VIRT_TO_BUS 585 depends on VIRT_TO_BUS
577 default N
578 ---help--- 586 ---help---
579 Enable support for ADDI-DATA APCI_1516 cards 587 Enable support for ADDI-DATA APCI_1516 cards
580 588
@@ -584,7 +592,6 @@ config COMEDI_ADDI_APCI_1516
584config COMEDI_ADDI_APCI_1564 592config COMEDI_ADDI_APCI_1564
585 tristate "ADDI-DATA APCI_1564 support" 593 tristate "ADDI-DATA APCI_1564 support"
586 depends on VIRT_TO_BUS 594 depends on VIRT_TO_BUS
587 default N
588 ---help--- 595 ---help---
589 Enable support for ADDI-DATA APCI_1564 cards 596 Enable support for ADDI-DATA APCI_1564 cards
590 597
@@ -594,7 +601,6 @@ config COMEDI_ADDI_APCI_1564
594config COMEDI_ADDI_APCI_16XX 601config COMEDI_ADDI_APCI_16XX
595 tristate "ADDI-DATA APCI_16xx support" 602 tristate "ADDI-DATA APCI_16xx support"
596 depends on VIRT_TO_BUS 603 depends on VIRT_TO_BUS
597 default N
598 ---help--- 604 ---help---
599 Enable support for ADDI-DATA APCI_16xx cards 605 Enable support for ADDI-DATA APCI_16xx cards
600 606
@@ -604,7 +610,6 @@ config COMEDI_ADDI_APCI_16XX
604config COMEDI_ADDI_APCI_2016 610config COMEDI_ADDI_APCI_2016
605 tristate "ADDI-DATA APCI_2016 support" 611 tristate "ADDI-DATA APCI_2016 support"
606 depends on VIRT_TO_BUS 612 depends on VIRT_TO_BUS
607 default N
608 ---help--- 613 ---help---
609 Enable support for ADDI-DATA APCI_2016 cards 614 Enable support for ADDI-DATA APCI_2016 cards
610 615
@@ -614,7 +619,6 @@ config COMEDI_ADDI_APCI_2016
614config COMEDI_ADDI_APCI_2032 619config COMEDI_ADDI_APCI_2032
615 tristate "ADDI-DATA APCI_2032 support" 620 tristate "ADDI-DATA APCI_2032 support"
616 depends on VIRT_TO_BUS 621 depends on VIRT_TO_BUS
617 default N
618 ---help--- 622 ---help---
619 Enable support for ADDI-DATA APCI_2032 cards 623 Enable support for ADDI-DATA APCI_2032 cards
620 624
@@ -624,7 +628,6 @@ config COMEDI_ADDI_APCI_2032
624config COMEDI_ADDI_APCI_2200 628config COMEDI_ADDI_APCI_2200
625 tristate "ADDI-DATA APCI_2200 support" 629 tristate "ADDI-DATA APCI_2200 support"
626 depends on VIRT_TO_BUS 630 depends on VIRT_TO_BUS
627 default N
628 ---help--- 631 ---help---
629 Enable support for ADDI-DATA APCI_2200 cards 632 Enable support for ADDI-DATA APCI_2200 cards
630 633
@@ -635,7 +638,6 @@ config COMEDI_ADDI_APCI_3001
635 tristate "ADDI-DATA APCI_3001 support" 638 tristate "ADDI-DATA APCI_3001 support"
636 depends on VIRT_TO_BUS 639 depends on VIRT_TO_BUS
637 select COMEDI_FC 640 select COMEDI_FC
638 default N
639 ---help--- 641 ---help---
640 Enable support for ADDI-DATA APCI_3001 cards 642 Enable support for ADDI-DATA APCI_3001 cards
641 643
@@ -646,7 +648,6 @@ config COMEDI_ADDI_APCI_3120
646 tristate "ADDI-DATA APCI_3520 support" 648 tristate "ADDI-DATA APCI_3520 support"
647 depends on VIRT_TO_BUS 649 depends on VIRT_TO_BUS
648 select COMEDI_FC 650 select COMEDI_FC
649 default N
650 ---help--- 651 ---help---
651 Enable support for ADDI-DATA APCI_3520 cards 652 Enable support for ADDI-DATA APCI_3520 cards
652 653
@@ -656,7 +657,6 @@ config COMEDI_ADDI_APCI_3120
656config COMEDI_ADDI_APCI_3501 657config COMEDI_ADDI_APCI_3501
657 tristate "ADDI-DATA APCI_3501 support" 658 tristate "ADDI-DATA APCI_3501 support"
658 depends on VIRT_TO_BUS 659 depends on VIRT_TO_BUS
659 default N
660 ---help--- 660 ---help---
661 Enable support for ADDI-DATA APCI_3501 cards 661 Enable support for ADDI-DATA APCI_3501 cards
662 662
@@ -666,7 +666,6 @@ config COMEDI_ADDI_APCI_3501
666config COMEDI_ADDI_APCI_3XXX 666config COMEDI_ADDI_APCI_3XXX
667 tristate "ADDI-DATA APCI_3xxx support" 667 tristate "ADDI-DATA APCI_3xxx support"
668 depends on VIRT_TO_BUS 668 depends on VIRT_TO_BUS
669 default N
670 ---help--- 669 ---help---
671 Enable support for ADDI-DATA APCI_3xxx cards 670 Enable support for ADDI-DATA APCI_3xxx cards
672 671
@@ -676,7 +675,6 @@ config COMEDI_ADDI_APCI_3XXX
676config COMEDI_ADL_PCI6208 675config COMEDI_ADL_PCI6208
677 tristate "ADLink PCI-6208A support" 676 tristate "ADLink PCI-6208A support"
678 select COMEDI_8255 677 select COMEDI_8255
679 default N
680 ---help--- 678 ---help---
681 Enable support for ADLink PCI-6208A cards 679 Enable support for ADLink PCI-6208A cards
682 680
@@ -685,7 +683,6 @@ config COMEDI_ADL_PCI6208
685 683
686config COMEDI_ADL_PCI7230 684config COMEDI_ADL_PCI7230
687 tristate "ADLink PCI-7230 digital io board support" 685 tristate "ADLink PCI-7230 digital io board support"
688 default N
689 ---help--- 686 ---help---
690 Enable support for ADlink PCI-7230 digital io board support 687 Enable support for ADlink PCI-7230 digital io board support
691 688
@@ -694,7 +691,6 @@ config COMEDI_ADL_PCI7230
694 691
695config COMEDI_ADL_PCI7296 692config COMEDI_ADL_PCI7296
696 tristate "ADLink PCI-7296 96 ch. digital io board support" 693 tristate "ADLink PCI-7296 96 ch. digital io board support"
697 default N
698 ---help--- 694 ---help---
699 Enable support for ADlink PCI-7296 96 ch. digital io board support 695 Enable support for ADlink PCI-7296 96 ch. digital io board support
700 696
@@ -703,7 +699,6 @@ config COMEDI_ADL_PCI7296
703 699
704config COMEDI_ADL_PCI7432 700config COMEDI_ADL_PCI7432
705 tristate "ADLink PCI-7432 64 ch. isolated digital io board support" 701 tristate "ADLink PCI-7432 64 ch. isolated digital io board support"
706 default N
707 ---help--- 702 ---help---
708 Enable support for ADlink PCI-7432 64 ch. isolated digital io board 703 Enable support for ADlink PCI-7432 64 ch. isolated digital io board
709 704
@@ -712,7 +707,6 @@ config COMEDI_ADL_PCI7432
712 707
713config COMEDI_ADL_PCI8164 708config COMEDI_ADL_PCI8164
714 tristate "ADLink PCI-8164 4 Axes Motion Control board support" 709 tristate "ADLink PCI-8164 4 Axes Motion Control board support"
715 default N
716 ---help--- 710 ---help---
717 Enable support for ADlink PCI-8164 4 Axes Motion Control board 711 Enable support for ADlink PCI-8164 4 Axes Motion Control board
718 712
@@ -722,7 +716,6 @@ config COMEDI_ADL_PCI8164
722config COMEDI_ADL_PCI9111 716config COMEDI_ADL_PCI9111
723 tristate "ADLink PCI-9111HR support" 717 tristate "ADLink PCI-9111HR support"
724 select COMEDI_FC 718 select COMEDI_FC
725 default N
726 ---help--- 719 ---help---
727 Enable support for ADlink PCI9111 cards 720 Enable support for ADlink PCI9111 cards
728 721
@@ -733,7 +726,6 @@ config COMEDI_ADL_PCI9118
733 tristate "ADLink PCI-9118DG, PCI-9118HG, PCI-9118HR support" 726 tristate "ADLink PCI-9118DG, PCI-9118HG, PCI-9118HR support"
734 select COMEDI_FC 727 select COMEDI_FC
735 depends on VIRT_TO_BUS 728 depends on VIRT_TO_BUS
736 default N
737 ---help--- 729 ---help---
738 Enable support for ADlink PCI-9118DG, PCI-9118HG, PCI-9118HR cards 730 Enable support for ADlink PCI-9118DG, PCI-9118HG, PCI-9118HR cards
739 731
@@ -742,7 +734,6 @@ config COMEDI_ADL_PCI9118
742 734
743config COMEDI_ADV_PCI1710 735config COMEDI_ADV_PCI1710
744 tristate "Advantech PCI-171x, PCI-1720 and PCI-1731 support" 736 tristate "Advantech PCI-171x, PCI-1720 and PCI-1731 support"
745 default N
746 ---help--- 737 ---help---
747 Enable support for Advantech PCI-1710, PCI-1710HG, PCI-1711, 738 Enable support for Advantech PCI-1710, PCI-1710HG, PCI-1711,
748 PCI-1713, PCI-1720 and PCI-1731 739 PCI-1713, PCI-1720 and PCI-1731
@@ -752,7 +743,6 @@ config COMEDI_ADV_PCI1710
752 743
753config COMEDI_ADV_PCI1723 744config COMEDI_ADV_PCI1723
754 tristate "Advantech PCI-1723 support" 745 tristate "Advantech PCI-1723 support"
755 default N
756 ---help--- 746 ---help---
757 Enable support for Advantech PCI-1723 cards 747 Enable support for Advantech PCI-1723 cards
758 748
@@ -762,7 +752,6 @@ config COMEDI_ADV_PCI1723
762config COMEDI_ADV_PCI_DIO 752config COMEDI_ADV_PCI_DIO
763 tristate "Advantech PCI DIO card support" 753 tristate "Advantech PCI DIO card support"
764 select COMEDI_8255 754 select COMEDI_8255
765 default N
766 ---help--- 755 ---help---
767 Enable support for Advantech PCI DIO cards 756 Enable support for Advantech PCI DIO cards
768 PCI-1730, PCI-1733, PCI-1734, PCI-1735U, PCI-1736UP, PCI-1739U, 757 PCI-1730, PCI-1733, PCI-1734, PCI-1735U, PCI-1736UP, PCI-1739U,
@@ -772,31 +761,29 @@ config COMEDI_ADV_PCI_DIO
772 To compile this driver as a module, choose M here: the module will be 761 To compile this driver as a module, choose M here: the module will be
773 called adv_pci_dio. 762 called adv_pci_dio.
774 763
775config COMEDI_AMPLC_DIO200 764config COMEDI_AMPLC_DIO200_PCI
776 tristate "Amplicon PC272E and PCI272 DIO board support" 765 tristate "Amplicon PCI215 and PCI272 DIO board support"
777 select COMEDI_8255 766 select COMEDI_AMPLC_DIO200
778 default N
779 ---help--- 767 ---help---
780 Enable support for Amplicon PC272E and PCI272 DIO boards 768 Enable support for Amplicon PCI215 and PCI272 DIO boards.
781 769
782 To compile this driver as a module, choose M here: the module will be 770 To compile this driver as a module, choose M here: the module will be
783 called amplc_dio200. 771 called amplc_dio200.
784 772
785config COMEDI_AMPLC_PC236 773config COMEDI_AMPLC_PC236_PCI
786 tristate "Amplicon PC36AT and PCI236 DIO board support" 774 tristate "Amplicon PCI236 DIO board support"
787 select COMEDI_8255 775 select COMEDI_AMPLC_PC236
788 default N
789 ---help--- 776 ---help---
790 Enable support for Amplicon PC36AT and PCI236 DIO boards 777 Enable support for Amplicon PCI236 DIO board.
791 778
792 To compile this driver as a module, choose M here: the module will be 779 To compile this driver as a module, choose M here: the module will be
793 called amplc_pc236. 780 called amplc_pc236.
794 781
795config COMEDI_AMPLC_PC263 782config COMEDI_AMPLC_PC263_PCI
796 tristate "Amplicon PC263 and PCI263 relay board support" 783 tristate "Amplicon PCI263 relay board support"
797 default N 784 select COMEDI_AMPLC_PC263
798 ---help--- 785 ---help---
799 Enable support for Amplicon PC263 and PCI263 relay boards 786 Enable support for Amplicon PCI263 relay board.
800 787
801 To compile this driver as a module, choose M here: the module will be 788 To compile this driver as a module, choose M here: the module will be
802 called amplc_pc263. 789 called amplc_pc263.
@@ -804,7 +791,6 @@ config COMEDI_AMPLC_PC263
804config COMEDI_AMPLC_PCI224 791config COMEDI_AMPLC_PCI224
805 tristate "Amplicon PCI224 and PCI234 support" 792 tristate "Amplicon PCI224 and PCI234 support"
806 select COMEDI_FC 793 select COMEDI_FC
807 default N
808 ---help--- 794 ---help---
809 Enable support for Amplicon PCI224 and PCI234 AO boards 795 Enable support for Amplicon PCI224 and PCI234 AO boards
810 796
@@ -814,7 +800,6 @@ config COMEDI_AMPLC_PCI224
814config COMEDI_AMPLC_PCI230 800config COMEDI_AMPLC_PCI230
815 tristate "Amplicon PCI230 and PCI260 support" 801 tristate "Amplicon PCI230 and PCI260 support"
816 select COMEDI_8255 802 select COMEDI_8255
817 default N
818 ---help--- 803 ---help---
819 Enable support for Amplicon PCI230 and PCI260 Multifunction I/O 804 Enable support for Amplicon PCI230 and PCI260 Multifunction I/O
820 boards 805 boards
@@ -824,16 +809,23 @@ config COMEDI_AMPLC_PCI230
824 809
825config COMEDI_CONTEC_PCI_DIO 810config COMEDI_CONTEC_PCI_DIO
826 tristate "Contec PIO1616L digital I/O board support" 811 tristate "Contec PIO1616L digital I/O board support"
827 default N
828 ---help--- 812 ---help---
829 Enable support for the Contec PIO1616L digital I/O board 813 Enable support for the Contec PIO1616L digital I/O board
830 814
831 To compile this driver as a module, choose M here: the module will be 815 To compile this driver as a module, choose M here: the module will be
832 called contec_pci_dio. 816 called contec_pci_dio.
833 817
818config COMEDI_DAS08_PCI
819 tristate "DAS-08 PCI support"
820 select COMEDI_DAS08
821 ---help---
822 Enable support for PCI DAS-08 cards.
823
824 To compile this driver as a module, choose M here: the module will be
825 called das08.
826
834config COMEDI_DT3000 827config COMEDI_DT3000
835 tristate "Data Translation DT3000 series support" 828 tristate "Data Translation DT3000 series support"
836 default N
837 ---help--- 829 ---help---
838 Enable support for Data Translation DT3000 series 830 Enable support for Data Translation DT3000 series
839 DT3001, DT3001-PGL, DT3002, DT3003, DT3003-PGL, DT3004, DT3005 and 831 DT3001, DT3001-PGL, DT3002, DT3003, DT3003-PGL, DT3004, DT3005 and
@@ -844,7 +836,6 @@ config COMEDI_DT3000
844 836
845config COMEDI_DYNA_PCI10XX 837config COMEDI_DYNA_PCI10XX
846 tristate "Dynalog PCI DAQ series support" 838 tristate "Dynalog PCI DAQ series support"
847 default N
848 ---help--- 839 ---help---
849 Enable support for Dynalog PCI DAQ series 840 Enable support for Dynalog PCI DAQ series
850 PCI-1050 841 PCI-1050
@@ -854,7 +845,6 @@ config COMEDI_DYNA_PCI10XX
854 845
855config COMEDI_UNIOXX5 846config COMEDI_UNIOXX5
856 tristate "Fastwel UNIOxx-5 analog and digital io board support" 847 tristate "Fastwel UNIOxx-5 analog and digital io board support"
857 default N
858 ---help--- 848 ---help---
859 Enable support for Fastwel UNIOxx-5 (analog and digital i/o) boards 849 Enable support for Fastwel UNIOxx-5 (analog and digital i/o) boards
860 850
@@ -864,7 +854,6 @@ config COMEDI_UNIOXX5
864config COMEDI_GSC_HPDI 854config COMEDI_GSC_HPDI
865 tristate "General Standards PCI-HPDI32 / PMC-HPDI32 support" 855 tristate "General Standards PCI-HPDI32 / PMC-HPDI32 support"
866 select COMEDI_FC 856 select COMEDI_FC
867 default N
868 ---help--- 857 ---help---
869 Enable support for General Standards Corporation high speed parallel 858 Enable support for General Standards Corporation high speed parallel
870 digital interface rs485 boards PCI-HPDI32 and PMC-HPDI32. 859 digital interface rs485 boards PCI-HPDI32 and PMC-HPDI32.
@@ -875,7 +864,6 @@ config COMEDI_GSC_HPDI
875 864
876config COMEDI_ICP_MULTI 865config COMEDI_ICP_MULTI
877 tristate "Inova ICP_MULTI support" 866 tristate "Inova ICP_MULTI support"
878 default N
879 ---help--- 867 ---help---
880 Enable support for Inova ICP_MULTI card 868 Enable support for Inova ICP_MULTI card
881 869
@@ -884,7 +872,6 @@ config COMEDI_ICP_MULTI
884 872
885config COMEDI_II_PCI20KC 873config COMEDI_II_PCI20KC
886 tristate "Intelligent Instruments PCI-20001C carrier support" 874 tristate "Intelligent Instruments PCI-20001C carrier support"
887 default N
888 ---help--- 875 ---help---
889 Enable support for Intelligent Instruments PCI-20001C carrier 876 Enable support for Intelligent Instruments PCI-20001C carrier
890 PCI-20001, PCI-20006 and PCI-20341 877 PCI-20001, PCI-20006 and PCI-20341
@@ -895,7 +882,6 @@ config COMEDI_II_PCI20KC
895config COMEDI_DAQBOARD2000 882config COMEDI_DAQBOARD2000
896 tristate "IOtech DAQboard/2000 support" 883 tristate "IOtech DAQboard/2000 support"
897 select COMEDI_8255 884 select COMEDI_8255
898 default N
899 ---help--- 885 ---help---
900 Enable support for the IOtech DAQboard/2000 886 Enable support for the IOtech DAQboard/2000
901 887
@@ -904,7 +890,6 @@ config COMEDI_DAQBOARD2000
904 890
905config COMEDI_JR3_PCI 891config COMEDI_JR3_PCI
906 tristate "JR3/PCI force sensor board support" 892 tristate "JR3/PCI force sensor board support"
907 default N
908 ---help--- 893 ---help---
909 Enable support for JR3/PCI force sensor boards 894 Enable support for JR3/PCI force sensor boards
910 895
@@ -913,7 +898,6 @@ config COMEDI_JR3_PCI
913 898
914config COMEDI_KE_COUNTER 899config COMEDI_KE_COUNTER
915 tristate "Kolter-Electronic PCI Counter 1 card support" 900 tristate "Kolter-Electronic PCI Counter 1 card support"
916 default N
917 ---help--- 901 ---help---
918 Enable support for Kolter-Electronic PCI Counter 1 cards 902 Enable support for Kolter-Electronic PCI Counter 1 cards
919 903
@@ -924,7 +908,6 @@ config COMEDI_CB_PCIDAS64
924 tristate "MeasurementComputing PCI-DAS 64xx, 60xx, and 4020 support" 908 tristate "MeasurementComputing PCI-DAS 64xx, 60xx, and 4020 support"
925 select COMEDI_8255 909 select COMEDI_8255
926 select COMEDI_FC 910 select COMEDI_FC
927 default N
928 ---help--- 911 ---help---
929 Enable support for ComputerBoards/MeasurementComputing PCI-DAS 64xx, 912 Enable support for ComputerBoards/MeasurementComputing PCI-DAS 64xx,
930 60xx, and 4020 series with the PLX 9080 PCI controller 913 60xx, and 4020 series with the PLX 9080 PCI controller
@@ -936,7 +919,6 @@ config COMEDI_CB_PCIDAS
936 tristate "MeasurementComputing PCI-DAS support" 919 tristate "MeasurementComputing PCI-DAS support"
937 select COMEDI_8255 920 select COMEDI_8255
938 select COMEDI_FC 921 select COMEDI_FC
939 default N
940 ---help--- 922 ---help---
941 Enable support for ComputerBoards/MeasurementComputing PCI-DAS with 923 Enable support for ComputerBoards/MeasurementComputing PCI-DAS with
942 AMCC S5933 PCIcontroller: PCI-DAS1602/16, PCI-DAS1602/16jr, 924 AMCC S5933 PCIcontroller: PCI-DAS1602/16, PCI-DAS1602/16jr,
@@ -949,7 +931,6 @@ config COMEDI_CB_PCIDAS
949config COMEDI_CB_PCIDDA 931config COMEDI_CB_PCIDDA
950 tristate "MeasurementComputing PCI-DDA series support" 932 tristate "MeasurementComputing PCI-DDA series support"
951 select COMEDI_8255 933 select COMEDI_8255
952 default N
953 ---help--- 934 ---help---
954 Enable support for ComputerBoards/MeasurementComputing PCI-DDA 935 Enable support for ComputerBoards/MeasurementComputing PCI-DDA
955 series: PCI-DDA08/12, PCI-DDA04/12, PCI-DDA02/12, PCI-DDA08/16, 936 series: PCI-DDA08/12, PCI-DDA04/12, PCI-DDA02/12, PCI-DDA08/16,
@@ -961,7 +942,6 @@ config COMEDI_CB_PCIDDA
961config COMEDI_CB_PCIDIO 942config COMEDI_CB_PCIDIO
962 tristate "MeasurementComputing PCI-DIO series support" 943 tristate "MeasurementComputing PCI-DIO series support"
963 select COMEDI_8255 944 select COMEDI_8255
964 default N
965 ---help--- 945 ---help---
966 Enable support for ComputerBoards/MeasurementComputing PCI-DIO series 946 Enable support for ComputerBoards/MeasurementComputing PCI-DIO series
967 PCI-DIO24, PCI-DIO24H and PCI-DIO48H 947 PCI-DIO24, PCI-DIO24H and PCI-DIO48H
@@ -972,7 +952,6 @@ config COMEDI_CB_PCIDIO
972config COMEDI_CB_PCIMDAS 952config COMEDI_CB_PCIMDAS
973 tristate "MeasurementComputing PCIM-DAS1602/16 support" 953 tristate "MeasurementComputing PCIM-DAS1602/16 support"
974 select COMEDI_8255 954 select COMEDI_8255
975 default N
976 ---help--- 955 ---help---
977 Enable support for ComputerBoards/MeasurementComputing PCI Migration 956 Enable support for ComputerBoards/MeasurementComputing PCI Migration
978 series PCIM-DAS1602/16 957 series PCIM-DAS1602/16
@@ -983,7 +962,6 @@ config COMEDI_CB_PCIMDAS
983config COMEDI_CB_PCIMDDA 962config COMEDI_CB_PCIMDDA
984 tristate "MeasurementComputing PCIM-DDA06-16 support" 963 tristate "MeasurementComputing PCIM-DDA06-16 support"
985 select COMEDI_8255 964 select COMEDI_8255
986 default N
987 ---help--- 965 ---help---
988 Enable support for ComputerBoards/MeasurementComputing PCIM-DDA06-16 966 Enable support for ComputerBoards/MeasurementComputing PCIM-DDA06-16
989 967
@@ -992,7 +970,6 @@ config COMEDI_CB_PCIMDDA
992 970
993config COMEDI_ME4000 971config COMEDI_ME4000
994 tristate "Meilhaus ME-4000 support" 972 tristate "Meilhaus ME-4000 support"
995 default N
996 ---help--- 973 ---help---
997 Enable support for Meilhaus PCI data acquisition cards 974 Enable support for Meilhaus PCI data acquisition cards
998 ME-4650, ME-4670i, ME-4680, ME-4680i and ME-4680is 975 ME-4650, ME-4670i, ME-4680, ME-4680i and ME-4680is
@@ -1002,7 +979,6 @@ config COMEDI_ME4000
1002 979
1003config COMEDI_ME_DAQ 980config COMEDI_ME_DAQ
1004 tristate "Meilhaus ME-2000i, ME-2600i, ME-3000vm1 support" 981 tristate "Meilhaus ME-2000i, ME-2600i, ME-3000vm1 support"
1005 default N
1006 ---help--- 982 ---help---
1007 Enable support for Meilhaus PCI data acquisition cards 983 Enable support for Meilhaus PCI data acquisition cards
1008 ME-2000i, ME-2600i and ME-3000vm1 984 ME-2000i, ME-2600i and ME-3000vm1
@@ -1013,7 +989,6 @@ config COMEDI_ME_DAQ
1013config COMEDI_NI_6527 989config COMEDI_NI_6527
1014 tristate "NI 6527 support" 990 tristate "NI 6527 support"
1015 depends on COMEDI_MITE 991 depends on COMEDI_MITE
1016 default N
1017 ---help--- 992 ---help---
1018 Enable support for the National Instruments 6527 PCI card 993 Enable support for the National Instruments 6527 PCI card
1019 994
@@ -1023,7 +998,6 @@ config COMEDI_NI_6527
1023config COMEDI_NI_65XX 998config COMEDI_NI_65XX
1024 tristate "NI 65xx static dio PCI card support" 999 tristate "NI 65xx static dio PCI card support"
1025 depends on COMEDI_MITE 1000 depends on COMEDI_MITE
1026 default N
1027 ---help--- 1001 ---help---
1028 Enable support for National Instruments 65xx static dio boards. 1002 Enable support for National Instruments 65xx static dio boards.
1029 Supported devices: National Instruments PCI-6509 (ni_65xx), 1003 Supported devices: National Instruments PCI-6509 (ni_65xx),
@@ -1037,7 +1011,6 @@ config COMEDI_NI_65XX
1037config COMEDI_NI_660X 1011config COMEDI_NI_660X
1038 tristate "NI 660x counter/timer PCI card support" 1012 tristate "NI 660x counter/timer PCI card support"
1039 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON 1013 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON
1040 default N
1041 ---help--- 1014 ---help---
1042 Enable support for National Instruments PCI-6601 (ni_660x), PCI-6602, 1015 Enable support for National Instruments PCI-6601 (ni_660x), PCI-6602,
1043 PXI-6602 and PXI-6608. 1016 PXI-6602 and PXI-6608.
@@ -1048,7 +1021,6 @@ config COMEDI_NI_660X
1048config COMEDI_NI_670X 1021config COMEDI_NI_670X
1049 tristate "NI 670x PCI card support" 1022 tristate "NI 670x PCI card support"
1050 depends on COMEDI_MITE 1023 depends on COMEDI_MITE
1051 default N
1052 ---help--- 1024 ---help---
1053 Enable support for National Instruments PCI-6703 and PCI-6704 1025 Enable support for National Instruments PCI-6703 and PCI-6704
1054 1026
@@ -1059,7 +1031,6 @@ config COMEDI_NI_PCIDIO
1059 tristate "NI PCI-DIO32HS, PCI-DIO96, PCI-6533, PCI-6503 support" 1031 tristate "NI PCI-DIO32HS, PCI-DIO96, PCI-6533, PCI-6503 support"
1060 depends on COMEDI_MITE 1032 depends on COMEDI_MITE
1061 select COMEDI_8255 1033 select COMEDI_8255
1062 default N
1063 ---help--- 1034 ---help---
1064 Enable support for National Instruments PCI-DIO-32HS, PXI-6533, 1035 Enable support for National Instruments PCI-DIO-32HS, PXI-6533,
1065 PCI-DIO-96, PCI-DIO-96B, PXI-6508, PCI-6503, PCI-6503B, PCI-6503X, 1036 PCI-DIO-96, PCI-DIO-96B, PXI-6508, PCI-6503, PCI-6503B, PCI-6503X,
@@ -1075,7 +1046,6 @@ config COMEDI_NI_PCIMIO
1075 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON 1046 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON
1076 select COMEDI_8255 1047 select COMEDI_8255
1077 select COMEDI_FC 1048 select COMEDI_FC
1078 default N
1079 ---help--- 1049 ---help---
1080 Enable support for National Instruments PCI-MIO-E series and M series 1050 Enable support for National Instruments PCI-MIO-E series and M series
1081 (all boards): PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1, 1051 (all boards): PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1,
@@ -1094,7 +1064,6 @@ config COMEDI_NI_PCIMIO
1094config COMEDI_RTD520 1064config COMEDI_RTD520
1095 tristate "Real Time Devices PCI4520/DM7520 support" 1065 tristate "Real Time Devices PCI4520/DM7520 support"
1096 select COMEDI_8255 1066 select COMEDI_8255
1097 default N
1098 ---help--- 1067 ---help---
1099 Enable support for Real Time Devices PCI4520/DM7520 1068 Enable support for Real Time Devices PCI4520/DM7520
1100 1069
@@ -1103,7 +1072,6 @@ config COMEDI_RTD520
1103 1072
1104config COMEDI_S526 1073config COMEDI_S526
1105 tristate "Sensoray s526 support" 1074 tristate "Sensoray s526 support"
1106 default N
1107 ---help--- 1075 ---help---
1108 Enable support for Sensoray s526 1076 Enable support for Sensoray s526
1109 1077
@@ -1113,7 +1081,6 @@ config COMEDI_S526
1113config COMEDI_S626 1081config COMEDI_S626
1114 tristate "Sensoray 626 support" 1082 tristate "Sensoray 626 support"
1115 select COMEDI_FC 1083 select COMEDI_FC
1116 default N
1117 ---help--- 1084 ---help---
1118 Enable support for Sensoray 626 1085 Enable support for Sensoray 626
1119 1086
@@ -1122,7 +1089,6 @@ config COMEDI_S626
1122 1089
1123config COMEDI_SSV_DNP 1090config COMEDI_SSV_DNP
1124 tristate "SSV Embedded Systems DIL/Net-PC support" 1091 tristate "SSV Embedded Systems DIL/Net-PC support"
1125 default N
1126 ---help--- 1092 ---help---
1127 Enable support for SSV Embedded Systems DIL/Net-PC 1093 Enable support for SSV Embedded Systems DIL/Net-PC
1128 1094
@@ -1134,7 +1100,6 @@ endif # COMEDI_PCI_DRIVERS
1134menuconfig COMEDI_PCMCIA_DRIVERS 1100menuconfig COMEDI_PCMCIA_DRIVERS
1135 tristate "Comedi PCMCIA drivers" 1101 tristate "Comedi PCMCIA drivers"
1136 depends on COMEDI && (PCMCIA || PCCARD) 1102 depends on COMEDI && (PCMCIA || PCCARD)
1137 default N
1138 ---help--- 1103 ---help---
1139 Enable comedi PCMCIA and PCCARD drivers to be built 1104 Enable comedi PCMCIA and PCCARD drivers to be built
1140 1105
@@ -1146,7 +1111,6 @@ if COMEDI_PCMCIA_DRIVERS && PCMCIA
1146 1111
1147config COMEDI_CB_DAS16_CS 1112config COMEDI_CB_DAS16_CS
1148 tristate "CB DAS16 series PCMCIA support" 1113 tristate "CB DAS16 series PCMCIA support"
1149 default N
1150 ---help--- 1114 ---help---
1151 Enable support for the ComputerBoards/MeasurementComputing PCMCIA 1115 Enable support for the ComputerBoards/MeasurementComputing PCMCIA
1152 cards DAS16/16, PCM-DAS16D/12 and PCM-DAS16s/16 1116 cards DAS16/16, PCM-DAS16D/12 and PCM-DAS16s/16
@@ -1157,7 +1121,6 @@ config COMEDI_CB_DAS16_CS
1157config COMEDI_DAS08_CS 1121config COMEDI_DAS08_CS
1158 tristate "CB DAS08 PCMCIA support" 1122 tristate "CB DAS08 PCMCIA support"
1159 select COMEDI_DAS08 1123 select COMEDI_DAS08
1160 default N
1161 ---help--- 1124 ---help---
1162 Enable support for the ComputerBoards/MeasurementComputing DAS-08 1125 Enable support for the ComputerBoards/MeasurementComputing DAS-08
1163 PCMCIA card 1126 PCMCIA card
@@ -1168,7 +1131,6 @@ config COMEDI_DAS08_CS
1168config COMEDI_NI_DAQ_700_CS 1131config COMEDI_NI_DAQ_700_CS
1169 tristate "NI DAQCard-700 PCMCIA support" 1132 tristate "NI DAQCard-700 PCMCIA support"
1170 depends on COMEDI_NI_COMMON 1133 depends on COMEDI_NI_COMMON
1171 default N
1172 ---help--- 1134 ---help---
1173 Enable support for the National Instruments PCMCIA DAQCard-700 DIO 1135 Enable support for the National Instruments PCMCIA DAQCard-700 DIO
1174 1136
@@ -1179,7 +1141,6 @@ config COMEDI_NI_DAQ_DIO24_CS
1179 tristate "NI DAQ-Card DIO-24 PCMCIA support" 1141 tristate "NI DAQ-Card DIO-24 PCMCIA support"
1180 depends on COMEDI_NI_COMMON 1142 depends on COMEDI_NI_COMMON
1181 select COMEDI_8255 1143 select COMEDI_8255
1182 default N
1183 ---help--- 1144 ---help---
1184 Enable support for the National Instruments PCMCIA DAQ-Card DIO-24 1145 Enable support for the National Instruments PCMCIA DAQ-Card DIO-24
1185 1146
@@ -1189,7 +1150,6 @@ config COMEDI_NI_DAQ_DIO24_CS
1189config COMEDI_NI_LABPC_CS 1150config COMEDI_NI_LABPC_CS
1190 tristate "NI DAQCard-1200 PCMCIA support" 1151 tristate "NI DAQCard-1200 PCMCIA support"
1191 depends on COMEDI_NI_LABPC 1152 depends on COMEDI_NI_LABPC
1192 default N
1193 ---help--- 1153 ---help---
1194 Enable support for the National Instruments PCMCIA DAQCard-1200 1154 Enable support for the National Instruments PCMCIA DAQCard-1200
1195 1155
@@ -1201,7 +1161,6 @@ config COMEDI_NI_MIO_CS
1201 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON 1161 depends on COMEDI_NI_TIO && COMEDI_NI_COMMON
1202 select COMEDI_8255 1162 select COMEDI_8255
1203 select COMEDI_FC 1163 select COMEDI_FC
1204 default N
1205 ---help--- 1164 ---help---
1206 Enable support for the National Instruments PCMCIA DAQCard E series 1165 Enable support for the National Instruments PCMCIA DAQCard E series
1207 DAQCard-ai-16xe-50, DAQCard-ai-16e-4, DAQCard-6062E, DAQCard-6024E 1166 DAQCard-ai-16xe-50, DAQCard-ai-16e-4, DAQCard-6062E, DAQCard-6024E
@@ -1212,7 +1171,6 @@ config COMEDI_NI_MIO_CS
1212 1171
1213config COMEDI_QUATECH_DAQP_CS 1172config COMEDI_QUATECH_DAQP_CS
1214 tristate "Quatech DAQP PCMCIA data capture card support" 1173 tristate "Quatech DAQP PCMCIA data capture card support"
1215 default N
1216 ---help--- 1174 ---help---
1217 Enable support for the Quatech DAQP PCMCIA data capture cards 1175 Enable support for the Quatech DAQP PCMCIA data capture cards
1218 DAQP-208 and DAQP-308 1176 DAQP-208 and DAQP-308
@@ -1225,7 +1183,6 @@ endif # COMEDI_PCMCIA_DRIVERS
1225menuconfig COMEDI_USB_DRIVERS 1183menuconfig COMEDI_USB_DRIVERS
1226 tristate "Comedi USB drivers" 1184 tristate "Comedi USB drivers"
1227 depends on COMEDI && USB 1185 depends on COMEDI && USB
1228 default N
1229 ---help--- 1186 ---help---
1230 Enable comedi USB drivers to be built 1187 Enable comedi USB drivers to be built
1231 1188
@@ -1237,7 +1194,6 @@ if COMEDI_USB_DRIVERS && USB
1237 1194
1238config COMEDI_DT9812 1195config COMEDI_DT9812
1239 tristate "DataTranslation DT9812 USB module support" 1196 tristate "DataTranslation DT9812 USB module support"
1240 default N
1241 ---help--- 1197 ---help---
1242 Enable support for the Data Translation DT9812 USB module 1198 Enable support for the Data Translation DT9812 USB module
1243 1199
@@ -1246,7 +1202,6 @@ config COMEDI_DT9812
1246 1202
1247config COMEDI_USBDUX 1203config COMEDI_USBDUX
1248 tristate "ITL USB-DUX-D support" 1204 tristate "ITL USB-DUX-D support"
1249 default N
1250 ---help--- 1205 ---help---
1251 Enable support for the Incite Technology Ltd USB-DUX-D Board 1206 Enable support for the Incite Technology Ltd USB-DUX-D Board
1252 1207
@@ -1256,7 +1211,6 @@ config COMEDI_USBDUX
1256config COMEDI_USBDUXFAST 1211config COMEDI_USBDUXFAST
1257 tristate "ITL USB-DUXfast support" 1212 tristate "ITL USB-DUXfast support"
1258 select COMEDI_FC 1213 select COMEDI_FC
1259 default N
1260 ---help--- 1214 ---help---
1261 Enable support for the Incite Technology Ltd USB-DUXfast Board 1215 Enable support for the Incite Technology Ltd USB-DUXfast Board
1262 1216
@@ -1266,7 +1220,6 @@ config COMEDI_USBDUXFAST
1266config COMEDI_USBDUXSIGMA 1220config COMEDI_USBDUXSIGMA
1267 tristate "ITL USB-DUXsigma support" 1221 tristate "ITL USB-DUXsigma support"
1268 select COMEDI_FC 1222 select COMEDI_FC
1269 default N
1270 ---help--- 1223 ---help---
1271 Enable support for the Incite Technology Ltd USB-DUXsigma Board 1224 Enable support for the Incite Technology Ltd USB-DUXsigma Board
1272 1225
@@ -1275,7 +1228,6 @@ config COMEDI_USBDUXSIGMA
1275 1228
1276config COMEDI_VMK80XX 1229config COMEDI_VMK80XX
1277 tristate "Velleman VM110/VM140 USB Board support" 1230 tristate "Velleman VM110/VM140 USB Board support"
1278 default N
1279 ---help--- 1231 ---help---
1280 Build the Velleman USB Board Low-Level Driver supporting the 1232 Build the Velleman USB Board Low-Level Driver supporting the
1281 K8055/K8061 aka VM110/VM140 devices 1233 K8055/K8061 aka VM110/VM140 devices
@@ -1288,7 +1240,6 @@ endif # COMEDI_USB_DRIVERS
1288menuconfig COMEDI_NI_COMMON 1240menuconfig COMEDI_NI_COMMON
1289 tristate "Comedi National Instruments card support" 1241 tristate "Comedi National Instruments card support"
1290 depends on COMEDI 1242 depends on COMEDI
1291 default N
1292 ---help--- 1243 ---help---
1293 Enable comedi support for National Instruments cards. 1244 Enable comedi support for National Instruments cards.
1294 Modules in this section are used by many comedi NI drivers. 1245 Modules in this section are used by many comedi NI drivers.
@@ -1302,7 +1253,6 @@ if COMEDI_NI_COMMON
1302config COMEDI_MITE 1253config COMEDI_MITE
1303 tristate "NI Mite PCI interface chip support" 1254 tristate "NI Mite PCI interface chip support"
1304 depends on PCI 1255 depends on PCI
1305 default N
1306 ---help--- 1256 ---help---
1307 Enable support for National Instruments Mite PCI interface chip 1257 Enable support for National Instruments Mite PCI interface chip
1308 1258
@@ -1312,7 +1262,6 @@ config COMEDI_MITE
1312config COMEDI_NI_TIO 1262config COMEDI_NI_TIO
1313 tristate "NI general purpose counter support" 1263 tristate "NI general purpose counter support"
1314 depends on COMEDI_MITE 1264 depends on COMEDI_MITE
1315 default N
1316 ---help--- 1265 ---help---
1317 Enable support for National Instruments general purpose counters. 1266 Enable support for National Instruments general purpose counters.
1318 This module is not used directly by end-users. Rather, it 1267 This module is not used directly by end-users. Rather, it
@@ -1328,7 +1277,6 @@ config COMEDI_NI_LABPC
1328 select COMEDI_8255 1277 select COMEDI_8255
1329 select COMEDI_FC 1278 select COMEDI_FC
1330 depends on VIRT_TO_BUS 1279 depends on VIRT_TO_BUS
1331 default N
1332 ---help--- 1280 ---help---
1333 Enable support for National Instruments Lab-PC and compatibles 1281 Enable support for National Instruments Lab-PC and compatibles
1334 Lab-PC-1200, Lab-PC-1200AI, Lab-PC+ and PCI-1200. 1282 Lab-PC-1200, Lab-PC-1200AI, Lab-PC+ and PCI-1200.
@@ -1343,7 +1291,6 @@ endif # COMEDI_NI_COMMON
1343config COMEDI_8255 1291config COMEDI_8255
1344 tristate "Generic 8255 support" 1292 tristate "Generic 8255 support"
1345 depends on COMEDI 1293 depends on COMEDI
1346 default N
1347 ---help--- 1294 ---help---
1348 Enable generic 8255 support. 1295 Enable generic 8255 support.
1349 1296
@@ -1357,24 +1304,9 @@ config COMEDI_8255
1357 To compile this driver as a module, choose M here: the module will be 1304 To compile this driver as a module, choose M here: the module will be
1358 called 8255. 1305 called 8255.
1359 1306
1360config COMEDI_DAS08
1361 tristate "DAS-08 compatible support"
1362 depends on COMEDI
1363 select COMEDI_8255
1364 default N
1365 ---help---
1366 Enable support for DAS08 and compatible ISA, PC/104 and PCI cards.
1367
1368 Note that PCMCIA DAS08 cards are not directly supported by this
1369 driver, and need a separate driver as a wrapper.
1370
1371 To compile this driver as a module, choose M here: the module will be
1372 called das08.
1373
1374config COMEDI_FC 1307config COMEDI_FC
1375 tristate "Comedi shared functions for low-level driver support" 1308 tristate "Comedi shared functions for low-level driver support"
1376 depends on COMEDI 1309 depends on COMEDI
1377 default N
1378 ---help--- 1310 ---help---
1379 Enable support for shared functions for low-level drivers. 1311 Enable support for shared functions for low-level drivers.
1380 This module is not used directly by end-users. Rather, it 1312 This module is not used directly by end-users. Rather, it
@@ -1382,3 +1314,22 @@ config COMEDI_FC
1382 1314
1383 To compile this driver as a module, choose M here: the module will be 1315 To compile this driver as a module, choose M here: the module will be
1384 called comedi_fc. 1316 called comedi_fc.
1317
1318config COMEDI_AMPLC_DIO200
1319 tristate
1320 depends on COMEDI
1321 select COMEDI_8255
1322
1323config COMEDI_AMPLC_PC236
1324 tristate
1325 depends on COMEDI
1326 select COMEDI_8255
1327
1328config COMEDI_AMPLC_PC263
1329 tristate
1330 depends on COMEDI
1331
1332config COMEDI_DAS08
1333 tristate
1334 depends on COMEDI
1335 select COMEDI_8255
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index 14ea35ac0156..8ea55aef10a7 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -465,7 +465,7 @@
465/* only relevant to kernel modules. */ 465/* only relevant to kernel modules. */
466 466
467#define COMEDI_CB_EOS 1 /* end of scan */ 467#define COMEDI_CB_EOS 1 /* end of scan */
468#define COMEDI_CB_EOA 2 /* end of acquisition */ 468#define COMEDI_CB_EOA 2 /* end of acquisition/output */
469#define COMEDI_CB_BLOCK 4 /* data has arrived: 469#define COMEDI_CB_BLOCK 4 /* data has arrived:
470 * wakes up read() / write() */ 470 * wakes up read() / write() */
471#define COMEDI_CB_EOBUF 8 /* DEPRECATED: end of buffer */ 471#define COMEDI_CB_EOBUF 8 /* DEPRECATED: end of buffer */
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 9bcf87ae4c00..76776571ed91 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -58,14 +58,35 @@ MODULE_LICENSE("GPL");
58#ifdef CONFIG_COMEDI_DEBUG 58#ifdef CONFIG_COMEDI_DEBUG
59int comedi_debug; 59int comedi_debug;
60EXPORT_SYMBOL(comedi_debug); 60EXPORT_SYMBOL(comedi_debug);
61module_param(comedi_debug, int, 0644); 61module_param(comedi_debug, int, S_IRUGO | S_IWUSR);
62MODULE_PARM_DESC(comedi_debug,
63 "enable comedi core and driver debugging if non-zero (default 0)"
64 );
62#endif 65#endif
63 66
64bool comedi_autoconfig = 1; 67bool comedi_autoconfig = 1;
65module_param(comedi_autoconfig, bool, 0444); 68module_param(comedi_autoconfig, bool, S_IRUGO);
69MODULE_PARM_DESC(comedi_autoconfig,
70 "enable drivers to auto-configure comedi devices (default 1)");
66 71
67static int comedi_num_legacy_minors; 72static int comedi_num_legacy_minors;
68module_param(comedi_num_legacy_minors, int, 0444); 73module_param(comedi_num_legacy_minors, int, S_IRUGO);
74MODULE_PARM_DESC(comedi_num_legacy_minors,
75 "number of comedi minor devices to reserve for non-auto-configured devices (default 0)"
76 );
77
78unsigned int comedi_default_buf_size_kb = CONFIG_COMEDI_DEFAULT_BUF_SIZE_KB;
79module_param(comedi_default_buf_size_kb, uint, S_IRUGO | S_IWUSR);
80MODULE_PARM_DESC(comedi_default_buf_size_kb,
81 "default asynchronous buffer size in KiB (default "
82 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_SIZE_KB) ")");
83
84unsigned int comedi_default_buf_maxsize_kb
85 = CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB;
86module_param(comedi_default_buf_maxsize_kb, uint, S_IRUGO | S_IWUSR);
87MODULE_PARM_DESC(comedi_default_buf_maxsize_kb,
88 "default maximum size of asynchronous buffer in KiB (default "
89 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB) ")");
69 90
70static DEFINE_SPINLOCK(comedi_file_info_table_lock); 91static DEFINE_SPINLOCK(comedi_file_info_table_lock);
71static struct comedi_device_file_info 92static struct comedi_device_file_info
@@ -108,15 +129,283 @@ static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
108static int comedi_fasync(int fd, struct file *file, int on); 129static int comedi_fasync(int fd, struct file *file, int on);
109 130
110static int is_device_busy(struct comedi_device *dev); 131static int is_device_busy(struct comedi_device *dev);
132
111static int resize_async_buffer(struct comedi_device *dev, 133static int resize_async_buffer(struct comedi_device *dev,
112 struct comedi_subdevice *s, 134 struct comedi_subdevice *s,
113 struct comedi_async *async, unsigned new_size); 135 struct comedi_async *async, unsigned new_size)
136{
137 int retval;
138
139 if (new_size > async->max_bufsize)
140 return -EPERM;
141
142 if (s->busy) {
143 DPRINTK("subdevice is busy, cannot resize buffer\n");
144 return -EBUSY;
145 }
146 if (async->mmap_count) {
147 DPRINTK("subdevice is mmapped, cannot resize buffer\n");
148 return -EBUSY;
149 }
150
151 if (!async->prealloc_buf)
152 return -EINVAL;
153
154 /* make sure buffer is an integral number of pages
155 * (we round up) */
156 new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK;
157
158 retval = comedi_buf_alloc(dev, s, new_size);
159 if (retval < 0)
160 return retval;
161
162 if (s->buf_change) {
163 retval = s->buf_change(dev, s, new_size);
164 if (retval < 0)
165 return retval;
166 }
167
168 DPRINTK("comedi%i subd %d buffer resized to %i bytes\n",
169 dev->minor, (int)(s - dev->subdevices), async->prealloc_bufsz);
170 return 0;
171}
172
173/* sysfs attribute files */
174
175static const unsigned bytes_per_kibi = 1024;
176
177static ssize_t show_max_read_buffer_kb(struct device *dev,
178 struct device_attribute *attr, char *buf)
179{
180 ssize_t retval;
181 struct comedi_device_file_info *info = dev_get_drvdata(dev);
182 unsigned max_buffer_size_kb = 0;
183 struct comedi_subdevice *const read_subdevice =
184 comedi_get_read_subdevice(info);
185
186 mutex_lock(&info->device->mutex);
187 if (read_subdevice &&
188 (read_subdevice->subdev_flags & SDF_CMD_READ) &&
189 read_subdevice->async) {
190 max_buffer_size_kb = read_subdevice->async->max_bufsize /
191 bytes_per_kibi;
192 }
193 retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
194 mutex_unlock(&info->device->mutex);
195
196 return retval;
197}
198
199static ssize_t store_max_read_buffer_kb(struct device *dev,
200 struct device_attribute *attr,
201 const char *buf, size_t count)
202{
203 struct comedi_device_file_info *info = dev_get_drvdata(dev);
204 unsigned int new_max_size_kb;
205 unsigned int new_max_size;
206 int ret;
207 struct comedi_subdevice *const read_subdevice =
208 comedi_get_read_subdevice(info);
209
210 ret = kstrtouint(buf, 10, &new_max_size_kb);
211 if (ret)
212 return ret;
213 if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
214 return -EINVAL;
215 new_max_size = new_max_size_kb * bytes_per_kibi;
216
217 mutex_lock(&info->device->mutex);
218 if (read_subdevice == NULL ||
219 (read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
220 read_subdevice->async == NULL) {
221 mutex_unlock(&info->device->mutex);
222 return -EINVAL;
223 }
224 read_subdevice->async->max_bufsize = new_max_size;
225 mutex_unlock(&info->device->mutex);
226
227 return count;
228}
229
230static ssize_t show_read_buffer_kb(struct device *dev,
231 struct device_attribute *attr, char *buf)
232{
233 ssize_t retval;
234 struct comedi_device_file_info *info = dev_get_drvdata(dev);
235 unsigned buffer_size_kb = 0;
236 struct comedi_subdevice *const read_subdevice =
237 comedi_get_read_subdevice(info);
238
239 mutex_lock(&info->device->mutex);
240 if (read_subdevice &&
241 (read_subdevice->subdev_flags & SDF_CMD_READ) &&
242 read_subdevice->async) {
243 buffer_size_kb = read_subdevice->async->prealloc_bufsz /
244 bytes_per_kibi;
245 }
246 retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
247 mutex_unlock(&info->device->mutex);
248
249 return retval;
250}
251
252static ssize_t store_read_buffer_kb(struct device *dev,
253 struct device_attribute *attr,
254 const char *buf, size_t count)
255{
256 struct comedi_device_file_info *info = dev_get_drvdata(dev);
257 unsigned int new_size_kb;
258 unsigned int new_size;
259 int retval;
260 int ret;
261 struct comedi_subdevice *const read_subdevice =
262 comedi_get_read_subdevice(info);
263
264 ret = kstrtouint(buf, 10, &new_size_kb);
265 if (ret)
266 return ret;
267 if (new_size_kb > (UINT_MAX / bytes_per_kibi))
268 return -EINVAL;
269 new_size = new_size_kb * bytes_per_kibi;
270
271 mutex_lock(&info->device->mutex);
272 if (read_subdevice == NULL ||
273 (read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
274 read_subdevice->async == NULL) {
275 mutex_unlock(&info->device->mutex);
276 return -EINVAL;
277 }
278 retval = resize_async_buffer(info->device, read_subdevice,
279 read_subdevice->async, new_size);
280 mutex_unlock(&info->device->mutex);
281
282 if (retval < 0)
283 return retval;
284 return count;
285}
286
287static ssize_t show_max_write_buffer_kb(struct device *dev,
288 struct device_attribute *attr,
289 char *buf)
290{
291 ssize_t retval;
292 struct comedi_device_file_info *info = dev_get_drvdata(dev);
293 unsigned max_buffer_size_kb = 0;
294 struct comedi_subdevice *const write_subdevice =
295 comedi_get_write_subdevice(info);
296
297 mutex_lock(&info->device->mutex);
298 if (write_subdevice &&
299 (write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
300 write_subdevice->async) {
301 max_buffer_size_kb = write_subdevice->async->max_bufsize /
302 bytes_per_kibi;
303 }
304 retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
305 mutex_unlock(&info->device->mutex);
306
307 return retval;
308}
309
310static ssize_t store_max_write_buffer_kb(struct device *dev,
311 struct device_attribute *attr,
312 const char *buf, size_t count)
313{
314 struct comedi_device_file_info *info = dev_get_drvdata(dev);
315 unsigned int new_max_size_kb;
316 unsigned int new_max_size;
317 int ret;
318 struct comedi_subdevice *const write_subdevice =
319 comedi_get_write_subdevice(info);
320
321 ret = kstrtouint(buf, 10, &new_max_size_kb);
322 if (ret)
323 return ret;
324 if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
325 return -EINVAL;
326 new_max_size = new_max_size_kb * bytes_per_kibi;
327
328 mutex_lock(&info->device->mutex);
329 if (write_subdevice == NULL ||
330 (write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
331 write_subdevice->async == NULL) {
332 mutex_unlock(&info->device->mutex);
333 return -EINVAL;
334 }
335 write_subdevice->async->max_bufsize = new_max_size;
336 mutex_unlock(&info->device->mutex);
337
338 return count;
339}
340
341static ssize_t show_write_buffer_kb(struct device *dev,
342 struct device_attribute *attr, char *buf)
343{
344 ssize_t retval;
345 struct comedi_device_file_info *info = dev_get_drvdata(dev);
346 unsigned buffer_size_kb = 0;
347 struct comedi_subdevice *const write_subdevice =
348 comedi_get_write_subdevice(info);
349
350 mutex_lock(&info->device->mutex);
351 if (write_subdevice &&
352 (write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
353 write_subdevice->async) {
354 buffer_size_kb = write_subdevice->async->prealloc_bufsz /
355 bytes_per_kibi;
356 }
357 retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
358 mutex_unlock(&info->device->mutex);
114 359
115/* declarations for sysfs attribute files */ 360 return retval;
116static struct device_attribute dev_attr_max_read_buffer_kb; 361}
117static struct device_attribute dev_attr_read_buffer_kb; 362
118static struct device_attribute dev_attr_max_write_buffer_kb; 363static ssize_t store_write_buffer_kb(struct device *dev,
119static struct device_attribute dev_attr_write_buffer_kb; 364 struct device_attribute *attr,
365 const char *buf, size_t count)
366{
367 struct comedi_device_file_info *info = dev_get_drvdata(dev);
368 unsigned int new_size_kb;
369 unsigned int new_size;
370 int retval;
371 int ret;
372 struct comedi_subdevice *const write_subdevice =
373 comedi_get_write_subdevice(info);
374
375 ret = kstrtouint(buf, 10, &new_size_kb);
376 if (ret)
377 return ret;
378 if (new_size_kb > (UINT_MAX / bytes_per_kibi))
379 return -EINVAL;
380 new_size = ((uint64_t) new_size_kb) * bytes_per_kibi;
381
382 mutex_lock(&info->device->mutex);
383 if (write_subdevice == NULL ||
384 (write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
385 write_subdevice->async == NULL) {
386 mutex_unlock(&info->device->mutex);
387 return -EINVAL;
388 }
389 retval = resize_async_buffer(info->device, write_subdevice,
390 write_subdevice->async, new_size);
391 mutex_unlock(&info->device->mutex);
392
393 if (retval < 0)
394 return retval;
395 return count;
396}
397
398static struct device_attribute comedi_dev_attrs[] = {
399 __ATTR(max_read_buffer_kb, S_IRUGO | S_IWUSR,
400 show_max_read_buffer_kb, store_max_read_buffer_kb),
401 __ATTR(read_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
402 show_read_buffer_kb, store_read_buffer_kb),
403 __ATTR(max_write_buffer_kb, S_IRUGO | S_IWUSR,
404 show_max_write_buffer_kb, store_max_write_buffer_kb),
405 __ATTR(write_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
406 show_write_buffer_kb, store_write_buffer_kb),
407 __ATTR_NULL
408};
120 409
121static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, 410static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
122 unsigned long arg) 411 unsigned long arg)
@@ -280,7 +569,7 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
280 if (ret == 0) { 569 if (ret == 0) {
281 if (!try_module_get(dev->driver->module)) { 570 if (!try_module_get(dev->driver->module)) {
282 comedi_device_detach(dev); 571 comedi_device_detach(dev);
283 return -ENOSYS; 572 ret = -ENOSYS;
284 } 573 }
285 } 574 }
286 575
@@ -1545,7 +1834,7 @@ done:
1545 return retval; 1834 return retval;
1546} 1835}
1547 1836
1548static unsigned int comedi_poll(struct file *file, poll_table * wait) 1837static unsigned int comedi_poll(struct file *file, poll_table *wait)
1549{ 1838{
1550 unsigned int mask = 0; 1839 unsigned int mask = 0;
1551 const unsigned minor = iminor(file->f_dentry->d_inode); 1840 const unsigned minor = iminor(file->f_dentry->d_inode);
@@ -2054,6 +2343,8 @@ static int __init comedi_init(void)
2054 return PTR_ERR(comedi_class); 2343 return PTR_ERR(comedi_class);
2055 } 2344 }
2056 2345
2346 comedi_class->dev_attrs = comedi_dev_attrs;
2347
2057 /* XXX requires /proc interface */ 2348 /* XXX requires /proc interface */
2058 comedi_proc_init(); 2349 comedi_proc_init();
2059 2350
@@ -2192,11 +2483,9 @@ static void comedi_device_cleanup(struct comedi_device *dev)
2192 2483
2193int comedi_alloc_board_minor(struct device *hardware_device) 2484int comedi_alloc_board_minor(struct device *hardware_device)
2194{ 2485{
2195 unsigned long flags;
2196 struct comedi_device_file_info *info; 2486 struct comedi_device_file_info *info;
2197 struct device *csdev; 2487 struct device *csdev;
2198 unsigned i; 2488 unsigned i;
2199 int retval;
2200 2489
2201 info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); 2490 info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
2202 if (info == NULL) 2491 if (info == NULL)
@@ -2206,15 +2495,16 @@ int comedi_alloc_board_minor(struct device *hardware_device)
2206 kfree(info); 2495 kfree(info);
2207 return -ENOMEM; 2496 return -ENOMEM;
2208 } 2497 }
2498 info->hardware_device = hardware_device;
2209 comedi_device_init(info->device); 2499 comedi_device_init(info->device);
2210 spin_lock_irqsave(&comedi_file_info_table_lock, flags); 2500 spin_lock(&comedi_file_info_table_lock);
2211 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; ++i) { 2501 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; ++i) {
2212 if (comedi_file_info_table[i] == NULL) { 2502 if (comedi_file_info_table[i] == NULL) {
2213 comedi_file_info_table[i] = info; 2503 comedi_file_info_table[i] = info;
2214 break; 2504 break;
2215 } 2505 }
2216 } 2506 }
2217 spin_unlock_irqrestore(&comedi_file_info_table_lock, flags); 2507 spin_unlock(&comedi_file_info_table_lock);
2218 if (i == COMEDI_NUM_BOARD_MINORS) { 2508 if (i == COMEDI_NUM_BOARD_MINORS) {
2219 comedi_device_cleanup(info->device); 2509 comedi_device_cleanup(info->device);
2220 kfree(info->device); 2510 kfree(info->device);
@@ -2230,55 +2520,19 @@ int comedi_alloc_board_minor(struct device *hardware_device)
2230 if (!IS_ERR(csdev)) 2520 if (!IS_ERR(csdev))
2231 info->device->class_dev = csdev; 2521 info->device->class_dev = csdev;
2232 dev_set_drvdata(csdev, info); 2522 dev_set_drvdata(csdev, info);
2233 retval = device_create_file(csdev, &dev_attr_max_read_buffer_kb); 2523
2234 if (retval) {
2235 printk(KERN_ERR
2236 "comedi: "
2237 "failed to create sysfs attribute file \"%s\".\n",
2238 dev_attr_max_read_buffer_kb.attr.name);
2239 comedi_free_board_minor(i);
2240 return retval;
2241 }
2242 retval = device_create_file(csdev, &dev_attr_read_buffer_kb);
2243 if (retval) {
2244 printk(KERN_ERR
2245 "comedi: "
2246 "failed to create sysfs attribute file \"%s\".\n",
2247 dev_attr_read_buffer_kb.attr.name);
2248 comedi_free_board_minor(i);
2249 return retval;
2250 }
2251 retval = device_create_file(csdev, &dev_attr_max_write_buffer_kb);
2252 if (retval) {
2253 printk(KERN_ERR
2254 "comedi: "
2255 "failed to create sysfs attribute file \"%s\".\n",
2256 dev_attr_max_write_buffer_kb.attr.name);
2257 comedi_free_board_minor(i);
2258 return retval;
2259 }
2260 retval = device_create_file(csdev, &dev_attr_write_buffer_kb);
2261 if (retval) {
2262 printk(KERN_ERR
2263 "comedi: "
2264 "failed to create sysfs attribute file \"%s\".\n",
2265 dev_attr_write_buffer_kb.attr.name);
2266 comedi_free_board_minor(i);
2267 return retval;
2268 }
2269 return i; 2524 return i;
2270} 2525}
2271 2526
2272void comedi_free_board_minor(unsigned minor) 2527void comedi_free_board_minor(unsigned minor)
2273{ 2528{
2274 unsigned long flags;
2275 struct comedi_device_file_info *info; 2529 struct comedi_device_file_info *info;
2276 2530
2277 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); 2531 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
2278 spin_lock_irqsave(&comedi_file_info_table_lock, flags); 2532 spin_lock(&comedi_file_info_table_lock);
2279 info = comedi_file_info_table[minor]; 2533 info = comedi_file_info_table[minor];
2280 comedi_file_info_table[minor] = NULL; 2534 comedi_file_info_table[minor] = NULL;
2281 spin_unlock_irqrestore(&comedi_file_info_table_lock, flags); 2535 spin_unlock(&comedi_file_info_table_lock);
2282 2536
2283 if (info) { 2537 if (info) {
2284 struct comedi_device *dev = info->device; 2538 struct comedi_device *dev = info->device;
@@ -2294,14 +2548,29 @@ void comedi_free_board_minor(unsigned minor)
2294 } 2548 }
2295} 2549}
2296 2550
2551int comedi_find_board_minor(struct device *hardware_device)
2552{
2553 int minor;
2554 struct comedi_device_file_info *info;
2555
2556 for (minor = 0; minor < COMEDI_NUM_BOARD_MINORS; minor++) {
2557 spin_lock(&comedi_file_info_table_lock);
2558 info = comedi_file_info_table[minor];
2559 if (info && info->hardware_device == hardware_device) {
2560 spin_unlock(&comedi_file_info_table_lock);
2561 return minor;
2562 }
2563 spin_unlock(&comedi_file_info_table_lock);
2564 }
2565 return -ENODEV;
2566}
2567
2297int comedi_alloc_subdevice_minor(struct comedi_device *dev, 2568int comedi_alloc_subdevice_minor(struct comedi_device *dev,
2298 struct comedi_subdevice *s) 2569 struct comedi_subdevice *s)
2299{ 2570{
2300 unsigned long flags;
2301 struct comedi_device_file_info *info; 2571 struct comedi_device_file_info *info;
2302 struct device *csdev; 2572 struct device *csdev;
2303 unsigned i; 2573 unsigned i;
2304 int retval;
2305 2574
2306 info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); 2575 info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
2307 if (info == NULL) 2576 if (info == NULL)
@@ -2309,14 +2578,14 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
2309 info->device = dev; 2578 info->device = dev;
2310 info->read_subdevice = s; 2579 info->read_subdevice = s;
2311 info->write_subdevice = s; 2580 info->write_subdevice = s;
2312 spin_lock_irqsave(&comedi_file_info_table_lock, flags); 2581 spin_lock(&comedi_file_info_table_lock);
2313 for (i = COMEDI_FIRST_SUBDEVICE_MINOR; i < COMEDI_NUM_MINORS; ++i) { 2582 for (i = COMEDI_FIRST_SUBDEVICE_MINOR; i < COMEDI_NUM_MINORS; ++i) {
2314 if (comedi_file_info_table[i] == NULL) { 2583 if (comedi_file_info_table[i] == NULL) {
2315 comedi_file_info_table[i] = info; 2584 comedi_file_info_table[i] = info;
2316 break; 2585 break;
2317 } 2586 }
2318 } 2587 }
2319 spin_unlock_irqrestore(&comedi_file_info_table_lock, flags); 2588 spin_unlock(&comedi_file_info_table_lock);
2320 if (i == COMEDI_NUM_MINORS) { 2589 if (i == COMEDI_NUM_MINORS) {
2321 kfree(info); 2590 kfree(info);
2322 printk(KERN_ERR 2591 printk(KERN_ERR
@@ -2331,48 +2600,12 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
2331 if (!IS_ERR(csdev)) 2600 if (!IS_ERR(csdev))
2332 s->class_dev = csdev; 2601 s->class_dev = csdev;
2333 dev_set_drvdata(csdev, info); 2602 dev_set_drvdata(csdev, info);
2334 retval = device_create_file(csdev, &dev_attr_max_read_buffer_kb); 2603
2335 if (retval) {
2336 printk(KERN_ERR
2337 "comedi: "
2338 "failed to create sysfs attribute file \"%s\".\n",
2339 dev_attr_max_read_buffer_kb.attr.name);
2340 comedi_free_subdevice_minor(s);
2341 return retval;
2342 }
2343 retval = device_create_file(csdev, &dev_attr_read_buffer_kb);
2344 if (retval) {
2345 printk(KERN_ERR
2346 "comedi: "
2347 "failed to create sysfs attribute file \"%s\".\n",
2348 dev_attr_read_buffer_kb.attr.name);
2349 comedi_free_subdevice_minor(s);
2350 return retval;
2351 }
2352 retval = device_create_file(csdev, &dev_attr_max_write_buffer_kb);
2353 if (retval) {
2354 printk(KERN_ERR
2355 "comedi: "
2356 "failed to create sysfs attribute file \"%s\".\n",
2357 dev_attr_max_write_buffer_kb.attr.name);
2358 comedi_free_subdevice_minor(s);
2359 return retval;
2360 }
2361 retval = device_create_file(csdev, &dev_attr_write_buffer_kb);
2362 if (retval) {
2363 printk(KERN_ERR
2364 "comedi: "
2365 "failed to create sysfs attribute file \"%s\".\n",
2366 dev_attr_write_buffer_kb.attr.name);
2367 comedi_free_subdevice_minor(s);
2368 return retval;
2369 }
2370 return i; 2604 return i;
2371} 2605}
2372 2606
2373void comedi_free_subdevice_minor(struct comedi_subdevice *s) 2607void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2374{ 2608{
2375 unsigned long flags;
2376 struct comedi_device_file_info *info; 2609 struct comedi_device_file_info *info;
2377 2610
2378 if (s == NULL) 2611 if (s == NULL)
@@ -2383,10 +2616,10 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2383 BUG_ON(s->minor >= COMEDI_NUM_MINORS); 2616 BUG_ON(s->minor >= COMEDI_NUM_MINORS);
2384 BUG_ON(s->minor < COMEDI_FIRST_SUBDEVICE_MINOR); 2617 BUG_ON(s->minor < COMEDI_FIRST_SUBDEVICE_MINOR);
2385 2618
2386 spin_lock_irqsave(&comedi_file_info_table_lock, flags); 2619 spin_lock(&comedi_file_info_table_lock);
2387 info = comedi_file_info_table[s->minor]; 2620 info = comedi_file_info_table[s->minor];
2388 comedi_file_info_table[s->minor] = NULL; 2621 comedi_file_info_table[s->minor] = NULL;
2389 spin_unlock_irqrestore(&comedi_file_info_table_lock, flags); 2622 spin_unlock(&comedi_file_info_table_lock);
2390 2623
2391 if (s->class_dev) { 2624 if (s->class_dev) {
2392 device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, s->minor)); 2625 device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, s->minor));
@@ -2397,310 +2630,12 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2397 2630
2398struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor) 2631struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor)
2399{ 2632{
2400 unsigned long flags;
2401 struct comedi_device_file_info *info; 2633 struct comedi_device_file_info *info;
2402 2634
2403 BUG_ON(minor >= COMEDI_NUM_MINORS); 2635 BUG_ON(minor >= COMEDI_NUM_MINORS);
2404 spin_lock_irqsave(&comedi_file_info_table_lock, flags); 2636 spin_lock(&comedi_file_info_table_lock);
2405 info = comedi_file_info_table[minor]; 2637 info = comedi_file_info_table[minor];
2406 spin_unlock_irqrestore(&comedi_file_info_table_lock, flags); 2638 spin_unlock(&comedi_file_info_table_lock);
2407 return info; 2639 return info;
2408} 2640}
2409EXPORT_SYMBOL_GPL(comedi_get_device_file_info); 2641EXPORT_SYMBOL_GPL(comedi_get_device_file_info);
2410
2411static int resize_async_buffer(struct comedi_device *dev,
2412 struct comedi_subdevice *s,
2413 struct comedi_async *async, unsigned new_size)
2414{
2415 int retval;
2416
2417 if (new_size > async->max_bufsize)
2418 return -EPERM;
2419
2420 if (s->busy) {
2421 DPRINTK("subdevice is busy, cannot resize buffer\n");
2422 return -EBUSY;
2423 }
2424 if (async->mmap_count) {
2425 DPRINTK("subdevice is mmapped, cannot resize buffer\n");
2426 return -EBUSY;
2427 }
2428
2429 if (!async->prealloc_buf)
2430 return -EINVAL;
2431
2432 /* make sure buffer is an integral number of pages
2433 * (we round up) */
2434 new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK;
2435
2436 retval = comedi_buf_alloc(dev, s, new_size);
2437 if (retval < 0)
2438 return retval;
2439
2440 if (s->buf_change) {
2441 retval = s->buf_change(dev, s, new_size);
2442 if (retval < 0)
2443 return retval;
2444 }
2445
2446 DPRINTK("comedi%i subd %d buffer resized to %i bytes\n",
2447 dev->minor, (int)(s - dev->subdevices), async->prealloc_bufsz);
2448 return 0;
2449}
2450
2451/* sysfs attribute files */
2452
2453static const unsigned bytes_per_kibi = 1024;
2454
2455static ssize_t show_max_read_buffer_kb(struct device *dev,
2456 struct device_attribute *attr, char *buf)
2457{
2458 ssize_t retval;
2459 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2460 unsigned max_buffer_size_kb = 0;
2461 struct comedi_subdevice *const read_subdevice =
2462 comedi_get_read_subdevice(info);
2463
2464 mutex_lock(&info->device->mutex);
2465 if (read_subdevice &&
2466 (read_subdevice->subdev_flags & SDF_CMD_READ) &&
2467 read_subdevice->async) {
2468 max_buffer_size_kb = read_subdevice->async->max_bufsize /
2469 bytes_per_kibi;
2470 }
2471 retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
2472 mutex_unlock(&info->device->mutex);
2473
2474 return retval;
2475}
2476
2477static ssize_t store_max_read_buffer_kb(struct device *dev,
2478 struct device_attribute *attr,
2479 const char *buf, size_t count)
2480{
2481 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2482 unsigned int new_max_size_kb;
2483 unsigned int new_max_size;
2484 int ret;
2485 struct comedi_subdevice *const read_subdevice =
2486 comedi_get_read_subdevice(info);
2487
2488 ret = kstrtouint(buf, 10, &new_max_size_kb);
2489 if (ret)
2490 return ret;
2491 if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
2492 return -EINVAL;
2493 new_max_size = new_max_size_kb * bytes_per_kibi;
2494
2495 mutex_lock(&info->device->mutex);
2496 if (read_subdevice == NULL ||
2497 (read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
2498 read_subdevice->async == NULL) {
2499 mutex_unlock(&info->device->mutex);
2500 return -EINVAL;
2501 }
2502 read_subdevice->async->max_bufsize = new_max_size;
2503 mutex_unlock(&info->device->mutex);
2504
2505 return count;
2506}
2507
2508static struct device_attribute dev_attr_max_read_buffer_kb = {
2509 .attr = {
2510 .name = "max_read_buffer_kb",
2511 .mode = S_IRUGO | S_IWUSR},
2512 .show = &show_max_read_buffer_kb,
2513 .store = &store_max_read_buffer_kb
2514};
2515
2516static ssize_t show_read_buffer_kb(struct device *dev,
2517 struct device_attribute *attr, char *buf)
2518{
2519 ssize_t retval;
2520 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2521 unsigned buffer_size_kb = 0;
2522 struct comedi_subdevice *const read_subdevice =
2523 comedi_get_read_subdevice(info);
2524
2525 mutex_lock(&info->device->mutex);
2526 if (read_subdevice &&
2527 (read_subdevice->subdev_flags & SDF_CMD_READ) &&
2528 read_subdevice->async) {
2529 buffer_size_kb = read_subdevice->async->prealloc_bufsz /
2530 bytes_per_kibi;
2531 }
2532 retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
2533 mutex_unlock(&info->device->mutex);
2534
2535 return retval;
2536}
2537
2538static ssize_t store_read_buffer_kb(struct device *dev,
2539 struct device_attribute *attr,
2540 const char *buf, size_t count)
2541{
2542 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2543 unsigned int new_size_kb;
2544 unsigned int new_size;
2545 int retval;
2546 int ret;
2547 struct comedi_subdevice *const read_subdevice =
2548 comedi_get_read_subdevice(info);
2549
2550 ret = kstrtouint(buf, 10, &new_size_kb);
2551 if (ret)
2552 return ret;
2553 if (new_size_kb > (UINT_MAX / bytes_per_kibi))
2554 return -EINVAL;
2555 new_size = new_size_kb * bytes_per_kibi;
2556
2557 mutex_lock(&info->device->mutex);
2558 if (read_subdevice == NULL ||
2559 (read_subdevice->subdev_flags & SDF_CMD_READ) == 0 ||
2560 read_subdevice->async == NULL) {
2561 mutex_unlock(&info->device->mutex);
2562 return -EINVAL;
2563 }
2564 retval = resize_async_buffer(info->device, read_subdevice,
2565 read_subdevice->async, new_size);
2566 mutex_unlock(&info->device->mutex);
2567
2568 if (retval < 0)
2569 return retval;
2570 return count;
2571}
2572
2573static struct device_attribute dev_attr_read_buffer_kb = {
2574 .attr = {
2575 .name = "read_buffer_kb",
2576 .mode = S_IRUGO | S_IWUSR | S_IWGRP},
2577 .show = &show_read_buffer_kb,
2578 .store = &store_read_buffer_kb
2579};
2580
2581static ssize_t show_max_write_buffer_kb(struct device *dev,
2582 struct device_attribute *attr,
2583 char *buf)
2584{
2585 ssize_t retval;
2586 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2587 unsigned max_buffer_size_kb = 0;
2588 struct comedi_subdevice *const write_subdevice =
2589 comedi_get_write_subdevice(info);
2590
2591 mutex_lock(&info->device->mutex);
2592 if (write_subdevice &&
2593 (write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
2594 write_subdevice->async) {
2595 max_buffer_size_kb = write_subdevice->async->max_bufsize /
2596 bytes_per_kibi;
2597 }
2598 retval = snprintf(buf, PAGE_SIZE, "%i\n", max_buffer_size_kb);
2599 mutex_unlock(&info->device->mutex);
2600
2601 return retval;
2602}
2603
2604static ssize_t store_max_write_buffer_kb(struct device *dev,
2605 struct device_attribute *attr,
2606 const char *buf, size_t count)
2607{
2608 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2609 unsigned int new_max_size_kb;
2610 unsigned int new_max_size;
2611 int ret;
2612 struct comedi_subdevice *const write_subdevice =
2613 comedi_get_write_subdevice(info);
2614
2615 ret = kstrtouint(buf, 10, &new_max_size_kb);
2616 if (ret)
2617 return ret;
2618 if (new_max_size_kb > (UINT_MAX / bytes_per_kibi))
2619 return -EINVAL;
2620 new_max_size = new_max_size_kb * bytes_per_kibi;
2621
2622 mutex_lock(&info->device->mutex);
2623 if (write_subdevice == NULL ||
2624 (write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
2625 write_subdevice->async == NULL) {
2626 mutex_unlock(&info->device->mutex);
2627 return -EINVAL;
2628 }
2629 write_subdevice->async->max_bufsize = new_max_size;
2630 mutex_unlock(&info->device->mutex);
2631
2632 return count;
2633}
2634
2635static struct device_attribute dev_attr_max_write_buffer_kb = {
2636 .attr = {
2637 .name = "max_write_buffer_kb",
2638 .mode = S_IRUGO | S_IWUSR},
2639 .show = &show_max_write_buffer_kb,
2640 .store = &store_max_write_buffer_kb
2641};
2642
2643static ssize_t show_write_buffer_kb(struct device *dev,
2644 struct device_attribute *attr, char *buf)
2645{
2646 ssize_t retval;
2647 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2648 unsigned buffer_size_kb = 0;
2649 struct comedi_subdevice *const write_subdevice =
2650 comedi_get_write_subdevice(info);
2651
2652 mutex_lock(&info->device->mutex);
2653 if (write_subdevice &&
2654 (write_subdevice->subdev_flags & SDF_CMD_WRITE) &&
2655 write_subdevice->async) {
2656 buffer_size_kb = write_subdevice->async->prealloc_bufsz /
2657 bytes_per_kibi;
2658 }
2659 retval = snprintf(buf, PAGE_SIZE, "%i\n", buffer_size_kb);
2660 mutex_unlock(&info->device->mutex);
2661
2662 return retval;
2663}
2664
2665static ssize_t store_write_buffer_kb(struct device *dev,
2666 struct device_attribute *attr,
2667 const char *buf, size_t count)
2668{
2669 struct comedi_device_file_info *info = dev_get_drvdata(dev);
2670 unsigned int new_size_kb;
2671 unsigned int new_size;
2672 int retval;
2673 int ret;
2674 struct comedi_subdevice *const write_subdevice =
2675 comedi_get_write_subdevice(info);
2676
2677 ret = kstrtouint(buf, 10, &new_size_kb);
2678 if (ret)
2679 return ret;
2680 if (new_size_kb > (UINT_MAX / bytes_per_kibi))
2681 return -EINVAL;
2682 new_size = ((uint64_t) new_size_kb) * bytes_per_kibi;
2683
2684 mutex_lock(&info->device->mutex);
2685 if (write_subdevice == NULL ||
2686 (write_subdevice->subdev_flags & SDF_CMD_WRITE) == 0 ||
2687 write_subdevice->async == NULL) {
2688 mutex_unlock(&info->device->mutex);
2689 return -EINVAL;
2690 }
2691 retval = resize_async_buffer(info->device, write_subdevice,
2692 write_subdevice->async, new_size);
2693 mutex_unlock(&info->device->mutex);
2694
2695 if (retval < 0)
2696 return retval;
2697 return count;
2698}
2699
2700static struct device_attribute dev_attr_write_buffer_kb = {
2701 .attr = {
2702 .name = "write_buffer_kb",
2703 .mode = S_IRUGO | S_IWUSR | S_IWGRP},
2704 .show = &show_write_buffer_kb,
2705 .store = &store_write_buffer_kb
2706};
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 7a0d4bcbc355..134be93eaa6d 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -180,13 +180,18 @@ struct comedi_async {
180 unsigned int x); 180 unsigned int x);
181}; 181};
182 182
183struct pci_dev;
184struct usb_interface;
185
183struct comedi_driver { 186struct comedi_driver {
184 struct comedi_driver *next; 187 struct comedi_driver *next;
185 188
186 const char *driver_name; 189 const char *driver_name;
187 struct module *module; 190 struct module *module;
188 int (*attach) (struct comedi_device *, struct comedi_devconfig *); 191 int (*attach) (struct comedi_device *, struct comedi_devconfig *);
189 int (*detach) (struct comedi_device *); 192 void (*detach) (struct comedi_device *);
193 int (*attach_pci) (struct comedi_device *, struct pci_dev *);
194 int (*attach_usb) (struct comedi_device *, struct usb_interface *);
190 195
191 /* number of elements in board_name and board_id arrays */ 196 /* number of elements in board_name and board_id arrays */
192 unsigned int num_names; 197 unsigned int num_names;
@@ -230,10 +235,16 @@ struct comedi_device {
230 void (*close) (struct comedi_device *dev); 235 void (*close) (struct comedi_device *dev);
231}; 236};
232 237
238static inline const void *comedi_board(struct comedi_device *dev)
239{
240 return dev->board_ptr;
241}
242
233struct comedi_device_file_info { 243struct comedi_device_file_info {
234 struct comedi_device *device; 244 struct comedi_device *device;
235 struct comedi_subdevice *read_subdevice; 245 struct comedi_subdevice *read_subdevice;
236 struct comedi_subdevice *write_subdevice; 246 struct comedi_subdevice *write_subdevice;
247 struct device *hardware_device;
237}; 248};
238 249
239#ifdef CONFIG_COMEDI_DEBUG 250#ifdef CONFIG_COMEDI_DEBUG
@@ -287,6 +298,56 @@ int comedi_device_attach(struct comedi_device *dev,
287int comedi_driver_register(struct comedi_driver *); 298int comedi_driver_register(struct comedi_driver *);
288int comedi_driver_unregister(struct comedi_driver *); 299int comedi_driver_unregister(struct comedi_driver *);
289 300
301/**
302 * module_comedi_driver() - Helper macro for registering a comedi driver
303 * @__comedi_driver: comedi_driver struct
304 *
305 * Helper macro for comedi drivers which do not do anything special in module
306 * init/exit. This eliminates a lot of boilerplate. Each module may only use
307 * this macro once, and calling it replaces module_init() and module_exit().
308 */
309#define module_comedi_driver(__comedi_driver) \
310 module_driver(__comedi_driver, comedi_driver_register, \
311 comedi_driver_unregister)
312
313struct pci_driver;
314
315int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
316void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
317
318/**
319 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
320 * @__comedi_driver: comedi_driver struct
321 * @__pci_driver: pci_driver struct
322 *
323 * Helper macro for comedi PCI drivers which do not do anything special
324 * in module init/exit. This eliminates a lot of boilerplate. Each
325 * module may only use this macro once, and calling it replaces
326 * module_init() and module_exit()
327 */
328#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \
329 module_driver(__comedi_driver, comedi_pci_driver_register, \
330 comedi_pci_driver_unregister, &(__pci_driver))
331
332struct usb_driver;
333
334int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
335void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
336
337/**
338 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
339 * @__comedi_driver: comedi_driver struct
340 * @__usb_driver: usb_driver struct
341 *
342 * Helper macro for comedi USB drivers which do not do anything special
343 * in module init/exit. This eliminates a lot of boilerplate. Each
344 * module may only use this macro once, and calling it replaces
345 * module_init() and module_exit()
346 */
347#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
348 module_driver(__comedi_driver, comedi_usb_driver_register, \
349 comedi_usb_driver_unregister, &(__usb_driver))
350
290void init_polling(void); 351void init_polling(void);
291void cleanup_polling(void); 352void cleanup_polling(void);
292void start_polling(struct comedi_device *); 353void start_polling(struct comedi_device *);
@@ -456,11 +517,12 @@ static inline void *comedi_aux_data(int options[], int n)
456int comedi_alloc_subdevice_minor(struct comedi_device *dev, 517int comedi_alloc_subdevice_minor(struct comedi_device *dev,
457 struct comedi_subdevice *s); 518 struct comedi_subdevice *s);
458void comedi_free_subdevice_minor(struct comedi_subdevice *s); 519void comedi_free_subdevice_minor(struct comedi_subdevice *s);
459int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name); 520int comedi_pci_auto_config(struct pci_dev *pcidev,
521 struct comedi_driver *driver);
460void comedi_pci_auto_unconfig(struct pci_dev *pcidev); 522void comedi_pci_auto_unconfig(struct pci_dev *pcidev);
461struct usb_device; /* forward declaration */ 523int comedi_usb_auto_config(struct usb_interface *intf,
462int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name); 524 struct comedi_driver *driver);
463void comedi_usb_auto_unconfig(struct usb_device *usbdev); 525void comedi_usb_auto_unconfig(struct usb_interface *intf);
464 526
465#ifdef CONFIG_COMEDI_PCI_DRIVERS 527#ifdef CONFIG_COMEDI_PCI_DRIVERS
466#define CONFIG_COMEDI_PCI 528#define CONFIG_COMEDI_PCI
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index bf185e2807d1..1c3d6386ea36 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -106,6 +106,26 @@ void comedi_device_detach(struct comedi_device *dev)
106 __comedi_device_detach(dev); 106 __comedi_device_detach(dev);
107} 107}
108 108
109/* do a little post-config cleanup */
110/* called with module refcount incremented, decrements it */
111static int comedi_device_postconfig(struct comedi_device *dev)
112{
113 int ret = postconfig(dev);
114 module_put(dev->driver->module);
115 if (ret < 0) {
116 __comedi_device_detach(dev);
117 return ret;
118 }
119 if (!dev->board_name) {
120 printk(KERN_WARNING "BUG: dev->board_name=<%p>\n",
121 dev->board_name);
122 dev->board_name = "BUG";
123 }
124 smp_wmb();
125 dev->attached = 1;
126 return 0;
127}
128
109int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) 129int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
110{ 130{
111 struct comedi_driver *driv; 131 struct comedi_driver *driv;
@@ -121,59 +141,36 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
121 } 141 }
122 if (driv->num_names) { 142 if (driv->num_names) {
123 dev->board_ptr = comedi_recognize(driv, it->board_name); 143 dev->board_ptr = comedi_recognize(driv, it->board_name);
124 if (dev->board_ptr == NULL) { 144 if (dev->board_ptr)
125 module_put(driv->module); 145 break;
126 continue; 146 } else if (strcmp(driv->driver_name, it->board_name))
127 } 147 break;
128 } else { 148 module_put(driv->module);
129 if (strcmp(driv->driver_name, it->board_name)) { 149 }
130 module_put(driv->module); 150 if (driv == NULL) {
151 /* recognize has failed if we get here */
152 /* report valid board names before returning error */
153 for (driv = comedi_drivers; driv; driv = driv->next) {
154 if (!try_module_get(driv->module)) {
155 printk(KERN_INFO
156 "comedi: failed to increment module count\n");
131 continue; 157 continue;
132 } 158 }
159 comedi_report_boards(driv);
160 module_put(driv->module);
133 } 161 }
134 /* initialize dev->driver here so 162 return -EIO;
135 * comedi_error() can be called from attach */
136 dev->driver = driv;
137 ret = driv->attach(dev, it);
138 if (ret < 0) {
139 module_put(dev->driver->module);
140 __comedi_device_detach(dev);
141 return ret;
142 }
143 goto attached;
144 } 163 }
145 164 /* initialize dev->driver here so
146 /* recognize has failed if we get here */ 165 * comedi_error() can be called from attach */
147 /* report valid board names before returning error */ 166 dev->driver = driv;
148 for (driv = comedi_drivers; driv; driv = driv->next) { 167 ret = driv->attach(dev, it);
149 if (!try_module_get(driv->module)) {
150 printk(KERN_INFO
151 "comedi: failed to increment module count\n");
152 continue;
153 }
154 comedi_report_boards(driv);
155 module_put(driv->module);
156 }
157 return -EIO;
158
159attached:
160 /* do a little post-config cleanup */
161 ret = postconfig(dev);
162 module_put(dev->driver->module);
163 if (ret < 0) { 168 if (ret < 0) {
169 module_put(dev->driver->module);
164 __comedi_device_detach(dev); 170 __comedi_device_detach(dev);
165 return ret; 171 return ret;
166 } 172 }
167 173 return comedi_device_postconfig(dev);
168 if (!dev->board_name) {
169 printk(KERN_WARNING "BUG: dev->board_name=<%p>\n",
170 dev->board_name);
171 dev->board_name = "BUG";
172 }
173 smp_wmb();
174 dev->attached = 1;
175
176 return 0;
177} 174}
178 175
179int comedi_driver_register(struct comedi_driver *driver) 176int comedi_driver_register(struct comedi_driver *driver)
@@ -242,6 +239,8 @@ static int postconfig(struct comedi_device *dev)
242 s->len_chanlist = 1; 239 s->len_chanlist = 1;
243 240
244 if (s->do_cmd) { 241 if (s->do_cmd) {
242 unsigned int buf_size;
243
245 BUG_ON((s->subdev_flags & (SDF_CMD_READ | 244 BUG_ON((s->subdev_flags & (SDF_CMD_READ |
246 SDF_CMD_WRITE)) == 0); 245 SDF_CMD_WRITE)) == 0);
247 BUG_ON(!s->do_cmdtest); 246 BUG_ON(!s->do_cmdtest);
@@ -257,19 +256,20 @@ static int postconfig(struct comedi_device *dev)
257 async->subdevice = s; 256 async->subdevice = s;
258 s->async = async; 257 s->async = async;
259 258
260#define DEFAULT_BUF_MAXSIZE (64*1024) 259 async->max_bufsize =
261#define DEFAULT_BUF_SIZE (64*1024) 260 comedi_default_buf_maxsize_kb * 1024;
262 261 buf_size = comedi_default_buf_size_kb * 1024;
263 async->max_bufsize = DEFAULT_BUF_MAXSIZE; 262 if (buf_size > async->max_bufsize)
263 buf_size = async->max_bufsize;
264 264
265 async->prealloc_buf = NULL; 265 async->prealloc_buf = NULL;
266 async->prealloc_bufsz = 0; 266 async->prealloc_bufsz = 0;
267 if (comedi_buf_alloc(dev, s, DEFAULT_BUF_SIZE) < 0) { 267 if (comedi_buf_alloc(dev, s, buf_size) < 0) {
268 printk(KERN_INFO "Buffer allocation failed\n"); 268 printk(KERN_INFO "Buffer allocation failed\n");
269 return -ENOMEM; 269 return -ENOMEM;
270 } 270 }
271 if (s->buf_change) { 271 if (s->buf_change) {
272 ret = s->buf_change(dev, s, DEFAULT_BUF_SIZE); 272 ret = s->buf_change(dev, s, buf_size);
273 if (ret < 0) 273 if (ret < 0)
274 return ret; 274 return ret;
275 } 275 }
@@ -814,67 +814,102 @@ void comedi_reset_async_buf(struct comedi_async *async)
814 async->events = 0; 814 async->events = 0;
815} 815}
816 816
817static int comedi_auto_config(struct device *hardware_device, 817static int
818 const char *board_name, const int *options, 818comedi_auto_config_helper(struct device *hardware_device,
819 unsigned num_options) 819 struct comedi_driver *driver,
820 int (*attach_wrapper) (struct comedi_device *,
821 void *), void *context)
820{ 822{
821 struct comedi_devconfig it;
822 int minor; 823 int minor;
823 struct comedi_device_file_info *dev_file_info; 824 struct comedi_device_file_info *dev_file_info;
824 int retval; 825 struct comedi_device *comedi_dev;
825 unsigned *private_data = NULL; 826 int ret;
826 827
827 if (!comedi_autoconfig) { 828 if (!comedi_autoconfig)
828 dev_set_drvdata(hardware_device, NULL);
829 return 0; 829 return 0;
830 }
831 830
832 minor = comedi_alloc_board_minor(hardware_device); 831 minor = comedi_alloc_board_minor(hardware_device);
833 if (minor < 0) 832 if (minor < 0)
834 return minor; 833 return minor;
835 834
836 private_data = kmalloc(sizeof(unsigned), GFP_KERNEL); 835 dev_file_info = comedi_get_device_file_info(minor);
837 if (private_data == NULL) { 836 comedi_dev = dev_file_info->device;
838 retval = -ENOMEM; 837
839 goto cleanup; 838 mutex_lock(&comedi_dev->mutex);
839 if (comedi_dev->attached)
840 ret = -EBUSY;
841 else if (!try_module_get(driver->module)) {
842 printk(KERN_INFO "comedi: failed to increment module count\n");
843 ret = -EIO;
844 } else {
845 /* set comedi_dev->driver here for attach wrapper */
846 comedi_dev->driver = driver;
847 ret = (*attach_wrapper)(comedi_dev, context);
848 if (ret < 0) {
849 module_put(driver->module);
850 __comedi_device_detach(comedi_dev);
851 } else {
852 ret = comedi_device_postconfig(comedi_dev);
853 }
840 } 854 }
841 *private_data = minor; 855 mutex_unlock(&comedi_dev->mutex);
842 dev_set_drvdata(hardware_device, private_data);
843 856
844 dev_file_info = comedi_get_device_file_info(minor); 857 if (ret < 0)
858 comedi_free_board_minor(minor);
859 return ret;
860}
861
862static int comedi_auto_config_wrapper(struct comedi_device *dev, void *context)
863{
864 struct comedi_devconfig *it = context;
865 struct comedi_driver *driv = dev->driver;
866
867 if (driv->num_names) {
868 /* look for generic board entry matching driver name, which
869 * has already been copied to it->board_name */
870 dev->board_ptr = comedi_recognize(driv, it->board_name);
871 if (dev->board_ptr == NULL) {
872 printk(KERN_WARNING
873 "comedi: auto config failed to find board entry"
874 " '%s' for driver '%s'\n", it->board_name,
875 driv->driver_name);
876 comedi_report_boards(driv);
877 return -EINVAL;
878 }
879 }
880 return driv->attach(dev, it);
881}
882
883static int comedi_auto_config(struct device *hardware_device,
884 struct comedi_driver *driver, const int *options,
885 unsigned num_options)
886{
887 struct comedi_devconfig it;
845 888
846 memset(&it, 0, sizeof(it)); 889 memset(&it, 0, sizeof(it));
847 strncpy(it.board_name, board_name, COMEDI_NAMELEN); 890 strncpy(it.board_name, driver->driver_name, COMEDI_NAMELEN);
848 it.board_name[COMEDI_NAMELEN - 1] = '\0'; 891 it.board_name[COMEDI_NAMELEN - 1] = '\0';
849 BUG_ON(num_options > COMEDI_NDEVCONFOPTS); 892 BUG_ON(num_options > COMEDI_NDEVCONFOPTS);
850 memcpy(it.options, options, num_options * sizeof(int)); 893 memcpy(it.options, options, num_options * sizeof(int));
851 894 return comedi_auto_config_helper(hardware_device, driver,
852 mutex_lock(&dev_file_info->device->mutex); 895 comedi_auto_config_wrapper, &it);
853 retval = comedi_device_attach(dev_file_info->device, &it);
854 mutex_unlock(&dev_file_info->device->mutex);
855
856cleanup:
857 if (retval < 0) {
858 kfree(private_data);
859 comedi_free_board_minor(minor);
860 }
861 return retval;
862} 896}
863 897
864static void comedi_auto_unconfig(struct device *hardware_device) 898static void comedi_auto_unconfig(struct device *hardware_device)
865{ 899{
866 unsigned *minor = (unsigned *)dev_get_drvdata(hardware_device); 900 int minor;
867 if (minor == NULL)
868 return;
869
870 BUG_ON(*minor >= COMEDI_NUM_BOARD_MINORS);
871 901
872 comedi_free_board_minor(*minor); 902 if (hardware_device == NULL)
873 dev_set_drvdata(hardware_device, NULL); 903 return;
874 kfree(minor); 904 minor = comedi_find_board_minor(hardware_device);
905 if (minor < 0)
906 return;
907 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
908 comedi_free_board_minor(minor);
875} 909}
876 910
877int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name) 911static int comedi_old_pci_auto_config(struct pci_dev *pcidev,
912 struct comedi_driver *driver)
878{ 913{
879 int options[2]; 914 int options[2];
880 915
@@ -883,9 +918,30 @@ int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name)
883 /* pci slot */ 918 /* pci slot */
884 options[1] = PCI_SLOT(pcidev->devfn); 919 options[1] = PCI_SLOT(pcidev->devfn);
885 920
886 return comedi_auto_config(&pcidev->dev, board_name, 921 return comedi_auto_config(&pcidev->dev, driver,
887 options, ARRAY_SIZE(options)); 922 options, ARRAY_SIZE(options));
888} 923}
924
925static int comedi_pci_attach_wrapper(struct comedi_device *dev, void *pcidev)
926{
927 return dev->driver->attach_pci(dev, pcidev);
928}
929
930static int comedi_new_pci_auto_config(struct pci_dev *pcidev,
931 struct comedi_driver *driver)
932{
933 return comedi_auto_config_helper(&pcidev->dev, driver,
934 comedi_pci_attach_wrapper, pcidev);
935}
936
937int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver)
938{
939
940 if (driver->attach_pci)
941 return comedi_new_pci_auto_config(pcidev, driver);
942 else
943 return comedi_old_pci_auto_config(pcidev, driver);
944}
889EXPORT_SYMBOL_GPL(comedi_pci_auto_config); 945EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
890 946
891void comedi_pci_auto_unconfig(struct pci_dev *pcidev) 947void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
@@ -894,16 +950,96 @@ void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
894} 950}
895EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); 951EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
896 952
897int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name) 953int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
954 struct pci_driver *pci_driver)
955{
956 int ret;
957
958 ret = comedi_driver_register(comedi_driver);
959 if (ret < 0)
960 return ret;
961
962 /* FIXME: Remove this test after auditing all comedi pci drivers */
963 if (!pci_driver->name)
964 pci_driver->name = comedi_driver->driver_name;
965
966 ret = pci_register_driver(pci_driver);
967 if (ret < 0) {
968 comedi_driver_unregister(comedi_driver);
969 return ret;
970 }
971
972 return 0;
973}
974EXPORT_SYMBOL_GPL(comedi_pci_driver_register);
975
976void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
977 struct pci_driver *pci_driver)
978{
979 pci_unregister_driver(pci_driver);
980 comedi_driver_unregister(comedi_driver);
981}
982EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);
983
984static int comedi_old_usb_auto_config(struct usb_interface *intf,
985 struct comedi_driver *driver)
986{
987 return comedi_auto_config(&intf->dev, driver, NULL, 0);
988}
989
990static int comedi_usb_attach_wrapper(struct comedi_device *dev, void *intf)
991{
992 return dev->driver->attach_usb(dev, intf);
993}
994
995static int comedi_new_usb_auto_config(struct usb_interface *intf,
996 struct comedi_driver *driver)
997{
998 return comedi_auto_config_helper(&intf->dev, driver,
999 comedi_usb_attach_wrapper, intf);
1000}
1001
1002int comedi_usb_auto_config(struct usb_interface *intf,
1003 struct comedi_driver *driver)
898{ 1004{
899 BUG_ON(usbdev == NULL); 1005 BUG_ON(intf == NULL);
900 return comedi_auto_config(&usbdev->dev, board_name, NULL, 0); 1006 if (driver->attach_usb)
1007 return comedi_new_usb_auto_config(intf, driver);
1008 else
1009 return comedi_old_usb_auto_config(intf, driver);
901} 1010}
902EXPORT_SYMBOL_GPL(comedi_usb_auto_config); 1011EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
903 1012
904void comedi_usb_auto_unconfig(struct usb_device *usbdev) 1013void comedi_usb_auto_unconfig(struct usb_interface *intf)
905{ 1014{
906 BUG_ON(usbdev == NULL); 1015 BUG_ON(intf == NULL);
907 comedi_auto_unconfig(&usbdev->dev); 1016 comedi_auto_unconfig(&intf->dev);
908} 1017}
909EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); 1018EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
1019
1020int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
1021 struct usb_driver *usb_driver)
1022{
1023 int ret;
1024
1025 ret = comedi_driver_register(comedi_driver);
1026 if (ret < 0)
1027 return ret;
1028
1029 ret = usb_register(usb_driver);
1030 if (ret < 0) {
1031 comedi_driver_unregister(comedi_driver);
1032 return ret;
1033 }
1034
1035 return 0;
1036}
1037EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
1038
1039void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
1040 struct usb_driver *usb_driver)
1041{
1042 usb_deregister(usb_driver);
1043 comedi_driver_unregister(comedi_driver);
1044}
1045EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c
index 6c26ac887eee..27e39e4eb6b3 100644
--- a/drivers/staging/comedi/drivers/8255.c
+++ b/drivers/staging/comedi/drivers/8255.c
@@ -107,31 +107,6 @@ struct subdev_8255_struct {
107#define CALLBACK_FUNC (((struct subdev_8255_struct *)s->private)->cb_func) 107#define CALLBACK_FUNC (((struct subdev_8255_struct *)s->private)->cb_func)
108#define subdevpriv ((struct subdev_8255_struct *)s->private) 108#define subdevpriv ((struct subdev_8255_struct *)s->private)
109 109
110static int dev_8255_attach(struct comedi_device *dev,
111 struct comedi_devconfig *it);
112static int dev_8255_detach(struct comedi_device *dev);
113static struct comedi_driver driver_8255 = {
114 .driver_name = "8255",
115 .module = THIS_MODULE,
116 .attach = dev_8255_attach,
117 .detach = dev_8255_detach,
118};
119
120static int __init driver_8255_init_module(void)
121{
122 return comedi_driver_register(&driver_8255);
123}
124
125static void __exit driver_8255_cleanup_module(void)
126{
127 comedi_driver_unregister(&driver_8255);
128}
129
130module_init(driver_8255_init_module);
131module_exit(driver_8255_cleanup_module);
132
133static void do_config(struct comedi_device *dev, struct comedi_subdevice *s);
134
135void subdev_8255_interrupt(struct comedi_device *dev, 110void subdev_8255_interrupt(struct comedi_device *dev,
136 struct comedi_subdevice *s) 111 struct comedi_subdevice *s)
137{ 112{
@@ -185,6 +160,23 @@ static int subdev_8255_insn(struct comedi_device *dev,
185 return 2; 160 return 2;
186} 161}
187 162
163static void do_config(struct comedi_device *dev, struct comedi_subdevice *s)
164{
165 int config;
166
167 config = CR_CW;
168 /* 1 in io_bits indicates output, 1 in config indicates input */
169 if (!(s->io_bits & 0x0000ff))
170 config |= CR_A_IO;
171 if (!(s->io_bits & 0x00ff00))
172 config |= CR_B_IO;
173 if (!(s->io_bits & 0x0f0000))
174 config |= CR_C_LO_IO;
175 if (!(s->io_bits & 0xf00000))
176 config |= CR_C_HI_IO;
177 CALLBACK_FUNC(1, _8255_CR, config, CALLBACK_ARG);
178}
179
188static int subdev_8255_insn_config(struct comedi_device *dev, 180static int subdev_8255_insn_config(struct comedi_device *dev,
189 struct comedi_subdevice *s, 181 struct comedi_subdevice *s,
190 struct comedi_insn *insn, unsigned int *data) 182 struct comedi_insn *insn, unsigned int *data)
@@ -222,23 +214,6 @@ static int subdev_8255_insn_config(struct comedi_device *dev,
222 return 1; 214 return 1;
223} 215}
224 216
225static void do_config(struct comedi_device *dev, struct comedi_subdevice *s)
226{
227 int config;
228
229 config = CR_CW;
230 /* 1 in io_bits indicates output, 1 in config indicates input */
231 if (!(s->io_bits & 0x0000ff))
232 config |= CR_A_IO;
233 if (!(s->io_bits & 0x00ff00))
234 config |= CR_B_IO;
235 if (!(s->io_bits & 0x0f0000))
236 config |= CR_C_LO_IO;
237 if (!(s->io_bits & 0xf00000))
238 config |= CR_C_HI_IO;
239 CALLBACK_FUNC(1, _8255_CR, config, CALLBACK_ARG);
240}
241
242static int subdev_8255_cmdtest(struct comedi_device *dev, 217static int subdev_8255_cmdtest(struct comedi_device *dev,
243 struct comedi_subdevice *s, 218 struct comedi_subdevice *s,
244 struct comedi_cmd *cmd) 219 struct comedi_cmd *cmd)
@@ -442,14 +417,12 @@ static int dev_8255_attach(struct comedi_device *dev,
442 return 0; 417 return 0;
443} 418}
444 419
445static int dev_8255_detach(struct comedi_device *dev) 420static void dev_8255_detach(struct comedi_device *dev)
446{ 421{
447 int i; 422 int i;
448 unsigned long iobase; 423 unsigned long iobase;
449 struct comedi_subdevice *s; 424 struct comedi_subdevice *s;
450 425
451 printk(KERN_INFO "comedi%d: 8255: remove\n", dev->minor);
452
453 for (i = 0; i < dev->n_subdevices; i++) { 426 for (i = 0; i < dev->n_subdevices; i++) {
454 s = dev->subdevices + i; 427 s = dev->subdevices + i;
455 if (s->type != COMEDI_SUBD_UNUSED) { 428 if (s->type != COMEDI_SUBD_UNUSED) {
@@ -458,10 +431,16 @@ static int dev_8255_detach(struct comedi_device *dev)
458 } 431 }
459 subdev_8255_cleanup(dev, s); 432 subdev_8255_cleanup(dev, s);
460 } 433 }
461
462 return 0;
463} 434}
464 435
436static struct comedi_driver dev_8255_driver = {
437 .driver_name = "8255",
438 .module = THIS_MODULE,
439 .attach = dev_8255_attach,
440 .detach = dev_8255_detach,
441};
442module_comedi_driver(dev_8255_driver);
443
465MODULE_AUTHOR("Comedi http://www.comedi.org"); 444MODULE_AUTHOR("Comedi http://www.comedi.org");
466MODULE_DESCRIPTION("Comedi low-level driver"); 445MODULE_DESCRIPTION("Comedi low-level driver");
467MODULE_LICENSE("GPL"); 446MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/acl7225b.c b/drivers/staging/comedi/drivers/acl7225b.c
index 9def2250bb80..4e4fc418655f 100644
--- a/drivers/staging/comedi/drivers/acl7225b.c
+++ b/drivers/staging/comedi/drivers/acl7225b.c
@@ -22,46 +22,13 @@ Devices: [Adlink] ACL-7225b (acl7225b), [ICP] P16R16DIO (p16r16dio)
22#define ACL7225_DI_LO 2 /* Digital input low byte (DI0-DI7) */ 22#define ACL7225_DI_LO 2 /* Digital input low byte (DI0-DI7) */
23#define ACL7225_DI_HI 3 /* Digital input high byte (DI8-DI15) */ 23#define ACL7225_DI_HI 3 /* Digital input high byte (DI8-DI15) */
24 24
25static int acl7225b_attach(struct comedi_device *dev,
26 struct comedi_devconfig *it);
27static int acl7225b_detach(struct comedi_device *dev);
28
29struct boardtype { 25struct boardtype {
30 const char *name; /* driver name */ 26 const char *name; /* driver name */
31 int io_range; /* len of I/O space */ 27 int io_range; /* len of I/O space */
32}; 28};
33 29
34static const struct boardtype boardtypes[] = {
35 {"acl7225b", ACL7225_SIZE,},
36 {"p16r16dio", P16R16DIO_SIZE,},
37};
38
39#define n_boardtypes (sizeof(boardtypes)/sizeof(struct boardtype))
40#define this_board ((const struct boardtype *)dev->board_ptr) 30#define this_board ((const struct boardtype *)dev->board_ptr)
41 31
42static struct comedi_driver driver_acl7225b = {
43 .driver_name = "acl7225b",
44 .module = THIS_MODULE,
45 .attach = acl7225b_attach,
46 .detach = acl7225b_detach,
47 .board_name = &boardtypes[0].name,
48 .num_names = n_boardtypes,
49 .offset = sizeof(struct boardtype),
50};
51
52static int __init driver_acl7225b_init_module(void)
53{
54 return comedi_driver_register(&driver_acl7225b);
55}
56
57static void __exit driver_acl7225b_cleanup_module(void)
58{
59 comedi_driver_unregister(&driver_acl7225b);
60}
61
62module_init(driver_acl7225b_init_module);
63module_exit(driver_acl7225b_cleanup_module);
64
65static int acl7225b_do_insn(struct comedi_device *dev, 32static int acl7225b_do_insn(struct comedi_device *dev,
66 struct comedi_subdevice *s, 33 struct comedi_subdevice *s,
67 struct comedi_insn *insn, unsigned int *data) 34 struct comedi_insn *insn, unsigned int *data)
@@ -152,16 +119,28 @@ static int acl7225b_attach(struct comedi_device *dev,
152 return 0; 119 return 0;
153} 120}
154 121
155static int acl7225b_detach(struct comedi_device *dev) 122static void acl7225b_detach(struct comedi_device *dev)
156{ 123{
157 printk(KERN_INFO "comedi%d: acl7225b: remove\n", dev->minor);
158
159 if (dev->iobase) 124 if (dev->iobase)
160 release_region(dev->iobase, this_board->io_range); 125 release_region(dev->iobase, this_board->io_range);
161
162 return 0;
163} 126}
164 127
128static const struct boardtype boardtypes[] = {
129 { "acl7225b", ACL7225_SIZE, },
130 { "p16r16dio", P16R16DIO_SIZE, },
131};
132
133static struct comedi_driver acl7225b_driver = {
134 .driver_name = "acl7225b",
135 .module = THIS_MODULE,
136 .attach = acl7225b_attach,
137 .detach = acl7225b_detach,
138 .board_name = &boardtypes[0].name,
139 .num_names = ARRAY_SIZE(boardtypes),
140 .offset = sizeof(struct boardtype),
141};
142module_comedi_driver(acl7225b_driver);
143
165MODULE_AUTHOR("Comedi http://www.comedi.org"); 144MODULE_AUTHOR("Comedi http://www.comedi.org");
166MODULE_DESCRIPTION("Comedi low-level driver"); 145MODULE_DESCRIPTION("Comedi low-level driver");
167MODULE_LICENSE("GPL"); 146MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c
index ca5bd9b8704a..44aaf8351ba3 100644
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.c
+++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c
@@ -224,2318 +224,1213 @@ MODULE_DEVICE_TABLE(pci, addi_apci_tbl);
224 224
225static const struct addi_board boardtypes[] = { 225static const struct addi_board boardtypes[] = {
226#ifdef CONFIG_APCI_3120 226#ifdef CONFIG_APCI_3120
227 {"apci3120", 227 {
228 APCI3120_BOARD_VENDOR_ID, 228 .pc_DriverName = "apci3120",
229 0x818D, 229 .i_VendorId = APCI3120_BOARD_VENDOR_ID,
230 AMCC_OP_REG_SIZE, 230 .i_DeviceId = 0x818D,
231 APCI3120_ADDRESS_RANGE, 231 .i_IorangeBase0 = AMCC_OP_REG_SIZE,
232 8, 232 .i_IorangeBase1 = APCI3120_ADDRESS_RANGE,
233 0, 233 .i_IorangeBase2 = 8,
234 ADDIDATA_NO_EEPROM, 234 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
235 NULL, 235 .i_NbrAiChannel = 16,
236 16, 236 .i_NbrAiChannelDiff = 8,
237 8, 237 .i_AiChannelList = 16,
238 16, 238 .i_NbrAoChannel = 8,
239 8, 239 .i_AiMaxdata = 0xffff,
240 0xffff, 240 .i_AoMaxdata = 0x3fff,
241 0x3fff, 241 .pr_AiRangelist = &range_apci3120_ai,
242 &range_apci3120_ai, 242 .pr_AoRangelist = &range_apci3120_ao,
243 &range_apci3120_ao, 243 .i_NbrDiChannel = 4,
244 4, 244 .i_NbrDoChannel = 4,
245 4, 245 .i_DoMaxdata = 0x0f,
246 0x0f, 246 .i_Dma = 1,
247 0, 247 .i_Timer = 1,
248 NULL, 248 .b_AvailableConvertUnit = 1,
249 1, 249 .ui_MinAcquisitiontimeNs = 10000,
250 1, 250 .ui_MinDelaytimeNs = 100000,
251 1, 251 .interrupt = v_APCI3120_Interrupt,
252 10000, 252 .reset = i_APCI3120_Reset,
253 100000, 253 .ai_config = i_APCI3120_InsnConfigAnalogInput,
254 v_APCI3120_Interrupt, 254 .ai_read = i_APCI3120_InsnReadAnalogInput,
255 i_APCI3120_Reset, 255 .ai_cmdtest = i_APCI3120_CommandTestAnalogInput,
256 i_APCI3120_InsnConfigAnalogInput, 256 .ai_cmd = i_APCI3120_CommandAnalogInput,
257 i_APCI3120_InsnReadAnalogInput, 257 .ai_cancel = i_APCI3120_StopCyclicAcquisition,
258 NULL, 258 .ao_write = i_APCI3120_InsnWriteAnalogOutput,
259 NULL, 259 .di_read = i_APCI3120_InsnReadDigitalInput,
260 i_APCI3120_CommandTestAnalogInput, 260 .di_bits = i_APCI3120_InsnBitsDigitalInput,
261 i_APCI3120_CommandAnalogInput, 261 .do_config = i_APCI3120_InsnConfigDigitalOutput,
262 i_APCI3120_StopCyclicAcquisition, 262 .do_write = i_APCI3120_InsnWriteDigitalOutput,
263 NULL, 263 .do_bits = i_APCI3120_InsnBitsDigitalOutput,
264 i_APCI3120_InsnWriteAnalogOutput, 264 .timer_config = i_APCI3120_InsnConfigTimer,
265 NULL, 265 .timer_write = i_APCI3120_InsnWriteTimer,
266 NULL, 266 .timer_read = i_APCI3120_InsnReadTimer,
267 i_APCI3120_InsnReadDigitalInput, 267 },
268 NULL,
269 i_APCI3120_InsnBitsDigitalInput,
270 i_APCI3120_InsnConfigDigitalOutput,
271 i_APCI3120_InsnWriteDigitalOutput,
272 i_APCI3120_InsnBitsDigitalOutput,
273 NULL,
274 i_APCI3120_InsnConfigTimer,
275 i_APCI3120_InsnWriteTimer,
276 i_APCI3120_InsnReadTimer,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL},
282#endif 268#endif
283#ifdef CONFIG_APCI_1032 269#ifdef CONFIG_APCI_1032
284 {"apci1032", 270 {
285 APCI1032_BOARD_VENDOR_ID, 271 .pc_DriverName = "apci1032",
286 0x1003, 272 .i_VendorId = APCI1032_BOARD_VENDOR_ID,
287 4, 273 .i_DeviceId = 0x1003,
288 APCI1032_ADDRESS_RANGE, 274 .i_IorangeBase0 = 4,
289 0, 275 .i_IorangeBase1 = APCI1032_ADDRESS_RANGE,
290 0, 276 .i_PCIEeprom = ADDIDATA_EEPROM,
291 ADDIDATA_EEPROM, 277 .pc_EepromChip = ADDIDATA_93C76,
292 ADDIDATA_93C76, 278 .i_NbrDiChannel = 32,
293 0, 279 .interrupt = v_APCI1032_Interrupt,
294 0, 280 .reset = i_APCI1032_Reset,
295 0, 281 .di_config = i_APCI1032_ConfigDigitalInput,
296 0, 282 .di_read = i_APCI1032_Read1DigitalInput,
297 0, 283 .di_bits = i_APCI1032_ReadMoreDigitalInput,
298 0, 284 },
299 NULL,
300 NULL,
301 32,
302 0,
303 0,
304 0,
305 NULL,
306 0,
307 0,
308 0,
309 0,
310 0,
311 v_APCI1032_Interrupt,
312 i_APCI1032_Reset,
313 NULL,
314 NULL,
315 NULL,
316 NULL,
317 NULL,
318 NULL,
319 NULL,
320 NULL,
321 NULL,
322 NULL,
323 i_APCI1032_ConfigDigitalInput,
324 i_APCI1032_Read1DigitalInput,
325 NULL,
326 i_APCI1032_ReadMoreDigitalInput,
327 NULL,
328 NULL,
329 NULL,
330 NULL,
331 NULL,
332 NULL,
333 NULL,
334 NULL,
335 NULL,
336 NULL,
337 NULL,
338 NULL},
339#endif 285#endif
340#ifdef CONFIG_APCI_1516 286#ifdef CONFIG_APCI_1516
341 {"apci1516", 287 {
342 APCI1516_BOARD_VENDOR_ID, 288 .pc_DriverName = "apci1516",
343 0x1001, 289 .i_VendorId = APCI1516_BOARD_VENDOR_ID,
344 128, 290 .i_DeviceId = 0x1001,
345 APCI1516_ADDRESS_RANGE, 291 .i_IorangeBase0 = 128,
346 32, 292 .i_IorangeBase1 = APCI1516_ADDRESS_RANGE,
347 0, 293 .i_IorangeBase2 = 32,
348 ADDIDATA_EEPROM, 294 .i_PCIEeprom = ADDIDATA_EEPROM,
349 ADDIDATA_S5920, 295 .pc_EepromChip = ADDIDATA_S5920,
350 0, 296 .i_NbrDiChannel = 8,
351 0, 297 .i_NbrDoChannel = 8,
352 0, 298 .i_Timer = 1,
353 0, 299 .reset = i_APCI1516_Reset,
354 0, 300 .di_read = i_APCI1516_Read1DigitalInput,
355 0, 301 .di_bits = i_APCI1516_ReadMoreDigitalInput,
356 NULL, 302 .do_config = i_APCI1516_ConfigDigitalOutput,
357 NULL, 303 .do_write = i_APCI1516_WriteDigitalOutput,
358 8, 304 .do_bits = i_APCI1516_ReadDigitalOutput,
359 8, 305 .timer_config = i_APCI1516_ConfigWatchdog,
360 0, 306 .timer_write = i_APCI1516_StartStopWriteWatchdog,
361 0, 307 .timer_read = i_APCI1516_ReadWatchdog,
362 NULL, 308 },
363 0,
364 1,
365 0,
366 0,
367 0,
368 NULL,
369 i_APCI1516_Reset,
370 NULL, NULL,
371 NULL,
372 NULL,
373 NULL,
374 NULL,
375 NULL,
376 NULL,
377 NULL,
378 NULL,
379 NULL,
380 i_APCI1516_Read1DigitalInput,
381 NULL,
382 i_APCI1516_ReadMoreDigitalInput,
383 i_APCI1516_ConfigDigitalOutput,
384 i_APCI1516_WriteDigitalOutput,
385 i_APCI1516_ReadDigitalOutput,
386 NULL,
387 i_APCI1516_ConfigWatchdog,
388 i_APCI1516_StartStopWriteWatchdog,
389 i_APCI1516_ReadWatchdog,
390 NULL,
391 NULL,
392 NULL,
393 NULL,
394 NULL},
395#endif 309#endif
396#ifdef CONFIG_APCI_2016 310#ifdef CONFIG_APCI_2016
397 {"apci2016", 311 {
398 APCI2016_BOARD_VENDOR_ID, 312 .pc_DriverName = "apci2016",
399 0x1002, 313 .i_VendorId = APCI2016_BOARD_VENDOR_ID,
400 128, 314 .i_DeviceId = 0x1002,
401 APCI2016_ADDRESS_RANGE, 315 .i_IorangeBase0 = 128,
402 32, 316 .i_IorangeBase1 = APCI2016_ADDRESS_RANGE,
403 0, 317 .i_IorangeBase2 = 32,
404 ADDIDATA_EEPROM, 318 .i_PCIEeprom = ADDIDATA_EEPROM,
405 ADDIDATA_S5920, 319 .pc_EepromChip = ADDIDATA_S5920,
406 0, 320 .i_NbrDoChannel = 16,
407 0, 321 .i_Timer = 1,
408 0, 322 .reset = i_APCI2016_Reset,
409 0, 323 .do_config = i_APCI2016_ConfigDigitalOutput,
410 0, 324 .do_write = i_APCI2016_WriteDigitalOutput,
411 0, 325 .do_bits = i_APCI2016_BitsDigitalOutput,
412 NULL, 326 .timer_config = i_APCI2016_ConfigWatchdog,
413 NULL, 327 .timer_write = i_APCI2016_StartStopWriteWatchdog,
414 0, 328 .timer_read = i_APCI2016_ReadWatchdog,
415 16, 329 },
416 0,
417 0,
418 NULL,
419 0,
420 1,
421 0,
422 0,
423 0,
424 NULL,
425 i_APCI2016_Reset,
426 NULL,
427 NULL,
428 NULL,
429 NULL,
430 NULL,
431 NULL,
432 NULL,
433 NULL,
434 NULL,
435 NULL,
436 NULL,
437 NULL,
438 NULL,
439 NULL,
440 i_APCI2016_ConfigDigitalOutput,
441 i_APCI2016_WriteDigitalOutput,
442 i_APCI2016_BitsDigitalOutput,
443 NULL,
444 i_APCI2016_ConfigWatchdog,
445 i_APCI2016_StartStopWriteWatchdog,
446 i_APCI2016_ReadWatchdog,
447 NULL,
448 NULL,
449 NULL,
450 NULL,
451 NULL},
452#endif 330#endif
453#ifdef CONFIG_APCI_2032 331#ifdef CONFIG_APCI_2032
454 {"apci2032", 332 {
455 APCI2032_BOARD_VENDOR_ID, 333 .pc_DriverName = "apci2032",
456 0x1004, 334 .i_VendorId = APCI2032_BOARD_VENDOR_ID,
457 4, 335 .i_DeviceId = 0x1004,
458 APCI2032_ADDRESS_RANGE, 336 .i_IorangeBase0 = 4,
459 0, 337 .i_IorangeBase1 = APCI2032_ADDRESS_RANGE,
460 0, 338 .i_PCIEeprom = ADDIDATA_EEPROM,
461 ADDIDATA_EEPROM, 339 .pc_EepromChip = ADDIDATA_93C76,
462 ADDIDATA_93C76, 340 .i_NbrDoChannel = 32,
463 0, 341 .i_DoMaxdata = 0xffffffff,
464 0, 342 .i_Timer = 1,
465 0, 343 .interrupt = v_APCI2032_Interrupt,
466 0, 344 .reset = i_APCI2032_Reset,
467 0, 345 .do_config = i_APCI2032_ConfigDigitalOutput,
468 0, 346 .do_write = i_APCI2032_WriteDigitalOutput,
469 NULL, 347 .do_bits = i_APCI2032_ReadDigitalOutput,
470 NULL, 348 .do_read = i_APCI2032_ReadInterruptStatus,
471 0, 349 .timer_config = i_APCI2032_ConfigWatchdog,
472 32, 350 .timer_write = i_APCI2032_StartStopWriteWatchdog,
473 0xffffffff, 351 .timer_read = i_APCI2032_ReadWatchdog,
474 0, 352 },
475 NULL,
476 0,
477 1,
478 0,
479 0,
480 0,
481 v_APCI2032_Interrupt,
482 i_APCI2032_Reset,
483 NULL, NULL,
484 NULL,
485 NULL,
486 NULL,
487 NULL,
488 NULL,
489 NULL,
490 NULL,
491 NULL,
492 NULL,
493 NULL,
494 NULL,
495 NULL,
496 i_APCI2032_ConfigDigitalOutput,
497 i_APCI2032_WriteDigitalOutput,
498 i_APCI2032_ReadDigitalOutput,
499 i_APCI2032_ReadInterruptStatus,
500 i_APCI2032_ConfigWatchdog,
501 i_APCI2032_StartStopWriteWatchdog,
502 i_APCI2032_ReadWatchdog,
503 NULL,
504 NULL,
505 NULL,
506 NULL,
507 NULL},
508#endif 353#endif
509#ifdef CONFIG_APCI_2200 354#ifdef CONFIG_APCI_2200
510 {"apci2200", 355 {
511 APCI2200_BOARD_VENDOR_ID, 356 .pc_DriverName = "apci2200",
512 0x1005, 357 .i_VendorId = APCI2200_BOARD_VENDOR_ID,
513 4, 358 .i_DeviceId = 0x1005,
514 APCI2200_ADDRESS_RANGE, 359 .i_IorangeBase0 = 4,
515 0, 360 .i_IorangeBase1 = APCI2200_ADDRESS_RANGE,
516 0, 361 .i_PCIEeprom = ADDIDATA_EEPROM,
517 ADDIDATA_EEPROM, 362 .pc_EepromChip = ADDIDATA_93C76,
518 ADDIDATA_93C76, 363 .i_NbrDiChannel = 8,
519 0, 364 .i_NbrDoChannel = 16,
520 0, 365 .i_Timer = 1,
521 0, 366 .reset = i_APCI2200_Reset,
522 0, 367 .di_read = i_APCI2200_Read1DigitalInput,
523 0, 368 .di_bits = i_APCI2200_ReadMoreDigitalInput,
524 0, 369 .do_config = i_APCI2200_ConfigDigitalOutput,
525 NULL, 370 .do_write = i_APCI2200_WriteDigitalOutput,
526 NULL, 371 .do_bits = i_APCI2200_ReadDigitalOutput,
527 8, 372 .timer_config = i_APCI2200_ConfigWatchdog,
528 16, 373 .timer_write = i_APCI2200_StartStopWriteWatchdog,
529 0, 374 .timer_read = i_APCI2200_ReadWatchdog,
530 0, 375 },
531 NULL,
532 0,
533 1,
534 0,
535 0,
536 0,
537 NULL,
538 i_APCI2200_Reset,
539 NULL, NULL,
540 NULL,
541 NULL,
542 NULL,
543 NULL,
544 NULL,
545 NULL,
546 NULL,
547 NULL,
548 NULL,
549 i_APCI2200_Read1DigitalInput,
550 NULL,
551 i_APCI2200_ReadMoreDigitalInput,
552 i_APCI2200_ConfigDigitalOutput,
553 i_APCI2200_WriteDigitalOutput,
554 i_APCI2200_ReadDigitalOutput,
555 NULL,
556 i_APCI2200_ConfigWatchdog,
557 i_APCI2200_StartStopWriteWatchdog,
558 i_APCI2200_ReadWatchdog,
559 NULL,
560 NULL,
561 NULL,
562 NULL,
563 NULL},
564#endif 376#endif
565#ifdef CONFIG_APCI_1564 377#ifdef CONFIG_APCI_1564
566 {"apci1564", 378 {
567 APCI1564_BOARD_VENDOR_ID, 379 .pc_DriverName = "apci1564",
568 0x1006, 380 .i_VendorId = APCI1564_BOARD_VENDOR_ID,
569 128, 381 .i_DeviceId = 0x1006,
570 APCI1564_ADDRESS_RANGE, 382 .i_IorangeBase0 = 128,
571 0, 383 .i_IorangeBase1 = APCI1564_ADDRESS_RANGE,
572 0, 384 .i_PCIEeprom = ADDIDATA_EEPROM,
573 ADDIDATA_EEPROM, 385 .pc_EepromChip = ADDIDATA_93C76,
574 ADDIDATA_93C76, 386 .i_NbrDiChannel = 32,
575 0, 387 .i_NbrDoChannel = 32,
576 0, 388 .i_DoMaxdata = 0xffffffff,
577 0, 389 .i_Timer = 1,
578 0, 390 .interrupt = v_APCI1564_Interrupt,
579 0, 391 .reset = i_APCI1564_Reset,
580 0, 392 .di_config = i_APCI1564_ConfigDigitalInput,
581 NULL, 393 .di_read = i_APCI1564_Read1DigitalInput,
582 NULL, 394 .di_bits = i_APCI1564_ReadMoreDigitalInput,
583 32, 395 .do_config = i_APCI1564_ConfigDigitalOutput,
584 32, 396 .do_write = i_APCI1564_WriteDigitalOutput,
585 0xffffffff, 397 .do_bits = i_APCI1564_ReadDigitalOutput,
586 0, 398 .do_read = i_APCI1564_ReadInterruptStatus,
587 NULL, 399 .timer_config = i_APCI1564_ConfigTimerCounterWatchdog,
588 0, 400 .timer_write = i_APCI1564_StartStopWriteTimerCounterWatchdog,
589 1, 401 .timer_read = i_APCI1564_ReadTimerCounterWatchdog,
590 0, 402 },
591 0,
592 0,
593 v_APCI1564_Interrupt,
594 i_APCI1564_Reset,
595 NULL,
596 NULL,
597 NULL,
598 NULL,
599 NULL,
600 NULL,
601 NULL,
602 NULL,
603 NULL,
604 NULL,
605 i_APCI1564_ConfigDigitalInput,
606 i_APCI1564_Read1DigitalInput,
607 NULL,
608 i_APCI1564_ReadMoreDigitalInput,
609 i_APCI1564_ConfigDigitalOutput,
610 i_APCI1564_WriteDigitalOutput,
611 i_APCI1564_ReadDigitalOutput,
612 i_APCI1564_ReadInterruptStatus,
613 i_APCI1564_ConfigTimerCounterWatchdog,
614 i_APCI1564_StartStopWriteTimerCounterWatchdog,
615 i_APCI1564_ReadTimerCounterWatchdog,
616 NULL,
617 NULL,
618 NULL,
619 NULL,
620 NULL},
621#endif 403#endif
622#ifdef CONFIG_APCI_1500 404#ifdef CONFIG_APCI_1500
623 {"apci1500", 405 {
624 APCI1500_BOARD_VENDOR_ID, 406 .pc_DriverName = "apci1500",
625 0x80fc, 407 .i_VendorId = APCI1500_BOARD_VENDOR_ID,
626 128, 408 .i_DeviceId = 0x80fc,
627 APCI1500_ADDRESS_RANGE, 409 .i_IorangeBase0 = 128,
628 4, 410 .i_IorangeBase1 = APCI1500_ADDRESS_RANGE,
629 0, 411 .i_IorangeBase2 = 4,
630 ADDIDATA_NO_EEPROM, 412 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
631 NULL, 413 .i_NbrDiChannel = 16,
632 0, 414 .i_NbrDoChannel = 16,
633 0, 415 .i_DoMaxdata = 0xffff,
634 0, 416 .i_Timer = 1,
635 0, 417 .interrupt = v_APCI1500_Interrupt,
636 0, 418 .reset = i_APCI1500_Reset,
637 0, 419 .di_config = i_APCI1500_ConfigDigitalInputEvent,
638 NULL, 420 .di_read = i_APCI1500_Initialisation,
639 NULL, 421 .di_write = i_APCI1500_StartStopInputEvent,
640 16, 422 .di_bits = i_APCI1500_ReadMoreDigitalInput,
641 16, 423 .do_config = i_APCI1500_ConfigDigitalOutputErrorInterrupt,
642 0xffff, 424 .do_write = i_APCI1500_WriteDigitalOutput,
643 0, 425 .do_bits = i_APCI1500_ConfigureInterrupt,
644 NULL, 426 .timer_config = i_APCI1500_ConfigCounterTimerWatchdog,
645 0, 427 .timer_write = i_APCI1500_StartStopTriggerTimerCounterWatchdog,
646 1, 428 .timer_read = i_APCI1500_ReadInterruptMask,
647 0, 429 .timer_bits = i_APCI1500_ReadCounterTimerWatchdog,
648 0, 430 },
649 0,
650 v_APCI1500_Interrupt,
651 i_APCI1500_Reset,
652 NULL,
653 NULL,
654 NULL,
655 NULL,
656 NULL,
657 NULL,
658 NULL,
659 NULL,
660 NULL,
661 NULL,
662 i_APCI1500_ConfigDigitalInputEvent,
663 i_APCI1500_Initialisation,
664 i_APCI1500_StartStopInputEvent,
665 i_APCI1500_ReadMoreDigitalInput,
666 i_APCI1500_ConfigDigitalOutputErrorInterrupt,
667 i_APCI1500_WriteDigitalOutput,
668 i_APCI1500_ConfigureInterrupt,
669 NULL,
670 i_APCI1500_ConfigCounterTimerWatchdog,
671 i_APCI1500_StartStopTriggerTimerCounterWatchdog,
672 i_APCI1500_ReadInterruptMask,
673 i_APCI1500_ReadCounterTimerWatchdog,
674 NULL,
675 NULL,
676 NULL,
677 NULL},
678#endif 431#endif
679#ifdef CONFIG_APCI_3001 432#ifdef CONFIG_APCI_3001
680 {"apci3001", 433 {
681 APCI3120_BOARD_VENDOR_ID, 434 .pc_DriverName = "apci3001",
682 0x828D, 435 .i_VendorId = APCI3120_BOARD_VENDOR_ID,
683 AMCC_OP_REG_SIZE, 436 .i_DeviceId = 0x828D,
684 APCI3120_ADDRESS_RANGE, 437 .i_IorangeBase0 = AMCC_OP_REG_SIZE,
685 8, 438 .i_IorangeBase1 = APCI3120_ADDRESS_RANGE,
686 0, 439 .i_IorangeBase2 = 8,
687 ADDIDATA_NO_EEPROM, 440 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
688 NULL, 441 .i_NbrAiChannel = 16,
689 16, 442 .i_NbrAiChannelDiff = 8,
690 8, 443 .i_AiChannelList = 16,
691 16, 444 .i_AiMaxdata = 0xfff,
692 0, 445 .pr_AiRangelist = &range_apci3120_ai,
693 0xfff, 446 .i_NbrDiChannel = 4,
694 0, 447 .i_NbrDoChannel = 4,
695 &range_apci3120_ai, 448 .i_DoMaxdata = 0x0f,
696 NULL, 449 .i_Dma = 1,
697 4, 450 .i_Timer = 1,
698 4, 451 .b_AvailableConvertUnit = 1,
699 0x0f, 452 .ui_MinAcquisitiontimeNs = 10000,
700 0, 453 .ui_MinDelaytimeNs = 100000,
701 NULL, 454 .interrupt = v_APCI3120_Interrupt,
702 1, 455 .reset = i_APCI3120_Reset,
703 1, 456 .ai_config = i_APCI3120_InsnConfigAnalogInput,
704 1, 457 .ai_read = i_APCI3120_InsnReadAnalogInput,
705 10000, 458 .ai_cmdtest = i_APCI3120_CommandTestAnalogInput,
706 100000, 459 .ai_cmd = i_APCI3120_CommandAnalogInput,
707 v_APCI3120_Interrupt, 460 .ai_cancel = i_APCI3120_StopCyclicAcquisition,
708 i_APCI3120_Reset, 461 .di_read = i_APCI3120_InsnReadDigitalInput,
709 i_APCI3120_InsnConfigAnalogInput, 462 .di_bits = i_APCI3120_InsnBitsDigitalInput,
710 i_APCI3120_InsnReadAnalogInput, 463 .do_config = i_APCI3120_InsnConfigDigitalOutput,
711 NULL, 464 .do_write = i_APCI3120_InsnWriteDigitalOutput,
712 NULL, 465 .do_bits = i_APCI3120_InsnBitsDigitalOutput,
713 i_APCI3120_CommandTestAnalogInput, 466 .timer_config = i_APCI3120_InsnConfigTimer,
714 i_APCI3120_CommandAnalogInput, 467 .timer_write = i_APCI3120_InsnWriteTimer,
715 i_APCI3120_StopCyclicAcquisition, 468 .timer_read = i_APCI3120_InsnReadTimer,
716 NULL, 469 },
717 NULL,
718 NULL,
719 NULL,
720 i_APCI3120_InsnReadDigitalInput,
721 NULL,
722 i_APCI3120_InsnBitsDigitalInput,
723 i_APCI3120_InsnConfigDigitalOutput,
724 i_APCI3120_InsnWriteDigitalOutput,
725 i_APCI3120_InsnBitsDigitalOutput,
726 NULL,
727 i_APCI3120_InsnConfigTimer,
728 i_APCI3120_InsnWriteTimer,
729 i_APCI3120_InsnReadTimer,
730 NULL,
731 NULL,
732 NULL,
733 NULL,
734 NULL},
735#endif 470#endif
736#ifdef CONFIG_APCI_3501 471#ifdef CONFIG_APCI_3501
737 {"apci3501", 472 {
738 APCI3501_BOARD_VENDOR_ID, 473 .pc_DriverName = "apci3501",
739 0x3001, 474 .i_VendorId = APCI3501_BOARD_VENDOR_ID,
740 64, 475 .i_DeviceId = 0x3001,
741 APCI3501_ADDRESS_RANGE, 476 .i_IorangeBase0 = 64,
742 0, 477 .i_IorangeBase1 = APCI3501_ADDRESS_RANGE,
743 0, 478 .i_PCIEeprom = ADDIDATA_EEPROM,
744 ADDIDATA_EEPROM, 479 .pc_EepromChip = ADDIDATA_S5933,
745 ADDIDATA_S5933, 480 .i_AoMaxdata = 16383,
746 0, 481 .pr_AoRangelist = &range_apci3501_ao,
747 0, 482 .i_NbrDiChannel = 2,
748 0, 483 .i_NbrDoChannel = 2,
749 8, 484 .i_DoMaxdata = 0x3,
750 0, 485 .i_Timer = 1,
751 16383, 486 .interrupt = v_APCI3501_Interrupt,
752 NULL, 487 .reset = i_APCI3501_Reset,
753 &range_apci3501_ao, 488 .ao_config = i_APCI3501_ConfigAnalogOutput,
754 2, 489 .ao_write = i_APCI3501_WriteAnalogOutput,
755 2, 490 .di_bits = i_APCI3501_ReadDigitalInput,
756 0x3, 491 .do_config = i_APCI3501_ConfigDigitalOutput,
757 0, 492 .do_write = i_APCI3501_WriteDigitalOutput,
758 NULL, 493 .do_bits = i_APCI3501_ReadDigitalOutput,
759 0, 494 .timer_config = i_APCI3501_ConfigTimerCounterWatchdog,
760 1, 495 .timer_write = i_APCI3501_StartStopWriteTimerCounterWatchdog,
761 0, 496 .timer_read = i_APCI3501_ReadTimerCounterWatchdog,
762 0, 497 },
763 0,
764 v_APCI3501_Interrupt,
765 i_APCI3501_Reset,
766 NULL, NULL,
767 NULL,
768 NULL,
769 NULL,
770 NULL,
771 NULL,
772 i_APCI3501_ConfigAnalogOutput,
773 i_APCI3501_WriteAnalogOutput,
774 NULL,
775 NULL,
776 NULL,
777 NULL,
778 i_APCI3501_ReadDigitalInput,
779 i_APCI3501_ConfigDigitalOutput,
780 i_APCI3501_WriteDigitalOutput,
781 i_APCI3501_ReadDigitalOutput,
782 NULL,
783 i_APCI3501_ConfigTimerCounterWatchdog,
784 i_APCI3501_StartStopWriteTimerCounterWatchdog,
785 i_APCI3501_ReadTimerCounterWatchdog,
786 NULL,
787 NULL,
788 NULL,
789 NULL,
790 NULL},
791#endif 498#endif
792#ifdef CONFIG_APCI_035 499#ifdef CONFIG_APCI_035
793 {"apci035", 500 {
794 APCI035_BOARD_VENDOR_ID, 501 .pc_DriverName = "apci035",
795 0x0300, 502 .i_VendorId = APCI035_BOARD_VENDOR_ID,
796 127, 503 .i_DeviceId = 0x0300,
797 APCI035_ADDRESS_RANGE, 504 .i_IorangeBase0 = 127,
798 0, 505 .i_IorangeBase1 = APCI035_ADDRESS_RANGE,
799 0, 506 .i_PCIEeprom = 1,
800 1, 507 .pc_EepromChip = ADDIDATA_S5920,
801 ADDIDATA_S5920, 508 .i_NbrAiChannel = 16,
802 16, 509 .i_NbrAiChannelDiff = 8,
803 8, 510 .i_AiChannelList = 16,
804 16, 511 .i_AiMaxdata = 0xff,
805 0, 512 .pr_AiRangelist = &range_apci035_ai,
806 0xff, 513 .i_Timer = 1,
807 0, 514 .ui_MinAcquisitiontimeNs = 10000,
808 &range_apci035_ai, 515 .ui_MinDelaytimeNs = 100000,
809 NULL, 516 .interrupt = v_APCI035_Interrupt,
810 0, 517 .reset = i_APCI035_Reset,
811 0, 518 .ai_config = i_APCI035_ConfigAnalogInput,
812 0, 519 .ai_read = i_APCI035_ReadAnalogInput,
813 0, 520 .timer_config = i_APCI035_ConfigTimerWatchdog,
814 NULL, 521 .timer_write = i_APCI035_StartStopWriteTimerWatchdog,
815 0, 522 .timer_read = i_APCI035_ReadTimerWatchdog,
816 1, 523 },
817 0,
818 10000,
819 100000,
820 v_APCI035_Interrupt,
821 i_APCI035_Reset,
822 i_APCI035_ConfigAnalogInput,
823 i_APCI035_ReadAnalogInput,
824 NULL,
825 NULL,
826 NULL,
827 NULL,
828 NULL,
829 NULL,
830 NULL,
831 NULL,
832 NULL,
833 NULL,
834 NULL,
835 NULL,
836 NULL,
837 NULL,
838 NULL,
839 NULL,
840 i_APCI035_ConfigTimerWatchdog,
841 i_APCI035_StartStopWriteTimerWatchdog,
842 i_APCI035_ReadTimerWatchdog,
843 NULL,
844 NULL,
845 NULL,
846 NULL,
847 NULL},
848#endif 524#endif
849#ifdef CONFIG_APCI_3200 525#ifdef CONFIG_APCI_3200
850 {"apci3200", 526 {
851 APCI3200_BOARD_VENDOR_ID, 527 .pc_DriverName = "apci3200",
852 0x3000, 528 .i_VendorId = APCI3200_BOARD_VENDOR_ID,
853 128, 529 .i_DeviceId = 0x3000,
854 256, 530 .i_IorangeBase0 = 128,
855 4, 531 .i_IorangeBase1 = 256,
856 4, 532 .i_IorangeBase2 = 4,
857 ADDIDATA_EEPROM, 533 .i_IorangeBase3 = 4,
858 ADDIDATA_S5920, 534 .i_PCIEeprom = ADDIDATA_EEPROM,
859 16, 535 .pc_EepromChip = ADDIDATA_S5920,
860 8, 536 .i_NbrAiChannel = 16,
861 16, 537 .i_NbrAiChannelDiff = 8,
862 0, 538 .i_AiChannelList = 16,
863 0x3ffff, 539 .i_AiMaxdata = 0x3ffff,
864 0, 540 .pr_AiRangelist = &range_apci3200_ai,
865 &range_apci3200_ai, 541 .i_NbrDiChannel = 4,
866 NULL, 542 .i_NbrDoChannel = 4,
867 4, 543 .ui_MinAcquisitiontimeNs = 10000,
868 4, 544 .ui_MinDelaytimeNs = 100000,
869 0, 545 .interrupt = v_APCI3200_Interrupt,
870 0, 546 .reset = i_APCI3200_Reset,
871 NULL, 547 .ai_config = i_APCI3200_ConfigAnalogInput,
872 0, 548 .ai_read = i_APCI3200_ReadAnalogInput,
873 0, 549 .ai_write = i_APCI3200_InsnWriteReleaseAnalogInput,
874 0, 550 .ai_bits = i_APCI3200_InsnBits_AnalogInput_Test,
875 10000, 551 .ai_cmdtest = i_APCI3200_CommandTestAnalogInput,
876 100000, 552 .ai_cmd = i_APCI3200_CommandAnalogInput,
877 v_APCI3200_Interrupt, 553 .ai_cancel = i_APCI3200_StopCyclicAcquisition,
878 i_APCI3200_Reset, 554 .di_bits = i_APCI3200_ReadDigitalInput,
879 i_APCI3200_ConfigAnalogInput, 555 .do_config = i_APCI3200_ConfigDigitalOutput,
880 i_APCI3200_ReadAnalogInput, 556 .do_write = i_APCI3200_WriteDigitalOutput,
881 i_APCI3200_InsnWriteReleaseAnalogInput, 557 .do_bits = i_APCI3200_ReadDigitalOutput,
882 i_APCI3200_InsnBits_AnalogInput_Test, 558 },
883 i_APCI3200_CommandTestAnalogInput,
884 i_APCI3200_CommandAnalogInput,
885 i_APCI3200_StopCyclicAcquisition,
886 NULL,
887 NULL,
888 NULL,
889 NULL,
890 NULL,
891 NULL,
892 i_APCI3200_ReadDigitalInput,
893 i_APCI3200_ConfigDigitalOutput,
894 i_APCI3200_WriteDigitalOutput,
895 i_APCI3200_ReadDigitalOutput,
896 NULL,
897 NULL,
898 NULL,
899 NULL,
900 NULL,
901 NULL,
902 NULL,
903 NULL,
904 NULL},
905#endif 559#endif
906#ifdef CONFIG_APCI_3300 560#ifdef CONFIG_APCI_3300
907 /* Begin JK .20.10.2004 = APCI-3300 integration */ 561 /* Begin JK .20.10.2004 = APCI-3300 integration */
908 {"apci3300", 562 {
909 APCI3200_BOARD_VENDOR_ID, 563 .pc_DriverName = "apci3300",
910 0x3007, 564 .i_VendorId = APCI3200_BOARD_VENDOR_ID,
911 128, 565 .i_DeviceId = 0x3007,
912 256, 566 .i_IorangeBase0 = 128,
913 4, 567 .i_IorangeBase1 = 256,
914 4, 568 .i_IorangeBase2 = 4,
915 ADDIDATA_EEPROM, 569 .i_IorangeBase3 = 4,
916 ADDIDATA_S5920, 570 .i_PCIEeprom = ADDIDATA_EEPROM,
917 0, 571 .pc_EepromChip = ADDIDATA_S5920,
918 8, 572 .i_NbrAiChannelDiff = 8,
919 8, 573 .i_AiChannelList = 8,
920 0, 574 .i_AiMaxdata = 0x3ffff,
921 0x3ffff, 575 .pr_AiRangelist = &range_apci3300_ai,
922 0, 576 .i_NbrDiChannel = 4,
923 &range_apci3300_ai, 577 .i_NbrDoChannel = 4,
924 NULL, 578 .ui_MinAcquisitiontimeNs = 10000,
925 4, 579 .ui_MinDelaytimeNs = 100000,
926 4, 580 .interrupt = v_APCI3200_Interrupt,
927 0, 581 .reset = i_APCI3200_Reset,
928 0, 582 .ai_config = i_APCI3200_ConfigAnalogInput,
929 NULL, 583 .ai_read = i_APCI3200_ReadAnalogInput,
930 0, 584 .ai_write = i_APCI3200_InsnWriteReleaseAnalogInput,
931 0, 585 .ai_bits = i_APCI3200_InsnBits_AnalogInput_Test,
932 0, 586 .ai_cmdtest = i_APCI3200_CommandTestAnalogInput,
933 10000, 587 .ai_cmd = i_APCI3200_CommandAnalogInput,
934 100000, 588 .ai_cancel = i_APCI3200_StopCyclicAcquisition,
935 v_APCI3200_Interrupt, 589 .di_bits = i_APCI3200_ReadDigitalInput,
936 i_APCI3200_Reset, 590 .do_config = i_APCI3200_ConfigDigitalOutput,
937 i_APCI3200_ConfigAnalogInput, 591 .do_write = i_APCI3200_WriteDigitalOutput,
938 i_APCI3200_ReadAnalogInput, 592 .do_bits = i_APCI3200_ReadDigitalOutput,
939 i_APCI3200_InsnWriteReleaseAnalogInput, 593 },
940 i_APCI3200_InsnBits_AnalogInput_Test,
941 i_APCI3200_CommandTestAnalogInput,
942 i_APCI3200_CommandAnalogInput,
943 i_APCI3200_StopCyclicAcquisition,
944 NULL,
945 NULL,
946 NULL,
947 NULL,
948 NULL,
949 NULL,
950 i_APCI3200_ReadDigitalInput,
951 i_APCI3200_ConfigDigitalOutput,
952 i_APCI3200_WriteDigitalOutput,
953 i_APCI3200_ReadDigitalOutput,
954 NULL,
955 NULL,
956 NULL,
957 NULL,
958 NULL,
959 NULL,
960 NULL,
961 NULL,
962 NULL},
963#endif 594#endif
964#ifdef CONFIG_APCI_1710 595#ifdef CONFIG_APCI_1710
965 {"apci1710", APCI1710_BOARD_VENDOR_ID, APCI1710_BOARD_DEVICE_ID, 596 {
966 128, 597 .pc_DriverName = "apci1710",
967 8, 598 .i_VendorId = APCI1710_BOARD_VENDOR_ID,
968 256, 599 .i_DeviceId = APCI1710_BOARD_DEVICE_ID,
969 0, 600 .i_IorangeBase0 = 128,
970 ADDIDATA_NO_EEPROM, 601 .i_IorangeBase1 = 8,
971 NULL, 602 .i_IorangeBase2 = 256,
972 0, 603 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
973 0, 604 .interrupt = v_APCI1710_Interrupt,
974 0, 605 .reset = i_APCI1710_Reset,
975 0, 606 },
976 0,
977 0,
978 NULL,
979 NULL,
980 0,
981 0,
982 0,
983 0,
984 NULL,
985 0,
986 0,
987 0,
988 0,
989 0,
990 v_APCI1710_Interrupt,
991 i_APCI1710_Reset,
992 NULL,
993 NULL,
994 NULL,
995 NULL,
996 NULL,
997 NULL,
998 NULL,
999 NULL,
1000 NULL,
1001 NULL,
1002 NULL,
1003 NULL,
1004 NULL,
1005 NULL,
1006 NULL,
1007 NULL,
1008 NULL,
1009 NULL,
1010 NULL,
1011 NULL,
1012 NULL,
1013 NULL,
1014 NULL,
1015 NULL,
1016 NULL,
1017 NULL},
1018#endif 607#endif
1019#ifdef CONFIG_APCI_16XX 608#ifdef CONFIG_APCI_16XX
1020 {"apci1648", 609 {
1021 PCI_VENDOR_ID_ADDIDATA, 610 .pc_DriverName = "apci1648",
1022 0x1009, 611 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1023 128, 612 .i_DeviceId = 0x1009,
1024 0, 613 .i_IorangeBase0 = 128,
1025 0, 614 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1026 0, 615 .i_NbrTTLChannel = 48,
1027 ADDIDATA_NO_EEPROM, 616 .pr_TTLRangelist = &range_apci16xx_ttl,
1028 NULL, 617 .reset = i_APCI16XX_Reset,
1029 0, 618 .ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
1030 0, 619 .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO,
1031 0, 620 .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue,
1032 0, 621 .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO,
1033 0, 622 }, {
1034 0, 623 .pc_DriverName = "apci1696",
1035 NULL, 624 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1036 NULL, 625 .i_DeviceId = 0x100A,
1037 0, 626 .i_IorangeBase0 = 128,
1038 0, 627 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1039 0, 628 .i_NbrTTLChannel = 96,
1040 48, 629 .pr_TTLRangelist = &range_apci16xx_ttl,
1041 &range_apci16xx_ttl, 630 .reset = i_APCI16XX_Reset,
1042 0, 631 .ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
1043 0, 632 .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO,
1044 0, 633 .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue,
1045 0, 634 .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO,
1046 0, 635 },
1047 NULL,
1048 i_APCI16XX_Reset,
1049 NULL,
1050 NULL,
1051 NULL,
1052 NULL,
1053 NULL,
1054 NULL,
1055 NULL,
1056 NULL,
1057 NULL,
1058 NULL,
1059 NULL,
1060 NULL,
1061 NULL,
1062 NULL,
1063 NULL,
1064 NULL,
1065 NULL,
1066 NULL,
1067 NULL,
1068 NULL,
1069 NULL,
1070 NULL,
1071 i_APCI16XX_InsnConfigInitTTLIO,
1072 i_APCI16XX_InsnBitsReadTTLIO,
1073 i_APCI16XX_InsnReadTTLIOAllPortValue,
1074 i_APCI16XX_InsnBitsWriteTTLIO},
1075
1076 {"apci1696",
1077 PCI_VENDOR_ID_ADDIDATA,
1078 0x100A,
1079 128,
1080 0,
1081 0,
1082 0,
1083 ADDIDATA_NO_EEPROM,
1084 NULL,
1085 0,
1086 0,
1087 0,
1088 0,
1089 0,
1090 0,
1091 NULL,
1092 NULL,
1093 0,
1094 0,
1095 0,
1096 96,
1097 &range_apci16xx_ttl,
1098 0,
1099 0,
1100 0,
1101 0,
1102 0,
1103 NULL,
1104 i_APCI16XX_Reset,
1105 NULL,
1106 NULL,
1107 NULL,
1108 NULL,
1109 NULL,
1110 NULL,
1111 NULL,
1112 NULL,
1113 NULL,
1114 NULL,
1115 NULL,
1116 NULL,
1117 NULL,
1118 NULL,
1119 NULL,
1120 NULL,
1121 NULL,
1122 NULL,
1123 NULL,
1124 NULL,
1125 NULL,
1126 NULL,
1127 i_APCI16XX_InsnConfigInitTTLIO,
1128 i_APCI16XX_InsnBitsReadTTLIO,
1129 i_APCI16XX_InsnReadTTLIOAllPortValue,
1130 i_APCI16XX_InsnBitsWriteTTLIO},
1131#endif 636#endif
1132#ifdef CONFIG_APCI_3XXX 637#ifdef CONFIG_APCI_3XXX
1133 {"apci3000-16", 638 {
1134 PCI_VENDOR_ID_ADDIDATA, 639 .pc_DriverName = "apci3000-16",
1135 0x3010, 640 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1136 256, 641 .i_DeviceId = 0x3010,
1137 256, 642 .i_IorangeBase0 = 256,
1138 256, 643 .i_IorangeBase1 = 256,
1139 256, 644 .i_IorangeBase2 = 256,
1140 ADDIDATA_NO_EEPROM, 645 .i_IorangeBase3 = 256,
1141 ADDIDATA_9054, 646 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1142 16, 647 .pc_EepromChip = ADDIDATA_9054,
1143 8, 648 .i_NbrAiChannel = 16,
1144 16, 649 .i_NbrAiChannelDiff = 8,
1145 0, 650 .i_AiChannelList = 16,
1146 4095, 651 .i_AiMaxdata = 4095,
1147 0, 652 .pr_AiRangelist = &range_apci3XXX_ai,
1148 &range_apci3XXX_ai, 653 .i_NbrTTLChannel = 24,
1149 NULL, 654 .pr_TTLRangelist = &range_apci3XXX_ttl,
1150 0, 655 .b_AvailableConvertUnit = 6,
1151 0, 656 .ui_MinAcquisitiontimeNs = 10000,
1152 0, 657 .interrupt = v_APCI3XXX_Interrupt,
1153 24, 658 .reset = i_APCI3XXX_Reset,
1154 &range_apci3XXX_ttl, 659 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1155 0, 660 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1156 0, 661 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1157 6, 662 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1158 10000, 663 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1159 0, 664 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1160 v_APCI3XXX_Interrupt, 665 }, {
1161 i_APCI3XXX_Reset, 666 .pc_DriverName = "apci3000-8",
1162 i_APCI3XXX_InsnConfigAnalogInput, 667 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1163 i_APCI3XXX_InsnReadAnalogInput, 668 .i_DeviceId = 0x300F,
1164 NULL, 669 .i_IorangeBase0 = 256,
1165 NULL, 670 .i_IorangeBase1 = 256,
1166 NULL, 671 .i_IorangeBase2 = 256,
1167 NULL, 672 .i_IorangeBase3 = 256,
1168 NULL, 673 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1169 NULL, 674 .pc_EepromChip = ADDIDATA_9054,
1170 NULL, 675 .i_NbrAiChannel = 8,
1171 NULL, 676 .i_NbrAiChannelDiff = 4,
1172 NULL, 677 .i_AiChannelList = 8,
1173 NULL, 678 .i_AiMaxdata = 4095,
1174 NULL, 679 .pr_AiRangelist = &range_apci3XXX_ai,
1175 NULL, 680 .i_NbrTTLChannel = 24,
1176 NULL, 681 .pr_TTLRangelist = &range_apci3XXX_ttl,
1177 NULL, 682 .b_AvailableConvertUnit = 6,
1178 NULL, 683 .ui_MinAcquisitiontimeNs = 10000,
1179 NULL, 684 .interrupt = v_APCI3XXX_Interrupt,
1180 NULL, 685 .reset = i_APCI3XXX_Reset,
1181 NULL, 686 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1182 NULL, 687 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1183 NULL, 688 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1184 i_APCI3XXX_InsnConfigInitTTLIO, 689 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1185 i_APCI3XXX_InsnBitsTTLIO, 690 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1186 i_APCI3XXX_InsnReadTTLIO, 691 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1187 i_APCI3XXX_InsnWriteTTLIO}, 692 }, {
1188 693 .pc_DriverName = "apci3000-4",
1189 {"apci3000-8", 694 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1190 PCI_VENDOR_ID_ADDIDATA, 695 .i_DeviceId = 0x300E,
1191 0x300F, 696 .i_IorangeBase0 = 256,
1192 256, 697 .i_IorangeBase1 = 256,
1193 256, 698 .i_IorangeBase2 = 256,
1194 256, 699 .i_IorangeBase3 = 256,
1195 256, 700 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1196 ADDIDATA_NO_EEPROM, 701 .pc_EepromChip = ADDIDATA_9054,
1197 ADDIDATA_9054, 702 .i_NbrAiChannel = 4,
1198 8, 703 .i_NbrAiChannelDiff = 2,
1199 4, 704 .i_AiChannelList = 4,
1200 8, 705 .i_AiMaxdata = 4095,
1201 0, 706 .pr_AiRangelist = &range_apci3XXX_ai,
1202 4095, 707 .i_NbrTTLChannel = 24,
1203 0, 708 .pr_TTLRangelist = &range_apci3XXX_ttl,
1204 &range_apci3XXX_ai, 709 .b_AvailableConvertUnit = 6,
1205 NULL, 710 .ui_MinAcquisitiontimeNs = 10000,
1206 0, 711 .interrupt = v_APCI3XXX_Interrupt,
1207 0, 712 .reset = i_APCI3XXX_Reset,
1208 0, 713 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1209 24, 714 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1210 &range_apci3XXX_ttl, 715 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1211 0, 716 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1212 0, 717 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1213 6, 718 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1214 10000, 719 }, {
1215 0, 720 .pc_DriverName = "apci3006-16",
1216 v_APCI3XXX_Interrupt, 721 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1217 i_APCI3XXX_Reset, 722 .i_DeviceId = 0x3013,
1218 i_APCI3XXX_InsnConfigAnalogInput, 723 .i_IorangeBase0 = 256,
1219 i_APCI3XXX_InsnReadAnalogInput, 724 .i_IorangeBase1 = 256,
1220 NULL, 725 .i_IorangeBase2 = 256,
1221 NULL, 726 .i_IorangeBase3 = 256,
1222 NULL, 727 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1223 NULL, 728 .pc_EepromChip = ADDIDATA_9054,
1224 NULL, 729 .i_NbrAiChannel = 16,
1225 NULL, 730 .i_NbrAiChannelDiff = 8,
1226 NULL, 731 .i_AiChannelList = 16,
1227 NULL, 732 .i_AiMaxdata = 65535,
1228 NULL, 733 .pr_AiRangelist = &range_apci3XXX_ai,
1229 NULL, 734 .i_NbrTTLChannel = 24,
1230 NULL, 735 .pr_TTLRangelist = &range_apci3XXX_ttl,
1231 NULL, 736 .b_AvailableConvertUnit = 6,
1232 NULL, 737 .ui_MinAcquisitiontimeNs = 10000,
1233 NULL, 738 .interrupt = v_APCI3XXX_Interrupt,
1234 NULL, 739 .reset = i_APCI3XXX_Reset,
1235 NULL, 740 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1236 NULL, 741 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1237 NULL, 742 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1238 NULL, 743 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1239 NULL, 744 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1240 i_APCI3XXX_InsnConfigInitTTLIO, 745 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1241 i_APCI3XXX_InsnBitsTTLIO, 746 }, {
1242 i_APCI3XXX_InsnReadTTLIO, 747 .pc_DriverName = "apci3006-8",
1243 i_APCI3XXX_InsnWriteTTLIO}, 748 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1244 749 .i_DeviceId = 0x3014,
1245 {"apci3000-4", 750 .i_IorangeBase0 = 256,
1246 PCI_VENDOR_ID_ADDIDATA, 751 .i_IorangeBase1 = 256,
1247 0x300E, 752 .i_IorangeBase2 = 256,
1248 256, 753 .i_IorangeBase3 = 256,
1249 256, 754 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1250 256, 755 .pc_EepromChip = ADDIDATA_9054,
1251 256, 756 .i_NbrAiChannel = 8,
1252 ADDIDATA_NO_EEPROM, 757 .i_NbrAiChannelDiff = 4,
1253 ADDIDATA_9054, 758 .i_AiChannelList = 8,
1254 4, 759 .i_AiMaxdata = 65535,
1255 2, 760 .pr_AiRangelist = &range_apci3XXX_ai,
1256 4, 761 .i_NbrTTLChannel = 24,
1257 0, 762 .pr_TTLRangelist = &range_apci3XXX_ttl,
1258 4095, 763 .b_AvailableConvertUnit = 6,
1259 0, 764 .ui_MinAcquisitiontimeNs = 10000,
1260 &range_apci3XXX_ai, 765 .interrupt = v_APCI3XXX_Interrupt,
1261 NULL, 766 .reset = i_APCI3XXX_Reset,
1262 0, 767 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1263 0, 768 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1264 0, 769 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1265 24, 770 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1266 &range_apci3XXX_ttl, 771 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1267 0, 772 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1268 0, 773 }, {
1269 6, 774 .pc_DriverName = "apci3006-4",
1270 10000, 775 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1271 0, 776 .i_DeviceId = 0x3015,
1272 v_APCI3XXX_Interrupt, 777 .i_IorangeBase0 = 256,
1273 i_APCI3XXX_Reset, 778 .i_IorangeBase1 = 256,
1274 i_APCI3XXX_InsnConfigAnalogInput, 779 .i_IorangeBase2 = 256,
1275 i_APCI3XXX_InsnReadAnalogInput, 780 .i_IorangeBase3 = 256,
1276 NULL, 781 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1277 NULL, 782 .pc_EepromChip = ADDIDATA_9054,
1278 NULL, 783 .i_NbrAiChannel = 4,
1279 NULL, 784 .i_NbrAiChannelDiff = 2,
1280 NULL, 785 .i_AiChannelList = 4,
1281 NULL, 786 .i_AiMaxdata = 65535,
1282 NULL, 787 .pr_AiRangelist = &range_apci3XXX_ai,
1283 NULL, 788 .i_NbrTTLChannel = 24,
1284 NULL, 789 .pr_TTLRangelist = &range_apci3XXX_ttl,
1285 NULL, 790 .b_AvailableConvertUnit = 6,
1286 NULL, 791 .ui_MinAcquisitiontimeNs = 10000,
1287 NULL, 792 .interrupt = v_APCI3XXX_Interrupt,
1288 NULL, 793 .reset = i_APCI3XXX_Reset,
1289 NULL, 794 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1290 NULL, 795 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1291 NULL, 796 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1292 NULL, 797 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1293 NULL, 798 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1294 NULL, 799 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1295 NULL, 800 }, {
1296 i_APCI3XXX_InsnConfigInitTTLIO, 801 .pc_DriverName = "apci3010-16",
1297 i_APCI3XXX_InsnBitsTTLIO, 802 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1298 i_APCI3XXX_InsnReadTTLIO, 803 .i_DeviceId = 0x3016,
1299 i_APCI3XXX_InsnWriteTTLIO}, 804 .i_IorangeBase0 = 256,
1300 805 .i_IorangeBase1 = 256,
1301 {"apci3006-16", 806 .i_IorangeBase2 = 256,
1302 PCI_VENDOR_ID_ADDIDATA, 807 .i_IorangeBase3 = 256,
1303 0x3013, 808 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1304 256, 809 .pc_EepromChip = ADDIDATA_9054,
1305 256, 810 .i_NbrAiChannel = 16,
1306 256, 811 .i_NbrAiChannelDiff = 8,
1307 256, 812 .i_AiChannelList = 16,
1308 ADDIDATA_NO_EEPROM, 813 .i_AiMaxdata = 4095,
1309 ADDIDATA_9054, 814 .pr_AiRangelist = &range_apci3XXX_ai,
1310 16, 815 .i_NbrDiChannel = 4,
1311 8, 816 .i_NbrDoChannel = 4,
1312 16, 817 .i_DoMaxdata = 1,
1313 0, 818 .i_NbrTTLChannel = 24,
1314 65535, 819 .pr_TTLRangelist = &range_apci3XXX_ttl,
1315 0, 820 .b_AvailableConvertUnit = 6,
1316 &range_apci3XXX_ai, 821 .ui_MinAcquisitiontimeNs = 5000,
1317 NULL, 822 .interrupt = v_APCI3XXX_Interrupt,
1318 0, 823 .reset = i_APCI3XXX_Reset,
1319 0, 824 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1320 0, 825 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1321 24, 826 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1322 &range_apci3XXX_ttl, 827 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1323 0, 828 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1324 0, 829 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1325 6, 830 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1326 10000, 831 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1327 0, 832 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1328 v_APCI3XXX_Interrupt, 833 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1329 i_APCI3XXX_Reset, 834 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1330 i_APCI3XXX_InsnConfigAnalogInput, 835 }, {
1331 i_APCI3XXX_InsnReadAnalogInput, 836 .pc_DriverName = "apci3010-8",
1332 NULL, 837 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1333 NULL, 838 .i_DeviceId = 0x3017,
1334 NULL, 839 .i_IorangeBase0 = 256,
1335 NULL, 840 .i_IorangeBase1 = 256,
1336 NULL, 841 .i_IorangeBase2 = 256,
1337 NULL, 842 .i_IorangeBase3 = 256,
1338 NULL, 843 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1339 NULL, 844 .pc_EepromChip = ADDIDATA_9054,
1340 NULL, 845 .i_NbrAiChannel = 8,
1341 NULL, 846 .i_NbrAiChannelDiff = 4,
1342 NULL, 847 .i_AiChannelList = 8,
1343 NULL, 848 .i_AiMaxdata = 4095,
1344 NULL, 849 .pr_AiRangelist = &range_apci3XXX_ai,
1345 NULL, 850 .i_NbrDiChannel = 4,
1346 NULL, 851 .i_NbrDoChannel = 4,
1347 NULL, 852 .i_DoMaxdata = 1,
1348 NULL, 853 .i_NbrTTLChannel = 24,
1349 NULL, 854 .pr_TTLRangelist = &range_apci3XXX_ttl,
1350 NULL, 855 .b_AvailableConvertUnit = 6,
1351 NULL, 856 .ui_MinAcquisitiontimeNs = 5000,
1352 i_APCI3XXX_InsnConfigInitTTLIO, 857 .interrupt = v_APCI3XXX_Interrupt,
1353 i_APCI3XXX_InsnBitsTTLIO, 858 .reset = i_APCI3XXX_Reset,
1354 i_APCI3XXX_InsnReadTTLIO, 859 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1355 i_APCI3XXX_InsnWriteTTLIO}, 860 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1356 861 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1357 {"apci3006-8", 862 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1358 PCI_VENDOR_ID_ADDIDATA, 863 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1359 0x3014, 864 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1360 256, 865 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1361 256, 866 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1362 256, 867 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1363 256, 868 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1364 ADDIDATA_NO_EEPROM, 869 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1365 ADDIDATA_9054, 870 }, {
1366 8, 871 .pc_DriverName = "apci3010-4",
1367 4, 872 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1368 8, 873 .i_DeviceId = 0x3018,
1369 0, 874 .i_IorangeBase0 = 256,
1370 65535, 875 .i_IorangeBase1 = 256,
1371 0, 876 .i_IorangeBase2 = 256,
1372 &range_apci3XXX_ai, 877 .i_IorangeBase3 = 256,
1373 NULL, 878 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1374 0, 879 .pc_EepromChip = ADDIDATA_9054,
1375 0, 880 .i_NbrAiChannel = 4,
1376 0, 881 .i_NbrAiChannelDiff = 2,
1377 24, 882 .i_AiChannelList = 4,
1378 &range_apci3XXX_ttl, 883 .i_AiMaxdata = 4095,
1379 0, 884 .pr_AiRangelist = &range_apci3XXX_ai,
1380 0, 885 .i_NbrDiChannel = 4,
1381 6, 886 .i_NbrDoChannel = 4,
1382 10000, 887 .i_DoMaxdata = 1,
1383 0, 888 .i_NbrTTLChannel = 24,
1384 v_APCI3XXX_Interrupt, 889 .pr_TTLRangelist = &range_apci3XXX_ttl,
1385 i_APCI3XXX_Reset, 890 .b_AvailableConvertUnit = 6,
1386 i_APCI3XXX_InsnConfigAnalogInput, 891 .ui_MinAcquisitiontimeNs = 5000,
1387 i_APCI3XXX_InsnReadAnalogInput, 892 .interrupt = v_APCI3XXX_Interrupt,
1388 NULL, 893 .reset = i_APCI3XXX_Reset,
1389 NULL, 894 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1390 NULL, 895 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1391 NULL, 896 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1392 NULL, 897 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1393 NULL, 898 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1394 NULL, 899 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1395 NULL, 900 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1396 NULL, 901 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1397 NULL, 902 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1398 NULL, 903 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1399 NULL, 904 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1400 NULL, 905 }, {
1401 NULL, 906 .pc_DriverName = "apci3016-16",
1402 NULL, 907 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1403 NULL, 908 .i_DeviceId = 0x3019,
1404 NULL, 909 .i_IorangeBase0 = 256,
1405 NULL, 910 .i_IorangeBase1 = 256,
1406 NULL, 911 .i_IorangeBase2 = 256,
1407 NULL, 912 .i_IorangeBase3 = 256,
1408 i_APCI3XXX_InsnConfigInitTTLIO, 913 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1409 i_APCI3XXX_InsnBitsTTLIO, 914 .pc_EepromChip = ADDIDATA_9054,
1410 i_APCI3XXX_InsnReadTTLIO, 915 .i_NbrAiChannel = 16,
1411 i_APCI3XXX_InsnWriteTTLIO}, 916 .i_NbrAiChannelDiff = 8,
1412 917 .i_AiChannelList = 16,
1413 {"apci3006-4", 918 .i_AiMaxdata = 65535,
1414 PCI_VENDOR_ID_ADDIDATA, 919 .pr_AiRangelist = &range_apci3XXX_ai,
1415 0x3015, 920 .i_NbrDiChannel = 4,
1416 256, 921 .i_NbrDoChannel = 4,
1417 256, 922 .i_DoMaxdata = 1,
1418 256, 923 .i_NbrTTLChannel = 24,
1419 256, 924 .pr_TTLRangelist = &range_apci3XXX_ttl,
1420 ADDIDATA_NO_EEPROM, 925 .b_AvailableConvertUnit = 6,
1421 ADDIDATA_9054, 926 .ui_MinAcquisitiontimeNs = 5000,
1422 4, 927 .interrupt = v_APCI3XXX_Interrupt,
1423 2, 928 .reset = i_APCI3XXX_Reset,
1424 4, 929 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1425 0, 930 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1426 65535, 931 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1427 0, 932 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1428 &range_apci3XXX_ai, 933 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1429 NULL, 934 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1430 0, 935 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1431 0, 936 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1432 0, 937 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1433 24, 938 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1434 &range_apci3XXX_ttl, 939 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1435 0, 940 }, {
1436 0, 941 .pc_DriverName = "apci3016-8",
1437 6, 942 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1438 10000, 943 .i_DeviceId = 0x301A,
1439 0, 944 .i_IorangeBase0 = 256,
1440 v_APCI3XXX_Interrupt, 945 .i_IorangeBase1 = 256,
1441 i_APCI3XXX_Reset, 946 .i_IorangeBase2 = 256,
1442 i_APCI3XXX_InsnConfigAnalogInput, 947 .i_IorangeBase3 = 256,
1443 i_APCI3XXX_InsnReadAnalogInput, 948 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1444 NULL, 949 .pc_EepromChip = ADDIDATA_9054,
1445 NULL, 950 .i_NbrAiChannel = 8,
1446 NULL, 951 .i_NbrAiChannelDiff = 4,
1447 NULL, 952 .i_AiChannelList = 8,
1448 NULL, 953 .i_AiMaxdata = 65535,
1449 NULL, 954 .pr_AiRangelist = &range_apci3XXX_ai,
1450 NULL, 955 .i_NbrDiChannel = 4,
1451 NULL, 956 .i_NbrDoChannel = 4,
1452 NULL, 957 .i_DoMaxdata = 1,
1453 NULL, 958 .i_NbrTTLChannel = 24,
1454 NULL, 959 .pr_TTLRangelist = &range_apci3XXX_ttl,
1455 NULL, 960 .b_AvailableConvertUnit = 6,
1456 NULL, 961 .ui_MinAcquisitiontimeNs = 5000,
1457 NULL, 962 .interrupt = v_APCI3XXX_Interrupt,
1458 NULL, 963 .reset = i_APCI3XXX_Reset,
1459 NULL, 964 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1460 NULL, 965 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1461 NULL, 966 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1462 NULL, 967 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1463 NULL, 968 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1464 i_APCI3XXX_InsnConfigInitTTLIO, 969 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1465 i_APCI3XXX_InsnBitsTTLIO, 970 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1466 i_APCI3XXX_InsnReadTTLIO, 971 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1467 i_APCI3XXX_InsnWriteTTLIO}, 972 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1468 973 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1469 {"apci3010-16", 974 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1470 PCI_VENDOR_ID_ADDIDATA, 975 }, {
1471 0x3016, 976 .pc_DriverName = "apci3016-4",
1472 256, 977 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1473 256, 978 .i_DeviceId = 0x301B,
1474 256, 979 .i_IorangeBase0 = 256,
1475 256, 980 .i_IorangeBase1 = 256,
1476 ADDIDATA_NO_EEPROM, 981 .i_IorangeBase2 = 256,
1477 ADDIDATA_9054, 982 .i_IorangeBase3 = 256,
1478 16, 983 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1479 8, 984 .pc_EepromChip = ADDIDATA_9054,
1480 16, 985 .i_NbrAiChannel = 4,
1481 0, 986 .i_NbrAiChannelDiff = 2,
1482 4095, 987 .i_AiChannelList = 4,
1483 0, 988 .i_AiMaxdata = 65535,
1484 &range_apci3XXX_ai, 989 .pr_AiRangelist = &range_apci3XXX_ai,
1485 NULL, 990 .i_NbrDiChannel = 4,
1486 4, 991 .i_NbrDoChannel = 4,
1487 4, 992 .i_DoMaxdata = 1,
1488 1, 993 .i_NbrTTLChannel = 24,
1489 24, 994 .pr_TTLRangelist = &range_apci3XXX_ttl,
1490 &range_apci3XXX_ttl, 995 .b_AvailableConvertUnit = 6,
1491 0, 996 .ui_MinAcquisitiontimeNs = 5000,
1492 0, 997 .interrupt = v_APCI3XXX_Interrupt,
1493 6, 998 .reset = i_APCI3XXX_Reset,
1494 5000, 999 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1495 0, 1000 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1496 v_APCI3XXX_Interrupt, 1001 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1497 i_APCI3XXX_Reset, 1002 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1498 i_APCI3XXX_InsnConfigAnalogInput, 1003 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1499 i_APCI3XXX_InsnReadAnalogInput, 1004 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1500 NULL, 1005 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1501 NULL, 1006 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1502 NULL, 1007 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1503 NULL, 1008 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1504 NULL, 1009 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1505 NULL, 1010 }, {
1506 NULL, 1011 .pc_DriverName = "apci3100-16-4",
1507 NULL, 1012 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1508 NULL, 1013 .i_DeviceId = 0x301C,
1509 i_APCI3XXX_InsnReadDigitalInput, 1014 .i_IorangeBase0 = 256,
1510 NULL, 1015 .i_IorangeBase1 = 256,
1511 i_APCI3XXX_InsnBitsDigitalInput, 1016 .i_IorangeBase2 = 256,
1512 NULL, 1017 .i_IorangeBase3 = 256,
1513 i_APCI3XXX_InsnWriteDigitalOutput, 1018 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1514 i_APCI3XXX_InsnBitsDigitalOutput, 1019 .pc_EepromChip = ADDIDATA_9054,
1515 i_APCI3XXX_InsnReadDigitalOutput, 1020 .i_NbrAiChannel = 16,
1516 NULL, 1021 .i_NbrAiChannelDiff = 8,
1517 NULL, 1022 .i_AiChannelList = 16,
1518 NULL, 1023 .i_NbrAoChannel = 4,
1519 NULL, 1024 .i_AiMaxdata = 4095,
1520 i_APCI3XXX_InsnConfigInitTTLIO, 1025 .i_AoMaxdata = 4095,
1521 i_APCI3XXX_InsnBitsTTLIO, 1026 .pr_AiRangelist = &range_apci3XXX_ai,
1522 i_APCI3XXX_InsnReadTTLIO, 1027 .pr_AoRangelist = &range_apci3XXX_ao,
1523 i_APCI3XXX_InsnWriteTTLIO}, 1028 .i_NbrTTLChannel = 24,
1524 1029 .pr_TTLRangelist = &range_apci3XXX_ttl,
1525 {"apci3010-8", 1030 .b_AvailableConvertUnit = 6,
1526 PCI_VENDOR_ID_ADDIDATA, 1031 .ui_MinAcquisitiontimeNs = 10000,
1527 0x3017, 1032 .interrupt = v_APCI3XXX_Interrupt,
1528 256, 1033 .reset = i_APCI3XXX_Reset,
1529 256, 1034 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1530 256, 1035 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1531 256, 1036 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1532 ADDIDATA_NO_EEPROM, 1037 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1533 ADDIDATA_9054, 1038 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1534 8, 1039 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1535 4, 1040 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1536 8, 1041 }, {
1537 0, 1042 .pc_DriverName = "apci3100-8-4",
1538 4095, 1043 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1539 0, 1044 .i_DeviceId = 0x301D,
1540 &range_apci3XXX_ai, 1045 .i_IorangeBase0 = 256,
1541 NULL, 1046 .i_IorangeBase1 = 256,
1542 4, 1047 .i_IorangeBase2 = 256,
1543 4, 1048 .i_IorangeBase3 = 256,
1544 1, 1049 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1545 24, 1050 .pc_EepromChip = ADDIDATA_9054,
1546 &range_apci3XXX_ttl, 1051 .i_NbrAiChannel = 8,
1547 0, 1052 .i_NbrAiChannelDiff = 4,
1548 0, 1053 .i_AiChannelList = 8,
1549 6, 1054 .i_NbrAoChannel = 4,
1550 5000, 1055 .i_AiMaxdata = 4095,
1551 0, 1056 .i_AoMaxdata = 4095,
1552 v_APCI3XXX_Interrupt, 1057 .pr_AiRangelist = &range_apci3XXX_ai,
1553 i_APCI3XXX_Reset, 1058 .pr_AoRangelist = &range_apci3XXX_ao,
1554 i_APCI3XXX_InsnConfigAnalogInput, 1059 .i_NbrTTLChannel = 24,
1555 i_APCI3XXX_InsnReadAnalogInput, 1060 .pr_TTLRangelist = &range_apci3XXX_ttl,
1556 NULL, 1061 .b_AvailableConvertUnit = 6,
1557 NULL, 1062 .ui_MinAcquisitiontimeNs = 10000,
1558 NULL, 1063 .interrupt = v_APCI3XXX_Interrupt,
1559 NULL, 1064 .reset = i_APCI3XXX_Reset,
1560 NULL, 1065 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1561 NULL, 1066 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1562 NULL, 1067 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1563 NULL, 1068 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1564 NULL, 1069 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1565 i_APCI3XXX_InsnReadDigitalInput, 1070 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1566 NULL, 1071 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1567 i_APCI3XXX_InsnBitsDigitalInput, 1072 }, {
1568 NULL, 1073 .pc_DriverName = "apci3106-16-4",
1569 i_APCI3XXX_InsnWriteDigitalOutput, 1074 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1570 i_APCI3XXX_InsnBitsDigitalOutput, 1075 .i_DeviceId = 0x301E,
1571 i_APCI3XXX_InsnReadDigitalOutput, 1076 .i_IorangeBase0 = 256,
1572 NULL, 1077 .i_IorangeBase1 = 256,
1573 NULL, 1078 .i_IorangeBase2 = 256,
1574 NULL, 1079 .i_IorangeBase3 = 256,
1575 NULL, 1080 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1576 i_APCI3XXX_InsnConfigInitTTLIO, 1081 .pc_EepromChip = ADDIDATA_9054,
1577 i_APCI3XXX_InsnBitsTTLIO, 1082 .i_NbrAiChannel = 16,
1578 i_APCI3XXX_InsnReadTTLIO, 1083 .i_NbrAiChannelDiff = 8,
1579 i_APCI3XXX_InsnWriteTTLIO}, 1084 .i_AiChannelList = 16,
1580 1085 .i_NbrAoChannel = 4,
1581 {"apci3010-4", 1086 .i_AiMaxdata = 65535,
1582 PCI_VENDOR_ID_ADDIDATA, 1087 .i_AoMaxdata = 4095,
1583 0x3018, 1088 .pr_AiRangelist = &range_apci3XXX_ai,
1584 256, 1089 .pr_AoRangelist = &range_apci3XXX_ao,
1585 256, 1090 .i_NbrTTLChannel = 24,
1586 256, 1091 .pr_TTLRangelist = &range_apci3XXX_ttl,
1587 256, 1092 .b_AvailableConvertUnit = 6,
1588 ADDIDATA_NO_EEPROM, 1093 .ui_MinAcquisitiontimeNs = 10000,
1589 ADDIDATA_9054, 1094 .interrupt = v_APCI3XXX_Interrupt,
1590 4, 1095 .reset = i_APCI3XXX_Reset,
1591 2, 1096 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1592 4, 1097 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1593 0, 1098 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1594 4095, 1099 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1595 0, 1100 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1596 &range_apci3XXX_ai, 1101 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1597 NULL, 1102 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1598 4, 1103 }, {
1599 4, 1104 .pc_DriverName = "apci3106-8-4",
1600 1, 1105 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1601 24, 1106 .i_DeviceId = 0x301F,
1602 &range_apci3XXX_ttl, 1107 .i_IorangeBase0 = 256,
1603 0, 1108 .i_IorangeBase1 = 256,
1604 0, 1109 .i_IorangeBase2 = 256,
1605 6, 1110 .i_IorangeBase3 = 256,
1606 5000, 1111 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1607 0, 1112 .pc_EepromChip = ADDIDATA_9054,
1608 v_APCI3XXX_Interrupt, 1113 .i_NbrAiChannel = 8,
1609 i_APCI3XXX_Reset, 1114 .i_NbrAiChannelDiff = 4,
1610 i_APCI3XXX_InsnConfigAnalogInput, 1115 .i_AiChannelList = 8,
1611 i_APCI3XXX_InsnReadAnalogInput, 1116 .i_NbrAoChannel = 4,
1612 NULL, 1117 .i_AiMaxdata = 65535,
1613 NULL, 1118 .i_AoMaxdata = 4095,
1614 NULL, 1119 .pr_AiRangelist = &range_apci3XXX_ai,
1615 NULL, 1120 .pr_AoRangelist = &range_apci3XXX_ao,
1616 NULL, 1121 .i_NbrTTLChannel = 24,
1617 NULL, 1122 .pr_TTLRangelist = &range_apci3XXX_ttl,
1618 NULL, 1123 .b_AvailableConvertUnit = 6,
1619 NULL, 1124 .ui_MinAcquisitiontimeNs = 10000,
1620 NULL, 1125 .interrupt = v_APCI3XXX_Interrupt,
1621 i_APCI3XXX_InsnReadDigitalInput, 1126 .reset = i_APCI3XXX_Reset,
1622 NULL, 1127 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1623 i_APCI3XXX_InsnBitsDigitalInput, 1128 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1624 NULL, 1129 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1625 i_APCI3XXX_InsnWriteDigitalOutput, 1130 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1626 i_APCI3XXX_InsnBitsDigitalOutput, 1131 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1627 i_APCI3XXX_InsnReadDigitalOutput, 1132 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1628 NULL, 1133 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1629 NULL, 1134 }, {
1630 NULL, 1135 .pc_DriverName = "apci3110-16-4",
1631 NULL, 1136 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1632 i_APCI3XXX_InsnConfigInitTTLIO, 1137 .i_DeviceId = 0x3020,
1633 i_APCI3XXX_InsnBitsTTLIO, 1138 .i_IorangeBase0 = 256,
1634 i_APCI3XXX_InsnReadTTLIO, 1139 .i_IorangeBase1 = 256,
1635 i_APCI3XXX_InsnWriteTTLIO}, 1140 .i_IorangeBase2 = 256,
1636 1141 .i_IorangeBase3 = 256,
1637 {"apci3016-16", 1142 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1638 PCI_VENDOR_ID_ADDIDATA, 1143 .pc_EepromChip = ADDIDATA_9054,
1639 0x3019, 1144 .i_NbrAiChannel = 16,
1640 256, 1145 .i_NbrAiChannelDiff = 8,
1641 256, 1146 .i_AiChannelList = 16,
1642 256, 1147 .i_NbrAoChannel = 4,
1643 256, 1148 .i_AiMaxdata = 4095,
1644 ADDIDATA_NO_EEPROM, 1149 .i_AoMaxdata = 4095,
1645 ADDIDATA_9054, 1150 .pr_AiRangelist = &range_apci3XXX_ai,
1646 16, 1151 .pr_AoRangelist = &range_apci3XXX_ao,
1647 8, 1152 .i_NbrDiChannel = 4,
1648 16, 1153 .i_NbrDoChannel = 4,
1649 0, 1154 .i_DoMaxdata = 1,
1650 65535, 1155 .i_NbrTTLChannel = 24,
1651 0, 1156 .pr_TTLRangelist = &range_apci3XXX_ttl,
1652 &range_apci3XXX_ai, 1157 .b_AvailableConvertUnit = 6,
1653 NULL, 1158 .ui_MinAcquisitiontimeNs = 5000,
1654 4, 1159 .interrupt = v_APCI3XXX_Interrupt,
1655 4, 1160 .reset = i_APCI3XXX_Reset,
1656 1, 1161 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1657 24, 1162 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1658 &range_apci3XXX_ttl, 1163 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1659 0, 1164 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1660 0, 1165 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1661 6, 1166 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1662 5000, 1167 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1663 0, 1168 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1664 v_APCI3XXX_Interrupt, 1169 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1665 i_APCI3XXX_Reset, 1170 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1666 i_APCI3XXX_InsnConfigAnalogInput, 1171 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1667 i_APCI3XXX_InsnReadAnalogInput, 1172 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1668 NULL, 1173 }, {
1669 NULL, 1174 .pc_DriverName = "apci3110-8-4",
1670 NULL, 1175 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1671 NULL, 1176 .i_DeviceId = 0x3021,
1672 NULL, 1177 .i_IorangeBase0 = 256,
1673 NULL, 1178 .i_IorangeBase1 = 256,
1674 NULL, 1179 .i_IorangeBase2 = 256,
1675 NULL, 1180 .i_IorangeBase3 = 256,
1676 NULL, 1181 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1677 i_APCI3XXX_InsnReadDigitalInput, 1182 .pc_EepromChip = ADDIDATA_9054,
1678 NULL, 1183 .i_NbrAiChannel = 8,
1679 i_APCI3XXX_InsnBitsDigitalInput, 1184 .i_NbrAiChannelDiff = 4,
1680 NULL, 1185 .i_AiChannelList = 8,
1681 i_APCI3XXX_InsnWriteDigitalOutput, 1186 .i_NbrAoChannel = 4,
1682 i_APCI3XXX_InsnBitsDigitalOutput, 1187 .i_AiMaxdata = 4095,
1683 i_APCI3XXX_InsnReadDigitalOutput, 1188 .i_AoMaxdata = 4095,
1684 NULL, 1189 .pr_AiRangelist = &range_apci3XXX_ai,
1685 NULL, 1190 .pr_AoRangelist = &range_apci3XXX_ao,
1686 NULL, 1191 .i_NbrDiChannel = 4,
1687 NULL, 1192 .i_NbrDoChannel = 4,
1688 i_APCI3XXX_InsnConfigInitTTLIO, 1193 .i_DoMaxdata = 1,
1689 i_APCI3XXX_InsnBitsTTLIO, 1194 .i_NbrTTLChannel = 24,
1690 i_APCI3XXX_InsnReadTTLIO, 1195 .pr_TTLRangelist = &range_apci3XXX_ttl,
1691 i_APCI3XXX_InsnWriteTTLIO}, 1196 .b_AvailableConvertUnit = 6,
1692 1197 .ui_MinAcquisitiontimeNs = 5000,
1693 {"apci3016-8", 1198 .interrupt = v_APCI3XXX_Interrupt,
1694 PCI_VENDOR_ID_ADDIDATA, 1199 .reset = i_APCI3XXX_Reset,
1695 0x301A, 1200 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1696 256, 1201 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1697 256, 1202 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1698 256, 1203 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1699 256, 1204 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1700 ADDIDATA_NO_EEPROM, 1205 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1701 ADDIDATA_9054, 1206 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1702 8, 1207 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1703 4, 1208 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1704 8, 1209 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1705 0, 1210 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1706 65535, 1211 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1707 0, 1212 }, {
1708 &range_apci3XXX_ai, 1213 .pc_DriverName = "apci3116-16-4",
1709 NULL, 1214 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1710 4, 1215 .i_DeviceId = 0x3022,
1711 4, 1216 .i_IorangeBase0 = 256,
1712 1, 1217 .i_IorangeBase1 = 256,
1713 24, 1218 .i_IorangeBase2 = 256,
1714 &range_apci3XXX_ttl, 1219 .i_IorangeBase3 = 256,
1715 0, 1220 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1716 0, 1221 .pc_EepromChip = ADDIDATA_9054,
1717 6, 1222 .i_NbrAiChannel = 16,
1718 5000, 1223 .i_NbrAiChannelDiff = 8,
1719 0, 1224 .i_AiChannelList = 16,
1720 v_APCI3XXX_Interrupt, 1225 .i_NbrAoChannel = 4,
1721 i_APCI3XXX_Reset, 1226 .i_AiMaxdata = 65535,
1722 i_APCI3XXX_InsnConfigAnalogInput, 1227 .i_AoMaxdata = 4095,
1723 i_APCI3XXX_InsnReadAnalogInput, 1228 .pr_AiRangelist = &range_apci3XXX_ai,
1724 NULL, 1229 .pr_AoRangelist = &range_apci3XXX_ao,
1725 NULL, 1230 .i_NbrDiChannel = 4,
1726 NULL, 1231 .i_NbrDoChannel = 4,
1727 NULL, 1232 .i_DoMaxdata = 1,
1728 NULL, 1233 .i_NbrTTLChannel = 24,
1729 NULL, 1234 .pr_TTLRangelist = &range_apci3XXX_ttl,
1730 NULL, 1235 .b_AvailableConvertUnit = 6,
1731 NULL, 1236 .ui_MinAcquisitiontimeNs = 5000,
1732 NULL, 1237 .interrupt = v_APCI3XXX_Interrupt,
1733 i_APCI3XXX_InsnReadDigitalInput, 1238 .reset = i_APCI3XXX_Reset,
1734 NULL, 1239 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1735 i_APCI3XXX_InsnBitsDigitalInput, 1240 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1736 NULL, 1241 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1737 i_APCI3XXX_InsnWriteDigitalOutput, 1242 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1738 i_APCI3XXX_InsnBitsDigitalOutput, 1243 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1739 i_APCI3XXX_InsnReadDigitalOutput, 1244 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1740 NULL, 1245 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1741 NULL, 1246 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1742 NULL, 1247 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1743 NULL, 1248 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1744 i_APCI3XXX_InsnConfigInitTTLIO, 1249 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1745 i_APCI3XXX_InsnBitsTTLIO, 1250 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1746 i_APCI3XXX_InsnReadTTLIO, 1251 }, {
1747 i_APCI3XXX_InsnWriteTTLIO}, 1252 .pc_DriverName = "apci3116-8-4",
1748 1253 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1749 {"apci3016-4", 1254 .i_DeviceId = 0x3023,
1750 PCI_VENDOR_ID_ADDIDATA, 1255 .i_IorangeBase0 = 256,
1751 0x301B, 1256 .i_IorangeBase1 = 256,
1752 256, 1257 .i_IorangeBase2 = 256,
1753 256, 1258 .i_IorangeBase3 = 256,
1754 256, 1259 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1755 256, 1260 .pc_EepromChip = ADDIDATA_9054,
1756 ADDIDATA_NO_EEPROM, 1261 .i_NbrAiChannel = 8,
1757 ADDIDATA_9054, 1262 .i_NbrAiChannelDiff = 4,
1758 4, 1263 .i_AiChannelList = 8,
1759 2, 1264 .i_NbrAoChannel = 4,
1760 4, 1265 .i_AiMaxdata = 65535,
1761 0, 1266 .i_AoMaxdata = 4095,
1762 65535, 1267 .pr_AiRangelist = &range_apci3XXX_ai,
1763 0, 1268 .pr_AoRangelist = &range_apci3XXX_ao,
1764 &range_apci3XXX_ai, 1269 .i_NbrDiChannel = 4,
1765 NULL, 1270 .i_NbrDoChannel = 4,
1766 4, 1271 .i_DoMaxdata = 1,
1767 4, 1272 .i_NbrTTLChannel = 24,
1768 1, 1273 .pr_TTLRangelist = &range_apci3XXX_ttl,
1769 24, 1274 .b_AvailableConvertUnit = 6,
1770 &range_apci3XXX_ttl, 1275 .ui_MinAcquisitiontimeNs = 5000,
1771 0, 1276 .interrupt = v_APCI3XXX_Interrupt,
1772 0, 1277 .reset = i_APCI3XXX_Reset,
1773 6, 1278 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1774 5000, 1279 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1775 0, 1280 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1776 v_APCI3XXX_Interrupt, 1281 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1777 i_APCI3XXX_Reset, 1282 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1778 i_APCI3XXX_InsnConfigAnalogInput, 1283 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1779 i_APCI3XXX_InsnReadAnalogInput, 1284 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1780 NULL, 1285 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1781 NULL, 1286 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1782 NULL, 1287 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1783 NULL, 1288 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1784 NULL, 1289 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1785 NULL, 1290 }, {
1786 NULL, 1291 .pc_DriverName = "apci3003",
1787 NULL, 1292 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1788 NULL, 1293 .i_DeviceId = 0x300B,
1789 i_APCI3XXX_InsnReadDigitalInput, 1294 .i_IorangeBase0 = 256,
1790 NULL, 1295 .i_IorangeBase1 = 256,
1791 i_APCI3XXX_InsnBitsDigitalInput, 1296 .i_IorangeBase2 = 256,
1792 NULL, 1297 .i_IorangeBase3 = 256,
1793 i_APCI3XXX_InsnWriteDigitalOutput, 1298 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1794 i_APCI3XXX_InsnBitsDigitalOutput, 1299 .pc_EepromChip = ADDIDATA_9054,
1795 i_APCI3XXX_InsnReadDigitalOutput, 1300 .i_NbrAiChannelDiff = 4,
1796 NULL, 1301 .i_AiChannelList = 4,
1797 NULL, 1302 .i_AiMaxdata = 65535,
1798 NULL, 1303 .pr_AiRangelist = &range_apci3XXX_ai,
1799 NULL, 1304 .i_NbrDiChannel = 4,
1800 i_APCI3XXX_InsnConfigInitTTLIO, 1305 .i_NbrDoChannel = 4,
1801 i_APCI3XXX_InsnBitsTTLIO, 1306 .i_DoMaxdata = 1,
1802 i_APCI3XXX_InsnReadTTLIO, 1307 .b_AvailableConvertUnit = 7,
1803 i_APCI3XXX_InsnWriteTTLIO}, 1308 .ui_MinAcquisitiontimeNs = 2500,
1804 1309 .interrupt = v_APCI3XXX_Interrupt,
1805 {"apci3100-16-4", 1310 .reset = i_APCI3XXX_Reset,
1806 PCI_VENDOR_ID_ADDIDATA, 1311 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1807 0x301C, 1312 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1808 256, 1313 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1809 256, 1314 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1810 256, 1315 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1811 256, 1316 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1812 ADDIDATA_NO_EEPROM, 1317 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1813 ADDIDATA_9054, 1318 }, {
1814 16, 1319 .pc_DriverName = "apci3002-16",
1815 8, 1320 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1816 16, 1321 .i_DeviceId = 0x3002,
1817 4, 1322 .i_IorangeBase0 = 256,
1818 4095, 1323 .i_IorangeBase1 = 256,
1819 4095, 1324 .i_IorangeBase2 = 256,
1820 &range_apci3XXX_ai, 1325 .i_IorangeBase3 = 256,
1821 &range_apci3XXX_ao, 1326 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1822 0, 1327 .pc_EepromChip = ADDIDATA_9054,
1823 0, 1328 .i_NbrAiChannelDiff = 16,
1824 0, 1329 .i_AiChannelList = 16,
1825 24, 1330 .i_AiMaxdata = 65535,
1826 &range_apci3XXX_ttl, 1331 .pr_AiRangelist = &range_apci3XXX_ai,
1827 0, 1332 .i_NbrDiChannel = 4,
1828 0, 1333 .i_NbrDoChannel = 4,
1829 6, 1334 .i_DoMaxdata = 1,
1830 10000, 1335 .b_AvailableConvertUnit = 6,
1831 0, 1336 .ui_MinAcquisitiontimeNs = 5000,
1832 v_APCI3XXX_Interrupt, 1337 .interrupt = v_APCI3XXX_Interrupt,
1833 i_APCI3XXX_Reset, 1338 .reset = i_APCI3XXX_Reset,
1834 i_APCI3XXX_InsnConfigAnalogInput, 1339 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1835 i_APCI3XXX_InsnReadAnalogInput, 1340 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1836 NULL, 1341 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1837 NULL, 1342 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1838 NULL, 1343 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1839 NULL, 1344 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1840 NULL, 1345 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1841 NULL, 1346 }, {
1842 i_APCI3XXX_InsnWriteAnalogOutput, 1347 .pc_DriverName = "apci3002-8",
1843 NULL, 1348 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1844 NULL, 1349 .i_DeviceId = 0x3003,
1845 NULL, 1350 .i_IorangeBase0 = 256,
1846 NULL, 1351 .i_IorangeBase1 = 256,
1847 NULL, 1352 .i_IorangeBase2 = 256,
1848 NULL, 1353 .i_IorangeBase3 = 256,
1849 NULL, 1354 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1850 NULL, 1355 .pc_EepromChip = ADDIDATA_9054,
1851 NULL, 1356 .i_NbrAiChannelDiff = 8,
1852 NULL, 1357 .i_AiChannelList = 8,
1853 NULL, 1358 .i_AiMaxdata = 65535,
1854 NULL, 1359 .pr_AiRangelist = &range_apci3XXX_ai,
1855 NULL, 1360 .i_NbrDiChannel = 4,
1856 i_APCI3XXX_InsnConfigInitTTLIO, 1361 .i_NbrDoChannel = 4,
1857 i_APCI3XXX_InsnBitsTTLIO, 1362 .i_DoMaxdata = 1,
1858 i_APCI3XXX_InsnReadTTLIO, 1363 .b_AvailableConvertUnit = 6,
1859 i_APCI3XXX_InsnWriteTTLIO}, 1364 .ui_MinAcquisitiontimeNs = 5000,
1860 1365 .interrupt = v_APCI3XXX_Interrupt,
1861 {"apci3100-8-4", 1366 .reset = i_APCI3XXX_Reset,
1862 PCI_VENDOR_ID_ADDIDATA, 1367 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1863 0x301D, 1368 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1864 256, 1369 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1865 256, 1370 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1866 256, 1371 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1867 256, 1372 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1868 ADDIDATA_NO_EEPROM, 1373 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1869 ADDIDATA_9054, 1374 }, {
1870 8, 1375 .pc_DriverName = "apci3002-4",
1871 4, 1376 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1872 8, 1377 .i_DeviceId = 0x3004,
1873 4, 1378 .i_IorangeBase0 = 256,
1874 4095, 1379 .i_IorangeBase1 = 256,
1875 4095, 1380 .i_IorangeBase2 = 256,
1876 &range_apci3XXX_ai, 1381 .i_IorangeBase3 = 256,
1877 &range_apci3XXX_ao, 1382 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1878 0, 1383 .pc_EepromChip = ADDIDATA_9054,
1879 0, 1384 .i_NbrAiChannelDiff = 4,
1880 0, 1385 .i_AiChannelList = 4,
1881 24, 1386 .i_AiMaxdata = 65535,
1882 &range_apci3XXX_ttl, 1387 .pr_AiRangelist = &range_apci3XXX_ai,
1883 0, 1388 .i_NbrDiChannel = 4,
1884 0, 1389 .i_NbrDoChannel = 4,
1885 6, 1390 .i_DoMaxdata = 1,
1886 10000, 1391 .b_AvailableConvertUnit = 6,
1887 0, 1392 .ui_MinAcquisitiontimeNs = 5000,
1888 v_APCI3XXX_Interrupt, 1393 .interrupt = v_APCI3XXX_Interrupt,
1889 i_APCI3XXX_Reset, 1394 .reset = i_APCI3XXX_Reset,
1890 i_APCI3XXX_InsnConfigAnalogInput, 1395 .ai_config = i_APCI3XXX_InsnConfigAnalogInput,
1891 i_APCI3XXX_InsnReadAnalogInput, 1396 .ai_read = i_APCI3XXX_InsnReadAnalogInput,
1892 NULL, 1397 .di_read = i_APCI3XXX_InsnReadDigitalInput,
1893 NULL, 1398 .di_bits = i_APCI3XXX_InsnBitsDigitalInput,
1894 NULL, 1399 .do_write = i_APCI3XXX_InsnWriteDigitalOutput,
1895 NULL, 1400 .do_bits = i_APCI3XXX_InsnBitsDigitalOutput,
1896 NULL, 1401 .do_read = i_APCI3XXX_InsnReadDigitalOutput,
1897 NULL, 1402 }, {
1898 i_APCI3XXX_InsnWriteAnalogOutput, 1403 .pc_DriverName = "apci3500",
1899 NULL, 1404 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
1900 NULL, 1405 .i_DeviceId = 0x3024,
1901 NULL, 1406 .i_IorangeBase0 = 256,
1902 NULL, 1407 .i_IorangeBase1 = 256,
1903 NULL, 1408 .i_IorangeBase2 = 256,
1904 NULL, 1409 .i_IorangeBase3 = 256,
1905 NULL, 1410 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
1906 NULL, 1411 .pc_EepromChip = ADDIDATA_9054,
1907 NULL, 1412 .i_NbrAoChannel = 4,
1908 NULL, 1413 .i_AoMaxdata = 4095,
1909 NULL, 1414 .pr_AoRangelist = &range_apci3XXX_ao,
1910 NULL, 1415 .i_NbrTTLChannel = 24,
1911 NULL, 1416 .pr_TTLRangelist = &range_apci3XXX_ttl,
1912 i_APCI3XXX_InsnConfigInitTTLIO, 1417 .interrupt = v_APCI3XXX_Interrupt,
1913 i_APCI3XXX_InsnBitsTTLIO, 1418 .reset = i_APCI3XXX_Reset,
1914 i_APCI3XXX_InsnReadTTLIO, 1419 .ao_write = i_APCI3XXX_InsnWriteAnalogOutput,
1915 i_APCI3XXX_InsnWriteTTLIO}, 1420 .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO,
1916 1421 .ttl_bits = i_APCI3XXX_InsnBitsTTLIO,
1917 {"apci3106-16-4", 1422 .ttl_read = i_APCI3XXX_InsnReadTTLIO,
1918 PCI_VENDOR_ID_ADDIDATA, 1423 .ttl_write = i_APCI3XXX_InsnWriteTTLIO,
1919 0x301E, 1424 },
1920 256,
1921 256,
1922 256,
1923 256,
1924 ADDIDATA_NO_EEPROM,
1925 ADDIDATA_9054,
1926 16,
1927 8,
1928 16,
1929 4,
1930 65535,
1931 4095,
1932 &range_apci3XXX_ai,
1933 &range_apci3XXX_ao,
1934 0,
1935 0,
1936 0,
1937 24,
1938 &range_apci3XXX_ttl,
1939 0,
1940 0,
1941 6,
1942 10000,
1943 0,
1944 v_APCI3XXX_Interrupt,
1945 i_APCI3XXX_Reset,
1946 i_APCI3XXX_InsnConfigAnalogInput,
1947 i_APCI3XXX_InsnReadAnalogInput,
1948 NULL,
1949 NULL,
1950 NULL,
1951 NULL,
1952 NULL,
1953 NULL,
1954 i_APCI3XXX_InsnWriteAnalogOutput,
1955 NULL,
1956 NULL,
1957 NULL,
1958 NULL,
1959 NULL,
1960 NULL,
1961 NULL,
1962 NULL,
1963 NULL,
1964 NULL,
1965 NULL,
1966 NULL,
1967 NULL,
1968 i_APCI3XXX_InsnConfigInitTTLIO,
1969 i_APCI3XXX_InsnBitsTTLIO,
1970 i_APCI3XXX_InsnReadTTLIO,
1971 i_APCI3XXX_InsnWriteTTLIO},
1972
1973 {"apci3106-8-4",
1974 PCI_VENDOR_ID_ADDIDATA,
1975 0x301F,
1976 256,
1977 256,
1978 256,
1979 256,
1980 ADDIDATA_NO_EEPROM,
1981 ADDIDATA_9054,
1982 8,
1983 4,
1984 8,
1985 4,
1986 65535,
1987 4095,
1988 &range_apci3XXX_ai,
1989 &range_apci3XXX_ao,
1990 0,
1991 0,
1992 0,
1993 24,
1994 &range_apci3XXX_ttl,
1995 0,
1996 0,
1997 6,
1998 10000,
1999 0,
2000 v_APCI3XXX_Interrupt,
2001 i_APCI3XXX_Reset,
2002 i_APCI3XXX_InsnConfigAnalogInput,
2003 i_APCI3XXX_InsnReadAnalogInput,
2004 NULL,
2005 NULL,
2006 NULL,
2007 NULL,
2008 NULL,
2009 NULL,
2010 i_APCI3XXX_InsnWriteAnalogOutput,
2011 NULL,
2012 NULL,
2013 NULL,
2014 NULL,
2015 NULL,
2016 NULL,
2017 NULL,
2018 NULL,
2019 NULL,
2020 NULL,
2021 NULL,
2022 NULL,
2023 NULL,
2024 i_APCI3XXX_InsnConfigInitTTLIO,
2025 i_APCI3XXX_InsnBitsTTLIO,
2026 i_APCI3XXX_InsnReadTTLIO,
2027 i_APCI3XXX_InsnWriteTTLIO},
2028
2029 {"apci3110-16-4",
2030 PCI_VENDOR_ID_ADDIDATA,
2031 0x3020,
2032 256,
2033 256,
2034 256,
2035 256,
2036 ADDIDATA_NO_EEPROM,
2037 ADDIDATA_9054,
2038 16,
2039 8,
2040 16,
2041 4,
2042 4095,
2043 4095,
2044 &range_apci3XXX_ai,
2045 &range_apci3XXX_ao,
2046 4,
2047 4,
2048 1,
2049 24,
2050 &range_apci3XXX_ttl,
2051 0,
2052 0,
2053 6,
2054 5000,
2055 0,
2056 v_APCI3XXX_Interrupt,
2057 i_APCI3XXX_Reset,
2058 i_APCI3XXX_InsnConfigAnalogInput,
2059 i_APCI3XXX_InsnReadAnalogInput,
2060 NULL,
2061 NULL,
2062 NULL,
2063 NULL,
2064 NULL,
2065 NULL,
2066 i_APCI3XXX_InsnWriteAnalogOutput,
2067 NULL,
2068 NULL,
2069 i_APCI3XXX_InsnReadDigitalInput,
2070 NULL,
2071 i_APCI3XXX_InsnBitsDigitalInput,
2072 NULL,
2073 i_APCI3XXX_InsnWriteDigitalOutput,
2074 i_APCI3XXX_InsnBitsDigitalOutput,
2075 i_APCI3XXX_InsnReadDigitalOutput,
2076 NULL,
2077 NULL,
2078 NULL,
2079 NULL,
2080 i_APCI3XXX_InsnConfigInitTTLIO,
2081 i_APCI3XXX_InsnBitsTTLIO,
2082 i_APCI3XXX_InsnReadTTLIO,
2083 i_APCI3XXX_InsnWriteTTLIO},
2084
2085 {"apci3110-8-4",
2086 PCI_VENDOR_ID_ADDIDATA,
2087 0x3021,
2088 256,
2089 256,
2090 256,
2091 256,
2092 ADDIDATA_NO_EEPROM,
2093 ADDIDATA_9054,
2094 8,
2095 4,
2096 8,
2097 4,
2098 4095,
2099 4095,
2100 &range_apci3XXX_ai,
2101 &range_apci3XXX_ao,
2102 4,
2103 4,
2104 1,
2105 24,
2106 &range_apci3XXX_ttl,
2107 0,
2108 0,
2109 6,
2110 5000,
2111 0,
2112 v_APCI3XXX_Interrupt,
2113 i_APCI3XXX_Reset,
2114 i_APCI3XXX_InsnConfigAnalogInput,
2115 i_APCI3XXX_InsnReadAnalogInput,
2116 NULL,
2117 NULL,
2118 NULL,
2119 NULL,
2120 NULL,
2121 NULL,
2122 i_APCI3XXX_InsnWriteAnalogOutput,
2123 NULL,
2124 NULL,
2125 i_APCI3XXX_InsnReadDigitalInput,
2126 NULL,
2127 i_APCI3XXX_InsnBitsDigitalInput,
2128 NULL,
2129 i_APCI3XXX_InsnWriteDigitalOutput,
2130 i_APCI3XXX_InsnBitsDigitalOutput,
2131 i_APCI3XXX_InsnReadDigitalOutput,
2132 NULL,
2133 NULL,
2134 NULL,
2135 NULL,
2136 i_APCI3XXX_InsnConfigInitTTLIO,
2137 i_APCI3XXX_InsnBitsTTLIO,
2138 i_APCI3XXX_InsnReadTTLIO,
2139 i_APCI3XXX_InsnWriteTTLIO},
2140
2141 {"apci3116-16-4",
2142 PCI_VENDOR_ID_ADDIDATA,
2143 0x3022,
2144 256,
2145 256,
2146 256,
2147 256,
2148 ADDIDATA_NO_EEPROM,
2149 ADDIDATA_9054,
2150 16,
2151 8,
2152 16,
2153 4,
2154 65535,
2155 4095,
2156 &range_apci3XXX_ai,
2157 &range_apci3XXX_ao,
2158 4,
2159 4,
2160 1,
2161 24,
2162 &range_apci3XXX_ttl,
2163 0,
2164 0,
2165 6,
2166 5000,
2167 0,
2168 v_APCI3XXX_Interrupt,
2169 i_APCI3XXX_Reset,
2170 i_APCI3XXX_InsnConfigAnalogInput,
2171 i_APCI3XXX_InsnReadAnalogInput,
2172 NULL,
2173 NULL,
2174 NULL,
2175 NULL,
2176 NULL,
2177 NULL,
2178 i_APCI3XXX_InsnWriteAnalogOutput,
2179 NULL,
2180 NULL,
2181 i_APCI3XXX_InsnReadDigitalInput,
2182 NULL,
2183 i_APCI3XXX_InsnBitsDigitalInput,
2184 NULL,
2185 i_APCI3XXX_InsnWriteDigitalOutput,
2186 i_APCI3XXX_InsnBitsDigitalOutput,
2187 i_APCI3XXX_InsnReadDigitalOutput,
2188 NULL,
2189 NULL,
2190 NULL,
2191 NULL,
2192 i_APCI3XXX_InsnConfigInitTTLIO,
2193 i_APCI3XXX_InsnBitsTTLIO,
2194 i_APCI3XXX_InsnReadTTLIO,
2195 i_APCI3XXX_InsnWriteTTLIO},
2196
2197 {"apci3116-8-4",
2198 PCI_VENDOR_ID_ADDIDATA,
2199 0x3023,
2200 256,
2201 256,
2202 256,
2203 256,
2204 ADDIDATA_NO_EEPROM,
2205 ADDIDATA_9054,
2206 8,
2207 4,
2208 8,
2209 4,
2210 65535,
2211 4095,
2212 &range_apci3XXX_ai,
2213 &range_apci3XXX_ao,
2214 4,
2215 4,
2216 1,
2217 24,
2218 &range_apci3XXX_ttl,
2219 0,
2220 0,
2221 6,
2222 5000,
2223 0,
2224 v_APCI3XXX_Interrupt,
2225 i_APCI3XXX_Reset,
2226 i_APCI3XXX_InsnConfigAnalogInput,
2227 i_APCI3XXX_InsnReadAnalogInput,
2228 NULL,
2229 NULL,
2230 NULL,
2231 NULL,
2232 NULL,
2233 NULL,
2234 i_APCI3XXX_InsnWriteAnalogOutput,
2235 NULL,
2236 NULL,
2237 i_APCI3XXX_InsnReadDigitalInput,
2238 NULL,
2239 i_APCI3XXX_InsnBitsDigitalInput,
2240 NULL,
2241 i_APCI3XXX_InsnWriteDigitalOutput,
2242 i_APCI3XXX_InsnBitsDigitalOutput,
2243 i_APCI3XXX_InsnReadDigitalOutput,
2244 NULL,
2245 NULL,
2246 NULL,
2247 NULL,
2248 i_APCI3XXX_InsnConfigInitTTLIO,
2249 i_APCI3XXX_InsnBitsTTLIO,
2250 i_APCI3XXX_InsnReadTTLIO,
2251 i_APCI3XXX_InsnWriteTTLIO},
2252
2253 {"apci3003",
2254 PCI_VENDOR_ID_ADDIDATA,
2255 0x300B,
2256 256,
2257 256,
2258 256,
2259 256,
2260 ADDIDATA_NO_EEPROM,
2261 ADDIDATA_9054,
2262 0,
2263 4,
2264 4,
2265 0,
2266 65535,
2267 0,
2268 &range_apci3XXX_ai,
2269 NULL,
2270 4,
2271 4,
2272 1,
2273 0,
2274 NULL,
2275 0,
2276 0,
2277 7,
2278 2500,
2279 0,
2280 v_APCI3XXX_Interrupt,
2281 i_APCI3XXX_Reset,
2282 i_APCI3XXX_InsnConfigAnalogInput,
2283 i_APCI3XXX_InsnReadAnalogInput,
2284 NULL,
2285 NULL,
2286 NULL,
2287 NULL,
2288 NULL,
2289 NULL,
2290 NULL,
2291 NULL,
2292 NULL,
2293 i_APCI3XXX_InsnReadDigitalInput,
2294 NULL,
2295 i_APCI3XXX_InsnBitsDigitalInput,
2296 NULL,
2297 i_APCI3XXX_InsnWriteDigitalOutput,
2298 i_APCI3XXX_InsnBitsDigitalOutput,
2299 i_APCI3XXX_InsnReadDigitalOutput,
2300 NULL,
2301 NULL,
2302 NULL,
2303 NULL,
2304 NULL,
2305 NULL,
2306 NULL},
2307
2308 {"apci3002-16",
2309 PCI_VENDOR_ID_ADDIDATA,
2310 0x3002,
2311 256,
2312 256,
2313 256,
2314 256,
2315 ADDIDATA_NO_EEPROM,
2316 ADDIDATA_9054,
2317 0,
2318 16,
2319 16,
2320 0,
2321 65535,
2322 0,
2323 &range_apci3XXX_ai,
2324 NULL,
2325 4,
2326 4,
2327 1,
2328 0,
2329 NULL,
2330 0,
2331 0,
2332 6,
2333 5000,
2334 0,
2335 v_APCI3XXX_Interrupt,
2336 i_APCI3XXX_Reset,
2337 i_APCI3XXX_InsnConfigAnalogInput,
2338 i_APCI3XXX_InsnReadAnalogInput,
2339 NULL,
2340 NULL,
2341 NULL,
2342 NULL,
2343 NULL,
2344 NULL,
2345 NULL,
2346 NULL,
2347 NULL,
2348 i_APCI3XXX_InsnReadDigitalInput,
2349 NULL,
2350 i_APCI3XXX_InsnBitsDigitalInput,
2351 NULL,
2352 i_APCI3XXX_InsnWriteDigitalOutput,
2353 i_APCI3XXX_InsnBitsDigitalOutput,
2354 i_APCI3XXX_InsnReadDigitalOutput,
2355 NULL,
2356 NULL,
2357 NULL,
2358 NULL,
2359 NULL,
2360 NULL,
2361 NULL},
2362
2363 {"apci3002-8",
2364 PCI_VENDOR_ID_ADDIDATA,
2365 0x3003,
2366 256,
2367 256,
2368 256,
2369 256,
2370 ADDIDATA_NO_EEPROM,
2371 ADDIDATA_9054,
2372 0,
2373 8,
2374 8,
2375 0,
2376 65535,
2377 0,
2378 &range_apci3XXX_ai,
2379 NULL,
2380 4,
2381 4,
2382 1,
2383 0,
2384 NULL,
2385 0,
2386 0,
2387 6,
2388 5000,
2389 0,
2390 v_APCI3XXX_Interrupt,
2391 i_APCI3XXX_Reset,
2392 i_APCI3XXX_InsnConfigAnalogInput,
2393 i_APCI3XXX_InsnReadAnalogInput,
2394 NULL,
2395 NULL,
2396 NULL,
2397 NULL,
2398 NULL,
2399 NULL,
2400 NULL,
2401 NULL,
2402 NULL,
2403 i_APCI3XXX_InsnReadDigitalInput,
2404 NULL,
2405 i_APCI3XXX_InsnBitsDigitalInput,
2406 NULL,
2407 i_APCI3XXX_InsnWriteDigitalOutput,
2408 i_APCI3XXX_InsnBitsDigitalOutput,
2409 i_APCI3XXX_InsnReadDigitalOutput,
2410 NULL,
2411 NULL,
2412 NULL,
2413 NULL,
2414 NULL,
2415 NULL,
2416 NULL},
2417
2418 {"apci3002-4",
2419 PCI_VENDOR_ID_ADDIDATA,
2420 0x3004,
2421 256,
2422 256,
2423 256,
2424 256,
2425 ADDIDATA_NO_EEPROM,
2426 ADDIDATA_9054,
2427 0,
2428 4,
2429 4,
2430 0,
2431 65535,
2432 0,
2433 &range_apci3XXX_ai,
2434 NULL,
2435 4,
2436 4,
2437 1,
2438 0,
2439 NULL,
2440 0,
2441 0,
2442 6,
2443 5000,
2444 0,
2445 v_APCI3XXX_Interrupt,
2446 i_APCI3XXX_Reset,
2447 i_APCI3XXX_InsnConfigAnalogInput,
2448 i_APCI3XXX_InsnReadAnalogInput,
2449 NULL,
2450 NULL,
2451 NULL,
2452 NULL,
2453 NULL,
2454 NULL,
2455 NULL,
2456 NULL,
2457 NULL,
2458 i_APCI3XXX_InsnReadDigitalInput,
2459 NULL,
2460 i_APCI3XXX_InsnBitsDigitalInput,
2461 NULL,
2462 i_APCI3XXX_InsnWriteDigitalOutput,
2463 i_APCI3XXX_InsnBitsDigitalOutput,
2464 i_APCI3XXX_InsnReadDigitalOutput,
2465 NULL,
2466 NULL,
2467 NULL,
2468 NULL,
2469 NULL,
2470 NULL,
2471 NULL},
2472
2473 {"apci3500",
2474 PCI_VENDOR_ID_ADDIDATA,
2475 0x3024,
2476 256,
2477 256,
2478 256,
2479 256,
2480 ADDIDATA_NO_EEPROM,
2481 ADDIDATA_9054,
2482 0,
2483 0,
2484 0,
2485 4,
2486 0,
2487 4095,
2488 NULL,
2489 &range_apci3XXX_ao,
2490 0,
2491 0,
2492 0,
2493 24,
2494 &range_apci3XXX_ttl,
2495 0,
2496 0,
2497 0,
2498 0,
2499 0,
2500 v_APCI3XXX_Interrupt,
2501 i_APCI3XXX_Reset,
2502 NULL,
2503 NULL,
2504 NULL,
2505 NULL,
2506 NULL,
2507 NULL,
2508 NULL,
2509 NULL,
2510 i_APCI3XXX_InsnWriteAnalogOutput,
2511 NULL,
2512 NULL,
2513 NULL,
2514 NULL,
2515 NULL,
2516 NULL,
2517 NULL,
2518 NULL,
2519 NULL,
2520 NULL,
2521 NULL,
2522 NULL,
2523 NULL,
2524 i_APCI3XXX_InsnConfigInitTTLIO,
2525 i_APCI3XXX_InsnBitsTTLIO,
2526 i_APCI3XXX_InsnReadTTLIO,
2527 i_APCI3XXX_InsnWriteTTLIO},
2528#endif 1425#endif
2529}; 1426};
2530 1427
2531#define n_boardtypes (sizeof(boardtypes)/sizeof(struct addi_board))
2532
2533static struct comedi_driver driver_addi = { 1428static struct comedi_driver driver_addi = {
2534 .driver_name = ADDIDATA_DRIVER_NAME, 1429 .driver_name = ADDIDATA_DRIVER_NAME,
2535 .module = THIS_MODULE, 1430 .module = THIS_MODULE,
2536 .attach = i_ADDI_Attach, 1431 .attach = i_ADDI_Attach,
2537 .detach = i_ADDI_Detach, 1432 .detach = i_ADDI_Detach,
2538 .num_names = n_boardtypes, 1433 .num_names = ARRAY_SIZE(boardtypes),
2539 .board_name = &boardtypes[0].pc_DriverName, 1434 .board_name = &boardtypes[0].pc_DriverName,
2540 .offset = sizeof(struct addi_board), 1435 .offset = sizeof(struct addi_board),
2541}; 1436};
@@ -2543,7 +1438,7 @@ static struct comedi_driver driver_addi = {
2543static int __devinit driver_addi_pci_probe(struct pci_dev *dev, 1438static int __devinit driver_addi_pci_probe(struct pci_dev *dev,
2544 const struct pci_device_id *ent) 1439 const struct pci_device_id *ent)
2545{ 1440{
2546 return comedi_pci_auto_config(dev, driver_addi.driver_name); 1441 return comedi_pci_auto_config(dev, &driver_addi);
2547} 1442}
2548 1443
2549static void __devexit driver_addi_pci_remove(struct pci_dev *dev) 1444static void __devexit driver_addi_pci_remove(struct pci_dev *dev)
@@ -2821,16 +1716,13 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2821 /* Set the initialisation flag */ 1716 /* Set the initialisation flag */
2822 devpriv->b_AiInitialisation = 1; 1717 devpriv->b_AiInitialisation = 1;
2823 1718
2824 s->insn_config = 1719 s->insn_config = this_board->ai_config;
2825 this_board->i_hwdrv_InsnConfigAnalogInput; 1720 s->insn_read = this_board->ai_read;
2826 s->insn_read = this_board->i_hwdrv_InsnReadAnalogInput; 1721 s->insn_write = this_board->ai_write;
2827 s->insn_write = 1722 s->insn_bits = this_board->ai_bits;
2828 this_board->i_hwdrv_InsnWriteAnalogInput; 1723 s->do_cmdtest = this_board->ai_cmdtest;
2829 s->insn_bits = this_board->i_hwdrv_InsnBitsAnalogInput; 1724 s->do_cmd = this_board->ai_cmd;
2830 s->do_cmdtest = 1725 s->cancel = this_board->ai_cancel;
2831 this_board->i_hwdrv_CommandTestAnalogInput;
2832 s->do_cmd = this_board->i_hwdrv_CommandAnalogInput;
2833 s->cancel = this_board->i_hwdrv_CancelAnalogInput;
2834 1726
2835 } else { 1727 } else {
2836 s->type = COMEDI_SUBD_UNUSED; 1728 s->type = COMEDI_SUBD_UNUSED;
@@ -2846,10 +1738,8 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2846 s->len_chanlist = 1738 s->len_chanlist =
2847 devpriv->s_EeParameters.i_NbrAoChannel; 1739 devpriv->s_EeParameters.i_NbrAoChannel;
2848 s->range_table = this_board->pr_AoRangelist; 1740 s->range_table = this_board->pr_AoRangelist;
2849 s->insn_config = 1741 s->insn_config = this_board->ao_config;
2850 this_board->i_hwdrv_InsnConfigAnalogOutput; 1742 s->insn_write = this_board->ao_write;
2851 s->insn_write =
2852 this_board->i_hwdrv_InsnWriteAnalogOutput;
2853 } else { 1743 } else {
2854 s->type = COMEDI_SUBD_UNUSED; 1744 s->type = COMEDI_SUBD_UNUSED;
2855 } 1745 }
@@ -2864,12 +1754,10 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2864 devpriv->s_EeParameters.i_NbrDiChannel; 1754 devpriv->s_EeParameters.i_NbrDiChannel;
2865 s->range_table = &range_digital; 1755 s->range_table = &range_digital;
2866 s->io_bits = 0; /* all bits input */ 1756 s->io_bits = 0; /* all bits input */
2867 s->insn_config = 1757 s->insn_config = this_board->di_config;
2868 this_board->i_hwdrv_InsnConfigDigitalInput; 1758 s->insn_read = this_board->di_read;
2869 s->insn_read = this_board->i_hwdrv_InsnReadDigitalInput; 1759 s->insn_write = this_board->di_write;
2870 s->insn_write = 1760 s->insn_bits = this_board->di_bits;
2871 this_board->i_hwdrv_InsnWriteDigitalInput;
2872 s->insn_bits = this_board->i_hwdrv_InsnBitsDigitalInput;
2873 } else { 1761 } else {
2874 s->type = COMEDI_SUBD_UNUSED; 1762 s->type = COMEDI_SUBD_UNUSED;
2875 } 1763 }
@@ -2886,13 +1774,11 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2886 s->range_table = &range_digital; 1774 s->range_table = &range_digital;
2887 s->io_bits = 0xf; /* all bits output */ 1775 s->io_bits = 0xf; /* all bits output */
2888 1776
2889 s->insn_config = this_board->i_hwdrv_InsnConfigDigitalOutput; /* for digital output memory.. */ 1777 /* insn_config - for digital output memory */
2890 s->insn_write = 1778 s->insn_config = this_board->do_config;
2891 this_board->i_hwdrv_InsnWriteDigitalOutput; 1779 s->insn_write = this_board->do_write;
2892 s->insn_bits = 1780 s->insn_bits = this_board->do_bits;
2893 this_board->i_hwdrv_InsnBitsDigitalOutput; 1781 s->insn_read = this_board->do_read;
2894 s->insn_read =
2895 this_board->i_hwdrv_InsnReadDigitalOutput;
2896 } else { 1782 } else {
2897 s->type = COMEDI_SUBD_UNUSED; 1783 s->type = COMEDI_SUBD_UNUSED;
2898 } 1784 }
@@ -2907,10 +1793,10 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2907 s->len_chanlist = 1; 1793 s->len_chanlist = 1;
2908 s->range_table = &range_digital; 1794 s->range_table = &range_digital;
2909 1795
2910 s->insn_write = this_board->i_hwdrv_InsnWriteTimer; 1796 s->insn_write = this_board->timer_write;
2911 s->insn_read = this_board->i_hwdrv_InsnReadTimer; 1797 s->insn_read = this_board->timer_read;
2912 s->insn_config = this_board->i_hwdrv_InsnConfigTimer; 1798 s->insn_config = this_board->timer_config;
2913 s->insn_bits = this_board->i_hwdrv_InsnBitsTimer; 1799 s->insn_bits = this_board->timer_bits;
2914 } else { 1800 } else {
2915 s->type = COMEDI_SUBD_UNUSED; 1801 s->type = COMEDI_SUBD_UNUSED;
2916 } 1802 }
@@ -2926,10 +1812,10 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2926 s->io_bits = 0; /* all bits input */ 1812 s->io_bits = 0; /* all bits input */
2927 s->len_chanlist = this_board->i_NbrTTLChannel; 1813 s->len_chanlist = this_board->i_NbrTTLChannel;
2928 s->range_table = &range_digital; 1814 s->range_table = &range_digital;
2929 s->insn_config = this_board->i_hwdr_ConfigInitTTLIO; 1815 s->insn_config = this_board->ttl_config;
2930 s->insn_bits = this_board->i_hwdr_ReadTTLIOBits; 1816 s->insn_bits = this_board->ttl_bits;
2931 s->insn_read = this_board->i_hwdr_ReadTTLIOAllPortValue; 1817 s->insn_read = this_board->ttl_read;
2932 s->insn_write = this_board->i_hwdr_WriteTTLIOChlOnOff; 1818 s->insn_write = this_board->ttl_write;
2933 } else { 1819 } else {
2934 s->type = COMEDI_SUBD_UNUSED; 1820 s->type = COMEDI_SUBD_UNUSED;
2935 } 1821 }
@@ -2953,50 +1839,22 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2953 return 0; 1839 return 0;
2954} 1840}
2955 1841
2956/* 1842static void i_ADDI_Detach(struct comedi_device *dev)
2957+----------------------------------------------------------------------------+
2958| Function name : static int i_ADDI_Detach(struct comedi_device *dev) |
2959| |
2960| |
2961+----------------------------------------------------------------------------+
2962| Task : Deallocates resources of the addi_common driver |
2963| Free the DMA buffers, unregister irq. |
2964| |
2965+----------------------------------------------------------------------------+
2966| Input Parameters : struct comedi_device *dev |
2967| |
2968| |
2969+----------------------------------------------------------------------------+
2970| Return Value : 0 |
2971| |
2972+----------------------------------------------------------------------------+
2973*/
2974
2975static int i_ADDI_Detach(struct comedi_device *dev)
2976{ 1843{
2977
2978 if (dev->private) { 1844 if (dev->private) {
2979 if (devpriv->b_ValidDriver) { 1845 if (devpriv->b_ValidDriver)
2980 i_ADDI_Reset(dev); 1846 i_ADDI_Reset(dev);
2981 } 1847 if (dev->irq)
2982
2983 if (dev->irq) {
2984 free_irq(dev->irq, dev); 1848 free_irq(dev->irq, dev);
2985 } 1849 if ((this_board->pc_EepromChip == NULL) ||
2986 1850 (strcmp(this_board->pc_EepromChip, ADDIDATA_9054) != 0)) {
2987 if ((this_board->pc_EepromChip == NULL) 1851 if (devpriv->allocated)
2988 || (strcmp(this_board->pc_EepromChip,
2989 ADDIDATA_9054) != 0)) {
2990 if (devpriv->allocated) {
2991 i_pci_card_free(devpriv->amcc); 1852 i_pci_card_free(devpriv->amcc);
2992 }
2993
2994 if (devpriv->ul_DmaBufferVirtual[0]) { 1853 if (devpriv->ul_DmaBufferVirtual[0]) {
2995 free_pages((unsigned long)devpriv-> 1854 free_pages((unsigned long)devpriv->
2996 ul_DmaBufferVirtual[0], 1855 ul_DmaBufferVirtual[0],
2997 devpriv->ui_DmaBufferPages[0]); 1856 devpriv->ui_DmaBufferPages[0]);
2998 } 1857 }
2999
3000 if (devpriv->ul_DmaBufferVirtual[1]) { 1858 if (devpriv->ul_DmaBufferVirtual[1]) {
3001 free_pages((unsigned long)devpriv-> 1859 free_pages((unsigned long)devpriv->
3002 ul_DmaBufferVirtual[1], 1860 ul_DmaBufferVirtual[1],
@@ -3004,20 +1862,14 @@ static int i_ADDI_Detach(struct comedi_device *dev)
3004 } 1862 }
3005 } else { 1863 } else {
3006 iounmap(devpriv->dw_AiBase); 1864 iounmap(devpriv->dw_AiBase);
3007 1865 if (devpriv->allocated)
3008 if (devpriv->allocated) {
3009 i_pci_card_free(devpriv->amcc); 1866 i_pci_card_free(devpriv->amcc);
3010 }
3011 } 1867 }
3012
3013 if (pci_list_builded) { 1868 if (pci_list_builded) {
3014 /* v_pci_card_list_cleanup(PCI_VENDOR_ID_AMCC); */
3015 v_pci_card_list_cleanup(this_board->i_VendorId); 1869 v_pci_card_list_cleanup(this_board->i_VendorId);
3016 pci_list_builded = 0; 1870 pci_list_builded = 0;
3017 } 1871 }
3018 } 1872 }
3019
3020 return 0;
3021} 1873}
3022 1874
3023/* 1875/*
@@ -3041,7 +1893,7 @@ static int i_ADDI_Detach(struct comedi_device *dev)
3041static int i_ADDI_Reset(struct comedi_device *dev) 1893static int i_ADDI_Reset(struct comedi_device *dev)
3042{ 1894{
3043 1895
3044 this_board->i_hwdrv_Reset(dev); 1896 this_board->reset(dev);
3045 return 0; 1897 return 0;
3046} 1898}
3047 1899
@@ -3067,7 +1919,7 @@ static int i_ADDI_Reset(struct comedi_device *dev)
3067static irqreturn_t v_ADDI_Interrupt(int irq, void *d) 1919static irqreturn_t v_ADDI_Interrupt(int irq, void *d)
3068{ 1920{
3069 struct comedi_device *dev = d; 1921 struct comedi_device *dev = d;
3070 this_board->v_hwdrv_Interrupt(irq, d); 1922 this_board->interrupt(irq, d);
3071 return IRQ_RETVAL(1); 1923 return IRQ_RETVAL(1);
3072} 1924}
3073 1925
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.h b/drivers/staging/comedi/drivers/addi-data/addi_common.h
index c6980b7dfea0..2c3f34703dd2 100644
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.h
+++ b/drivers/staging/comedi/drivers/addi-data/addi_common.h
@@ -94,111 +94,72 @@ struct addi_board {
94 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */ 94 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */
95 95
96 /* interrupt and reset */ 96 /* interrupt and reset */
97 void (*v_hwdrv_Interrupt)(int irq, void *d); 97 void (*interrupt)(int irq, void *d);
98 int (*i_hwdrv_Reset)(struct comedi_device *dev); 98 int (*reset)(struct comedi_device *);
99 99
100 /* Subdevice functions */ 100 /* Subdevice functions */
101 101
102 /* ANALOG INPUT */ 102 /* ANALOG INPUT */
103 int (*i_hwdrv_InsnConfigAnalogInput)(struct comedi_device *dev, 103 int (*ai_config)(struct comedi_device *, struct comedi_subdevice *,
104 struct comedi_subdevice *s, 104 struct comedi_insn *, unsigned int *);
105 struct comedi_insn *insn, 105 int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
106 unsigned int *data); 106 struct comedi_insn *, unsigned int *);
107 int (*i_hwdrv_InsnReadAnalogInput)(struct comedi_device *dev, 107 int (*ai_write)(struct comedi_device *, struct comedi_subdevice *,
108 struct comedi_subdevice *s, 108 struct comedi_insn *, unsigned int *);
109 struct comedi_insn *insn, 109 int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
110 unsigned int *data); 110 struct comedi_insn *, unsigned int *);
111 int (*i_hwdrv_InsnWriteAnalogInput)(struct comedi_device *dev, 111 int (*ai_cmdtest)(struct comedi_device *, struct comedi_subdevice *,
112 struct comedi_subdevice *s, 112 struct comedi_cmd *);
113 struct comedi_insn *insn, 113 int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
114 unsigned int *data); 114 int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
115 int (*i_hwdrv_InsnBitsAnalogInput)(struct comedi_device *dev,
116 struct comedi_subdevice *s,
117 struct comedi_insn *insn,
118 unsigned int *data);
119 int (*i_hwdrv_CommandTestAnalogInput)(struct comedi_device *dev,
120 struct comedi_subdevice *s,
121 struct comedi_cmd *cmd);
122 int (*i_hwdrv_CommandAnalogInput)(struct comedi_device *dev,
123 struct comedi_subdevice *s);
124 int (*i_hwdrv_CancelAnalogInput)(struct comedi_device *dev,
125 struct comedi_subdevice *s);
126 115
127 /* Analog Output */ 116 /* Analog Output */
128 int (*i_hwdrv_InsnConfigAnalogOutput)(struct comedi_device *dev, 117 int (*ao_config)(struct comedi_device *, struct comedi_subdevice *,
129 struct comedi_subdevice *s, 118 struct comedi_insn *, unsigned int *);
130 struct comedi_insn *insn, 119 int (*ao_write)(struct comedi_device *, struct comedi_subdevice *,
131 unsigned int *data); 120 struct comedi_insn *, unsigned int *);
132 int (*i_hwdrv_InsnWriteAnalogOutput)(struct comedi_device *dev, 121 int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *,
133 struct comedi_subdevice *s, 122 struct comedi_insn *, unsigned int *);
134 struct comedi_insn *insn,
135 unsigned int *data);
136 int (*i_hwdrv_InsnBitsAnalogOutput)(struct comedi_device *dev,
137 struct comedi_subdevice *s,
138 struct comedi_insn *insn,
139 unsigned int *data);
140 123
141 /* Digital Input */ 124 /* Digital Input */
142 int (*i_hwdrv_InsnConfigDigitalInput) (struct comedi_device *dev, 125 int (*di_config)(struct comedi_device *, struct comedi_subdevice *,
143 struct comedi_subdevice *s, 126 struct comedi_insn *, unsigned int *);
144 struct comedi_insn *insn, 127 int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
145 unsigned int *data); 128 struct comedi_insn *, unsigned int *);
146 int (*i_hwdrv_InsnReadDigitalInput) (struct comedi_device *dev, 129 int (*di_write)(struct comedi_device *, struct comedi_subdevice *,
147 struct comedi_subdevice *s, 130 struct comedi_insn *, unsigned int *);
148 struct comedi_insn *insn, 131 int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
149 unsigned int *data); 132 struct comedi_insn *, unsigned int *);
150 int (*i_hwdrv_InsnWriteDigitalInput) (struct comedi_device *dev,
151 struct comedi_subdevice *s,
152 struct comedi_insn *insn,
153 unsigned int *data);
154 int (*i_hwdrv_InsnBitsDigitalInput) (struct comedi_device *dev,
155 struct comedi_subdevice *s,
156 struct comedi_insn *insn,
157 unsigned int *data);
158 133
159 /* Digital Output */ 134 /* Digital Output */
160 int (*i_hwdrv_InsnConfigDigitalOutput)(struct comedi_device *dev, 135 int (*do_config)(struct comedi_device *, struct comedi_subdevice *,
161 struct comedi_subdevice *s, 136 struct comedi_insn *, unsigned int *);
162 struct comedi_insn *insn, 137 int (*do_write)(struct comedi_device *, struct comedi_subdevice *,
163 unsigned int *data); 138 struct comedi_insn *, unsigned int *);
164 int (*i_hwdrv_InsnWriteDigitalOutput)(struct comedi_device *dev, 139 int (*do_bits)(struct comedi_device *, struct comedi_subdevice *,
165 struct comedi_subdevice *s, 140 struct comedi_insn *, unsigned int *);
166 struct comedi_insn *insn, 141 int (*do_read)(struct comedi_device *, struct comedi_subdevice *,
167 unsigned int *data); 142 struct comedi_insn *, unsigned int *);
168 int (*i_hwdrv_InsnBitsDigitalOutput)(struct comedi_device *dev,
169 struct comedi_subdevice *s,
170 struct comedi_insn *insn,
171 unsigned int *data);
172 int (*i_hwdrv_InsnReadDigitalOutput)(struct comedi_device *dev,
173 struct comedi_subdevice *s,
174 struct comedi_insn *insn,
175 unsigned int *data);
176 143
177 /* TIMER */ 144 /* TIMER */
178 int (*i_hwdrv_InsnConfigTimer)(struct comedi_device *dev, 145 int (*timer_config)(struct comedi_device *, struct comedi_subdevice *,
179 struct comedi_subdevice *s, 146 struct comedi_insn *, unsigned int *);
180 struct comedi_insn *insn, unsigned int *data); 147 int (*timer_write)(struct comedi_device *, struct comedi_subdevice *,
181 int (*i_hwdrv_InsnWriteTimer)(struct comedi_device *dev, 148 struct comedi_insn *, unsigned int *);
182 struct comedi_subdevice *s, struct comedi_insn *insn, 149 int (*timer_read)(struct comedi_device *, struct comedi_subdevice *,
183 unsigned int *data); 150 struct comedi_insn *, unsigned int *);
184 int (*i_hwdrv_InsnReadTimer)(struct comedi_device *dev, struct comedi_subdevice *s, 151 int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *,
185 struct comedi_insn *insn, unsigned int *data); 152 struct comedi_insn *, unsigned int *);
186 int (*i_hwdrv_InsnBitsTimer)(struct comedi_device *dev, struct comedi_subdevice *s,
187 struct comedi_insn *insn, unsigned int *data);
188 153
189 /* TTL IO */ 154 /* TTL IO */
190 int (*i_hwdr_ConfigInitTTLIO)(struct comedi_device *dev, 155 int (*ttl_config)(struct comedi_device *, struct comedi_subdevice *,
191 struct comedi_subdevice *s, struct comedi_insn *insn, 156 struct comedi_insn *, unsigned int *);
192 unsigned int *data); 157 int (*ttl_bits)(struct comedi_device *, struct comedi_subdevice *,
193 int (*i_hwdr_ReadTTLIOBits)(struct comedi_device *dev, struct comedi_subdevice *s, 158 struct comedi_insn *, unsigned int *);
194 struct comedi_insn *insn, unsigned int *data); 159 int (*ttl_read)(struct comedi_device *, struct comedi_subdevice *,
195 int (*i_hwdr_ReadTTLIOAllPortValue)(struct comedi_device *dev, 160 struct comedi_insn *, unsigned int *);
196 struct comedi_subdevice *s, 161 int (*ttl_write)(struct comedi_device *, struct comedi_subdevice *,
197 struct comedi_insn *insn, 162 struct comedi_insn *, unsigned int *);
198 unsigned int *data);
199 int (*i_hwdr_WriteTTLIOChlOnOff)(struct comedi_device *dev,
200 struct comedi_subdevice *s,
201 struct comedi_insn *insn, unsigned int *data);
202}; 163};
203 164
204/* MODULE INFO STRUCTURE */ 165/* MODULE INFO STRUCTURE */
@@ -455,7 +416,7 @@ static unsigned short pci_list_builded; /* set to 1 when list of card is known *
455 416
456/* Function declarations */ 417/* Function declarations */
457static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it); 418static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it);
458static int i_ADDI_Detach(struct comedi_device *dev); 419static void i_ADDI_Detach(struct comedi_device *dev);
459static int i_ADDI_Reset(struct comedi_device *dev); 420static int i_ADDI_Reset(struct comedi_device *dev);
460 421
461static irqreturn_t v_ADDI_Interrupt(int irq, void *d); 422static irqreturn_t v_ADDI_Interrupt(int irq, void *d);
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
index e886ced4978f..ffe390c6da83 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
@@ -156,7 +156,7 @@ int i_APCI3120_InsnReadAnalogInput(struct comedi_device *dev, struct comedi_subd
156 } else 156 } else
157 us_ConvertTiming = (unsigned short) (devpriv->ui_EocEosConversionTime / 1000); /* nano to useconds */ 157 us_ConvertTiming = (unsigned short) (devpriv->ui_EocEosConversionTime / 1000); /* nano to useconds */
158 158
159 /* this_board->i_hwdrv_InsnReadAnalogInput(dev,us_ConvertTiming,insn->n,&insn->chanspec,data,insn->unused[0]); */ 159 /* this_board->ai_read(dev,us_ConvertTiming,insn->n,&insn->chanspec,data,insn->unused[0]); */
160 160
161 /* Clear software registers */ 161 /* Clear software registers */
162 devpriv->b_TimerSelectMode = 0; 162 devpriv->b_TimerSelectMode = 0;
@@ -670,7 +670,7 @@ int i_APCI3120_CommandAnalogInput(struct comedi_device *dev, struct comedi_subde
670 /* mode 1 */ 670 /* mode 1 */
671 671
672 devpriv->ui_AiTimer0 = cmd->convert_arg; /* timer constant in nano seconds */ 672 devpriv->ui_AiTimer0 = cmd->convert_arg; /* timer constant in nano seconds */
673 /* return this_board->i_hwdrv_CommandAnalogInput(1,dev,s); */ 673 /* return this_board->ai_cmd(1,dev,s); */
674 return i_APCI3120_CyclicAnalogInput(1, dev, s); 674 return i_APCI3120_CyclicAnalogInput(1, dev, s);
675 } 675 }
676 676
@@ -680,7 +680,7 @@ int i_APCI3120_CommandAnalogInput(struct comedi_device *dev, struct comedi_subde
680 /* mode 2 */ 680 /* mode 2 */
681 devpriv->ui_AiTimer1 = cmd->scan_begin_arg; 681 devpriv->ui_AiTimer1 = cmd->scan_begin_arg;
682 devpriv->ui_AiTimer0 = cmd->convert_arg; /* variable changed timer2 to timer0 */ 682 devpriv->ui_AiTimer0 = cmd->convert_arg; /* variable changed timer2 to timer0 */
683 /* return this_board->i_hwdrv_CommandAnalogInput(2,dev,s); */ 683 /* return this_board->ai_cmd(2,dev,s); */
684 return i_APCI3120_CyclicAnalogInput(2, dev, s); 684 return i_APCI3120_CyclicAnalogInput(2, dev, s);
685 } 685 }
686 return -1; 686 return -1;
@@ -1922,7 +1922,7 @@ int i_APCI3120_InsnConfigTimer(struct comedi_device *dev, struct comedi_subdevic
1922 1922
1923 ui_Timervalue2 = data[1] / 1000; /* convert nano seconds to u seconds */ 1923 ui_Timervalue2 = data[1] / 1000; /* convert nano seconds to u seconds */
1924 1924
1925 /* this_board->i_hwdrv_InsnConfigTimer(dev, ui_Timervalue2,(unsigned char)data[0]); */ 1925 /* this_board->timer_config(dev, ui_Timervalue2,(unsigned char)data[0]); */
1926 us_TmpValue = (unsigned short) inw(devpriv->iobase + APCI3120_RD_STATUS); 1926 us_TmpValue = (unsigned short) inw(devpriv->iobase + APCI3120_RD_STATUS);
1927 1927
1928/* 1928/*
@@ -2092,7 +2092,7 @@ int i_APCI3120_InsnWriteTimer(struct comedi_device *dev, struct comedi_subdevice
2092 ui_Timervalue2 = 0; 2092 ui_Timervalue2 = 0;
2093 } 2093 }
2094 2094
2095 /* this_board->i_hwdrv_InsnWriteTimer(dev,data[0],ui_Timervalue2); */ 2095 /* this_board->timer_write(dev,data[0],ui_Timervalue2); */
2096 2096
2097 switch (data[0]) { 2097 switch (data[0]) {
2098 case APCI3120_START: 2098 case APCI3120_START:
@@ -2260,7 +2260,7 @@ int i_APCI3120_InsnReadTimer(struct comedi_device *dev, struct comedi_subdevice
2260 comedi_error(dev, "\nread:timer2 not configured "); 2260 comedi_error(dev, "\nread:timer2 not configured ");
2261 } 2261 }
2262 2262
2263 /* this_board->i_hwdrv_InsnReadTimer(dev,data); */ 2263 /* this_board->timer_read(dev,data); */
2264 if (devpriv->b_Timer2Mode == APCI3120_TIMER) { 2264 if (devpriv->b_Timer2Mode == APCI3120_TIMER) {
2265 2265
2266 /* Read the LOW unsigned short of Timer 2 register */ 2266 /* Read the LOW unsigned short of Timer 2 register */
@@ -2331,7 +2331,7 @@ int i_APCI3120_InsnReadDigitalInput(struct comedi_device *dev,
2331 2331
2332 ui_Chan = CR_CHAN(insn->chanspec); /* channel specified */ 2332 ui_Chan = CR_CHAN(insn->chanspec); /* channel specified */
2333 2333
2334 /* this_board->i_hwdrv_InsnReadDigitalInput(dev,ui_Chan,data); */ 2334 /* this_board->di_read(dev,ui_Chan,data); */
2335 if (ui_Chan <= 3) { 2335 if (ui_Chan <= 3) {
2336 ui_TmpValue = (unsigned int) inw(devpriv->iobase + APCI3120_RD_STATUS); 2336 ui_TmpValue = (unsigned int) inw(devpriv->iobase + APCI3120_RD_STATUS);
2337 2337
@@ -2379,7 +2379,7 @@ int i_APCI3120_InsnBitsDigitalInput(struct comedi_device *dev, struct comedi_sub
2379 *****/ 2379 *****/
2380 2380
2381 *data = (ui_TmpValue >> 8) & 0xf; 2381 *data = (ui_TmpValue >> 8) & 0xf;
2382 /* this_board->i_hwdrv_InsnBitsDigitalInput(dev,data); */ 2382 /* this_board->di_bits(dev,data); */
2383 return insn->n; 2383 return insn->n;
2384} 2384}
2385 2385
@@ -2595,7 +2595,7 @@ int i_APCI3120_InsnWriteAnalogOutput(struct comedi_device *dev,
2595 ui_Range = CR_RANGE(insn->chanspec); 2595 ui_Range = CR_RANGE(insn->chanspec);
2596 ui_Channel = CR_CHAN(insn->chanspec); 2596 ui_Channel = CR_CHAN(insn->chanspec);
2597 2597
2598 /* this_board->i_hwdrv_InsnWriteAnalogOutput(dev, ui_Range, ui_Channel,data[0]); */ 2598 /* this_board->ao_write(dev, ui_Range, ui_Channel,data[0]); */
2599 if (ui_Range) { /* if 1 then unipolar */ 2599 if (ui_Range) { /* if 1 then unipolar */
2600 2600
2601 if (data[0] != 0) 2601 if (data[0] != 0)
diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c
index 4fc9e8520217..de8c68af3210 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -54,8 +54,6 @@ References:
54#include "../comedidev.h" 54#include "../comedidev.h"
55#include "comedi_pci.h" 55#include "comedi_pci.h"
56 56
57#define PCI6208_DRIVER_NAME "adl_pci6208"
58
59/* Board descriptions */ 57/* Board descriptions */
60struct pci6208_board { 58struct pci6208_board {
61 const char *name; 59 const char *name;
@@ -85,17 +83,6 @@ static const struct pci6208_board pci6208_boards[] = {
85 } 83 }
86}; 84};
87 85
88/* This is used by modprobe to translate PCI IDs to drivers. Should
89 * only be used for PCI and ISA-PnP devices */
90static DEFINE_PCI_DEVICE_TABLE(pci6208_pci_table) = {
91 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
92 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
93 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
94 { 0 }
95};
96
97MODULE_DEVICE_TABLE(pci, pci6208_pci_table);
98
99/* Will be initialized in pci6208_find device(). */ 86/* Will be initialized in pci6208_find device(). */
100#define thisboard ((const struct pci6208_board *)dev->board_ptr) 87#define thisboard ((const struct pci6208_board *)dev->board_ptr)
101 88
@@ -107,157 +94,6 @@ struct pci6208_private {
107 94
108#define devpriv ((struct pci6208_private *)dev->private) 95#define devpriv ((struct pci6208_private *)dev->private)
109 96
110static int pci6208_attach(struct comedi_device *dev,
111 struct comedi_devconfig *it);
112static int pci6208_detach(struct comedi_device *dev);
113
114static struct comedi_driver driver_pci6208 = {
115 .driver_name = PCI6208_DRIVER_NAME,
116 .module = THIS_MODULE,
117 .attach = pci6208_attach,
118 .detach = pci6208_detach,
119};
120
121static int __devinit driver_pci6208_pci_probe(struct pci_dev *dev,
122 const struct pci_device_id *ent)
123{
124 return comedi_pci_auto_config(dev, driver_pci6208.driver_name);
125}
126
127static void __devexit driver_pci6208_pci_remove(struct pci_dev *dev)
128{
129 comedi_pci_auto_unconfig(dev);
130}
131
132static struct pci_driver driver_pci6208_pci_driver = {
133 .id_table = pci6208_pci_table,
134 .probe = &driver_pci6208_pci_probe,
135 .remove = __devexit_p(&driver_pci6208_pci_remove)
136};
137
138static int __init driver_pci6208_init_module(void)
139{
140 int retval;
141
142 retval = comedi_driver_register(&driver_pci6208);
143 if (retval < 0)
144 return retval;
145
146 driver_pci6208_pci_driver.name = (char *)driver_pci6208.driver_name;
147 return pci_register_driver(&driver_pci6208_pci_driver);
148}
149
150static void __exit driver_pci6208_cleanup_module(void)
151{
152 pci_unregister_driver(&driver_pci6208_pci_driver);
153 comedi_driver_unregister(&driver_pci6208);
154}
155
156module_init(driver_pci6208_init_module);
157module_exit(driver_pci6208_cleanup_module);
158
159static int pci6208_find_device(struct comedi_device *dev, int bus, int slot);
160static int
161pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr,
162 int dev_minor);
163
164/*read/write functions*/
165static int pci6208_ao_winsn(struct comedi_device *dev,
166 struct comedi_subdevice *s,
167 struct comedi_insn *insn, unsigned int *data);
168static int pci6208_ao_rinsn(struct comedi_device *dev,
169 struct comedi_subdevice *s,
170 struct comedi_insn *insn, unsigned int *data);
171/* static int pci6208_dio_insn_bits (struct comedi_device *dev,
172 * struct comedi_subdevice *s, */
173/* struct comedi_insn *insn,unsigned int *data); */
174/* static int pci6208_dio_insn_config(struct comedi_device *dev,
175 * struct comedi_subdevice *s, */
176/* struct comedi_insn *insn,unsigned int *data); */
177
178/*
179 * Attach is called by the Comedi core to configure the driver
180 * for a particular board. If you specified a board_name array
181 * in the driver structure, dev->board_ptr contains that
182 * address.
183 */
184static int pci6208_attach(struct comedi_device *dev,
185 struct comedi_devconfig *it)
186{
187 struct comedi_subdevice *s;
188 int retval;
189 unsigned long io_base;
190
191 printk(KERN_INFO "comedi%d: pci6208: ", dev->minor);
192
193 retval = alloc_private(dev, sizeof(struct pci6208_private));
194 if (retval < 0)
195 return retval;
196
197 retval = pci6208_find_device(dev, it->options[0], it->options[1]);
198 if (retval < 0)
199 return retval;
200
201 retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor);
202 if (retval < 0)
203 return retval;
204
205 dev->iobase = io_base;
206 dev->board_name = thisboard->name;
207
208/*
209 * Allocate the subdevice structures. alloc_subdevice() is a
210 * convenient macro defined in comedidev.h.
211 */
212 if (alloc_subdevices(dev, 2) < 0)
213 return -ENOMEM;
214
215 s = dev->subdevices + 0;
216 /* analog output subdevice */
217 s->type = COMEDI_SUBD_AO;
218 s->subdev_flags = SDF_WRITABLE; /* anything else to add here?? */
219 s->n_chan = thisboard->ao_chans;
220 s->maxdata = 0xffff; /* 16-bit DAC */
221 s->range_table = &range_bipolar10; /* this needs to be checked. */
222 s->insn_write = pci6208_ao_winsn;
223 s->insn_read = pci6208_ao_rinsn;
224
225 /* s=dev->subdevices+1; */
226 /* digital i/o subdevice */
227 /* s->type=COMEDI_SUBD_DIO; */
228 /* s->subdev_flags=SDF_READABLE|SDF_WRITABLE; */
229 /* s->n_chan=16; */
230 /* s->maxdata=1; */
231 /* s->range_table=&range_digital; */
232 /* s->insn_bits = pci6208_dio_insn_bits; */
233 /* s->insn_config = pci6208_dio_insn_config; */
234
235 printk(KERN_INFO "attached\n");
236
237 return 1;
238}
239
240/*
241 * _detach is called to deconfigure a device. It should deallocate
242 * resources.
243 * This function is also called when _attach() fails, so it should be
244 * careful not to release resources that were not necessarily
245 * allocated by _attach(). dev->private and dev->subdevices are
246 * deallocated automatically by the core.
247 */
248static int pci6208_detach(struct comedi_device *dev)
249{
250 printk(KERN_INFO "comedi%d: pci6208: remove\n", dev->minor);
251
252 if (devpriv && devpriv->pci_dev) {
253 if (dev->iobase)
254 comedi_pci_disable(devpriv->pci_dev);
255 pci_dev_put(devpriv->pci_dev);
256 }
257
258 return 0;
259}
260
261static int pci6208_ao_winsn(struct comedi_device *dev, 97static int pci6208_ao_winsn(struct comedi_device *dev,
262 struct comedi_subdevice *s, 98 struct comedi_subdevice *s,
263 struct comedi_insn *insn, unsigned int *data) 99 struct comedi_insn *insn, unsigned int *data)
@@ -410,7 +246,7 @@ pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr,
410 unsigned long io_base, io_range, lcr_io_base, lcr_io_range; 246 unsigned long io_base, io_range, lcr_io_base, lcr_io_range;
411 247
412 /* Enable PCI device and request regions */ 248 /* Enable PCI device and request regions */
413 if (comedi_pci_enable(pci_dev, PCI6208_DRIVER_NAME) < 0) { 249 if (comedi_pci_enable(pci_dev, "adl_pci6208") < 0) {
414 printk(KERN_ERR "comedi%d: Failed to enable PCI device " 250 printk(KERN_ERR "comedi%d: Failed to enable PCI device "
415 "and request regions\n", 251 "and request regions\n",
416 dev_minor); 252 dev_minor);
@@ -442,6 +278,103 @@ pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr,
442 return 0; 278 return 0;
443} 279}
444 280
281static int pci6208_attach(struct comedi_device *dev,
282 struct comedi_devconfig *it)
283{
284 struct comedi_subdevice *s;
285 int retval;
286 unsigned long io_base;
287
288 printk(KERN_INFO "comedi%d: pci6208: ", dev->minor);
289
290 retval = alloc_private(dev, sizeof(struct pci6208_private));
291 if (retval < 0)
292 return retval;
293
294 retval = pci6208_find_device(dev, it->options[0], it->options[1]);
295 if (retval < 0)
296 return retval;
297
298 retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor);
299 if (retval < 0)
300 return retval;
301
302 dev->iobase = io_base;
303 dev->board_name = thisboard->name;
304
305 if (alloc_subdevices(dev, 2) < 0)
306 return -ENOMEM;
307
308 s = dev->subdevices + 0;
309 /* analog output subdevice */
310 s->type = COMEDI_SUBD_AO;
311 s->subdev_flags = SDF_WRITABLE; /* anything else to add here?? */
312 s->n_chan = thisboard->ao_chans;
313 s->maxdata = 0xffff; /* 16-bit DAC */
314 s->range_table = &range_bipolar10; /* this needs to be checked. */
315 s->insn_write = pci6208_ao_winsn;
316 s->insn_read = pci6208_ao_rinsn;
317
318 /* s=dev->subdevices+1; */
319 /* digital i/o subdevice */
320 /* s->type=COMEDI_SUBD_DIO; */
321 /* s->subdev_flags=SDF_READABLE|SDF_WRITABLE; */
322 /* s->n_chan=16; */
323 /* s->maxdata=1; */
324 /* s->range_table=&range_digital; */
325 /* s->insn_bits = pci6208_dio_insn_bits; */
326 /* s->insn_config = pci6208_dio_insn_config; */
327
328 printk(KERN_INFO "attached\n");
329
330 return 1;
331}
332
333static void pci6208_detach(struct comedi_device *dev)
334{
335 if (devpriv && devpriv->pci_dev) {
336 if (dev->iobase)
337 comedi_pci_disable(devpriv->pci_dev);
338 pci_dev_put(devpriv->pci_dev);
339 }
340}
341
342static struct comedi_driver adl_pci6208_driver = {
343 .driver_name = "adl_pci6208",
344 .module = THIS_MODULE,
345 .attach = pci6208_attach,
346 .detach = pci6208_detach,
347};
348
349static int __devinit adl_pci6208_pci_probe(struct pci_dev *dev,
350 const struct pci_device_id *ent)
351{
352 return comedi_pci_auto_config(dev, &adl_pci6208_driver);
353}
354
355static void __devexit adl_pci6208_pci_remove(struct pci_dev *dev)
356{
357 comedi_pci_auto_unconfig(dev);
358}
359
360/* This is used by modprobe to translate PCI IDs to drivers. Should
361 * only be used for PCI and ISA-PnP devices */
362static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
363 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
364 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
365 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
366 { 0 }
367};
368MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
369
370static struct pci_driver adl_pci6208_pci_driver = {
371 .name = "adl_pci6208",
372 .id_table = adl_pci6208_pci_table,
373 .probe = adl_pci6208_pci_probe,
374 .remove = __devexit_p(adl_pci6208_pci_remove),
375};
376module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
377
445MODULE_AUTHOR("Comedi http://www.comedi.org"); 378MODULE_AUTHOR("Comedi http://www.comedi.org");
446MODULE_DESCRIPTION("Comedi low-level driver"); 379MODULE_DESCRIPTION("Comedi low-level driver");
447MODULE_LICENSE("GPL"); 380MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/adl_pci7230.c b/drivers/staging/comedi/drivers/adl_pci7230.c
index 20d570554fa4..e8053bc825f4 100644
--- a/drivers/staging/comedi/drivers/adl_pci7230.c
+++ b/drivers/staging/comedi/drivers/adl_pci7230.c
@@ -43,13 +43,6 @@ Configuration Options:
43 43
44#define PCI_DEVICE_ID_PCI7230 0x7230 44#define PCI_DEVICE_ID_PCI7230 0x7230
45 45
46static DEFINE_PCI_DEVICE_TABLE(adl_pci7230_pci_table) = {
47 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) },
48 {0}
49};
50
51MODULE_DEVICE_TABLE(pci, adl_pci7230_pci_table);
52
53struct adl_pci7230_private { 46struct adl_pci7230_private {
54 int data; 47 int data;
55 struct pci_dev *pci_dev; 48 struct pci_dev *pci_dev;
@@ -57,27 +50,36 @@ struct adl_pci7230_private {
57 50
58#define devpriv ((struct adl_pci7230_private *)dev->private) 51#define devpriv ((struct adl_pci7230_private *)dev->private)
59 52
60static int adl_pci7230_attach(struct comedi_device *dev, 53static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
61 struct comedi_devconfig *it); 54 struct comedi_subdevice *s,
62static int adl_pci7230_detach(struct comedi_device *dev); 55 struct comedi_insn *insn,
63static struct comedi_driver driver_adl_pci7230 = { 56 unsigned int *data)
64 .driver_name = "adl_pci7230", 57{
65 .module = THIS_MODULE, 58 if (insn->n != 2)
66 .attach = adl_pci7230_attach, 59 return -EINVAL;
67 .detach = adl_pci7230_detach, 60
68}; 61 if (data[0]) {
62 s->state &= ~data[0];
63 s->state |= (data[0] & data[1]);
64
65 outl((s->state << 16) & 0xffffffff, dev->iobase + PCI7230_DO);
66 }
69 67
70/* Digital IO */ 68 return 2;
69}
71 70
72static int adl_pci7230_di_insn_bits(struct comedi_device *dev, 71static int adl_pci7230_di_insn_bits(struct comedi_device *dev,
73 struct comedi_subdevice *s, 72 struct comedi_subdevice *s,
74 struct comedi_insn *insn, 73 struct comedi_insn *insn,
75 unsigned int *data); 74 unsigned int *data)
75{
76 if (insn->n != 2)
77 return -EINVAL;
76 78
77static int adl_pci7230_do_insn_bits(struct comedi_device *dev, 79 data[1] = inl(dev->iobase + PCI7230_DI) & 0xffffffff;
78 struct comedi_subdevice *s, 80
79 struct comedi_insn *insn, 81 return 2;
80 unsigned int *data); 82}
81 83
82static int adl_pci7230_attach(struct comedi_device *dev, 84static int adl_pci7230_attach(struct comedi_device *dev,
83 struct comedi_devconfig *it) 85 struct comedi_devconfig *it)
@@ -148,89 +150,46 @@ static int adl_pci7230_attach(struct comedi_device *dev,
148 return 1; 150 return 1;
149} 151}
150 152
151static int adl_pci7230_detach(struct comedi_device *dev) 153static void adl_pci7230_detach(struct comedi_device *dev)
152{ 154{
153 printk(KERN_DEBUG "comedi%d: pci7230: remove\n", dev->minor);
154
155 if (devpriv && devpriv->pci_dev) { 155 if (devpriv && devpriv->pci_dev) {
156 if (dev->iobase) 156 if (dev->iobase)
157 comedi_pci_disable(devpriv->pci_dev); 157 comedi_pci_disable(devpriv->pci_dev);
158 pci_dev_put(devpriv->pci_dev); 158 pci_dev_put(devpriv->pci_dev);
159 } 159 }
160
161 return 0;
162}
163
164static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
165 struct comedi_subdevice *s,
166 struct comedi_insn *insn,
167 unsigned int *data)
168{
169 if (insn->n != 2)
170 return -EINVAL;
171
172 if (data[0]) {
173 s->state &= ~data[0];
174 s->state |= (data[0] & data[1]);
175
176 outl((s->state << 16) & 0xffffffff, dev->iobase + PCI7230_DO);
177 }
178
179 return 2;
180} 160}
181 161
182static int adl_pci7230_di_insn_bits(struct comedi_device *dev, 162static struct comedi_driver adl_pci7230_driver = {
183 struct comedi_subdevice *s, 163 .driver_name = "adl_pci7230",
184 struct comedi_insn *insn, 164 .module = THIS_MODULE,
185 unsigned int *data) 165 .attach = adl_pci7230_attach,
186{ 166 .detach = adl_pci7230_detach,
187 if (insn->n != 2) 167};
188 return -EINVAL;
189
190 data[1] = inl(dev->iobase + PCI7230_DI) & 0xffffffff;
191
192 return 2;
193}
194 168
195static int __devinit driver_adl_pci7230_pci_probe(struct pci_dev *dev, 169static int __devinit adl_pci7230_pci_probe(struct pci_dev *dev,
196 const struct pci_device_id 170 const struct pci_device_id *ent)
197 *ent)
198{ 171{
199 return comedi_pci_auto_config(dev, driver_adl_pci7230.driver_name); 172 return comedi_pci_auto_config(dev, &adl_pci7230_driver);
200} 173}
201 174
202static void __devexit driver_adl_pci7230_pci_remove(struct pci_dev *dev) 175static void __devexit adl_pci7230_pci_remove(struct pci_dev *dev)
203{ 176{
204 comedi_pci_auto_unconfig(dev); 177 comedi_pci_auto_unconfig(dev);
205} 178}
206 179
207static struct pci_driver driver_adl_pci7230_pci_driver = { 180static DEFINE_PCI_DEVICE_TABLE(adl_pci7230_pci_table) = {
208 .id_table = adl_pci7230_pci_table, 181 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) },
209 .probe = &driver_adl_pci7230_pci_probe, 182 { 0 }
210 .remove = __devexit_p(&driver_adl_pci7230_pci_remove)
211}; 183};
184MODULE_DEVICE_TABLE(pci, adl_pci7230_pci_table);
212 185
213static int __init driver_adl_pci7230_init_module(void) 186static struct pci_driver adl_pci7230_pci_driver = {
214{ 187 .name = "adl_pci7230",
215 int retval; 188 .id_table = adl_pci7230_pci_table,
216 189 .probe = adl_pci7230_pci_probe,
217 retval = comedi_driver_register(&driver_adl_pci7230); 190 .remove = __devexit_p(adl_pci7230_pci_remove),
218 if (retval < 0) 191};
219 return retval; 192module_comedi_pci_driver(adl_pci7230_driver, adl_pci7230_pci_driver);
220
221 driver_adl_pci7230_pci_driver.name =
222 (char *)driver_adl_pci7230.driver_name;
223 return pci_register_driver(&driver_adl_pci7230_pci_driver);
224}
225
226static void __exit driver_adl_pci7230_cleanup_module(void)
227{
228 pci_unregister_driver(&driver_adl_pci7230_pci_driver);
229 comedi_driver_unregister(&driver_adl_pci7230);
230}
231
232module_init(driver_adl_pci7230_init_module);
233module_exit(driver_adl_pci7230_cleanup_module);
234 193
235MODULE_AUTHOR("Comedi http://www.comedi.org"); 194MODULE_AUTHOR("Comedi http://www.comedi.org");
236MODULE_DESCRIPTION("Comedi low-level driver"); 195MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adl_pci7296.c b/drivers/staging/comedi/drivers/adl_pci7296.c
index 9a2320537bdb..b4dae3b7598b 100644
--- a/drivers/staging/comedi/drivers/adl_pci7296.c
+++ b/drivers/staging/comedi/drivers/adl_pci7296.c
@@ -48,13 +48,6 @@ Configuration Options:
48 48
49#define PCI_DEVICE_ID_PCI7296 0x7296 49#define PCI_DEVICE_ID_PCI7296 0x7296
50 50
51static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
52 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
53 {0}
54};
55
56MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
57
58struct adl_pci7296_private { 51struct adl_pci7296_private {
59 int data; 52 int data;
60 struct pci_dev *pci_dev; 53 struct pci_dev *pci_dev;
@@ -63,16 +56,6 @@ struct adl_pci7296_private {
63#define devpriv ((struct adl_pci7296_private *)dev->private) 56#define devpriv ((struct adl_pci7296_private *)dev->private)
64 57
65static int adl_pci7296_attach(struct comedi_device *dev, 58static int adl_pci7296_attach(struct comedi_device *dev,
66 struct comedi_devconfig *it);
67static int adl_pci7296_detach(struct comedi_device *dev);
68static struct comedi_driver driver_adl_pci7296 = {
69 .driver_name = "adl_pci7296",
70 .module = THIS_MODULE,
71 .attach = adl_pci7296_attach,
72 .detach = adl_pci7296_detach,
73};
74
75static int adl_pci7296_attach(struct comedi_device *dev,
76 struct comedi_devconfig *it) 59 struct comedi_devconfig *it)
77{ 60{
78 struct pci_dev *pcidev = NULL; 61 struct pci_dev *pcidev = NULL;
@@ -151,66 +134,52 @@ static int adl_pci7296_attach(struct comedi_device *dev,
151 return -EIO; 134 return -EIO;
152} 135}
153 136
154static int adl_pci7296_detach(struct comedi_device *dev) 137static void adl_pci7296_detach(struct comedi_device *dev)
155{ 138{
156 printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);
157
158 if (devpriv && devpriv->pci_dev) { 139 if (devpriv && devpriv->pci_dev) {
159 if (dev->iobase) 140 if (dev->iobase)
160 comedi_pci_disable(devpriv->pci_dev); 141 comedi_pci_disable(devpriv->pci_dev);
161 pci_dev_put(devpriv->pci_dev); 142 pci_dev_put(devpriv->pci_dev);
162 } 143 }
163 /* detach four 8255 digital io subdevices */
164 if (dev->subdevices) { 144 if (dev->subdevices) {
165 subdev_8255_cleanup(dev, dev->subdevices + 0); 145 subdev_8255_cleanup(dev, dev->subdevices + 0);
166 subdev_8255_cleanup(dev, dev->subdevices + 1); 146 subdev_8255_cleanup(dev, dev->subdevices + 1);
167 subdev_8255_cleanup(dev, dev->subdevices + 2); 147 subdev_8255_cleanup(dev, dev->subdevices + 2);
168 subdev_8255_cleanup(dev, dev->subdevices + 3); 148 subdev_8255_cleanup(dev, dev->subdevices + 3);
169
170 } 149 }
171
172 return 0;
173} 150}
174 151
175static int __devinit driver_adl_pci7296_pci_probe(struct pci_dev *dev, 152static struct comedi_driver adl_pci7296_driver = {
176 const struct pci_device_id 153 .driver_name = "adl_pci7296",
177 *ent) 154 .module = THIS_MODULE,
155 .attach = adl_pci7296_attach,
156 .detach = adl_pci7296_detach,
157};
158
159static int __devinit adl_pci7296_pci_probe(struct pci_dev *dev,
160 const struct pci_device_id *ent)
178{ 161{
179 return comedi_pci_auto_config(dev, driver_adl_pci7296.driver_name); 162 return comedi_pci_auto_config(dev, &adl_pci7296_driver);
180} 163}
181 164
182static void __devexit driver_adl_pci7296_pci_remove(struct pci_dev *dev) 165static void __devexit adl_pci7296_pci_remove(struct pci_dev *dev)
183{ 166{
184 comedi_pci_auto_unconfig(dev); 167 comedi_pci_auto_unconfig(dev);
185} 168}
186 169
187static struct pci_driver driver_adl_pci7296_pci_driver = { 170static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
188 .id_table = adl_pci7296_pci_table, 171 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
189 .probe = &driver_adl_pci7296_pci_probe, 172 { 0 }
190 .remove = __devexit_p(&driver_adl_pci7296_pci_remove)
191}; 173};
174MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
192 175
193static int __init driver_adl_pci7296_init_module(void) 176static struct pci_driver adl_pci7296_pci_driver = {
194{ 177 .name = "adl_pci7296",
195 int retval; 178 .id_table = adl_pci7296_pci_table,
196 179 .probe = adl_pci7296_pci_probe,
197 retval = comedi_driver_register(&driver_adl_pci7296); 180 .remove = __devexit_p(adl_pci7296_pci_remove),
198 if (retval < 0) 181};
199 return retval; 182module_comedi_pci_driver(adl_pci7296_driver, adl_pci7296_pci_driver);
200
201 driver_adl_pci7296_pci_driver.name =
202 (char *)driver_adl_pci7296.driver_name;
203 return pci_register_driver(&driver_adl_pci7296_pci_driver);
204}
205
206static void __exit driver_adl_pci7296_cleanup_module(void)
207{
208 pci_unregister_driver(&driver_adl_pci7296_pci_driver);
209 comedi_driver_unregister(&driver_adl_pci7296);
210}
211
212module_init(driver_adl_pci7296_init_module);
213module_exit(driver_adl_pci7296_cleanup_module);
214 183
215MODULE_AUTHOR("Comedi http://www.comedi.org"); 184MODULE_AUTHOR("Comedi http://www.comedi.org");
216MODULE_DESCRIPTION("Comedi low-level driver"); 185MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adl_pci7432.c b/drivers/staging/comedi/drivers/adl_pci7432.c
index 86ee21976041..9cbfb61a4478 100644
--- a/drivers/staging/comedi/drivers/adl_pci7432.c
+++ b/drivers/staging/comedi/drivers/adl_pci7432.c
@@ -43,13 +43,6 @@ Configuration Options:
43 43
44#define PCI_DEVICE_ID_PCI7432 0x7432 44#define PCI_DEVICE_ID_PCI7432 0x7432
45 45
46static DEFINE_PCI_DEVICE_TABLE(adl_pci7432_pci_table) = {
47 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432) },
48 {0}
49};
50
51MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table);
52
53struct adl_pci7432_private { 46struct adl_pci7432_private {
54 int data; 47 int data;
55 struct pci_dev *pci_dev; 48 struct pci_dev *pci_dev;
@@ -57,29 +50,44 @@ struct adl_pci7432_private {
57 50
58#define devpriv ((struct adl_pci7432_private *)dev->private) 51#define devpriv ((struct adl_pci7432_private *)dev->private)
59 52
60static int adl_pci7432_attach(struct comedi_device *dev, 53static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
61 struct comedi_devconfig *it); 54 struct comedi_subdevice *s,
62static int adl_pci7432_detach(struct comedi_device *dev); 55 struct comedi_insn *insn,
63static struct comedi_driver driver_adl_pci7432 = { 56 unsigned int *data)
64 .driver_name = "adl_pci7432", 57{
65 .module = THIS_MODULE, 58 printk(KERN_DEBUG "comedi: pci7432_do_insn_bits called\n");
66 .attach = adl_pci7432_attach, 59 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
67 .detach = adl_pci7432_detach, 60
68}; 61 if (insn->n != 2)
62 return -EINVAL;
69 63
70/* Digital IO */ 64 if (data[0]) {
65 s->state &= ~data[0];
66 s->state |= (data[0] & data[1]);
67
68 printk(KERN_DEBUG "comedi: out: %8x on iobase %4lx\n", s->state,
69 dev->iobase + PCI7432_DO);
70 outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO);
71 }
72 return 2;
73}
71 74
72static int adl_pci7432_di_insn_bits(struct comedi_device *dev, 75static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
73 struct comedi_subdevice *s, 76 struct comedi_subdevice *s,
74 struct comedi_insn *insn, 77 struct comedi_insn *insn,
75 unsigned int *data); 78 unsigned int *data)
79{
80 printk(KERN_DEBUG "comedi: pci7432_di_insn_bits called\n");
81 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
76 82
77static int adl_pci7432_do_insn_bits(struct comedi_device *dev, 83 if (insn->n != 2)
78 struct comedi_subdevice *s, 84 return -EINVAL;
79 struct comedi_insn *insn, 85
80 unsigned int *data); 86 data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff;
87 printk(KERN_DEBUG "comedi: data1 %8x\n", data[1]);
81 88
82/* */ 89 return 2;
90}
83 91
84static int adl_pci7432_attach(struct comedi_device *dev, 92static int adl_pci7432_attach(struct comedi_device *dev,
85 struct comedi_devconfig *it) 93 struct comedi_devconfig *it)
@@ -153,97 +161,46 @@ static int adl_pci7432_attach(struct comedi_device *dev,
153 return -EIO; 161 return -EIO;
154} 162}
155 163
156static int adl_pci7432_detach(struct comedi_device *dev) 164static void adl_pci7432_detach(struct comedi_device *dev)
157{ 165{
158 printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);
159
160 if (devpriv && devpriv->pci_dev) { 166 if (devpriv && devpriv->pci_dev) {
161 if (dev->iobase) 167 if (dev->iobase)
162 comedi_pci_disable(devpriv->pci_dev); 168 comedi_pci_disable(devpriv->pci_dev);
163 pci_dev_put(devpriv->pci_dev); 169 pci_dev_put(devpriv->pci_dev);
164 } 170 }
165
166 return 0;
167} 171}
168 172
169static int adl_pci7432_do_insn_bits(struct comedi_device *dev, 173static struct comedi_driver adl_pci7432_driver = {
170 struct comedi_subdevice *s, 174 .driver_name = "adl_pci7432",
171 struct comedi_insn *insn, 175 .module = THIS_MODULE,
172 unsigned int *data) 176 .attach = adl_pci7432_attach,
173{ 177 .detach = adl_pci7432_detach,
174 printk(KERN_DEBUG "comedi: pci7432_do_insn_bits called\n"); 178};
175 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
176
177 if (insn->n != 2)
178 return -EINVAL;
179
180 if (data[0]) {
181 s->state &= ~data[0];
182 s->state |= (data[0] & data[1]);
183
184 printk(KERN_DEBUG "comedi: out: %8x on iobase %4lx\n", s->state,
185 dev->iobase + PCI7432_DO);
186 outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO);
187 }
188 return 2;
189}
190
191static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
192 struct comedi_subdevice *s,
193 struct comedi_insn *insn,
194 unsigned int *data)
195{
196 printk(KERN_DEBUG "comedi: pci7432_di_insn_bits called\n");
197 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
198
199 if (insn->n != 2)
200 return -EINVAL;
201
202 data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff;
203 printk(KERN_DEBUG "comedi: data1 %8x\n", data[1]);
204
205 return 2;
206}
207 179
208static int __devinit driver_adl_pci7432_pci_probe(struct pci_dev *dev, 180static int __devinit adl_pci7432_pci_probe(struct pci_dev *dev,
209 const struct pci_device_id 181 const struct pci_device_id *ent)
210 *ent)
211{ 182{
212 return comedi_pci_auto_config(dev, driver_adl_pci7432.driver_name); 183 return comedi_pci_auto_config(dev, &adl_pci7432_driver);
213} 184}
214 185
215static void __devexit driver_adl_pci7432_pci_remove(struct pci_dev *dev) 186static void __devexit adl_pci7432_pci_remove(struct pci_dev *dev)
216{ 187{
217 comedi_pci_auto_unconfig(dev); 188 comedi_pci_auto_unconfig(dev);
218} 189}
219 190
220static struct pci_driver driver_adl_pci7432_pci_driver = { 191static DEFINE_PCI_DEVICE_TABLE(adl_pci7432_pci_table) = {
221 .id_table = adl_pci7432_pci_table, 192 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432) },
222 .probe = &driver_adl_pci7432_pci_probe, 193 { 0 }
223 .remove = __devexit_p(&driver_adl_pci7432_pci_remove)
224}; 194};
195MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table);
225 196
226static int __init driver_adl_pci7432_init_module(void) 197static struct pci_driver adl_pci7432_pci_driver = {
227{ 198 .name = "adl_pci7432",
228 int retval; 199 .id_table = adl_pci7432_pci_table,
229 200 .probe = adl_pci7432_pci_probe,
230 retval = comedi_driver_register(&driver_adl_pci7432); 201 .remove = __devexit_p(adl_pci7432_pci_remove),
231 if (retval < 0) 202};
232 return retval; 203module_comedi_pci_driver(adl_pci7432_driver, adl_pci7432_pci_driver);
233
234 driver_adl_pci7432_pci_driver.name =
235 (char *)driver_adl_pci7432.driver_name;
236 return pci_register_driver(&driver_adl_pci7432_pci_driver);
237}
238
239static void __exit driver_adl_pci7432_cleanup_module(void)
240{
241 pci_unregister_driver(&driver_adl_pci7432_pci_driver);
242 comedi_driver_unregister(&driver_adl_pci7432);
243}
244
245module_init(driver_adl_pci7432_init_module);
246module_exit(driver_adl_pci7432_cleanup_module);
247 204
248MODULE_AUTHOR("Comedi http://www.comedi.org"); 205MODULE_AUTHOR("Comedi http://www.comedi.org");
249MODULE_DESCRIPTION("Comedi low-level driver"); 206MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c
index 3b83d65bc1bc..409ef13ad090 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -56,13 +56,6 @@ Configuration Options:
56 56
57#define PCI_DEVICE_ID_PCI8164 0x8164 57#define PCI_DEVICE_ID_PCI8164 0x8164
58 58
59static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
60 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) },
61 {0}
62};
63
64MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
65
66struct adl_pci8164_private { 59struct adl_pci8164_private {
67 int data; 60 int data;
68 struct pci_dev *pci_dev; 61 struct pci_dev *pci_dev;
@@ -70,159 +63,6 @@ struct adl_pci8164_private {
70 63
71#define devpriv ((struct adl_pci8164_private *)dev->private) 64#define devpriv ((struct adl_pci8164_private *)dev->private)
72 65
73static int adl_pci8164_attach(struct comedi_device *dev,
74 struct comedi_devconfig *it);
75static int adl_pci8164_detach(struct comedi_device *dev);
76static struct comedi_driver driver_adl_pci8164 = {
77 .driver_name = "adl_pci8164",
78 .module = THIS_MODULE,
79 .attach = adl_pci8164_attach,
80 .detach = adl_pci8164_detach,
81};
82
83static int adl_pci8164_insn_read_msts(struct comedi_device *dev,
84 struct comedi_subdevice *s,
85 struct comedi_insn *insn,
86 unsigned int *data);
87
88static int adl_pci8164_insn_read_ssts(struct comedi_device *dev,
89 struct comedi_subdevice *s,
90 struct comedi_insn *insn,
91 unsigned int *data);
92
93static int adl_pci8164_insn_read_buf0(struct comedi_device *dev,
94 struct comedi_subdevice *s,
95 struct comedi_insn *insn,
96 unsigned int *data);
97
98static int adl_pci8164_insn_read_buf1(struct comedi_device *dev,
99 struct comedi_subdevice *s,
100 struct comedi_insn *insn,
101 unsigned int *data);
102
103static int adl_pci8164_insn_write_cmd(struct comedi_device *dev,
104 struct comedi_subdevice *s,
105 struct comedi_insn *insn,
106 unsigned int *data);
107
108static int adl_pci8164_insn_write_otp(struct comedi_device *dev,
109 struct comedi_subdevice *s,
110 struct comedi_insn *insn,
111 unsigned int *data);
112
113static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
114 struct comedi_subdevice *s,
115 struct comedi_insn *insn,
116 unsigned int *data);
117
118static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
119 struct comedi_subdevice *s,
120 struct comedi_insn *insn,
121 unsigned int *data);
122
123static int adl_pci8164_attach(struct comedi_device *dev,
124 struct comedi_devconfig *it)
125{
126 struct pci_dev *pcidev = NULL;
127 struct comedi_subdevice *s;
128 int bus, slot;
129
130 printk(KERN_INFO "comedi: attempt to attach...\n");
131 printk(KERN_INFO "comedi%d: adl_pci8164\n", dev->minor);
132
133 dev->board_name = "pci8164";
134 bus = it->options[0];
135 slot = it->options[1];
136
137 if (alloc_private(dev, sizeof(struct adl_pci8164_private)) < 0)
138 return -ENOMEM;
139
140 if (alloc_subdevices(dev, 4) < 0)
141 return -ENOMEM;
142
143 for_each_pci_dev(pcidev) {
144 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
145 pcidev->device == PCI_DEVICE_ID_PCI8164) {
146 if (bus || slot) {
147 /* requested particular bus/slot */
148 if (pcidev->bus->number != bus
149 || PCI_SLOT(pcidev->devfn) != slot)
150 continue;
151 }
152 devpriv->pci_dev = pcidev;
153 if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) {
154 printk(KERN_ERR "comedi%d: Failed to enable "
155 "PCI device and request regions\n", dev->minor);
156 return -EIO;
157 }
158 dev->iobase = pci_resource_start(pcidev, 2);
159 printk(KERN_DEBUG "comedi: base addr %4lx\n",
160 dev->iobase);
161
162 s = dev->subdevices + 0;
163 s->type = COMEDI_SUBD_PROC;
164 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
165 s->n_chan = 4;
166 s->maxdata = 0xffff;
167 s->len_chanlist = 4;
168 /* s->range_table = &range_axis; */
169 s->insn_read = adl_pci8164_insn_read_msts;
170 s->insn_write = adl_pci8164_insn_write_cmd;
171
172 s = dev->subdevices + 1;
173 s->type = COMEDI_SUBD_PROC;
174 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
175 s->n_chan = 4;
176 s->maxdata = 0xffff;
177 s->len_chanlist = 4;
178 /* s->range_table = &range_axis; */
179 s->insn_read = adl_pci8164_insn_read_ssts;
180 s->insn_write = adl_pci8164_insn_write_otp;
181
182 s = dev->subdevices + 2;
183 s->type = COMEDI_SUBD_PROC;
184 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
185 s->n_chan = 4;
186 s->maxdata = 0xffff;
187 s->len_chanlist = 4;
188 /* s->range_table = &range_axis; */
189 s->insn_read = adl_pci8164_insn_read_buf0;
190 s->insn_write = adl_pci8164_insn_write_buf0;
191
192 s = dev->subdevices + 3;
193 s->type = COMEDI_SUBD_PROC;
194 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
195 s->n_chan = 4;
196 s->maxdata = 0xffff;
197 s->len_chanlist = 4;
198 /* s->range_table = &range_axis; */
199 s->insn_read = adl_pci8164_insn_read_buf1;
200 s->insn_write = adl_pci8164_insn_write_buf1;
201
202 printk(KERN_INFO "comedi: attached\n");
203
204 return 1;
205 }
206 }
207
208 printk(KERN_ERR "comedi%d: no supported board found!"
209 "(req. bus/slot : %d/%d)\n", dev->minor, bus, slot);
210 return -EIO;
211}
212
213static int adl_pci8164_detach(struct comedi_device *dev)
214{
215 printk(KERN_INFO "comedi%d: pci8164: remove\n", dev->minor);
216
217 if (devpriv && devpriv->pci_dev) {
218 if (dev->iobase)
219 comedi_pci_disable(devpriv->pci_dev);
220 pci_dev_put(devpriv->pci_dev);
221 }
222
223 return 0;
224}
225
226/* 66/*
227 all the read commands are the same except for the addition a constant 67 all the read commands are the same except for the addition a constant
228 * const to the data for inw() 68 * const to the data for inw()
@@ -384,45 +224,136 @@ static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
384 return 2; 224 return 2;
385} 225}
386 226
387static int __devinit driver_adl_pci8164_pci_probe(struct pci_dev *dev, 227static int adl_pci8164_attach(struct comedi_device *dev,
388 const struct pci_device_id 228 struct comedi_devconfig *it)
389 *ent)
390{ 229{
391 return comedi_pci_auto_config(dev, driver_adl_pci8164.driver_name); 230 struct pci_dev *pcidev = NULL;
231 struct comedi_subdevice *s;
232 int bus, slot;
233
234 printk(KERN_INFO "comedi: attempt to attach...\n");
235 printk(KERN_INFO "comedi%d: adl_pci8164\n", dev->minor);
236
237 dev->board_name = "pci8164";
238 bus = it->options[0];
239 slot = it->options[1];
240
241 if (alloc_private(dev, sizeof(struct adl_pci8164_private)) < 0)
242 return -ENOMEM;
243
244 if (alloc_subdevices(dev, 4) < 0)
245 return -ENOMEM;
246
247 for_each_pci_dev(pcidev) {
248 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
249 pcidev->device == PCI_DEVICE_ID_PCI8164) {
250 if (bus || slot) {
251 /* requested particular bus/slot */
252 if (pcidev->bus->number != bus
253 || PCI_SLOT(pcidev->devfn) != slot)
254 continue;
255 }
256 devpriv->pci_dev = pcidev;
257 if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) {
258 printk(KERN_ERR "comedi%d: Failed to enable "
259 "PCI device and request regions\n", dev->minor);
260 return -EIO;
261 }
262 dev->iobase = pci_resource_start(pcidev, 2);
263 printk(KERN_DEBUG "comedi: base addr %4lx\n",
264 dev->iobase);
265
266 s = dev->subdevices + 0;
267 s->type = COMEDI_SUBD_PROC;
268 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
269 s->n_chan = 4;
270 s->maxdata = 0xffff;
271 s->len_chanlist = 4;
272 /* s->range_table = &range_axis; */
273 s->insn_read = adl_pci8164_insn_read_msts;
274 s->insn_write = adl_pci8164_insn_write_cmd;
275
276 s = dev->subdevices + 1;
277 s->type = COMEDI_SUBD_PROC;
278 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
279 s->n_chan = 4;
280 s->maxdata = 0xffff;
281 s->len_chanlist = 4;
282 /* s->range_table = &range_axis; */
283 s->insn_read = adl_pci8164_insn_read_ssts;
284 s->insn_write = adl_pci8164_insn_write_otp;
285
286 s = dev->subdevices + 2;
287 s->type = COMEDI_SUBD_PROC;
288 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
289 s->n_chan = 4;
290 s->maxdata = 0xffff;
291 s->len_chanlist = 4;
292 /* s->range_table = &range_axis; */
293 s->insn_read = adl_pci8164_insn_read_buf0;
294 s->insn_write = adl_pci8164_insn_write_buf0;
295
296 s = dev->subdevices + 3;
297 s->type = COMEDI_SUBD_PROC;
298 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
299 s->n_chan = 4;
300 s->maxdata = 0xffff;
301 s->len_chanlist = 4;
302 /* s->range_table = &range_axis; */
303 s->insn_read = adl_pci8164_insn_read_buf1;
304 s->insn_write = adl_pci8164_insn_write_buf1;
305
306 printk(KERN_INFO "comedi: attached\n");
307
308 return 1;
309 }
310 }
311
312 printk(KERN_ERR "comedi%d: no supported board found!"
313 "(req. bus/slot : %d/%d)\n", dev->minor, bus, slot);
314 return -EIO;
392} 315}
393 316
394static void __devexit driver_adl_pci8164_pci_remove(struct pci_dev *dev) 317static void adl_pci8164_detach(struct comedi_device *dev)
395{ 318{
396 comedi_pci_auto_unconfig(dev); 319 if (devpriv && devpriv->pci_dev) {
320 if (dev->iobase)
321 comedi_pci_disable(devpriv->pci_dev);
322 pci_dev_put(devpriv->pci_dev);
323 }
397} 324}
398 325
399static struct pci_driver driver_adl_pci8164_pci_driver = { 326static struct comedi_driver adl_pci8164_driver = {
400 .id_table = adl_pci8164_pci_table, 327 .driver_name = "adl_pci8164",
401 .probe = &driver_adl_pci8164_pci_probe, 328 .module = THIS_MODULE,
402 .remove = __devexit_p(&driver_adl_pci8164_pci_remove) 329 .attach = adl_pci8164_attach,
330 .detach = adl_pci8164_detach,
403}; 331};
404 332
405static int __init driver_adl_pci8164_init_module(void) 333static int __devinit adl_pci8164_pci_probe(struct pci_dev *dev,
334 const struct pci_device_id *ent)
406{ 335{
407 int retval; 336 return comedi_pci_auto_config(dev, &adl_pci8164_driver);
408
409 retval = comedi_driver_register(&driver_adl_pci8164);
410 if (retval < 0)
411 return retval;
412
413 driver_adl_pci8164_pci_driver.name =
414 (char *)driver_adl_pci8164.driver_name;
415 return pci_register_driver(&driver_adl_pci8164_pci_driver);
416} 337}
417 338
418static void __exit driver_adl_pci8164_cleanup_module(void) 339static void __devexit adl_pci8164_pci_remove(struct pci_dev *dev)
419{ 340{
420 pci_unregister_driver(&driver_adl_pci8164_pci_driver); 341 comedi_pci_auto_unconfig(dev);
421 comedi_driver_unregister(&driver_adl_pci8164);
422} 342}
423 343
424module_init(driver_adl_pci8164_init_module); 344static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
425module_exit(driver_adl_pci8164_cleanup_module); 345 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) },
346 {0}
347};
348MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
349
350static struct pci_driver adl_pci8164_pci_driver = {
351 .name = "adl_pci8164",
352 .id_table = adl_pci8164_pci_table,
353 .probe = adl_pci8164_pci_probe,
354 .remove = __devexit_p(adl_pci8164_pci_remove),
355};
356module_comedi_pci_driver(adl_pci8164_driver, adl_pci8164_pci_driver);
426 357
427MODULE_AUTHOR("Comedi http://www.comedi.org"); 358MODULE_AUTHOR("Comedi http://www.comedi.org");
428MODULE_DESCRIPTION("Comedi low-level driver"); 359MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index 2a9bd88a4abb..ccfb1a52154e 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -289,16 +289,6 @@ TODO:
289 PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_2); \ 289 PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_2); \
290 } while (0) 290 } while (0)
291 291
292/* Function prototypes */
293
294static int pci9111_attach(struct comedi_device *dev,
295 struct comedi_devconfig *it);
296static int pci9111_detach(struct comedi_device *dev);
297static void pci9111_ai_munge(struct comedi_device *dev,
298 struct comedi_subdevice *s, void *data,
299 unsigned int num_bytes,
300 unsigned int start_chan_index);
301
302static const struct comedi_lrange pci9111_hr_ai_range = { 292static const struct comedi_lrange pci9111_hr_ai_range = {
303 5, 293 5,
304 { 294 {
@@ -310,14 +300,6 @@ static const struct comedi_lrange pci9111_hr_ai_range = {
310 } 300 }
311}; 301};
312 302
313static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = {
314 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID) },
315 /* { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID) }, */
316 { 0 }
317};
318
319MODULE_DEVICE_TABLE(pci, pci9111_pci_table);
320
321/* */ 303/* */
322/* Board specification structure */ 304/* Board specification structure */
323/* */ 305/* */
@@ -354,51 +336,6 @@ static const struct pci9111_board pci9111_boards[] = {
354#define pci9111_board_nbr \ 336#define pci9111_board_nbr \
355 (sizeof(pci9111_boards)/sizeof(struct pci9111_board)) 337 (sizeof(pci9111_boards)/sizeof(struct pci9111_board))
356 338
357static struct comedi_driver pci9111_driver = {
358 .driver_name = PCI9111_DRIVER_NAME,
359 .module = THIS_MODULE,
360 .attach = pci9111_attach,
361 .detach = pci9111_detach,
362};
363
364static int __devinit pci9111_driver_pci_probe(struct pci_dev *dev,
365 const struct pci_device_id *ent)
366{
367 return comedi_pci_auto_config(dev, pci9111_driver.driver_name);
368}
369
370static void __devexit pci9111_driver_pci_remove(struct pci_dev *dev)
371{
372 comedi_pci_auto_unconfig(dev);
373}
374
375static struct pci_driver pci9111_driver_pci_driver = {
376 .id_table = pci9111_pci_table,
377 .probe = &pci9111_driver_pci_probe,
378 .remove = __devexit_p(&pci9111_driver_pci_remove)
379};
380
381static int __init pci9111_driver_init_module(void)
382{
383 int retval;
384
385 retval = comedi_driver_register(&pci9111_driver);
386 if (retval < 0)
387 return retval;
388
389 pci9111_driver_pci_driver.name = (char *)pci9111_driver.driver_name;
390 return pci_register_driver(&pci9111_driver_pci_driver);
391}
392
393static void __exit pci9111_driver_cleanup_module(void)
394{
395 pci_unregister_driver(&pci9111_driver_pci_driver);
396 comedi_driver_unregister(&pci9111_driver);
397}
398
399module_init(pci9111_driver_init_module);
400module_exit(pci9111_driver_cleanup_module);
401
402/* Private data structure */ 339/* Private data structure */
403 340
404struct pci9111_private_data { 341struct pci9111_private_data {
@@ -1445,31 +1382,54 @@ found:
1445 return 0; 1382 return 0;
1446} 1383}
1447 1384
1448/* Detach */ 1385static void pci9111_detach(struct comedi_device *dev)
1449
1450static int pci9111_detach(struct comedi_device *dev)
1451{ 1386{
1452 /* Reset device */
1453
1454 if (dev->private != NULL) { 1387 if (dev->private != NULL) {
1455 if (dev_private->is_valid) 1388 if (dev_private->is_valid)
1456 pci9111_reset(dev); 1389 pci9111_reset(dev);
1457
1458 } 1390 }
1459 /* Release previously allocated irq */
1460
1461 if (dev->irq != 0) 1391 if (dev->irq != 0)
1462 free_irq(dev->irq, dev); 1392 free_irq(dev->irq, dev);
1463
1464 if (dev_private != NULL && dev_private->pci_device != NULL) { 1393 if (dev_private != NULL && dev_private->pci_device != NULL) {
1465 if (dev->iobase) 1394 if (dev->iobase)
1466 comedi_pci_disable(dev_private->pci_device); 1395 comedi_pci_disable(dev_private->pci_device);
1467 pci_dev_put(dev_private->pci_device); 1396 pci_dev_put(dev_private->pci_device);
1468 } 1397 }
1398}
1469 1399
1470 return 0; 1400static struct comedi_driver adl_pci9111_driver = {
1401 .driver_name = "adl_pci9111",
1402 .module = THIS_MODULE,
1403 .attach = pci9111_attach,
1404 .detach = pci9111_detach,
1405};
1406
1407static int __devinit pci9111_pci_probe(struct pci_dev *dev,
1408 const struct pci_device_id *ent)
1409{
1410 return comedi_pci_auto_config(dev, &adl_pci9111_driver);
1471} 1411}
1472 1412
1413static void __devexit pci9111_pci_remove(struct pci_dev *dev)
1414{
1415 comedi_pci_auto_unconfig(dev);
1416}
1417
1418static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = {
1419 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID) },
1420 /* { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID) }, */
1421 { 0 }
1422};
1423MODULE_DEVICE_TABLE(pci, pci9111_pci_table);
1424
1425static struct pci_driver adl_pci9111_pci_driver = {
1426 .name = "adl_pci9111",
1427 .id_table = pci9111_pci_table,
1428 .probe = pci9111_pci_probe,
1429 .remove = __devexit_p(pci9111_pci_remove),
1430};
1431module_comedi_pci_driver(adl_pci9111_driver, adl_pci9111_pci_driver);
1432
1473MODULE_AUTHOR("Comedi http://www.comedi.org"); 1433MODULE_AUTHOR("Comedi http://www.comedi.org");
1474MODULE_DESCRIPTION("Comedi low-level driver"); 1434MODULE_DESCRIPTION("Comedi low-level driver");
1475MODULE_LICENSE("GPL"); 1435MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index f17654e44aef..78645863297b 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -221,10 +221,6 @@ static const struct comedi_lrange range_pci9118hg = { 8, {
221 * of BIP/UNI ranges 221 * of BIP/UNI ranges
222 */ 222 */
223 223
224static int pci9118_attach(struct comedi_device *dev,
225 struct comedi_devconfig *it);
226static int pci9118_detach(struct comedi_device *dev);
227
228struct boardtype { 224struct boardtype {
229 const char *name; /* board name */ 225 const char *name; /* board name */
230 int vendor_id; /* PCI vendor a device ID of card */ 226 int vendor_id; /* PCI vendor a device ID of card */
@@ -252,81 +248,6 @@ struct boardtype {
252 248
253}; 249};
254 250
255static DEFINE_PCI_DEVICE_TABLE(pci9118_pci_table) = {
256 { PCI_DEVICE(PCI_VENDOR_ID_AMCC, 0x80d9) },
257 { 0 }
258};
259
260MODULE_DEVICE_TABLE(pci, pci9118_pci_table);
261
262static const struct boardtype boardtypes[] = {
263 {"pci9118dg", PCI_VENDOR_ID_AMCC, 0x80d9,
264 AMCC_OP_REG_SIZE, IORANGE_9118,
265 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff,
266 &range_pci9118dg_hr, &range_bipolar10,
267 3000, 12, 512},
268 {"pci9118hg", PCI_VENDOR_ID_AMCC, 0x80d9,
269 AMCC_OP_REG_SIZE, IORANGE_9118,
270 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff,
271 &range_pci9118hg, &range_bipolar10,
272 3000, 12, 512},
273 {"pci9118hr", PCI_VENDOR_ID_AMCC, 0x80d9,
274 AMCC_OP_REG_SIZE, IORANGE_9118,
275 16, 8, 256, PCI9118_CHANLEN, 2, 0xffff, 0x0fff,
276 &range_pci9118dg_hr, &range_bipolar10,
277 10000, 40, 512},
278};
279
280#define n_boardtypes (sizeof(boardtypes)/sizeof(struct boardtype))
281
282static struct comedi_driver driver_pci9118 = {
283 .driver_name = "adl_pci9118",
284 .module = THIS_MODULE,
285 .attach = pci9118_attach,
286 .detach = pci9118_detach,
287 .num_names = n_boardtypes,
288 .board_name = &boardtypes[0].name,
289 .offset = sizeof(struct boardtype),
290};
291
292static int __devinit driver_pci9118_pci_probe(struct pci_dev *dev,
293 const struct pci_device_id *ent)
294{
295 return comedi_pci_auto_config(dev, driver_pci9118.driver_name);
296}
297
298static void __devexit driver_pci9118_pci_remove(struct pci_dev *dev)
299{
300 comedi_pci_auto_unconfig(dev);
301}
302
303static struct pci_driver driver_pci9118_pci_driver = {
304 .id_table = pci9118_pci_table,
305 .probe = &driver_pci9118_pci_probe,
306 .remove = __devexit_p(&driver_pci9118_pci_remove)
307};
308
309static int __init driver_pci9118_init_module(void)
310{
311 int retval;
312
313 retval = comedi_driver_register(&driver_pci9118);
314 if (retval < 0)
315 return retval;
316
317 driver_pci9118_pci_driver.name = (char *)driver_pci9118.driver_name;
318 return pci_register_driver(&driver_pci9118_pci_driver);
319}
320
321static void __exit driver_pci9118_cleanup_module(void)
322{
323 pci_unregister_driver(&driver_pci9118_pci_driver);
324 comedi_driver_unregister(&driver_pci9118);
325}
326
327module_init(driver_pci9118_init_module);
328module_exit(driver_pci9118_cleanup_module);
329
330struct pci9118_private { 251struct pci9118_private {
331 unsigned long iobase_a; /* base+size for AMCC chip */ 252 unsigned long iobase_a; /* base+size for AMCC chip */
332 unsigned int master; /* master capable */ 253 unsigned int master; /* master capable */
@@ -2190,9 +2111,6 @@ static int pci9118_reset(struct comedi_device *dev)
2190 return 0; 2111 return 0;
2191} 2112}
2192 2113
2193/*
2194==============================================================================
2195*/
2196static int pci9118_attach(struct comedi_device *dev, 2114static int pci9118_attach(struct comedi_device *dev,
2197 struct comedi_devconfig *it) 2115 struct comedi_devconfig *it)
2198{ 2116{
@@ -2435,10 +2353,7 @@ static int pci9118_attach(struct comedi_device *dev,
2435 return 0; 2353 return 0;
2436} 2354}
2437 2355
2438/* 2356static void pci9118_detach(struct comedi_device *dev)
2439==============================================================================
2440*/
2441static int pci9118_detach(struct comedi_device *dev)
2442{ 2357{
2443 if (dev->private) { 2358 if (dev->private) {
2444 if (devpriv->valid) 2359 if (devpriv->valid)
@@ -2458,13 +2373,100 @@ static int pci9118_detach(struct comedi_device *dev)
2458 free_pages((unsigned long)devpriv->dmabuf_virt[1], 2373 free_pages((unsigned long)devpriv->dmabuf_virt[1],
2459 devpriv->dmabuf_pages[1]); 2374 devpriv->dmabuf_pages[1]);
2460 } 2375 }
2376}
2461 2377
2462 return 0; 2378static const struct boardtype boardtypes[] = {
2379 {
2380 .name = "pci9118dg",
2381 .vendor_id = PCI_VENDOR_ID_AMCC,
2382 .device_id = 0x80d9,
2383 .iorange_amcc = AMCC_OP_REG_SIZE,
2384 .iorange_9118 = IORANGE_9118,
2385 .n_aichan = 16,
2386 .n_aichand = 8,
2387 .mux_aichan = 256,
2388 .n_aichanlist = PCI9118_CHANLEN,
2389 .n_aochan = 2,
2390 .ai_maxdata = 0x0fff,
2391 .ao_maxdata = 0x0fff,
2392 .rangelist_ai = &range_pci9118dg_hr,
2393 .rangelist_ao = &range_bipolar10,
2394 .ai_ns_min = 3000,
2395 .ai_pacer_min = 12,
2396 .half_fifo_size = 512,
2397 }, {
2398 .name = "pci9118hg",
2399 .vendor_id = PCI_VENDOR_ID_AMCC,
2400 .device_id = 0x80d9,
2401 .iorange_amcc = AMCC_OP_REG_SIZE,
2402 .iorange_9118 = IORANGE_9118,
2403 .n_aichan = 16,
2404 .n_aichand = 8,
2405 .mux_aichan = 256,
2406 .n_aichanlist = PCI9118_CHANLEN,
2407 .n_aochan = 2,
2408 .ai_maxdata = 0x0fff,
2409 .ao_maxdata = 0x0fff,
2410 .rangelist_ai = &range_pci9118hg,
2411 .rangelist_ao = &range_bipolar10,
2412 .ai_ns_min = 3000,
2413 .ai_pacer_min = 12,
2414 .half_fifo_size = 512,
2415 }, {
2416 .name = "pci9118hr",
2417 .vendor_id = PCI_VENDOR_ID_AMCC,
2418 .device_id = 0x80d9,
2419 .iorange_amcc = AMCC_OP_REG_SIZE,
2420 .iorange_9118 = IORANGE_9118,
2421 .n_aichan = 16,
2422 .n_aichand = 8,
2423 .mux_aichan = 256,
2424 .n_aichanlist = PCI9118_CHANLEN,
2425 .n_aochan = 2,
2426 .ai_maxdata = 0xffff,
2427 .ao_maxdata = 0x0fff,
2428 .rangelist_ai = &range_pci9118dg_hr,
2429 .rangelist_ao = &range_bipolar10,
2430 .ai_ns_min = 10000,
2431 .ai_pacer_min = 40,
2432 .half_fifo_size = 512,
2433 },
2434};
2435
2436static struct comedi_driver adl_pci9118_driver = {
2437 .driver_name = "adl_pci9118",
2438 .module = THIS_MODULE,
2439 .attach = pci9118_attach,
2440 .detach = pci9118_detach,
2441 .num_names = ARRAY_SIZE(boardtypes),
2442 .board_name = &boardtypes[0].name,
2443 .offset = sizeof(struct boardtype),
2444};
2445
2446static int __devinit adl_pci9118_pci_probe(struct pci_dev *dev,
2447 const struct pci_device_id *ent)
2448{
2449 return comedi_pci_auto_config(dev, &adl_pci9118_driver);
2463} 2450}
2464 2451
2465/* 2452static void __devexit adl_pci9118_pci_remove(struct pci_dev *dev)
2466============================================================================== 2453{
2467*/ 2454 comedi_pci_auto_unconfig(dev);
2455}
2456
2457static DEFINE_PCI_DEVICE_TABLE(adl_pci9118_pci_table) = {
2458 { PCI_DEVICE(PCI_VENDOR_ID_AMCC, 0x80d9) },
2459 { 0 }
2460};
2461MODULE_DEVICE_TABLE(pci, adl_pci9118_pci_table);
2462
2463static struct pci_driver adl_pci9118_pci_driver = {
2464 .name = "adl_pci9118",
2465 .id_table = adl_pci9118_pci_table,
2466 .probe = adl_pci9118_pci_probe,
2467 .remove = __devexit_p(adl_pci9118_pci_remove),
2468};
2469module_comedi_pci_driver(adl_pci9118_driver, adl_pci9118_pci_driver);
2468 2470
2469MODULE_AUTHOR("Comedi http://www.comedi.org"); 2471MODULE_AUTHOR("Comedi http://www.comedi.org");
2470MODULE_DESCRIPTION("Comedi low-level driver"); 2472MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adq12b.c b/drivers/staging/comedi/drivers/adq12b.c
index 5361f318b010..7d585a12050f 100644
--- a/drivers/staging/comedi/drivers/adq12b.c
+++ b/drivers/staging/comedi/drivers/adq12b.c
@@ -125,24 +125,6 @@ struct adq12b_board {
125 int do_chans; 125 int do_chans;
126}; 126};
127 127
128static const struct adq12b_board adq12b_boards[] = {
129 {
130 .name = "adq12b",
131 .ai_se_chans = 16,
132 .ai_diff_chans = 8,
133 .ai_bits = 12,
134 .di_chans = 5,
135 .do_chans = 8}
136/* potentially, more adq-based deviced will be added */
137/*,
138 .name = "adq12b",
139 .ai_chans = 16, // this is just for reference, hardcoded again later
140 .ai_bits = 12,
141 .di_chans = 8,
142 .do_chans = 5
143 }*/
144};
145
146#define thisboard ((const struct adq12b_board *)dev->board_ptr) 128#define thisboard ((const struct adq12b_board *)dev->board_ptr)
147 129
148struct adq12b_private { 130struct adq12b_private {
@@ -156,41 +138,88 @@ struct adq12b_private {
156#define devpriv ((struct adq12b_private *)dev->private) 138#define devpriv ((struct adq12b_private *)dev->private)
157 139
158/* 140/*
159 * The struct comedi_driver structure tells the Comedi core module 141 * "instructions" read/write data in "one-shot" or "software-triggered"
160 * which functions to call to configure/deconfigure (attach/detach) 142 * mode.
161 * the board, and also about the kernel module that contains
162 * the device code.
163 */ 143 */
164static int adq12b_attach(struct comedi_device *dev,
165 struct comedi_devconfig *it);
166static int adq12b_detach(struct comedi_device *dev);
167
168static struct comedi_driver driver_adq12b = {
169 .driver_name = "adq12b",
170 .module = THIS_MODULE,
171 .attach = adq12b_attach,
172 .detach = adq12b_detach,
173 .board_name = &adq12b_boards[0].name,
174 .offset = sizeof(struct adq12b_board),
175 .num_names = ARRAY_SIZE(adq12b_boards),
176};
177 144
178static int adq12b_ai_rinsn(struct comedi_device *dev, 145static int adq12b_ai_rinsn(struct comedi_device *dev,
179 struct comedi_subdevice *s, struct comedi_insn *insn, 146 struct comedi_subdevice *s, struct comedi_insn *insn,
180 unsigned int *data); 147 unsigned int *data)
148{
149 int n, i;
150 int range, channel;
151 unsigned char hi, lo, status;
152
153 /* change channel and range only if it is different from the previous */
154 range = CR_RANGE(insn->chanspec);
155 channel = CR_CHAN(insn->chanspec);
156 if (channel != devpriv->last_channel || range != devpriv->last_range) {
157 outb((range << 4) | channel, dev->iobase + ADQ12B_CTREG);
158 udelay(50); /* wait for the mux to settle */
159 }
160
161 /* trigger conversion */
162 status = inb(dev->iobase + ADQ12B_ADLOW);
163
164 /* convert n samples */
165 for (n = 0; n < insn->n; n++) {
166
167 /* wait for end of conversion */
168 i = 0;
169 do {
170 /* udelay(1); */
171 status = inb(dev->iobase + ADQ12B_STINR);
172 status = status & ADQ12B_EOC;
173 } while (status == 0 && ++i < TIMEOUT);
174 /* } while (++i < 10); */
175
176 /* read data */
177 hi = inb(dev->iobase + ADQ12B_ADHIG);
178 lo = inb(dev->iobase + ADQ12B_ADLOW);
179
180 /* printk("debug: chan=%d range=%d status=%d hi=%d lo=%d\n",
181 channel, range, status, hi, lo); */
182 data[n] = (hi << 8) | lo;
183
184 }
185
186 /* return the number of samples read/written */
187 return n;
188}
189
181static int adq12b_di_insn_bits(struct comedi_device *dev, 190static int adq12b_di_insn_bits(struct comedi_device *dev,
182 struct comedi_subdevice *s, 191 struct comedi_subdevice *s,
183 struct comedi_insn *insn, unsigned int *data); 192 struct comedi_insn *insn, unsigned int *data)
193{
194
195 /* only bits 0-4 have information about digital inputs */
196 data[1] = (inb(dev->iobase + ADQ12B_STINR) & (0x1f));
197
198 return 2;
199}
200
184static int adq12b_do_insn_bits(struct comedi_device *dev, 201static int adq12b_do_insn_bits(struct comedi_device *dev,
185 struct comedi_subdevice *s, 202 struct comedi_subdevice *s,
186 struct comedi_insn *insn, unsigned int *data); 203 struct comedi_insn *insn, unsigned int *data)
204{
205 int channel;
206
207 for (channel = 0; channel < 8; channel++)
208 if (((data[0] >> channel) & 0x01) != 0)
209 outb((((data[1] >> channel) & 0x01) << 3) | channel,
210 dev->iobase + ADQ12B_OUTBR);
211
212 /* store information to retrieve when asked for reading */
213 if (data[0]) {
214 devpriv->digital_state &= ~data[0];
215 devpriv->digital_state |= (data[0] & data[1]);
216 }
217
218 data[1] = devpriv->digital_state;
219
220 return 2;
221}
187 222
188/*
189 * Attach is called by the Comedi core to configure the driver
190 * for a particular board. If you specified a board_name array
191 * in the driver structure, dev->board_ptr contains that
192 * address.
193 */
194static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it) 223static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
195{ 224{
196 struct comedi_subdevice *s; 225 struct comedi_subdevice *s;
@@ -295,125 +324,34 @@ static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
295 return 0; 324 return 0;
296} 325}
297 326
298/* 327static void adq12b_detach(struct comedi_device *dev)
299 * _detach is called to deconfigure a device. It should deallocate
300 * resources.
301 * This function is also called when _attach() fails, so it should be
302 * careful not to release resources that were not necessarily
303 * allocated by _attach(). dev->private and dev->subdevices are
304 * deallocated automatically by the core.
305 */
306static int adq12b_detach(struct comedi_device *dev)
307{ 328{
308 if (dev->iobase) 329 if (dev->iobase)
309 release_region(dev->iobase, ADQ12B_SIZE); 330 release_region(dev->iobase, ADQ12B_SIZE);
310
311 kfree(devpriv); 331 kfree(devpriv);
312
313 printk(KERN_INFO "comedi%d: adq12b: removed\n", dev->minor);
314
315 return 0;
316}
317
318/*
319 * "instructions" read/write data in "one-shot" or "software-triggered"
320 * mode.
321 */
322
323static int adq12b_ai_rinsn(struct comedi_device *dev,
324 struct comedi_subdevice *s, struct comedi_insn *insn,
325 unsigned int *data)
326{
327 int n, i;
328 int range, channel;
329 unsigned char hi, lo, status;
330
331 /* change channel and range only if it is different from the previous */
332 range = CR_RANGE(insn->chanspec);
333 channel = CR_CHAN(insn->chanspec);
334 if (channel != devpriv->last_channel || range != devpriv->last_range) {
335 outb((range << 4) | channel, dev->iobase + ADQ12B_CTREG);
336 udelay(50); /* wait for the mux to settle */
337 }
338
339 /* trigger conversion */
340 status = inb(dev->iobase + ADQ12B_ADLOW);
341
342 /* convert n samples */
343 for (n = 0; n < insn->n; n++) {
344
345 /* wait for end of conversion */
346 i = 0;
347 do {
348 /* udelay(1); */
349 status = inb(dev->iobase + ADQ12B_STINR);
350 status = status & ADQ12B_EOC;
351 } while (status == 0 && ++i < TIMEOUT);
352 /* } while (++i < 10); */
353
354 /* read data */
355 hi = inb(dev->iobase + ADQ12B_ADHIG);
356 lo = inb(dev->iobase + ADQ12B_ADLOW);
357
358 /* printk("debug: chan=%d range=%d status=%d hi=%d lo=%d\n",
359 channel, range, status, hi, lo); */
360 data[n] = (hi << 8) | lo;
361
362 }
363
364 /* return the number of samples read/written */
365 return n;
366}
367
368static int adq12b_di_insn_bits(struct comedi_device *dev,
369 struct comedi_subdevice *s,
370 struct comedi_insn *insn, unsigned int *data)
371{
372
373 /* only bits 0-4 have information about digital inputs */
374 data[1] = (inb(dev->iobase + ADQ12B_STINR) & (0x1f));
375
376 return 2;
377} 332}
378 333
379static int adq12b_do_insn_bits(struct comedi_device *dev, 334static const struct adq12b_board adq12b_boards[] = {
380 struct comedi_subdevice *s, 335 {
381 struct comedi_insn *insn, unsigned int *data) 336 .name = "adq12b",
382{ 337 .ai_se_chans = 16,
383 int channel; 338 .ai_diff_chans = 8,
384 339 .ai_bits = 12,
385 for (channel = 0; channel < 8; channel++) 340 .di_chans = 5,
386 if (((data[0] >> channel) & 0x01) != 0) 341 .do_chans = 8,
387 outb((((data[1] >> channel) & 0x01) << 3) | channel, 342 },
388 dev->iobase + ADQ12B_OUTBR); 343};
389
390 /* store information to retrieve when asked for reading */
391 if (data[0]) {
392 devpriv->digital_state &= ~data[0];
393 devpriv->digital_state |= (data[0] & data[1]);
394 }
395
396 data[1] = devpriv->digital_state;
397
398 return 2;
399}
400
401/*
402 * A convenient macro that defines init_module() and cleanup_module(),
403 * as necessary.
404 */
405static int __init driver_adq12b_init_module(void)
406{
407 return comedi_driver_register(&driver_adq12b);
408}
409
410static void __exit driver_adq12b_cleanup_module(void)
411{
412 comedi_driver_unregister(&driver_adq12b);
413}
414 344
415module_init(driver_adq12b_init_module); 345static struct comedi_driver adq12b_driver = {
416module_exit(driver_adq12b_cleanup_module); 346 .driver_name = "adq12b",
347 .module = THIS_MODULE,
348 .attach = adq12b_attach,
349 .detach = adq12b_detach,
350 .board_name = &adq12b_boards[0].name,
351 .offset = sizeof(struct adq12b_board),
352 .num_names = ARRAY_SIZE(adq12b_boards),
353};
354module_comedi_driver(adq12b_driver);
417 355
418MODULE_AUTHOR("Comedi http://www.comedi.org"); 356MODULE_AUTHOR("Comedi http://www.comedi.org");
419MODULE_DESCRIPTION("Comedi low-level driver"); 357MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 8318c82a555a..de8c98cfe367 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -191,10 +191,6 @@ static const struct comedi_lrange range_pci171x_da = { 2, {
191 } 191 }
192}; 192};
193 193
194static int pci1710_attach(struct comedi_device *dev,
195 struct comedi_devconfig *it);
196static int pci1710_detach(struct comedi_device *dev);
197
198struct boardtype { 194struct boardtype {
199 const char *name; /* board name */ 195 const char *name; /* board name */
200 int device_id; 196 int device_id;
@@ -216,17 +212,6 @@ struct boardtype {
216 unsigned int fifo_half_size; /* size of FIFO/2 */ 212 unsigned int fifo_half_size; /* size of FIFO/2 */
217}; 213};
218 214
219static DEFINE_PCI_DEVICE_TABLE(pci1710_pci_table) = {
220 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) },
221 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) },
222 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1713) },
223 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1720) },
224 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1731) },
225 { 0 }
226};
227
228MODULE_DEVICE_TABLE(pci, pci1710_pci_table);
229
230static const struct boardtype boardtypes[] = { 215static const struct boardtype boardtypes[] = {
231 {"pci1710", 0x1710, 216 {"pci1710", 0x1710,
232 IORANGE_171x, 1, TYPE_PCI171X, 217 IORANGE_171x, 1, TYPE_PCI171X,
@@ -264,18 +249,6 @@ static const struct boardtype boardtypes[] = {
264 {.name = DRV_NAME}, 249 {.name = DRV_NAME},
265}; 250};
266 251
267#define n_boardtypes (sizeof(boardtypes)/sizeof(struct boardtype))
268
269static struct comedi_driver driver_pci1710 = {
270 .driver_name = DRV_NAME,
271 .module = THIS_MODULE,
272 .attach = pci1710_attach,
273 .detach = pci1710_detach,
274 .num_names = n_boardtypes,
275 .board_name = &boardtypes[0].name,
276 .offset = sizeof(struct boardtype),
277};
278
279struct pci1710_private { 252struct pci1710_private {
280 struct pci_dev *pcidev; /* ptr to PCI device */ 253 struct pci_dev *pcidev; /* ptr to PCI device */
281 char valid; /* card is usable */ 254 char valid; /* card is usable */
@@ -676,7 +649,9 @@ static void interrupt_pci1710_every_sample(void *d)
676 s->async->buf_int_count, s->async->buf_int_ptr, 649 s->async->buf_int_count, s->async->buf_int_ptr,
677 s->async->buf_user_count, s->async->buf_user_ptr); 650 s->async->buf_user_count, s->async->buf_user_ptr);
678 DPRINTK("adv_pci1710 EDBG: EOS2\n"); 651 DPRINTK("adv_pci1710 EDBG: EOS2\n");
679 if ((!devpriv->neverending_ai) && (devpriv->ai_act_scan >= devpriv->ai_scans)) { /* all data sampled */ 652 if ((!devpriv->neverending_ai) &&
653 (devpriv->ai_act_scan >= devpriv->ai_scans)) {
654 /* all data sampled */
680 pci171x_ai_cancel(dev, s); 655 pci171x_ai_cancel(dev, s);
681 s->async->events |= COMEDI_CB_EOA; 656 s->async->events |= COMEDI_CB_EOA;
682 comedi_event(dev, s); 657 comedi_event(dev, s);
@@ -804,8 +779,8 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d)
804 irq); 779 irq);
805 if (!dev->attached) /* is device attached? */ 780 if (!dev->attached) /* is device attached? */
806 return IRQ_NONE; /* no, exit */ 781 return IRQ_NONE; /* no, exit */
807 782 /* is this interrupt from our board? */
808 if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ)) /* is this interrupt from our board? */ 783 if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ))
809 return IRQ_NONE; /* no, exit */ 784 return IRQ_NONE; /* no, exit */
810 785
811 DPRINTK("adv_pci1710 EDBG: interrupt_service_pci1710() ST: %4x\n", 786 DPRINTK("adv_pci1710 EDBG: interrupt_service_pci1710() ST: %4x\n",
@@ -814,7 +789,7 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d)
814 if (devpriv->ai_et) { /* Switch from initial TRIG_EXT to TRIG_xxx. */ 789 if (devpriv->ai_et) { /* Switch from initial TRIG_EXT to TRIG_xxx. */
815 devpriv->ai_et = 0; 790 devpriv->ai_et = 0;
816 devpriv->CntrlReg &= Control_CNT0; 791 devpriv->CntrlReg &= Control_CNT0;
817 devpriv->CntrlReg |= Control_SW; /* set software trigger */ 792 devpriv->CntrlReg |= Control_SW; /* set software trigger */
818 outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); 793 outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
819 devpriv->CntrlReg = devpriv->ai_et_CntrlReg; 794 devpriv->CntrlReg = devpriv->ai_et_CntrlReg;
820 outb(0, dev->iobase + PCI171x_CLRFIFO); 795 outb(0, dev->iobase + PCI171x_CLRFIFO);
@@ -865,7 +840,8 @@ static int pci171x_ai_docmd_and_mode(int mode, struct comedi_device *dev,
865 devpriv->neverending_ai = 0; 840 devpriv->neverending_ai = 0;
866 841
867 devpriv->CntrlReg &= Control_CNT0; 842 devpriv->CntrlReg &= Control_CNT0;
868 if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { /* don't we want wake up every scan? devpriv->ai_eos=1; */ 843 /* don't we want wake up every scan? devpriv->ai_eos=1; */
844 if ((devpriv->ai_flags & TRIG_WAKE_EOS)) {
869 devpriv->ai_eos = 1; 845 devpriv->ai_eos = 1;
870 } else { 846 } else {
871 devpriv->CntrlReg |= Control_ONEFH; 847 devpriv->CntrlReg |= Control_ONEFH;
@@ -982,13 +958,13 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
982#ifdef PCI171X_EXTDEBUG 958#ifdef PCI171X_EXTDEBUG
983 pci171x_cmdtest_out(1, cmd); 959 pci171x_cmdtest_out(1, cmd);
984#endif 960#endif
985 DPRINTK 961 DPRINTK(
986 ("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=1\n", 962 "adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=1\n",
987 err); 963 err);
988 return 1; 964 return 1;
989 } 965 }
990 966
991 /* step 2: make sure trigger sources are unique and mutually compatible */ 967 /* step2: make sure trigger srcs are unique and mutually compatible */
992 968
993 if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) { 969 if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) {
994 cmd->start_src = TRIG_NOW; 970 cmd->start_src = TRIG_NOW;
@@ -1015,9 +991,9 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
1015#ifdef PCI171X_EXTDEBUG 991#ifdef PCI171X_EXTDEBUG
1016 pci171x_cmdtest_out(2, cmd); 992 pci171x_cmdtest_out(2, cmd);
1017#endif 993#endif
1018 DPRINTK 994 DPRINTK(
1019 ("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=2\n", 995 "adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=2\n",
1020 err); 996 err);
1021 return 2; 997 return 2;
1022 } 998 }
1023 999
@@ -1065,9 +1041,9 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
1065#ifdef PCI171X_EXTDEBUG 1041#ifdef PCI171X_EXTDEBUG
1066 pci171x_cmdtest_out(3, cmd); 1042 pci171x_cmdtest_out(3, cmd);
1067#endif 1043#endif
1068 DPRINTK 1044 DPRINTK(
1069 ("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=3\n", 1045 "adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=3\n",
1070 err); 1046 err);
1071 return 3; 1047 return 3;
1072 } 1048 }
1073 1049
@@ -1160,48 +1136,41 @@ static int check_channel_list(struct comedi_device *dev,
1160 return 0; 1136 return 0;
1161 } 1137 }
1162 1138
1163 if (n_chan > 1) { 1139 if (n_chan == 1)
1164 chansegment[0] = chanlist[0]; /* first channel is every time ok */ 1140 return 1; /* seglen=1 */
1165 for (i = 1, seglen = 1; i < n_chan; i++, seglen++) { /* build part of chanlist */ 1141
1166 /* printk("%d. %d %d\n",i,CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i])); */ 1142 chansegment[0] = chanlist[0]; /* first channel is every time ok */
1167 if (chanlist[0] == chanlist[i]) 1143 for (i = 1, seglen = 1; i < n_chan; i++, seglen++) {
1168 break; /* we detect loop, this must by finish */ 1144 if (chanlist[0] == chanlist[i])
1169 if (CR_CHAN(chanlist[i]) & 1) /* odd channel cann't by differencial */ 1145 break; /* we detected a loop, stop */
1170 if (CR_AREF(chanlist[i]) == AREF_DIFF) { 1146 if ((CR_CHAN(chanlist[i]) & 1) &&
1171 comedi_error(dev, 1147 (CR_AREF(chanlist[i]) == AREF_DIFF)) {
1172 "Odd channel can't be differential input!\n"); 1148 comedi_error(dev, "Odd channel cannot be differential input!\n");
1173 return 0; 1149 return 0;
1174 }
1175 nowmustbechan =
1176 (CR_CHAN(chansegment[i - 1]) + 1) % s->n_chan;
1177 if (CR_AREF(chansegment[i - 1]) == AREF_DIFF)
1178 nowmustbechan = (nowmustbechan + 1) % s->n_chan;
1179 if (nowmustbechan != CR_CHAN(chanlist[i])) { /* channel list isn't continuous :-( */
1180 printk
1181 ("channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n",
1182 i, CR_CHAN(chanlist[i]), nowmustbechan,
1183 CR_CHAN(chanlist[0]));
1184 return 0;
1185 }
1186 chansegment[i] = chanlist[i]; /* well, this is next correct channel in list */
1187 } 1150 }
1151 nowmustbechan = (CR_CHAN(chansegment[i - 1]) + 1) % s->n_chan;
1152 if (CR_AREF(chansegment[i - 1]) == AREF_DIFF)
1153 nowmustbechan = (nowmustbechan + 1) % s->n_chan;
1154 if (nowmustbechan != CR_CHAN(chanlist[i])) {
1155 printk("channel list must be continuous! chanlist[%i]=%d but must be %d or %d!\n",
1156 i, CR_CHAN(chanlist[i]), nowmustbechan,
1157 CR_CHAN(chanlist[0]));
1158 return 0;
1159 }
1160 chansegment[i] = chanlist[i]; /* next correct channel in list */
1161 }
1188 1162
1189 for (i = 0, segpos = 0; i < n_chan; i++) { /* check whole chanlist */ 1163 for (i = 0, segpos = 0; i < n_chan; i++) {
1190 /* printk("%d %d=%d %d\n",CR_CHAN(chansegment[i%seglen]),CR_RANGE(chansegment[i%seglen]),CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i])); */ 1164 if (chanlist[i] != chansegment[i % seglen]) {
1191 if (chanlist[i] != chansegment[i % seglen]) { 1165 printk("bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n",
1192 printk 1166 i, CR_CHAN(chansegment[i]),
1193 ("bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", 1167 CR_RANGE(chansegment[i]),
1194 i, CR_CHAN(chansegment[i]), 1168 CR_AREF(chansegment[i]),
1195 CR_RANGE(chansegment[i]), 1169 CR_CHAN(chanlist[i % seglen]),
1196 CR_AREF(chansegment[i]), 1170 CR_RANGE(chanlist[i % seglen]),
1197 CR_CHAN(chanlist[i % seglen]), 1171 CR_AREF(chansegment[i % seglen]));
1198 CR_RANGE(chanlist[i % seglen]), 1172 return 0;
1199 CR_AREF(chansegment[i % seglen]));
1200 return 0; /* chan/gain list is strange */
1201 }
1202 } 1173 }
1203 } else {
1204 seglen = 1;
1205 } 1174 }
1206 return seglen; 1175 return seglen;
1207} 1176}
@@ -1221,14 +1190,14 @@ static void setup_channel_list(struct comedi_device *dev,
1221 DPRINTK("SegLen: %d\n", seglen); 1190 DPRINTK("SegLen: %d\n", seglen);
1222 for (i = 0; i < seglen; i++) { /* store range list to card */ 1191 for (i = 0; i < seglen; i++) { /* store range list to card */
1223 chanprog = muxonechan[CR_CHAN(chanlist[i])]; 1192 chanprog = muxonechan[CR_CHAN(chanlist[i])];
1224 outw(chanprog, dev->iobase + PCI171x_MUX); /* select channel */ 1193 outw(chanprog, dev->iobase + PCI171x_MUX); /* select channel */
1225 range = this_board->rangecode_ai[CR_RANGE(chanlist[i])]; 1194 range = this_board->rangecode_ai[CR_RANGE(chanlist[i])];
1226 if (CR_AREF(chanlist[i]) == AREF_DIFF) 1195 if (CR_AREF(chanlist[i]) == AREF_DIFF)
1227 range |= 0x0020; 1196 range |= 0x0020;
1228 outw(range, dev->iobase + PCI171x_RANGE); /* select gain */ 1197 outw(range, dev->iobase + PCI171x_RANGE); /* select gain */
1229#ifdef PCI171x_PARANOIDCHECK 1198#ifdef PCI171x_PARANOIDCHECK
1230 devpriv->act_chanlist[i] = 1199 devpriv->act_chanlist[i] =
1231 (CR_CHAN(chanlist[i]) << 12) & 0xf000; 1200 (CR_CHAN(chanlist[i]) << 12) & 0xf000;
1232#endif 1201#endif
1233 DPRINTK("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range, 1202 DPRINTK("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range,
1234 devpriv->act_chanlist[i]); 1203 devpriv->act_chanlist[i]);
@@ -1236,13 +1205,14 @@ static void setup_channel_list(struct comedi_device *dev,
1236#ifdef PCI171x_PARANOIDCHECK 1205#ifdef PCI171x_PARANOIDCHECK
1237 for ( ; i < n_chan; i++) { /* store remainder of channel list */ 1206 for ( ; i < n_chan; i++) { /* store remainder of channel list */
1238 devpriv->act_chanlist[i] = 1207 devpriv->act_chanlist[i] =
1239 (CR_CHAN(chanlist[i]) << 12) & 0xf000; 1208 (CR_CHAN(chanlist[i]) << 12) & 0xf000;
1240 } 1209 }
1241#endif 1210#endif
1242 1211
1243 devpriv->ai_et_MuxVal = 1212 devpriv->ai_et_MuxVal =
1244 CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8); 1213 CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8);
1245 outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); /* select channel interval to scan */ 1214 /* select channel interval to scan */
1215 outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX);
1246 DPRINTK("MUX: %4x L%4x.H%4x\n", 1216 DPRINTK("MUX: %4x L%4x.H%4x\n",
1247 CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8), 1217 CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8),
1248 CR_CHAN(chanlist[0]), CR_CHAN(chanlist[seglen - 1])); 1218 CR_CHAN(chanlist[0]), CR_CHAN(chanlist[seglen - 1]));
@@ -1365,9 +1335,6 @@ static int pci1710_reset(struct comedi_device *dev)
1365 DPRINTK("adv_pci1710 EDBG: END: pci1710_reset(...)\n"); 1335 DPRINTK("adv_pci1710 EDBG: END: pci1710_reset(...)\n");
1366} 1336}
1367 1337
1368/*
1369==============================================================================
1370*/
1371static int pci1710_attach(struct comedi_device *dev, 1338static int pci1710_attach(struct comedi_device *dev,
1372 struct comedi_devconfig *it) 1339 struct comedi_devconfig *it)
1373{ 1340{
@@ -1398,13 +1365,13 @@ static int pci1710_attach(struct comedi_device *dev,
1398 while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH, 1365 while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH,
1399 PCI_ANY_ID, pcidev))) { 1366 PCI_ANY_ID, pcidev))) {
1400 if (strcmp(this_board->name, DRV_NAME) == 0) { 1367 if (strcmp(this_board->name, DRV_NAME) == 0) {
1401 for (i = 0; i < n_boardtypes; ++i) { 1368 for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
1402 if (pcidev->device == boardtypes[i].device_id) { 1369 if (pcidev->device == boardtypes[i].device_id) {
1403 board_index = i; 1370 board_index = i;
1404 break; 1371 break;
1405 } 1372 }
1406 } 1373 }
1407 if (i == n_boardtypes) 1374 if (i == ARRAY_SIZE(boardtypes))
1408 continue; 1375 continue;
1409 } else { 1376 } else {
1410 if (pcidev->device != boardtypes[board_index].device_id) 1377 if (pcidev->device != boardtypes[board_index].device_id)
@@ -1584,12 +1551,8 @@ static int pci1710_attach(struct comedi_device *dev,
1584 return 0; 1551 return 0;
1585} 1552}
1586 1553
1587/* 1554static void pci1710_detach(struct comedi_device *dev)
1588==============================================================================
1589*/
1590static int pci1710_detach(struct comedi_device *dev)
1591{ 1555{
1592
1593 if (dev->private) { 1556 if (dev->private) {
1594 if (devpriv->valid) 1557 if (devpriv->valid)
1595 pci1710_reset(dev); 1558 pci1710_reset(dev);
@@ -1598,57 +1561,49 @@ static int pci1710_detach(struct comedi_device *dev)
1598 if (devpriv->pcidev) { 1561 if (devpriv->pcidev) {
1599 if (dev->iobase) 1562 if (dev->iobase)
1600 comedi_pci_disable(devpriv->pcidev); 1563 comedi_pci_disable(devpriv->pcidev);
1601
1602 pci_dev_put(devpriv->pcidev); 1564 pci_dev_put(devpriv->pcidev);
1603 } 1565 }
1604 } 1566 }
1605
1606 return 0;
1607} 1567}
1608 1568
1609/* 1569static struct comedi_driver adv_pci1710_driver = {
1610============================================================================== 1570 .driver_name = "adv_pci1710",
1611*/ 1571 .module = THIS_MODULE,
1612static int __devinit driver_pci1710_pci_probe(struct pci_dev *dev, 1572 .attach = pci1710_attach,
1613 const struct pci_device_id *ent) 1573 .detach = pci1710_detach,
1574 .num_names = ARRAY_SIZE(boardtypes),
1575 .board_name = &boardtypes[0].name,
1576 .offset = sizeof(struct boardtype),
1577};
1578
1579static int __devinit adv_pci1710_pci_probe(struct pci_dev *dev,
1580 const struct pci_device_id *ent)
1614{ 1581{
1615 return comedi_pci_auto_config(dev, driver_pci1710.driver_name); 1582 return comedi_pci_auto_config(dev, &adv_pci1710_driver);
1616} 1583}
1617 1584
1618static void __devexit driver_pci1710_pci_remove(struct pci_dev *dev) 1585static void __devexit adv_pci1710_pci_remove(struct pci_dev *dev)
1619{ 1586{
1620 comedi_pci_auto_unconfig(dev); 1587 comedi_pci_auto_unconfig(dev);
1621} 1588}
1622 1589
1623static struct pci_driver driver_pci1710_pci_driver = { 1590static DEFINE_PCI_DEVICE_TABLE(adv_pci1710_pci_table) = {
1624 .id_table = pci1710_pci_table, 1591 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) },
1625 .probe = &driver_pci1710_pci_probe, 1592 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) },
1626 .remove = __devexit_p(&driver_pci1710_pci_remove) 1593 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1713) },
1594 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1720) },
1595 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1731) },
1596 { 0 }
1627}; 1597};
1598MODULE_DEVICE_TABLE(pci, adv_pci1710_pci_table);
1628 1599
1629static int __init driver_pci1710_init_module(void) 1600static struct pci_driver adv_pci1710_pci_driver = {
1630{ 1601 .name = "adv_pci1710",
1631 int retval; 1602 .id_table = adv_pci1710_pci_table,
1632 1603 .probe = adv_pci1710_pci_probe,
1633 retval = comedi_driver_register(&driver_pci1710); 1604 .remove = __devexit_p(adv_pci1710_pci_remove),
1634 if (retval < 0) 1605};
1635 return retval; 1606module_comedi_pci_driver(adv_pci1710_driver, adv_pci1710_pci_driver);
1636
1637 driver_pci1710_pci_driver.name = (char *)driver_pci1710.driver_name;
1638 return pci_register_driver(&driver_pci1710_pci_driver);
1639}
1640
1641static void __exit driver_pci1710_cleanup_module(void)
1642{
1643 pci_unregister_driver(&driver_pci1710_pci_driver);
1644 comedi_driver_unregister(&driver_pci1710);
1645}
1646
1647module_init(driver_pci1710_init_module);
1648module_exit(driver_pci1710_cleanup_module);
1649/*
1650==============================================================================
1651*/
1652 1607
1653MODULE_AUTHOR("Comedi http://www.comedi.org"); 1608MODULE_AUTHOR("Comedi http://www.comedi.org");
1654MODULE_DESCRIPTION("Comedi low-level driver"); 1609MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c
index 29455a8e88b4..336addcbce3a 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -150,36 +150,6 @@ static const struct pci1723_board boardtypes[] = {
150 }, 150 },
151}; 151};
152 152
153/*
154 * This is used by modprobe to translate PCI IDs to drivers.
155 * Should only be used for PCI and ISA-PnP devices
156 */
157static DEFINE_PCI_DEVICE_TABLE(pci1723_pci_table) = {
158 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) },
159 { 0 }
160};
161
162MODULE_DEVICE_TABLE(pci, pci1723_pci_table);
163
164/*
165 * The struct comedi_driver structure tells the Comedi core module
166 * which functions to call to configure/deconfigure (attach/detach)
167 * the board, and also about the kernel module that contains
168 * the device code.
169 */
170static int pci1723_attach(struct comedi_device *dev,
171 struct comedi_devconfig *it);
172static int pci1723_detach(struct comedi_device *dev);
173
174#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pci1723_board))
175
176static struct comedi_driver driver_pci1723 = {
177 .driver_name = "adv_pci1723",
178 .module = THIS_MODULE,
179 .attach = pci1723_attach,
180 .detach = pci1723_detach,
181};
182
183/* This structure is for data unique to this hardware driver. */ 153/* This structure is for data unique to this hardware driver. */
184struct pci1723_private { 154struct pci1723_private {
185 int valid; /* card is usable; */ 155 int valid; /* card is usable; */
@@ -319,10 +289,6 @@ static int pci1723_dio_insn_bits(struct comedi_device *dev,
319 return 2; 289 return 2;
320} 290}
321 291
322/*
323 * Attach is called by the Comedi core to configure the driver
324 * for a pci1723 board.
325 */
326static int pci1723_attach(struct comedi_device *dev, 292static int pci1723_attach(struct comedi_device *dev,
327 struct comedi_devconfig *it) 293 struct comedi_devconfig *it)
328{ 294{
@@ -465,73 +431,50 @@ static int pci1723_attach(struct comedi_device *dev,
465 return 0; 431 return 0;
466} 432}
467 433
468/* 434static void pci1723_detach(struct comedi_device *dev)
469 * _detach is called to deconfigure a device. It should deallocate
470 * resources.
471 * This function is also called when _attach() fails, so it should be
472 * careful not to release resources that were not necessarily
473 * allocated by _attach(). dev->private and dev->subdevices are
474 * deallocated automatically by the core.
475 */
476static int pci1723_detach(struct comedi_device *dev)
477{ 435{
478 printk(KERN_ERR "comedi%d: pci1723: remove\n", dev->minor);
479
480 if (dev->private) { 436 if (dev->private) {
481 if (devpriv->valid) 437 if (devpriv->valid)
482 pci1723_reset(dev); 438 pci1723_reset(dev);
483
484 if (devpriv->pcidev) { 439 if (devpriv->pcidev) {
485 if (dev->iobase) 440 if (dev->iobase)
486 comedi_pci_disable(devpriv->pcidev); 441 comedi_pci_disable(devpriv->pcidev);
487 pci_dev_put(devpriv->pcidev); 442 pci_dev_put(devpriv->pcidev);
488 } 443 }
489 } 444 }
490
491 return 0;
492} 445}
493 446
494/* 447static struct comedi_driver adv_pci1723_driver = {
495 * A convenient macro that defines init_module() and cleanup_module(), 448 .driver_name = "adv_pci1723",
496 * as necessary. 449 .module = THIS_MODULE,
497 */ 450 .attach = pci1723_attach,
498static int __devinit driver_pci1723_pci_probe(struct pci_dev *dev, 451 .detach = pci1723_detach,
499 const struct pci_device_id *ent) 452};
453
454static int __devinit adv_pci1723_pci_probe(struct pci_dev *dev,
455 const struct pci_device_id *ent)
500{ 456{
501 return comedi_pci_auto_config(dev, driver_pci1723.driver_name); 457 return comedi_pci_auto_config(dev, &adv_pci1723_driver);
502} 458}
503 459
504static void __devexit driver_pci1723_pci_remove(struct pci_dev *dev) 460static void __devexit adv_pci1723_pci_remove(struct pci_dev *dev)
505{ 461{
506 comedi_pci_auto_unconfig(dev); 462 comedi_pci_auto_unconfig(dev);
507} 463}
508 464
509static struct pci_driver driver_pci1723_pci_driver = { 465static DEFINE_PCI_DEVICE_TABLE(adv_pci1723_pci_table) = {
510 .id_table = pci1723_pci_table, 466 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) },
511 .probe = &driver_pci1723_pci_probe, 467 { 0 }
512 .remove = __devexit_p(&driver_pci1723_pci_remove)
513}; 468};
469MODULE_DEVICE_TABLE(pci, adv_pci1723_pci_table);
514 470
515static int __init driver_pci1723_init_module(void) 471static struct pci_driver adv_pci1723_pci_driver = {
516{ 472 .name = "adv_pci1723",
517 int retval; 473 .id_table = adv_pci1723_pci_table,
518 474 .probe = adv_pci1723_pci_probe,
519 retval = comedi_driver_register(&driver_pci1723); 475 .remove = __devexit_p(adv_pci1723_pci_remove),
520 if (retval < 0) 476};
521 return retval; 477module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver);
522
523 driver_pci1723_pci_driver.name = (char *)driver_pci1723.driver_name;
524 return pci_register_driver(&driver_pci1723_pci_driver);
525}
526
527static void __exit driver_pci1723_cleanup_module(void)
528{
529 pci_unregister_driver(&driver_pci1723_pci_driver);
530 comedi_driver_unregister(&driver_pci1723);
531}
532
533module_init(driver_pci1723_init_module);
534module_exit(driver_pci1723_cleanup_module);
535 478
536MODULE_AUTHOR("Comedi http://www.comedi.org"); 479MODULE_AUTHOR("Comedi http://www.comedi.org");
537MODULE_DESCRIPTION("Comedi low-level driver"); 480MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c
index 7af068f4a749..43a32dc12cde 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -237,10 +237,6 @@ enum hw_io_access {
237 237
238#define OMBCMD_RETRY 0x03 /* 3 times try request before error */ 238#define OMBCMD_RETRY 0x03 /* 3 times try request before error */
239 239
240static int pci_dio_attach(struct comedi_device *dev,
241 struct comedi_devconfig *it);
242static int pci_dio_detach(struct comedi_device *dev);
243
244struct diosubd_data { 240struct diosubd_data {
245 int chans; /* num of chans */ 241 int chans; /* num of chans */
246 int addr; /* PCI address ofset */ 242 int addr; /* PCI address ofset */
@@ -263,26 +259,6 @@ struct dio_boardtype {
263 enum hw_io_access io_access; 259 enum hw_io_access io_access;
264}; 260};
265 261
266static DEFINE_PCI_DEVICE_TABLE(pci_dio_pci_table) = {
267 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
268 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
269 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1734) },
270 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1735) },
271 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1736) },
272 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1739) },
273 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1750) },
274 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1751) },
275 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1752) },
276 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1753) },
277 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1754) },
278 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1756) },
279 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) },
280 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1762) },
281 { 0 }
282};
283
284MODULE_DEVICE_TABLE(pci, pci_dio_pci_table);
285
286static const struct dio_boardtype boardtypes[] = { 262static const struct dio_boardtype boardtypes[] = {
287 {"pci1730", PCI_VENDOR_ID_ADVANTECH, 0x1730, PCIDIO_MAINREG, 263 {"pci1730", PCI_VENDOR_ID_ADVANTECH, 0x1730, PCIDIO_MAINREG,
288 TYPE_PCI1730, 264 TYPE_PCI1730,
@@ -406,15 +382,6 @@ static const struct dio_boardtype boardtypes[] = {
406 IO_16b} 382 IO_16b}
407}; 383};
408 384
409#define n_boardtypes (sizeof(boardtypes)/sizeof(struct dio_boardtype))
410
411static struct comedi_driver driver_pci_dio = {
412 .driver_name = "adv_pci_dio",
413 .module = THIS_MODULE,
414 .attach = pci_dio_attach,
415 .detach = pci_dio_detach
416};
417
418struct pci_dio_private { 385struct pci_dio_private {
419 struct pci_dio_private *prev; /* previous private struct */ 386 struct pci_dio_private *prev; /* previous private struct */
420 struct pci_dio_private *next; /* next private struct */ 387 struct pci_dio_private *next; /* next private struct */
@@ -1116,9 +1083,6 @@ static int CheckAndAllocCard(struct comedi_device *dev,
1116 return 1; 1083 return 1;
1117} 1084}
1118 1085
1119/*
1120==============================================================================
1121*/
1122static int pci_dio_attach(struct comedi_device *dev, 1086static int pci_dio_attach(struct comedi_device *dev,
1123 struct comedi_devconfig *it) 1087 struct comedi_devconfig *it)
1124{ 1088{
@@ -1134,7 +1098,7 @@ static int pci_dio_attach(struct comedi_device *dev,
1134 1098
1135 for_each_pci_dev(pcidev) { 1099 for_each_pci_dev(pcidev) {
1136 /* loop through cards supported by this driver */ 1100 /* loop through cards supported by this driver */
1137 for (i = 0; i < n_boardtypes; ++i) { 1101 for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
1138 if (boardtypes[i].vendor_id != pcidev->vendor) 1102 if (boardtypes[i].vendor_id != pcidev->vendor)
1139 continue; 1103 continue;
1140 if (boardtypes[i].device_id != pcidev->device) 1104 if (boardtypes[i].device_id != pcidev->device)
@@ -1162,7 +1126,7 @@ static int pci_dio_attach(struct comedi_device *dev,
1162 return -EIO; 1126 return -EIO;
1163 } 1127 }
1164 1128
1165 if (comedi_pci_enable(pcidev, driver_pci_dio.driver_name)) { 1129 if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
1166 dev_err(dev->hw_dev, "Error: Can't enable PCI device and request regions!\n"); 1130 dev_err(dev->hw_dev, "Error: Can't enable PCI device and request regions!\n");
1167 return -EIO; 1131 return -EIO;
1168 } 1132 }
@@ -1246,10 +1210,7 @@ static int pci_dio_attach(struct comedi_device *dev,
1246 return 0; 1210 return 0;
1247} 1211}
1248 1212
1249/* 1213static void pci_dio_detach(struct comedi_device *dev)
1250==============================================================================
1251*/
1252static int pci_dio_detach(struct comedi_device *dev)
1253{ 1214{
1254 int i, j; 1215 int i, j;
1255 struct comedi_subdevice *s; 1216 struct comedi_subdevice *s;
@@ -1258,20 +1219,14 @@ static int pci_dio_detach(struct comedi_device *dev)
1258 if (dev->private) { 1219 if (dev->private) {
1259 if (devpriv->valid) 1220 if (devpriv->valid)
1260 pci_dio_reset(dev); 1221 pci_dio_reset(dev);
1261
1262
1263 /* This shows the silliness of using this kind of
1264 * scheme for numbering subdevices. Don't do it. --ds */
1265 subdev = 0; 1222 subdev = 0;
1266 for (i = 0; i < MAX_DI_SUBDEVS; i++) { 1223 for (i = 0; i < MAX_DI_SUBDEVS; i++) {
1267 if (this_board->sdi[i].chans) 1224 if (this_board->sdi[i].chans)
1268 subdev++; 1225 subdev++;
1269
1270 } 1226 }
1271 for (i = 0; i < MAX_DO_SUBDEVS; i++) { 1227 for (i = 0; i < MAX_DO_SUBDEVS; i++) {
1272 if (this_board->sdo[i].chans) 1228 if (this_board->sdo[i].chans)
1273 subdev++; 1229 subdev++;
1274
1275 } 1230 }
1276 for (i = 0; i < MAX_DIO_SUBDEVG; i++) { 1231 for (i = 0; i < MAX_DIO_SUBDEVG; i++) {
1277 for (j = 0; j < this_board->sdio[i].regs; j++) { 1232 for (j = 0; j < this_board->sdio[i].regs; j++) {
@@ -1280,82 +1235,73 @@ static int pci_dio_detach(struct comedi_device *dev)
1280 subdev++; 1235 subdev++;
1281 } 1236 }
1282 } 1237 }
1283
1284 if (this_board->boardid.chans) 1238 if (this_board->boardid.chans)
1285 subdev++; 1239 subdev++;
1286
1287 for (i = 0; i < MAX_8254_SUBDEVS; i++) 1240 for (i = 0; i < MAX_8254_SUBDEVS; i++)
1288 if (this_board->s8254[i].chans) 1241 if (this_board->s8254[i].chans)
1289 subdev++; 1242 subdev++;
1290
1291 for (i = 0; i < dev->n_subdevices; i++) { 1243 for (i = 0; i < dev->n_subdevices; i++) {
1292 s = dev->subdevices + i; 1244 s = dev->subdevices + i;
1293 s->private = NULL; 1245 s->private = NULL;
1294 } 1246 }
1295
1296 if (devpriv->pcidev) { 1247 if (devpriv->pcidev) {
1297 if (dev->iobase) 1248 if (dev->iobase)
1298 comedi_pci_disable(devpriv->pcidev); 1249 comedi_pci_disable(devpriv->pcidev);
1299
1300 pci_dev_put(devpriv->pcidev); 1250 pci_dev_put(devpriv->pcidev);
1301 } 1251 }
1302
1303 if (devpriv->prev) 1252 if (devpriv->prev)
1304 devpriv->prev->next = devpriv->next; 1253 devpriv->prev->next = devpriv->next;
1305 else 1254 else
1306 pci_priv = devpriv->next; 1255 pci_priv = devpriv->next;
1307
1308 if (devpriv->next) 1256 if (devpriv->next)
1309 devpriv->next->prev = devpriv->prev; 1257 devpriv->next->prev = devpriv->prev;
1310
1311 } 1258 }
1312
1313 return 0;
1314} 1259}
1315 1260
1316/* 1261static struct comedi_driver adv_pci_dio_driver = {
1317============================================================================== 1262 .driver_name = "adv_pci_dio",
1318*/ 1263 .module = THIS_MODULE,
1319static int __devinit driver_pci_dio_pci_probe(struct pci_dev *dev, 1264 .attach = pci_dio_attach,
1320 const struct pci_device_id *ent) 1265 .detach = pci_dio_detach
1266};
1267
1268static int __devinit adv_pci_dio_pci_probe(struct pci_dev *dev,
1269 const struct pci_device_id *ent)
1321{ 1270{
1322 return comedi_pci_auto_config(dev, driver_pci_dio.driver_name); 1271 return comedi_pci_auto_config(dev, &adv_pci_dio_driver);
1323} 1272}
1324 1273
1325static void __devexit driver_pci_dio_pci_remove(struct pci_dev *dev) 1274static void __devexit adv_pci_dio_pci_remove(struct pci_dev *dev)
1326{ 1275{
1327 comedi_pci_auto_unconfig(dev); 1276 comedi_pci_auto_unconfig(dev);
1328} 1277}
1329 1278
1330static struct pci_driver driver_pci_dio_pci_driver = { 1279static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = {
1331 .id_table = pci_dio_pci_table, 1280 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
1332 .probe = &driver_pci_dio_pci_probe, 1281 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
1333 .remove = __devexit_p(&driver_pci_dio_pci_remove) 1282 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1734) },
1283 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1735) },
1284 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1736) },
1285 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1739) },
1286 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1750) },
1287 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1751) },
1288 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1752) },
1289 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1753) },
1290 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1754) },
1291 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1756) },
1292 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) },
1293 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1762) },
1294 { 0 }
1334}; 1295};
1296MODULE_DEVICE_TABLE(pci, adv_pci_dio_pci_table);
1335 1297
1336static int __init driver_pci_dio_init_module(void) 1298static struct pci_driver adv_pci_dio_pci_driver = {
1337{ 1299 .name = "adv_pci_dio",
1338 int retval; 1300 .id_table = adv_pci_dio_pci_table,
1339 1301 .probe = adv_pci_dio_pci_probe,
1340 retval = comedi_driver_register(&driver_pci_dio); 1302 .remove = __devexit_p(adv_pci_dio_pci_remove),
1341 if (retval < 0) 1303};
1342 return retval; 1304module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver);
1343
1344 driver_pci_dio_pci_driver.name = (char *)driver_pci_dio.driver_name;
1345 return pci_register_driver(&driver_pci_dio_pci_driver);
1346}
1347
1348static void __exit driver_pci_dio_cleanup_module(void)
1349{
1350 pci_unregister_driver(&driver_pci_dio_pci_driver);
1351 comedi_driver_unregister(&driver_pci_dio);
1352}
1353
1354module_init(driver_pci_dio_init_module);
1355module_exit(driver_pci_dio_cleanup_module);
1356/*
1357==============================================================================
1358*/
1359 1305
1360MODULE_AUTHOR("Comedi http://www.comedi.org"); 1306MODULE_AUTHOR("Comedi http://www.comedi.org");
1361MODULE_DESCRIPTION("Comedi low-level driver"); 1307MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c
index b0f98e5e4bf3..64d82bc4ffe4 100644
--- a/drivers/staging/comedi/drivers/aio_aio12_8.c
+++ b/drivers/staging/comedi/drivers/aio_aio12_8.c
@@ -209,36 +209,23 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
209 return 0; 209 return 0;
210} 210}
211 211
212static int aio_aio12_8_detach(struct comedi_device *dev) 212static void aio_aio12_8_detach(struct comedi_device *dev)
213{ 213{
214 subdev_8255_cleanup(dev, &dev->subdevices[2]); 214 subdev_8255_cleanup(dev, &dev->subdevices[2]);
215 if (dev->iobase) 215 if (dev->iobase)
216 release_region(dev->iobase, 24); 216 release_region(dev->iobase, 24);
217 return 0;
218} 217}
219 218
220static struct comedi_driver driver_aio_aio12_8 = { 219static struct comedi_driver aio_aio12_8_driver = {
221 .driver_name = "aio_aio12_8", 220 .driver_name = "aio_aio12_8",
222 .module = THIS_MODULE, 221 .module = THIS_MODULE,
223 .attach = aio_aio12_8_attach, 222 .attach = aio_aio12_8_attach,
224 .detach = aio_aio12_8_detach, 223 .detach = aio_aio12_8_detach,
225 .board_name = &board_types[0].name, 224 .board_name = &board_types[0].name,
226 .num_names = 1, 225 .num_names = ARRAY_SIZE(board_types),
227 .offset = sizeof(struct aio12_8_boardtype), 226 .offset = sizeof(struct aio12_8_boardtype),
228}; 227};
229 228module_comedi_driver(aio_aio12_8_driver);
230static int __init driver_aio_aio12_8_init_module(void)
231{
232 return comedi_driver_register(&driver_aio_aio12_8);
233}
234
235static void __exit driver_aio_aio12_8_cleanup_module(void)
236{
237 comedi_driver_unregister(&driver_aio_aio12_8);
238}
239
240module_init(driver_aio_aio12_8_init_module);
241module_exit(driver_aio_aio12_8_cleanup_module);
242 229
243MODULE_AUTHOR("Comedi http://www.comedi.org"); 230MODULE_AUTHOR("Comedi http://www.comedi.org");
244MODULE_DESCRIPTION("Comedi low-level driver"); 231MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/aio_iiro_16.c b/drivers/staging/comedi/drivers/aio_iiro_16.c
index 160b0a0f4f1e..04f6f94b1f47 100644
--- a/drivers/staging/comedi/drivers/aio_iiro_16.c
+++ b/drivers/staging/comedi/drivers/aio_iiro_16.c
@@ -67,30 +67,41 @@ struct aio_iiro_16_private {
67 67
68#define devpriv ((struct aio_iiro_16_private *) dev->private) 68#define devpriv ((struct aio_iiro_16_private *) dev->private)
69 69
70static int aio_iiro_16_attach(struct comedi_device *dev, 70static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
71 struct comedi_devconfig *it); 71 struct comedi_subdevice *s,
72 72 struct comedi_insn *insn,
73static int aio_iiro_16_detach(struct comedi_device *dev); 73 unsigned int *data)
74 74{
75static struct comedi_driver driver_aio_iiro_16 = { 75 if (insn->n != 2)
76 .driver_name = "aio_iiro_16", 76 return -EINVAL;
77 .module = THIS_MODULE, 77
78 .attach = aio_iiro_16_attach, 78 if (data[0]) {
79 .detach = aio_iiro_16_detach, 79 s->state &= ~data[0];
80 .board_name = &aio_iiro_16_boards[0].name, 80 s->state |= data[0] & data[1];
81 .offset = sizeof(struct aio_iiro_16_board), 81 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
82 .num_names = ARRAY_SIZE(aio_iiro_16_boards), 82 outb((s->state >> 8) & 0xff,
83}; 83 dev->iobase + AIO_IIRO_16_RELAY_8_15);
84 }
85
86 data[1] = s->state;
87
88 return 2;
89}
84 90
85static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev, 91static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
86 struct comedi_subdevice *s, 92 struct comedi_subdevice *s,
87 struct comedi_insn *insn, 93 struct comedi_insn *insn,
88 unsigned int *data); 94 unsigned int *data)
95{
96 if (insn->n != 2)
97 return -EINVAL;
89 98
90static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev, 99 data[1] = 0;
91 struct comedi_subdevice *s, 100 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
92 struct comedi_insn *insn, 101 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
93 unsigned int *data); 102
103 return 2;
104}
94 105
95static int aio_iiro_16_attach(struct comedi_device *dev, 106static int aio_iiro_16_attach(struct comedi_device *dev,
96 struct comedi_devconfig *it) 107 struct comedi_devconfig *it)
@@ -138,64 +149,22 @@ static int aio_iiro_16_attach(struct comedi_device *dev,
138 return 1; 149 return 1;
139} 150}
140 151
141static int aio_iiro_16_detach(struct comedi_device *dev) 152static void aio_iiro_16_detach(struct comedi_device *dev)
142{ 153{
143 printk(KERN_INFO "comedi%d: aio_iiro_16: remove\n", dev->minor);
144
145 if (dev->iobase) 154 if (dev->iobase)
146 release_region(dev->iobase, AIO_IIRO_16_SIZE); 155 release_region(dev->iobase, AIO_IIRO_16_SIZE);
147
148 return 0;
149}
150
151static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
152 struct comedi_subdevice *s,
153 struct comedi_insn *insn,
154 unsigned int *data)
155{
156 if (insn->n != 2)
157 return -EINVAL;
158
159 if (data[0]) {
160 s->state &= ~data[0];
161 s->state |= data[0] & data[1];
162 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
163 outb((s->state >> 8) & 0xff,
164 dev->iobase + AIO_IIRO_16_RELAY_8_15);
165 }
166
167 data[1] = s->state;
168
169 return 2;
170}
171
172static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
173 struct comedi_subdevice *s,
174 struct comedi_insn *insn,
175 unsigned int *data)
176{
177 if (insn->n != 2)
178 return -EINVAL;
179
180 data[1] = 0;
181 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
182 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
183
184 return 2;
185}
186
187static int __init driver_aio_iiro_16_init_module(void)
188{
189 return comedi_driver_register(&driver_aio_iiro_16);
190} 156}
191 157
192static void __exit driver_aio_iiro_16_cleanup_module(void) 158static struct comedi_driver aio_iiro_16_driver = {
193{ 159 .driver_name = "aio_iiro_16",
194 comedi_driver_unregister(&driver_aio_iiro_16); 160 .module = THIS_MODULE,
195} 161 .attach = aio_iiro_16_attach,
196 162 .detach = aio_iiro_16_detach,
197module_init(driver_aio_iiro_16_init_module); 163 .board_name = &aio_iiro_16_boards[0].name,
198module_exit(driver_aio_iiro_16_cleanup_module); 164 .offset = sizeof(struct aio_iiro_16_board),
165 .num_names = ARRAY_SIZE(aio_iiro_16_boards),
166};
167module_comedi_driver(aio_iiro_16_driver);
199 168
200MODULE_AUTHOR("Comedi http://www.comedi.org"); 169MODULE_AUTHOR("Comedi http://www.comedi.org");
201MODULE_DESCRIPTION("Comedi low-level driver"); 170MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c
index 566cc4411452..c9c5d97b3ca2 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -217,6 +217,14 @@ order they appear in the channel list.
217 217
218#define DIO200_DRIVER_NAME "amplc_dio200" 218#define DIO200_DRIVER_NAME "amplc_dio200"
219 219
220#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA_MODULE
221#define CONFIG_COMEDI_AMPLC_DIO200_ISA
222#endif
223
224#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI_MODULE
225#define CONFIG_COMEDI_AMPLC_DIO200_PCI
226#endif
227
220/* PCI IDs */ 228/* PCI IDs */
221#define PCI_VENDOR_ID_AMPLICON 0x14dc 229#define PCI_VENDOR_ID_AMPLICON 0x14dc
222#define PCI_DEVICE_ID_AMPLICON_PCI272 0x000a 230#define PCI_DEVICE_ID_AMPLICON_PCI272 0x000a
@@ -274,10 +282,14 @@ enum dio200_model {
274}; 282};
275 283
276enum dio200_layout { 284enum dio200_layout {
285#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
277 pc212_layout, 286 pc212_layout,
278 pc214_layout, 287 pc214_layout,
288#endif
279 pc215_layout, 289 pc215_layout,
290#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
280 pc218_layout, 291 pc218_layout,
292#endif
281 pc272_layout 293 pc272_layout
282}; 294};
283 295
@@ -290,6 +302,7 @@ struct dio200_board {
290}; 302};
291 303
292static const struct dio200_board dio200_boards[] = { 304static const struct dio200_board dio200_boards[] = {
305#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
293 { 306 {
294 .name = "pc212e", 307 .name = "pc212e",
295 .bustype = isa_bustype, 308 .bustype = isa_bustype,
@@ -308,15 +321,6 @@ static const struct dio200_board dio200_boards[] = {
308 .model = pc215e_model, 321 .model = pc215e_model,
309 .layout = pc215_layout, 322 .layout = pc215_layout,
310 }, 323 },
311#ifdef CONFIG_COMEDI_PCI
312 {
313 .name = "pci215",
314 .devid = PCI_DEVICE_ID_AMPLICON_PCI215,
315 .bustype = pci_bustype,
316 .model = pci215_model,
317 .layout = pc215_layout,
318 },
319#endif
320 { 324 {
321 .name = "pc218e", 325 .name = "pc218e",
322 .bustype = isa_bustype, 326 .bustype = isa_bustype,
@@ -329,7 +333,15 @@ static const struct dio200_board dio200_boards[] = {
329 .model = pc272e_model, 333 .model = pc272e_model,
330 .layout = pc272_layout, 334 .layout = pc272_layout,
331 }, 335 },
332#ifdef CONFIG_COMEDI_PCI 336#endif
337#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
338 {
339 .name = "pci215",
340 .devid = PCI_DEVICE_ID_AMPLICON_PCI215,
341 .bustype = pci_bustype,
342 .model = pci215_model,
343 .layout = pc215_layout,
344 },
333 { 345 {
334 .name = "pci272", 346 .name = "pci272",
335 .devid = PCI_DEVICE_ID_AMPLICON_PCI272, 347 .devid = PCI_DEVICE_ID_AMPLICON_PCI272,
@@ -337,8 +349,6 @@ static const struct dio200_board dio200_boards[] = {
337 .model = pci272_model, 349 .model = pci272_model,
338 .layout = pc272_layout, 350 .layout = pc272_layout,
339 }, 351 },
340#endif
341#ifdef CONFIG_COMEDI_PCI
342 { 352 {
343 .name = DIO200_DRIVER_NAME, 353 .name = DIO200_DRIVER_NAME,
344 .devid = PCI_DEVICE_ID_INVALID, 354 .devid = PCI_DEVICE_ID_INVALID,
@@ -367,6 +377,7 @@ struct dio200_layout_struct {
367}; 377};
368 378
369static const struct dio200_layout_struct dio200_layouts[] = { 379static const struct dio200_layout_struct dio200_layouts[] = {
380#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
370 [pc212_layout] = { 381 [pc212_layout] = {
371 .n_subdevs = 6, 382 .n_subdevs = 6,
372 .sdtype = {sd_8255, sd_8254, sd_8254, sd_8254, 383 .sdtype = {sd_8255, sd_8254, sd_8254, sd_8254,
@@ -385,6 +396,7 @@ static const struct dio200_layout_struct dio200_layouts[] = {
385 .has_int_sce = 0, 396 .has_int_sce = 0,
386 .has_clk_gat_sce = 0, 397 .has_clk_gat_sce = 0,
387 }, 398 },
399#endif
388 [pc215_layout] = { 400 [pc215_layout] = {
389 .n_subdevs = 5, 401 .n_subdevs = 5,
390 .sdtype = {sd_8255, sd_8255, sd_8254, 402 .sdtype = {sd_8255, sd_8255, sd_8254,
@@ -394,6 +406,7 @@ static const struct dio200_layout_struct dio200_layouts[] = {
394 .has_int_sce = 1, 406 .has_int_sce = 1,
395 .has_clk_gat_sce = 1, 407 .has_clk_gat_sce = 1,
396 }, 408 },
409#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
397 [pc218_layout] = { 410 [pc218_layout] = {
398 .n_subdevs = 7, 411 .n_subdevs = 7,
399 .sdtype = {sd_8254, sd_8254, sd_8255, sd_8254, 412 .sdtype = {sd_8254, sd_8254, sd_8255, sd_8254,
@@ -405,6 +418,7 @@ static const struct dio200_layout_struct dio200_layouts[] = {
405 .has_int_sce = 1, 418 .has_int_sce = 1,
406 .has_clk_gat_sce = 1, 419 .has_clk_gat_sce = 1,
407 }, 420 },
421#endif
408 [pc272_layout] = { 422 [pc272_layout] = {
409 .n_subdevs = 4, 423 .n_subdevs = 4,
410 .sdtype = {sd_8255, sd_8255, sd_8255, 424 .sdtype = {sd_8255, sd_8255, sd_8255,
@@ -419,7 +433,7 @@ static const struct dio200_layout_struct dio200_layouts[] = {
419 * PCI driver table. 433 * PCI driver table.
420 */ 434 */
421 435
422#ifdef CONFIG_COMEDI_PCI 436#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
423static DEFINE_PCI_DEVICE_TABLE(dio200_pci_table) = { 437static DEFINE_PCI_DEVICE_TABLE(dio200_pci_table) = {
424 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215) }, 438 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215) },
425 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272) }, 439 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272) },
@@ -427,7 +441,7 @@ static DEFINE_PCI_DEVICE_TABLE(dio200_pci_table) = {
427}; 441};
428 442
429MODULE_DEVICE_TABLE(pci, dio200_pci_table); 443MODULE_DEVICE_TABLE(pci, dio200_pci_table);
430#endif /* CONFIG_COMEDI_PCI */ 444#endif /* CONFIG_COMEDI_AMPLC_DIO200_PCI */
431 445
432/* 446/*
433 * Useful for shorthand access to the particular board structure 447 * Useful for shorthand access to the particular board structure
@@ -441,7 +455,7 @@ MODULE_DEVICE_TABLE(pci, dio200_pci_table);
441 feel free to suggest moving the variable to the struct comedi_device struct. 455 feel free to suggest moving the variable to the struct comedi_device struct.
442 */ 456 */
443struct dio200_private { 457struct dio200_private {
444#ifdef CONFIG_COMEDI_PCI 458#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
445 struct pci_dev *pci_dev; /* PCI device */ 459 struct pci_dev *pci_dev; /* PCI device */
446#endif 460#endif
447 int intr_sd; 461 int intr_sd;
@@ -479,7 +493,7 @@ struct dio200_subdev_intr {
479 */ 493 */
480static int dio200_attach(struct comedi_device *dev, 494static int dio200_attach(struct comedi_device *dev,
481 struct comedi_devconfig *it); 495 struct comedi_devconfig *it);
482static int dio200_detach(struct comedi_device *dev); 496static void dio200_detach(struct comedi_device *dev);
483static struct comedi_driver driver_amplc_dio200 = { 497static struct comedi_driver driver_amplc_dio200 = {
484 .driver_name = DIO200_DRIVER_NAME, 498 .driver_name = DIO200_DRIVER_NAME,
485 .module = THIS_MODULE, 499 .module = THIS_MODULE,
@@ -490,12 +504,12 @@ static struct comedi_driver driver_amplc_dio200 = {
490 .num_names = ARRAY_SIZE(dio200_boards), 504 .num_names = ARRAY_SIZE(dio200_boards),
491}; 505};
492 506
493#ifdef CONFIG_COMEDI_PCI 507#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
494static int __devinit driver_amplc_dio200_pci_probe(struct pci_dev *dev, 508static int __devinit driver_amplc_dio200_pci_probe(struct pci_dev *dev,
495 const struct pci_device_id 509 const struct pci_device_id
496 *ent) 510 *ent)
497{ 511{
498 return comedi_pci_auto_config(dev, driver_amplc_dio200.driver_name); 512 return comedi_pci_auto_config(dev, &driver_amplc_dio200);
499} 513}
500 514
501static void __devexit driver_amplc_dio200_pci_remove(struct pci_dev *dev) 515static void __devexit driver_amplc_dio200_pci_remove(struct pci_dev *dev)
@@ -549,7 +563,7 @@ module_exit(driver_amplc_dio200_cleanup_module);
549 * This function looks for a PCI device matching the requested board name, 563 * This function looks for a PCI device matching the requested board name,
550 * bus and slot. 564 * bus and slot.
551 */ 565 */
552#ifdef CONFIG_COMEDI_PCI 566#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
553static int 567static int
554dio200_find_pci(struct comedi_device *dev, int bus, int slot, 568dio200_find_pci(struct comedi_device *dev, int bus, int slot,
555 struct pci_dev **pci_dev_p) 569 struct pci_dev **pci_dev_p)
@@ -611,6 +625,7 @@ dio200_find_pci(struct comedi_device *dev, int bus, int slot,
611 * This function checks and requests an I/O region, reporting an error 625 * This function checks and requests an I/O region, reporting an error
612 * if there is a conflict. 626 * if there is a conflict.
613 */ 627 */
628#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
614static int 629static int
615dio200_request_region(unsigned minor, unsigned long from, unsigned long extent) 630dio200_request_region(unsigned minor, unsigned long from, unsigned long extent)
616{ 631{
@@ -621,6 +636,7 @@ dio200_request_region(unsigned minor, unsigned long from, unsigned long extent)
621 } 636 }
622 return 0; 637 return 0;
623} 638}
639#endif
624 640
625/* 641/*
626 * 'insn_bits' function for an 'INTERRUPT' subdevice. 642 * 'insn_bits' function for an 'INTERRUPT' subdevice.
@@ -1332,7 +1348,7 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1332 struct comedi_subdevice *s; 1348 struct comedi_subdevice *s;
1333 unsigned long iobase = 0; 1349 unsigned long iobase = 0;
1334 unsigned int irq = 0; 1350 unsigned int irq = 0;
1335#ifdef CONFIG_COMEDI_PCI 1351#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
1336 struct pci_dev *pci_dev = NULL; 1352 struct pci_dev *pci_dev = NULL;
1337 int bus = 0, slot = 0; 1353 int bus = 0, slot = 0;
1338#endif 1354#endif
@@ -1354,12 +1370,14 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1354 1370
1355 /* Process options. */ 1371 /* Process options. */
1356 switch (thisboard->bustype) { 1372 switch (thisboard->bustype) {
1373#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
1357 case isa_bustype: 1374 case isa_bustype:
1358 iobase = it->options[0]; 1375 iobase = it->options[0];
1359 irq = it->options[1]; 1376 irq = it->options[1];
1360 share_irq = 0; 1377 share_irq = 0;
1361 break; 1378 break;
1362#ifdef CONFIG_COMEDI_PCI 1379#endif
1380#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
1363 case pci_bustype: 1381 case pci_bustype:
1364 bus = it->options[0]; 1382 bus = it->options[0];
1365 slot = it->options[1]; 1383 slot = it->options[1];
@@ -1382,7 +1400,7 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1382 devpriv->intr_sd = -1; 1400 devpriv->intr_sd = -1;
1383 1401
1384 /* Enable device and reserve I/O spaces. */ 1402 /* Enable device and reserve I/O spaces. */
1385#ifdef CONFIG_COMEDI_PCI 1403#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
1386 if (pci_dev) { 1404 if (pci_dev) {
1387 ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME); 1405 ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
1388 if (ret < 0) { 1406 if (ret < 0) {
@@ -1396,9 +1414,11 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1396 } else 1414 } else
1397#endif 1415#endif
1398 { 1416 {
1417#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
1399 ret = dio200_request_region(dev->minor, iobase, DIO200_IO_SIZE); 1418 ret = dio200_request_region(dev->minor, iobase, DIO200_IO_SIZE);
1400 if (ret < 0) 1419 if (ret < 0)
1401 return ret; 1420 return ret;
1421#endif
1402 } 1422 }
1403 dev->iobase = iobase; 1423 dev->iobase = iobase;
1404 1424
@@ -1474,12 +1494,19 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1474 } 1494 }
1475 1495
1476 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name); 1496 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name);
1477 if (thisboard->bustype == isa_bustype) { 1497 switch (thisboard->bustype) {
1498#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
1499 case isa_bustype:
1478 printk("(base %#lx) ", iobase); 1500 printk("(base %#lx) ", iobase);
1479 } else { 1501 break;
1480#ifdef CONFIG_COMEDI_PCI 1502#endif
1503#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
1504 case pci_bustype:
1481 printk("(pci %s) ", pci_name(pci_dev)); 1505 printk("(pci %s) ", pci_name(pci_dev));
1506 break;
1482#endif 1507#endif
1508 default:
1509 break;
1483 } 1510 }
1484 if (irq) 1511 if (irq)
1485 printk("(irq %u%s) ", irq, (dev->irq ? "" : " UNAVAILABLE")); 1512 printk("(irq %u%s) ", irq, (dev->irq ? "" : " UNAVAILABLE"));
@@ -1491,22 +1518,11 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1491 return 1; 1518 return 1;
1492} 1519}
1493 1520
1494/* 1521static void dio200_detach(struct comedi_device *dev)
1495 * _detach is called to deconfigure a device. It should deallocate
1496 * resources.
1497 * This function is also called when _attach() fails, so it should be
1498 * careful not to release resources that were not necessarily
1499 * allocated by _attach(). dev->private and dev->subdevices are
1500 * deallocated automatically by the core.
1501 */
1502static int dio200_detach(struct comedi_device *dev)
1503{ 1522{
1504 const struct dio200_layout_struct *layout; 1523 const struct dio200_layout_struct *layout;
1505 unsigned n; 1524 unsigned n;
1506 1525
1507 printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor,
1508 DIO200_DRIVER_NAME);
1509
1510 if (dev->irq) 1526 if (dev->irq)
1511 free_irq(dev->irq, dev); 1527 free_irq(dev->irq, dev);
1512 if (dev->subdevices) { 1528 if (dev->subdevices) {
@@ -1529,7 +1545,7 @@ static int dio200_detach(struct comedi_device *dev)
1529 } 1545 }
1530 } 1546 }
1531 if (devpriv) { 1547 if (devpriv) {
1532#ifdef CONFIG_COMEDI_PCI 1548#ifdef CONFIG_COMEDI_AMPLC_DIO200_PCI
1533 if (devpriv->pci_dev) { 1549 if (devpriv->pci_dev) {
1534 if (dev->iobase) 1550 if (dev->iobase)
1535 comedi_pci_disable(devpriv->pci_dev); 1551 comedi_pci_disable(devpriv->pci_dev);
@@ -1537,15 +1553,12 @@ static int dio200_detach(struct comedi_device *dev)
1537 } else 1553 } else
1538#endif 1554#endif
1539 { 1555 {
1556#ifdef CONFIG_COMEDI_AMPLC_DIO200_ISA
1540 if (dev->iobase) 1557 if (dev->iobase)
1541 release_region(dev->iobase, DIO200_IO_SIZE); 1558 release_region(dev->iobase, DIO200_IO_SIZE);
1559#endif
1542 } 1560 }
1543 } 1561 }
1544 if (dev->board_name)
1545 printk(KERN_INFO "comedi%d: %s removed\n",
1546 dev->minor, dev->board_name);
1547
1548 return 0;
1549} 1562}
1550 1563
1551MODULE_AUTHOR("Comedi http://www.comedi.org"); 1564MODULE_AUTHOR("Comedi http://www.comedi.org");
diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c
index 7972cadd403e..57ba3228b1a9 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -63,6 +63,14 @@ unused.
63 63
64#define PC236_DRIVER_NAME "amplc_pc236" 64#define PC236_DRIVER_NAME "amplc_pc236"
65 65
66#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA_MODULE
67#define CONFIG_COMEDI_AMPLC_PC236_ISA
68#endif
69
70#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI_MODULE
71#define CONFIG_COMEDI_AMPLC_PC236_PCI
72#endif
73
66/* PCI236 PCI configuration register information */ 74/* PCI236 PCI configuration register information */
67#define PCI_VENDOR_ID_AMPLICON 0x14dc 75#define PCI_VENDOR_ID_AMPLICON 0x14dc
68#define PCI_DEVICE_ID_AMPLICON_PCI236 0x0009 76#define PCI_DEVICE_ID_AMPLICON_PCI236 0x0009
@@ -106,13 +114,15 @@ struct pc236_board {
106 enum pc236_model model; 114 enum pc236_model model;
107}; 115};
108static const struct pc236_board pc236_boards[] = { 116static const struct pc236_board pc236_boards[] = {
117#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
109 { 118 {
110 .name = "pc36at", 119 .name = "pc36at",
111 .fancy_name = "PC36AT", 120 .fancy_name = "PC36AT",
112 .bustype = isa_bustype, 121 .bustype = isa_bustype,
113 .model = pc36at_model, 122 .model = pc36at_model,
114 }, 123 },
115#ifdef CONFIG_COMEDI_PCI 124#endif
125#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
116 { 126 {
117 .name = "pci236", 127 .name = "pci236",
118 .fancy_name = "PCI236", 128 .fancy_name = "PCI236",
@@ -120,8 +130,6 @@ static const struct pc236_board pc236_boards[] = {
120 .bustype = pci_bustype, 130 .bustype = pci_bustype,
121 .model = pci236_model, 131 .model = pci236_model,
122 }, 132 },
123#endif
124#ifdef CONFIG_COMEDI_PCI
125 { 133 {
126 .name = PC236_DRIVER_NAME, 134 .name = PC236_DRIVER_NAME,
127 .fancy_name = PC236_DRIVER_NAME, 135 .fancy_name = PC236_DRIVER_NAME,
@@ -132,14 +140,14 @@ static const struct pc236_board pc236_boards[] = {
132#endif 140#endif
133}; 141};
134 142
135#ifdef CONFIG_COMEDI_PCI 143#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
136static DEFINE_PCI_DEVICE_TABLE(pc236_pci_table) = { 144static DEFINE_PCI_DEVICE_TABLE(pc236_pci_table) = {
137 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI236) }, 145 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI236) },
138 {0} 146 {0}
139}; 147};
140 148
141MODULE_DEVICE_TABLE(pci, pc236_pci_table); 149MODULE_DEVICE_TABLE(pci, pc236_pci_table);
142#endif /* CONFIG_COMEDI_PCI */ 150#endif /* CONFIG_COMEDI_AMPLC_PC236_PCI */
143 151
144/* 152/*
145 * Useful for shorthand access to the particular board structure 153 * Useful for shorthand access to the particular board structure
@@ -151,7 +159,7 @@ MODULE_DEVICE_TABLE(pci, pc236_pci_table);
151 feel free to suggest moving the variable to the struct comedi_device struct. 159 feel free to suggest moving the variable to the struct comedi_device struct.
152 */ 160 */
153struct pc236_private { 161struct pc236_private {
154#ifdef CONFIG_COMEDI_PCI 162#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
155 /* PCI device */ 163 /* PCI device */
156 struct pci_dev *pci_dev; 164 struct pci_dev *pci_dev;
157 unsigned long lcr_iobase; /* PLX PCI9052 config registers in PCIBAR1 */ 165 unsigned long lcr_iobase; /* PLX PCI9052 config registers in PCIBAR1 */
@@ -168,7 +176,7 @@ struct pc236_private {
168 * the device code. 176 * the device code.
169 */ 177 */
170static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it); 178static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it);
171static int pc236_detach(struct comedi_device *dev); 179static void pc236_detach(struct comedi_device *dev);
172static struct comedi_driver driver_amplc_pc236 = { 180static struct comedi_driver driver_amplc_pc236 = {
173 .driver_name = PC236_DRIVER_NAME, 181 .driver_name = PC236_DRIVER_NAME,
174 .module = THIS_MODULE, 182 .module = THIS_MODULE,
@@ -179,12 +187,12 @@ static struct comedi_driver driver_amplc_pc236 = {
179 .num_names = ARRAY_SIZE(pc236_boards), 187 .num_names = ARRAY_SIZE(pc236_boards),
180}; 188};
181 189
182#ifdef CONFIG_COMEDI_PCI 190#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
183static int __devinit driver_amplc_pc236_pci_probe(struct pci_dev *dev, 191static int __devinit driver_amplc_pc236_pci_probe(struct pci_dev *dev,
184 const struct pci_device_id 192 const struct pci_device_id
185 *ent) 193 *ent)
186{ 194{
187 return comedi_pci_auto_config(dev, driver_amplc_pc236.driver_name); 195 return comedi_pci_auto_config(dev, &driver_amplc_pc236);
188} 196}
189 197
190static void __devexit driver_amplc_pc236_pci_remove(struct pci_dev *dev) 198static void __devexit driver_amplc_pc236_pci_remove(struct pci_dev *dev)
@@ -234,8 +242,10 @@ module_init(driver_amplc_pc236_init_module);
234module_exit(driver_amplc_pc236_cleanup_module); 242module_exit(driver_amplc_pc236_cleanup_module);
235#endif 243#endif
236 244
245#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
237static int pc236_request_region(unsigned minor, unsigned long from, 246static int pc236_request_region(unsigned minor, unsigned long from,
238 unsigned long extent); 247 unsigned long extent);
248#endif
239static void pc236_intr_disable(struct comedi_device *dev); 249static void pc236_intr_disable(struct comedi_device *dev);
240static void pc236_intr_enable(struct comedi_device *dev); 250static void pc236_intr_enable(struct comedi_device *dev);
241static int pc236_intr_check(struct comedi_device *dev); 251static int pc236_intr_check(struct comedi_device *dev);
@@ -255,7 +265,7 @@ static irqreturn_t pc236_interrupt(int irq, void *d);
255 * This function looks for a PCI device matching the requested board name, 265 * This function looks for a PCI device matching the requested board name,
256 * bus and slot. 266 * bus and slot.
257 */ 267 */
258#ifdef CONFIG_COMEDI_PCI 268#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
259static int 269static int
260pc236_find_pci(struct comedi_device *dev, int bus, int slot, 270pc236_find_pci(struct comedi_device *dev, int bus, int slot,
261 struct pci_dev **pci_dev_p) 271 struct pci_dev **pci_dev_p)
@@ -324,7 +334,7 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
324 struct comedi_subdevice *s; 334 struct comedi_subdevice *s;
325 unsigned long iobase = 0; 335 unsigned long iobase = 0;
326 unsigned int irq = 0; 336 unsigned int irq = 0;
327#ifdef CONFIG_COMEDI_PCI 337#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
328 struct pci_dev *pci_dev = NULL; 338 struct pci_dev *pci_dev = NULL;
329 int bus = 0, slot = 0; 339 int bus = 0, slot = 0;
330#endif 340#endif
@@ -345,12 +355,14 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
345 } 355 }
346 /* Process options. */ 356 /* Process options. */
347 switch (thisboard->bustype) { 357 switch (thisboard->bustype) {
358#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
348 case isa_bustype: 359 case isa_bustype:
349 iobase = it->options[0]; 360 iobase = it->options[0];
350 irq = it->options[1]; 361 irq = it->options[1];
351 share_irq = 0; 362 share_irq = 0;
352 break; 363 break;
353#ifdef CONFIG_COMEDI_PCI 364#endif
365#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
354 case pci_bustype: 366 case pci_bustype:
355 bus = it->options[0]; 367 bus = it->options[0];
356 slot = it->options[1]; 368 slot = it->options[1];
@@ -361,7 +373,7 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
361 return ret; 373 return ret;
362 devpriv->pci_dev = pci_dev; 374 devpriv->pci_dev = pci_dev;
363 break; 375 break;
364#endif /* CONFIG_COMEDI_PCI */ 376#endif
365 default: 377 default:
366 printk(KERN_ERR 378 printk(KERN_ERR
367 "comedi%d: %s: BUG! cannot determine board type!\n", 379 "comedi%d: %s: BUG! cannot determine board type!\n",
@@ -376,7 +388,7 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
376 dev->board_name = thisboard->name; 388 dev->board_name = thisboard->name;
377 389
378 /* Enable device and reserve I/O spaces. */ 390 /* Enable device and reserve I/O spaces. */
379#ifdef CONFIG_COMEDI_PCI 391#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
380 if (pci_dev) { 392 if (pci_dev) {
381 393
382 ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME); 394 ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME);
@@ -392,9 +404,11 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
392 } else 404 } else
393#endif 405#endif
394 { 406 {
407#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
395 ret = pc236_request_region(dev->minor, iobase, PC236_IO_SIZE); 408 ret = pc236_request_region(dev->minor, iobase, PC236_IO_SIZE);
396 if (ret < 0) 409 if (ret < 0)
397 return ret; 410 return ret;
411#endif
398 } 412 }
399 dev->iobase = iobase; 413 dev->iobase = iobase;
400 414
@@ -439,12 +453,19 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
439 } 453 }
440 } 454 }
441 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name); 455 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name);
442 if (thisboard->bustype == isa_bustype) { 456 switch (thisboard->bustype) {
457#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
458 case isa_bustype:
443 printk("(base %#lx) ", iobase); 459 printk("(base %#lx) ", iobase);
444 } else { 460 break;
445#ifdef CONFIG_COMEDI_PCI 461#endif
462#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
463 case pci_bustype:
446 printk("(pci %s) ", pci_name(pci_dev)); 464 printk("(pci %s) ", pci_name(pci_dev));
465 break;
447#endif 466#endif
467 default:
468 break;
448 } 469 }
449 if (irq) 470 if (irq)
450 printk("(irq %u%s) ", irq, (dev->irq ? "" : " UNAVAILABLE")); 471 printk("(irq %u%s) ", irq, (dev->irq ? "" : " UNAVAILABLE"));
@@ -456,27 +477,16 @@ static int pc236_attach(struct comedi_device *dev, struct comedi_devconfig *it)
456 return 1; 477 return 1;
457} 478}
458 479
459/* 480static void pc236_detach(struct comedi_device *dev)
460 * _detach is called to deconfigure a device. It should deallocate
461 * resources.
462 * This function is also called when _attach() fails, so it should be
463 * careful not to release resources that were not necessarily
464 * allocated by _attach(). dev->private and dev->subdevices are
465 * deallocated automatically by the core.
466 */
467static int pc236_detach(struct comedi_device *dev)
468{ 481{
469 printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor,
470 PC236_DRIVER_NAME);
471 if (devpriv) 482 if (devpriv)
472 pc236_intr_disable(dev); 483 pc236_intr_disable(dev);
473
474 if (dev->irq) 484 if (dev->irq)
475 free_irq(dev->irq, dev); 485 free_irq(dev->irq, dev);
476 if (dev->subdevices) 486 if (dev->subdevices)
477 subdev_8255_cleanup(dev, dev->subdevices + 0); 487 subdev_8255_cleanup(dev, dev->subdevices + 0);
478 if (devpriv) { 488 if (devpriv) {
479#ifdef CONFIG_COMEDI_PCI 489#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
480 if (devpriv->pci_dev) { 490 if (devpriv->pci_dev) {
481 if (dev->iobase) 491 if (dev->iobase)
482 comedi_pci_disable(devpriv->pci_dev); 492 comedi_pci_disable(devpriv->pci_dev);
@@ -484,21 +494,19 @@ static int pc236_detach(struct comedi_device *dev)
484 } else 494 } else
485#endif 495#endif
486 { 496 {
497#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
487 if (dev->iobase) 498 if (dev->iobase)
488 release_region(dev->iobase, PC236_IO_SIZE); 499 release_region(dev->iobase, PC236_IO_SIZE);
500#endif
489 } 501 }
490 } 502 }
491 if (dev->board_name) {
492 printk(KERN_INFO "comedi%d: %s removed\n",
493 dev->minor, dev->board_name);
494 }
495 return 0;
496} 503}
497 504
498/* 505/*
499 * This function checks and requests an I/O region, reporting an error 506 * This function checks and requests an I/O region, reporting an error
500 * if there is a conflict. 507 * if there is a conflict.
501 */ 508 */
509#ifdef CONFIG_COMEDI_AMPLC_PC236_ISA
502static int pc236_request_region(unsigned minor, unsigned long from, 510static int pc236_request_region(unsigned minor, unsigned long from,
503 unsigned long extent) 511 unsigned long extent)
504{ 512{
@@ -509,6 +517,7 @@ static int pc236_request_region(unsigned minor, unsigned long from,
509 } 517 }
510 return 0; 518 return 0;
511} 519}
520#endif
512 521
513/* 522/*
514 * This function is called to mark the interrupt as disabled (no command 523 * This function is called to mark the interrupt as disabled (no command
@@ -521,7 +530,7 @@ static void pc236_intr_disable(struct comedi_device *dev)
521 530
522 spin_lock_irqsave(&dev->spinlock, flags); 531 spin_lock_irqsave(&dev->spinlock, flags);
523 devpriv->enable_irq = 0; 532 devpriv->enable_irq = 0;
524#ifdef CONFIG_COMEDI_PCI 533#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
525 if (devpriv->lcr_iobase) 534 if (devpriv->lcr_iobase)
526 outl(PCI236_INTR_DISABLE, devpriv->lcr_iobase + PLX9052_INTCSR); 535 outl(PCI236_INTR_DISABLE, devpriv->lcr_iobase + PLX9052_INTCSR);
527#endif 536#endif
@@ -539,7 +548,7 @@ static void pc236_intr_enable(struct comedi_device *dev)
539 548
540 spin_lock_irqsave(&dev->spinlock, flags); 549 spin_lock_irqsave(&dev->spinlock, flags);
541 devpriv->enable_irq = 1; 550 devpriv->enable_irq = 1;
542#ifdef CONFIG_COMEDI_PCI 551#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
543 if (devpriv->lcr_iobase) 552 if (devpriv->lcr_iobase)
544 outl(PCI236_INTR_ENABLE, devpriv->lcr_iobase + PLX9052_INTCSR); 553 outl(PCI236_INTR_ENABLE, devpriv->lcr_iobase + PLX9052_INTCSR);
545#endif 554#endif
@@ -561,7 +570,7 @@ static int pc236_intr_check(struct comedi_device *dev)
561 spin_lock_irqsave(&dev->spinlock, flags); 570 spin_lock_irqsave(&dev->spinlock, flags);
562 if (devpriv->enable_irq) { 571 if (devpriv->enable_irq) {
563 retval = 1; 572 retval = 1;
564#ifdef CONFIG_COMEDI_PCI 573#ifdef CONFIG_COMEDI_AMPLC_PC236_PCI
565 if (devpriv->lcr_iobase) { 574 if (devpriv->lcr_iobase) {
566 if ((inl(devpriv->lcr_iobase + PLX9052_INTCSR) 575 if ((inl(devpriv->lcr_iobase + PLX9052_INTCSR)
567 & PLX9052_INTCSR_LI1STAT_MASK) 576 & PLX9052_INTCSR_LI1STAT_MASK)
diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c
index 191ac0d23ce7..974d7450051e 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -50,6 +50,14 @@ The state of the outputs can be read.
50 50
51#define PC263_DRIVER_NAME "amplc_pc263" 51#define PC263_DRIVER_NAME "amplc_pc263"
52 52
53#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA_MODULE
54#define CONFIG_COMEDI_AMPLC_PC263_ISA
55#endif
56
57#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI_MODULE
58#define CONFIG_COMEDI_AMPLC_PC263_PCI
59#endif
60
53/* PCI263 PCI configuration register information */ 61/* PCI263 PCI configuration register information */
54#define PCI_VENDOR_ID_AMPLICON 0x14dc 62#define PCI_VENDOR_ID_AMPLICON 0x14dc
55#define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c 63#define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c
@@ -73,13 +81,15 @@ struct pc263_board {
73 enum pc263_model model; 81 enum pc263_model model;
74}; 82};
75static const struct pc263_board pc263_boards[] = { 83static const struct pc263_board pc263_boards[] = {
84#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
76 { 85 {
77 .name = "pc263", 86 .name = "pc263",
78 .fancy_name = "PC263", 87 .fancy_name = "PC263",
79 .bustype = isa_bustype, 88 .bustype = isa_bustype,
80 .model = pc263_model, 89 .model = pc263_model,
81 }, 90 },
82#ifdef CONFIG_COMEDI_PCI 91#endif
92#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
83 { 93 {
84 .name = "pci263", 94 .name = "pci263",
85 .fancy_name = "PCI263", 95 .fancy_name = "PCI263",
@@ -87,8 +97,6 @@ static const struct pc263_board pc263_boards[] = {
87 .bustype = pci_bustype, 97 .bustype = pci_bustype,
88 .model = pci263_model, 98 .model = pci263_model,
89 }, 99 },
90#endif
91#ifdef CONFIG_COMEDI_PCI
92 { 100 {
93 .name = PC263_DRIVER_NAME, 101 .name = PC263_DRIVER_NAME,
94 .fancy_name = PC263_DRIVER_NAME, 102 .fancy_name = PC263_DRIVER_NAME,
@@ -99,14 +107,14 @@ static const struct pc263_board pc263_boards[] = {
99#endif 107#endif
100}; 108};
101 109
102#ifdef CONFIG_COMEDI_PCI 110#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
103static DEFINE_PCI_DEVICE_TABLE(pc263_pci_table) = { 111static DEFINE_PCI_DEVICE_TABLE(pc263_pci_table) = {
104 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) }, 112 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) },
105 {0} 113 {0}
106}; 114};
107 115
108MODULE_DEVICE_TABLE(pci, pc263_pci_table); 116MODULE_DEVICE_TABLE(pci, pc263_pci_table);
109#endif /* CONFIG_COMEDI_PCI */ 117#endif /* CONFIG_COMEDI_AMPLC_PC263_PCI */
110 118
111/* 119/*
112 * Useful for shorthand access to the particular board structure 120 * Useful for shorthand access to the particular board structure
@@ -117,14 +125,14 @@ MODULE_DEVICE_TABLE(pci, pc263_pci_table);
117 several hardware drivers keep similar information in this structure, 125 several hardware drivers keep similar information in this structure,
118 feel free to suggest moving the variable to the struct comedi_device struct. 126 feel free to suggest moving the variable to the struct comedi_device struct.
119*/ 127*/
120#ifdef CONFIG_COMEDI_PCI 128#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
121struct pc263_private { 129struct pc263_private {
122 /* PCI device. */ 130 /* PCI device. */
123 struct pci_dev *pci_dev; 131 struct pci_dev *pci_dev;
124}; 132};
125 133
126#define devpriv ((struct pc263_private *)dev->private) 134#define devpriv ((struct pc263_private *)dev->private)
127#endif /* CONFIG_COMEDI_PCI */ 135#endif /* CONFIG_COMEDI_AMPLC_PC263_PCI */
128 136
129/* 137/*
130 * The struct comedi_driver structure tells the Comedi core module 138 * The struct comedi_driver structure tells the Comedi core module
@@ -133,7 +141,7 @@ struct pc263_private {
133 * the device code. 141 * the device code.
134 */ 142 */
135static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it); 143static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it);
136static int pc263_detach(struct comedi_device *dev); 144static void pc263_detach(struct comedi_device *dev);
137static struct comedi_driver driver_amplc_pc263 = { 145static struct comedi_driver driver_amplc_pc263 = {
138 .driver_name = PC263_DRIVER_NAME, 146 .driver_name = PC263_DRIVER_NAME,
139 .module = THIS_MODULE, 147 .module = THIS_MODULE,
@@ -144,8 +152,10 @@ static struct comedi_driver driver_amplc_pc263 = {
144 .num_names = ARRAY_SIZE(pc263_boards), 152 .num_names = ARRAY_SIZE(pc263_boards),
145}; 153};
146 154
155#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
147static int pc263_request_region(unsigned minor, unsigned long from, 156static int pc263_request_region(unsigned minor, unsigned long from,
148 unsigned long extent); 157 unsigned long extent);
158#endif
149static int pc263_dio_insn_bits(struct comedi_device *dev, 159static int pc263_dio_insn_bits(struct comedi_device *dev,
150 struct comedi_subdevice *s, 160 struct comedi_subdevice *s,
151 struct comedi_insn *insn, unsigned int *data); 161 struct comedi_insn *insn, unsigned int *data);
@@ -157,7 +167,7 @@ static int pc263_dio_insn_config(struct comedi_device *dev,
157 * This function looks for a PCI device matching the requested board name, 167 * This function looks for a PCI device matching the requested board name,
158 * bus and slot. 168 * bus and slot.
159 */ 169 */
160#ifdef CONFIG_COMEDI_PCI 170#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
161static int 171static int
162pc263_find_pci(struct comedi_device *dev, int bus, int slot, 172pc263_find_pci(struct comedi_device *dev, int bus, int slot,
163 struct pci_dev **pci_dev_p) 173 struct pci_dev **pci_dev_p)
@@ -225,7 +235,7 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
225{ 235{
226 struct comedi_subdevice *s; 236 struct comedi_subdevice *s;
227 unsigned long iobase = 0; 237 unsigned long iobase = 0;
228#ifdef CONFIG_COMEDI_PCI 238#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
229 struct pci_dev *pci_dev = NULL; 239 struct pci_dev *pci_dev = NULL;
230 int bus = 0, slot = 0; 240 int bus = 0, slot = 0;
231#endif 241#endif
@@ -237,7 +247,7 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
237 * Allocate the private structure area. alloc_private() is a 247 * Allocate the private structure area. alloc_private() is a
238 * convenient macro defined in comedidev.h. 248 * convenient macro defined in comedidev.h.
239 */ 249 */
240#ifdef CONFIG_COMEDI_PCI 250#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
241 ret = alloc_private(dev, sizeof(struct pc263_private)); 251 ret = alloc_private(dev, sizeof(struct pc263_private));
242 if (ret < 0) { 252 if (ret < 0) {
243 printk(KERN_ERR "comedi%d: error! out of memory!\n", 253 printk(KERN_ERR "comedi%d: error! out of memory!\n",
@@ -247,10 +257,12 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
247#endif 257#endif
248 /* Process options. */ 258 /* Process options. */
249 switch (thisboard->bustype) { 259 switch (thisboard->bustype) {
260#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
250 case isa_bustype: 261 case isa_bustype:
251 iobase = it->options[0]; 262 iobase = it->options[0];
252 break; 263 break;
253#ifdef CONFIG_COMEDI_PCI 264#endif
265#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
254 case pci_bustype: 266 case pci_bustype:
255 bus = it->options[0]; 267 bus = it->options[0];
256 slot = it->options[1]; 268 slot = it->options[1];
@@ -260,7 +272,7 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
260 return ret; 272 return ret;
261 devpriv->pci_dev = pci_dev; 273 devpriv->pci_dev = pci_dev;
262 break; 274 break;
263#endif /* CONFIG_COMEDI_PCI */ 275#endif
264 default: 276 default:
265 printk(KERN_ERR 277 printk(KERN_ERR
266 "comedi%d: %s: BUG! cannot determine board type!\n", 278 "comedi%d: %s: BUG! cannot determine board type!\n",
@@ -275,7 +287,7 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
275 dev->board_name = thisboard->name; 287 dev->board_name = thisboard->name;
276 288
277 /* Enable device and reserve I/O spaces. */ 289 /* Enable device and reserve I/O spaces. */
278#ifdef CONFIG_COMEDI_PCI 290#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
279 if (pci_dev) { 291 if (pci_dev) {
280 ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME); 292 ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
281 if (ret < 0) { 293 if (ret < 0) {
@@ -289,9 +301,11 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
289 } else 301 } else
290#endif 302#endif
291 { 303 {
304#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
292 ret = pc263_request_region(dev->minor, iobase, PC263_IO_SIZE); 305 ret = pc263_request_region(dev->minor, iobase, PC263_IO_SIZE);
293 if (ret < 0) 306 if (ret < 0)
294 return ret; 307 return ret;
308#endif
295 } 309 }
296 dev->iobase = iobase; 310 dev->iobase = iobase;
297 311
@@ -322,12 +336,18 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
322 s->state = s->state | (inb(dev->iobase) << 8); 336 s->state = s->state | (inb(dev->iobase) << 8);
323 337
324 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name); 338 printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name);
325 if (thisboard->bustype == isa_bustype) { 339 switch (thisboard->bustype) {
340#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
341 case isa_bustype:
326 printk("(base %#lx) ", iobase); 342 printk("(base %#lx) ", iobase);
327 } else { 343 break;
328#ifdef CONFIG_COMEDI_PCI 344#endif
345#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
329 printk("(pci %s) ", pci_name(pci_dev)); 346 printk("(pci %s) ", pci_name(pci_dev));
347 break;
330#endif 348#endif
349 default:
350 break;
331 } 351 }
332 352
333 printk("attached\n"); 353 printk("attached\n");
@@ -335,23 +355,13 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
335 return 1; 355 return 1;
336} 356}
337 357
338/* 358static void pc263_detach(struct comedi_device *dev)
339 * _detach is called to deconfigure a device. It should deallocate
340 * resources.
341 * This function is also called when _attach() fails, so it should be
342 * careful not to release resources that were not necessarily
343 * allocated by _attach(). dev->private and dev->subdevices are
344 * deallocated automatically by the core.
345 */
346static int pc263_detach(struct comedi_device *dev)
347{ 359{
348 printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor, 360#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
349 PC263_DRIVER_NAME); 361 if (devpriv)
350
351#ifdef CONFIG_COMEDI_PCI
352 if (devpriv) {
353#endif 362#endif
354#ifdef CONFIG_COMEDI_PCI 363 {
364#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
355 if (devpriv->pci_dev) { 365 if (devpriv->pci_dev) {
356 if (dev->iobase) 366 if (dev->iobase)
357 comedi_pci_disable(devpriv->pci_dev); 367 comedi_pci_disable(devpriv->pci_dev);
@@ -359,21 +369,19 @@ static int pc263_detach(struct comedi_device *dev)
359 } else 369 } else
360#endif 370#endif
361 { 371 {
372#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
362 if (dev->iobase) 373 if (dev->iobase)
363 release_region(dev->iobase, PC263_IO_SIZE); 374 release_region(dev->iobase, PC263_IO_SIZE);
375#endif
364 } 376 }
365 } 377 }
366 if (dev->board_name) {
367 printk(KERN_INFO "comedi%d: %s removed\n",
368 dev->minor, dev->board_name);
369 }
370 return 0;
371} 378}
372 379
373/* 380/*
374 * This function checks and requests an I/O region, reporting an error 381 * This function checks and requests an I/O region, reporting an error
375 * if there is a conflict. 382 * if there is a conflict.
376 */ 383 */
384#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
377static int pc263_request_region(unsigned minor, unsigned long from, 385static int pc263_request_region(unsigned minor, unsigned long from,
378 unsigned long extent) 386 unsigned long extent)
379{ 387{
@@ -384,6 +392,7 @@ static int pc263_request_region(unsigned minor, unsigned long from,
384 } 392 }
385 return 0; 393 return 0;
386} 394}
395#endif
387 396
388/* DIO devices are slightly special. Although it is possible to 397/* DIO devices are slightly special. Although it is possible to
389 * implement the insn_read/insn_write interface, it is much more 398 * implement the insn_read/insn_write interface, it is much more
@@ -429,12 +438,12 @@ static int pc263_dio_insn_config(struct comedi_device *dev,
429 * A convenient macro that defines init_module() and cleanup_module(), 438 * A convenient macro that defines init_module() and cleanup_module(),
430 * as necessary. 439 * as necessary.
431 */ 440 */
432#ifdef CONFIG_COMEDI_PCI 441#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
433static int __devinit driver_amplc_pc263_pci_probe(struct pci_dev *dev, 442static int __devinit driver_amplc_pc263_pci_probe(struct pci_dev *dev,
434 const struct pci_device_id 443 const struct pci_device_id
435 *ent) 444 *ent)
436{ 445{
437 return comedi_pci_auto_config(dev, driver_amplc_pc263.driver_name); 446 return comedi_pci_auto_config(dev, &driver_amplc_pc263);
438} 447}
439 448
440static void __devexit driver_amplc_pc263_pci_remove(struct pci_dev *dev) 449static void __devexit driver_amplc_pc263_pci_remove(struct pci_dev *dev)
diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index b278917cec25..fbf19cae8747 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -380,18 +380,6 @@ static const struct pci224_board pci224_boards[] = {
380}; 380};
381 381
382/* 382/*
383 * PCI driver table.
384 */
385
386static DEFINE_PCI_DEVICE_TABLE(pci224_pci_table) = {
387 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) },
388 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) },
389 {0}
390};
391
392MODULE_DEVICE_TABLE(pci, pci224_pci_table);
393
394/*
395 * Useful for shorthand access to the particular board structure 383 * Useful for shorthand access to the particular board structure
396 */ 384 */
397#define thisboard ((struct pci224_board *)dev->board_ptr) 385#define thisboard ((struct pci224_board *)dev->board_ptr)
@@ -422,65 +410,6 @@ struct pci224_private {
422#define devpriv ((struct pci224_private *)dev->private) 410#define devpriv ((struct pci224_private *)dev->private)
423 411
424/* 412/*
425 * The struct comedi_driver structure tells the Comedi core module
426 * which functions to call to configure/deconfigure (attach/detach)
427 * the board, and also about the kernel module that contains
428 * the device code.
429 */
430static int pci224_attach(struct comedi_device *dev,
431 struct comedi_devconfig *it);
432static int pci224_detach(struct comedi_device *dev);
433static struct comedi_driver driver_amplc_pci224 = {
434 .driver_name = DRIVER_NAME,
435 .module = THIS_MODULE,
436 .attach = pci224_attach,
437 .detach = pci224_detach,
438 .board_name = &pci224_boards[0].name,
439 .offset = sizeof(struct pci224_board),
440 .num_names = ARRAY_SIZE(pci224_boards),
441};
442
443static int __devinit driver_amplc_pci224_pci_probe(struct pci_dev *dev,
444 const struct pci_device_id
445 *ent)
446{
447 return comedi_pci_auto_config(dev, driver_amplc_pci224.driver_name);
448}
449
450static void __devexit driver_amplc_pci224_pci_remove(struct pci_dev *dev)
451{
452 comedi_pci_auto_unconfig(dev);
453}
454
455static struct pci_driver driver_amplc_pci224_pci_driver = {
456 .id_table = pci224_pci_table,
457 .probe = &driver_amplc_pci224_pci_probe,
458 .remove = __devexit_p(&driver_amplc_pci224_pci_remove)
459};
460
461static int __init driver_amplc_pci224_init_module(void)
462{
463 int retval;
464
465 retval = comedi_driver_register(&driver_amplc_pci224);
466 if (retval < 0)
467 return retval;
468
469 driver_amplc_pci224_pci_driver.name =
470 (char *)driver_amplc_pci224.driver_name;
471 return pci_register_driver(&driver_amplc_pci224_pci_driver);
472}
473
474static void __exit driver_amplc_pci224_cleanup_module(void)
475{
476 pci_unregister_driver(&driver_amplc_pci224_pci_driver);
477 comedi_driver_unregister(&driver_amplc_pci224);
478}
479
480module_init(driver_amplc_pci224_init_module);
481module_exit(driver_amplc_pci224_cleanup_module);
482
483/*
484 * Called from the 'insn_write' function to perform a single write. 413 * Called from the 'insn_write' function to perform a single write.
485 */ 414 */
486static void 415static void
@@ -1312,6 +1241,20 @@ static irqreturn_t pci224_interrupt(int irq, void *d)
1312} 1241}
1313 1242
1314/* 1243/*
1244 * This function looks for a board matching the supplied PCI device.
1245 */
1246static const struct pci224_board
1247*pci224_find_pci_board(struct pci_dev *pci_dev)
1248{
1249 int i;
1250
1251 for (i = 0; i < ARRAY_SIZE(pci224_boards); i++)
1252 if (pci_dev->device == pci224_boards[i].devid)
1253 return &pci224_boards[i];
1254 return NULL;
1255}
1256
1257/*
1315 * This function looks for a PCI device matching the requested board name, 1258 * This function looks for a PCI device matching the requested board name,
1316 * bus and slot. 1259 * bus and slot.
1317 */ 1260 */
@@ -1336,17 +1279,12 @@ pci224_find_pci(struct comedi_device *dev, int bus, int slot,
1336 } 1279 }
1337 if (thisboard->model == any_model) { 1280 if (thisboard->model == any_model) {
1338 /* Match any supported model. */ 1281 /* Match any supported model. */
1339 int i; 1282 const struct pci224_board *board_ptr;
1340 1283 board_ptr = pci224_find_pci_board(pci_dev);
1341 for (i = 0; i < ARRAY_SIZE(pci224_boards); i++) { 1284 if (board_ptr == NULL)
1342 if (pci_dev->device == pci224_boards[i].devid) {
1343 /* Change board_ptr to matched board. */
1344 dev->board_ptr = &pci224_boards[i];
1345 break;
1346 }
1347 }
1348 if (i == ARRAY_SIZE(pci224_boards))
1349 continue; 1285 continue;
1286 /* Change board_ptr to matched board. */
1287 dev->board_ptr = board_ptr;
1350 } else { 1288 } else {
1351 /* Match specific model name. */ 1289 /* Match specific model name. */
1352 if (thisboard->devid != pci_dev->device) 1290 if (thisboard->devid != pci_dev->device)
@@ -1370,35 +1308,16 @@ pci224_find_pci(struct comedi_device *dev, int bus, int slot,
1370} 1308}
1371 1309
1372/* 1310/*
1373 * Attach is called by the Comedi core to configure the driver 1311 * Common part of attach and attach_pci.
1374 * for a particular board. If you specified a board_name array
1375 * in the driver structure, dev->board_ptr contains that
1376 * address.
1377 */ 1312 */
1378static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1313static int pci224_attach_common(struct comedi_device *dev,
1314 struct pci_dev *pci_dev, int *options)
1379{ 1315{
1380 struct comedi_subdevice *s; 1316 struct comedi_subdevice *s;
1381 struct pci_dev *pci_dev;
1382 unsigned int irq; 1317 unsigned int irq;
1383 int bus = 0, slot = 0;
1384 unsigned n; 1318 unsigned n;
1385 int ret; 1319 int ret;
1386 1320
1387 printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, DRIVER_NAME);
1388
1389 bus = it->options[0];
1390 slot = it->options[1];
1391 ret = alloc_private(dev, sizeof(struct pci224_private));
1392 if (ret < 0) {
1393 printk(KERN_ERR "comedi%d: error! out of memory!\n",
1394 dev->minor);
1395 return ret;
1396 }
1397
1398 ret = pci224_find_pci(dev, bus, slot, &pci_dev);
1399 if (ret < 0)
1400 return ret;
1401
1402 devpriv->pci_dev = pci_dev; 1321 devpriv->pci_dev = pci_dev;
1403 ret = comedi_pci_enable(pci_dev, DRIVER_NAME); 1322 ret = comedi_pci_enable(pci_dev, DRIVER_NAME);
1404 if (ret < 0) { 1323 if (ret < 0) {
@@ -1483,24 +1402,26 @@ static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1483 if (!s->range_table_list) 1402 if (!s->range_table_list)
1484 return -ENOMEM; 1403 return -ENOMEM;
1485 1404
1486 for (n = 2; n < 3 + s->n_chan; n++) { 1405 if (options) {
1487 if (it->options[n] < 0 || it->options[n] > 1) { 1406 for (n = 2; n < 3 + s->n_chan; n++) {
1488 printk(KERN_WARNING "comedi%d: %s: warning! " 1407 if (options[n] < 0 || options[n] > 1) {
1489 "bad options[%u]=%d\n", 1408 printk(KERN_WARNING
1490 dev->minor, DRIVER_NAME, n, 1409 "comedi%d: %s: warning! bad options[%u]=%d\n",
1491 it->options[n]); 1410 dev->minor, DRIVER_NAME, n,
1411 options[n]);
1412 }
1492 } 1413 }
1493 } 1414 }
1494 for (n = 0; n < s->n_chan; n++) { 1415 for (n = 0; n < s->n_chan; n++) {
1495 if (n < COMEDI_NDEVCONFOPTS - 3 && 1416 if (n < COMEDI_NDEVCONFOPTS - 3 && options &&
1496 it->options[3 + n] == 1) { 1417 options[3 + n] == 1) {
1497 if (it->options[2] == 1) 1418 if (options[2] == 1)
1498 range_table_list[n] = &range_pci234_ext; 1419 range_table_list[n] = &range_pci234_ext;
1499 else 1420 else
1500 range_table_list[n] = &range_bipolar5; 1421 range_table_list[n] = &range_bipolar5;
1501 1422
1502 } else { 1423 } else {
1503 if (it->options[2] == 1) { 1424 if (options && options[2] == 1) {
1504 range_table_list[n] = 1425 range_table_list[n] =
1505 &range_pci234_ext2; 1426 &range_pci234_ext2;
1506 } else { 1427 } else {
@@ -1511,14 +1432,14 @@ static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1511 devpriv->hwrange = hwrange_pci234; 1432 devpriv->hwrange = hwrange_pci234;
1512 } else { 1433 } else {
1513 /* PCI224 range options. */ 1434 /* PCI224 range options. */
1514 if (it->options[2] == 1) { 1435 if (options && options[2] == 1) {
1515 s->range_table = &range_pci224_external; 1436 s->range_table = &range_pci224_external;
1516 devpriv->hwrange = hwrange_pci224_external; 1437 devpriv->hwrange = hwrange_pci224_external;
1517 } else { 1438 } else {
1518 if (it->options[2] != 0) { 1439 if (options && options[2] != 0) {
1519 printk(KERN_WARNING "comedi%d: %s: warning! " 1440 printk(KERN_WARNING "comedi%d: %s: warning! "
1520 "bad options[2]=%d\n", 1441 "bad options[2]=%d\n",
1521 dev->minor, DRIVER_NAME, it->options[2]); 1442 dev->minor, DRIVER_NAME, options[2]);
1522 } 1443 }
1523 s->range_table = &range_pci224_internal; 1444 s->range_table = &range_pci224_internal;
1524 devpriv->hwrange = hwrange_pci224_internal; 1445 devpriv->hwrange = hwrange_pci224_internal;
@@ -1552,21 +1473,59 @@ static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1552 return 1; 1473 return 1;
1553} 1474}
1554 1475
1555/* 1476static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1556 * _detach is called to deconfigure a device. It should deallocate 1477{
1557 * resources. 1478 struct pci_dev *pci_dev;
1558 * This function is also called when _attach() fails, so it should be 1479 int bus, slot;
1559 * careful not to release resources that were not necessarily 1480 int ret;
1560 * allocated by _attach(). dev->private and dev->subdevices are 1481
1561 * deallocated automatically by the core. 1482 printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, DRIVER_NAME);
1562 */ 1483
1563static int pci224_detach(struct comedi_device *dev) 1484 bus = it->options[0];
1485 slot = it->options[1];
1486 ret = alloc_private(dev, sizeof(struct pci224_private));
1487 if (ret < 0) {
1488 printk(KERN_ERR "comedi%d: error! out of memory!\n",
1489 dev->minor);
1490 return ret;
1491 }
1492
1493 ret = pci224_find_pci(dev, bus, slot, &pci_dev);
1494 if (ret < 0)
1495 return ret;
1496
1497 return pci224_attach_common(dev, pci_dev, it->options);
1498}
1499
1500static int
1501pci224_attach_pci(struct comedi_device *dev, struct pci_dev *pci_dev)
1564{ 1502{
1565 printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor, DRIVER_NAME); 1503 int ret;
1504
1505 printk(KERN_DEBUG "comedi%d: %s: attach_pci %s\n", dev->minor,
1506 DRIVER_NAME, pci_name(pci_dev));
1507
1508 ret = alloc_private(dev, sizeof(struct pci224_private));
1509 if (ret < 0) {
1510 printk(KERN_ERR "comedi%d: error! out of memory!\n",
1511 dev->minor);
1512 return ret;
1513 }
1566 1514
1515 dev->board_ptr = pci224_find_pci_board(pci_dev);
1516 if (dev->board_ptr == NULL) {
1517 printk(KERN_ERR
1518 "comedi%d: %s: BUG! cannot determine board type!\n",
1519 dev->minor, DRIVER_NAME);
1520 return -EINVAL;
1521 }
1522 return pci224_attach_common(dev, pci_dev, NULL);
1523}
1524
1525static void pci224_detach(struct comedi_device *dev)
1526{
1567 if (dev->irq) 1527 if (dev->irq)
1568 free_irq(dev->irq, dev); 1528 free_irq(dev->irq, dev);
1569
1570 if (dev->subdevices) { 1529 if (dev->subdevices) {
1571 struct comedi_subdevice *s; 1530 struct comedi_subdevice *s;
1572 1531
@@ -1581,18 +1540,49 @@ static int pci224_detach(struct comedi_device *dev)
1581 if (devpriv->pci_dev) { 1540 if (devpriv->pci_dev) {
1582 if (dev->iobase) 1541 if (dev->iobase)
1583 comedi_pci_disable(devpriv->pci_dev); 1542 comedi_pci_disable(devpriv->pci_dev);
1584
1585 pci_dev_put(devpriv->pci_dev); 1543 pci_dev_put(devpriv->pci_dev);
1586 } 1544 }
1587 } 1545 }
1588 if (dev->board_name) { 1546}
1589 printk(KERN_INFO "comedi%d: %s removed\n",
1590 dev->minor, dev->board_name);
1591 }
1592 1547
1593 return 0; 1548static struct comedi_driver amplc_pci224_driver = {
1549 .driver_name = "amplc_pci224",
1550 .module = THIS_MODULE,
1551 .attach = pci224_attach,
1552 .detach = pci224_detach,
1553 .attach_pci = pci224_attach_pci,
1554 .board_name = &pci224_boards[0].name,
1555 .offset = sizeof(struct pci224_board),
1556 .num_names = ARRAY_SIZE(pci224_boards),
1557};
1558
1559static int __devinit amplc_pci224_pci_probe(struct pci_dev *dev,
1560 const struct pci_device_id
1561 *ent)
1562{
1563 return comedi_pci_auto_config(dev, &amplc_pci224_driver);
1594} 1564}
1595 1565
1566static void __devexit amplc_pci224_pci_remove(struct pci_dev *dev)
1567{
1568 comedi_pci_auto_unconfig(dev);
1569}
1570
1571static DEFINE_PCI_DEVICE_TABLE(amplc_pci224_pci_table) = {
1572 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) },
1573 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) },
1574 { 0 }
1575};
1576MODULE_DEVICE_TABLE(pci, amplc_pci224_pci_table);
1577
1578static struct pci_driver amplc_pci224_pci_driver = {
1579 .name = "amplc_pci224",
1580 .id_table = amplc_pci224_pci_table,
1581 .probe = amplc_pci224_pci_probe,
1582 .remove = __devexit_p(amplc_pci224_pci_remove),
1583};
1584module_comedi_pci_driver(amplc_pci224_driver, amplc_pci224_pci_driver);
1585
1596MODULE_AUTHOR("Comedi http://www.comedi.org"); 1586MODULE_AUTHOR("Comedi http://www.comedi.org");
1597MODULE_DESCRIPTION("Comedi low-level driver"); 1587MODULE_DESCRIPTION("Comedi low-level driver");
1598MODULE_LICENSE("GPL"); 1588MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 538979551c8e..d4c80b1281f2 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -500,13 +500,6 @@ static const struct pci230_board pci230_boards[] = {
500 }, 500 },
501}; 501};
502 502
503static DEFINE_PCI_DEVICE_TABLE(pci230_pci_table) = {
504 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230) },
505 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260) },
506 {0}
507};
508
509MODULE_DEVICE_TABLE(pci, pci230_pci_table);
510/* 503/*
511 * Useful for shorthand access to the particular board structure 504 * Useful for shorthand access to the particular board structure
512 */ 505 */
@@ -595,65 +588,6 @@ static const struct comedi_lrange pci230_ao_range = { 2, {
595/* PCI230 daccon bipolar flag for each analogue output range. */ 588/* PCI230 daccon bipolar flag for each analogue output range. */
596static const unsigned char pci230_ao_bipolar[2] = { 0, 1 }; 589static const unsigned char pci230_ao_bipolar[2] = { 0, 1 };
597 590
598/*
599 * The struct comedi_driver structure tells the Comedi core module
600 * which functions to call to configure/deconfigure (attach/detach)
601 * the board, and also about the kernel module that contains
602 * the device code.
603 */
604static int pci230_attach(struct comedi_device *dev,
605 struct comedi_devconfig *it);
606static int pci230_detach(struct comedi_device *dev);
607static struct comedi_driver driver_amplc_pci230 = {
608 .driver_name = "amplc_pci230",
609 .module = THIS_MODULE,
610 .attach = pci230_attach,
611 .detach = pci230_detach,
612 .board_name = &pci230_boards[0].name,
613 .offset = sizeof(pci230_boards[0]),
614 .num_names = ARRAY_SIZE(pci230_boards),
615};
616
617static int __devinit driver_amplc_pci230_pci_probe(struct pci_dev *dev,
618 const struct pci_device_id
619 *ent)
620{
621 return comedi_pci_auto_config(dev, driver_amplc_pci230.driver_name);
622}
623
624static void __devexit driver_amplc_pci230_pci_remove(struct pci_dev *dev)
625{
626 comedi_pci_auto_unconfig(dev);
627}
628
629static struct pci_driver driver_amplc_pci230_pci_driver = {
630 .id_table = pci230_pci_table,
631 .probe = &driver_amplc_pci230_pci_probe,
632 .remove = __devexit_p(&driver_amplc_pci230_pci_remove)
633};
634
635static int __init driver_amplc_pci230_init_module(void)
636{
637 int retval;
638
639 retval = comedi_driver_register(&driver_amplc_pci230);
640 if (retval < 0)
641 return retval;
642
643 driver_amplc_pci230_pci_driver.name =
644 (char *)driver_amplc_pci230.driver_name;
645 return pci_register_driver(&driver_amplc_pci230_pci_driver);
646}
647
648static void __exit driver_amplc_pci230_cleanup_module(void)
649{
650 pci_unregister_driver(&driver_amplc_pci230_pci_driver);
651 comedi_driver_unregister(&driver_amplc_pci230);
652}
653
654module_init(driver_amplc_pci230_init_module);
655module_exit(driver_amplc_pci230_cleanup_module);
656
657static int pci230_ai_rinsn(struct comedi_device *dev, 591static int pci230_ai_rinsn(struct comedi_device *dev,
658 struct comedi_subdevice *s, struct comedi_insn *insn, 592 struct comedi_subdevice *s, struct comedi_insn *insn,
659 unsigned int *data); 593 unsigned int *data);
@@ -1003,35 +937,19 @@ static int pci230_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1003 return 1; 937 return 1;
1004} 938}
1005 939
1006/* 940static void pci230_detach(struct comedi_device *dev)
1007 * _detach is called to deconfigure a device. It should deallocate
1008 * resources.
1009 * This function is also called when _attach() fails, so it should be
1010 * careful not to release resources that were not necessarily
1011 * allocated by _attach(). dev->private and dev->subdevices are
1012 * deallocated automatically by the core.
1013 */
1014static int pci230_detach(struct comedi_device *dev)
1015{ 941{
1016 printk("comedi%d: amplc_pci230: remove\n", dev->minor);
1017
1018 if (dev->subdevices && thisboard->have_dio) 942 if (dev->subdevices && thisboard->have_dio)
1019 /* Clean up dio subdevice. */
1020 subdev_8255_cleanup(dev, dev->subdevices + 2); 943 subdev_8255_cleanup(dev, dev->subdevices + 2);
1021
1022 if (dev->irq) 944 if (dev->irq)
1023 free_irq(dev->irq, dev); 945 free_irq(dev->irq, dev);
1024
1025 if (devpriv) { 946 if (devpriv) {
1026 if (devpriv->pci_dev) { 947 if (devpriv->pci_dev) {
1027 if (dev->iobase) 948 if (dev->iobase)
1028 comedi_pci_disable(devpriv->pci_dev); 949 comedi_pci_disable(devpriv->pci_dev);
1029
1030 pci_dev_put(devpriv->pci_dev); 950 pci_dev_put(devpriv->pci_dev);
1031 } 951 }
1032 } 952 }
1033
1034 return 0;
1035} 953}
1036 954
1037static int get_resources(struct comedi_device *dev, unsigned int res_mask, 955static int get_resources(struct comedi_device *dev, unsigned int res_mask,
@@ -3048,6 +2966,42 @@ static int pci230_ai_cancel(struct comedi_device *dev,
3048 return 0; 2966 return 0;
3049} 2967}
3050 2968
2969static struct comedi_driver amplc_pci230_driver = {
2970 .driver_name = "amplc_pci230",
2971 .module = THIS_MODULE,
2972 .attach = pci230_attach,
2973 .detach = pci230_detach,
2974 .board_name = &pci230_boards[0].name,
2975 .offset = sizeof(pci230_boards[0]),
2976 .num_names = ARRAY_SIZE(pci230_boards),
2977};
2978
2979static int __devinit amplc_pci230_pci_probe(struct pci_dev *dev,
2980 const struct pci_device_id *ent)
2981{
2982 return comedi_pci_auto_config(dev, &amplc_pci230_driver);
2983}
2984
2985static void __devexit amplc_pci230_pci_remove(struct pci_dev *dev)
2986{
2987 comedi_pci_auto_unconfig(dev);
2988}
2989
2990static DEFINE_PCI_DEVICE_TABLE(amplc_pci230_pci_table) = {
2991 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230) },
2992 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260) },
2993 { 0 }
2994};
2995MODULE_DEVICE_TABLE(pci, amplc_pci230_pci_table);
2996
2997static struct pci_driver amplc_pci230_pci_driver = {
2998 .name = "amplc_pci230",
2999 .id_table = amplc_pci230_pci_table,
3000 .probe = amplc_pci230_pci_probe,
3001 .remove = __devexit_p(amplc_pci230_pci_remove)
3002};
3003module_comedi_pci_driver(amplc_pci230_driver, amplc_pci230_pci_driver);
3004
3051MODULE_AUTHOR("Comedi http://www.comedi.org"); 3005MODULE_AUTHOR("Comedi http://www.comedi.org");
3052MODULE_DESCRIPTION("Comedi low-level driver"); 3006MODULE_DESCRIPTION("Comedi low-level driver");
3053MODULE_LICENSE("GPL"); 3007MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c
index 11cdaf2a5aa5..fb9951a746a6 100644
--- a/drivers/staging/comedi/drivers/c6xdigio.c
+++ b/drivers/staging/comedi/drivers/c6xdigio.c
@@ -97,16 +97,6 @@ union encvaluetype {
97 97
98#define C6XDIGIO_TIME_OUT 20 98#define C6XDIGIO_TIME_OUT 20
99 99
100static int c6xdigio_attach(struct comedi_device *dev,
101 struct comedi_devconfig *it);
102static int c6xdigio_detach(struct comedi_device *dev);
103struct comedi_driver driver_c6xdigio = {
104 .driver_name = "c6xdigio",
105 .module = THIS_MODULE,
106 .attach = c6xdigio_attach,
107 .detach = c6xdigio_detach,
108};
109
110static void C6X_pwmInit(unsigned long baseAddr) 100static void C6X_pwmInit(unsigned long baseAddr)
111{ 101{
112 int timeout = 0; 102 int timeout = 0;
@@ -407,10 +397,6 @@ static void board_init(struct comedi_device *dev)
407 397
408} 398}
409 399
410/* static void board_halt(struct comedi_device *dev) { */
411/* C6X_pwmInit(dev->iobase); */
412/* } */
413
414/* 400/*
415 options[0] - I/O port 401 options[0] - I/O port
416 options[1] - irq 402 options[1] - irq
@@ -500,36 +486,22 @@ static int c6xdigio_attach(struct comedi_device *dev,
500 return 0; 486 return 0;
501} 487}
502 488
503static int c6xdigio_detach(struct comedi_device *dev) 489static void c6xdigio_detach(struct comedi_device *dev)
504{ 490{
505 /* board_halt(dev); may not need this */
506
507 printk(KERN_DEBUG "comedi%d: c6xdigio: remove\n", dev->minor);
508
509 if (dev->iobase) 491 if (dev->iobase)
510 release_region(dev->iobase, C6XDIGIO_SIZE); 492 release_region(dev->iobase, C6XDIGIO_SIZE);
511
512 /* Not using IRQ so I am not sure if I need this */
513 if (dev->irq) 493 if (dev->irq)
514 free_irq(dev->irq, dev); 494 free_irq(dev->irq, dev);
515
516 pnp_unregister_driver(&c6xdigio_pnp_driver); 495 pnp_unregister_driver(&c6xdigio_pnp_driver);
517
518 return 0;
519}
520
521static int __init driver_c6xdigio_init_module(void)
522{
523 return comedi_driver_register(&driver_c6xdigio);
524} 496}
525 497
526static void __exit driver_c6xdigio_cleanup_module(void) 498static struct comedi_driver c6xdigio_driver = {
527{ 499 .driver_name = "c6xdigio",
528 comedi_driver_unregister(&driver_c6xdigio); 500 .module = THIS_MODULE,
529} 501 .attach = c6xdigio_attach,
530 502 .detach = c6xdigio_detach,
531module_init(driver_c6xdigio_init_module); 503};
532module_exit(driver_c6xdigio_cleanup_module); 504module_comedi_driver(c6xdigio_driver);
533 505
534MODULE_AUTHOR("Comedi http://www.comedi.org"); 506MODULE_AUTHOR("Comedi http://www.comedi.org");
535MODULE_DESCRIPTION("Comedi low-level driver"); 507MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index 49404f49f7b7..35159235a1b6 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -91,7 +91,7 @@ struct das16cs_private {
91 91
92static int das16cs_attach(struct comedi_device *dev, 92static int das16cs_attach(struct comedi_device *dev,
93 struct comedi_devconfig *it); 93 struct comedi_devconfig *it);
94static int das16cs_detach(struct comedi_device *dev); 94static void das16cs_detach(struct comedi_device *dev);
95static struct comedi_driver driver_das16cs = { 95static struct comedi_driver driver_das16cs = {
96 .driver_name = "cb_das16_cs", 96 .driver_name = "cb_das16_cs",
97 .module = THIS_MODULE, 97 .module = THIS_MODULE,
@@ -255,15 +255,10 @@ static int das16cs_attach(struct comedi_device *dev,
255 return 1; 255 return 1;
256} 256}
257 257
258static int das16cs_detach(struct comedi_device *dev) 258static void das16cs_detach(struct comedi_device *dev)
259{ 259{
260 dev_dbg(dev->hw_dev, "comedi%d: das16cs: remove\n", dev->minor);
261
262 if (dev->irq) 260 if (dev->irq)
263 free_irq(dev->irq, dev); 261 free_irq(dev->irq, dev);
264
265
266 return 0;
267} 262}
268 263
269static irqreturn_t das16cs_interrupt(int irq, void *d) 264static irqreturn_t das16cs_interrupt(int irq, void *d)
diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c
index 7e4ffcfdac62..ee9e084bb96c 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -405,20 +405,6 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
405 }, 405 },
406}; 406};
407 407
408static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
409 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) },
410 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) },
411 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0010) },
412 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0019) },
413 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001c) },
414 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x004c) },
415 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001a) },
416 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001b) },
417 { 0 }
418};
419
420MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table);
421
422/* 408/*
423 * Useful for shorthand access to the particular board structure 409 * Useful for shorthand access to the particular board structure
424 */ 410 */
@@ -462,22 +448,6 @@ struct cb_pcidas_private {
462 */ 448 */
463#define devpriv ((struct cb_pcidas_private *)dev->private) 449#define devpriv ((struct cb_pcidas_private *)dev->private)
464 450
465/*
466 * The struct comedi_driver structure tells the Comedi core module
467 * which functions to call to configure/deconfigure (attach/detach)
468 * the board, and also about the kernel module that contains
469 * the device code.
470 */
471static int cb_pcidas_attach(struct comedi_device *dev,
472 struct comedi_devconfig *it);
473static int cb_pcidas_detach(struct comedi_device *dev);
474static struct comedi_driver driver_cb_pcidas = {
475 .driver_name = "cb_pcidas",
476 .module = THIS_MODULE,
477 .attach = cb_pcidas_attach,
478 .detach = cb_pcidas_detach,
479};
480
481static int cb_pcidas_ai_rinsn(struct comedi_device *dev, 451static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
482 struct comedi_subdevice *s, 452 struct comedi_subdevice *s,
483 struct comedi_insn *insn, unsigned int *data); 453 struct comedi_insn *insn, unsigned int *data);
@@ -756,26 +726,12 @@ found:
756 return 1; 726 return 1;
757} 727}
758 728
759/* 729static void cb_pcidas_detach(struct comedi_device *dev)
760 * cb_pcidas_detach is called to deconfigure a device. It should deallocate
761 * resources.
762 * This function is also called when _attach() fails, so it should be
763 * careful not to release resources that were not necessarily
764 * allocated by _attach(). dev->private and dev->subdevices are
765 * deallocated automatically by the core.
766 */
767static int cb_pcidas_detach(struct comedi_device *dev)
768{ 730{
769
770 if (devpriv) { 731 if (devpriv) {
771 if (devpriv->s5933_config) { 732 if (devpriv->s5933_config) {
772 /* disable and clear interrupts on amcc s5933 */
773 outl(INTCSR_INBOX_INTR_STATUS, 733 outl(INTCSR_INBOX_INTR_STATUS,
774 devpriv->s5933_config + AMCC_OP_REG_INTCSR); 734 devpriv->s5933_config + AMCC_OP_REG_INTCSR);
775#ifdef CB_PCIDAS_DEBUG
776 dev_dbg(dev->hw_dev, "detaching, incsr is 0x%x\n",
777 inl(devpriv->s5933_config + AMCC_OP_REG_INTCSR));
778#endif
779 } 735 }
780 } 736 }
781 if (dev->irq) 737 if (dev->irq)
@@ -787,8 +743,6 @@ static int cb_pcidas_detach(struct comedi_device *dev)
787 comedi_pci_disable(devpriv->pci_dev); 743 comedi_pci_disable(devpriv->pci_dev);
788 pci_dev_put(devpriv->pci_dev); 744 pci_dev_put(devpriv->pci_dev);
789 } 745 }
790
791 return 0;
792} 746}
793 747
794/* 748/*
@@ -1918,47 +1872,44 @@ static int nvram_read(struct comedi_device *dev, unsigned int address,
1918 return 0; 1872 return 0;
1919} 1873}
1920 1874
1921/* 1875static struct comedi_driver cb_pcidas_driver = {
1922 * A convenient macro that defines init_module() and cleanup_module(), 1876 .driver_name = "cb_pcidas",
1923 * as necessary. 1877 .module = THIS_MODULE,
1924 */ 1878 .attach = cb_pcidas_attach,
1925static int __devinit driver_cb_pcidas_pci_probe(struct pci_dev *dev, 1879 .detach = cb_pcidas_detach,
1926 const struct pci_device_id *ent) 1880};
1881
1882static int __devinit cb_pcidas_pci_probe(struct pci_dev *dev,
1883 const struct pci_device_id *ent)
1927{ 1884{
1928 return comedi_pci_auto_config(dev, driver_cb_pcidas.driver_name); 1885 return comedi_pci_auto_config(dev, &cb_pcidas_driver);
1929} 1886}
1930 1887
1931static void __devexit driver_cb_pcidas_pci_remove(struct pci_dev *dev) 1888static void __devexit cb_pcidas_pci_remove(struct pci_dev *dev)
1932{ 1889{
1933 comedi_pci_auto_unconfig(dev); 1890 comedi_pci_auto_unconfig(dev);
1934} 1891}
1935 1892
1936static struct pci_driver driver_cb_pcidas_pci_driver = { 1893static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
1937 .id_table = cb_pcidas_pci_table, 1894 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) },
1938 .probe = &driver_cb_pcidas_pci_probe, 1895 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) },
1939 .remove = __devexit_p(&driver_cb_pcidas_pci_remove) 1896 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0010) },
1897 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0019) },
1898 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001c) },
1899 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x004c) },
1900 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001a) },
1901 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001b) },
1902 { 0 }
1940}; 1903};
1904MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table);
1941 1905
1942static int __init driver_cb_pcidas_init_module(void) 1906static struct pci_driver cb_pcidas_pci_driver = {
1943{ 1907 .name = "cb_pcidas",
1944 int retval; 1908 .id_table = cb_pcidas_pci_table,
1945 1909 .probe = cb_pcidas_pci_probe,
1946 retval = comedi_driver_register(&driver_cb_pcidas); 1910 .remove = __devexit_p(cb_pcidas_pci_remove)
1947 if (retval < 0) 1911};
1948 return retval; 1912module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver);
1949
1950 driver_cb_pcidas_pci_driver.name = (char *)driver_cb_pcidas.driver_name;
1951 return pci_register_driver(&driver_cb_pcidas_pci_driver);
1952}
1953
1954static void __exit driver_cb_pcidas_cleanup_module(void)
1955{
1956 pci_unregister_driver(&driver_cb_pcidas_pci_driver);
1957 comedi_driver_unregister(&driver_cb_pcidas);
1958}
1959
1960module_init(driver_cb_pcidas_init_module);
1961module_exit(driver_cb_pcidas_cleanup_module);
1962 1913
1963MODULE_AUTHOR("Comedi http://www.comedi.org"); 1914MODULE_AUTHOR("Comedi http://www.comedi.org");
1964MODULE_DESCRIPTION("Comedi low-level driver"); 1915MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 915157d47805..9d0b8754ff5b 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1026,31 +1026,6 @@ static const struct pcidas64_board pcidas64_boards[] = {
1026#endif 1026#endif
1027}; 1027};
1028 1028
1029static DEFINE_PCI_DEVICE_TABLE(pcidas64_pci_table) = {
1030 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x001d) },
1031 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x001e) },
1032 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0035) },
1033 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0036) },
1034 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0037) },
1035 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0052) },
1036 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005d) },
1037 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005e) },
1038 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005f) },
1039 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0061) },
1040 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0062) },
1041 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0063) },
1042 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0064) },
1043 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0066) },
1044 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0067) },
1045 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0068) },
1046 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x006f) },
1047 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0078) },
1048 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0079) },
1049 { 0 }
1050};
1051
1052MODULE_DEVICE_TABLE(pci, pcidas64_pci_table);
1053
1054static inline struct pcidas64_board *board(const struct comedi_device *dev) 1029static inline struct pcidas64_board *board(const struct comedi_device *dev)
1055{ 1030{
1056 return (struct pcidas64_board *)dev->board_ptr; 1031 return (struct pcidas64_board *)dev->board_ptr;
@@ -1127,21 +1102,6 @@ static inline struct pcidas64_private *priv(struct comedi_device *dev)
1127 return dev->private; 1102 return dev->private;
1128} 1103}
1129 1104
1130/*
1131 * The comedi_driver structure tells the Comedi core module
1132 * which functions to call to configure/deconfigure (attach/detach)
1133 * the board, and also about the kernel module that contains
1134 * the device code.
1135 */
1136static int attach(struct comedi_device *dev, struct comedi_devconfig *it);
1137static int detach(struct comedi_device *dev);
1138static struct comedi_driver driver_cb_pcidas = {
1139 .driver_name = "cb_pcidas64",
1140 .module = THIS_MODULE,
1141 .attach = attach,
1142 .detach = detach,
1143};
1144
1145static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, 1105static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
1146 struct comedi_insn *insn, unsigned int *data); 1106 struct comedi_insn *insn, unsigned int *data);
1147static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s, 1107static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -1216,44 +1176,6 @@ static unsigned int get_ao_divisor(unsigned int ns, unsigned int flags);
1216static void load_ao_dma(struct comedi_device *dev, 1176static void load_ao_dma(struct comedi_device *dev,
1217 const struct comedi_cmd *cmd); 1177 const struct comedi_cmd *cmd);
1218 1178
1219static int __devinit driver_cb_pcidas_pci_probe(struct pci_dev *dev,
1220 const struct pci_device_id *ent)
1221{
1222 return comedi_pci_auto_config(dev, driver_cb_pcidas.driver_name);
1223}
1224
1225static void __devexit driver_cb_pcidas_pci_remove(struct pci_dev *dev)
1226{
1227 comedi_pci_auto_unconfig(dev);
1228}
1229
1230static struct pci_driver driver_cb_pcidas_pci_driver = {
1231 .id_table = pcidas64_pci_table,
1232 .probe = &driver_cb_pcidas_pci_probe,
1233 .remove = __devexit_p(&driver_cb_pcidas_pci_remove)
1234};
1235
1236static int __init driver_cb_pcidas_init_module(void)
1237{
1238 int retval;
1239
1240 retval = comedi_driver_register(&driver_cb_pcidas);
1241 if (retval < 0)
1242 return retval;
1243
1244 driver_cb_pcidas_pci_driver.name = (char *)driver_cb_pcidas.driver_name;
1245 return pci_register_driver(&driver_cb_pcidas_pci_driver);
1246}
1247
1248static void __exit driver_cb_pcidas_cleanup_module(void)
1249{
1250 pci_unregister_driver(&driver_cb_pcidas_pci_driver);
1251 comedi_driver_unregister(&driver_cb_pcidas);
1252}
1253
1254module_init(driver_cb_pcidas_init_module);
1255module_exit(driver_cb_pcidas_cleanup_module);
1256
1257static unsigned int ai_range_bits_6xxx(const struct comedi_device *dev, 1179static unsigned int ai_range_bits_6xxx(const struct comedi_device *dev,
1258 unsigned int range_index) 1180 unsigned int range_index)
1259{ 1181{
@@ -1781,7 +1703,7 @@ static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
1781 dev_dbg(dev->hw_dev, "Found %s on bus %i, slot %i\n", board(dev)->name, 1703 dev_dbg(dev->hw_dev, "Found %s on bus %i, slot %i\n", board(dev)->name,
1782 pcidev->bus->number, PCI_SLOT(pcidev->devfn)); 1704 pcidev->bus->number, PCI_SLOT(pcidev->devfn));
1783 1705
1784 if (comedi_pci_enable(pcidev, driver_cb_pcidas.driver_name)) { 1706 if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
1785 dev_warn(dev->hw_dev, "failed to enable PCI device and request regions\n"); 1707 dev_warn(dev->hw_dev, "failed to enable PCI device and request regions\n");
1786 return -EIO; 1708 return -EIO;
1787 } 1709 }
@@ -1868,15 +1790,7 @@ static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
1868 return 0; 1790 return 0;
1869} 1791}
1870 1792
1871/* 1793static void detach(struct comedi_device *dev)
1872 * _detach is called to deconfigure a device. It should deallocate
1873 * resources.
1874 * This function is also called when _attach() fails, so it should be
1875 * careful not to release resources that were not necessarily
1876 * allocated by _attach(). dev->private and dev->subdevices are
1877 * deallocated automatically by the core.
1878 */
1879static int detach(struct comedi_device *dev)
1880{ 1794{
1881 unsigned int i; 1795 unsigned int i;
1882 1796
@@ -1938,8 +1852,6 @@ static int detach(struct comedi_device *dev)
1938 } 1852 }
1939 if (dev->subdevices) 1853 if (dev->subdevices)
1940 subdev_8255_cleanup(dev, dev->subdevices + 4); 1854 subdev_8255_cleanup(dev, dev->subdevices + 4);
1941
1942 return 0;
1943} 1855}
1944 1856
1945static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, 1857static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -4315,6 +4227,56 @@ static void i2c_write(struct comedi_device *dev, unsigned int address,
4315 i2c_stop(dev); 4227 i2c_stop(dev);
4316} 4228}
4317 4229
4230static struct comedi_driver cb_pcidas64_driver = {
4231 .driver_name = "cb_pcidas64",
4232 .module = THIS_MODULE,
4233 .attach = attach,
4234 .detach = detach,
4235};
4236
4237static int __devinit cb_pcidas64_pci_probe(struct pci_dev *dev,
4238 const struct pci_device_id *ent)
4239{
4240 return comedi_pci_auto_config(dev, &cb_pcidas64_driver);
4241}
4242
4243static void __devexit cb_pcidas64_pci_remove(struct pci_dev *dev)
4244{
4245 comedi_pci_auto_unconfig(dev);
4246}
4247
4248static DEFINE_PCI_DEVICE_TABLE(cb_pcidas64_pci_table) = {
4249 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x001d) },
4250 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x001e) },
4251 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0035) },
4252 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0036) },
4253 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0037) },
4254 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0052) },
4255 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005d) },
4256 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005e) },
4257 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x005f) },
4258 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0061) },
4259 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0062) },
4260 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0063) },
4261 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0064) },
4262 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0066) },
4263 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0067) },
4264 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0068) },
4265 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x006f) },
4266 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0078) },
4267 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0079) },
4268 { 0 }
4269};
4270MODULE_DEVICE_TABLE(pci, cb_pcidas64_pci_table);
4271
4272static struct pci_driver cb_pcidas64_pci_driver = {
4273 .name = "cb_pcidas64",
4274 .id_table = cb_pcidas64_pci_table,
4275 .probe = cb_pcidas64_pci_probe,
4276 .remove = __devexit_p(cb_pcidas64_pci_remove),
4277};
4278module_comedi_pci_driver(cb_pcidas64_driver, cb_pcidas64_pci_driver);
4279
4318MODULE_AUTHOR("Comedi http://www.comedi.org"); 4280MODULE_AUTHOR("Comedi http://www.comedi.org");
4319MODULE_DESCRIPTION("Comedi low-level driver"); 4281MODULE_DESCRIPTION("Comedi low-level driver");
4320MODULE_LICENSE("GPL"); 4282MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c
index abba220a767f..25ebca11eadc 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -51,9 +51,12 @@ Please report success/failure with other different cards to
51#include "comedi_pci.h" 51#include "comedi_pci.h"
52#include "8255.h" 52#include "8255.h"
53 53
54#define PCI_VENDOR_ID_CB 0x1307 /* PCI vendor number of ComputerBoards */ 54
55/* PCI vendor number of ComputerBoards */
56#define PCI_VENDOR_ID_CB 0x1307
55#define EEPROM_SIZE 128 /* number of entries in eeprom */ 57#define EEPROM_SIZE 128 /* number of entries in eeprom */
56#define MAX_AO_CHANNELS 8 /* maximum number of ao channels for supported boards */ 58/* maximum number of ao channels for supported boards */
59#define MAX_AO_CHANNELS 8
57 60
58/* PCI-DDA base addresses */ 61/* PCI-DDA base addresses */
59#define DIGITALIO_BADRINDEX 2 62#define DIGITALIO_BADRINDEX 2
@@ -94,20 +97,26 @@ Please report success/failure with other different cards to
94 97
95#define DACALIBRATION1 4 /* D/A CALIBRATION REGISTER 1 */ 98#define DACALIBRATION1 4 /* D/A CALIBRATION REGISTER 1 */
96/* write bits */ 99/* write bits */
97#define SERIAL_IN_BIT 0x1 /* serial data input for eeprom, caldacs, reference dac */ 100/* serial data input for eeprom, caldacs, reference dac */
101#define SERIAL_IN_BIT 0x1
98#define CAL_CHANNEL_MASK (0x7 << 1) 102#define CAL_CHANNEL_MASK (0x7 << 1)
99#define CAL_CHANNEL_BITS(channel) (((channel) << 1) & CAL_CHANNEL_MASK) 103#define CAL_CHANNEL_BITS(channel) (((channel) << 1) & CAL_CHANNEL_MASK)
100/* read bits */ 104/* read bits */
101#define CAL_COUNTER_MASK 0x1f 105#define CAL_COUNTER_MASK 0x1f
102#define CAL_COUNTER_OVERFLOW_BIT 0x20 /* calibration counter overflow status bit */ 106/* calibration counter overflow status bit */
103#define AO_BELOW_REF_BIT 0x40 /* analog output is less than reference dac voltage */ 107#define CAL_COUNTER_OVERFLOW_BIT 0x20
108/* analog output is less than reference dac voltage */
109#define AO_BELOW_REF_BIT 0x40
104#define SERIAL_OUT_BIT 0x80 /* serial data out, for reading from eeprom */ 110#define SERIAL_OUT_BIT 0x80 /* serial data out, for reading from eeprom */
105 111
106#define DACALIBRATION2 6 /* D/A CALIBRATION REGISTER 2 */ 112#define DACALIBRATION2 6 /* D/A CALIBRATION REGISTER 2 */
107#define SELECT_EEPROM_BIT 0x1 /* send serial data in to eeprom */ 113#define SELECT_EEPROM_BIT 0x1 /* send serial data in to eeprom */
108#define DESELECT_REF_DAC_BIT 0x2 /* don't send serial data to MAX542 reference dac */ 114/* don't send serial data to MAX542 reference dac */
109#define DESELECT_CALDAC_BIT(n) (0x4 << (n)) /* don't send serial data to caldac n */ 115#define DESELECT_REF_DAC_BIT 0x2
110#define DUMMY_BIT 0x40 /* manual says to set this bit with no explanation */ 116/* don't send serial data to caldac n */
117#define DESELECT_CALDAC_BIT(n) (0x4 << (n))
118/* manual says to set this bit with no explanation */
119#define DUMMY_BIT 0x40
111 120
112#define DADATA 8 /* FIRST D/A DATA REGISTER (0) */ 121#define DADATA 8 /* FIRST D/A DATA REGISTER (0) */
113 122
@@ -195,26 +204,17 @@ static const struct cb_pcidda_board cb_pcidda_boards[] = {
195 }, 204 },
196}; 205};
197 206
198static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = {
199 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0020) },
200 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0021) },
201 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0022) },
202 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0023) },
203 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0024) },
204 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0025) },
205 { 0 }
206};
207
208MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table);
209
210/* 207/*
211 * Useful for shorthand access to the particular board structure 208 * Useful for shorthand access to the particular board structure
212 */ 209 */
213#define thisboard ((const struct cb_pcidda_board *)dev->board_ptr) 210#define thisboard ((const struct cb_pcidda_board *)dev->board_ptr)
214 211
215/* this structure is for data unique to this hardware driver. If 212/*
216 several hardware drivers keep similar information in this structure, 213 * this structure is for data unique to this hardware driver. If
217 feel free to suggest moving the variable to the struct comedi_device struct. */ 214 * several hardware drivers keep similar information in this structure,
215 * feel free to suggest moving the variable to the struct comedi_device
216 * struct.
217 */
218struct cb_pcidda_private { 218struct cb_pcidda_private {
219 int data; 219 int data;
220 220
@@ -227,8 +227,10 @@ struct cb_pcidda_private {
227 /* unsigned long control_status; */ 227 /* unsigned long control_status; */
228 /* unsigned long adc_fifo; */ 228 /* unsigned long adc_fifo; */
229 229
230 unsigned int dac_cal1_bits; /* bits last written to da calibration register 1 */ 230 /* bits last written to da calibration register 1 */
231 unsigned int ao_range[MAX_AO_CHANNELS]; /* current range settings for output channels */ 231 unsigned int dac_cal1_bits;
232 /* current range settings for output channels */
233 unsigned int ao_range[MAX_AO_CHANNELS];
232 u16 eeprom_data[EEPROM_SIZE]; /* software copy of board's eeprom */ 234 u16 eeprom_data[EEPROM_SIZE]; /* software copy of board's eeprom */
233}; 235};
234 236
@@ -238,9 +240,6 @@ struct cb_pcidda_private {
238 */ 240 */
239#define devpriv ((struct cb_pcidda_private *)dev->private) 241#define devpriv ((struct cb_pcidda_private *)dev->private)
240 242
241static int cb_pcidda_attach(struct comedi_device *dev,
242 struct comedi_devconfig *it);
243static int cb_pcidda_detach(struct comedi_device *dev);
244/* static int cb_pcidda_ai_rinsn(struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data); */ 243/* static int cb_pcidda_ai_rinsn(struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data); */
245static int cb_pcidda_ao_winsn(struct comedi_device *dev, 244static int cb_pcidda_ao_winsn(struct comedi_device *dev,
246 struct comedi_subdevice *s, 245 struct comedi_subdevice *s,
@@ -259,19 +258,6 @@ static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel,
259 unsigned int range); 258 unsigned int range);
260 259
261/* 260/*
262 * The struct comedi_driver structure tells the Comedi core module
263 * which functions to call to configure/deconfigure (attach/detach)
264 * the board, and also about the kernel module that contains
265 * the device code.
266 */
267static struct comedi_driver driver_cb_pcidda = {
268 .driver_name = "cb_pcidda",
269 .module = THIS_MODULE,
270 .attach = cb_pcidda_attach,
271 .detach = cb_pcidda_detach,
272};
273
274/*
275 * Attach is called by the Comedi core to configure the driver 261 * Attach is called by the Comedi core to configure the driver
276 * for a particular board. 262 * for a particular board.
277 */ 263 */
@@ -377,7 +363,8 @@ found:
377 dev_dbg(dev->hw_dev, "eeprom:\n"); 363 dev_dbg(dev->hw_dev, "eeprom:\n");
378 for (index = 0; index < EEPROM_SIZE; index++) { 364 for (index = 0; index < EEPROM_SIZE; index++) {
379 devpriv->eeprom_data[index] = cb_pcidda_read_eeprom(dev, index); 365 devpriv->eeprom_data[index] = cb_pcidda_read_eeprom(dev, index);
380 dev_dbg(dev->hw_dev, "%i:0x%x\n", index, devpriv->eeprom_data[index]); 366 dev_dbg(dev->hw_dev, "%i:0x%x\n", index,
367 devpriv->eeprom_data[index]);
381 } 368 }
382 369
383 /* set calibrations dacs */ 370 /* set calibrations dacs */
@@ -387,19 +374,8 @@ found:
387 return 1; 374 return 1;
388} 375}
389 376
390/* 377static void cb_pcidda_detach(struct comedi_device *dev)
391 * _detach is called to deconfigure a device. It should deallocate
392 * resources.
393 * This function is also called when _attach() fails, so it should be
394 * careful not to release resources that were not necessarily
395 * allocated by _attach(). dev->private and dev->subdevices are
396 * deallocated automatically by the core.
397 */
398static int cb_pcidda_detach(struct comedi_device *dev)
399{ 378{
400/*
401 * Deallocate the I/O ports.
402 */
403 if (devpriv) { 379 if (devpriv) {
404 if (devpriv->pci_dev) { 380 if (devpriv->pci_dev) {
405 if (devpriv->dac) 381 if (devpriv->dac)
@@ -407,13 +383,10 @@ static int cb_pcidda_detach(struct comedi_device *dev)
407 pci_dev_put(devpriv->pci_dev); 383 pci_dev_put(devpriv->pci_dev);
408 } 384 }
409 } 385 }
410 /* cleanup 8255 */
411 if (dev->subdevices) { 386 if (dev->subdevices) {
412 subdev_8255_cleanup(dev, dev->subdevices + 1); 387 subdev_8255_cleanup(dev, dev->subdevices + 1);
413 subdev_8255_cleanup(dev, dev->subdevices + 2); 388 subdev_8255_cleanup(dev, dev->subdevices + 2);
414 } 389 }
415
416 return 0;
417} 390}
418 391
419/* 392/*
@@ -484,7 +457,10 @@ static int cb_pcidda_ai_cmdtest(struct comedi_device *dev,
484 if (err) 457 if (err)
485 return 1; 458 return 1;
486 459
487 /* step 2: make sure trigger sources are unique and mutually compatible */ 460 /*
461 * step 2: make sure trigger sources are unique and mutually
462 * compatible
463 */
488 464
489 /* note that mutual compatibility is not an issue here */ 465 /* note that mutual compatibility is not an issue here */
490 if (cmd->scan_begin_src != TRIG_TIMER 466 if (cmd->scan_begin_src != TRIG_TIMER
@@ -696,8 +672,10 @@ static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
696 unsigned int i; 672 unsigned int i;
697 unsigned int cal2_bits; 673 unsigned int cal2_bits;
698 unsigned int value; 674 unsigned int value;
699 const int max_num_caldacs = 4; /* one caldac for every two dac channels */ 675 /* one caldac for every two dac channels */
700 const int read_instruction = 0x6; /* bits to send to tell eeprom we want to read */ 676 const int max_num_caldacs = 4;
677 /* bits to send to tell eeprom we want to read */
678 const int read_instruction = 0x6;
701 const int instruction_length = 3; 679 const int instruction_length = 3;
702 const int address_length = 8; 680 const int address_length = 8;
703 681
@@ -729,9 +707,11 @@ static void cb_pcidda_write_caldac(struct comedi_device *dev,
729{ 707{
730 unsigned int cal2_bits; 708 unsigned int cal2_bits;
731 unsigned int i; 709 unsigned int i;
732 const int num_channel_bits = 3; /* caldacs use 3 bit channel specification */ 710 /* caldacs use 3 bit channel specification */
711 const int num_channel_bits = 3;
733 const int num_caldac_bits = 8; /* 8 bit calibration dacs */ 712 const int num_caldac_bits = 8; /* 8 bit calibration dacs */
734 const int max_num_caldacs = 4; /* one caldac for every two dac channels */ 713 /* one caldac for every two dac channels */
714 const int max_num_caldacs = 4;
735 715
736 /* write 3 bit channel */ 716 /* write 3 bit channel */
737 cb_pcidda_serial_out(dev, channel, num_channel_bits); 717 cb_pcidda_serial_out(dev, channel, num_channel_bits);
@@ -790,14 +770,20 @@ static unsigned int offset_eeprom_address(unsigned int ao_channel,
790 return 0x7 + 2 * range + 12 * ao_channel; 770 return 0x7 + 2 * range + 12 * ao_channel;
791} 771}
792 772
793/* returns eeprom address that provides gain calibration for given ao channel and range */ 773/*
774 * returns eeprom address that provides gain calibration for given ao
775 * channel and range
776 */
794static unsigned int gain_eeprom_address(unsigned int ao_channel, 777static unsigned int gain_eeprom_address(unsigned int ao_channel,
795 unsigned int range) 778 unsigned int range)
796{ 779{
797 return 0x8 + 2 * range + 12 * ao_channel; 780 return 0x8 + 2 * range + 12 * ao_channel;
798} 781}
799 782
800/* returns upper byte of eeprom entry, which gives the coarse adjustment values */ 783/*
784 * returns upper byte of eeprom entry, which gives the coarse adjustment
785 * values
786 */
801static unsigned int eeprom_coarse_byte(unsigned int word) 787static unsigned int eeprom_coarse_byte(unsigned int word)
802{ 788{
803 return (word >> 8) & 0xff; 789 return (word >> 8) & 0xff;
@@ -815,7 +801,7 @@ static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel,
815{ 801{
816 unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain; 802 unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain;
817 803
818 /* remember range so we can tell when we need to readjust calibration */ 804 /* remember range so we can tell when we need to readjust calibration */
819 devpriv->ao_range[channel] = range; 805 devpriv->ao_range[channel] = range;
820 806
821 /* get values from eeprom data */ 807 /* get values from eeprom data */
@@ -843,47 +829,42 @@ static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel,
843 fine_gain_channel(channel), fine_gain); 829 fine_gain_channel(channel), fine_gain);
844} 830}
845 831
846/* 832static struct comedi_driver cb_pcidda_driver = {
847 * A convenient macro that defines init_module() and cleanup_module(), 833 .driver_name = "cb_pcidda",
848 * as necessary. 834 .module = THIS_MODULE,
849 */ 835 .attach = cb_pcidda_attach,
850static int __devinit driver_cb_pcidda_pci_probe(struct pci_dev *dev, 836 .detach = cb_pcidda_detach,
851 const struct pci_device_id *ent) 837};
838
839static int __devinit cb_pcidda_pci_probe(struct pci_dev *dev,
840 const struct pci_device_id *ent)
852{ 841{
853 return comedi_pci_auto_config(dev, driver_cb_pcidda.driver_name); 842 return comedi_pci_auto_config(dev, &cb_pcidda_driver);
854} 843}
855 844
856static void __devexit driver_cb_pcidda_pci_remove(struct pci_dev *dev) 845static void __devexit cb_pcidda_pci_remove(struct pci_dev *dev)
857{ 846{
858 comedi_pci_auto_unconfig(dev); 847 comedi_pci_auto_unconfig(dev);
859} 848}
860 849
861static struct pci_driver driver_cb_pcidda_pci_driver = { 850static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = {
862 .id_table = cb_pcidda_pci_table, 851 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0020) },
863 .probe = &driver_cb_pcidda_pci_probe, 852 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0021) },
864 .remove = __devexit_p(&driver_cb_pcidda_pci_remove) 853 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0022) },
854 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0023) },
855 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0024) },
856 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0025) },
857 { 0 }
865}; 858};
859MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table);
866 860
867static int __init driver_cb_pcidda_init_module(void) 861static struct pci_driver cb_pcidda_pci_driver = {
868{ 862 .name = "cb_pcidda",
869 int retval; 863 .id_table = cb_pcidda_pci_table,
870 864 .probe = cb_pcidda_pci_probe,
871 retval = comedi_driver_register(&driver_cb_pcidda); 865 .remove = __devexit_p(cb_pcidda_pci_remove),
872 if (retval < 0) 866};
873 return retval; 867module_comedi_pci_driver(cb_pcidda_driver, cb_pcidda_pci_driver);
874
875 driver_cb_pcidda_pci_driver.name = (char *)driver_cb_pcidda.driver_name;
876 return pci_register_driver(&driver_cb_pcidda_pci_driver);
877}
878
879static void __exit driver_cb_pcidda_cleanup_module(void)
880{
881 pci_unregister_driver(&driver_cb_pcidda_pci_driver);
882 comedi_driver_unregister(&driver_cb_pcidda);
883}
884
885module_init(driver_cb_pcidda_init_module);
886module_exit(driver_cb_pcidda_cleanup_module);
887 868
888MODULE_AUTHOR("Comedi http://www.comedi.org"); 869MODULE_AUTHOR("Comedi http://www.comedi.org");
889MODULE_DESCRIPTION("Comedi low-level driver"); 870MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c b/drivers/staging/comedi/drivers/cb_pcidio.c
index 8f3215239a15..713132c8dbb5 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -86,19 +86,6 @@ static const struct pcidio_board pcidio_boards[] = {
86 }, 86 },
87}; 87};
88 88
89/* This is used by modprobe to translate PCI IDs to drivers. Should
90 * only be used for PCI and ISA-PnP devices */
91/* Please add your PCI vendor ID to comedidev.h, and it will be forwarded
92 * upstream. */
93static DEFINE_PCI_DEVICE_TABLE(pcidio_pci_table) = {
94 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0028) },
95 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0014) },
96 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000b) },
97 { 0 }
98};
99
100MODULE_DEVICE_TABLE(pci, pcidio_pci_table);
101
102/* 89/*
103 * Useful for shorthand access to the particular board structure 90 * Useful for shorthand access to the particular board structure
104 */ 91 */
@@ -125,59 +112,6 @@ struct pcidio_private {
125 */ 112 */
126#define devpriv ((struct pcidio_private *)dev->private) 113#define devpriv ((struct pcidio_private *)dev->private)
127 114
128/*
129 * The struct comedi_driver structure tells the Comedi core module
130 * which functions to call to configure/deconfigure (attach/detach)
131 * the board, and also about the kernel module that contains
132 * the device code.
133 */
134static int pcidio_attach(struct comedi_device *dev,
135 struct comedi_devconfig *it);
136static int pcidio_detach(struct comedi_device *dev);
137static struct comedi_driver driver_cb_pcidio = {
138 .driver_name = "cb_pcidio",
139 .module = THIS_MODULE,
140 .attach = pcidio_attach,
141 .detach = pcidio_detach,
142
143/* It is not necessary to implement the following members if you are
144 * writing a driver for a ISA PnP or PCI card */
145
146 /* Most drivers will support multiple types of boards by
147 * having an array of board structures. These were defined
148 * in pcidio_boards[] above. Note that the element 'name'
149 * was first in the structure -- Comedi uses this fact to
150 * extract the name of the board without knowing any details
151 * about the structure except for its length.
152 * When a device is attached (by comedi_config), the name
153 * of the device is given to Comedi, and Comedi tries to
154 * match it by going through the list of board names. If
155 * there is a match, the address of the pointer is put
156 * into dev->board_ptr and driver->attach() is called.
157 *
158 * Note that these are not necessary if you can determine
159 * the type of board in software. ISA PnP, PCI, and PCMCIA
160 * devices are such boards.
161 */
162
163/* The following fields should NOT be initialized if you are dealing
164 * with PCI devices
165 *
166 * .board_name = pcidio_boards,
167 * .offset = sizeof(struct pcidio_board),
168 * .num_names = sizeof(pcidio_boards) / sizeof(structpcidio_board),
169 */
170
171};
172
173/*------------------------------- FUNCTIONS -----------------------------------*/
174
175/*
176 * Attach is called by the Comedi core to configure the driver
177 * for a particular board. If you specified a board_name array
178 * in the driver structure, dev->board_ptr contains that
179 * address.
180 */
181static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig *it) 115static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
182{ 116{
183 struct pci_dev *pcidev = NULL; 117 struct pci_dev *pcidev = NULL;
@@ -261,15 +195,7 @@ found:
261 return 1; 195 return 1;
262} 196}
263 197
264/* 198static void pcidio_detach(struct comedi_device *dev)
265 * _detach is called to deconfigure a device. It should deallocate
266 * resources.
267 * This function is also called when _attach() fails, so it should be
268 * careful not to release resources that were not necessarily
269 * allocated by _attach(). dev->private and dev->subdevices are
270 * deallocated automatically by the core.
271 */
272static int pcidio_detach(struct comedi_device *dev)
273{ 199{
274 if (devpriv) { 200 if (devpriv) {
275 if (devpriv->pci_dev) { 201 if (devpriv->pci_dev) {
@@ -283,50 +209,41 @@ static int pcidio_detach(struct comedi_device *dev)
283 for (i = 0; i < thisboard->n_8255; i++) 209 for (i = 0; i < thisboard->n_8255; i++)
284 subdev_8255_cleanup(dev, dev->subdevices + i); 210 subdev_8255_cleanup(dev, dev->subdevices + i);
285 } 211 }
286 return 0;
287} 212}
288 213
289/* 214static struct comedi_driver cb_pcidio_driver = {
290 * A convenient macro that defines init_module() and cleanup_module(), 215 .driver_name = "cb_pcidio",
291 * as necessary. 216 .module = THIS_MODULE,
292 */ 217 .attach = pcidio_attach,
293static int __devinit driver_cb_pcidio_pci_probe(struct pci_dev *dev, 218 .detach = pcidio_detach,
219};
220
221static int __devinit cb_pcidio_pci_probe(struct pci_dev *dev,
294 const struct pci_device_id *ent) 222 const struct pci_device_id *ent)
295{ 223{
296 return comedi_pci_auto_config(dev, driver_cb_pcidio.driver_name); 224 return comedi_pci_auto_config(dev, &cb_pcidio_driver);
297} 225}
298 226
299static void __devexit driver_cb_pcidio_pci_remove(struct pci_dev *dev) 227static void __devexit cb_pcidio_pci_remove(struct pci_dev *dev)
300{ 228{
301 comedi_pci_auto_unconfig(dev); 229 comedi_pci_auto_unconfig(dev);
302} 230}
303 231
304static struct pci_driver driver_cb_pcidio_pci_driver = { 232static DEFINE_PCI_DEVICE_TABLE(cb_pcidio_pci_table) = {
305 .id_table = pcidio_pci_table, 233 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0028) },
306 .probe = &driver_cb_pcidio_pci_probe, 234 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0014) },
307 .remove = __devexit_p(&driver_cb_pcidio_pci_remove) 235 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000b) },
236 { 0 }
308}; 237};
238MODULE_DEVICE_TABLE(pci, cb_pcidio_pci_table);
309 239
310static int __init driver_cb_pcidio_init_module(void) 240static struct pci_driver cb_pcidio_pci_driver = {
311{ 241 .name = "cb_pcidio",
312 int retval; 242 .id_table = cb_pcidio_pci_table,
313 243 .probe = cb_pcidio_pci_probe,
314 retval = comedi_driver_register(&driver_cb_pcidio); 244 .remove = __devexit_p(cb_pcidio_pci_remove),
315 if (retval < 0) 245};
316 return retval; 246module_comedi_pci_driver(cb_pcidio_driver, cb_pcidio_pci_driver);
317
318 driver_cb_pcidio_pci_driver.name = (char *)driver_cb_pcidio.driver_name;
319 return pci_register_driver(&driver_cb_pcidio_pci_driver);
320}
321
322static void __exit driver_cb_pcidio_cleanup_module(void)
323{
324 pci_unregister_driver(&driver_cb_pcidio_pci_driver);
325 comedi_driver_unregister(&driver_cb_pcidio);
326}
327
328module_init(driver_cb_pcidio_init_module);
329module_exit(driver_cb_pcidio_cleanup_module);
330 247
331MODULE_AUTHOR("Comedi http://www.comedi.org"); 248MODULE_AUTHOR("Comedi http://www.comedi.org");
332MODULE_DESCRIPTION("Comedi low-level driver"); 249MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 8ba694263bd3..5f834d02ec24 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -123,15 +123,6 @@ static const struct cb_pcimdas_board cb_pcimdas_boards[] = {
123 }, 123 },
124}; 124};
125 125
126/* This is used by modprobe to translate PCI IDs to drivers. Should
127 * only be used for PCI and ISA-PnP devices */
128static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
129 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0056) },
130 { 0 }
131};
132
133MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
134
135#define N_BOARDS 1 /* Max number of boards supported */ 126#define N_BOARDS 1 /* Max number of boards supported */
136 127
137/* 128/*
@@ -139,9 +130,12 @@ MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
139 */ 130 */
140#define thisboard ((const struct cb_pcimdas_board *)dev->board_ptr) 131#define thisboard ((const struct cb_pcimdas_board *)dev->board_ptr)
141 132
142/* this structure is for data unique to this hardware driver. If 133/*
143 several hardware drivers keep similar information in this structure, 134 * this structure is for data unique to this hardware driver. If
144 feel free to suggest moving the variable to the struct comedi_device struct. */ 135 * several hardware drivers keep similar information in this structure,
136 * feel free to suggest moving the variable to the struct comedi_device
137 * struct.
138 */
145struct cb_pcimdas_private { 139struct cb_pcimdas_private {
146 int data; 140 int data;
147 141
@@ -172,22 +166,6 @@ struct cb_pcimdas_private {
172 */ 166 */
173#define devpriv ((struct cb_pcimdas_private *)dev->private) 167#define devpriv ((struct cb_pcimdas_private *)dev->private)
174 168
175/*
176 * The struct comedi_driver structure tells the Comedi core module
177 * which functions to call to configure/deconfigure (attach/detach)
178 * the board, and also about the kernel module that contains
179 * the device code.
180 */
181static int cb_pcimdas_attach(struct comedi_device *dev,
182 struct comedi_devconfig *it);
183static int cb_pcimdas_detach(struct comedi_device *dev);
184static struct comedi_driver driver_cb_pcimdas = {
185 .driver_name = "cb_pcimdas",
186 .module = THIS_MODULE,
187 .attach = cb_pcimdas_attach,
188 .detach = cb_pcimdas_detach,
189};
190
191static int cb_pcimdas_ai_rinsn(struct comedi_device *dev, 169static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
192 struct comedi_subdevice *s, 170 struct comedi_subdevice *s,
193 struct comedi_insn *insn, unsigned int *data); 171 struct comedi_insn *insn, unsigned int *data);
@@ -317,7 +295,8 @@ found:
317 s->subdev_flags = SDF_WRITABLE; 295 s->subdev_flags = SDF_WRITABLE;
318 s->n_chan = thisboard->ao_nchan; 296 s->n_chan = thisboard->ao_nchan;
319 s->maxdata = 1 << thisboard->ao_bits; 297 s->maxdata = 1 << thisboard->ao_bits;
320 s->range_table = &range_unknown; /* ranges are hardware settable, but not software readable. */ 298 /* ranges are hardware settable, but not software readable. */
299 s->range_table = &range_unknown;
321 s->insn_write = &cb_pcimdas_ao_winsn; 300 s->insn_write = &cb_pcimdas_ao_winsn;
322 s->insn_read = &cb_pcimdas_ao_rinsn; 301 s->insn_read = &cb_pcimdas_ao_rinsn;
323 302
@@ -331,29 +310,8 @@ found:
331 return 1; 310 return 1;
332} 311}
333 312
334/* 313static void cb_pcimdas_detach(struct comedi_device *dev)
335 * _detach is called to deconfigure a device. It should deallocate
336 * resources.
337 * This function is also called when _attach() fails, so it should be
338 * careful not to release resources that were not necessarily
339 * allocated by _attach(). dev->private and dev->subdevices are
340 * deallocated automatically by the core.
341 */
342static int cb_pcimdas_detach(struct comedi_device *dev)
343{ 314{
344 if (devpriv) {
345 dev_dbg(dev->hw_dev, "devpriv->BADR0 = 0x%lx\n",
346 devpriv->BADR0);
347 dev_dbg(dev->hw_dev, "devpriv->BADR1 = 0x%lx\n",
348 devpriv->BADR1);
349 dev_dbg(dev->hw_dev, "devpriv->BADR2 = 0x%lx\n",
350 devpriv->BADR2);
351 dev_dbg(dev->hw_dev, "devpriv->BADR3 = 0x%lx\n",
352 devpriv->BADR3);
353 dev_dbg(dev->hw_dev, "devpriv->BADR4 = 0x%lx\n",
354 devpriv->BADR4);
355 }
356
357 if (dev->irq) 315 if (dev->irq)
358 free_irq(dev->irq, dev); 316 free_irq(dev->irq, dev);
359 if (devpriv) { 317 if (devpriv) {
@@ -363,8 +321,6 @@ static int cb_pcimdas_detach(struct comedi_device *dev)
363 pci_dev_put(devpriv->pci_dev); 321 pci_dev_put(devpriv->pci_dev);
364 } 322 }
365 } 323 }
366
367 return 0;
368} 324}
369 325
370/* 326/*
@@ -402,7 +358,10 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
402 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */ 358 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
403 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */ 359 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
404 360
405 /* write channel limits to multiplexer, set Low (bits 0-3) and High (bits 4-7) channels to chan. */ 361 /*
362 * write channel limits to multiplexer, set Low (bits 0-3) and
363 * High (bits 4-7) channels to chan.
364 */
406 chanlims = chan | (chan << 4); 365 chanlims = chan | (chan << 4);
407 outb(chanlims, devpriv->BADR3 + 0); 366 outb(chanlims, devpriv->BADR3 + 0);
408 367
@@ -479,49 +438,37 @@ static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
479 return i; 438 return i;
480} 439}
481 440
482/* 441static struct comedi_driver cb_pcimdas_driver = {
483 * A convenient macro that defines init_module() and cleanup_module(), 442 .driver_name = "cb_pcimdas",
484 * as necessary. 443 .module = THIS_MODULE,
485 */ 444 .attach = cb_pcimdas_attach,
486static int __devinit driver_cb_pcimdas_pci_probe(struct pci_dev *dev, 445 .detach = cb_pcimdas_detach,
487 const struct pci_device_id 446};
488 *ent) 447
448static int __devinit cb_pcimdas_pci_probe(struct pci_dev *dev,
449 const struct pci_device_id *ent)
489{ 450{
490 return comedi_pci_auto_config(dev, driver_cb_pcimdas.driver_name); 451 return comedi_pci_auto_config(dev, &cb_pcimdas_driver);
491} 452}
492 453
493static void __devexit driver_cb_pcimdas_pci_remove(struct pci_dev *dev) 454static void __devexit cb_pcimdas_pci_remove(struct pci_dev *dev)
494{ 455{
495 comedi_pci_auto_unconfig(dev); 456 comedi_pci_auto_unconfig(dev);
496} 457}
497 458
498static struct pci_driver driver_cb_pcimdas_pci_driver = { 459static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
499 .id_table = cb_pcimdas_pci_table, 460 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0056) },
500 .probe = &driver_cb_pcimdas_pci_probe, 461 { 0 }
501 .remove = __devexit_p(&driver_cb_pcimdas_pci_remove)
502}; 462};
463MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
503 464
504static int __init driver_cb_pcimdas_init_module(void) 465static struct pci_driver cb_pcimdas_pci_driver = {
505{ 466 .name = "cb_pcimdas",
506 int retval; 467 .id_table = cb_pcimdas_pci_table,
507 468 .probe = cb_pcimdas_pci_probe,
508 retval = comedi_driver_register(&driver_cb_pcimdas); 469 .remove = __devexit_p(cb_pcimdas_pci_remove),
509 if (retval < 0) 470};
510 return retval; 471module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
511
512 driver_cb_pcimdas_pci_driver.name =
513 (char *)driver_cb_pcimdas.driver_name;
514 return pci_register_driver(&driver_cb_pcimdas_pci_driver);
515}
516
517static void __exit driver_cb_pcimdas_cleanup_module(void)
518{
519 pci_unregister_driver(&driver_cb_pcimdas_pci_driver);
520 comedi_driver_unregister(&driver_cb_pcimdas);
521}
522
523module_init(driver_cb_pcimdas_init_module);
524module_exit(driver_cb_pcimdas_cleanup_module);
525 472
526MODULE_AUTHOR("Comedi http://www.comedi.org"); 473MODULE_AUTHOR("Comedi http://www.comedi.org");
527MODULE_DESCRIPTION("Comedi low-level driver"); 474MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c
index 40bddfa22220..b339685e234d 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdda.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdda.c
@@ -140,17 +140,6 @@ static const struct board_struct boards[] = {
140#define REG_SZ (thisboard->reg_sz) 140#define REG_SZ (thisboard->reg_sz)
141#define REGS_BADRINDEX (thisboard->regs_badrindex) 141#define REGS_BADRINDEX (thisboard->regs_badrindex)
142 142
143/* This is used by modprobe to translate PCI IDs to drivers. Should
144 * only be used for PCI and ISA-PnP devices */
145/* Please add your PCI vendor ID to comedidev.h, and it will be forwarded
146 * upstream. */
147static DEFINE_PCI_DEVICE_TABLE(pci_table) = {
148 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, PCI_ID_PCIM_DDA06_16) },
149 {0}
150};
151
152MODULE_DEVICE_TABLE(pci, pci_table);
153
154/* 143/*
155 * this structure is for data unique to this hardware driver. If 144 * this structure is for data unique to this hardware driver. If
156 * several hardware drivers keep similar information in this structure, 145 * several hardware drivers keep similar information in this structure,
@@ -161,7 +150,6 @@ struct board_private_struct {
161 unsigned long registers; /* set by probe */ 150 unsigned long registers; /* set by probe */
162 unsigned long dio_registers; 151 unsigned long dio_registers;
163 char attached_to_8255; /* boolean */ 152 char attached_to_8255; /* boolean */
164 char attached_successfully; /* boolean */
165 /* would be useful for a PCI device */ 153 /* would be useful for a PCI device */
166 struct pci_dev *pci_dev; 154 struct pci_dev *pci_dev;
167 155
@@ -177,66 +165,6 @@ struct board_private_struct {
177 */ 165 */
178#define devpriv ((struct board_private_struct *)dev->private) 166#define devpriv ((struct board_private_struct *)dev->private)
179 167
180/*
181 * The struct comedi_driver structure tells the Comedi core module
182 * which functions to call to configure/deconfigure (attach/detach)
183 * the board, and also about the kernel module that contains
184 * the device code.
185 */
186static int attach(struct comedi_device *dev, struct comedi_devconfig *it);
187static int detach(struct comedi_device *dev);
188static struct comedi_driver cb_pcimdda_driver = {
189 .driver_name = "cb_pcimdda",
190 .module = THIS_MODULE,
191 .attach = attach,
192 .detach = detach,
193};
194
195MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
196MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "
197 "series. Currently only supports PCIM-DDA06-16 (which "
198 "also happens to be the only board in this series. :) ) ");
199MODULE_LICENSE("GPL");
200static int __devinit cb_pcimdda_driver_pci_probe(struct pci_dev *dev,
201 const struct pci_device_id
202 *ent)
203{
204 return comedi_pci_auto_config(dev, cb_pcimdda_driver.driver_name);
205}
206
207static void __devexit cb_pcimdda_driver_pci_remove(struct pci_dev *dev)
208{
209 comedi_pci_auto_unconfig(dev);
210}
211
212static struct pci_driver cb_pcimdda_driver_pci_driver = {
213 .id_table = pci_table,
214 .probe = &cb_pcimdda_driver_pci_probe,
215 .remove = __devexit_p(&cb_pcimdda_driver_pci_remove)
216};
217
218static int __init cb_pcimdda_driver_init_module(void)
219{
220 int retval;
221
222 retval = comedi_driver_register(&cb_pcimdda_driver);
223 if (retval < 0)
224 return retval;
225
226 cb_pcimdda_driver_pci_driver.name =
227 (char *)cb_pcimdda_driver.driver_name;
228 return pci_register_driver(&cb_pcimdda_driver_pci_driver);
229}
230
231static void __exit cb_pcimdda_driver_cleanup_module(void)
232{
233 pci_unregister_driver(&cb_pcimdda_driver_pci_driver);
234 comedi_driver_unregister(&cb_pcimdda_driver);
235}
236
237module_init(cb_pcimdda_driver_init_module);
238module_exit(cb_pcimdda_driver_cleanup_module);
239
240static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, 168static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
241 struct comedi_insn *insn, unsigned int *data); 169 struct comedi_insn *insn, unsigned int *data);
242static int ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, 170static int ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -354,44 +282,24 @@ static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
354 s->type = COMEDI_SUBD_UNUSED; 282 s->type = COMEDI_SUBD_UNUSED;
355 } 283 }
356 284
357 devpriv->attached_successfully = 1;
358
359 printk("attached\n"); 285 printk("attached\n");
360 286
361 return 1; 287 return 1;
362} 288}
363 289
364/* 290static void detach(struct comedi_device *dev)
365 * _detach is called to deconfigure a device. It should deallocate
366 * resources.
367 * This function is also called when _attach() fails, so it should be
368 * careful not to release resources that were not necessarily
369 * allocated by _attach(). dev->private and dev->subdevices are
370 * deallocated automatically by the core.
371 */
372static int detach(struct comedi_device *dev)
373{ 291{
374 if (devpriv) { 292 if (devpriv) {
375
376 if (dev->subdevices && devpriv->attached_to_8255) { 293 if (dev->subdevices && devpriv->attached_to_8255) {
377 /* de-register us from the 8255 driver */
378 subdev_8255_cleanup(dev, dev->subdevices + 2); 294 subdev_8255_cleanup(dev, dev->subdevices + 2);
379 devpriv->attached_to_8255 = 0; 295 devpriv->attached_to_8255 = 0;
380 } 296 }
381
382 if (devpriv->pci_dev) { 297 if (devpriv->pci_dev) {
383 if (devpriv->registers) 298 if (devpriv->registers)
384 comedi_pci_disable(devpriv->pci_dev); 299 comedi_pci_disable(devpriv->pci_dev);
385 pci_dev_put(devpriv->pci_dev); 300 pci_dev_put(devpriv->pci_dev);
386 } 301 }
387
388 if (devpriv->attached_successfully && thisboard)
389 printk("comedi%d: %s: detached\n", dev->minor,
390 thisboard->name);
391
392 } 302 }
393
394 return 0;
395} 303}
396 304
397static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, 305static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -515,3 +423,41 @@ static int probe(struct comedi_device *dev, const struct comedi_devconfig *it)
515 "card found at the requested position\n"); 423 "card found at the requested position\n");
516 return -ENODEV; 424 return -ENODEV;
517} 425}
426
427static struct comedi_driver cb_pcimdda_driver = {
428 .driver_name = "cb_pcimdda",
429 .module = THIS_MODULE,
430 .attach = attach,
431 .detach = detach,
432};
433
434static int __devinit cb_pcimdda_pci_probe(struct pci_dev *dev,
435 const struct pci_device_id *ent)
436{
437 return comedi_pci_auto_config(dev, &cb_pcimdda_driver);
438}
439
440static void __devexit cb_pcimdda_pci_remove(struct pci_dev *dev)
441{
442 comedi_pci_auto_unconfig(dev);
443}
444
445static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
446 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, PCI_ID_PCIM_DDA06_16) },
447 { 0 }
448};
449MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
450
451static struct pci_driver cb_pcimdda_driver_pci_driver = {
452 .name = "cb_pcimdda",
453 .id_table = cb_pcimdda_pci_table,
454 .probe = cb_pcimdda_pci_probe,
455 .remove = __devexit_p(cb_pcimdda_pci_remove),
456};
457module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
458
459MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
460MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "
461 "series. Currently only supports PCIM-DDA06-16 (which "
462 "also happens to be the only board in this series. :) ) ");
463MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index d8aefb23d6b9..29412de06c31 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -60,7 +60,6 @@ Configuration Options:
60#define MAX_CHANS 256 60#define MAX_CHANS 256
61 61
62#define MODULE_NAME "comedi_bond" 62#define MODULE_NAME "comedi_bond"
63MODULE_LICENSE("GPL");
64#ifndef STR 63#ifndef STR
65# define STR1(x) #x 64# define STR1(x) #x
66# define STR(x) STR1(x) 65# define STR(x) STR1(x)
@@ -79,10 +78,6 @@ MODULE_PARM_DESC(debug, "If true, print extra cryptic debugging output useful"
79 } while (0) 78 } while (0)
80#define WARNING(x...) printk(KERN_WARNING MODULE_NAME ": WARNING: "x) 79#define WARNING(x...) printk(KERN_WARNING MODULE_NAME ": WARNING: "x)
81#define ERROR(x...) printk(KERN_ERR MODULE_NAME ": INTERNAL ERROR: "x) 80#define ERROR(x...) printk(KERN_ERR MODULE_NAME ": INTERNAL ERROR: "x)
82MODULE_AUTHOR("Calin A. Culianu");
83MODULE_DESCRIPTION(MODULE_NAME "A driver for COMEDI to bond multiple COMEDI "
84 "devices together as one. In the words of John Lennon: "
85 "'And the world will live as one...'");
86 81
87/* 82/*
88 * Board descriptions for two imaginary boards. Describing the 83 * Board descriptions for two imaginary boards. Describing the
@@ -93,12 +88,6 @@ struct BondingBoard {
93 const char *name; 88 const char *name;
94}; 89};
95 90
96static const struct BondingBoard bondingBoards[] = {
97 {
98 .name = MODULE_NAME,
99 },
100};
101
102/* 91/*
103 * Useful for shorthand access to the particular board structure 92 * Useful for shorthand access to the particular board structure
104 */ 93 */
@@ -133,129 +122,6 @@ struct Private {
133 */ 122 */
134#define devpriv ((struct Private *)dev->private) 123#define devpriv ((struct Private *)dev->private)
135 124
136/*
137 * The struct comedi_driver structure tells the Comedi core module
138 * which functions to call to configure/deconfigure (attach/detach)
139 * the board, and also about the kernel module that contains
140 * the device code.
141 */
142static int bonding_attach(struct comedi_device *dev,
143 struct comedi_devconfig *it);
144static int bonding_detach(struct comedi_device *dev);
145/** Build Private array of all devices.. */
146static int doDevConfig(struct comedi_device *dev, struct comedi_devconfig *it);
147static void doDevUnconfig(struct comedi_device *dev);
148/* Ugly implementation of realloc that always copies memory around -- I'm lazy,
149 * what can I say? I like to do wasteful memcopies.. :) */
150static void *Realloc(const void *ptr, size_t len, size_t old_len);
151
152static struct comedi_driver driver_bonding = {
153 .driver_name = MODULE_NAME,
154 .module = THIS_MODULE,
155 .attach = bonding_attach,
156 .detach = bonding_detach,
157 /* It is not necessary to implement the following members if you are
158 * writing a driver for a ISA PnP or PCI card */
159 /* Most drivers will support multiple types of boards by
160 * having an array of board structures. These were defined
161 * in skel_boards[] above. Note that the element 'name'
162 * was first in the structure -- Comedi uses this fact to
163 * extract the name of the board without knowing any details
164 * about the structure except for its length.
165 * When a device is attached (by comedi_config), the name
166 * of the device is given to Comedi, and Comedi tries to
167 * match it by going through the list of board names. If
168 * there is a match, the address of the pointer is put
169 * into dev->board_ptr and driver->attach() is called.
170 *
171 * Note that these are not necessary if you can determine
172 * the type of board in software. ISA PnP, PCI, and PCMCIA
173 * devices are such boards.
174 */
175 .board_name = &bondingBoards[0].name,
176 .offset = sizeof(struct BondingBoard),
177 .num_names = ARRAY_SIZE(bondingBoards),
178};
179
180static int bonding_dio_insn_bits(struct comedi_device *dev,
181 struct comedi_subdevice *s,
182 struct comedi_insn *insn, unsigned int *data);
183static int bonding_dio_insn_config(struct comedi_device *dev,
184 struct comedi_subdevice *s,
185 struct comedi_insn *insn,
186 unsigned int *data);
187
188/*
189 * Attach is called by the Comedi core to configure the driver
190 * for a particular board. If you specified a board_name array
191 * in the driver structure, dev->board_ptr contains that
192 * address.
193 */
194static int bonding_attach(struct comedi_device *dev,
195 struct comedi_devconfig *it)
196{
197 struct comedi_subdevice *s;
198
199 LOG_MSG("comedi%d\n", dev->minor);
200
201 /*
202 * Allocate the private structure area. alloc_private() is a
203 * convenient macro defined in comedidev.h.
204 */
205 if (alloc_private(dev, sizeof(struct Private)) < 0)
206 return -ENOMEM;
207
208 /*
209 * Setup our bonding from config params.. sets up our Private struct..
210 */
211 if (!doDevConfig(dev, it))
212 return -EINVAL;
213
214 /*
215 * Initialize dev->board_name. Note that we can use the "thisboard"
216 * macro now, since we just initialized it in the last line.
217 */
218 dev->board_name = devpriv->name;
219
220 /*
221 * Allocate the subdevice structures. alloc_subdevice() is a
222 * convenient macro defined in comedidev.h.
223 */
224 if (alloc_subdevices(dev, 1) < 0)
225 return -ENOMEM;
226
227 s = dev->subdevices + 0;
228 s->type = COMEDI_SUBD_DIO;
229 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
230 s->n_chan = devpriv->nchans;
231 s->maxdata = 1;
232 s->range_table = &range_digital;
233 s->insn_bits = bonding_dio_insn_bits;
234 s->insn_config = bonding_dio_insn_config;
235
236 LOG_MSG("attached with %u DIO channels coming from %u different "
237 "subdevices all bonded together. "
238 "John Lennon would be proud!\n",
239 devpriv->nchans, devpriv->ndevs);
240
241 return 1;
242}
243
244/*
245 * _detach is called to deconfigure a device. It should deallocate
246 * resources.
247 * This function is also called when _attach() fails, so it should be
248 * careful not to release resources that were not necessarily
249 * allocated by _attach(). dev->private and dev->subdevices are
250 * deallocated automatically by the core.
251 */
252static int bonding_detach(struct comedi_device *dev)
253{
254 LOG_MSG("comedi%d: remove\n", dev->minor);
255 doDevUnconfig(dev);
256 return 0;
257}
258
259/* DIO devices are slightly special. Although it is possible to 125/* DIO devices are slightly special. Although it is possible to
260 * implement the insn_read/insn_write interface, it is much more 126 * implement the insn_read/insn_write interface, it is much more
261 * useful to applications if you implement the insn_bits interface. 127 * useful to applications if you implement the insn_bits interface.
@@ -466,7 +332,57 @@ static int doDevConfig(struct comedi_device *dev, struct comedi_devconfig *it)
466 return 1; 332 return 1;
467} 333}
468 334
469static void doDevUnconfig(struct comedi_device *dev) 335static int bonding_attach(struct comedi_device *dev,
336 struct comedi_devconfig *it)
337{
338 struct comedi_subdevice *s;
339
340 LOG_MSG("comedi%d\n", dev->minor);
341
342 /*
343 * Allocate the private structure area. alloc_private() is a
344 * convenient macro defined in comedidev.h.
345 */
346 if (alloc_private(dev, sizeof(struct Private)) < 0)
347 return -ENOMEM;
348
349 /*
350 * Setup our bonding from config params.. sets up our Private struct..
351 */
352 if (!doDevConfig(dev, it))
353 return -EINVAL;
354
355 /*
356 * Initialize dev->board_name. Note that we can use the "thisboard"
357 * macro now, since we just initialized it in the last line.
358 */
359 dev->board_name = devpriv->name;
360
361 /*
362 * Allocate the subdevice structures. alloc_subdevice() is a
363 * convenient macro defined in comedidev.h.
364 */
365 if (alloc_subdevices(dev, 1) < 0)
366 return -ENOMEM;
367
368 s = dev->subdevices + 0;
369 s->type = COMEDI_SUBD_DIO;
370 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
371 s->n_chan = devpriv->nchans;
372 s->maxdata = 1;
373 s->range_table = &range_digital;
374 s->insn_bits = bonding_dio_insn_bits;
375 s->insn_config = bonding_dio_insn_config;
376
377 LOG_MSG("attached with %u DIO channels coming from %u different "
378 "subdevices all bonded together. "
379 "John Lennon would be proud!\n",
380 devpriv->nchans, devpriv->ndevs);
381
382 return 1;
383}
384
385static void bonding_detach(struct comedi_device *dev)
470{ 386{
471 unsigned long devs_closed = 0; 387 unsigned long devs_closed = 0;
472 388
@@ -490,15 +406,25 @@ static void doDevUnconfig(struct comedi_device *dev)
490 } 406 }
491} 407}
492 408
493static int __init init(void) 409static const struct BondingBoard bondingBoards[] = {
494{ 410 {
495 return comedi_driver_register(&driver_bonding); 411 .name = "comedi_bond",
496} 412 },
413};
497 414
498static void __exit cleanup(void) 415static struct comedi_driver bonding_driver = {
499{ 416 .driver_name = "comedi_bond",
500 comedi_driver_unregister(&driver_bonding); 417 .module = THIS_MODULE,
501} 418 .attach = bonding_attach,
419 .detach = bonding_detach,
420 .board_name = &bondingBoards[0].name,
421 .offset = sizeof(struct BondingBoard),
422 .num_names = ARRAY_SIZE(bondingBoards),
423};
424module_comedi_driver(bonding_driver);
502 425
503module_init(init); 426MODULE_AUTHOR("Calin A. Culianu");
504module_exit(cleanup); 427MODULE_DESCRIPTION(MODULE_NAME "A driver for COMEDI to bond multiple COMEDI "
428 "devices together as one. In the words of John Lennon: "
429 "'And the world will live as one...'");
430MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/comedi_parport.c b/drivers/staging/comedi/drivers/comedi_parport.c
index 21d834dd92b6..bff5dcd76107 100644
--- a/drivers/staging/comedi/drivers/comedi_parport.c
+++ b/drivers/staging/comedi/drivers/comedi_parport.c
@@ -91,29 +91,6 @@ pin, which can be used to wake up tasks.
91#define PARPORT_B 1 91#define PARPORT_B 1
92#define PARPORT_C 2 92#define PARPORT_C 2
93 93
94static int parport_attach(struct comedi_device *dev,
95 struct comedi_devconfig *it);
96static int parport_detach(struct comedi_device *dev);
97static struct comedi_driver driver_parport = {
98 .driver_name = "comedi_parport",
99 .module = THIS_MODULE,
100 .attach = parport_attach,
101 .detach = parport_detach,
102};
103
104static int __init driver_parport_init_module(void)
105{
106 return comedi_driver_register(&driver_parport);
107}
108
109static void __exit driver_parport_cleanup_module(void)
110{
111 comedi_driver_unregister(&driver_parport);
112}
113
114module_init(driver_parport_init_module);
115module_exit(driver_parport_cleanup_module);
116
117struct parport_private { 94struct parport_private {
118 unsigned int a_data; 95 unsigned int a_data;
119 unsigned int c_data; 96 unsigned int c_data;
@@ -395,19 +372,22 @@ static int parport_attach(struct comedi_device *dev,
395 return 1; 372 return 1;
396} 373}
397 374
398static int parport_detach(struct comedi_device *dev) 375static void parport_detach(struct comedi_device *dev)
399{ 376{
400 printk(KERN_INFO "comedi%d: parport: remove\n", dev->minor);
401
402 if (dev->iobase) 377 if (dev->iobase)
403 release_region(dev->iobase, PARPORT_SIZE); 378 release_region(dev->iobase, PARPORT_SIZE);
404
405 if (dev->irq) 379 if (dev->irq)
406 free_irq(dev->irq, dev); 380 free_irq(dev->irq, dev);
407
408 return 0;
409} 381}
410 382
383static struct comedi_driver parport_driver = {
384 .driver_name = "comedi_parport",
385 .module = THIS_MODULE,
386 .attach = parport_attach,
387 .detach = parport_detach,
388};
389module_comedi_driver(parport_driver);
390
411MODULE_AUTHOR("Comedi http://www.comedi.org"); 391MODULE_AUTHOR("Comedi http://www.comedi.org");
412MODULE_DESCRIPTION("Comedi low-level driver"); 392MODULE_DESCRIPTION("Comedi low-level driver");
413MODULE_LICENSE("GPL"); 393MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index a804742b8022..873e37450bba 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -67,15 +67,6 @@ struct waveform_board {
67 67
68#define N_CHANS 8 68#define N_CHANS 8
69 69
70static const struct waveform_board waveform_boards[] = {
71 {
72 .name = "comedi_test",
73 .ai_chans = N_CHANS,
74 .ai_bits = 16,
75 .have_dio = 0,
76 },
77};
78
79#define thisboard ((const struct waveform_board *)dev->board_ptr) 70#define thisboard ((const struct waveform_board *)dev->board_ptr)
80 71
81/* Data unique to this driver */ 72/* Data unique to this driver */
@@ -94,54 +85,6 @@ struct waveform_private {
94}; 85};
95#define devpriv ((struct waveform_private *)dev->private) 86#define devpriv ((struct waveform_private *)dev->private)
96 87
97static int waveform_attach(struct comedi_device *dev,
98 struct comedi_devconfig *it);
99static int waveform_detach(struct comedi_device *dev);
100static struct comedi_driver driver_waveform = {
101 .driver_name = "comedi_test",
102 .module = THIS_MODULE,
103 .attach = waveform_attach,
104 .detach = waveform_detach,
105 .board_name = &waveform_boards[0].name,
106 .offset = sizeof(struct waveform_board),
107 .num_names = ARRAY_SIZE(waveform_boards),
108};
109
110static int __init driver_waveform_init_module(void)
111{
112 return comedi_driver_register(&driver_waveform);
113}
114
115static void __exit driver_waveform_cleanup_module(void)
116{
117 comedi_driver_unregister(&driver_waveform);
118}
119
120module_init(driver_waveform_init_module);
121module_exit(driver_waveform_cleanup_module);
122
123static int waveform_ai_cmdtest(struct comedi_device *dev,
124 struct comedi_subdevice *s,
125 struct comedi_cmd *cmd);
126static int waveform_ai_cmd(struct comedi_device *dev,
127 struct comedi_subdevice *s);
128static int waveform_ai_cancel(struct comedi_device *dev,
129 struct comedi_subdevice *s);
130static int waveform_ai_insn_read(struct comedi_device *dev,
131 struct comedi_subdevice *s,
132 struct comedi_insn *insn, unsigned int *data);
133static int waveform_ao_insn_write(struct comedi_device *dev,
134 struct comedi_subdevice *s,
135 struct comedi_insn *insn, unsigned int *data);
136static short fake_sawtooth(struct comedi_device *dev, unsigned int range,
137 unsigned long current_time);
138static short fake_squarewave(struct comedi_device *dev, unsigned int range,
139 unsigned long current_time);
140static short fake_flatline(struct comedi_device *dev, unsigned int range,
141 unsigned long current_time);
142static short fake_waveform(struct comedi_device *dev, unsigned int channel,
143 unsigned int range, unsigned long current_time);
144
145/* 1000 nanosec in a microsec */ 88/* 1000 nanosec in a microsec */
146static const int nano_per_micro = 1000; 89static const int nano_per_micro = 1000;
147 90
@@ -154,6 +97,78 @@ static const struct comedi_lrange waveform_ai_ranges = {
154 } 97 }
155}; 98};
156 99
100static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index,
101 unsigned long current_time)
102{
103 struct comedi_subdevice *s = dev->read_subdev;
104 unsigned int offset = s->maxdata / 2;
105 u64 value;
106 const struct comedi_krange *krange =
107 &s->range_table->range[range_index];
108 u64 binary_amplitude;
109
110 binary_amplitude = s->maxdata;
111 binary_amplitude *= devpriv->uvolt_amplitude;
112 do_div(binary_amplitude, krange->max - krange->min);
113
114 current_time %= devpriv->usec_period;
115 value = current_time;
116 value *= binary_amplitude * 2;
117 do_div(value, devpriv->usec_period);
118 value -= binary_amplitude; /* get rid of sawtooth's dc offset */
119
120 return offset + value;
121}
122
123static short fake_squarewave(struct comedi_device *dev,
124 unsigned int range_index,
125 unsigned long current_time)
126{
127 struct comedi_subdevice *s = dev->read_subdev;
128 unsigned int offset = s->maxdata / 2;
129 u64 value;
130 const struct comedi_krange *krange =
131 &s->range_table->range[range_index];
132 current_time %= devpriv->usec_period;
133
134 value = s->maxdata;
135 value *= devpriv->uvolt_amplitude;
136 do_div(value, krange->max - krange->min);
137
138 if (current_time < devpriv->usec_period / 2)
139 value *= -1;
140
141 return offset + value;
142}
143
144static short fake_flatline(struct comedi_device *dev, unsigned int range_index,
145 unsigned long current_time)
146{
147 return dev->read_subdev->maxdata / 2;
148}
149
150/* generates a different waveform depending on what channel is read */
151static short fake_waveform(struct comedi_device *dev, unsigned int channel,
152 unsigned int range, unsigned long current_time)
153{
154 enum {
155 SAWTOOTH_CHAN,
156 SQUARE_CHAN,
157 };
158 switch (channel) {
159 case SAWTOOTH_CHAN:
160 return fake_sawtooth(dev, range, current_time);
161 break;
162 case SQUARE_CHAN:
163 return fake_squarewave(dev, range, current_time);
164 break;
165 default:
166 break;
167 }
168
169 return fake_flatline(dev, range, current_time);
170}
171
157/* 172/*
158 This is the background routine used to generate arbitrary data. 173 This is the background routine used to generate arbitrary data.
159 It should run in the background; therefore it is scheduled by 174 It should run in the background; therefore it is scheduled by
@@ -217,84 +232,6 @@ static void waveform_ai_interrupt(unsigned long arg)
217 comedi_event(dev, dev->read_subdev); 232 comedi_event(dev, dev->read_subdev);
218} 233}
219 234
220static int waveform_attach(struct comedi_device *dev,
221 struct comedi_devconfig *it)
222{
223 struct comedi_subdevice *s;
224 int amplitude = it->options[0];
225 int period = it->options[1];
226 int i;
227
228 dev->board_name = thisboard->name;
229
230 if (alloc_private(dev, sizeof(struct waveform_private)) < 0)
231 return -ENOMEM;
232
233 /* set default amplitude and period */
234 if (amplitude <= 0)
235 amplitude = 1000000; /* 1 volt */
236 if (period <= 0)
237 period = 100000; /* 0.1 sec */
238
239 devpriv->uvolt_amplitude = amplitude;
240 devpriv->usec_period = period;
241
242 dev->n_subdevices = 2;
243 if (alloc_subdevices(dev, dev->n_subdevices) < 0)
244 return -ENOMEM;
245
246 s = dev->subdevices + 0;
247 dev->read_subdev = s;
248 /* analog input subdevice */
249 s->type = COMEDI_SUBD_AI;
250 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
251 s->n_chan = thisboard->ai_chans;
252 s->maxdata = (1 << thisboard->ai_bits) - 1;
253 s->range_table = &waveform_ai_ranges;
254 s->len_chanlist = s->n_chan * 2;
255 s->insn_read = waveform_ai_insn_read;
256 s->do_cmd = waveform_ai_cmd;
257 s->do_cmdtest = waveform_ai_cmdtest;
258 s->cancel = waveform_ai_cancel;
259
260 s = dev->subdevices + 1;
261 dev->write_subdev = s;
262 /* analog output subdevice (loopback) */
263 s->type = COMEDI_SUBD_AO;
264 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
265 s->n_chan = thisboard->ai_chans;
266 s->maxdata = (1 << thisboard->ai_bits) - 1;
267 s->range_table = &waveform_ai_ranges;
268 s->len_chanlist = s->n_chan * 2;
269 s->insn_write = waveform_ao_insn_write;
270 s->do_cmd = NULL;
271 s->do_cmdtest = NULL;
272 s->cancel = NULL;
273
274 /* Our default loopback value is just a 0V flatline */
275 for (i = 0; i < s->n_chan; i++)
276 devpriv->ao_loopbacks[i] = s->maxdata / 2;
277
278 init_timer(&(devpriv->timer));
279 devpriv->timer.function = waveform_ai_interrupt;
280 devpriv->timer.data = (unsigned long)dev;
281
282 printk(KERN_INFO "comedi%d: comedi_test: "
283 "%i microvolt, %li microsecond waveform attached\n", dev->minor,
284 devpriv->uvolt_amplitude, devpriv->usec_period);
285 return 1;
286}
287
288static int waveform_detach(struct comedi_device *dev)
289{
290 printk("comedi%d: comedi_test: remove\n", dev->minor);
291
292 if (dev->private)
293 waveform_ai_cancel(dev, dev->read_subdev);
294
295 return 0;
296}
297
298static int waveform_ai_cmdtest(struct comedi_device *dev, 235static int waveform_ai_cmdtest(struct comedi_device *dev,
299 struct comedi_subdevice *s, 236 struct comedi_subdevice *s,
300 struct comedi_cmd *cmd) 237 struct comedi_cmd *cmd)
@@ -465,78 +402,6 @@ static int waveform_ai_cancel(struct comedi_device *dev,
465 return 0; 402 return 0;
466} 403}
467 404
468static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index,
469 unsigned long current_time)
470{
471 struct comedi_subdevice *s = dev->read_subdev;
472 unsigned int offset = s->maxdata / 2;
473 u64 value;
474 const struct comedi_krange *krange =
475 &s->range_table->range[range_index];
476 u64 binary_amplitude;
477
478 binary_amplitude = s->maxdata;
479 binary_amplitude *= devpriv->uvolt_amplitude;
480 do_div(binary_amplitude, krange->max - krange->min);
481
482 current_time %= devpriv->usec_period;
483 value = current_time;
484 value *= binary_amplitude * 2;
485 do_div(value, devpriv->usec_period);
486 value -= binary_amplitude; /* get rid of sawtooth's dc offset */
487
488 return offset + value;
489}
490
491static short fake_squarewave(struct comedi_device *dev,
492 unsigned int range_index,
493 unsigned long current_time)
494{
495 struct comedi_subdevice *s = dev->read_subdev;
496 unsigned int offset = s->maxdata / 2;
497 u64 value;
498 const struct comedi_krange *krange =
499 &s->range_table->range[range_index];
500 current_time %= devpriv->usec_period;
501
502 value = s->maxdata;
503 value *= devpriv->uvolt_amplitude;
504 do_div(value, krange->max - krange->min);
505
506 if (current_time < devpriv->usec_period / 2)
507 value *= -1;
508
509 return offset + value;
510}
511
512static short fake_flatline(struct comedi_device *dev, unsigned int range_index,
513 unsigned long current_time)
514{
515 return dev->read_subdev->maxdata / 2;
516}
517
518/* generates a different waveform depending on what channel is read */
519static short fake_waveform(struct comedi_device *dev, unsigned int channel,
520 unsigned int range, unsigned long current_time)
521{
522 enum {
523 SAWTOOTH_CHAN,
524 SQUARE_CHAN,
525 };
526 switch (channel) {
527 case SAWTOOTH_CHAN:
528 return fake_sawtooth(dev, range, current_time);
529 break;
530 case SQUARE_CHAN:
531 return fake_squarewave(dev, range, current_time);
532 break;
533 default:
534 break;
535 }
536
537 return fake_flatline(dev, range, current_time);
538}
539
540static int waveform_ai_insn_read(struct comedi_device *dev, 405static int waveform_ai_insn_read(struct comedi_device *dev,
541 struct comedi_subdevice *s, 406 struct comedi_subdevice *s,
542 struct comedi_insn *insn, unsigned int *data) 407 struct comedi_insn *insn, unsigned int *data)
@@ -561,6 +426,100 @@ static int waveform_ao_insn_write(struct comedi_device *dev,
561 return insn->n; 426 return insn->n;
562} 427}
563 428
429static int waveform_attach(struct comedi_device *dev,
430 struct comedi_devconfig *it)
431{
432 struct comedi_subdevice *s;
433 int amplitude = it->options[0];
434 int period = it->options[1];
435 int i;
436
437 dev->board_name = thisboard->name;
438
439 if (alloc_private(dev, sizeof(struct waveform_private)) < 0)
440 return -ENOMEM;
441
442 /* set default amplitude and period */
443 if (amplitude <= 0)
444 amplitude = 1000000; /* 1 volt */
445 if (period <= 0)
446 period = 100000; /* 0.1 sec */
447
448 devpriv->uvolt_amplitude = amplitude;
449 devpriv->usec_period = period;
450
451 dev->n_subdevices = 2;
452 if (alloc_subdevices(dev, dev->n_subdevices) < 0)
453 return -ENOMEM;
454
455 s = dev->subdevices + 0;
456 dev->read_subdev = s;
457 /* analog input subdevice */
458 s->type = COMEDI_SUBD_AI;
459 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
460 s->n_chan = thisboard->ai_chans;
461 s->maxdata = (1 << thisboard->ai_bits) - 1;
462 s->range_table = &waveform_ai_ranges;
463 s->len_chanlist = s->n_chan * 2;
464 s->insn_read = waveform_ai_insn_read;
465 s->do_cmd = waveform_ai_cmd;
466 s->do_cmdtest = waveform_ai_cmdtest;
467 s->cancel = waveform_ai_cancel;
468
469 s = dev->subdevices + 1;
470 dev->write_subdev = s;
471 /* analog output subdevice (loopback) */
472 s->type = COMEDI_SUBD_AO;
473 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
474 s->n_chan = thisboard->ai_chans;
475 s->maxdata = (1 << thisboard->ai_bits) - 1;
476 s->range_table = &waveform_ai_ranges;
477 s->len_chanlist = s->n_chan * 2;
478 s->insn_write = waveform_ao_insn_write;
479 s->do_cmd = NULL;
480 s->do_cmdtest = NULL;
481 s->cancel = NULL;
482
483 /* Our default loopback value is just a 0V flatline */
484 for (i = 0; i < s->n_chan; i++)
485 devpriv->ao_loopbacks[i] = s->maxdata / 2;
486
487 init_timer(&(devpriv->timer));
488 devpriv->timer.function = waveform_ai_interrupt;
489 devpriv->timer.data = (unsigned long)dev;
490
491 printk(KERN_INFO "comedi%d: comedi_test: "
492 "%i microvolt, %li microsecond waveform attached\n", dev->minor,
493 devpriv->uvolt_amplitude, devpriv->usec_period);
494 return 1;
495}
496
497static void waveform_detach(struct comedi_device *dev)
498{
499 if (dev->private)
500 waveform_ai_cancel(dev, dev->read_subdev);
501}
502
503static const struct waveform_board waveform_boards[] = {
504 {
505 .name = "comedi_test",
506 .ai_chans = N_CHANS,
507 .ai_bits = 16,
508 .have_dio = 0,
509 },
510};
511
512static struct comedi_driver waveform_driver = {
513 .driver_name = "comedi_test",
514 .module = THIS_MODULE,
515 .attach = waveform_attach,
516 .detach = waveform_detach,
517 .board_name = &waveform_boards[0].name,
518 .offset = sizeof(struct waveform_board),
519 .num_names = ARRAY_SIZE(waveform_boards),
520};
521module_comedi_driver(waveform_driver);
522
564MODULE_AUTHOR("Comedi http://www.comedi.org"); 523MODULE_AUTHOR("Comedi http://www.comedi.org");
565MODULE_DESCRIPTION("Comedi low-level driver"); 524MODULE_DESCRIPTION("Comedi low-level driver");
566MODULE_LICENSE("GPL"); 525MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c
index e3659bd6e85e..b8bac80f2baf 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -56,13 +56,6 @@ static const struct contec_board contec_boards[] = {
56}; 56};
57 57
58#define PCI_DEVICE_ID_PIO1616L 0x8172 58#define PCI_DEVICE_ID_PIO1616L 0x8172
59static DEFINE_PCI_DEVICE_TABLE(contec_pci_table) = {
60 { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L),
61 .driver_data = PIO1616L },
62 {0}
63};
64
65MODULE_DEVICE_TABLE(pci, contec_pci_table);
66 59
67#define thisboard ((const struct contec_board *)dev->board_ptr) 60#define thisboard ((const struct contec_board *)dev->board_ptr)
68 61
@@ -75,30 +68,42 @@ struct contec_private {
75 68
76#define devpriv ((struct contec_private *)dev->private) 69#define devpriv ((struct contec_private *)dev->private)
77 70
78static int contec_attach(struct comedi_device *dev, 71static int contec_do_insn_bits(struct comedi_device *dev,
79 struct comedi_devconfig *it); 72 struct comedi_subdevice *s,
80static int contec_detach(struct comedi_device *dev); 73 struct comedi_insn *insn, unsigned int *data)
81static struct comedi_driver driver_contec = { 74{
82 .driver_name = "contec_pci_dio", 75
83 .module = THIS_MODULE, 76 dev_dbg(dev->hw_dev, "contec_do_insn_bits called\n");
84 .attach = contec_attach, 77 dev_dbg(dev->hw_dev, "data: %d %d\n", data[0], data[1]);
85 .detach = contec_detach, 78
86}; 79 if (insn->n != 2)
80 return -EINVAL;
81
82 if (data[0]) {
83 s->state &= ~data[0];
84 s->state |= data[0] & data[1];
85 dev_dbg(dev->hw_dev, "out: %d on %lx\n", s->state,
86 dev->iobase + thisboard->out_offs);
87 outw(s->state, dev->iobase + thisboard->out_offs);
88 }
89 return 2;
90}
87 91
88/* Classic digital IO */
89static int contec_di_insn_bits(struct comedi_device *dev, 92static int contec_di_insn_bits(struct comedi_device *dev,
90 struct comedi_subdevice *s, 93 struct comedi_subdevice *s,
91 struct comedi_insn *insn, unsigned int *data); 94 struct comedi_insn *insn, unsigned int *data)
92static int contec_do_insn_bits(struct comedi_device *dev, 95{
93 struct comedi_subdevice *s, 96
94 struct comedi_insn *insn, unsigned int *data); 97 dev_dbg(dev->hw_dev, "contec_di_insn_bits called\n");
98 dev_dbg(dev->hw_dev, "data: %d %d\n", data[0], data[1]);
95 99
96#if 0 100 if (insn->n != 2)
97static int contec_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, 101 return -EINVAL;
98 struct comedi_cmd *cmd);
99 102
100static int contec_ns_to_timer(unsigned int *ns, int round); 103 data[1] = inw(dev->iobase + thisboard->in_offs);
101#endif 104
105 return 2;
106}
102 107
103static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it) 108static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
104{ 109{
@@ -164,107 +169,47 @@ static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
164 return -EIO; 169 return -EIO;
165} 170}
166 171
167static int contec_detach(struct comedi_device *dev) 172static void contec_detach(struct comedi_device *dev)
168{ 173{
169 printk("comedi%d: contec: remove\n", dev->minor);
170
171 if (devpriv && devpriv->pci_dev) { 174 if (devpriv && devpriv->pci_dev) {
172 if (dev->iobase) 175 if (dev->iobase)
173 comedi_pci_disable(devpriv->pci_dev); 176 comedi_pci_disable(devpriv->pci_dev);
174 pci_dev_put(devpriv->pci_dev); 177 pci_dev_put(devpriv->pci_dev);
175 } 178 }
176
177 return 0;
178}
179
180#if 0
181static int contec_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
182 struct comedi_cmd *cmd)
183{
184 printk("contec_cmdtest called\n");
185 return 0;
186}
187
188static int contec_ns_to_timer(unsigned int *ns, int round)
189{
190 return *ns;
191}
192#endif
193
194static int contec_do_insn_bits(struct comedi_device *dev,
195 struct comedi_subdevice *s,
196 struct comedi_insn *insn, unsigned int *data)
197{
198
199 dev_dbg(dev->hw_dev, "contec_do_insn_bits called\n");
200 dev_dbg(dev->hw_dev, "data: %d %d\n", data[0], data[1]);
201
202 if (insn->n != 2)
203 return -EINVAL;
204
205 if (data[0]) {
206 s->state &= ~data[0];
207 s->state |= data[0] & data[1];
208 dev_dbg(dev->hw_dev, "out: %d on %lx\n", s->state,
209 dev->iobase + thisboard->out_offs);
210 outw(s->state, dev->iobase + thisboard->out_offs);
211 }
212 return 2;
213} 179}
214 180
215static int contec_di_insn_bits(struct comedi_device *dev, 181static struct comedi_driver contec_pci_dio_driver = {
216 struct comedi_subdevice *s, 182 .driver_name = "contec_pci_dio",
217 struct comedi_insn *insn, unsigned int *data) 183 .module = THIS_MODULE,
218{ 184 .attach = contec_attach,
219 185 .detach = contec_detach,
220 dev_dbg(dev->hw_dev, "contec_di_insn_bits called\n"); 186};
221 dev_dbg(dev->hw_dev, "data: %d %d\n", data[0], data[1]);
222
223 if (insn->n != 2)
224 return -EINVAL;
225
226 data[1] = inw(dev->iobase + thisboard->in_offs);
227
228 return 2;
229}
230 187
231static int __devinit driver_contec_pci_probe(struct pci_dev *dev, 188static int __devinit contec_pci_dio_pci_probe(struct pci_dev *dev,
232 const struct pci_device_id *ent) 189 const struct pci_device_id *ent)
233{ 190{
234 return comedi_pci_auto_config(dev, driver_contec.driver_name); 191 return comedi_pci_auto_config(dev, &contec_pci_dio_driver);
235} 192}
236 193
237static void __devexit driver_contec_pci_remove(struct pci_dev *dev) 194static void __devexit contec_pci_dio_pci_remove(struct pci_dev *dev)
238{ 195{
239 comedi_pci_auto_unconfig(dev); 196 comedi_pci_auto_unconfig(dev);
240} 197}
241 198
242static struct pci_driver driver_contec_pci_driver = { 199static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = {
243 .id_table = contec_pci_table, 200 { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L),
244 .probe = &driver_contec_pci_probe, 201 .driver_data = PIO1616L },
245 .remove = __devexit_p(&driver_contec_pci_remove) 202 { 0 }
246}; 203};
204MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table);
247 205
248static int __init driver_contec_init_module(void) 206static struct pci_driver contec_pci_dio_pci_driver = {
249{ 207 .name = "contec_pci_dio",
250 int retval; 208 .id_table = contec_pci_dio_pci_table,
251 209 .probe = contec_pci_dio_pci_probe,
252 retval = comedi_driver_register(&driver_contec); 210 .remove = __devexit_p(contec_pci_dio_pci_remove),
253 if (retval < 0) 211};
254 return retval; 212module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver);
255
256 driver_contec_pci_driver.name = (char *)driver_contec.driver_name;
257 return pci_register_driver(&driver_contec_pci_driver);
258}
259
260static void __exit driver_contec_cleanup_module(void)
261{
262 pci_unregister_driver(&driver_contec_pci_driver);
263 comedi_driver_unregister(&driver_contec);
264}
265
266module_init(driver_contec_init_module);
267module_exit(driver_contec_cleanup_module);
268 213
269MODULE_AUTHOR("Comedi http://www.comedi.org"); 214MODULE_AUTHOR("Comedi http://www.comedi.org");
270MODULE_DESCRIPTION("Comedi low-level driver"); 215MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index e61c6a8f2857..696b58ca2e59 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -301,17 +301,6 @@ struct daqboard2000_hw {
301#define DAQBOARD2000_PosRefDacSelect 0x0100 301#define DAQBOARD2000_PosRefDacSelect 0x0100
302#define DAQBOARD2000_NegRefDacSelect 0x0000 302#define DAQBOARD2000_NegRefDacSelect 0x0000
303 303
304static int daqboard2000_attach(struct comedi_device *dev,
305 struct comedi_devconfig *it);
306static int daqboard2000_detach(struct comedi_device *dev);
307
308static struct comedi_driver driver_daqboard2000 = {
309 .driver_name = "daqboard2000",
310 .module = THIS_MODULE,
311 .attach = daqboard2000_attach,
312 .detach = daqboard2000_detach,
313};
314
315struct daq200_boardtype { 304struct daq200_boardtype {
316 const char *name; 305 const char *name;
317 int id; 306 int id;
@@ -321,16 +310,8 @@ static const struct daq200_boardtype boardtypes[] = {
321 {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4}, 310 {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4},
322}; 311};
323 312
324#define n_boardtypes (sizeof(boardtypes)/sizeof(struct daq200_boardtype))
325#define this_board ((const struct daq200_boardtype *)dev->board_ptr) 313#define this_board ((const struct daq200_boardtype *)dev->board_ptr)
326 314
327static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
328 { PCI_DEVICE(0x1616, 0x0409) },
329 {0}
330};
331
332MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table);
333
334struct daqboard2000_private { 315struct daqboard2000_private {
335 enum { 316 enum {
336 card_daqboard_2000 317 card_daqboard_2000
@@ -412,9 +393,12 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
412 DAQBOARD2000_AcqResetScanListFifo | 393 DAQBOARD2000_AcqResetScanListFifo |
413 DAQBOARD2000_AcqResetResultsFifo | DAQBOARD2000_AcqResetConfigPipe; 394 DAQBOARD2000_AcqResetResultsFifo | DAQBOARD2000_AcqResetConfigPipe;
414 395
415 /* If pacer clock is not set to some high value (> 10 us), we 396 /*
416 risk multiple samples to be put into the result FIFO. */ 397 * If pacer clock is not set to some high value (> 10 us), we
417 fpga->acqPacerClockDivLow = 1000000; /* 1 second, should be long enough */ 398 * risk multiple samples to be put into the result FIFO.
399 */
400 /* 1 second, should be long enough */
401 fpga->acqPacerClockDivLow = 1000000;
418 fpga->acqPacerClockDivHigh = 0; 402 fpga->acqPacerClockDivHigh = 0;
419 403
420 gain = CR_RANGE(insn->chanspec); 404 gain = CR_RANGE(insn->chanspec);
@@ -761,7 +745,7 @@ static int daqboard2000_attach(struct comedi_device *dev,
761 devpriv->pci_dev = card; 745 devpriv->pci_dev = card;
762 id = ((u32) card-> 746 id = ((u32) card->
763 subsystem_device << 16) | card->subsystem_vendor; 747 subsystem_device << 16) | card->subsystem_vendor;
764 for (i = 0; i < n_boardtypes; i++) { 748 for (i = 0; i < ARRAY_SIZE(boardtypes); i++) {
765 if (boardtypes[i].id == id) { 749 if (boardtypes[i].id == id) {
766 dev_dbg(dev->hw_dev, "%s\n", 750 dev_dbg(dev->hw_dev, "%s\n",
767 boardtypes[i].name); 751 boardtypes[i].name);
@@ -852,14 +836,12 @@ out:
852 return result; 836 return result;
853} 837}
854 838
855static int daqboard2000_detach(struct comedi_device *dev) 839static void daqboard2000_detach(struct comedi_device *dev)
856{ 840{
857 if (dev->subdevices) 841 if (dev->subdevices)
858 subdev_8255_cleanup(dev, dev->subdevices + 2); 842 subdev_8255_cleanup(dev, dev->subdevices + 2);
859
860 if (dev->irq) 843 if (dev->irq)
861 free_irq(dev->irq, dev); 844 free_irq(dev->irq, dev);
862
863 if (devpriv) { 845 if (devpriv) {
864 if (devpriv->daq) 846 if (devpriv->daq)
865 iounmap(devpriv->daq); 847 iounmap(devpriv->daq);
@@ -871,48 +853,39 @@ static int daqboard2000_detach(struct comedi_device *dev)
871 pci_dev_put(devpriv->pci_dev); 853 pci_dev_put(devpriv->pci_dev);
872 } 854 }
873 } 855 }
874 return 0;
875} 856}
876 857
877static int __devinit driver_daqboard2000_pci_probe(struct pci_dev *dev, 858static struct comedi_driver daqboard2000_driver = {
878 const struct pci_device_id 859 .driver_name = "daqboard2000",
879 *ent) 860 .module = THIS_MODULE,
861 .attach = daqboard2000_attach,
862 .detach = daqboard2000_detach,
863};
864
865static int __devinit daqboard2000_pci_probe(struct pci_dev *dev,
866 const struct pci_device_id *ent)
880{ 867{
881 return comedi_pci_auto_config(dev, driver_daqboard2000.driver_name); 868 return comedi_pci_auto_config(dev, &daqboard2000_driver);
882} 869}
883 870
884static void __devexit driver_daqboard2000_pci_remove(struct pci_dev *dev) 871static void __devexit daqboard2000_pci_remove(struct pci_dev *dev)
885{ 872{
886 comedi_pci_auto_unconfig(dev); 873 comedi_pci_auto_unconfig(dev);
887} 874}
888 875
889static struct pci_driver driver_daqboard2000_pci_driver = { 876static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
890 .id_table = daqboard2000_pci_table, 877 { PCI_DEVICE(0x1616, 0x0409) },
891 .probe = &driver_daqboard2000_pci_probe, 878 { 0 }
892 .remove = __devexit_p(&driver_daqboard2000_pci_remove)
893}; 879};
880MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table);
894 881
895static int __init driver_daqboard2000_init_module(void) 882static struct pci_driver daqboard2000_pci_driver = {
896{ 883 .name = "daqboard2000",
897 int retval; 884 .id_table = daqboard2000_pci_table,
898 885 .probe = daqboard2000_pci_probe,
899 retval = comedi_driver_register(&driver_daqboard2000); 886 .remove = __devexit_p(daqboard2000_pci_remove),
900 if (retval < 0) 887};
901 return retval; 888module_comedi_pci_driver(daqboard2000_driver, daqboard2000_pci_driver);
902
903 driver_daqboard2000_pci_driver.name =
904 (char *)driver_daqboard2000.driver_name;
905 return pci_register_driver(&driver_daqboard2000_pci_driver);
906}
907
908static void __exit driver_daqboard2000_cleanup_module(void)
909{
910 pci_unregister_driver(&driver_daqboard2000_pci_driver);
911 comedi_driver_unregister(&driver_daqboard2000);
912}
913
914module_init(driver_daqboard2000_init_module);
915module_exit(driver_daqboard2000_cleanup_module);
916 889
917MODULE_AUTHOR("Comedi http://www.comedi.org"); 890MODULE_AUTHOR("Comedi http://www.comedi.org");
918MODULE_DESCRIPTION("Comedi low-level driver"); 891MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index c2dd0ed36a73..1f319435e23f 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -61,6 +61,20 @@
61 61
62#define DRV_NAME "das08" 62#define DRV_NAME "das08"
63 63
64#ifdef CONFIG_COMEDI_DAS08_ISA_MODULE
65#define CONFIG_COMEDI_DAS08_ISA
66#endif
67#ifdef CONFIG_COMEDI_DAS08_PCI_MODULE
68#define CONFIG_COMEDI_DAS08_PCI
69#endif
70#ifdef CONFIG_COMEDI_DAS08_CS_MODULE
71#define CONFIG_COMEDI_DAS08_CS
72#endif
73
74#if defined(CONFIG_COMEDI_DAS08_ISA) || defined(CONFIG_COMEDI_DAS08_PCI)
75#define DO_COMEDI_DRIVER_REGISTER
76#endif
77
64#define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307 78#define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307
65#define PCI_DEVICE_ID_PCIDAS08 0x29 79#define PCI_DEVICE_ID_PCIDAS08 0x29
66#define PCIDAS08_SIZE 0x54 80#define PCIDAS08_SIZE 0x54
@@ -160,6 +174,7 @@ static int das08_di_rbits(struct comedi_device *dev, struct comedi_subdevice *s,
160 struct comedi_insn *insn, unsigned int *data); 174 struct comedi_insn *insn, unsigned int *data);
161static int das08_do_wbits(struct comedi_device *dev, struct comedi_subdevice *s, 175static int das08_do_wbits(struct comedi_device *dev, struct comedi_subdevice *s,
162 struct comedi_insn *insn, unsigned int *data); 176 struct comedi_insn *insn, unsigned int *data);
177#ifdef CONFIG_COMEDI_DAS08_ISA
163static int das08jr_di_rbits(struct comedi_device *dev, 178static int das08jr_di_rbits(struct comedi_device *dev,
164 struct comedi_subdevice *s, 179 struct comedi_subdevice *s,
165 struct comedi_insn *insn, unsigned int *data); 180 struct comedi_insn *insn, unsigned int *data);
@@ -172,6 +187,7 @@ static int das08jr_ao_winsn(struct comedi_device *dev,
172static int das08ao_ao_winsn(struct comedi_device *dev, 187static int das08ao_ao_winsn(struct comedi_device *dev,
173 struct comedi_subdevice *s, 188 struct comedi_subdevice *s,
174 struct comedi_insn *insn, unsigned int *data); 189 struct comedi_insn *insn, unsigned int *data);
190#endif
175static void i8254_set_mode_low(unsigned int base, int channel, 191static void i8254_set_mode_low(unsigned int base, int channel,
176 unsigned int mode); 192 unsigned int mode);
177 193
@@ -253,7 +269,9 @@ static const int *const das08_gainlists[] = {
253 das08_pgm_gainlist, 269 das08_pgm_gainlist,
254}; 270};
255 271
272#ifdef DO_COMEDI_DRIVER_REGISTER
256static const struct das08_board_struct das08_boards[] = { 273static const struct das08_board_struct das08_boards[] = {
274#ifdef CONFIG_COMEDI_DAS08_ISA
257 { 275 {
258 .name = "isa-das08", /* cio-das08.pdf */ 276 .name = "isa-das08", /* cio-das08.pdf */
259 .bustype = isa, 277 .bustype = isa,
@@ -395,25 +413,6 @@ static const struct das08_board_struct das08_boards[] = {
395 .i8254_offset = 0x04, 413 .i8254_offset = 0x04,
396 .iosize = 16, /* unchecked */ 414 .iosize = 16, /* unchecked */
397 }, 415 },
398#ifdef CONFIG_COMEDI_PCI
399 {
400 .name = "das08", /* pci-das08 */
401 .id = PCI_DEVICE_ID_PCIDAS08,
402 .bustype = pci,
403 .ai = das08_ai_rinsn,
404 .ai_nbits = 12,
405 .ai_pg = das08_bipolar5,
406 .ai_encoding = das08_encode12,
407 .ao = NULL,
408 .ao_nbits = 0,
409 .di = das08_di_rbits,
410 .do_ = das08_do_wbits,
411 .do_nchan = 4,
412 .i8255_offset = 0,
413 .i8254_offset = 4,
414 .iosize = 8,
415 },
416#endif
417 { 416 {
418 .name = "pc104-das08", 417 .name = "pc104-das08",
419 .bustype = pc104, 418 .bustype = pc104,
@@ -462,9 +461,30 @@ static const struct das08_board_struct das08_boards[] = {
462 .name = "das08-pga-g2", /* a KM board */ 461 .name = "das08-pga-g2", /* a KM board */
463 }, 462 },
464#endif 463#endif
464#endif /* CONFIG_COMEDI_DAS08_ISA */
465#ifdef CONFIG_COMEDI_DAS08_PCI
466 {
467 .name = "das08", /* pci-das08 */
468 .id = PCI_DEVICE_ID_PCIDAS08,
469 .bustype = pci,
470 .ai = das08_ai_rinsn,
471 .ai_nbits = 12,
472 .ai_pg = das08_bipolar5,
473 .ai_encoding = das08_encode12,
474 .ao = NULL,
475 .ao_nbits = 0,
476 .di = das08_di_rbits,
477 .do_ = das08_do_wbits,
478 .do_nchan = 4,
479 .i8255_offset = 0,
480 .i8254_offset = 4,
481 .iosize = 8,
482 },
483#endif /* CONFIG_COMEDI_DAS08_PCI */
465}; 484};
485#endif /* DO_COMEDI_DRIVER_REGISTER */
466 486
467#ifdef CONFIG_COMEDI_PCMCIA 487#ifdef CONFIG_COMEDI_DAS08_CS
468struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS] = { 488struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS] = {
469 { 489 {
470 .name = "pcm-das08", 490 .name = "pcm-das08",
@@ -504,7 +524,7 @@ struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS] = {
504}; 524};
505#endif 525#endif
506 526
507#ifdef CONFIG_COMEDI_PCI 527#ifdef CONFIG_COMEDI_DAS08_PCI
508static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = { 528static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = {
509 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, PCI_DEVICE_ID_PCIDAS08) }, 529 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, PCI_DEVICE_ID_PCIDAS08) },
510 {0} 530 {0}
@@ -619,6 +639,7 @@ static int das08_do_wbits(struct comedi_device *dev, struct comedi_subdevice *s,
619 return 2; 639 return 2;
620} 640}
621 641
642#ifdef CONFIG_COMEDI_DAS08_ISA
622static int das08jr_di_rbits(struct comedi_device *dev, 643static int das08jr_di_rbits(struct comedi_device *dev,
623 struct comedi_subdevice *s, 644 struct comedi_subdevice *s,
624 struct comedi_insn *insn, unsigned int *data) 645 struct comedi_insn *insn, unsigned int *data)
@@ -628,7 +649,9 @@ static int das08jr_di_rbits(struct comedi_device *dev,
628 649
629 return 2; 650 return 2;
630} 651}
652#endif
631 653
654#ifdef CONFIG_COMEDI_DAS08_ISA
632static int das08jr_do_wbits(struct comedi_device *dev, 655static int das08jr_do_wbits(struct comedi_device *dev,
633 struct comedi_subdevice *s, 656 struct comedi_subdevice *s,
634 struct comedi_insn *insn, unsigned int *data) 657 struct comedi_insn *insn, unsigned int *data)
@@ -643,7 +666,9 @@ static int das08jr_do_wbits(struct comedi_device *dev,
643 666
644 return 2; 667 return 2;
645} 668}
669#endif
646 670
671#ifdef CONFIG_COMEDI_DAS08_ISA
647static int das08jr_ao_winsn(struct comedi_device *dev, 672static int das08jr_ao_winsn(struct comedi_device *dev,
648 struct comedi_subdevice *s, 673 struct comedi_subdevice *s,
649 struct comedi_insn *insn, unsigned int *data) 674 struct comedi_insn *insn, unsigned int *data)
@@ -672,6 +697,7 @@ static int das08jr_ao_winsn(struct comedi_device *dev,
672 697
673 return n; 698 return n;
674} 699}
700#endif
675 701
676/* 702/*
677 * 703 *
@@ -679,6 +705,7 @@ static int das08jr_ao_winsn(struct comedi_device *dev,
679 * a different method to force an update. 705 * a different method to force an update.
680 * 706 *
681 */ 707 */
708#ifdef CONFIG_COMEDI_DAS08_ISA
682static int das08ao_ao_winsn(struct comedi_device *dev, 709static int das08ao_ao_winsn(struct comedi_device *dev,
683 struct comedi_subdevice *s, 710 struct comedi_subdevice *s,
684 struct comedi_insn *insn, unsigned int *data) 711 struct comedi_insn *insn, unsigned int *data)
@@ -707,6 +734,7 @@ static int das08ao_ao_winsn(struct comedi_device *dev,
707 734
708 return n; 735 return n;
709} 736}
737#endif
710 738
711static unsigned int i8254_read_channel_low(unsigned int base, int chan) 739static unsigned int i8254_read_channel_low(unsigned int base, int chan)
712{ 740{
@@ -842,6 +870,7 @@ static int das08_counter_config(struct comedi_device *dev,
842 return 2; 870 return 2;
843} 871}
844 872
873#ifdef DO_COMEDI_DRIVER_REGISTER
845static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it); 874static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it);
846 875
847static struct comedi_driver driver_das08 = { 876static struct comedi_driver driver_das08 = {
@@ -853,6 +882,7 @@ static struct comedi_driver driver_das08 = {
853 .num_names = sizeof(das08_boards) / sizeof(struct das08_board_struct), 882 .num_names = sizeof(das08_boards) / sizeof(struct das08_board_struct),
854 .offset = sizeof(struct das08_board_struct), 883 .offset = sizeof(struct das08_board_struct),
855}; 884};
885#endif
856 886
857int das08_common_attach(struct comedi_device *dev, unsigned long iobase) 887int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
858{ 888{
@@ -972,11 +1002,12 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
972} 1002}
973EXPORT_SYMBOL_GPL(das08_common_attach); 1003EXPORT_SYMBOL_GPL(das08_common_attach);
974 1004
1005#ifdef DO_COMEDI_DRIVER_REGISTER
975static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1006static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
976{ 1007{
977 int ret; 1008 int ret;
978 unsigned long iobase; 1009 unsigned long iobase;
979#ifdef CONFIG_COMEDI_PCI 1010#ifdef CONFIG_COMEDI_DAS08_PCI
980 unsigned long pci_iobase = 0; 1011 unsigned long pci_iobase = 0;
981 struct pci_dev *pdev = NULL; 1012 struct pci_dev *pdev = NULL;
982#endif 1013#endif
@@ -986,9 +1017,9 @@ static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
986 return ret; 1017 return ret;
987 1018
988 printk(KERN_INFO "comedi%d: das08: ", dev->minor); 1019 printk(KERN_INFO "comedi%d: das08: ", dev->minor);
1020#ifdef CONFIG_COMEDI_DAS08_PCI
989 /* deal with a pci board */ 1021 /* deal with a pci board */
990 if (thisboard->bustype == pci) { 1022 if (thisboard->bustype == pci) {
991#ifdef CONFIG_COMEDI_PCI
992 if (it->options[0] || it->options[1]) { 1023 if (it->options[0] || it->options[1]) {
993 printk("bus %i slot %i ", 1024 printk("bus %i slot %i ",
994 it->options[0], it->options[1]); 1025 it->options[0], it->options[1]);
@@ -1037,32 +1068,26 @@ static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1037 /* Enable local interrupt 1 and pci interrupt */ 1068 /* Enable local interrupt 1 and pci interrupt */
1038 outw(INTR1_ENABLE | PCI_INTR_ENABLE, pci_iobase + INTCSR); 1069 outw(INTR1_ENABLE | PCI_INTR_ENABLE, pci_iobase + INTCSR);
1039#endif 1070#endif
1040#else /* CONFIG_COMEDI_PCI */ 1071 } else
1041 printk(KERN_ERR "this driver has not been built with PCI support.\n"); 1072#endif /* CONFIG_COMEDI_DAS08_PCI */
1042 return -EINVAL; 1073 {
1043#endif /* CONFIG_COMEDI_PCI */
1044 } else {
1045 iobase = it->options[0]; 1074 iobase = it->options[0];
1046 } 1075 }
1047 printk(KERN_INFO "\n"); 1076 printk(KERN_INFO "\n");
1048 1077
1049 return das08_common_attach(dev, iobase); 1078 return das08_common_attach(dev, iobase);
1050} 1079}
1080#endif /* DO_COMEDI_DRIVER_REGISTER */
1051 1081
1052 1082void das08_common_detach(struct comedi_device *dev)
1053int das08_common_detach(struct comedi_device *dev)
1054{ 1083{
1055 printk(KERN_INFO "comedi%d: das08: remove\n", dev->minor);
1056
1057 if (dev->subdevices) 1084 if (dev->subdevices)
1058 subdev_8255_cleanup(dev, dev->subdevices + 4); 1085 subdev_8255_cleanup(dev, dev->subdevices + 4);
1059
1060 /* deallocate ioports for non-pcmcia, non-pci boards */
1061 if ((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) { 1086 if ((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) {
1062 if (dev->iobase) 1087 if (dev->iobase)
1063 release_region(dev->iobase, thisboard->iosize); 1088 release_region(dev->iobase, thisboard->iosize);
1064 } 1089 }
1065#ifdef CONFIG_COMEDI_PCI 1090#ifdef CONFIG_COMEDI_DAS08_PCI
1066 if (devpriv) { 1091 if (devpriv) {
1067 if (devpriv->pdev) { 1092 if (devpriv->pdev) {
1068 if (devpriv->pci_iobase) 1093 if (devpriv->pci_iobase)
@@ -1072,16 +1097,14 @@ int das08_common_detach(struct comedi_device *dev)
1072 } 1097 }
1073 } 1098 }
1074#endif 1099#endif
1075
1076 return 0;
1077} 1100}
1078EXPORT_SYMBOL_GPL(das08_common_detach); 1101EXPORT_SYMBOL_GPL(das08_common_detach);
1079 1102
1080#ifdef CONFIG_COMEDI_PCI 1103#ifdef CONFIG_COMEDI_DAS08_PCI
1081static int __devinit driver_das08_pci_probe(struct pci_dev *dev, 1104static int __devinit driver_das08_pci_probe(struct pci_dev *dev,
1082 const struct pci_device_id *ent) 1105 const struct pci_device_id *ent)
1083{ 1106{
1084 return comedi_pci_auto_config(dev, driver_das08.driver_name); 1107 return comedi_pci_auto_config(dev, &driver_das08);
1085} 1108}
1086 1109
1087static void __devexit driver_das08_pci_remove(struct pci_dev *dev) 1110static void __devexit driver_das08_pci_remove(struct pci_dev *dev)
@@ -1094,43 +1117,38 @@ static struct pci_driver driver_das08_pci_driver = {
1094 .probe = &driver_das08_pci_probe, 1117 .probe = &driver_das08_pci_probe,
1095 .remove = __devexit_p(&driver_das08_pci_remove) 1118 .remove = __devexit_p(&driver_das08_pci_remove)
1096}; 1119};
1120#endif /* CONFIG_COMEDI_DAS08_PCI */
1097 1121
1098static int __init driver_das08_init_module(void) 1122static int __init driver_das08_init_module(void)
1099{ 1123{
1100 int retval; 1124 int retval = 0;
1101 1125
1126#ifdef DO_COMEDI_DRIVER_REGISTER
1102 retval = comedi_driver_register(&driver_das08); 1127 retval = comedi_driver_register(&driver_das08);
1103 if (retval < 0) 1128 if (retval < 0)
1104 return retval; 1129 return retval;
1105 1130#endif
1131#ifdef CONFIG_COMEDI_DAS08_PCI
1106 driver_das08_pci_driver.name = (char *)driver_das08.driver_name; 1132 driver_das08_pci_driver.name = (char *)driver_das08.driver_name;
1107 return pci_register_driver(&driver_das08_pci_driver); 1133 retval = pci_register_driver(&driver_das08_pci_driver);
1134#endif
1135 return retval;
1108} 1136}
1109 1137
1110static void __exit driver_das08_cleanup_module(void) 1138static void __exit driver_das08_cleanup_module(void)
1111{ 1139{
1140#ifdef CONFIG_COMEDI_DAS08_PCI
1112 pci_unregister_driver(&driver_das08_pci_driver); 1141 pci_unregister_driver(&driver_das08_pci_driver);
1142#endif
1143#ifdef DO_COMEDI_DRIVER_REGISTER
1113 comedi_driver_unregister(&driver_das08); 1144 comedi_driver_unregister(&driver_das08);
1145#endif
1114} 1146}
1115 1147
1116module_init(driver_das08_init_module); 1148module_init(driver_das08_init_module);
1117module_exit(driver_das08_cleanup_module); 1149module_exit(driver_das08_cleanup_module);
1118#else
1119static int __init driver_das08_init_module(void)
1120{
1121 return comedi_driver_register(&driver_das08);
1122}
1123
1124static void __exit driver_das08_cleanup_module(void)
1125{
1126 comedi_driver_unregister(&driver_das08);
1127}
1128
1129module_init(driver_das08_init_module);
1130module_exit(driver_das08_cleanup_module);
1131#endif
1132 1150
1133#ifdef CONFIG_COMEDI_PCMCIA 1151#ifdef CONFIG_COMEDI_DAS08_CS
1134EXPORT_SYMBOL_GPL(das08_cs_boards); 1152EXPORT_SYMBOL_GPL(das08_cs_boards);
1135#endif 1153#endif
1136 1154
diff --git a/drivers/staging/comedi/drivers/das08.h b/drivers/staging/comedi/drivers/das08.h
index 2a30d764ddfc..0b92f24b261f 100644
--- a/drivers/staging/comedi/drivers/das08.h
+++ b/drivers/staging/comedi/drivers/das08.h
@@ -74,6 +74,6 @@ struct das08_private_struct {
74extern struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS]; 74extern struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS];
75 75
76int das08_common_attach(struct comedi_device *dev, unsigned long iobase); 76int das08_common_attach(struct comedi_device *dev, unsigned long iobase);
77int das08_common_detach(struct comedi_device *dev); 77void das08_common_detach(struct comedi_device *dev);
78 78
79#endif /* _DAS08_H */ 79#endif /* _DAS08_H */
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index e7905bac92da..998444c1ba32 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -339,38 +339,6 @@ struct munge_info {
339 unsigned have_byte:1; 339 unsigned have_byte:1;
340}; 340};
341 341
342static int das16_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
343 struct comedi_insn *insn, unsigned int *data);
344static int das16_do_wbits(struct comedi_device *dev, struct comedi_subdevice *s,
345 struct comedi_insn *insn, unsigned int *data);
346static int das16_di_rbits(struct comedi_device *dev, struct comedi_subdevice *s,
347 struct comedi_insn *insn, unsigned int *data);
348static int das16_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
349 struct comedi_insn *insn, unsigned int *data);
350
351static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
352 struct comedi_cmd *cmd);
353static int das16_cmd_exec(struct comedi_device *dev,
354 struct comedi_subdevice *s);
355static int das16_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
356static void das16_ai_munge(struct comedi_device *dev,
357 struct comedi_subdevice *s, void *array,
358 unsigned int num_bytes,
359 unsigned int start_chan_index);
360
361static void das16_reset(struct comedi_device *dev);
362static irqreturn_t das16_dma_interrupt(int irq, void *d);
363static void das16_timer_interrupt(unsigned long arg);
364static void das16_interrupt(struct comedi_device *dev);
365
366static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
367 int flags);
368static int das1600_mode_detect(struct comedi_device *dev);
369static unsigned int das16_suggest_transfer_size(struct comedi_device *dev,
370 struct comedi_cmd cmd);
371
372static void reg_dump(struct comedi_device *dev);
373
374struct das16_board { 342struct das16_board {
375 const char *name; 343 const char *name;
376 void *ai; 344 void *ai;
@@ -389,344 +357,6 @@ struct das16_board {
389 unsigned int id; 357 unsigned int id;
390}; 358};
391 359
392static const struct das16_board das16_boards[] = {
393 {
394 .name = "das-16",
395 .ai = das16_ai_rinsn,
396 .ai_nbits = 12,
397 .ai_speed = 15000,
398 .ai_pg = das16_pg_none,
399 .ao = das16_ao_winsn,
400 .ao_nbits = 12,
401 .di = das16_di_rbits,
402 .do_ = das16_do_wbits,
403 .i8255_offset = 0x10,
404 .i8254_offset = 0x0c,
405 .size = 0x14,
406 .id = 0x00,
407 },
408 {
409 .name = "das-16g",
410 .ai = das16_ai_rinsn,
411 .ai_nbits = 12,
412 .ai_speed = 15000,
413 .ai_pg = das16_pg_none,
414 .ao = das16_ao_winsn,
415 .ao_nbits = 12,
416 .di = das16_di_rbits,
417 .do_ = das16_do_wbits,
418 .i8255_offset = 0x10,
419 .i8254_offset = 0x0c,
420 .size = 0x14,
421 .id = 0x00,
422 },
423 {
424 .name = "das-16f",
425 .ai = das16_ai_rinsn,
426 .ai_nbits = 12,
427 .ai_speed = 8500,
428 .ai_pg = das16_pg_none,
429 .ao = das16_ao_winsn,
430 .ao_nbits = 12,
431 .di = das16_di_rbits,
432 .do_ = das16_do_wbits,
433 .i8255_offset = 0x10,
434 .i8254_offset = 0x0c,
435 .size = 0x14,
436 .id = 0x00,
437 },
438 {
439 .name = "cio-das16", /* cio-das16.pdf */
440 .ai = das16_ai_rinsn,
441 .ai_nbits = 12,
442 .ai_speed = 20000,
443 .ai_pg = das16_pg_none,
444 .ao = das16_ao_winsn,
445 .ao_nbits = 12,
446 .di = das16_di_rbits,
447 .do_ = das16_do_wbits,
448 .i8255_offset = 0x10,
449 .i8254_offset = 0x0c,
450 .size = 0x14,
451 .id = 0x80,
452 },
453 {
454 .name = "cio-das16/f", /* das16.pdf */
455 .ai = das16_ai_rinsn,
456 .ai_nbits = 12,
457 .ai_speed = 10000,
458 .ai_pg = das16_pg_none,
459 .ao = das16_ao_winsn,
460 .ao_nbits = 12,
461 .di = das16_di_rbits,
462 .do_ = das16_do_wbits,
463 .i8255_offset = 0x10,
464 .i8254_offset = 0x0c,
465 .size = 0x14,
466 .id = 0x80,
467 },
468 {
469 .name = "cio-das16/jr", /* cio-das16jr.pdf */
470 .ai = das16_ai_rinsn,
471 .ai_nbits = 12,
472 .ai_speed = 7692,
473 .ai_pg = das16_pg_16jr,
474 .ao = NULL,
475 .di = das16_di_rbits,
476 .do_ = das16_do_wbits,
477 .i8255_offset = 0,
478 .i8254_offset = 0x0c,
479 .size = 0x10,
480 .id = 0x00,
481 },
482 {
483 .name = "pc104-das16jr", /* pc104-das16jr_xx.pdf */
484 .ai = das16_ai_rinsn,
485 .ai_nbits = 12,
486 .ai_speed = 3300,
487 .ai_pg = das16_pg_16jr,
488 .ao = NULL,
489 .di = das16_di_rbits,
490 .do_ = das16_do_wbits,
491 .i8255_offset = 0,
492 .i8254_offset = 0x0c,
493 .size = 0x10,
494 .id = 0x00,
495 },
496 {
497 .name = "cio-das16jr/16", /* cio-das16jr_16.pdf */
498 .ai = das16_ai_rinsn,
499 .ai_nbits = 16,
500 .ai_speed = 10000,
501 .ai_pg = das16_pg_16jr_16,
502 .ao = NULL,
503 .di = das16_di_rbits,
504 .do_ = das16_do_wbits,
505 .i8255_offset = 0,
506 .i8254_offset = 0x0c,
507 .size = 0x10,
508 .id = 0x00,
509 },
510 {
511 .name = "pc104-das16jr/16", /* pc104-das16jr_xx.pdf */
512 .ai = das16_ai_rinsn,
513 .ai_nbits = 16,
514 .ai_speed = 10000,
515 .ai_pg = das16_pg_16jr_16,
516 .ao = NULL,
517 .di = das16_di_rbits,
518 .do_ = das16_do_wbits,
519 .i8255_offset = 0,
520 .i8254_offset = 0x0c,
521 .size = 0x10,
522 .id = 0x00,
523 },
524 {
525 .name = "das-1201", /* 4924.pdf (keithley user's manual) */
526 .ai = das16_ai_rinsn,
527 .ai_nbits = 12,
528 .ai_speed = 20000,
529 .ai_pg = das16_pg_none,
530 .ao = NULL,
531 .di = das16_di_rbits,
532 .do_ = das16_do_wbits,
533 .i8255_offset = 0x400,
534 .i8254_offset = 0x0c,
535 .size = 0x408,
536 .id = 0x20,
537 },
538 {
539 .name = "das-1202", /* 4924.pdf (keithley user's manual) */
540 .ai = das16_ai_rinsn,
541 .ai_nbits = 12,
542 .ai_speed = 10000,
543 .ai_pg = das16_pg_none,
544 .ao = NULL,
545 .di = das16_di_rbits,
546 .do_ = das16_do_wbits,
547 .i8255_offset = 0x400,
548 .i8254_offset = 0x0c,
549 .size = 0x408,
550 .id = 0x20,
551 },
552 {
553 /* 4919.pdf and 4922.pdf (keithley user's manual) */
554 .name = "das-1401",
555 .ai = das16_ai_rinsn,
556 .ai_nbits = 12,
557 .ai_speed = 10000,
558 .ai_pg = das16_pg_1601,
559 .ao = NULL,
560 .di = das16_di_rbits,
561 .do_ = das16_do_wbits,
562 .i8255_offset = 0x0,
563 .i8254_offset = 0x0c,
564 .size = 0x408,
565 .id = 0xc0 /* 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 */
566 },
567 {
568 /* 4919.pdf and 4922.pdf (keithley user's manual) */
569 .name = "das-1402",
570 .ai = das16_ai_rinsn,
571 .ai_nbits = 12,
572 .ai_speed = 10000,
573 .ai_pg = das16_pg_1602,
574 .ao = NULL,
575 .di = das16_di_rbits,
576 .do_ = das16_do_wbits,
577 .i8255_offset = 0x0,
578 .i8254_offset = 0x0c,
579 .size = 0x408,
580 .id = 0xc0 /* 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 */
581 },
582 {
583 .name = "das-1601", /* 4919.pdf */
584 .ai = das16_ai_rinsn,
585 .ai_nbits = 12,
586 .ai_speed = 10000,
587 .ai_pg = das16_pg_1601,
588 .ao = das16_ao_winsn,
589 .ao_nbits = 12,
590 .di = das16_di_rbits,
591 .do_ = das16_do_wbits,
592 .i8255_offset = 0x400,
593 .i8254_offset = 0x0c,
594 .size = 0x408,
595 .id = 0xc0},
596 {
597 .name = "das-1602", /* 4919.pdf */
598 .ai = das16_ai_rinsn,
599 .ai_nbits = 12,
600 .ai_speed = 10000,
601 .ai_pg = das16_pg_1602,
602 .ao = das16_ao_winsn,
603 .ao_nbits = 12,
604 .di = das16_di_rbits,
605 .do_ = das16_do_wbits,
606 .i8255_offset = 0x400,
607 .i8254_offset = 0x0c,
608 .size = 0x408,
609 .id = 0xc0},
610 {
611 .name = "cio-das1401/12", /* cio-das1400_series.pdf */
612 .ai = das16_ai_rinsn,
613 .ai_nbits = 12,
614 .ai_speed = 6250,
615 .ai_pg = das16_pg_1601,
616 .ao = NULL,
617 .di = das16_di_rbits,
618 .do_ = das16_do_wbits,
619 .i8255_offset = 0,
620 .i8254_offset = 0x0c,
621 .size = 0x408,
622 .id = 0xc0},
623 {
624 .name = "cio-das1402/12", /* cio-das1400_series.pdf */
625 .ai = das16_ai_rinsn,
626 .ai_nbits = 12,
627 .ai_speed = 6250,
628 .ai_pg = das16_pg_1602,
629 .ao = NULL,
630 .di = das16_di_rbits,
631 .do_ = das16_do_wbits,
632 .i8255_offset = 0,
633 .i8254_offset = 0x0c,
634 .size = 0x408,
635 .id = 0xc0},
636 {
637 .name = "cio-das1402/16", /* cio-das1400_series.pdf */
638 .ai = das16_ai_rinsn,
639 .ai_nbits = 16,
640 .ai_speed = 10000,
641 .ai_pg = das16_pg_1602,
642 .ao = NULL,
643 .di = das16_di_rbits,
644 .do_ = das16_do_wbits,
645 .i8255_offset = 0,
646 .i8254_offset = 0x0c,
647 .size = 0x408,
648 .id = 0xc0},
649 {
650 .name = "cio-das1601/12", /* cio-das160x-1x.pdf */
651 .ai = das16_ai_rinsn,
652 .ai_nbits = 12,
653 .ai_speed = 6250,
654 .ai_pg = das16_pg_1601,
655 .ao = das16_ao_winsn,
656 .ao_nbits = 12,
657 .di = das16_di_rbits,
658 .do_ = das16_do_wbits,
659 .i8255_offset = 0x400,
660 .i8254_offset = 0x0c,
661 .size = 0x408,
662 .id = 0xc0},
663 {
664 .name = "cio-das1602/12", /* cio-das160x-1x.pdf */
665 .ai = das16_ai_rinsn,
666 .ai_nbits = 12,
667 .ai_speed = 10000,
668 .ai_pg = das16_pg_1602,
669 .ao = das16_ao_winsn,
670 .ao_nbits = 12,
671 .di = das16_di_rbits,
672 .do_ = das16_do_wbits,
673 .i8255_offset = 0x400,
674 .i8254_offset = 0x0c,
675 .size = 0x408,
676 .id = 0xc0},
677 {
678 .name = "cio-das1602/16", /* cio-das160x-1x.pdf */
679 .ai = das16_ai_rinsn,
680 .ai_nbits = 16,
681 .ai_speed = 10000,
682 .ai_pg = das16_pg_1602,
683 .ao = das16_ao_winsn,
684 .ao_nbits = 12,
685 .di = das16_di_rbits,
686 .do_ = das16_do_wbits,
687 .i8255_offset = 0x400,
688 .i8254_offset = 0x0c,
689 .size = 0x408,
690 .id = 0xc0},
691 {
692 .name = "cio-das16/330", /* ? */
693 .ai = das16_ai_rinsn,
694 .ai_nbits = 12,
695 .ai_speed = 3030,
696 .ai_pg = das16_pg_16jr,
697 .ao = NULL,
698 .di = das16_di_rbits,
699 .do_ = das16_do_wbits,
700 .i8255_offset = 0,
701 .i8254_offset = 0x0c,
702 .size = 0x14,
703 .id = 0xf0},
704#if 0
705 {
706 .name = "das16/330i", /* ? */
707 },
708 {
709 .name = "das16/jr/ctr5", /* ? */
710 },
711 {
712 /* cio-das16_m1_16.pdf, this board is a bit quirky, no dma */
713 .name = "cio-das16/m1/16",
714 },
715#endif
716};
717
718static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it);
719static int das16_detach(struct comedi_device *dev);
720static struct comedi_driver driver_das16 = {
721 .driver_name = "das16",
722 .module = THIS_MODULE,
723 .attach = das16_attach,
724 .detach = das16_detach,
725 .board_name = &das16_boards[0].name,
726 .num_names = ARRAY_SIZE(das16_boards),
727 .offset = sizeof(das16_boards[0]),
728};
729
730#define DAS16_TIMEOUT 1000 360#define DAS16_TIMEOUT 1000
731 361
732/* Period for timer interrupt in jiffies. It's a function 362/* Period for timer interrupt in jiffies. It's a function
@@ -926,6 +556,62 @@ static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
926 return 0; 556 return 0;
927} 557}
928 558
559/* utility function that suggests a dma transfer size in bytes */
560static unsigned int das16_suggest_transfer_size(struct comedi_device *dev,
561 struct comedi_cmd cmd)
562{
563 unsigned int size;
564 unsigned int freq;
565
566 /* if we are using timer interrupt, we don't care how long it
567 * will take to complete transfer since it will be interrupted
568 * by timer interrupt */
569 if (devpriv->timer_mode)
570 return DAS16_DMA_SIZE;
571
572 /* otherwise, we are relying on dma terminal count interrupt,
573 * so pick a reasonable size */
574 if (cmd.convert_src == TRIG_TIMER)
575 freq = 1000000000 / cmd.convert_arg;
576 else if (cmd.scan_begin_src == TRIG_TIMER)
577 freq = (1000000000 / cmd.scan_begin_arg) * cmd.chanlist_len;
578 /* return some default value */
579 else
580 freq = 0xffffffff;
581
582 if (cmd.flags & TRIG_WAKE_EOS) {
583 size = sample_size * cmd.chanlist_len;
584 } else {
585 /* make buffer fill in no more than 1/3 second */
586 size = (freq / 3) * sample_size;
587 }
588
589 /* set a minimum and maximum size allowed */
590 if (size > DAS16_DMA_SIZE)
591 size = DAS16_DMA_SIZE - DAS16_DMA_SIZE % sample_size;
592 else if (size < sample_size)
593 size = sample_size;
594
595 if (cmd.stop_src == TRIG_COUNT && size > devpriv->adc_byte_count)
596 size = devpriv->adc_byte_count;
597
598 return size;
599}
600
601static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
602 int rounding_flags)
603{
604 i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1),
605 &(devpriv->divisor2), &ns,
606 rounding_flags & TRIG_ROUND_MASK);
607
608 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
609 i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 1, devpriv->divisor1, 2);
610 i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 2, devpriv->divisor2, 2);
611
612 return ns;
613}
614
929static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s) 615static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
930{ 616{
931 struct comedi_async *async = s->async; 617 struct comedi_async *async = s->async;
@@ -1170,34 +856,6 @@ static int das16_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
1170 return i; 856 return i;
1171} 857}
1172 858
1173static irqreturn_t das16_dma_interrupt(int irq, void *d)
1174{
1175 int status;
1176 struct comedi_device *dev = d;
1177
1178 status = inb(dev->iobase + DAS16_STATUS);
1179
1180 if ((status & DAS16_INT) == 0) {
1181 DEBUG_PRINT("spurious interrupt\n");
1182 return IRQ_NONE;
1183 }
1184
1185 /* clear interrupt */
1186 outb(0x00, dev->iobase + DAS16_STATUS);
1187 das16_interrupt(dev);
1188 return IRQ_HANDLED;
1189}
1190
1191static void das16_timer_interrupt(unsigned long arg)
1192{
1193 struct comedi_device *dev = (struct comedi_device *)arg;
1194
1195 das16_interrupt(dev);
1196
1197 if (devpriv->timer_running)
1198 mod_timer(&devpriv->timer, jiffies + timer_period());
1199}
1200
1201/* the pc104-das16jr (at least) has problems if the dma 859/* the pc104-das16jr (at least) has problems if the dma
1202 transfer is interrupted in the middle of transferring 860 transfer is interrupted in the middle of transferring
1203 a 16 bit sample, so this function takes care to get 861 a 16 bit sample, so this function takes care to get
@@ -1309,18 +967,32 @@ static void das16_interrupt(struct comedi_device *dev)
1309 cfc_handle_events(dev, s); 967 cfc_handle_events(dev, s);
1310} 968}
1311 969
1312static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns, 970static irqreturn_t das16_dma_interrupt(int irq, void *d)
1313 int rounding_flags)
1314{ 971{
1315 i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1), 972 int status;
1316 &(devpriv->divisor2), &ns, 973 struct comedi_device *dev = d;
1317 rounding_flags & TRIG_ROUND_MASK);
1318 974
1319 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */ 975 status = inb(dev->iobase + DAS16_STATUS);
1320 i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 1, devpriv->divisor1, 2);
1321 i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 2, devpriv->divisor2, 2);
1322 976
1323 return ns; 977 if ((status & DAS16_INT) == 0) {
978 DEBUG_PRINT("spurious interrupt\n");
979 return IRQ_NONE;
980 }
981
982 /* clear interrupt */
983 outb(0x00, dev->iobase + DAS16_STATUS);
984 das16_interrupt(dev);
985 return IRQ_HANDLED;
986}
987
988static void das16_timer_interrupt(unsigned long arg)
989{
990 struct comedi_device *dev = (struct comedi_device *)arg;
991
992 das16_interrupt(dev);
993
994 if (devpriv->timer_running)
995 mod_timer(&devpriv->timer, jiffies + timer_period());
1324} 996}
1325 997
1326static void reg_dump(struct comedi_device *dev) 998static void reg_dump(struct comedi_device *dev)
@@ -1394,6 +1066,22 @@ static int das1600_mode_detect(struct comedi_device *dev)
1394 return 0; 1066 return 0;
1395} 1067}
1396 1068
1069static void das16_ai_munge(struct comedi_device *dev,
1070 struct comedi_subdevice *s, void *array,
1071 unsigned int num_bytes,
1072 unsigned int start_chan_index)
1073{
1074 unsigned int i, num_samples = num_bytes / sizeof(short);
1075 short *data = array;
1076
1077 for (i = 0; i < num_samples; i++) {
1078 data[i] = le16_to_cpu(data[i]);
1079 if (thisboard->ai_nbits == 12)
1080 data[i] = (data[i] >> 4) & 0xfff;
1081
1082 }
1083}
1084
1397/* 1085/*
1398 * 1086 *
1399 * Options list: 1087 * Options list:
@@ -1402,7 +1090,6 @@ static int das1600_mode_detect(struct comedi_device *dev)
1402 * 2 DMA 1090 * 2 DMA
1403 * 3 Clock speed (in MHz) 1091 * 3 Clock speed (in MHz)
1404 */ 1092 */
1405
1406static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1093static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1407{ 1094{
1408 struct comedi_subdevice *s; 1095 struct comedi_subdevice *s;
@@ -1675,15 +1362,11 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1675 return 0; 1362 return 0;
1676} 1363}
1677 1364
1678static int das16_detach(struct comedi_device *dev) 1365static void das16_detach(struct comedi_device *dev)
1679{ 1366{
1680 printk(KERN_INFO "comedi%d: das16: remove\n", dev->minor);
1681
1682 das16_reset(dev); 1367 das16_reset(dev);
1683
1684 if (dev->subdevices) 1368 if (dev->subdevices)
1685 subdev_8255_cleanup(dev, dev->subdevices + 4); 1369 subdev_8255_cleanup(dev, dev->subdevices + 4);
1686
1687 if (devpriv) { 1370 if (devpriv) {
1688 int i; 1371 int i;
1689 for (i = 0; i < 2; i++) { 1372 for (i = 0; i < 2; i++) {
@@ -1698,10 +1381,8 @@ static int das16_detach(struct comedi_device *dev)
1698 kfree(devpriv->user_ai_range_table); 1381 kfree(devpriv->user_ai_range_table);
1699 kfree(devpriv->user_ao_range_table); 1382 kfree(devpriv->user_ao_range_table);
1700 } 1383 }
1701
1702 if (dev->irq) 1384 if (dev->irq)
1703 free_irq(dev->irq, dev); 1385 free_irq(dev->irq, dev);
1704
1705 if (dev->iobase) { 1386 if (dev->iobase) {
1706 if (thisboard->size < 0x400) { 1387 if (thisboard->size < 0x400) {
1707 release_region(dev->iobase, thisboard->size); 1388 release_region(dev->iobase, thisboard->size);
@@ -1711,80 +1392,318 @@ static int das16_detach(struct comedi_device *dev)
1711 thisboard->size & 0x3ff); 1392 thisboard->size & 0x3ff);
1712 } 1393 }
1713 } 1394 }
1714
1715 return 0;
1716} 1395}
1717 1396
1718static int __init driver_das16_init_module(void) 1397static const struct das16_board das16_boards[] = {
1719{ 1398 {
1720 return comedi_driver_register(&driver_das16); 1399 .name = "das-16",
1721} 1400 .ai = das16_ai_rinsn,
1722 1401 .ai_nbits = 12,
1723static void __exit driver_das16_cleanup_module(void) 1402 .ai_speed = 15000,
1724{ 1403 .ai_pg = das16_pg_none,
1725 comedi_driver_unregister(&driver_das16); 1404 .ao = das16_ao_winsn,
1726} 1405 .ao_nbits = 12,
1727 1406 .di = das16_di_rbits,
1728module_init(driver_das16_init_module); 1407 .do_ = das16_do_wbits,
1729module_exit(driver_das16_cleanup_module); 1408 .i8255_offset = 0x10,
1730 1409 .i8254_offset = 0x0c,
1731/* utility function that suggests a dma transfer size in bytes */ 1410 .size = 0x14,
1732static unsigned int das16_suggest_transfer_size(struct comedi_device *dev, 1411 .id = 0x00,
1733 struct comedi_cmd cmd) 1412 }, {
1734{ 1413 .name = "das-16g",
1735 unsigned int size; 1414 .ai = das16_ai_rinsn,
1736 unsigned int freq; 1415 .ai_nbits = 12,
1737 1416 .ai_speed = 15000,
1738 /* if we are using timer interrupt, we don't care how long it 1417 .ai_pg = das16_pg_none,
1739 * will take to complete transfer since it will be interrupted 1418 .ao = das16_ao_winsn,
1740 * by timer interrupt */ 1419 .ao_nbits = 12,
1741 if (devpriv->timer_mode) 1420 .di = das16_di_rbits,
1742 return DAS16_DMA_SIZE; 1421 .do_ = das16_do_wbits,
1743 1422 .i8255_offset = 0x10,
1744 /* otherwise, we are relying on dma terminal count interrupt, 1423 .i8254_offset = 0x0c,
1745 * so pick a reasonable size */ 1424 .size = 0x14,
1746 if (cmd.convert_src == TRIG_TIMER) 1425 .id = 0x00,
1747 freq = 1000000000 / cmd.convert_arg; 1426 }, {
1748 else if (cmd.scan_begin_src == TRIG_TIMER) 1427 .name = "das-16f",
1749 freq = (1000000000 / cmd.scan_begin_arg) * cmd.chanlist_len; 1428 .ai = das16_ai_rinsn,
1750 /* return some default value */ 1429 .ai_nbits = 12,
1751 else 1430 .ai_speed = 8500,
1752 freq = 0xffffffff; 1431 .ai_pg = das16_pg_none,
1753 1432 .ao = das16_ao_winsn,
1754 if (cmd.flags & TRIG_WAKE_EOS) { 1433 .ao_nbits = 12,
1755 size = sample_size * cmd.chanlist_len; 1434 .di = das16_di_rbits,
1756 } else { 1435 .do_ = das16_do_wbits,
1757 /* make buffer fill in no more than 1/3 second */ 1436 .i8255_offset = 0x10,
1758 size = (freq / 3) * sample_size; 1437 .i8254_offset = 0x0c,
1759 } 1438 .size = 0x14,
1760 1439 .id = 0x00,
1761 /* set a minimum and maximum size allowed */ 1440 }, {
1762 if (size > DAS16_DMA_SIZE) 1441 .name = "cio-das16",
1763 size = DAS16_DMA_SIZE - DAS16_DMA_SIZE % sample_size; 1442 .ai = das16_ai_rinsn,
1764 else if (size < sample_size) 1443 .ai_nbits = 12,
1765 size = sample_size; 1444 .ai_speed = 20000,
1766 1445 .ai_pg = das16_pg_none,
1767 if (cmd.stop_src == TRIG_COUNT && size > devpriv->adc_byte_count) 1446 .ao = das16_ao_winsn,
1768 size = devpriv->adc_byte_count; 1447 .ao_nbits = 12,
1769 1448 .di = das16_di_rbits,
1770 return size; 1449 .do_ = das16_do_wbits,
1771} 1450 .i8255_offset = 0x10,
1772 1451 .i8254_offset = 0x0c,
1773static void das16_ai_munge(struct comedi_device *dev, 1452 .size = 0x14,
1774 struct comedi_subdevice *s, void *array, 1453 .id = 0x80,
1775 unsigned int num_bytes, 1454 }, {
1776 unsigned int start_chan_index) 1455 .name = "cio-das16/f",
1777{ 1456 .ai = das16_ai_rinsn,
1778 unsigned int i, num_samples = num_bytes / sizeof(short); 1457 .ai_nbits = 12,
1779 short *data = array; 1458 .ai_speed = 10000,
1780 1459 .ai_pg = das16_pg_none,
1781 for (i = 0; i < num_samples; i++) { 1460 .ao = das16_ao_winsn,
1782 data[i] = le16_to_cpu(data[i]); 1461 .ao_nbits = 12,
1783 if (thisboard->ai_nbits == 12) 1462 .di = das16_di_rbits,
1784 data[i] = (data[i] >> 4) & 0xfff; 1463 .do_ = das16_do_wbits,
1464 .i8255_offset = 0x10,
1465 .i8254_offset = 0x0c,
1466 .size = 0x14,
1467 .id = 0x80,
1468 }, {
1469 .name = "cio-das16/jr",
1470 .ai = das16_ai_rinsn,
1471 .ai_nbits = 12,
1472 .ai_speed = 7692,
1473 .ai_pg = das16_pg_16jr,
1474 .ao = NULL,
1475 .di = das16_di_rbits,
1476 .do_ = das16_do_wbits,
1477 .i8255_offset = 0,
1478 .i8254_offset = 0x0c,
1479 .size = 0x10,
1480 .id = 0x00,
1481 }, {
1482 .name = "pc104-das16jr",
1483 .ai = das16_ai_rinsn,
1484 .ai_nbits = 12,
1485 .ai_speed = 3300,
1486 .ai_pg = das16_pg_16jr,
1487 .ao = NULL,
1488 .di = das16_di_rbits,
1489 .do_ = das16_do_wbits,
1490 .i8255_offset = 0,
1491 .i8254_offset = 0x0c,
1492 .size = 0x10,
1493 .id = 0x00,
1494 }, {
1495 .name = "cio-das16jr/16",
1496 .ai = das16_ai_rinsn,
1497 .ai_nbits = 16,
1498 .ai_speed = 10000,
1499 .ai_pg = das16_pg_16jr_16,
1500 .ao = NULL,
1501 .di = das16_di_rbits,
1502 .do_ = das16_do_wbits,
1503 .i8255_offset = 0,
1504 .i8254_offset = 0x0c,
1505 .size = 0x10,
1506 .id = 0x00,
1507 }, {
1508 .name = "pc104-das16jr/16",
1509 .ai = das16_ai_rinsn,
1510 .ai_nbits = 16,
1511 .ai_speed = 10000,
1512 .ai_pg = das16_pg_16jr_16,
1513 .ao = NULL,
1514 .di = das16_di_rbits,
1515 .do_ = das16_do_wbits,
1516 .i8255_offset = 0,
1517 .i8254_offset = 0x0c,
1518 .size = 0x10,
1519 .id = 0x00,
1520 }, {
1521 .name = "das-1201",
1522 .ai = das16_ai_rinsn,
1523 .ai_nbits = 12,
1524 .ai_speed = 20000,
1525 .ai_pg = das16_pg_none,
1526 .ao = NULL,
1527 .di = das16_di_rbits,
1528 .do_ = das16_do_wbits,
1529 .i8255_offset = 0x400,
1530 .i8254_offset = 0x0c,
1531 .size = 0x408,
1532 .id = 0x20,
1533 }, {
1534 .name = "das-1202",
1535 .ai = das16_ai_rinsn,
1536 .ai_nbits = 12,
1537 .ai_speed = 10000,
1538 .ai_pg = das16_pg_none,
1539 .ao = NULL,
1540 .di = das16_di_rbits,
1541 .do_ = das16_do_wbits,
1542 .i8255_offset = 0x400,
1543 .i8254_offset = 0x0c,
1544 .size = 0x408,
1545 .id = 0x20,
1546 }, {
1547 .name = "das-1401",
1548 .ai = das16_ai_rinsn,
1549 .ai_nbits = 12,
1550 .ai_speed = 10000,
1551 .ai_pg = das16_pg_1601,
1552 .ao = NULL,
1553 .di = das16_di_rbits,
1554 .do_ = das16_do_wbits,
1555 .i8255_offset = 0x0,
1556 .i8254_offset = 0x0c,
1557 .size = 0x408,
1558 .id = 0xc0,
1559 }, {
1560 .name = "das-1402",
1561 .ai = das16_ai_rinsn,
1562 .ai_nbits = 12,
1563 .ai_speed = 10000,
1564 .ai_pg = das16_pg_1602,
1565 .ao = NULL,
1566 .di = das16_di_rbits,
1567 .do_ = das16_do_wbits,
1568 .i8255_offset = 0x0,
1569 .i8254_offset = 0x0c,
1570 .size = 0x408,
1571 .id = 0xc0,
1572 }, {
1573 .name = "das-1601",
1574 .ai = das16_ai_rinsn,
1575 .ai_nbits = 12,
1576 .ai_speed = 10000,
1577 .ai_pg = das16_pg_1601,
1578 .ao = das16_ao_winsn,
1579 .ao_nbits = 12,
1580 .di = das16_di_rbits,
1581 .do_ = das16_do_wbits,
1582 .i8255_offset = 0x400,
1583 .i8254_offset = 0x0c,
1584 .size = 0x408,
1585 .id = 0xc0,
1586 }, {
1587 .name = "das-1602",
1588 .ai = das16_ai_rinsn,
1589 .ai_nbits = 12,
1590 .ai_speed = 10000,
1591 .ai_pg = das16_pg_1602,
1592 .ao = das16_ao_winsn,
1593 .ao_nbits = 12,
1594 .di = das16_di_rbits,
1595 .do_ = das16_do_wbits,
1596 .i8255_offset = 0x400,
1597 .i8254_offset = 0x0c,
1598 .size = 0x408,
1599 .id = 0xc0,
1600 }, {
1601 .name = "cio-das1401/12",
1602 .ai = das16_ai_rinsn,
1603 .ai_nbits = 12,
1604 .ai_speed = 6250,
1605 .ai_pg = das16_pg_1601,
1606 .ao = NULL,
1607 .di = das16_di_rbits,
1608 .do_ = das16_do_wbits,
1609 .i8255_offset = 0,
1610 .i8254_offset = 0x0c,
1611 .size = 0x408,
1612 .id = 0xc0,
1613 }, {
1614 .name = "cio-das1402/12",
1615 .ai = das16_ai_rinsn,
1616 .ai_nbits = 12,
1617 .ai_speed = 6250,
1618 .ai_pg = das16_pg_1602,
1619 .ao = NULL,
1620 .di = das16_di_rbits,
1621 .do_ = das16_do_wbits,
1622 .i8255_offset = 0,
1623 .i8254_offset = 0x0c,
1624 .size = 0x408,
1625 .id = 0xc0,
1626 }, {
1627 .name = "cio-das1402/16",
1628 .ai = das16_ai_rinsn,
1629 .ai_nbits = 16,
1630 .ai_speed = 10000,
1631 .ai_pg = das16_pg_1602,
1632 .ao = NULL,
1633 .di = das16_di_rbits,
1634 .do_ = das16_do_wbits,
1635 .i8255_offset = 0,
1636 .i8254_offset = 0x0c,
1637 .size = 0x408,
1638 .id = 0xc0,
1639 }, {
1640 .name = "cio-das1601/12",
1641 .ai = das16_ai_rinsn,
1642 .ai_nbits = 12,
1643 .ai_speed = 6250,
1644 .ai_pg = das16_pg_1601,
1645 .ao = das16_ao_winsn,
1646 .ao_nbits = 12,
1647 .di = das16_di_rbits,
1648 .do_ = das16_do_wbits,
1649 .i8255_offset = 0x400,
1650 .i8254_offset = 0x0c,
1651 .size = 0x408,
1652 .id = 0xc0,
1653 }, {
1654 .name = "cio-das1602/12",
1655 .ai = das16_ai_rinsn,
1656 .ai_nbits = 12,
1657 .ai_speed = 10000,
1658 .ai_pg = das16_pg_1602,
1659 .ao = das16_ao_winsn,
1660 .ao_nbits = 12,
1661 .di = das16_di_rbits,
1662 .do_ = das16_do_wbits,
1663 .i8255_offset = 0x400,
1664 .i8254_offset = 0x0c,
1665 .size = 0x408,
1666 .id = 0xc0,
1667 }, {
1668 .name = "cio-das1602/16",
1669 .ai = das16_ai_rinsn,
1670 .ai_nbits = 16,
1671 .ai_speed = 10000,
1672 .ai_pg = das16_pg_1602,
1673 .ao = das16_ao_winsn,
1674 .ao_nbits = 12,
1675 .di = das16_di_rbits,
1676 .do_ = das16_do_wbits,
1677 .i8255_offset = 0x400,
1678 .i8254_offset = 0x0c,
1679 .size = 0x408,
1680 .id = 0xc0,
1681 }, {
1682 .name = "cio-das16/330",
1683 .ai = das16_ai_rinsn,
1684 .ai_nbits = 12,
1685 .ai_speed = 3030,
1686 .ai_pg = das16_pg_16jr,
1687 .ao = NULL,
1688 .di = das16_di_rbits,
1689 .do_ = das16_do_wbits,
1690 .i8255_offset = 0,
1691 .i8254_offset = 0x0c,
1692 .size = 0x14,
1693 .id = 0xf0,
1694 },
1695};
1785 1696
1786 } 1697static struct comedi_driver das16_driver = {
1787} 1698 .driver_name = "das16",
1699 .module = THIS_MODULE,
1700 .attach = das16_attach,
1701 .detach = das16_detach,
1702 .board_name = &das16_boards[0].name,
1703 .num_names = ARRAY_SIZE(das16_boards),
1704 .offset = sizeof(das16_boards[0]),
1705};
1706module_comedi_driver(das16_driver);
1788 1707
1789MODULE_AUTHOR("Comedi http://www.comedi.org"); 1708MODULE_AUTHOR("Comedi http://www.comedi.org");
1790MODULE_DESCRIPTION("Comedi low-level driver"); 1709MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c
index 5376e718e3d7..d2e1490cd808 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -132,57 +132,11 @@ static const struct comedi_lrange range_das16m1 = { 9,
132 } 132 }
133}; 133};
134 134
135static int das16m1_do_wbits(struct comedi_device *dev,
136 struct comedi_subdevice *s,
137 struct comedi_insn *insn, unsigned int *data);
138static int das16m1_di_rbits(struct comedi_device *dev,
139 struct comedi_subdevice *s,
140 struct comedi_insn *insn, unsigned int *data);
141static int das16m1_ai_rinsn(struct comedi_device *dev,
142 struct comedi_subdevice *s,
143 struct comedi_insn *insn, unsigned int *data);
144
145static int das16m1_cmd_test(struct comedi_device *dev,
146 struct comedi_subdevice *s, struct comedi_cmd *cmd);
147static int das16m1_cmd_exec(struct comedi_device *dev,
148 struct comedi_subdevice *s);
149static int das16m1_cancel(struct comedi_device *dev,
150 struct comedi_subdevice *s);
151
152static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s);
153static irqreturn_t das16m1_interrupt(int irq, void *d);
154static void das16m1_handler(struct comedi_device *dev, unsigned int status);
155
156static unsigned int das16m1_set_pacer(struct comedi_device *dev,
157 unsigned int ns, int round_flag);
158
159static int das16m1_irq_bits(unsigned int irq);
160
161struct das16m1_board { 135struct das16m1_board {
162 const char *name; 136 const char *name;
163 unsigned int ai_speed; 137 unsigned int ai_speed;
164}; 138};
165 139
166static const struct das16m1_board das16m1_boards[] = {
167 {
168 .name = "cio-das16/m1", /* CIO-DAS16_M1.pdf */
169 .ai_speed = 1000, /* 1MHz max speed */
170 },
171};
172
173static int das16m1_attach(struct comedi_device *dev,
174 struct comedi_devconfig *it);
175static int das16m1_detach(struct comedi_device *dev);
176static struct comedi_driver driver_das16m1 = {
177 .driver_name = "das16m1",
178 .module = THIS_MODULE,
179 .attach = das16m1_attach,
180 .detach = das16m1_detach,
181 .board_name = &das16m1_boards[0].name,
182 .num_names = ARRAY_SIZE(das16m1_boards),
183 .offset = sizeof(das16m1_boards[0]),
184};
185
186struct das16m1_private_struct { 140struct das16m1_private_struct {
187 unsigned int control_state; 141 unsigned int control_state;
188 volatile unsigned int adc_count; /* number of samples completed */ 142 volatile unsigned int adc_count; /* number of samples completed */
@@ -198,22 +152,17 @@ struct das16m1_private_struct {
198#define devpriv ((struct das16m1_private_struct *)(dev->private)) 152#define devpriv ((struct das16m1_private_struct *)(dev->private))
199#define thisboard ((const struct das16m1_board *)(dev->board_ptr)) 153#define thisboard ((const struct das16m1_board *)(dev->board_ptr))
200 154
201static int __init driver_das16m1_init_module(void) 155static inline short munge_sample(short data)
202{ 156{
203 return comedi_driver_register(&driver_das16m1); 157 return (data >> 4) & 0xfff;
204} 158}
205 159
206static void __exit driver_das16m1_cleanup_module(void) 160static void munge_sample_array(short *array, unsigned int num_elements)
207{ 161{
208 comedi_driver_unregister(&driver_das16m1); 162 unsigned int i;
209}
210
211module_init(driver_das16m1_init_module);
212module_exit(driver_das16m1_cleanup_module);
213 163
214static inline short munge_sample(short data) 164 for (i = 0; i < num_elements; i++)
215{ 165 array[i] = munge_sample(array[i]);
216 return (data >> 4) & 0xfff;
217} 166}
218 167
219static int das16m1_cmd_test(struct comedi_device *dev, 168static int das16m1_cmd_test(struct comedi_device *dev,
@@ -340,6 +289,25 @@ static int das16m1_cmd_test(struct comedi_device *dev,
340 return 0; 289 return 0;
341} 290}
342 291
292/* This function takes a time in nanoseconds and sets the *
293 * 2 pacer clocks to the closest frequency possible. It also *
294 * returns the actual sampling period. */
295static unsigned int das16m1_set_pacer(struct comedi_device *dev,
296 unsigned int ns, int rounding_flags)
297{
298 i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, &(devpriv->divisor1),
299 &(devpriv->divisor2), &ns,
300 rounding_flags & TRIG_ROUND_MASK);
301
302 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
303 i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 1, devpriv->divisor1,
304 2);
305 i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 2, devpriv->divisor2,
306 2);
307
308 return ns;
309}
310
343static int das16m1_cmd_exec(struct comedi_device *dev, 311static int das16m1_cmd_exec(struct comedi_device *dev,
344 struct comedi_subdevice *s) 312 struct comedi_subdevice *s)
345{ 313{
@@ -484,57 +452,6 @@ static int das16m1_do_wbits(struct comedi_device *dev,
484 return 2; 452 return 2;
485} 453}
486 454
487static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s)
488{
489 unsigned long flags;
490 unsigned int status;
491
492 /* prevent race with interrupt handler */
493 spin_lock_irqsave(&dev->spinlock, flags);
494 status = inb(dev->iobase + DAS16M1_CS);
495 das16m1_handler(dev, status);
496 spin_unlock_irqrestore(&dev->spinlock, flags);
497
498 return s->async->buf_write_count - s->async->buf_read_count;
499}
500
501static irqreturn_t das16m1_interrupt(int irq, void *d)
502{
503 int status;
504 struct comedi_device *dev = d;
505
506 if (dev->attached == 0) {
507 comedi_error(dev, "premature interrupt");
508 return IRQ_HANDLED;
509 }
510 /* prevent race with comedi_poll() */
511 spin_lock(&dev->spinlock);
512
513 status = inb(dev->iobase + DAS16M1_CS);
514
515 if ((status & (IRQDATA | OVRUN)) == 0) {
516 comedi_error(dev, "spurious interrupt");
517 spin_unlock(&dev->spinlock);
518 return IRQ_NONE;
519 }
520
521 das16m1_handler(dev, status);
522
523 /* clear interrupt */
524 outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
525
526 spin_unlock(&dev->spinlock);
527 return IRQ_HANDLED;
528}
529
530static void munge_sample_array(short *array, unsigned int num_elements)
531{
532 unsigned int i;
533
534 for (i = 0; i < num_elements; i++)
535 array[i] = munge_sample(array[i]);
536}
537
538static void das16m1_handler(struct comedi_device *dev, unsigned int status) 455static void das16m1_handler(struct comedi_device *dev, unsigned int status)
539{ 456{
540 struct comedi_subdevice *s; 457 struct comedi_subdevice *s;
@@ -596,23 +513,47 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
596 513
597} 514}
598 515
599/* This function takes a time in nanoseconds and sets the * 516static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s)
600 * 2 pacer clocks to the closest frequency possible. It also *
601 * returns the actual sampling period. */
602static unsigned int das16m1_set_pacer(struct comedi_device *dev,
603 unsigned int ns, int rounding_flags)
604{ 517{
605 i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, &(devpriv->divisor1), 518 unsigned long flags;
606 &(devpriv->divisor2), &ns, 519 unsigned int status;
607 rounding_flags & TRIG_ROUND_MASK);
608 520
609 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */ 521 /* prevent race with interrupt handler */
610 i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 1, devpriv->divisor1, 522 spin_lock_irqsave(&dev->spinlock, flags);
611 2); 523 status = inb(dev->iobase + DAS16M1_CS);
612 i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 2, devpriv->divisor2, 524 das16m1_handler(dev, status);
613 2); 525 spin_unlock_irqrestore(&dev->spinlock, flags);
614 526
615 return ns; 527 return s->async->buf_write_count - s->async->buf_read_count;
528}
529
530static irqreturn_t das16m1_interrupt(int irq, void *d)
531{
532 int status;
533 struct comedi_device *dev = d;
534
535 if (dev->attached == 0) {
536 comedi_error(dev, "premature interrupt");
537 return IRQ_HANDLED;
538 }
539 /* prevent race with comedi_poll() */
540 spin_lock(&dev->spinlock);
541
542 status = inb(dev->iobase + DAS16M1_CS);
543
544 if ((status & (IRQDATA | OVRUN)) == 0) {
545 comedi_error(dev, "spurious interrupt");
546 spin_unlock(&dev->spinlock);
547 return IRQ_NONE;
548 }
549
550 das16m1_handler(dev, status);
551
552 /* clear interrupt */
553 outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
554
555 spin_unlock(&dev->spinlock);
556 return IRQ_HANDLED;
616} 557}
617 558
618static int das16m1_irq_bits(unsigned int irq) 559static int das16m1_irq_bits(unsigned int irq)
@@ -656,7 +597,6 @@ static int das16m1_irq_bits(unsigned int irq)
656 * 0 I/O base 597 * 0 I/O base
657 * 1 IRQ 598 * 1 IRQ
658 */ 599 */
659
660static int das16m1_attach(struct comedi_device *dev, 600static int das16m1_attach(struct comedi_device *dev,
661 struct comedi_devconfig *it) 601 struct comedi_devconfig *it)
662{ 602{
@@ -673,12 +613,12 @@ static int das16m1_attach(struct comedi_device *dev,
673 613
674 dev->board_name = thisboard->name; 614 dev->board_name = thisboard->name;
675 615
676 if (!request_region(iobase, DAS16M1_SIZE, driver_das16m1.driver_name)) { 616 if (!request_region(iobase, DAS16M1_SIZE, dev->driver->driver_name)) {
677 comedi_error(dev, "I/O port conflict\n"); 617 comedi_error(dev, "I/O port conflict\n");
678 return -EIO; 618 return -EIO;
679 } 619 }
680 if (!request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2, 620 if (!request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2,
681 driver_das16m1.driver_name)) { 621 dev->driver->driver_name)) {
682 release_region(iobase, DAS16M1_SIZE); 622 release_region(iobase, DAS16M1_SIZE);
683 comedi_error(dev, "I/O port conflict\n"); 623 comedi_error(dev, "I/O port conflict\n");
684 return -EIO; 624 return -EIO;
@@ -690,7 +630,7 @@ static int das16m1_attach(struct comedi_device *dev,
690 /* make sure it is valid */ 630 /* make sure it is valid */
691 if (das16m1_irq_bits(irq) >= 0) { 631 if (das16m1_irq_bits(irq) >= 0) {
692 ret = request_irq(irq, das16m1_interrupt, 0, 632 ret = request_irq(irq, das16m1_interrupt, 0,
693 driver_das16m1.driver_name, dev); 633 dev->driver->driver_name, dev);
694 if (ret < 0) 634 if (ret < 0)
695 return ret; 635 return ret;
696 dev->irq = irq; 636 dev->irq = irq;
@@ -763,25 +703,36 @@ static int das16m1_attach(struct comedi_device *dev,
763 return 0; 703 return 0;
764} 704}
765 705
766static int das16m1_detach(struct comedi_device *dev) 706static void das16m1_detach(struct comedi_device *dev)
767{ 707{
768
769/* das16m1_reset(dev); */
770
771 if (dev->subdevices) 708 if (dev->subdevices)
772 subdev_8255_cleanup(dev, dev->subdevices + 3); 709 subdev_8255_cleanup(dev, dev->subdevices + 3);
773
774 if (dev->irq) 710 if (dev->irq)
775 free_irq(dev->irq, dev); 711 free_irq(dev->irq, dev);
776
777 if (dev->iobase) { 712 if (dev->iobase) {
778 release_region(dev->iobase, DAS16M1_SIZE); 713 release_region(dev->iobase, DAS16M1_SIZE);
779 release_region(dev->iobase + DAS16M1_82C55, DAS16M1_SIZE2); 714 release_region(dev->iobase + DAS16M1_82C55, DAS16M1_SIZE2);
780 } 715 }
781
782 return 0;
783} 716}
784 717
718static const struct das16m1_board das16m1_boards[] = {
719 {
720 .name = "cio-das16/m1", /* CIO-DAS16_M1.pdf */
721 .ai_speed = 1000, /* 1MHz max speed */
722 },
723};
724
725static struct comedi_driver das16m1_driver = {
726 .driver_name = "das16m1",
727 .module = THIS_MODULE,
728 .attach = das16m1_attach,
729 .detach = das16m1_detach,
730 .board_name = &das16m1_boards[0].name,
731 .num_names = ARRAY_SIZE(das16m1_boards),
732 .offset = sizeof(das16m1_boards[0]),
733};
734module_comedi_driver(das16m1_driver);
735
785MODULE_AUTHOR("Comedi http://www.comedi.org"); 736MODULE_AUTHOR("Comedi http://www.comedi.org");
786MODULE_DESCRIPTION("Comedi low-level driver"); 737MODULE_DESCRIPTION("Comedi low-level driver");
787MODULE_LICENSE("GPL"); 738MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index 99ada5a53b9e..2ac344354c1d 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -183,9 +183,6 @@ enum {
183 das1802hr, das1802hr_da, das1801hc, das1802hc, das1801ao, das1802ao 183 das1802hr, das1802hr_da, das1801hc, das1802hc, das1801ao, das1802ao
184}; 184};
185 185
186static int das1800_attach(struct comedi_device *dev,
187 struct comedi_devconfig *it);
188static int das1800_detach(struct comedi_device *dev);
189static int das1800_probe(struct comedi_device *dev); 186static int das1800_probe(struct comedi_device *dev);
190static int das1800_cancel(struct comedi_device *dev, 187static int das1800_cancel(struct comedi_device *dev,
191 struct comedi_subdevice *s); 188 struct comedi_subdevice *s);
@@ -518,33 +515,6 @@ static const struct comedi_lrange range_ao_2 = {
518}; 515};
519*/ 516*/
520 517
521static struct comedi_driver driver_das1800 = {
522 .driver_name = "das1800",
523 .module = THIS_MODULE,
524 .attach = das1800_attach,
525 .detach = das1800_detach,
526 .num_names = ARRAY_SIZE(das1800_boards),
527 .board_name = &das1800_boards[0].name,
528 .offset = sizeof(struct das1800_board),
529};
530
531/*
532 * A convenient macro that defines init_module() and cleanup_module(),
533 * as necessary.
534 */
535static int __init driver_das1800_init_module(void)
536{
537 return comedi_driver_register(&driver_das1800);
538}
539
540static void __exit driver_das1800_cleanup_module(void)
541{
542 comedi_driver_unregister(&driver_das1800);
543}
544
545module_init(driver_das1800_init_module);
546module_exit(driver_das1800_cleanup_module);
547
548static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0, 518static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
549 unsigned int dma1) 519 unsigned int dma1)
550{ 520{
@@ -579,7 +549,7 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
579 return -EINVAL; 549 return -EINVAL;
580 break; 550 break;
581 } 551 }
582 if (request_dma(dma0, driver_das1800.driver_name)) { 552 if (request_dma(dma0, dev->driver->driver_name)) {
583 dev_err(dev->hw_dev, "failed to allocate dma channel %i\n", 553 dev_err(dev->hw_dev, "failed to allocate dma channel %i\n",
584 dma0); 554 dma0);
585 return -EINVAL; 555 return -EINVAL;
@@ -587,7 +557,7 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
587 devpriv->dma0 = dma0; 557 devpriv->dma0 = dma0;
588 devpriv->dma_current = dma0; 558 devpriv->dma_current = dma0;
589 if (dma1) { 559 if (dma1) {
590 if (request_dma(dma1, driver_das1800.driver_name)) { 560 if (request_dma(dma1, dev->driver->driver_name)) {
591 dev_err(dev->hw_dev, "failed to allocate dma channel %i\n", 561 dev_err(dev->hw_dev, "failed to allocate dma channel %i\n",
592 dma1); 562 dma1);
593 return -EINVAL; 563 return -EINVAL;
@@ -633,7 +603,7 @@ static int das1800_attach(struct comedi_device *dev,
633 return -ENOMEM; 603 return -ENOMEM;
634 604
635 printk(KERN_DEBUG "comedi%d: %s: io 0x%lx", dev->minor, 605 printk(KERN_DEBUG "comedi%d: %s: io 0x%lx", dev->minor,
636 driver_das1800.driver_name, iobase); 606 dev->driver->driver_name, iobase);
637 if (irq) { 607 if (irq) {
638 printk(KERN_CONT ", irq %u", irq); 608 printk(KERN_CONT ", irq %u", irq);
639 if (dma0) { 609 if (dma0) {
@@ -650,7 +620,7 @@ static int das1800_attach(struct comedi_device *dev,
650 } 620 }
651 621
652 /* check if io addresses are available */ 622 /* check if io addresses are available */
653 if (!request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name)) { 623 if (!request_region(iobase, DAS1800_SIZE, dev->driver->driver_name)) {
654 printk 624 printk
655 (" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", 625 (" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
656 iobase, iobase + DAS1800_SIZE - 1); 626 iobase, iobase + DAS1800_SIZE - 1);
@@ -671,7 +641,7 @@ static int das1800_attach(struct comedi_device *dev,
671 if (thisboard->ao_ability == 2) { 641 if (thisboard->ao_ability == 2) {
672 iobase2 = iobase + IOBASE2; 642 iobase2 = iobase + IOBASE2;
673 if (!request_region(iobase2, DAS1800_SIZE, 643 if (!request_region(iobase2, DAS1800_SIZE,
674 driver_das1800.driver_name)) { 644 dev->driver->driver_name)) {
675 printk 645 printk
676 (" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", 646 (" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
677 iobase2, iobase2 + DAS1800_SIZE - 1); 647 iobase2, iobase2 + DAS1800_SIZE - 1);
@@ -683,7 +653,7 @@ static int das1800_attach(struct comedi_device *dev,
683 /* grab our IRQ */ 653 /* grab our IRQ */
684 if (irq) { 654 if (irq) {
685 if (request_irq(irq, das1800_interrupt, 0, 655 if (request_irq(irq, das1800_interrupt, 0,
686 driver_das1800.driver_name, dev)) { 656 dev->driver->driver_name, dev)) {
687 dev_dbg(dev->hw_dev, "unable to allocate irq %u\n", 657 dev_dbg(dev->hw_dev, "unable to allocate irq %u\n",
688 irq); 658 irq);
689 return -EINVAL; 659 return -EINVAL;
@@ -797,9 +767,8 @@ static int das1800_attach(struct comedi_device *dev,
797 return 0; 767 return 0;
798}; 768};
799 769
800static int das1800_detach(struct comedi_device *dev) 770static void das1800_detach(struct comedi_device *dev)
801{ 771{
802 /* only free stuff if it has been allocated by _attach */
803 if (dev->iobase) 772 if (dev->iobase)
804 release_region(dev->iobase, DAS1800_SIZE); 773 release_region(dev->iobase, DAS1800_SIZE);
805 if (dev->irq) 774 if (dev->irq)
@@ -814,11 +783,6 @@ static int das1800_detach(struct comedi_device *dev)
814 kfree(devpriv->ai_buf0); 783 kfree(devpriv->ai_buf0);
815 kfree(devpriv->ai_buf1); 784 kfree(devpriv->ai_buf1);
816 } 785 }
817
818 dev_dbg(dev->hw_dev, "comedi%d: %s: remove\n", dev->minor,
819 driver_das1800.driver_name);
820
821 return 0;
822}; 786};
823 787
824/* probes and checks das-1800 series board type 788/* probes and checks das-1800 series board type
@@ -1811,6 +1775,17 @@ static unsigned int suggest_transfer_size(struct comedi_cmd *cmd)
1811 return size; 1775 return size;
1812} 1776}
1813 1777
1778static struct comedi_driver das1800_driver = {
1779 .driver_name = "das1800",
1780 .module = THIS_MODULE,
1781 .attach = das1800_attach,
1782 .detach = das1800_detach,
1783 .num_names = ARRAY_SIZE(das1800_boards),
1784 .board_name = &das1800_boards[0].name,
1785 .offset = sizeof(struct das1800_board),
1786};
1787module_comedi_driver(das1800_driver);
1788
1814MODULE_AUTHOR("Comedi http://www.comedi.org"); 1789MODULE_AUTHOR("Comedi http://www.comedi.org");
1815MODULE_DESCRIPTION("Comedi low-level driver"); 1790MODULE_DESCRIPTION("Comedi low-level driver");
1816MODULE_LICENSE("GPL"); 1791MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das6402.c b/drivers/staging/comedi/drivers/das6402.c
index f25684145e84..881f392d1dba 100644
--- a/drivers/staging/comedi/drivers/das6402.c
+++ b/drivers/staging/comedi/drivers/das6402.c
@@ -99,29 +99,6 @@ This driver has suffered bitrot.
99#define C2 0x80 99#define C2 0x80
100#define RWLH 0x30 100#define RWLH 0x30
101 101
102static int das6402_attach(struct comedi_device *dev,
103 struct comedi_devconfig *it);
104static int das6402_detach(struct comedi_device *dev);
105static struct comedi_driver driver_das6402 = {
106 .driver_name = "das6402",
107 .module = THIS_MODULE,
108 .attach = das6402_attach,
109 .detach = das6402_detach,
110};
111
112static int __init driver_das6402_init_module(void)
113{
114 return comedi_driver_register(&driver_das6402);
115}
116
117static void __exit driver_das6402_cleanup_module(void)
118{
119 comedi_driver_unregister(&driver_das6402);
120}
121
122module_init(driver_das6402_init_module);
123module_exit(driver_das6402_cleanup_module);
124
125struct das6402_private { 102struct das6402_private {
126 int ai_bytes_to_read; 103 int ai_bytes_to_read;
127 104
@@ -130,7 +107,14 @@ struct das6402_private {
130#define devpriv ((struct das6402_private *)dev->private) 107#define devpriv ((struct das6402_private *)dev->private)
131 108
132static void das6402_ai_fifo_dregs(struct comedi_device *dev, 109static void das6402_ai_fifo_dregs(struct comedi_device *dev,
133 struct comedi_subdevice *s); 110 struct comedi_subdevice *s)
111{
112 while (1) {
113 if (!(inb(dev->iobase + 8) & 0x01))
114 return;
115 comedi_buf_put(s->async, inw(dev->iobase));
116 }
117}
134 118
135static void das6402_setcounter(struct comedi_device *dev) 119static void das6402_setcounter(struct comedi_device *dev)
136{ 120{
@@ -209,16 +193,6 @@ static void das6402_ai_fifo_read(struct comedi_device *dev, short *data, int n)
209} 193}
210#endif 194#endif
211 195
212static void das6402_ai_fifo_dregs(struct comedi_device *dev,
213 struct comedi_subdevice *s)
214{
215 while (1) {
216 if (!(inb(dev->iobase + 8) & 0x01))
217 return;
218 comedi_buf_put(s->async, inw(dev->iobase));
219 }
220}
221
222static int das6402_ai_cancel(struct comedi_device *dev, 196static int das6402_ai_cancel(struct comedi_device *dev,
223 struct comedi_subdevice *s) 197 struct comedi_subdevice *s)
224{ 198{
@@ -300,16 +274,6 @@ static int board_init(struct comedi_device *dev)
300 return 0; 274 return 0;
301} 275}
302 276
303static int das6402_detach(struct comedi_device *dev)
304{
305 if (dev->irq)
306 free_irq(dev->irq, dev);
307 if (dev->iobase)
308 release_region(dev->iobase, DAS6402_SIZE);
309
310 return 0;
311}
312
313static int das6402_attach(struct comedi_device *dev, 277static int das6402_attach(struct comedi_device *dev,
314 struct comedi_devconfig *it) 278 struct comedi_devconfig *it)
315{ 279{
@@ -363,6 +327,22 @@ static int das6402_attach(struct comedi_device *dev,
363 return 0; 327 return 0;
364} 328}
365 329
330static void das6402_detach(struct comedi_device *dev)
331{
332 if (dev->irq)
333 free_irq(dev->irq, dev);
334 if (dev->iobase)
335 release_region(dev->iobase, DAS6402_SIZE);
336}
337
338static struct comedi_driver das6402_driver = {
339 .driver_name = "das6402",
340 .module = THIS_MODULE,
341 .attach = das6402_attach,
342 .detach = das6402_detach,
343};
344module_comedi_driver(das6402_driver)
345
366MODULE_AUTHOR("Comedi http://www.comedi.org"); 346MODULE_AUTHOR("Comedi http://www.comedi.org");
367MODULE_DESCRIPTION("Comedi low-level driver"); 347MODULE_DESCRIPTION("Comedi low-level driver");
368MODULE_LICENSE("GPL"); 348MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das800.c b/drivers/staging/comedi/drivers/das800.c
index 6e347b40fe61..a3a54e1c5c98 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -245,7 +245,7 @@ struct das800_private {
245 245
246static int das800_attach(struct comedi_device *dev, 246static int das800_attach(struct comedi_device *dev,
247 struct comedi_devconfig *it); 247 struct comedi_devconfig *it);
248static int das800_detach(struct comedi_device *dev); 248static void das800_detach(struct comedi_device *dev);
249static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s); 249static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
250 250
251static struct comedi_driver driver_das800 = { 251static struct comedi_driver driver_das800 = {
@@ -556,16 +556,12 @@ static int das800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
556 return 0; 556 return 0;
557}; 557};
558 558
559static int das800_detach(struct comedi_device *dev) 559static void das800_detach(struct comedi_device *dev)
560{ 560{
561 dev_info(dev->hw_dev, "comedi%d: das800: remove\n", dev->minor);
562
563 /* only free stuff if it has been allocated by _attach */
564 if (dev->iobase) 561 if (dev->iobase)
565 release_region(dev->iobase, DAS800_SIZE); 562 release_region(dev->iobase, DAS800_SIZE);
566 if (dev->irq) 563 if (dev->irq)
567 free_irq(dev->irq, dev); 564 free_irq(dev->irq, dev);
568 return 0;
569}; 565};
570 566
571static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 567static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index 2b4e6e6eb825..83828903db4b 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -224,7 +224,7 @@ struct dmm32at_private {
224 */ 224 */
225static int dmm32at_attach(struct comedi_device *dev, 225static int dmm32at_attach(struct comedi_device *dev,
226 struct comedi_devconfig *it); 226 struct comedi_devconfig *it);
227static int dmm32at_detach(struct comedi_device *dev); 227static void dmm32at_detach(struct comedi_device *dev);
228static struct comedi_driver driver_dmm32at = { 228static struct comedi_driver driver_dmm32at = {
229 .driver_name = "dmm32at", 229 .driver_name = "dmm32at",
230 .module = THIS_MODULE, 230 .module = THIS_MODULE,
@@ -450,23 +450,12 @@ static int dmm32at_attach(struct comedi_device *dev,
450 450
451} 451}
452 452
453/* 453static void dmm32at_detach(struct comedi_device *dev)
454 * _detach is called to deconfigure a device. It should deallocate
455 * resources.
456 * This function is also called when _attach() fails, so it should be
457 * careful not to release resources that were not necessarily
458 * allocated by _attach(). dev->private and dev->subdevices are
459 * deallocated automatically by the core.
460 */
461static int dmm32at_detach(struct comedi_device *dev)
462{ 454{
463 printk(KERN_INFO "comedi%d: dmm32at: remove\n", dev->minor);
464 if (dev->irq) 455 if (dev->irq)
465 free_irq(dev->irq, dev); 456 free_irq(dev->irq, dev);
466 if (dev->iobase) 457 if (dev->iobase)
467 release_region(dev->iobase, DMM32AT_MEMSIZE); 458 release_region(dev->iobase, DMM32AT_MEMSIZE);
468
469 return 0;
470} 459}
471 460
472/* 461/*
diff --git a/drivers/staging/comedi/drivers/dt2801.c b/drivers/staging/comedi/drivers/dt2801.c
index b85c8366a396..625bd617a8e9 100644
--- a/drivers/staging/comedi/drivers/dt2801.c
+++ b/drivers/staging/comedi/drivers/dt2801.c
@@ -88,29 +88,6 @@ Configuration options:
88#define DT2801_STATUS 1 88#define DT2801_STATUS 1
89#define DT2801_CMD 1 89#define DT2801_CMD 1
90 90
91static int dt2801_attach(struct comedi_device *dev,
92 struct comedi_devconfig *it);
93static int dt2801_detach(struct comedi_device *dev);
94static struct comedi_driver driver_dt2801 = {
95 .driver_name = "dt2801",
96 .module = THIS_MODULE,
97 .attach = dt2801_attach,
98 .detach = dt2801_detach,
99};
100
101static int __init driver_dt2801_init_module(void)
102{
103 return comedi_driver_register(&driver_dt2801);
104}
105
106static void __exit driver_dt2801_cleanup_module(void)
107{
108 comedi_driver_unregister(&driver_dt2801);
109}
110
111module_init(driver_dt2801_init_module);
112module_exit(driver_dt2801_cleanup_module);
113
114#if 0 91#if 0
115/* ignore 'defined but not used' warning */ 92/* ignore 'defined but not used' warning */
116static const struct comedi_lrange range_dt2801_ai_pgh_bipolar = { 4, { 93static const struct comedi_lrange range_dt2801_ai_pgh_bipolar = { 4, {
@@ -258,22 +235,6 @@ struct dt2801_private {
258 235
259#define devpriv ((struct dt2801_private *)dev->private) 236#define devpriv ((struct dt2801_private *)dev->private)
260 237
261static int dt2801_ai_insn_read(struct comedi_device *dev,
262 struct comedi_subdevice *s,
263 struct comedi_insn *insn, unsigned int *data);
264static int dt2801_ao_insn_read(struct comedi_device *dev,
265 struct comedi_subdevice *s,
266 struct comedi_insn *insn, unsigned int *data);
267static int dt2801_ao_insn_write(struct comedi_device *dev,
268 struct comedi_subdevice *s,
269 struct comedi_insn *insn, unsigned int *data);
270static int dt2801_dio_insn_bits(struct comedi_device *dev,
271 struct comedi_subdevice *s,
272 struct comedi_insn *insn, unsigned int *data);
273static int dt2801_dio_insn_config(struct comedi_device *dev,
274 struct comedi_subdevice *s,
275 struct comedi_insn *insn, unsigned int *data);
276
277/* These are the low-level routines: 238/* These are the low-level routines:
278 writecommand: write a command to the board 239 writecommand: write a command to the board
279 writedata: write data byte 240 writedata: write data byte
@@ -503,6 +464,123 @@ static const struct comedi_lrange *ai_range_lkup(int type, int opt)
503 return &range_unknown; 464 return &range_unknown;
504} 465}
505 466
467static int dt2801_error(struct comedi_device *dev, int stat)
468{
469 if (stat < 0) {
470 if (stat == -ETIME)
471 printk("dt2801: timeout\n");
472 else
473 printk("dt2801: error %d\n", stat);
474 return stat;
475 }
476 printk("dt2801: error status 0x%02x, resetting...\n", stat);
477
478 dt2801_reset(dev);
479 dt2801_reset(dev);
480
481 return -EIO;
482}
483
484static int dt2801_ai_insn_read(struct comedi_device *dev,
485 struct comedi_subdevice *s,
486 struct comedi_insn *insn, unsigned int *data)
487{
488 int d;
489 int stat;
490 int i;
491
492 for (i = 0; i < insn->n; i++) {
493 stat = dt2801_writecmd(dev, DT_C_READ_ADIM);
494 dt2801_writedata(dev, CR_RANGE(insn->chanspec));
495 dt2801_writedata(dev, CR_CHAN(insn->chanspec));
496 stat = dt2801_readdata2(dev, &d);
497
498 if (stat != 0)
499 return dt2801_error(dev, stat);
500
501 data[i] = d;
502 }
503
504 return i;
505}
506
507static int dt2801_ao_insn_read(struct comedi_device *dev,
508 struct comedi_subdevice *s,
509 struct comedi_insn *insn, unsigned int *data)
510{
511 data[0] = devpriv->ao_readback[CR_CHAN(insn->chanspec)];
512
513 return 1;
514}
515
516static int dt2801_ao_insn_write(struct comedi_device *dev,
517 struct comedi_subdevice *s,
518 struct comedi_insn *insn, unsigned int *data)
519{
520 dt2801_writecmd(dev, DT_C_WRITE_DAIM);
521 dt2801_writedata(dev, CR_CHAN(insn->chanspec));
522 dt2801_writedata2(dev, data[0]);
523
524 devpriv->ao_readback[CR_CHAN(insn->chanspec)] = data[0];
525
526 return 1;
527}
528
529static int dt2801_dio_insn_bits(struct comedi_device *dev,
530 struct comedi_subdevice *s,
531 struct comedi_insn *insn, unsigned int *data)
532{
533 int which = 0;
534
535 if (s == dev->subdevices + 4)
536 which = 1;
537
538 if (insn->n != 2)
539 return -EINVAL;
540 if (data[0]) {
541 s->state &= ~data[0];
542 s->state |= (data[0] & data[1]);
543 dt2801_writecmd(dev, DT_C_WRITE_DIG);
544 dt2801_writedata(dev, which);
545 dt2801_writedata(dev, s->state);
546 }
547 dt2801_writecmd(dev, DT_C_READ_DIG);
548 dt2801_writedata(dev, which);
549 dt2801_readdata(dev, data + 1);
550
551 return 2;
552}
553
554static int dt2801_dio_insn_config(struct comedi_device *dev,
555 struct comedi_subdevice *s,
556 struct comedi_insn *insn, unsigned int *data)
557{
558 int which = 0;
559
560 if (s == dev->subdevices + 4)
561 which = 1;
562
563 /* configure */
564 switch (data[0]) {
565 case INSN_CONFIG_DIO_OUTPUT:
566 s->io_bits = 0xff;
567 dt2801_writecmd(dev, DT_C_SET_DIGOUT);
568 break;
569 case INSN_CONFIG_DIO_INPUT:
570 s->io_bits = 0;
571 dt2801_writecmd(dev, DT_C_SET_DIGIN);
572 break;
573 case INSN_CONFIG_DIO_QUERY:
574 data[1] = s->io_bits ? COMEDI_OUTPUT : COMEDI_INPUT;
575 return insn->n;
576 default:
577 return -EINVAL;
578 }
579 dt2801_writedata(dev, which);
580
581 return 1;
582}
583
506/* 584/*
507 options: 585 options:
508 [0] - i/o base 586 [0] - i/o base
@@ -615,130 +693,19 @@ out:
615 return ret; 693 return ret;
616} 694}
617 695
618static int dt2801_detach(struct comedi_device *dev) 696static void dt2801_detach(struct comedi_device *dev)
619{ 697{
620 if (dev->iobase) 698 if (dev->iobase)
621 release_region(dev->iobase, DT2801_IOSIZE); 699 release_region(dev->iobase, DT2801_IOSIZE);
622
623 return 0;
624}
625
626static int dt2801_error(struct comedi_device *dev, int stat)
627{
628 if (stat < 0) {
629 if (stat == -ETIME)
630 printk("dt2801: timeout\n");
631 else
632 printk("dt2801: error %d\n", stat);
633 return stat;
634 }
635 printk("dt2801: error status 0x%02x, resetting...\n", stat);
636
637 dt2801_reset(dev);
638 dt2801_reset(dev);
639
640 return -EIO;
641}
642
643static int dt2801_ai_insn_read(struct comedi_device *dev,
644 struct comedi_subdevice *s,
645 struct comedi_insn *insn, unsigned int *data)
646{
647 int d;
648 int stat;
649 int i;
650
651 for (i = 0; i < insn->n; i++) {
652 stat = dt2801_writecmd(dev, DT_C_READ_ADIM);
653 dt2801_writedata(dev, CR_RANGE(insn->chanspec));
654 dt2801_writedata(dev, CR_CHAN(insn->chanspec));
655 stat = dt2801_readdata2(dev, &d);
656
657 if (stat != 0)
658 return dt2801_error(dev, stat);
659
660 data[i] = d;
661 }
662
663 return i;
664}
665
666static int dt2801_ao_insn_read(struct comedi_device *dev,
667 struct comedi_subdevice *s,
668 struct comedi_insn *insn, unsigned int *data)
669{
670 data[0] = devpriv->ao_readback[CR_CHAN(insn->chanspec)];
671
672 return 1;
673}
674
675static int dt2801_ao_insn_write(struct comedi_device *dev,
676 struct comedi_subdevice *s,
677 struct comedi_insn *insn, unsigned int *data)
678{
679 dt2801_writecmd(dev, DT_C_WRITE_DAIM);
680 dt2801_writedata(dev, CR_CHAN(insn->chanspec));
681 dt2801_writedata2(dev, data[0]);
682
683 devpriv->ao_readback[CR_CHAN(insn->chanspec)] = data[0];
684
685 return 1;
686}
687
688static int dt2801_dio_insn_bits(struct comedi_device *dev,
689 struct comedi_subdevice *s,
690 struct comedi_insn *insn, unsigned int *data)
691{
692 int which = 0;
693
694 if (s == dev->subdevices + 4)
695 which = 1;
696
697 if (insn->n != 2)
698 return -EINVAL;
699 if (data[0]) {
700 s->state &= ~data[0];
701 s->state |= (data[0] & data[1]);
702 dt2801_writecmd(dev, DT_C_WRITE_DIG);
703 dt2801_writedata(dev, which);
704 dt2801_writedata(dev, s->state);
705 }
706 dt2801_writecmd(dev, DT_C_READ_DIG);
707 dt2801_writedata(dev, which);
708 dt2801_readdata(dev, data + 1);
709
710 return 2;
711} 700}
712 701
713static int dt2801_dio_insn_config(struct comedi_device *dev, 702static struct comedi_driver dt2801_driver = {
714 struct comedi_subdevice *s, 703 .driver_name = "dt2801",
715 struct comedi_insn *insn, unsigned int *data) 704 .module = THIS_MODULE,
716{ 705 .attach = dt2801_attach,
717 int which = 0; 706 .detach = dt2801_detach,
718 707};
719 if (s == dev->subdevices + 4) 708module_comedi_driver(dt2801_driver);
720 which = 1;
721
722 /* configure */
723 switch (data[0]) {
724 case INSN_CONFIG_DIO_OUTPUT:
725 s->io_bits = 0xff;
726 dt2801_writecmd(dev, DT_C_SET_DIGOUT);
727 break;
728 case INSN_CONFIG_DIO_INPUT:
729 s->io_bits = 0;
730 dt2801_writecmd(dev, DT_C_SET_DIGIN);
731 break;
732 case INSN_CONFIG_DIO_QUERY:
733 data[1] = s->io_bits ? COMEDI_OUTPUT : COMEDI_INPUT;
734 return insn->n;
735 default:
736 return -EINVAL;
737 }
738 dt2801_writedata(dev, which);
739
740 return 1;
741}
742 709
743MODULE_AUTHOR("Comedi http://www.comedi.org"); 710MODULE_AUTHOR("Comedi http://www.comedi.org");
744MODULE_DESCRIPTION("Comedi low-level driver"); 711MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index 0131d5225b52..106ffea30b95 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -211,61 +211,8 @@ struct dt2811_board {
211 const struct comedi_lrange *unip_5; 211 const struct comedi_lrange *unip_5;
212}; 212};
213 213
214static const struct dt2811_board boardtypes[] = {
215 {"dt2811-pgh",
216 &range_dt2811_pgh_ai_5_bipolar,
217 &range_dt2811_pgh_ai_2_5_bipolar,
218 &range_dt2811_pgh_ai_5_unipolar,
219 },
220 {"dt2811-pgl",
221 &range_dt2811_pgl_ai_5_bipolar,
222 &range_dt2811_pgl_ai_2_5_bipolar,
223 &range_dt2811_pgl_ai_5_unipolar,
224 },
225};
226
227#define this_board ((const struct dt2811_board *)dev->board_ptr) 214#define this_board ((const struct dt2811_board *)dev->board_ptr)
228 215
229static int dt2811_attach(struct comedi_device *dev,
230 struct comedi_devconfig *it);
231static int dt2811_detach(struct comedi_device *dev);
232static struct comedi_driver driver_dt2811 = {
233 .driver_name = "dt2811",
234 .module = THIS_MODULE,
235 .attach = dt2811_attach,
236 .detach = dt2811_detach,
237 .board_name = &boardtypes[0].name,
238 .num_names = ARRAY_SIZE(boardtypes),
239 .offset = sizeof(struct dt2811_board),
240};
241
242static int __init driver_dt2811_init_module(void)
243{
244 return comedi_driver_register(&driver_dt2811);
245}
246
247static void __exit driver_dt2811_cleanup_module(void)
248{
249 comedi_driver_unregister(&driver_dt2811);
250}
251
252module_init(driver_dt2811_init_module);
253module_exit(driver_dt2811_cleanup_module);
254
255static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
256 struct comedi_insn *insn, unsigned int *data);
257static int dt2811_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
258 struct comedi_insn *insn, unsigned int *data);
259static int dt2811_ao_insn_read(struct comedi_device *dev,
260 struct comedi_subdevice *s,
261 struct comedi_insn *insn, unsigned int *data);
262static int dt2811_di_insn_bits(struct comedi_device *dev,
263 struct comedi_subdevice *s,
264 struct comedi_insn *insn, unsigned int *data);
265static int dt2811_do_insn_bits(struct comedi_device *dev,
266 struct comedi_subdevice *s,
267 struct comedi_insn *insn, unsigned int *data);
268
269enum { card_2811_pgh, card_2811_pgl }; 216enum { card_2811_pgh, card_2811_pgl };
270 217
271struct dt2811_private { 218struct dt2811_private {
@@ -317,6 +264,120 @@ static irqreturn_t dt2811_interrupt(int irq, void *d)
317} 264}
318#endif 265#endif
319 266
267static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
268 struct comedi_insn *insn, unsigned int *data)
269{
270 int chan = CR_CHAN(insn->chanspec);
271 int timeout = DT2811_TIMEOUT;
272 int i;
273
274 for (i = 0; i < insn->n; i++) {
275 outb(chan, dev->iobase + DT2811_ADGCR);
276
277 while (timeout
278 && inb(dev->iobase + DT2811_ADCSR) & DT2811_ADBUSY)
279 timeout--;
280 if (!timeout)
281 return -ETIME;
282
283 data[i] = inb(dev->iobase + DT2811_ADDATLO);
284 data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8;
285 data[i] &= 0xfff;
286 }
287
288 return i;
289}
290
291#if 0
292/* Wow. This is code from the Comedi stone age. But it hasn't been
293 * replaced, so I'll let it stay. */
294int dt2811_adtrig(kdev_t minor, comedi_adtrig *adtrig)
295{
296 struct comedi_device *dev = comedi_devices + minor;
297
298 if (adtrig->n < 1)
299 return 0;
300 dev->curadchan = adtrig->chan;
301 switch (dev->i_admode) {
302 case COMEDI_MDEMAND:
303 dev->ntrig = adtrig->n - 1;
304 /* not necessary */
305 /*printk("dt2811: AD soft trigger\n"); */
306 /*outb(DT2811_CLRERROR|DT2811_INTENB,
307 dev->iobase+DT2811_ADCSR); */
308 outb(dev->curadchan, dev->iobase + DT2811_ADGCR);
309 do_gettimeofday(&trigtime);
310 break;
311 case COMEDI_MCONTS:
312 dev->ntrig = adtrig->n;
313 break;
314 }
315
316 return 0;
317}
318#endif
319
320static int dt2811_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
321 struct comedi_insn *insn, unsigned int *data)
322{
323 int i;
324 int chan;
325
326 chan = CR_CHAN(insn->chanspec);
327
328 for (i = 0; i < insn->n; i++) {
329 outb(data[i] & 0xff, dev->iobase + DT2811_DADAT0LO + 2 * chan);
330 outb((data[i] >> 8) & 0xff,
331 dev->iobase + DT2811_DADAT0HI + 2 * chan);
332 devpriv->ao_readback[chan] = data[i];
333 }
334
335 return i;
336}
337
338static int dt2811_ao_insn_read(struct comedi_device *dev,
339 struct comedi_subdevice *s,
340 struct comedi_insn *insn, unsigned int *data)
341{
342 int i;
343 int chan;
344
345 chan = CR_CHAN(insn->chanspec);
346
347 for (i = 0; i < insn->n; i++)
348 data[i] = devpriv->ao_readback[chan];
349
350 return i;
351}
352
353static int dt2811_di_insn_bits(struct comedi_device *dev,
354 struct comedi_subdevice *s,
355 struct comedi_insn *insn, unsigned int *data)
356{
357 if (insn->n != 2)
358 return -EINVAL;
359
360 data[1] = inb(dev->iobase + DT2811_DIO);
361
362 return 2;
363}
364
365static int dt2811_do_insn_bits(struct comedi_device *dev,
366 struct comedi_subdevice *s,
367 struct comedi_insn *insn, unsigned int *data)
368{
369 if (insn->n != 2)
370 return -EINVAL;
371
372 s->state &= ~data[0];
373 s->state |= data[0] & data[1];
374 outb(s->state, dev->iobase + DT2811_DIO);
375
376 data[1] = s->state;
377
378 return 2;
379}
380
320/* 381/*
321 options[0] Board base address 382 options[0] Board base address
322 options[1] IRQ 383 options[1] IRQ
@@ -337,7 +398,6 @@ static irqreturn_t dt2811_interrupt(int irq, void *d)
337 1 == bipolar 2.5V (-2.5V -- +2.5V) 398 1 == bipolar 2.5V (-2.5V -- +2.5V)
338 2 == unipolar 5V (0V -- +5V) 399 2 == unipolar 5V (0V -- +5V)
339*/ 400*/
340
341static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) 401static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)
342{ 402{
343 /* int i, irq; */ 403 /* int i, irq; */
@@ -511,131 +571,38 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)
511 return 0; 571 return 0;
512} 572}
513 573
514static int dt2811_detach(struct comedi_device *dev) 574static void dt2811_detach(struct comedi_device *dev)
515{ 575{
516 printk(KERN_INFO "comedi%d: dt2811: remove\n", dev->minor);
517
518 if (dev->irq) 576 if (dev->irq)
519 free_irq(dev->irq, dev); 577 free_irq(dev->irq, dev);
520 if (dev->iobase) 578 if (dev->iobase)
521 release_region(dev->iobase, DT2811_SIZE); 579 release_region(dev->iobase, DT2811_SIZE);
522
523 return 0;
524}
525
526static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
527 struct comedi_insn *insn, unsigned int *data)
528{
529 int chan = CR_CHAN(insn->chanspec);
530 int timeout = DT2811_TIMEOUT;
531 int i;
532
533 for (i = 0; i < insn->n; i++) {
534 outb(chan, dev->iobase + DT2811_ADGCR);
535
536 while (timeout
537 && inb(dev->iobase + DT2811_ADCSR) & DT2811_ADBUSY)
538 timeout--;
539 if (!timeout)
540 return -ETIME;
541
542 data[i] = inb(dev->iobase + DT2811_ADDATLO);
543 data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8;
544 data[i] &= 0xfff;
545 }
546
547 return i;
548} 580}
549 581
550#if 0 582static const struct dt2811_board boardtypes[] = {
551/* Wow. This is code from the Comedi stone age. But it hasn't been 583 {
552 * replaced, so I'll let it stay. */ 584 .name = "dt2811-pgh",
553int dt2811_adtrig(kdev_t minor, comedi_adtrig *adtrig) 585 .bip_5 = &range_dt2811_pgh_ai_5_bipolar,
554{ 586 .bip_2_5 = &range_dt2811_pgh_ai_2_5_bipolar,
555 struct comedi_device *dev = comedi_devices + minor; 587 .unip_5 = &range_dt2811_pgh_ai_5_unipolar,
556 588 }, {
557 if (adtrig->n < 1) 589 .name = "dt2811-pgl",
558 return 0; 590 .bip_5 = &range_dt2811_pgl_ai_5_bipolar,
559 dev->curadchan = adtrig->chan; 591 .bip_2_5 = &range_dt2811_pgl_ai_2_5_bipolar,
560 switch (dev->i_admode) { 592 .unip_5 = &range_dt2811_pgl_ai_5_unipolar,
561 case COMEDI_MDEMAND: 593 },
562 dev->ntrig = adtrig->n - 1; 594};
563 /* not necessary */
564 /*printk("dt2811: AD soft trigger\n"); */
565 /*outb(DT2811_CLRERROR|DT2811_INTENB,
566 dev->iobase+DT2811_ADCSR); */
567 outb(dev->curadchan, dev->iobase + DT2811_ADGCR);
568 do_gettimeofday(&trigtime);
569 break;
570 case COMEDI_MCONTS:
571 dev->ntrig = adtrig->n;
572 break;
573 }
574
575 return 0;
576}
577#endif
578
579static int dt2811_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
580 struct comedi_insn *insn, unsigned int *data)
581{
582 int i;
583 int chan;
584
585 chan = CR_CHAN(insn->chanspec);
586
587 for (i = 0; i < insn->n; i++) {
588 outb(data[i] & 0xff, dev->iobase + DT2811_DADAT0LO + 2 * chan);
589 outb((data[i] >> 8) & 0xff,
590 dev->iobase + DT2811_DADAT0HI + 2 * chan);
591 devpriv->ao_readback[chan] = data[i];
592 }
593
594 return i;
595}
596
597static int dt2811_ao_insn_read(struct comedi_device *dev,
598 struct comedi_subdevice *s,
599 struct comedi_insn *insn, unsigned int *data)
600{
601 int i;
602 int chan;
603
604 chan = CR_CHAN(insn->chanspec);
605
606 for (i = 0; i < insn->n; i++)
607 data[i] = devpriv->ao_readback[chan];
608
609 return i;
610}
611
612static int dt2811_di_insn_bits(struct comedi_device *dev,
613 struct comedi_subdevice *s,
614 struct comedi_insn *insn, unsigned int *data)
615{
616 if (insn->n != 2)
617 return -EINVAL;
618
619 data[1] = inb(dev->iobase + DT2811_DIO);
620
621 return 2;
622}
623
624static int dt2811_do_insn_bits(struct comedi_device *dev,
625 struct comedi_subdevice *s,
626 struct comedi_insn *insn, unsigned int *data)
627{
628 if (insn->n != 2)
629 return -EINVAL;
630
631 s->state &= ~data[0];
632 s->state |= data[0] & data[1];
633 outb(s->state, dev->iobase + DT2811_DIO);
634
635 data[1] = s->state;
636 595
637 return 2; 596static struct comedi_driver dt2811_driver = {
638} 597 .driver_name = "dt2811",
598 .module = THIS_MODULE,
599 .attach = dt2811_attach,
600 .detach = dt2811_detach,
601 .board_name = &boardtypes[0].name,
602 .num_names = ARRAY_SIZE(boardtypes),
603 .offset = sizeof(struct dt2811_board),
604};
605module_comedi_driver(dt2811_driver);
639 606
640MODULE_AUTHOR("Comedi http://www.comedi.org"); 607MODULE_AUTHOR("Comedi http://www.comedi.org");
641MODULE_DESCRIPTION("Comedi low-level driver"); 608MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index 1c6248cf5928..fa4ade61be5f 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -60,31 +60,6 @@ addition, the clock does not seem to be very accurate.
60#define DT2814_ENB 0x10 60#define DT2814_ENB 0x10
61#define DT2814_CHANMASK 0x0f 61#define DT2814_CHANMASK 0x0f
62 62
63static int dt2814_attach(struct comedi_device *dev,
64 struct comedi_devconfig *it);
65static int dt2814_detach(struct comedi_device *dev);
66static struct comedi_driver driver_dt2814 = {
67 .driver_name = "dt2814",
68 .module = THIS_MODULE,
69 .attach = dt2814_attach,
70 .detach = dt2814_detach,
71};
72
73static int __init driver_dt2814_init_module(void)
74{
75 return comedi_driver_register(&driver_dt2814);
76}
77
78static void __exit driver_dt2814_cleanup_module(void)
79{
80 comedi_driver_unregister(&driver_dt2814);
81}
82
83module_init(driver_dt2814_init_module);
84module_exit(driver_dt2814_cleanup_module);
85
86static irqreturn_t dt2814_interrupt(int irq, void *dev);
87
88struct dt2814_private { 63struct dt2814_private {
89 64
90 int ntrig; 65 int ntrig;
@@ -260,6 +235,45 @@ static int dt2814_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
260 235
261} 236}
262 237
238static irqreturn_t dt2814_interrupt(int irq, void *d)
239{
240 int lo, hi;
241 struct comedi_device *dev = d;
242 struct comedi_subdevice *s;
243 int data;
244
245 if (!dev->attached) {
246 comedi_error(dev, "spurious interrupt");
247 return IRQ_HANDLED;
248 }
249
250 s = dev->subdevices + 0;
251
252 hi = inb(dev->iobase + DT2814_DATA);
253 lo = inb(dev->iobase + DT2814_DATA);
254
255 data = (hi << 4) | (lo >> 4);
256
257 if (!(--devpriv->ntrig)) {
258 int i;
259
260 outb(0, dev->iobase + DT2814_CSR);
261 /* note: turning off timed mode triggers another
262 sample. */
263
264 for (i = 0; i < DT2814_TIMEOUT; i++) {
265 if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH)
266 break;
267 }
268 inb(dev->iobase + DT2814_DATA);
269 inb(dev->iobase + DT2814_DATA);
270
271 s->async->events |= COMEDI_CB_EOA;
272 }
273 comedi_event(dev, s);
274 return IRQ_HANDLED;
275}
276
263static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it) 277static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it)
264{ 278{
265 int i, irq; 279 int i, irq;
@@ -347,57 +361,21 @@ static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it)
347 return 0; 361 return 0;
348} 362}
349 363
350static int dt2814_detach(struct comedi_device *dev) 364static void dt2814_detach(struct comedi_device *dev)
351{ 365{
352 printk(KERN_INFO "comedi%d: dt2814: remove\n", dev->minor);
353
354 if (dev->irq) 366 if (dev->irq)
355 free_irq(dev->irq, dev); 367 free_irq(dev->irq, dev);
356
357 if (dev->iobase) 368 if (dev->iobase)
358 release_region(dev->iobase, DT2814_SIZE); 369 release_region(dev->iobase, DT2814_SIZE);
359
360 return 0;
361} 370}
362 371
363static irqreturn_t dt2814_interrupt(int irq, void *d) 372static struct comedi_driver dt2814_driver = {
364{ 373 .driver_name = "dt2814",
365 int lo, hi; 374 .module = THIS_MODULE,
366 struct comedi_device *dev = d; 375 .attach = dt2814_attach,
367 struct comedi_subdevice *s; 376 .detach = dt2814_detach,
368 int data; 377};
369 378module_comedi_driver(dt2814_driver);
370 if (!dev->attached) {
371 comedi_error(dev, "spurious interrupt");
372 return IRQ_HANDLED;
373 }
374
375 s = dev->subdevices + 0;
376
377 hi = inb(dev->iobase + DT2814_DATA);
378 lo = inb(dev->iobase + DT2814_DATA);
379
380 data = (hi << 4) | (lo >> 4);
381
382 if (!(--devpriv->ntrig)) {
383 int i;
384
385 outb(0, dev->iobase + DT2814_CSR);
386 /* note: turning off timed mode triggers another
387 sample. */
388
389 for (i = 0; i < DT2814_TIMEOUT; i++) {
390 if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH)
391 break;
392 }
393 inb(dev->iobase + DT2814_DATA);
394 inb(dev->iobase + DT2814_DATA);
395
396 s->async->events |= COMEDI_CB_EOA;
397 }
398 comedi_event(dev, s);
399 return IRQ_HANDLED;
400}
401 379
402MODULE_AUTHOR("Comedi http://www.comedi.org"); 380MODULE_AUTHOR("Comedi http://www.comedi.org");
403MODULE_DESCRIPTION("Comedi low-level driver"); 381MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c
index 4155da43fd51..bbab712be4b9 100644
--- a/drivers/staging/comedi/drivers/dt2815.c
+++ b/drivers/staging/comedi/drivers/dt2815.c
@@ -72,31 +72,6 @@ static const struct comedi_lrange
72#define DT2815_DATA 0 72#define DT2815_DATA 0
73#define DT2815_STATUS 1 73#define DT2815_STATUS 1
74 74
75static int dt2815_attach(struct comedi_device *dev,
76 struct comedi_devconfig *it);
77static int dt2815_detach(struct comedi_device *dev);
78static struct comedi_driver driver_dt2815 = {
79 .driver_name = "dt2815",
80 .module = THIS_MODULE,
81 .attach = dt2815_attach,
82 .detach = dt2815_detach,
83};
84
85static int __init driver_dt2815_init_module(void)
86{
87 return comedi_driver_register(&driver_dt2815);
88}
89
90static void __exit driver_dt2815_cleanup_module(void)
91{
92 comedi_driver_unregister(&driver_dt2815);
93}
94
95module_init(driver_dt2815_init_module);
96module_exit(driver_dt2815_cleanup_module);
97
98static void dt2815_free_resources(struct comedi_device *dev);
99
100struct dt2815_private { 75struct dt2815_private {
101 76
102 const struct comedi_lrange *range_type_list[8]; 77 const struct comedi_lrange *range_type_list[8];
@@ -252,20 +227,19 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
252 return 0; 227 return 0;
253} 228}
254 229
255static void dt2815_free_resources(struct comedi_device *dev) 230static void dt2815_detach(struct comedi_device *dev)
256{ 231{
257 if (dev->iobase) 232 if (dev->iobase)
258 release_region(dev->iobase, DT2815_SIZE); 233 release_region(dev->iobase, DT2815_SIZE);
259} 234}
260 235
261static int dt2815_detach(struct comedi_device *dev) 236static struct comedi_driver dt2815_driver = {
262{ 237 .driver_name = "dt2815",
263 printk(KERN_INFO "comedi%d: dt2815: remove\n", dev->minor); 238 .module = THIS_MODULE,
264 239 .attach = dt2815_attach,
265 dt2815_free_resources(dev); 240 .detach = dt2815_detach,
266 241};
267 return 0; 242module_comedi_driver(dt2815_driver);
268}
269 243
270MODULE_AUTHOR("Comedi http://www.comedi.org"); 244MODULE_AUTHOR("Comedi http://www.comedi.org");
271MODULE_DESCRIPTION("Comedi low-level driver"); 245MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt2817.c b/drivers/staging/comedi/drivers/dt2817.c
index 99c1584153d7..1ee10e7bf1d2 100644
--- a/drivers/staging/comedi/drivers/dt2817.c
+++ b/drivers/staging/comedi/drivers/dt2817.c
@@ -47,29 +47,6 @@ Configuration options:
47#define DT2817_CR 0 47#define DT2817_CR 0
48#define DT2817_DATA 1 48#define DT2817_DATA 1
49 49
50static int dt2817_attach(struct comedi_device *dev,
51 struct comedi_devconfig *it);
52static int dt2817_detach(struct comedi_device *dev);
53static struct comedi_driver driver_dt2817 = {
54 .driver_name = "dt2817",
55 .module = THIS_MODULE,
56 .attach = dt2817_attach,
57 .detach = dt2817_detach,
58};
59
60static int __init driver_dt2817_init_module(void)
61{
62 return comedi_driver_register(&driver_dt2817);
63}
64
65static void __exit driver_dt2817_cleanup_module(void)
66{
67 comedi_driver_unregister(&driver_dt2817);
68}
69
70module_init(driver_dt2817_init_module);
71module_exit(driver_dt2817_cleanup_module);
72
73static int dt2817_dio_insn_config(struct comedi_device *dev, 50static int dt2817_dio_insn_config(struct comedi_device *dev,
74 struct comedi_subdevice *s, 51 struct comedi_subdevice *s,
75 struct comedi_insn *insn, unsigned int *data) 52 struct comedi_insn *insn, unsigned int *data)
@@ -182,16 +159,20 @@ static int dt2817_attach(struct comedi_device *dev, struct comedi_devconfig *it)
182 return 0; 159 return 0;
183} 160}
184 161
185static int dt2817_detach(struct comedi_device *dev) 162static void dt2817_detach(struct comedi_device *dev)
186{ 163{
187 printk(KERN_INFO "comedi%d: dt2817: remove\n", dev->minor);
188
189 if (dev->iobase) 164 if (dev->iobase)
190 release_region(dev->iobase, DT2817_SIZE); 165 release_region(dev->iobase, DT2817_SIZE);
191
192 return 0;
193} 166}
194 167
168static struct comedi_driver dt2817_driver = {
169 .driver_name = "dt2817",
170 .module = THIS_MODULE,
171 .attach = dt2817_attach,
172 .detach = dt2817_detach,
173};
174module_comedi_driver(dt2817_driver);
175
195MODULE_AUTHOR("Comedi http://www.comedi.org"); 176MODULE_AUTHOR("Comedi http://www.comedi.org");
196MODULE_DESCRIPTION("Comedi low-level driver"); 177MODULE_DESCRIPTION("Comedi low-level driver");
197MODULE_LICENSE("GPL"); 178MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
index 95ebc267bb74..736d8facaee8 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -221,136 +221,6 @@ struct dt282x_board {
221 int dabits; 221 int dabits;
222}; 222};
223 223
224static const struct dt282x_board boardtypes[] = {
225 {.name = "dt2821",
226 .adbits = 12,
227 .adchan_se = 16,
228 .adchan_di = 8,
229 .ai_speed = 20000,
230 .ispgl = 0,
231 .dachan = 2,
232 .dabits = 12,
233 },
234 {.name = "dt2821-f",
235 .adbits = 12,
236 .adchan_se = 16,
237 .adchan_di = 8,
238 .ai_speed = 6500,
239 .ispgl = 0,
240 .dachan = 2,
241 .dabits = 12,
242 },
243 {.name = "dt2821-g",
244 .adbits = 12,
245 .adchan_se = 16,
246 .adchan_di = 8,
247 .ai_speed = 4000,
248 .ispgl = 0,
249 .dachan = 2,
250 .dabits = 12,
251 },
252 {.name = "dt2823",
253 .adbits = 16,
254 .adchan_se = 0,
255 .adchan_di = 4,
256 .ai_speed = 10000,
257 .ispgl = 0,
258 .dachan = 2,
259 .dabits = 16,
260 },
261 {.name = "dt2824-pgh",
262 .adbits = 12,
263 .adchan_se = 16,
264 .adchan_di = 8,
265 .ai_speed = 20000,
266 .ispgl = 0,
267 .dachan = 0,
268 .dabits = 0,
269 },
270 {.name = "dt2824-pgl",
271 .adbits = 12,
272 .adchan_se = 16,
273 .adchan_di = 8,
274 .ai_speed = 20000,
275 .ispgl = 1,
276 .dachan = 0,
277 .dabits = 0,
278 },
279 {.name = "dt2825",
280 .adbits = 12,
281 .adchan_se = 16,
282 .adchan_di = 8,
283 .ai_speed = 20000,
284 .ispgl = 1,
285 .dachan = 2,
286 .dabits = 12,
287 },
288 {.name = "dt2827",
289 .adbits = 16,
290 .adchan_se = 0,
291 .adchan_di = 4,
292 .ai_speed = 10000,
293 .ispgl = 0,
294 .dachan = 2,
295 .dabits = 12,
296 },
297 {.name = "dt2828",
298 .adbits = 12,
299 .adchan_se = 4,
300 .adchan_di = 0,
301 .ai_speed = 10000,
302 .ispgl = 0,
303 .dachan = 2,
304 .dabits = 12,
305 },
306 {.name = "dt2829",
307 .adbits = 16,
308 .adchan_se = 8,
309 .adchan_di = 0,
310 .ai_speed = 33250,
311 .ispgl = 0,
312 .dachan = 2,
313 .dabits = 16,
314 },
315 {.name = "dt21-ez",
316 .adbits = 12,
317 .adchan_se = 16,
318 .adchan_di = 8,
319 .ai_speed = 10000,
320 .ispgl = 0,
321 .dachan = 2,
322 .dabits = 12,
323 },
324 {.name = "dt23-ez",
325 .adbits = 16,
326 .adchan_se = 16,
327 .adchan_di = 8,
328 .ai_speed = 10000,
329 .ispgl = 0,
330 .dachan = 0,
331 .dabits = 0,
332 },
333 {.name = "dt24-ez",
334 .adbits = 12,
335 .adchan_se = 16,
336 .adchan_di = 8,
337 .ai_speed = 10000,
338 .ispgl = 0,
339 .dachan = 0,
340 .dabits = 0,
341 },
342 {.name = "dt24-ez-pgl",
343 .adbits = 12,
344 .adchan_se = 16,
345 .adchan_di = 8,
346 .ai_speed = 10000,
347 .ispgl = 1,
348 .dachan = 0,
349 .dabits = 0,
350 },
351};
352
353#define n_boardtypes (sizeof(boardtypes)/sizeof(struct dt282x_board))
354#define this_board ((const struct dt282x_board *)dev->board_ptr) 224#define this_board ((const struct dt282x_board *)dev->board_ptr)
355 225
356struct dt282x_private { 226struct dt282x_private {
@@ -411,33 +281,6 @@ struct dt282x_private {
411 b \ 281 b \
412 } while (0) 282 } while (0)
413 283
414static int dt282x_attach(struct comedi_device *dev,
415 struct comedi_devconfig *it);
416static int dt282x_detach(struct comedi_device *dev);
417static struct comedi_driver driver_dt282x = {
418 .driver_name = "dt282x",
419 .module = THIS_MODULE,
420 .attach = dt282x_attach,
421 .detach = dt282x_detach,
422 .board_name = &boardtypes[0].name,
423 .num_names = n_boardtypes,
424 .offset = sizeof(struct dt282x_board),
425};
426
427static int __init driver_dt282x_init_module(void)
428{
429 return comedi_driver_register(&driver_dt282x);
430}
431
432static void __exit driver_dt282x_cleanup_module(void)
433{
434 comedi_driver_unregister(&driver_dt282x);
435}
436
437module_init(driver_dt282x_init_module);
438module_exit(driver_dt282x_cleanup_module);
439
440static void free_resources(struct comedi_device *dev);
441static int prep_ai_dma(struct comedi_device *dev, int chan, int size); 284static int prep_ai_dma(struct comedi_device *dev, int chan, int size);
442static int prep_ao_dma(struct comedi_device *dev, int chan, int size); 285static int prep_ao_dma(struct comedi_device *dev, int chan, int size);
443static int dt282x_ai_cancel(struct comedi_device *dev, 286static int dt282x_ai_cancel(struct comedi_device *dev,
@@ -1271,6 +1114,52 @@ enum { /* i/o base, irq, dma channels */
1271 opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */ 1114 opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */
1272}; 1115};
1273 1116
1117static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2)
1118{
1119 int ret;
1120
1121 devpriv->usedma = 0;
1122
1123 if (!dma1 && !dma2) {
1124 printk(KERN_ERR " (no dma)");
1125 return 0;
1126 }
1127
1128 if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7)
1129 return -EINVAL;
1130
1131 if (dma2 < dma1) {
1132 int i;
1133 i = dma1;
1134 dma1 = dma2;
1135 dma2 = i;
1136 }
1137
1138 ret = request_dma(dma1, "dt282x A");
1139 if (ret)
1140 return -EBUSY;
1141 devpriv->dma[0].chan = dma1;
1142
1143 ret = request_dma(dma2, "dt282x B");
1144 if (ret)
1145 return -EBUSY;
1146 devpriv->dma[1].chan = dma2;
1147
1148 devpriv->dma_maxsize = PAGE_SIZE;
1149 devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
1150 devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
1151 if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) {
1152 printk(KERN_ERR " can't get DMA memory");
1153 return -ENOMEM;
1154 }
1155
1156 printk(KERN_INFO " (dma=%d,%d)", dma1, dma2);
1157
1158 devpriv->usedma = 1;
1159
1160 return 0;
1161}
1162
1274/* 1163/*
1275 options: 1164 options:
1276 0 i/o base 1165 0 i/o base
@@ -1442,7 +1331,7 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1442 return 0; 1331 return 0;
1443} 1332}
1444 1333
1445static void free_resources(struct comedi_device *dev) 1334static void dt282x_detach(struct comedi_device *dev)
1446{ 1335{
1447 if (dev->irq) 1336 if (dev->irq)
1448 free_irq(dev->irq, dev); 1337 free_irq(dev->irq, dev);
@@ -1460,60 +1349,146 @@ static void free_resources(struct comedi_device *dev)
1460 } 1349 }
1461} 1350}
1462 1351
1463static int dt282x_detach(struct comedi_device *dev) 1352static const struct dt282x_board boardtypes[] = {
1464{ 1353 {
1465 printk(KERN_INFO "comedi%d: dt282x: remove\n", dev->minor); 1354 .name = "dt2821",
1466 1355 .adbits = 12,
1467 free_resources(dev); 1356 .adchan_se = 16,
1468 1357 .adchan_di = 8,
1469 return 0; 1358 .ai_speed = 20000,
1470} 1359 .ispgl = 0,
1471 1360 .dachan = 2,
1472static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2) 1361 .dabits = 12,
1473{ 1362 }, {
1474 int ret; 1363 .name = "dt2821-f",
1475 1364 .adbits = 12,
1476 devpriv->usedma = 0; 1365 .adchan_se = 16,
1477 1366 .adchan_di = 8,
1478 if (!dma1 && !dma2) { 1367 .ai_speed = 6500,
1479 printk(KERN_ERR " (no dma)"); 1368 .ispgl = 0,
1480 return 0; 1369 .dachan = 2,
1481 } 1370 .dabits = 12,
1482 1371 }, {
1483 if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7) 1372 .name = "dt2821-g",
1484 return -EINVAL; 1373 .adbits = 12,
1485 1374 .adchan_se = 16,
1486 if (dma2 < dma1) { 1375 .adchan_di = 8,
1487 int i; 1376 .ai_speed = 4000,
1488 i = dma1; 1377 .ispgl = 0,
1489 dma1 = dma2; 1378 .dachan = 2,
1490 dma2 = i; 1379 .dabits = 12,
1491 } 1380 }, {
1492 1381 .name = "dt2823",
1493 ret = request_dma(dma1, "dt282x A"); 1382 .adbits = 16,
1494 if (ret) 1383 .adchan_se = 0,
1495 return -EBUSY; 1384 .adchan_di = 4,
1496 devpriv->dma[0].chan = dma1; 1385 .ai_speed = 10000,
1497 1386 .ispgl = 0,
1498 ret = request_dma(dma2, "dt282x B"); 1387 .dachan = 2,
1499 if (ret) 1388 .dabits = 16,
1500 return -EBUSY; 1389 }, {
1501 devpriv->dma[1].chan = dma2; 1390 .name = "dt2824-pgh",
1502 1391 .adbits = 12,
1503 devpriv->dma_maxsize = PAGE_SIZE; 1392 .adchan_se = 16,
1504 devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); 1393 .adchan_di = 8,
1505 devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); 1394 .ai_speed = 20000,
1506 if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) { 1395 .ispgl = 0,
1507 printk(KERN_ERR " can't get DMA memory"); 1396 .dachan = 0,
1508 return -ENOMEM; 1397 .dabits = 0,
1509 } 1398 }, {
1510 1399 .name = "dt2824-pgl",
1511 printk(KERN_INFO " (dma=%d,%d)", dma1, dma2); 1400 .adbits = 12,
1512 1401 .adchan_se = 16,
1513 devpriv->usedma = 1; 1402 .adchan_di = 8,
1403 .ai_speed = 20000,
1404 .ispgl = 1,
1405 .dachan = 0,
1406 .dabits = 0,
1407 }, {
1408 .name = "dt2825",
1409 .adbits = 12,
1410 .adchan_se = 16,
1411 .adchan_di = 8,
1412 .ai_speed = 20000,
1413 .ispgl = 1,
1414 .dachan = 2,
1415 .dabits = 12,
1416 }, {
1417 .name = "dt2827",
1418 .adbits = 16,
1419 .adchan_se = 0,
1420 .adchan_di = 4,
1421 .ai_speed = 10000,
1422 .ispgl = 0,
1423 .dachan = 2,
1424 .dabits = 12,
1425 }, {
1426 .name = "dt2828",
1427 .adbits = 12,
1428 .adchan_se = 4,
1429 .adchan_di = 0,
1430 .ai_speed = 10000,
1431 .ispgl = 0,
1432 .dachan = 2,
1433 .dabits = 12,
1434 }, {
1435 .name = "dt2829",
1436 .adbits = 16,
1437 .adchan_se = 8,
1438 .adchan_di = 0,
1439 .ai_speed = 33250,
1440 .ispgl = 0,
1441 .dachan = 2,
1442 .dabits = 16,
1443 }, {
1444 .name = "dt21-ez",
1445 .adbits = 12,
1446 .adchan_se = 16,
1447 .adchan_di = 8,
1448 .ai_speed = 10000,
1449 .ispgl = 0,
1450 .dachan = 2,
1451 .dabits = 12,
1452 }, {
1453 .name = "dt23-ez",
1454 .adbits = 16,
1455 .adchan_se = 16,
1456 .adchan_di = 8,
1457 .ai_speed = 10000,
1458 .ispgl = 0,
1459 .dachan = 0,
1460 .dabits = 0,
1461 }, {
1462 .name = "dt24-ez",
1463 .adbits = 12,
1464 .adchan_se = 16,
1465 .adchan_di = 8,
1466 .ai_speed = 10000,
1467 .ispgl = 0,
1468 .dachan = 0,
1469 .dabits = 0,
1470 }, {
1471 .name = "dt24-ez-pgl",
1472 .adbits = 12,
1473 .adchan_se = 16,
1474 .adchan_di = 8,
1475 .ai_speed = 10000,
1476 .ispgl = 1,
1477 .dachan = 0,
1478 .dabits = 0,
1479 },
1480};
1514 1481
1515 return 0; 1482static struct comedi_driver dt282x_driver = {
1516} 1483 .driver_name = "dt282x",
1484 .module = THIS_MODULE,
1485 .attach = dt282x_attach,
1486 .detach = dt282x_detach,
1487 .board_name = &boardtypes[0].name,
1488 .num_names = ARRAY_SIZE(boardtypes),
1489 .offset = sizeof(struct dt282x_board),
1490};
1491module_comedi_driver(dt282x_driver);
1517 1492
1518MODULE_AUTHOR("Comedi http://www.comedi.org"); 1493MODULE_AUTHOR("Comedi http://www.comedi.org");
1519MODULE_DESCRIPTION("Comedi low-level driver"); 1494MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c
index 0a7979e52999..0d273269b572 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -164,19 +164,6 @@ static const struct dt3k_boardtype dt3k_boardtypes[] = {
164#define n_dt3k_boards sizeof(dt3k_boardtypes)/sizeof(struct dt3k_boardtype) 164#define n_dt3k_boards sizeof(dt3k_boardtypes)/sizeof(struct dt3k_boardtype)
165#define this_board ((const struct dt3k_boardtype *)dev->board_ptr) 165#define this_board ((const struct dt3k_boardtype *)dev->board_ptr)
166 166
167static DEFINE_PCI_DEVICE_TABLE(dt3k_pci_table) = {
168 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0022) },
169 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0027) },
170 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0023) },
171 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0024) },
172 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0028) },
173 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0025) },
174 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0026) },
175 { 0 }
176};
177
178MODULE_DEVICE_TABLE(pci, dt3k_pci_table);
179
180#define DT3000_SIZE (4*0x1000) 167#define DT3000_SIZE (4*0x1000)
181 168
182/* dual-ported RAM location definitions */ 169/* dual-ported RAM location definitions */
@@ -276,54 +263,6 @@ struct dt3k_private {
276 263
277#define devpriv ((struct dt3k_private *)dev->private) 264#define devpriv ((struct dt3k_private *)dev->private)
278 265
279static int dt3000_attach(struct comedi_device *dev,
280 struct comedi_devconfig *it);
281static int dt3000_detach(struct comedi_device *dev);
282static struct comedi_driver driver_dt3000 = {
283 .driver_name = "dt3000",
284 .module = THIS_MODULE,
285 .attach = dt3000_attach,
286 .detach = dt3000_detach,
287};
288
289static int __devinit driver_dt3000_pci_probe(struct pci_dev *dev,
290 const struct pci_device_id *ent)
291{
292 return comedi_pci_auto_config(dev, driver_dt3000.driver_name);
293}
294
295static void __devexit driver_dt3000_pci_remove(struct pci_dev *dev)
296{
297 comedi_pci_auto_unconfig(dev);
298}
299
300static struct pci_driver driver_dt3000_pci_driver = {
301 .id_table = dt3k_pci_table,
302 .probe = &driver_dt3000_pci_probe,
303 .remove = __devexit_p(&driver_dt3000_pci_remove)
304};
305
306static int __init driver_dt3000_init_module(void)
307{
308 int retval;
309
310 retval = comedi_driver_register(&driver_dt3000);
311 if (retval < 0)
312 return retval;
313
314 driver_dt3000_pci_driver.name = (char *)driver_dt3000.driver_name;
315 return pci_register_driver(&driver_dt3000_pci_driver);
316}
317
318static void __exit driver_dt3000_cleanup_module(void)
319{
320 pci_unregister_driver(&driver_dt3000_pci_driver);
321 comedi_driver_unregister(&driver_dt3000);
322}
323
324module_init(driver_dt3000_init_module);
325module_exit(driver_dt3000_cleanup_module);
326
327static void dt3k_ai_empty_fifo(struct comedi_device *dev, 266static void dt3k_ai_empty_fifo(struct comedi_device *dev,
328 struct comedi_subdevice *s); 267 struct comedi_subdevice *s);
329static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *arg, 268static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *arg,
@@ -841,7 +780,77 @@ static int dt3k_mem_insn_read(struct comedi_device *dev,
841 return i; 780 return i;
842} 781}
843 782
844static int dt_pci_probe(struct comedi_device *dev, int bus, int slot); 783static int setup_pci(struct comedi_device *dev)
784{
785 resource_size_t addr;
786 int ret;
787
788 ret = comedi_pci_enable(devpriv->pci_dev, "dt3000");
789 if (ret < 0)
790 return ret;
791
792 addr = pci_resource_start(devpriv->pci_dev, 0);
793 devpriv->phys_addr = addr;
794 devpriv->io_addr = ioremap(devpriv->phys_addr, DT3000_SIZE);
795 if (!devpriv->io_addr)
796 return -ENOMEM;
797#if DEBUG
798 printk("0x%08llx mapped to %p, ",
799 (unsigned long long)devpriv->phys_addr, devpriv->io_addr);
800#endif
801
802 return 0;
803}
804
805static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board)
806{
807 int i;
808
809 for (from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from);
810 from != NULL;
811 from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from)) {
812 for (i = 0; i < n_dt3k_boards; i++) {
813 if (from->device == dt3k_boardtypes[i].device_id) {
814 *board = i;
815 return from;
816 }
817 }
818 printk
819 ("unknown Data Translation PCI device found with device_id=0x%04x\n",
820 from->device);
821 }
822 *board = -1;
823 return from;
824}
825
826static int dt_pci_probe(struct comedi_device *dev, int bus, int slot)
827{
828 int board;
829 int ret;
830 struct pci_dev *pcidev;
831
832 pcidev = NULL;
833 while ((pcidev = dt_pci_find_device(pcidev, &board)) != NULL) {
834 if ((bus == 0 && slot == 0) ||
835 (pcidev->bus->number == bus &&
836 PCI_SLOT(pcidev->devfn) == slot)) {
837 break;
838 }
839 }
840 devpriv->pci_dev = pcidev;
841
842 if (board >= 0)
843 dev->board_ptr = dt3k_boardtypes + board;
844
845 if (!devpriv->pci_dev)
846 return 0;
847
848 ret = setup_pci(dev);
849 if (ret < 0)
850 return ret;
851
852 return 1;
853}
845 854
846static int dt3000_attach(struct comedi_device *dev, struct comedi_devconfig *it) 855static int dt3000_attach(struct comedi_device *dev, struct comedi_devconfig *it)
847{ 856{
@@ -935,11 +944,10 @@ static int dt3000_attach(struct comedi_device *dev, struct comedi_devconfig *it)
935 return 0; 944 return 0;
936} 945}
937 946
938static int dt3000_detach(struct comedi_device *dev) 947static void dt3000_detach(struct comedi_device *dev)
939{ 948{
940 if (dev->irq) 949 if (dev->irq)
941 free_irq(dev->irq, dev); 950 free_irq(dev->irq, dev);
942
943 if (devpriv) { 951 if (devpriv) {
944 if (devpriv->pci_dev) { 952 if (devpriv->pci_dev) {
945 if (devpriv->phys_addr) 953 if (devpriv->phys_addr)
@@ -949,85 +957,45 @@ static int dt3000_detach(struct comedi_device *dev)
949 if (devpriv->io_addr) 957 if (devpriv->io_addr)
950 iounmap(devpriv->io_addr); 958 iounmap(devpriv->io_addr);
951 } 959 }
952 /* XXX */
953
954 return 0;
955} 960}
956 961
957static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board); 962static struct comedi_driver dt3000_driver = {
958static int setup_pci(struct comedi_device *dev); 963 .driver_name = "dt3000",
964 .module = THIS_MODULE,
965 .attach = dt3000_attach,
966 .detach = dt3000_detach,
967};
959 968
960static int dt_pci_probe(struct comedi_device *dev, int bus, int slot) 969static int __devinit dt3000_pci_probe(struct pci_dev *dev,
970 const struct pci_device_id *ent)
961{ 971{
962 int board; 972 return comedi_pci_auto_config(dev, &dt3000_driver);
963 int ret;
964 struct pci_dev *pcidev;
965
966 pcidev = NULL;
967 while ((pcidev = dt_pci_find_device(pcidev, &board)) != NULL) {
968 if ((bus == 0 && slot == 0) ||
969 (pcidev->bus->number == bus &&
970 PCI_SLOT(pcidev->devfn) == slot)) {
971 break;
972 }
973 }
974 devpriv->pci_dev = pcidev;
975
976 if (board >= 0)
977 dev->board_ptr = dt3k_boardtypes + board;
978
979 if (!devpriv->pci_dev)
980 return 0;
981
982 ret = setup_pci(dev);
983 if (ret < 0)
984 return ret;
985
986 return 1;
987} 973}
988 974
989static int setup_pci(struct comedi_device *dev) 975static void __devexit dt3000_pci_remove(struct pci_dev *dev)
990{ 976{
991 resource_size_t addr; 977 comedi_pci_auto_unconfig(dev);
992 int ret;
993
994 ret = comedi_pci_enable(devpriv->pci_dev, "dt3000");
995 if (ret < 0)
996 return ret;
997
998 addr = pci_resource_start(devpriv->pci_dev, 0);
999 devpriv->phys_addr = addr;
1000 devpriv->io_addr = ioremap(devpriv->phys_addr, DT3000_SIZE);
1001 if (!devpriv->io_addr)
1002 return -ENOMEM;
1003#if DEBUG
1004 printk("0x%08llx mapped to %p, ",
1005 (unsigned long long)devpriv->phys_addr, devpriv->io_addr);
1006#endif
1007
1008 return 0;
1009} 978}
1010 979
1011static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board) 980static DEFINE_PCI_DEVICE_TABLE(dt3000_pci_table) = {
1012{ 981 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0022) },
1013 int i; 982 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0027) },
983 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0023) },
984 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0024) },
985 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0028) },
986 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0025) },
987 { PCI_DEVICE(PCI_VENDOR_ID_DT, 0x0026) },
988 { 0 }
989};
990MODULE_DEVICE_TABLE(pci, dt3000_pci_table);
1014 991
1015 for (from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from); 992static struct pci_driver dt3000_pci_driver = {
1016 from != NULL; 993 .name = "dt3000",
1017 from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from)) { 994 .id_table = dt3000_pci_table,
1018 for (i = 0; i < n_dt3k_boards; i++) { 995 .probe = dt3000_pci_probe,
1019 if (from->device == dt3k_boardtypes[i].device_id) { 996 .remove = __devexit_p(dt3000_pci_remove),
1020 *board = i; 997};
1021 return from; 998module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver);
1022 }
1023 }
1024 printk
1025 ("unknown Data Translation PCI device found with device_id=0x%04x\n",
1026 from->device);
1027 }
1028 *board = -1;
1029 return from;
1030}
1031 999
1032MODULE_AUTHOR("Comedi http://www.comedi.org"); 1000MODULE_AUTHOR("Comedi http://www.comedi.org");
1033MODULE_DESCRIPTION("Comedi low-level driver"); 1001MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 89a49dda4482..22cda5c76ce4 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -196,7 +196,7 @@ struct dt9812_flash_data {
196}; 196};
197 197
198#define DT9812_MAX_NUM_MULTI_BYTE_RDS \ 198#define DT9812_MAX_NUM_MULTI_BYTE_RDS \
199 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(u8)) 199 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(u8))
200 200
201struct dt9812_read_multi { 201struct dt9812_read_multi {
202 u8 count; 202 u8 count;
@@ -209,8 +209,8 @@ struct dt9812_write_byte {
209}; 209};
210 210
211#define DT9812_MAX_NUM_MULTI_BYTE_WRTS \ 211#define DT9812_MAX_NUM_MULTI_BYTE_WRTS \
212 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \ 212 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
213 sizeof(struct dt9812_write_byte)) 213 sizeof(struct dt9812_write_byte))
214 214
215struct dt9812_write_multi { 215struct dt9812_write_multi {
216 u8 count; 216 u8 count;
@@ -224,7 +224,8 @@ struct dt9812_rmw_byte {
224}; 224};
225 225
226#define DT9812_MAX_NUM_MULTI_BYTE_RMWS \ 226#define DT9812_MAX_NUM_MULTI_BYTE_RMWS \
227 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(struct dt9812_rmw_byte)) 227 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
228 sizeof(struct dt9812_rmw_byte))
228 229
229struct dt9812_rmw_multi { 230struct dt9812_rmw_multi {
230 u8 count; 231 u8 count;
@@ -365,7 +366,7 @@ static int dt9812_read_info(struct usb_dt9812 *dev, int offset, void *buf,
365} 366}
366 367
367static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count, 368static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count,
368 u8 * address, u8 * value) 369 u8 *address, u8 *value)
369{ 370{
370 struct dt9812_usb_cmd cmd; 371 struct dt9812_usb_cmd cmd;
371 int i, count, retval; 372 int i, count, retval;
@@ -391,8 +392,8 @@ static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count,
391} 392}
392 393
393static int dt9812_write_multiple_registers(struct usb_dt9812 *dev, 394static int dt9812_write_multiple_registers(struct usb_dt9812 *dev,
394 int reg_count, u8 * address, 395 int reg_count, u8 *address,
395 u8 * value) 396 u8 *value)
396{ 397{
397 struct dt9812_usb_cmd cmd; 398 struct dt9812_usb_cmd cmd;
398 int i, count, retval; 399 int i, count, retval;
@@ -430,7 +431,7 @@ static int dt9812_rmw_multiple_registers(struct usb_dt9812 *dev, int reg_count,
430 return retval; 431 return retval;
431} 432}
432 433
433static int dt9812_digital_in(struct slot_dt9812 *slot, u8 * bits) 434static int dt9812_digital_in(struct slot_dt9812 *slot, u8 *bits)
434{ 435{
435 int result = -ENODEV; 436 int result = -ENODEV;
436 437
@@ -476,7 +477,7 @@ static int dt9812_digital_out(struct slot_dt9812 *slot, u8 bits)
476 return result; 477 return result;
477} 478}
478 479
479static int dt9812_digital_out_shadow(struct slot_dt9812 *slot, u8 * bits) 480static int dt9812_digital_out_shadow(struct slot_dt9812 *slot, u8 *bits)
480{ 481{
481 int result = -ENODEV; 482 int result = -ENODEV;
482 483
@@ -552,7 +553,7 @@ static void dt9812_configure_gain(struct usb_dt9812 *dev,
552 } 553 }
553} 554}
554 555
555static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 * value, 556static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 *value,
556 enum dt9812_gain gain) 557 enum dt9812_gain gain)
557{ 558{
558 struct dt9812_rmw_byte rmw[3]; 559 struct dt9812_rmw_byte rmw[3];
@@ -619,7 +620,7 @@ exit:
619} 620}
620 621
621static int dt9812_analog_out_shadow(struct slot_dt9812 *slot, int channel, 622static int dt9812_analog_out_shadow(struct slot_dt9812 *slot, int channel,
622 u16 * value) 623 u16 *value)
623{ 624{
624 int result = -ENODEV; 625 int result = -ENODEV;
625 626
@@ -1110,9 +1111,9 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1110 return 0; 1111 return 0;
1111} 1112}
1112 1113
1113static int dt9812_detach(struct comedi_device *dev) 1114static void dt9812_detach(struct comedi_device *dev)
1114{ 1115{
1115 return 0; 1116 /* Nothing to cleanup */
1116} 1117}
1117 1118
1118static struct comedi_driver dt9812_comedi_driver = { 1119static struct comedi_driver dt9812_comedi_driver = {
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index da8a2bf31657..b0cec7b1b0c9 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -48,17 +48,6 @@
48 48
49static DEFINE_MUTEX(start_stop_sem); 49static DEFINE_MUTEX(start_stop_sem);
50 50
51static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = {
52 { PCI_DEVICE(PCI_VENDOR_ID_DYNALOG, 0x1050) },
53 { 0 }
54};
55
56MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
57
58static int dyna_pci10xx_attach(struct comedi_device *dev,
59 struct comedi_devconfig *it);
60static int dyna_pci10xx_detach(struct comedi_device *dev);
61
62static const struct comedi_lrange range_pci1050_ai = { 3, { 51static const struct comedi_lrange range_pci1050_ai = { 3, {
63 BIP_RANGE(10), 52 BIP_RANGE(10),
64 BIP_RANGE(5), 53 BIP_RANGE(5),
@@ -113,16 +102,6 @@ static const struct boardtype boardtypes[] = {
113 {.name = DRV_NAME}, 102 {.name = DRV_NAME},
114}; 103};
115 104
116static struct comedi_driver driver_dyna_pci10xx = {
117 .driver_name = DRV_NAME,
118 .module = THIS_MODULE,
119 .attach = dyna_pci10xx_attach,
120 .detach = dyna_pci10xx_detach,
121 .board_name = &boardtypes[0].name,
122 .offset = sizeof(struct boardtype),
123 .num_names = ARRAY_SIZE(boardtypes),
124};
125
126struct dyna_pci10xx_private { 105struct dyna_pci10xx_private {
127 struct pci_dev *pci_dev; /* ptr to PCI device */ 106 struct pci_dev *pci_dev; /* ptr to PCI device */
128 char valid; /* card is usable */ 107 char valid; /* card is usable */
@@ -408,54 +387,48 @@ found:
408 return 1; 387 return 1;
409} 388}
410 389
411static int dyna_pci10xx_detach(struct comedi_device *dev) 390static void dyna_pci10xx_detach(struct comedi_device *dev)
412{ 391{
413 if (devpriv && devpriv->pci_dev) { 392 if (devpriv && devpriv->pci_dev) {
414 comedi_pci_disable(devpriv->pci_dev); 393 comedi_pci_disable(devpriv->pci_dev);
415 mutex_destroy(&devpriv->mutex); 394 mutex_destroy(&devpriv->mutex);
416 } 395 }
417
418 return 0;
419} 396}
420 397
421static int __devinit driver_dyna_pci10xx_pci_probe(struct pci_dev *dev, 398static struct comedi_driver dyna_pci10xx_driver = {
422 const struct pci_device_id *ent) 399 .driver_name = "dyna_pci10xx",
400 .module = THIS_MODULE,
401 .attach = dyna_pci10xx_attach,
402 .detach = dyna_pci10xx_detach,
403 .board_name = &boardtypes[0].name,
404 .offset = sizeof(struct boardtype),
405 .num_names = ARRAY_SIZE(boardtypes),
406};
407
408static int __devinit dyna_pci10xx_pci_probe(struct pci_dev *dev,
409 const struct pci_device_id *ent)
423{ 410{
424 return comedi_pci_auto_config(dev, driver_dyna_pci10xx.driver_name); 411 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver);
425} 412}
426 413
427static void __devexit driver_dyna_pci10xx_pci_remove(struct pci_dev *dev) 414static void __devexit dyna_pci10xx_pci_remove(struct pci_dev *dev)
428{ 415{
429 comedi_pci_auto_unconfig(dev); 416 comedi_pci_auto_unconfig(dev);
430} 417}
431 418
432static struct pci_driver driver_dyna_pci10xx_pci_driver = { 419static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = {
433 .id_table = dyna_pci10xx_pci_table, 420 { PCI_DEVICE(PCI_VENDOR_ID_DYNALOG, 0x1050) },
434 .probe = &driver_dyna_pci10xx_pci_probe, 421 { 0 }
435 .remove = __devexit_p(&driver_dyna_pci10xx_pci_remove)
436}; 422};
423MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
437 424
438static int __init driver_dyna_pci10xx_init_module(void) 425static struct pci_driver dyna_pci10xx_pci_driver = {
439{ 426 .name = "dyna_pci10xx",
440 int retval; 427 .id_table = dyna_pci10xx_pci_table,
441 428 .probe = dyna_pci10xx_pci_probe,
442 retval = comedi_driver_register(&driver_dyna_pci10xx); 429 .remove = __devexit_p(dyna_pci10xx_pci_remove),
443 if (retval < 0) 430};
444 return retval; 431module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
445
446 driver_dyna_pci10xx_pci_driver.name =
447 (char *)driver_dyna_pci10xx.driver_name;
448 return pci_register_driver(&driver_dyna_pci10xx_pci_driver);
449}
450
451static void __exit driver_dyna_pci10xx_cleanup_module(void)
452{
453 pci_unregister_driver(&driver_dyna_pci10xx_pci_driver);
454 comedi_driver_unregister(&driver_dyna_pci10xx);
455}
456
457module_init(driver_dyna_pci10xx_init_module);
458module_exit(driver_dyna_pci10xx_cleanup_module);
459 432
460MODULE_LICENSE("GPL"); 433MODULE_LICENSE("GPL");
461MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>"); 434MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
diff --git a/drivers/staging/comedi/drivers/fl512.c b/drivers/staging/comedi/drivers/fl512.c
index 7f49add60b21..d23814450b40 100644
--- a/drivers/staging/comedi/drivers/fl512.c
+++ b/drivers/staging/comedi/drivers/fl512.c
@@ -42,38 +42,6 @@ static const struct comedi_lrange range_fl512 = { 4, {
42 } 42 }
43}; 43};
44 44
45static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it);
46static int fl512_detach(struct comedi_device *dev);
47
48static struct comedi_driver driver_fl512 = {
49 .driver_name = "fl512",
50 .module = THIS_MODULE,
51 .attach = fl512_attach,
52 .detach = fl512_detach,
53};
54
55static int __init driver_fl512_init_module(void)
56{
57 return comedi_driver_register(&driver_fl512);
58}
59
60static void __exit driver_fl512_cleanup_module(void)
61{
62 comedi_driver_unregister(&driver_fl512);
63}
64
65module_init(driver_fl512_init_module);
66module_exit(driver_fl512_cleanup_module);
67
68static int fl512_ai_insn(struct comedi_device *dev,
69 struct comedi_subdevice *s, struct comedi_insn *insn,
70 unsigned int *data);
71static int fl512_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
72 struct comedi_insn *insn, unsigned int *data);
73static int fl512_ao_insn_readback(struct comedi_device *dev,
74 struct comedi_subdevice *s,
75 struct comedi_insn *insn, unsigned int *data);
76
77/* 45/*
78 * fl512_ai_insn : this is the analog input function 46 * fl512_ai_insn : this is the analog input function
79 */ 47 */
@@ -140,9 +108,6 @@ static int fl512_ao_insn_readback(struct comedi_device *dev,
140 return n; 108 return n;
141} 109}
142 110
143/*
144 * start attach
145 */
146static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it) 111static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
147{ 112{
148 unsigned long iobase; 113 unsigned long iobase;
@@ -209,14 +174,20 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
209 return 1; 174 return 1;
210} 175}
211 176
212static int fl512_detach(struct comedi_device *dev) 177static void fl512_detach(struct comedi_device *dev)
213{ 178{
214 if (dev->iobase) 179 if (dev->iobase)
215 release_region(dev->iobase, FL512_SIZE); 180 release_region(dev->iobase, FL512_SIZE);
216 printk(KERN_INFO "comedi%d: fl512: dummy i detach\n", dev->minor);
217 return 0;
218} 181}
219 182
183static struct comedi_driver fl512_driver = {
184 .driver_name = "fl512",
185 .module = THIS_MODULE,
186 .attach = fl512_attach,
187 .detach = fl512_detach,
188};
189module_comedi_driver(fl512_driver);
190
220MODULE_AUTHOR("Comedi http://www.comedi.org"); 191MODULE_AUTHOR("Comedi http://www.comedi.org");
221MODULE_DESCRIPTION("Comedi low-level driver"); 192MODULE_DESCRIPTION("Comedi low-level driver");
222MODULE_LICENSE("GPL"); 193MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index bc020dea141b..8aece08bd0dd 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -53,8 +53,6 @@ support could be added to this driver.
53#include "plx9080.h" 53#include "plx9080.h"
54#include "comedi_fc.h" 54#include "comedi_fc.h"
55 55
56static int hpdi_attach(struct comedi_device *dev, struct comedi_devconfig *it);
57static int hpdi_detach(struct comedi_device *dev);
58static void abort_dma(struct comedi_device *dev, unsigned int channel); 56static void abort_dma(struct comedi_device *dev, unsigned int channel);
59static int hpdi_cmd(struct comedi_device *dev, struct comedi_subdevice *s); 57static int hpdi_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
60static int hpdi_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s, 58static int hpdi_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -287,15 +285,6 @@ static const struct hpdi_board hpdi_boards[] = {
287#endif 285#endif
288}; 286};
289 287
290static DEFINE_PCI_DEVICE_TABLE(hpdi_pci_table) = {
291 {
292 PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX,
293 0x2400, 0, 0, 0}, {
294 0}
295};
296
297MODULE_DEVICE_TABLE(pci, hpdi_pci_table);
298
299static inline struct hpdi_board *board(const struct comedi_device *dev) 288static inline struct hpdi_board *board(const struct comedi_device *dev)
300{ 289{
301 return (struct hpdi_board *)dev->board_ptr; 290 return (struct hpdi_board *)dev->board_ptr;
@@ -338,51 +327,6 @@ static inline struct hpdi_private *priv(struct comedi_device *dev)
338 return dev->private; 327 return dev->private;
339} 328}
340 329
341static struct comedi_driver driver_hpdi = {
342 .driver_name = "gsc_hpdi",
343 .module = THIS_MODULE,
344 .attach = hpdi_attach,
345 .detach = hpdi_detach,
346};
347
348static int __devinit driver_hpdi_pci_probe(struct pci_dev *dev,
349 const struct pci_device_id *ent)
350{
351 return comedi_pci_auto_config(dev, driver_hpdi.driver_name);
352}
353
354static void __devexit driver_hpdi_pci_remove(struct pci_dev *dev)
355{
356 comedi_pci_auto_unconfig(dev);
357}
358
359static struct pci_driver driver_hpdi_pci_driver = {
360 .id_table = hpdi_pci_table,
361 .probe = &driver_hpdi_pci_probe,
362 .remove = __devexit_p(&driver_hpdi_pci_remove)
363};
364
365static int __init driver_hpdi_init_module(void)
366{
367 int retval;
368
369 retval = comedi_driver_register(&driver_hpdi);
370 if (retval < 0)
371 return retval;
372
373 driver_hpdi_pci_driver.name = (char *)driver_hpdi.driver_name;
374 return pci_register_driver(&driver_hpdi_pci_driver);
375}
376
377static void __exit driver_hpdi_cleanup_module(void)
378{
379 pci_unregister_driver(&driver_hpdi_pci_driver);
380 comedi_driver_unregister(&driver_hpdi);
381}
382
383module_init(driver_hpdi_init_module);
384module_exit(driver_hpdi_cleanup_module);
385
386static int dio_config_insn(struct comedi_device *dev, 330static int dio_config_insn(struct comedi_device *dev,
387 struct comedi_subdevice *s, struct comedi_insn *insn, 331 struct comedi_subdevice *s, struct comedi_insn *insn,
388 unsigned int *data) 332 unsigned int *data)
@@ -645,7 +589,7 @@ static int hpdi_attach(struct comedi_device *dev, struct comedi_devconfig *it)
645 "gsc_hpdi: found %s on bus %i, slot %i\n", board(dev)->name, 589 "gsc_hpdi: found %s on bus %i, slot %i\n", board(dev)->name,
646 pcidev->bus->number, PCI_SLOT(pcidev->devfn)); 590 pcidev->bus->number, PCI_SLOT(pcidev->devfn));
647 591
648 if (comedi_pci_enable(pcidev, driver_hpdi.driver_name)) { 592 if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
649 printk(KERN_WARNING 593 printk(KERN_WARNING
650 " failed enable PCI device and request regions\n"); 594 " failed enable PCI device and request regions\n");
651 return -EIO; 595 return -EIO;
@@ -679,7 +623,7 @@ static int hpdi_attach(struct comedi_device *dev, struct comedi_devconfig *it)
679 623
680 /* get irq */ 624 /* get irq */
681 if (request_irq(pcidev->irq, handle_interrupt, IRQF_SHARED, 625 if (request_irq(pcidev->irq, handle_interrupt, IRQF_SHARED,
682 driver_hpdi.driver_name, dev)) { 626 dev->driver->driver_name, dev)) {
683 printk(KERN_WARNING 627 printk(KERN_WARNING
684 " unable to allocate irq %u\n", pcidev->irq); 628 " unable to allocate irq %u\n", pcidev->irq);
685 return -EINVAL; 629 return -EINVAL;
@@ -720,12 +664,10 @@ static int hpdi_attach(struct comedi_device *dev, struct comedi_devconfig *it)
720 return init_hpdi(dev); 664 return init_hpdi(dev);
721} 665}
722 666
723static int hpdi_detach(struct comedi_device *dev) 667static void hpdi_detach(struct comedi_device *dev)
724{ 668{
725 unsigned int i; 669 unsigned int i;
726 670
727 printk(KERN_WARNING "comedi%d: gsc_hpdi: remove\n", dev->minor);
728
729 if (dev->irq) 671 if (dev->irq)
730 free_irq(dev->irq, dev); 672 free_irq(dev->irq, dev);
731 if ((priv(dev)) && (priv(dev)->hw_dev)) { 673 if ((priv(dev)) && (priv(dev)->hw_dev)) {
@@ -758,7 +700,6 @@ static int hpdi_detach(struct comedi_device *dev)
758 comedi_pci_disable(priv(dev)->hw_dev); 700 comedi_pci_disable(priv(dev)->hw_dev);
759 pci_dev_put(priv(dev)->hw_dev); 701 pci_dev_put(priv(dev)->hw_dev);
760 } 702 }
761 return 0;
762} 703}
763 704
764static int dio_config_block_size(struct comedi_device *dev, unsigned int *data) 705static int dio_config_block_size(struct comedi_device *dev, unsigned int *data)
@@ -1113,6 +1054,39 @@ static int hpdi_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1113 return 0; 1054 return 0;
1114} 1055}
1115 1056
1057static struct comedi_driver gsc_hpdi_driver = {
1058 .driver_name = "gsc_hpdi",
1059 .module = THIS_MODULE,
1060 .attach = hpdi_attach,
1061 .detach = hpdi_detach,
1062};
1063
1064static int __devinit gsc_hpdi_pci_probe(struct pci_dev *dev,
1065 const struct pci_device_id *ent)
1066{
1067 return comedi_pci_auto_config(dev, &gsc_hpdi_driver);
1068}
1069
1070static void __devexit gsc_hpdi_pci_remove(struct pci_dev *dev)
1071{
1072 comedi_pci_auto_unconfig(dev);
1073}
1074
1075static DEFINE_PCI_DEVICE_TABLE(gsc_hpdi_pci_table) = {
1076 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX,
1077 0x2400, 0, 0, 0},
1078 { 0 }
1079};
1080MODULE_DEVICE_TABLE(pci, gsc_hpdi_pci_table);
1081
1082static struct pci_driver gsc_hpdi_pci_driver = {
1083 .name = "gsc_hpdi",
1084 .id_table = gsc_hpdi_pci_table,
1085 .probe = gsc_hpdi_pci_probe,
1086 .remove = __devexit_p(gsc_hpdi_pci_remove)
1087};
1088module_comedi_pci_driver(gsc_hpdi_driver, gsc_hpdi_pci_driver);
1089
1116MODULE_AUTHOR("Comedi http://www.comedi.org"); 1090MODULE_AUTHOR("Comedi http://www.comedi.org");
1117MODULE_DESCRIPTION("Comedi low-level driver"); 1091MODULE_DESCRIPTION("Comedi low-level driver");
1118MODULE_LICENSE("GPL"); 1092MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c
index 126550f3c02b..fdc596fb0990 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -121,15 +121,6 @@ static const char range_codes_analog[] = { 0x00, 0x20, 0x10, 0x30 };
121 121
122/* 122/*
123============================================================================== 123==============================================================================
124 Forward declarations
125==============================================================================
126*/
127static int icp_multi_attach(struct comedi_device *dev,
128 struct comedi_devconfig *it);
129static int icp_multi_detach(struct comedi_device *dev);
130
131/*
132==============================================================================
133 Data & Structure declarations 124 Data & Structure declarations
134============================================================================== 125==============================================================================
135*/ 126*/
@@ -154,50 +145,6 @@ struct boardtype {
154 const struct comedi_lrange *rangelist_ao; /* rangelist for D/A */ 145 const struct comedi_lrange *rangelist_ao; /* rangelist for D/A */
155}; 146};
156 147
157static const struct boardtype boardtypes[] = {
158 {"icp_multi", /* Driver name */
159 DEVICE_ID, /* PCI device ID */
160 IORANGE_ICP_MULTI, /* I/O range length */
161 1, /* 1=Card supports interrupts */
162 TYPE_ICP_MULTI, /* Card type = ICP MULTI */
163 16, /* Num of A/D channels */
164 8, /* Num of A/D channels in diff mode */
165 4, /* Num of D/A channels */
166 16, /* Num of digital inputs */
167 8, /* Num of digital outputs */
168 4, /* Num of counters */
169 0x0fff, /* Resolution of A/D */
170 0x0fff, /* Resolution of D/A */
171 &range_analog, /* Rangelist for A/D */
172 range_codes_analog, /* Range codes for programming */
173 &range_analog}, /* Rangelist for D/A */
174};
175
176#define n_boardtypes (sizeof(boardtypes)/sizeof(struct boardtype))
177
178static struct comedi_driver driver_icp_multi = {
179 .driver_name = "icp_multi",
180 .module = THIS_MODULE,
181 .attach = icp_multi_attach,
182 .detach = icp_multi_detach,
183 .num_names = n_boardtypes,
184 .board_name = &boardtypes[0].name,
185 .offset = sizeof(struct boardtype),
186};
187
188static int __init driver_icp_multi_init_module(void)
189{
190 return comedi_driver_register(&driver_icp_multi);
191}
192
193static void __exit driver_icp_multi_cleanup_module(void)
194{
195 comedi_driver_unregister(&driver_icp_multi);
196}
197
198module_init(driver_icp_multi_init_module);
199module_exit(driver_icp_multi_cleanup_module);
200
201struct icp_multi_private { 148struct icp_multi_private {
202 struct pcilst_struct *card; /* pointer to card */ 149 struct pcilst_struct *card; /* pointer to card */
203 char valid; /* card is usable */ 150 char valid; /* card is usable */
@@ -222,25 +169,81 @@ struct icp_multi_private {
222 169
223/* 170/*
224============================================================================== 171==============================================================================
225 More forward declarations 172
173Name: setup_channel_list
174
175Description:
176 This function sets the appropriate channel selection,
177 differential input mode and range bits in the ADC Command/
178 Status register.
179
180Parameters:
181 struct comedi_device *dev Pointer to current service structure
182 struct comedi_subdevice *s Pointer to current subdevice structure
183 unsigned int *chanlist Pointer to packed channel list
184 unsigned int n_chan Number of channels to scan
185
186Returns:Void
187
226============================================================================== 188==============================================================================
227*/ 189*/
228
229#if 0
230static int check_channel_list(struct comedi_device *dev,
231 struct comedi_subdevice *s,
232 unsigned int *chanlist, unsigned int n_chan);
233#endif
234static void setup_channel_list(struct comedi_device *dev, 190static void setup_channel_list(struct comedi_device *dev,
235 struct comedi_subdevice *s, 191 struct comedi_subdevice *s,
236 unsigned int *chanlist, unsigned int n_chan); 192 unsigned int *chanlist, unsigned int n_chan)
237static int icp_multi_reset(struct comedi_device *dev); 193{
194 unsigned int i, range, chanprog;
195 unsigned int diff;
238 196
239/* 197#ifdef ICP_MULTI_EXTDEBUG
240============================================================================== 198 printk(KERN_DEBUG
241 Functions 199 "icp multi EDBG: setup_channel_list(...,%d)\n", n_chan);
242============================================================================== 200#endif
243*/ 201 devpriv->act_chanlist_len = n_chan;
202 devpriv->act_chanlist_pos = 0;
203
204 for (i = 0; i < n_chan; i++) {
205 /* Get channel */
206 chanprog = CR_CHAN(chanlist[i]);
207
208 /* Determine if it is a differential channel (Bit 15 = 1) */
209 if (CR_AREF(chanlist[i]) == AREF_DIFF) {
210 diff = 1;
211 chanprog &= 0x0007;
212 } else {
213 diff = 0;
214 chanprog &= 0x000f;
215 }
216
217 /* Clear channel, range and input mode bits
218 * in A/D command/status register */
219 devpriv->AdcCmdStatus &= 0xf00f;
220
221 /* Set channel number and differential mode status bit */
222 if (diff) {
223 /* Set channel number, bits 9-11 & mode, bit 6 */
224 devpriv->AdcCmdStatus |= (chanprog << 9);
225 devpriv->AdcCmdStatus |= ADC_DI;
226 } else
227 /* Set channel number, bits 8-11 */
228 devpriv->AdcCmdStatus |= (chanprog << 8);
229
230 /* Get range for current channel */
231 range = this_board->rangecode[CR_RANGE(chanlist[i])];
232 /* Set range. bits 4-5 */
233 devpriv->AdcCmdStatus |= range;
234
235 /* Output channel, range, mode to ICP Multi */
236 writew(devpriv->AdcCmdStatus,
237 devpriv->io_addr + ICP_MULTI_ADC_CSR);
238
239#ifdef ICP_MULTI_EXTDEBUG
240 printk(KERN_DEBUG
241 "GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range,
242 devpriv->act_chanlist[i]);
243#endif
244 }
245
246}
244 247
245/* 248/*
246============================================================================== 249==============================================================================
@@ -764,84 +767,6 @@ static int check_channel_list(struct comedi_device *dev,
764/* 767/*
765============================================================================== 768==============================================================================
766 769
767Name: setup_channel_list
768
769Description:
770 This function sets the appropriate channel selection,
771 differential input mode and range bits in the ADC Command/
772 Status register.
773
774Parameters:
775 struct comedi_device *dev Pointer to current service structure
776 struct comedi_subdevice *s Pointer to current subdevice structure
777 unsigned int *chanlist Pointer to packed channel list
778 unsigned int n_chan Number of channels to scan
779
780Returns:Void
781
782==============================================================================
783*/
784static void setup_channel_list(struct comedi_device *dev,
785 struct comedi_subdevice *s,
786 unsigned int *chanlist, unsigned int n_chan)
787{
788 unsigned int i, range, chanprog;
789 unsigned int diff;
790
791#ifdef ICP_MULTI_EXTDEBUG
792 printk(KERN_DEBUG
793 "icp multi EDBG: setup_channel_list(...,%d)\n", n_chan);
794#endif
795 devpriv->act_chanlist_len = n_chan;
796 devpriv->act_chanlist_pos = 0;
797
798 for (i = 0; i < n_chan; i++) {
799 /* Get channel */
800 chanprog = CR_CHAN(chanlist[i]);
801
802 /* Determine if it is a differential channel (Bit 15 = 1) */
803 if (CR_AREF(chanlist[i]) == AREF_DIFF) {
804 diff = 1;
805 chanprog &= 0x0007;
806 } else {
807 diff = 0;
808 chanprog &= 0x000f;
809 }
810
811 /* Clear channel, range and input mode bits
812 * in A/D command/status register */
813 devpriv->AdcCmdStatus &= 0xf00f;
814
815 /* Set channel number and differential mode status bit */
816 if (diff) {
817 /* Set channel number, bits 9-11 & mode, bit 6 */
818 devpriv->AdcCmdStatus |= (chanprog << 9);
819 devpriv->AdcCmdStatus |= ADC_DI;
820 } else
821 /* Set channel number, bits 8-11 */
822 devpriv->AdcCmdStatus |= (chanprog << 8);
823
824 /* Get range for current channel */
825 range = this_board->rangecode[CR_RANGE(chanlist[i])];
826 /* Set range. bits 4-5 */
827 devpriv->AdcCmdStatus |= range;
828
829 /* Output channel, range, mode to ICP Multi */
830 writew(devpriv->AdcCmdStatus,
831 devpriv->io_addr + ICP_MULTI_ADC_CSR);
832
833#ifdef ICP_MULTI_EXTDEBUG
834 printk(KERN_DEBUG
835 "GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range,
836 devpriv->act_chanlist[i]);
837#endif
838 }
839
840}
841
842/*
843==============================================================================
844
845Name: icp_multi_reset 770Name: icp_multi_reset
846 771
847Description: 772Description:
@@ -897,23 +822,6 @@ static int icp_multi_reset(struct comedi_device *dev)
897 return 0; 822 return 0;
898} 823}
899 824
900/*
901==============================================================================
902
903Name: icp_multi_attach
904
905Description:
906 This function sets up all the appropriate data for the current
907 device.
908
909Parameters:
910 struct comedi_device *dev Pointer to current device structure
911 struct comedi_devconfig *it Pointer to current device configuration
912
913Returns:int 0 = success
914
915==============================================================================
916*/
917static int icp_multi_attach(struct comedi_device *dev, 825static int icp_multi_attach(struct comedi_device *dev,
918 struct comedi_devconfig *it) 826 struct comedi_devconfig *it)
919{ 827{
@@ -1099,44 +1007,53 @@ static int icp_multi_attach(struct comedi_device *dev,
1099 return 0; 1007 return 0;
1100} 1008}
1101 1009
1102/* 1010static void icp_multi_detach(struct comedi_device *dev)
1103==============================================================================
1104
1105Name: icp_multi_detach
1106
1107Description:
1108 This function releases all the resources used by the current
1109 device.
1110
1111Parameters:
1112 struct comedi_device *dev Pointer to current device structure
1113
1114Returns:int 0 = success
1115
1116==============================================================================
1117*/
1118static int icp_multi_detach(struct comedi_device *dev)
1119{ 1011{
1120
1121 if (dev->private) 1012 if (dev->private)
1122 if (devpriv->valid) 1013 if (devpriv->valid)
1123 icp_multi_reset(dev); 1014 icp_multi_reset(dev);
1124
1125 if (dev->irq) 1015 if (dev->irq)
1126 free_irq(dev->irq, dev); 1016 free_irq(dev->irq, dev);
1127
1128 if (dev->private && devpriv->io_addr) 1017 if (dev->private && devpriv->io_addr)
1129 iounmap(devpriv->io_addr); 1018 iounmap(devpriv->io_addr);
1130
1131 if (dev->private && devpriv->card) 1019 if (dev->private && devpriv->card)
1132 pci_card_free(devpriv->card); 1020 pci_card_free(devpriv->card);
1133
1134 if (--pci_list_builded == 0) 1021 if (--pci_list_builded == 0)
1135 pci_card_list_cleanup(PCI_VENDOR_ID_ICP); 1022 pci_card_list_cleanup(PCI_VENDOR_ID_ICP);
1136
1137 return 0;
1138} 1023}
1139 1024
1025static const struct boardtype boardtypes[] = {
1026 {
1027 .name = "icp_multi",
1028 .device_id = DEVICE_ID,
1029 .iorange = IORANGE_ICP_MULTI,
1030 .have_irq = 1,
1031 .cardtype = TYPE_ICP_MULTI,
1032 .n_aichan = 16,
1033 .n_aichand = 8,
1034 .n_aochan = 4,
1035 .n_dichan = 16,
1036 .n_dochan = 8,
1037 .n_ctrs = 4,
1038 .ai_maxdata = 0x0fff,
1039 .ao_maxdata = 0x0fff,
1040 .rangelist_ai = &range_analog,
1041 .rangecode = range_codes_analog,
1042 .rangelist_ao = &range_analog,
1043 },
1044};
1045
1046static struct comedi_driver icp_multi_driver = {
1047 .driver_name = "icp_multi",
1048 .module = THIS_MODULE,
1049 .attach = icp_multi_attach,
1050 .detach = icp_multi_detach,
1051 .num_names = ARRAY_SIZE(boardtypes),
1052 .board_name = &boardtypes[0].name,
1053 .offset = sizeof(struct boardtype),
1054};
1055module_comedi_driver(icp_multi_driver);
1056
1140MODULE_AUTHOR("Comedi http://www.comedi.org"); 1057MODULE_AUTHOR("Comedi http://www.comedi.org");
1141MODULE_DESCRIPTION("Comedi low-level driver"); 1058MODULE_DESCRIPTION("Comedi low-level driver");
1142MODULE_LICENSE("GPL"); 1059MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index e4711ef54719..f0a579a04a7d 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -159,17 +159,6 @@ struct pci20xxx_private {
159#define devpriv ((struct pci20xxx_private *)dev->private) 159#define devpriv ((struct pci20xxx_private *)dev->private)
160#define CHAN (CR_CHAN(it->chanlist[0])) 160#define CHAN (CR_CHAN(it->chanlist[0]))
161 161
162static int pci20xxx_attach(struct comedi_device *dev,
163 struct comedi_devconfig *it);
164static int pci20xxx_detach(struct comedi_device *dev);
165
166static struct comedi_driver driver_pci20xxx = {
167 .driver_name = "ii_pci20kc",
168 .module = THIS_MODULE,
169 .attach = pci20xxx_attach,
170 .detach = pci20xxx_detach,
171};
172
173static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s, 162static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s,
174 int opt0, int opt1); 163 int opt0, int opt1);
175static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s, 164static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -275,11 +264,9 @@ static int pci20xxx_attach(struct comedi_device *dev,
275 return 1; 264 return 1;
276} 265}
277 266
278static int pci20xxx_detach(struct comedi_device *dev) 267static void pci20xxx_detach(struct comedi_device *dev)
279{ 268{
280 printk(KERN_INFO "comedi%d: pci20xxx: remove\n", dev->minor); 269 /* Nothing to cleanup */
281
282 return 0;
283} 270}
284 271
285/* pci20006m */ 272/* pci20006m */
@@ -666,18 +653,13 @@ static unsigned int pci20xxx_di(struct comedi_device *dev,
666} 653}
667#endif 654#endif
668 655
669static int __init driver_pci20xxx_init_module(void) 656static struct comedi_driver pci20xxx_driver = {
670{ 657 .driver_name = "ii_pci20kc",
671 return comedi_driver_register(&driver_pci20xxx); 658 .module = THIS_MODULE,
672} 659 .attach = pci20xxx_attach,
673 660 .detach = pci20xxx_detach,
674static void __exit driver_pci20xxx_cleanup_module(void) 661};
675{ 662module_comedi_driver(pci20xxx_driver);
676 comedi_driver_unregister(&driver_pci20xxx);
677}
678
679module_init(driver_pci20xxx_init_module);
680module_exit(driver_pci20xxx_cleanup_module);
681 663
682MODULE_AUTHOR("Comedi http://www.comedi.org"); 664MODULE_AUTHOR("Comedi http://www.comedi.org");
683MODULE_DESCRIPTION("Comedi low-level driver"); 665MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
index 6a79ba10630d..d536a11edb95 100644
--- a/drivers/staging/comedi/drivers/jr3_pci.c
+++ b/drivers/staging/comedi/drivers/jr3_pci.c
@@ -59,28 +59,6 @@ Devices: [JR3] PCI force sensor board (jr3_pci)
59#define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113 59#define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113
60#define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114 60#define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114
61 61
62static int jr3_pci_attach(struct comedi_device *dev,
63 struct comedi_devconfig *it);
64static int jr3_pci_detach(struct comedi_device *dev);
65
66static struct comedi_driver driver_jr3_pci = {
67 .driver_name = "jr3_pci",
68 .module = THIS_MODULE,
69 .attach = jr3_pci_attach,
70 .detach = jr3_pci_detach,
71};
72
73static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = {
74 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL) },
75 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW) },
76 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL) },
77 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL) },
78 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_4_CHANNEL) },
79 {0}
80};
81
82MODULE_DEVICE_TABLE(pci, jr3_pci_pci_table);
83
84struct jr3_pci_dev_private { 62struct jr3_pci_dev_private {
85 63
86 struct pci_dev *pci_dev; 64 struct pci_dev *pci_dev;
@@ -948,9 +926,7 @@ out:
948 return result; 926 return result;
949} 927}
950 928
951MODULE_FIRMWARE("comedi/jr3pci.idm"); 929static void jr3_pci_detach(struct comedi_device *dev)
952
953static int jr3_pci_detach(struct comedi_device *dev)
954{ 930{
955 int i; 931 int i;
956 struct jr3_pci_dev_private *devpriv = dev->private; 932 struct jr3_pci_dev_private *devpriv = dev->private;
@@ -962,56 +938,52 @@ static int jr3_pci_detach(struct comedi_device *dev)
962 for (i = 0; i < devpriv->n_channels; i++) 938 for (i = 0; i < devpriv->n_channels; i++)
963 kfree(dev->subdevices[i].private); 939 kfree(dev->subdevices[i].private);
964 } 940 }
965
966 if (devpriv->iobase) 941 if (devpriv->iobase)
967 iounmap((void *)devpriv->iobase); 942 iounmap((void *)devpriv->iobase);
968 if (devpriv->pci_enabled) 943 if (devpriv->pci_enabled)
969 comedi_pci_disable(devpriv->pci_dev); 944 comedi_pci_disable(devpriv->pci_dev);
970
971 if (devpriv->pci_dev) 945 if (devpriv->pci_dev)
972 pci_dev_put(devpriv->pci_dev); 946 pci_dev_put(devpriv->pci_dev);
973 } 947 }
974 return 0;
975} 948}
976 949
977static int __devinit driver_jr3_pci_pci_probe(struct pci_dev *dev, 950static struct comedi_driver jr3_pci_driver = {
978 const struct pci_device_id *ent) 951 .driver_name = "jr3_pci",
952 .module = THIS_MODULE,
953 .attach = jr3_pci_attach,
954 .detach = jr3_pci_detach,
955};
956
957static int __devinit jr3_pci_pci_probe(struct pci_dev *dev,
958 const struct pci_device_id *ent)
979{ 959{
980 return comedi_pci_auto_config(dev, driver_jr3_pci.driver_name); 960 return comedi_pci_auto_config(dev, &jr3_pci_driver);
981} 961}
982 962
983static void __devexit driver_jr3_pci_pci_remove(struct pci_dev *dev) 963static void __devexit jr3_pci_pci_remove(struct pci_dev *dev)
984{ 964{
985 comedi_pci_auto_unconfig(dev); 965 comedi_pci_auto_unconfig(dev);
986} 966}
987 967
988static struct pci_driver driver_jr3_pci_pci_driver = { 968static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = {
989 .id_table = jr3_pci_pci_table, 969 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL) },
990 .probe = &driver_jr3_pci_pci_probe, 970 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW) },
991 .remove = __devexit_p(&driver_jr3_pci_pci_remove) 971 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL) },
972 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL) },
973 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_4_CHANNEL) },
974 { 0 }
992}; 975};
976MODULE_DEVICE_TABLE(pci, jr3_pci_pci_table);
993 977
994static int __init driver_jr3_pci_init_module(void) 978static struct pci_driver jr3_pci_pci_driver = {
995{ 979 .name = "jr3_pci",
996 int retval; 980 .id_table = jr3_pci_pci_table,
997 981 .probe = jr3_pci_pci_probe,
998 retval = comedi_driver_register(&driver_jr3_pci); 982 .remove = __devexit_p(jr3_pci_pci_remove),
999 if (retval < 0) 983};
1000 return retval; 984module_comedi_pci_driver(jr3_pci_driver, jr3_pci_pci_driver);
1001
1002 driver_jr3_pci_pci_driver.name = (char *)driver_jr3_pci.driver_name;
1003 return pci_register_driver(&driver_jr3_pci_pci_driver);
1004}
1005
1006static void __exit driver_jr3_pci_cleanup_module(void)
1007{
1008 pci_unregister_driver(&driver_jr3_pci_pci_driver);
1009 comedi_driver_unregister(&driver_jr3_pci);
1010}
1011
1012module_init(driver_jr3_pci_init_module);
1013module_exit(driver_jr3_pci_cleanup_module);
1014 985
1015MODULE_AUTHOR("Comedi http://www.comedi.org"); 986MODULE_AUTHOR("Comedi http://www.comedi.org");
1016MODULE_DESCRIPTION("Comedi low-level driver"); 987MODULE_DESCRIPTION("Comedi low-level driver");
1017MODULE_LICENSE("GPL"); 988MODULE_LICENSE("GPL");
989MODULE_FIRMWARE("comedi/jr3pci.idm");
diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c
index 4e9e9a078652..09d191844bf8 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -46,18 +46,6 @@ Kolter Electronic PCI Counter Card.
46#define PCI_VENDOR_ID_KOLTER 0x1001 46#define PCI_VENDOR_ID_KOLTER 0x1001
47#define CNT_CARD_DEVICE_ID 0x0014 47#define CNT_CARD_DEVICE_ID 0x0014
48 48
49/*-- function prototypes ----------------------------------------------------*/
50
51static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it);
52static int cnt_detach(struct comedi_device *dev);
53
54static DEFINE_PCI_DEVICE_TABLE(cnt_pci_table) = {
55 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
56 {0}
57};
58
59MODULE_DEVICE_TABLE(pci, cnt_pci_table);
60
61/*-- board specification structure ------------------------------------------*/ 49/*-- board specification structure ------------------------------------------*/
62 50
63struct cnt_board_struct { 51struct cnt_board_struct {
@@ -87,51 +75,6 @@ struct cnt_device_private {
87 75
88#define devpriv ((struct cnt_device_private *)dev->private) 76#define devpriv ((struct cnt_device_private *)dev->private)
89 77
90static struct comedi_driver cnt_driver = {
91 .driver_name = CNT_DRIVER_NAME,
92 .module = THIS_MODULE,
93 .attach = cnt_attach,
94 .detach = cnt_detach,
95};
96
97static int __devinit cnt_driver_pci_probe(struct pci_dev *dev,
98 const struct pci_device_id *ent)
99{
100 return comedi_pci_auto_config(dev, cnt_driver.driver_name);
101}
102
103static void __devexit cnt_driver_pci_remove(struct pci_dev *dev)
104{
105 comedi_pci_auto_unconfig(dev);
106}
107
108static struct pci_driver cnt_driver_pci_driver = {
109 .id_table = cnt_pci_table,
110 .probe = &cnt_driver_pci_probe,
111 .remove = __devexit_p(&cnt_driver_pci_remove)
112};
113
114static int __init cnt_driver_init_module(void)
115{
116 int retval;
117
118 retval = comedi_driver_register(&cnt_driver);
119 if (retval < 0)
120 return retval;
121
122 cnt_driver_pci_driver.name = (char *)cnt_driver.driver_name;
123 return pci_register_driver(&cnt_driver_pci_driver);
124}
125
126static void __exit cnt_driver_cleanup_module(void)
127{
128 pci_unregister_driver(&cnt_driver_pci_driver);
129 comedi_driver_unregister(&cnt_driver);
130}
131
132module_init(cnt_driver_init_module);
133module_exit(cnt_driver_cleanup_module);
134
135/*-- counter write ----------------------------------------------------------*/ 78/*-- counter write ----------------------------------------------------------*/
136 79
137/* This should be used only for resetting the counters; maybe it is better 80/* This should be used only for resetting the counters; maybe it is better
@@ -181,8 +124,6 @@ static int cnt_rinsn(struct comedi_device *dev,
181 return 1; 124 return 1;
182} 125}
183 126
184/*-- attach -----------------------------------------------------------------*/
185
186static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it) 127static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
187{ 128{
188 struct comedi_subdevice *subdevice; 129 struct comedi_subdevice *subdevice;
@@ -278,20 +219,47 @@ found:
278 return 0; 219 return 0;
279} 220}
280 221
281/*-- detach -----------------------------------------------------------------*/ 222static void cnt_detach(struct comedi_device *dev)
282
283static int cnt_detach(struct comedi_device *dev)
284{ 223{
285 if (devpriv && devpriv->pcidev) { 224 if (devpriv && devpriv->pcidev) {
286 if (dev->iobase) 225 if (dev->iobase)
287 comedi_pci_disable(devpriv->pcidev); 226 comedi_pci_disable(devpriv->pcidev);
288 pci_dev_put(devpriv->pcidev); 227 pci_dev_put(devpriv->pcidev);
289 } 228 }
290 printk(KERN_INFO "comedi%d: " CNT_DRIVER_NAME " remove\n",
291 dev->minor);
292 return 0;
293} 229}
294 230
231static struct comedi_driver ke_counter_driver = {
232 .driver_name = "ke_counter",
233 .module = THIS_MODULE,
234 .attach = cnt_attach,
235 .detach = cnt_detach,
236};
237
238static int __devinit ke_counter_pci_probe(struct pci_dev *dev,
239 const struct pci_device_id *ent)
240{
241 return comedi_pci_auto_config(dev, &ke_counter_driver);
242}
243
244static void __devexit ke_counter_pci_remove(struct pci_dev *dev)
245{
246 comedi_pci_auto_unconfig(dev);
247}
248
249static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
250 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
251 { 0 }
252};
253MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
254
255static struct pci_driver ke_counter_pci_driver = {
256 .name = "ke_counter",
257 .id_table = ke_counter_pci_table,
258 .probe = ke_counter_pci_probe,
259 .remove = __devexit_p(ke_counter_pci_remove),
260};
261module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
262
295MODULE_AUTHOR("Comedi http://www.comedi.org"); 263MODULE_AUTHOR("Comedi http://www.comedi.org");
296MODULE_DESCRIPTION("Comedi low-level driver"); 264MODULE_DESCRIPTION("Comedi low-level driver");
297MODULE_LICENSE("GPL"); 265MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c
index b0bc6bb877ab..8ca1b54600db 100644
--- a/drivers/staging/comedi/drivers/me4000.c
+++ b/drivers/staging/comedi/drivers/me4000.c
@@ -65,30 +65,6 @@ broken.
65#include "me4000_fw.h" 65#include "me4000_fw.h"
66#endif 66#endif
67 67
68/*=============================================================================
69 PCI device table.
70 This is used by modprobe to translate PCI IDs to drivers.
71 ===========================================================================*/
72
73static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = {
74 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4650) },
75 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4660) },
76 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4661) },
77 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4662) },
78 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4663) },
79 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4670) },
80 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4671) },
81 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4672) },
82 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4673) },
83 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4680) },
84 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4681) },
85 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4682) },
86 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4683) },
87 { 0 }
88};
89
90MODULE_DEVICE_TABLE(pci, me4000_pci_table);
91
92static const struct me4000_board me4000_boards[] = { 68static const struct me4000_board me4000_boards[] = {
93 {"ME-4650", 0x4650, {0, 0}, {16, 0, 0, 0}, {4}, {0} }, 69 {"ME-4650", 0x4650, {0, 0}, {16, 0, 0, 0}, {4}, {0} },
94 70
@@ -113,22 +89,8 @@ static const struct me4000_board me4000_boards[] = {
113#define ME4000_BOARD_VERSIONS (ARRAY_SIZE(me4000_boards) - 1) 89#define ME4000_BOARD_VERSIONS (ARRAY_SIZE(me4000_boards) - 1)
114 90
115/*----------------------------------------------------------------------------- 91/*-----------------------------------------------------------------------------
116 Comedi function prototypes
117 ---------------------------------------------------------------------------*/
118static int me4000_attach(struct comedi_device *dev,
119 struct comedi_devconfig *it);
120static int me4000_detach(struct comedi_device *dev);
121static struct comedi_driver driver_me4000 = {
122 .driver_name = "me4000",
123 .module = THIS_MODULE,
124 .attach = me4000_attach,
125 .detach = me4000_detach,
126};
127
128/*-----------------------------------------------------------------------------
129 Meilhaus function prototypes 92 Meilhaus function prototypes
130 ---------------------------------------------------------------------------*/ 93 ---------------------------------------------------------------------------*/
131static int me4000_probe(struct comedi_device *dev, struct comedi_devconfig *it);
132static int get_registers(struct comedi_device *dev, struct pci_dev *pci_dev_p); 94static int get_registers(struct comedi_device *dev, struct pci_dev *pci_dev_p);
133static int init_board_info(struct comedi_device *dev, 95static int init_board_info(struct comedi_device *dev,
134 struct pci_dev *pci_dev_p); 96 struct pci_dev *pci_dev_p);
@@ -139,76 +101,10 @@ static int init_cnt_context(struct comedi_device *dev);
139static int xilinx_download(struct comedi_device *dev); 101static int xilinx_download(struct comedi_device *dev);
140static int reset_board(struct comedi_device *dev); 102static int reset_board(struct comedi_device *dev);
141 103
142static int me4000_dio_insn_bits(struct comedi_device *dev,
143 struct comedi_subdevice *s,
144 struct comedi_insn *insn, unsigned int *data);
145
146static int me4000_dio_insn_config(struct comedi_device *dev,
147 struct comedi_subdevice *s,
148 struct comedi_insn *insn, unsigned int *data);
149
150static int cnt_reset(struct comedi_device *dev, unsigned int channel);
151
152static int cnt_config(struct comedi_device *dev,
153 unsigned int channel, unsigned int mode);
154
155static int me4000_cnt_insn_config(struct comedi_device *dev,
156 struct comedi_subdevice *s,
157 struct comedi_insn *insn, unsigned int *data);
158
159static int me4000_cnt_insn_write(struct comedi_device *dev,
160 struct comedi_subdevice *s,
161 struct comedi_insn *insn, unsigned int *data);
162
163static int me4000_cnt_insn_read(struct comedi_device *dev,
164 struct comedi_subdevice *s,
165 struct comedi_insn *insn, unsigned int *data);
166
167static int me4000_ai_insn_read(struct comedi_device *dev,
168 struct comedi_subdevice *subdevice,
169 struct comedi_insn *insn, unsigned int *data);
170
171static int me4000_ai_cancel(struct comedi_device *dev,
172 struct comedi_subdevice *s);
173
174static int ai_check_chanlist(struct comedi_device *dev,
175 struct comedi_subdevice *s,
176 struct comedi_cmd *cmd);
177
178static int ai_round_cmd_args(struct comedi_device *dev,
179 struct comedi_subdevice *s,
180 struct comedi_cmd *cmd,
181 unsigned int *init_ticks,
182 unsigned int *scan_ticks,
183 unsigned int *chan_ticks);
184
185static int ai_prepare(struct comedi_device *dev,
186 struct comedi_subdevice *s,
187 struct comedi_cmd *cmd,
188 unsigned int init_ticks,
189 unsigned int scan_ticks, unsigned int chan_ticks);
190
191static int ai_write_chanlist(struct comedi_device *dev, 104static int ai_write_chanlist(struct comedi_device *dev,
192 struct comedi_subdevice *s, 105 struct comedi_subdevice *s,
193 struct comedi_cmd *cmd); 106 struct comedi_cmd *cmd);
194 107
195static irqreturn_t me4000_ai_isr(int irq, void *dev_id);
196
197static int me4000_ai_do_cmd_test(struct comedi_device *dev,
198 struct comedi_subdevice *s,
199 struct comedi_cmd *cmd);
200
201static int me4000_ai_do_cmd(struct comedi_device *dev,
202 struct comedi_subdevice *s);
203
204static int me4000_ao_insn_write(struct comedi_device *dev,
205 struct comedi_subdevice *s,
206 struct comedi_insn *insn, unsigned int *data);
207
208static int me4000_ao_insn_read(struct comedi_device *dev,
209 struct comedi_subdevice *s,
210 struct comedi_insn *insn, unsigned int *data);
211
212/*----------------------------------------------------------------------------- 108/*-----------------------------------------------------------------------------
213 Meilhaus inline functions 109 Meilhaus inline functions
214 ---------------------------------------------------------------------------*/ 110 ---------------------------------------------------------------------------*/
@@ -262,130 +158,6 @@ static const struct comedi_lrange me4000_ao_range = {
262 } 158 }
263}; 159};
264 160
265static int me4000_attach(struct comedi_device *dev, struct comedi_devconfig *it)
266{
267 struct comedi_subdevice *s;
268 int result;
269
270 CALL_PDEBUG("In me4000_attach()\n");
271
272 result = me4000_probe(dev, it);
273 if (result)
274 return result;
275
276 /*
277 * Allocate the subdevice structures. alloc_subdevice() is a
278 * convenient macro defined in comedidev.h. It relies on
279 * n_subdevices being set correctly.
280 */
281 if (alloc_subdevices(dev, 4) < 0)
282 return -ENOMEM;
283
284 /*=========================================================================
285 Analog input subdevice
286 ========================================================================*/
287
288 s = dev->subdevices + 0;
289
290 if (thisboard->ai.count) {
291 s->type = COMEDI_SUBD_AI;
292 s->subdev_flags =
293 SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
294 s->n_chan = thisboard->ai.count;
295 s->maxdata = 0xFFFF; /* 16 bit ADC */
296 s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT;
297 s->range_table = &me4000_ai_range;
298 s->insn_read = me4000_ai_insn_read;
299
300 if (info->irq > 0) {
301 if (request_irq(info->irq, me4000_ai_isr,
302 IRQF_SHARED, "ME-4000", dev)) {
303 printk
304 ("comedi%d: me4000: me4000_attach(): "
305 "Unable to allocate irq\n", dev->minor);
306 } else {
307 dev->read_subdev = s;
308 s->subdev_flags |= SDF_CMD_READ;
309 s->cancel = me4000_ai_cancel;
310 s->do_cmdtest = me4000_ai_do_cmd_test;
311 s->do_cmd = me4000_ai_do_cmd;
312 }
313 } else {
314 printk(KERN_WARNING
315 "comedi%d: me4000: me4000_attach(): "
316 "No interrupt available\n", dev->minor);
317 }
318 } else {
319 s->type = COMEDI_SUBD_UNUSED;
320 }
321
322 /*=========================================================================
323 Analog output subdevice
324 ========================================================================*/
325
326 s = dev->subdevices + 1;
327
328 if (thisboard->ao.count) {
329 s->type = COMEDI_SUBD_AO;
330 s->subdev_flags = SDF_WRITEABLE | SDF_COMMON | SDF_GROUND;
331 s->n_chan = thisboard->ao.count;
332 s->maxdata = 0xFFFF; /* 16 bit DAC */
333 s->range_table = &me4000_ao_range;
334 s->insn_write = me4000_ao_insn_write;
335 s->insn_read = me4000_ao_insn_read;
336 } else {
337 s->type = COMEDI_SUBD_UNUSED;
338 }
339
340 /*=========================================================================
341 Digital I/O subdevice
342 ========================================================================*/
343
344 s = dev->subdevices + 2;
345
346 if (thisboard->dio.count) {
347 s->type = COMEDI_SUBD_DIO;
348 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
349 s->n_chan = thisboard->dio.count * 8;
350 s->maxdata = 1;
351 s->range_table = &range_digital;
352 s->insn_bits = me4000_dio_insn_bits;
353 s->insn_config = me4000_dio_insn_config;
354 } else {
355 s->type = COMEDI_SUBD_UNUSED;
356 }
357
358 /*
359 * Check for optoisolated ME-4000 version. If one the first
360 * port is a fixed output port and the second is a fixed input port.
361 */
362 if (!me4000_inl(dev, info->dio_context.dir_reg)) {
363 s->io_bits |= 0xFF;
364 me4000_outl(dev, ME4000_DIO_CTRL_BIT_MODE_0,
365 info->dio_context.dir_reg);
366 }
367
368 /*=========================================================================
369 Counter subdevice
370 ========================================================================*/
371
372 s = dev->subdevices + 3;
373
374 if (thisboard->cnt.count) {
375 s->type = COMEDI_SUBD_COUNTER;
376 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
377 s->n_chan = thisboard->cnt.count;
378 s->maxdata = 0xFFFF; /* 16 bit counters */
379 s->insn_read = me4000_cnt_insn_read;
380 s->insn_write = me4000_cnt_insn_write;
381 s->insn_config = me4000_cnt_insn_config;
382 } else {
383 s->type = COMEDI_SUBD_UNUSED;
384 }
385
386 return 0;
387}
388
389static int me4000_probe(struct comedi_device *dev, struct comedi_devconfig *it) 161static int me4000_probe(struct comedi_device *dev, struct comedi_devconfig *it)
390{ 162{
391 struct pci_dev *pci_device = NULL; 163 struct pci_dev *pci_device = NULL;
@@ -920,22 +692,6 @@ static int reset_board(struct comedi_device *dev)
920 return 0; 692 return 0;
921} 693}
922 694
923static int me4000_detach(struct comedi_device *dev)
924{
925 CALL_PDEBUG("In me4000_detach()\n");
926
927 if (info) {
928 if (info->pci_dev_p) {
929 reset_board(dev);
930 if (info->plx_regbase)
931 comedi_pci_disable(info->pci_dev_p);
932 pci_dev_put(info->pci_dev_p);
933 }
934 }
935
936 return 0;
937}
938
939/*============================================================================= 695/*=============================================================================
940 Analog input section 696 Analog input section
941 ===========================================================================*/ 697 ===========================================================================*/
@@ -2424,43 +2180,185 @@ static int me4000_cnt_insn_write(struct comedi_device *dev,
2424 return 1; 2180 return 1;
2425} 2181}
2426 2182
2427static int __devinit driver_me4000_pci_probe(struct pci_dev *dev, 2183static int me4000_attach(struct comedi_device *dev, struct comedi_devconfig *it)
2428 const struct pci_device_id *ent)
2429{ 2184{
2430 return comedi_pci_auto_config(dev, driver_me4000.driver_name); 2185 struct comedi_subdevice *s;
2186 int result;
2187
2188 CALL_PDEBUG("In me4000_attach()\n");
2189
2190 result = me4000_probe(dev, it);
2191 if (result)
2192 return result;
2193
2194 /*
2195 * Allocate the subdevice structures. alloc_subdevice() is a
2196 * convenient macro defined in comedidev.h. It relies on
2197 * n_subdevices being set correctly.
2198 */
2199 if (alloc_subdevices(dev, 4) < 0)
2200 return -ENOMEM;
2201
2202 /*=========================================================================
2203 Analog input subdevice
2204 ========================================================================*/
2205
2206 s = dev->subdevices + 0;
2207
2208 if (thisboard->ai.count) {
2209 s->type = COMEDI_SUBD_AI;
2210 s->subdev_flags =
2211 SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
2212 s->n_chan = thisboard->ai.count;
2213 s->maxdata = 0xFFFF; /* 16 bit ADC */
2214 s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT;
2215 s->range_table = &me4000_ai_range;
2216 s->insn_read = me4000_ai_insn_read;
2217
2218 if (info->irq > 0) {
2219 if (request_irq(info->irq, me4000_ai_isr,
2220 IRQF_SHARED, "ME-4000", dev)) {
2221 printk
2222 ("comedi%d: me4000: me4000_attach(): "
2223 "Unable to allocate irq\n", dev->minor);
2224 } else {
2225 dev->read_subdev = s;
2226 s->subdev_flags |= SDF_CMD_READ;
2227 s->cancel = me4000_ai_cancel;
2228 s->do_cmdtest = me4000_ai_do_cmd_test;
2229 s->do_cmd = me4000_ai_do_cmd;
2230 }
2231 } else {
2232 printk(KERN_WARNING
2233 "comedi%d: me4000: me4000_attach(): "
2234 "No interrupt available\n", dev->minor);
2235 }
2236 } else {
2237 s->type = COMEDI_SUBD_UNUSED;
2238 }
2239
2240 /*=========================================================================
2241 Analog output subdevice
2242 ========================================================================*/
2243
2244 s = dev->subdevices + 1;
2245
2246 if (thisboard->ao.count) {
2247 s->type = COMEDI_SUBD_AO;
2248 s->subdev_flags = SDF_WRITEABLE | SDF_COMMON | SDF_GROUND;
2249 s->n_chan = thisboard->ao.count;
2250 s->maxdata = 0xFFFF; /* 16 bit DAC */
2251 s->range_table = &me4000_ao_range;
2252 s->insn_write = me4000_ao_insn_write;
2253 s->insn_read = me4000_ao_insn_read;
2254 } else {
2255 s->type = COMEDI_SUBD_UNUSED;
2256 }
2257
2258 /*=========================================================================
2259 Digital I/O subdevice
2260 ========================================================================*/
2261
2262 s = dev->subdevices + 2;
2263
2264 if (thisboard->dio.count) {
2265 s->type = COMEDI_SUBD_DIO;
2266 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
2267 s->n_chan = thisboard->dio.count * 8;
2268 s->maxdata = 1;
2269 s->range_table = &range_digital;
2270 s->insn_bits = me4000_dio_insn_bits;
2271 s->insn_config = me4000_dio_insn_config;
2272 } else {
2273 s->type = COMEDI_SUBD_UNUSED;
2274 }
2275
2276 /*
2277 * Check for optoisolated ME-4000 version. If one the first
2278 * port is a fixed output port and the second is a fixed input port.
2279 */
2280 if (!me4000_inl(dev, info->dio_context.dir_reg)) {
2281 s->io_bits |= 0xFF;
2282 me4000_outl(dev, ME4000_DIO_CTRL_BIT_MODE_0,
2283 info->dio_context.dir_reg);
2284 }
2285
2286 /*=========================================================================
2287 Counter subdevice
2288 ========================================================================*/
2289
2290 s = dev->subdevices + 3;
2291
2292 if (thisboard->cnt.count) {
2293 s->type = COMEDI_SUBD_COUNTER;
2294 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
2295 s->n_chan = thisboard->cnt.count;
2296 s->maxdata = 0xFFFF; /* 16 bit counters */
2297 s->insn_read = me4000_cnt_insn_read;
2298 s->insn_write = me4000_cnt_insn_write;
2299 s->insn_config = me4000_cnt_insn_config;
2300 } else {
2301 s->type = COMEDI_SUBD_UNUSED;
2302 }
2303
2304 return 0;
2431} 2305}
2432 2306
2433static void __devexit driver_me4000_pci_remove(struct pci_dev *dev) 2307static void me4000_detach(struct comedi_device *dev)
2434{ 2308{
2435 comedi_pci_auto_unconfig(dev); 2309 if (info) {
2310 if (info->pci_dev_p) {
2311 reset_board(dev);
2312 if (info->plx_regbase)
2313 comedi_pci_disable(info->pci_dev_p);
2314 pci_dev_put(info->pci_dev_p);
2315 }
2316 }
2436} 2317}
2437 2318
2438static struct pci_driver driver_me4000_pci_driver = { 2319static struct comedi_driver me4000_driver = {
2439 .id_table = me4000_pci_table, 2320 .driver_name = "me4000",
2440 .probe = &driver_me4000_pci_probe, 2321 .module = THIS_MODULE,
2441 .remove = __devexit_p(&driver_me4000_pci_remove) 2322 .attach = me4000_attach,
2323 .detach = me4000_detach,
2442}; 2324};
2443 2325
2444static int __init driver_me4000_init_module(void) 2326static int __devinit me4000_pci_probe(struct pci_dev *dev,
2327 const struct pci_device_id *ent)
2445{ 2328{
2446 int retval; 2329 return comedi_pci_auto_config(dev, &me4000_driver);
2447
2448 retval = comedi_driver_register(&driver_me4000);
2449 if (retval < 0)
2450 return retval;
2451
2452 driver_me4000_pci_driver.name = (char *)driver_me4000.driver_name;
2453 return pci_register_driver(&driver_me4000_pci_driver);
2454} 2330}
2455 2331
2456static void __exit driver_me4000_cleanup_module(void) 2332static void __devexit me4000_pci_remove(struct pci_dev *dev)
2457{ 2333{
2458 pci_unregister_driver(&driver_me4000_pci_driver); 2334 comedi_pci_auto_unconfig(dev);
2459 comedi_driver_unregister(&driver_me4000);
2460} 2335}
2461 2336
2462module_init(driver_me4000_init_module); 2337static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = {
2463module_exit(driver_me4000_cleanup_module); 2338 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4650) },
2339 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4660) },
2340 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4661) },
2341 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4662) },
2342 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4663) },
2343 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4670) },
2344 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4671) },
2345 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4672) },
2346 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4673) },
2347 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4680) },
2348 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4681) },
2349 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4682) },
2350 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, 0x4683) },
2351 { 0 }
2352};
2353MODULE_DEVICE_TABLE(pci, me4000_pci_table);
2354
2355static struct pci_driver me4000_pci_driver = {
2356 .name = "me4000",
2357 .id_table = me4000_pci_table,
2358 .probe = me4000_pci_probe,
2359 .remove = __devexit_p(me4000_pci_remove),
2360};
2361module_comedi_pci_driver(me4000_driver, me4000_pci_driver);
2464 2362
2465MODULE_AUTHOR("Comedi http://www.comedi.org"); 2363MODULE_AUTHOR("Comedi http://www.comedi.org");
2466MODULE_DESCRIPTION("Comedi low-level driver"); 2364MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index 8b812e41c52b..ffe251250e6f 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -146,10 +146,6 @@ from http://www.comedi.org
146#define ME_COUNTER_STARTDATA_B 0x0022 /* - | W */ 146#define ME_COUNTER_STARTDATA_B 0x0022 /* - | W */
147#define ME_COUNTER_VALUE_B 0x0022 /* R | - */ 147#define ME_COUNTER_VALUE_B 0x0022 /* R | - */
148 148
149/* Function prototypes */
150static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it);
151static int me_detach(struct comedi_device *dev);
152
153static const struct comedi_lrange me2000_ai_range = { 149static const struct comedi_lrange me2000_ai_range = {
154 8, 150 8,
155 { 151 {
@@ -187,14 +183,6 @@ static const struct comedi_lrange me2600_ao_range = {
187 } 183 }
188}; 184};
189 185
190static DEFINE_PCI_DEVICE_TABLE(me_pci_table) = {
191 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) },
192 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) },
193 {0}
194};
195
196MODULE_DEVICE_TABLE(pci, me_pci_table);
197
198/* Board specification structure */ 186/* Board specification structure */
199struct me_board { 187struct me_board {
200 const char *name; /* driver name */ 188 const char *name; /* driver name */
@@ -247,51 +235,6 @@ static const struct me_board me_boards[] = {
247 235
248#define me_board_nbr (sizeof(me_boards)/sizeof(struct me_board)) 236#define me_board_nbr (sizeof(me_boards)/sizeof(struct me_board))
249 237
250static struct comedi_driver me_driver = {
251 .driver_name = ME_DRIVER_NAME,
252 .module = THIS_MODULE,
253 .attach = me_attach,
254 .detach = me_detach,
255};
256
257static int __devinit me_driver_pci_probe(struct pci_dev *dev,
258 const struct pci_device_id *ent)
259{
260 return comedi_pci_auto_config(dev, me_driver.driver_name);
261}
262
263static void __devexit me_driver_pci_remove(struct pci_dev *dev)
264{
265 comedi_pci_auto_unconfig(dev);
266}
267
268static struct pci_driver me_driver_pci_driver = {
269 .id_table = me_pci_table,
270 .probe = &me_driver_pci_probe,
271 .remove = __devexit_p(&me_driver_pci_remove)
272};
273
274static int __init me_driver_init_module(void)
275{
276 int retval;
277
278 retval = comedi_driver_register(&me_driver);
279 if (retval < 0)
280 return retval;
281
282 me_driver_pci_driver.name = (char *)me_driver.driver_name;
283 return pci_register_driver(&me_driver_pci_driver);
284}
285
286static void __exit me_driver_cleanup_module(void)
287{
288 pci_unregister_driver(&me_driver_pci_driver);
289 comedi_driver_unregister(&me_driver);
290}
291
292module_init(me_driver_init_module);
293module_exit(me_driver_cleanup_module);
294
295/* Private data structure */ 238/* Private data structure */
296struct me_private_data { 239struct me_private_data {
297 struct pci_dev *pci_device; 240 struct pci_dev *pci_device;
@@ -669,12 +612,6 @@ static int me_reset(struct comedi_device *dev)
669 return 0; 612 return 0;
670} 613}
671 614
672/*
673 * Attach
674 *
675 * - Register PCI device
676 * - Declare device driver capability
677 */
678static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) 615static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
679{ 616{
680 struct pci_dev *pci_device = NULL; 617 struct pci_dev *pci_device = NULL;
@@ -869,8 +806,7 @@ found:
869 return 0; 806 return 0;
870} 807}
871 808
872/* Detach */ 809static void me_detach(struct comedi_device *dev)
873static int me_detach(struct comedi_device *dev)
874{ 810{
875 if (dev_private) { 811 if (dev_private) {
876 if (dev_private->me_regbase) { 812 if (dev_private->me_regbase) {
@@ -882,13 +818,44 @@ static int me_detach(struct comedi_device *dev)
882 if (dev_private->pci_device) { 818 if (dev_private->pci_device) {
883 if (dev_private->plx_regbase_size) 819 if (dev_private->plx_regbase_size)
884 comedi_pci_disable(dev_private->pci_device); 820 comedi_pci_disable(dev_private->pci_device);
885
886 pci_dev_put(dev_private->pci_device); 821 pci_dev_put(dev_private->pci_device);
887 } 822 }
888 } 823 }
889 return 0;
890} 824}
891 825
826static struct comedi_driver me_daq_driver = {
827 .driver_name = "me_daq",
828 .module = THIS_MODULE,
829 .attach = me_attach,
830 .detach = me_detach,
831};
832
833static int __devinit me_daq_pci_probe(struct pci_dev *dev,
834 const struct pci_device_id *ent)
835{
836 return comedi_pci_auto_config(dev, &me_daq_driver);
837}
838
839static void __devexit me_daq_pci_remove(struct pci_dev *dev)
840{
841 comedi_pci_auto_unconfig(dev);
842}
843
844static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = {
845 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) },
846 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) },
847 { 0 }
848};
849MODULE_DEVICE_TABLE(pci, me_daq_pci_table);
850
851static struct pci_driver me_daq_pci_driver = {
852 .name = "me_daq",
853 .id_table = me_daq_pci_table,
854 .probe = me_daq_pci_probe,
855 .remove = __devexit_p(me_daq_pci_remove),
856};
857module_comedi_pci_driver(me_daq_driver, me_daq_pci_driver);
858
892MODULE_AUTHOR("Comedi http://www.comedi.org"); 859MODULE_AUTHOR("Comedi http://www.comedi.org");
893MODULE_DESCRIPTION("Comedi low-level driver"); 860MODULE_DESCRIPTION("Comedi low-level driver");
894MODULE_LICENSE("GPL"); 861MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index 999551f54c2a..83f1b27a4720 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -66,9 +66,9 @@ struct mite_struct {
66 66
67 struct pci_dev *pcidev; 67 struct pci_dev *pcidev;
68 resource_size_t mite_phys_addr; 68 resource_size_t mite_phys_addr;
69 void *mite_io_addr; 69 void __iomem *mite_io_addr;
70 resource_size_t daq_phys_addr; 70 resource_size_t daq_phys_addr;
71 void *daq_io_addr; 71 void __iomem *daq_io_addr;
72 72
73 struct mite_channel channels[MAX_MITE_DMA_CHANNELS]; 73 struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
74 short channel_allocated[MAX_MITE_DMA_CHANNELS]; 74 short channel_allocated[MAX_MITE_DMA_CHANNELS];
diff --git a/drivers/staging/comedi/drivers/mpc624.c b/drivers/staging/comedi/drivers/mpc624.c
index dd09a6d46e5c..4304e864a4d4 100644
--- a/drivers/staging/comedi/drivers/mpc624.c
+++ b/drivers/staging/comedi/drivers/mpc624.c
@@ -148,131 +148,6 @@ static const struct comedi_lrange range_mpc624_bipolar10 = {
148 } 148 }
149}; 149};
150 150
151/* -------------------------------------------------------------------------- */
152static int mpc624_attach(struct comedi_device *dev,
153 struct comedi_devconfig *it);
154static int mpc624_detach(struct comedi_device *dev);
155/* -------------------------------------------------------------------------- */
156static struct comedi_driver driver_mpc624 = {
157 .driver_name = "mpc624",
158 .module = THIS_MODULE,
159 .attach = mpc624_attach,
160 .detach = mpc624_detach
161};
162
163/* -------------------------------------------------------------------------- */
164static int mpc624_ai_rinsn(struct comedi_device *dev,
165 struct comedi_subdevice *s, struct comedi_insn *insn,
166 unsigned int *data);
167/* -------------------------------------------------------------------------- */
168static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it)
169{
170 struct comedi_subdevice *s;
171 unsigned long iobase;
172
173 iobase = it->options[0];
174 printk(KERN_INFO "comedi%d: mpc624 [0x%04lx, ", dev->minor, iobase);
175 if (request_region(iobase, MPC624_SIZE, "mpc624") == NULL) {
176 printk(KERN_ERR "I/O port(s) in use\n");
177 return -EIO;
178 }
179
180 dev->iobase = iobase;
181 dev->board_name = "mpc624";
182
183 /* Private structure initialization */
184 if (alloc_private(dev, sizeof(struct skel_private)) < 0)
185 return -ENOMEM;
186
187 switch (it->options[1]) {
188 case 0:
189 devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
190 printk(KERN_INFO "3.52 kHz, ");
191 break;
192 case 1:
193 devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz;
194 printk(KERN_INFO "1.76 kHz, ");
195 break;
196 case 2:
197 devpriv->ulConvertionRate = MPC624_SPEED_880_Hz;
198 printk(KERN_INFO "880 Hz, ");
199 break;
200 case 3:
201 devpriv->ulConvertionRate = MPC624_SPEED_440_Hz;
202 printk(KERN_INFO "440 Hz, ");
203 break;
204 case 4:
205 devpriv->ulConvertionRate = MPC624_SPEED_220_Hz;
206 printk(KERN_INFO "220 Hz, ");
207 break;
208 case 5:
209 devpriv->ulConvertionRate = MPC624_SPEED_110_Hz;
210 printk(KERN_INFO "110 Hz, ");
211 break;
212 case 6:
213 devpriv->ulConvertionRate = MPC624_SPEED_55_Hz;
214 printk(KERN_INFO "55 Hz, ");
215 break;
216 case 7:
217 devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz;
218 printk(KERN_INFO "27.5 Hz, ");
219 break;
220 case 8:
221 devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz;
222 printk(KERN_INFO "13.75 Hz, ");
223 break;
224 case 9:
225 devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz;
226 printk(KERN_INFO "6.875 Hz, ");
227 break;
228 default:
229 printk
230 (KERN_ERR "illegal conversion rate setting!"
231 " Valid numbers are 0..9. Using 9 => 6.875 Hz, ");
232 devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
233 }
234
235 /* Subdevices structures */
236 if (alloc_subdevices(dev, 1) < 0)
237 return -ENOMEM;
238
239 s = dev->subdevices + 0;
240 s->type = COMEDI_SUBD_AI;
241 s->subdev_flags = SDF_READABLE | SDF_DIFF;
242 s->n_chan = 8;
243 switch (it->options[1]) {
244 default:
245 s->maxdata = 0x3FFFFFFF;
246 printk(KERN_INFO "30 bit, ");
247 }
248
249 switch (it->options[1]) {
250 case 0:
251 s->range_table = &range_mpc624_bipolar1;
252 printk(KERN_INFO "1.01V]: ");
253 break;
254 default:
255 s->range_table = &range_mpc624_bipolar10;
256 printk(KERN_INFO "10.1V]: ");
257 }
258 s->len_chanlist = 1;
259 s->insn_read = mpc624_ai_rinsn;
260
261 printk(KERN_INFO "attached\n");
262
263 return 1;
264}
265
266static int mpc624_detach(struct comedi_device *dev)
267{
268 printk(KERN_INFO "comedi%d: mpc624: remove\n", dev->minor);
269
270 if (dev->iobase)
271 release_region(dev->iobase, MPC624_SIZE);
272
273 return 0;
274}
275
276/* Timeout 200ms */ 151/* Timeout 200ms */
277#define TIMEOUT 200 152#define TIMEOUT 200
278 153
@@ -406,18 +281,117 @@ static int mpc624_ai_rinsn(struct comedi_device *dev,
406 return n; 281 return n;
407} 282}
408 283
409static int __init driver_mpc624_init_module(void) 284static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it)
410{ 285{
411 return comedi_driver_register(&driver_mpc624); 286 struct comedi_subdevice *s;
287 unsigned long iobase;
288
289 iobase = it->options[0];
290 printk(KERN_INFO "comedi%d: mpc624 [0x%04lx, ", dev->minor, iobase);
291 if (request_region(iobase, MPC624_SIZE, "mpc624") == NULL) {
292 printk(KERN_ERR "I/O port(s) in use\n");
293 return -EIO;
294 }
295
296 dev->iobase = iobase;
297 dev->board_name = "mpc624";
298
299 /* Private structure initialization */
300 if (alloc_private(dev, sizeof(struct skel_private)) < 0)
301 return -ENOMEM;
302
303 switch (it->options[1]) {
304 case 0:
305 devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
306 printk(KERN_INFO "3.52 kHz, ");
307 break;
308 case 1:
309 devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz;
310 printk(KERN_INFO "1.76 kHz, ");
311 break;
312 case 2:
313 devpriv->ulConvertionRate = MPC624_SPEED_880_Hz;
314 printk(KERN_INFO "880 Hz, ");
315 break;
316 case 3:
317 devpriv->ulConvertionRate = MPC624_SPEED_440_Hz;
318 printk(KERN_INFO "440 Hz, ");
319 break;
320 case 4:
321 devpriv->ulConvertionRate = MPC624_SPEED_220_Hz;
322 printk(KERN_INFO "220 Hz, ");
323 break;
324 case 5:
325 devpriv->ulConvertionRate = MPC624_SPEED_110_Hz;
326 printk(KERN_INFO "110 Hz, ");
327 break;
328 case 6:
329 devpriv->ulConvertionRate = MPC624_SPEED_55_Hz;
330 printk(KERN_INFO "55 Hz, ");
331 break;
332 case 7:
333 devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz;
334 printk(KERN_INFO "27.5 Hz, ");
335 break;
336 case 8:
337 devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz;
338 printk(KERN_INFO "13.75 Hz, ");
339 break;
340 case 9:
341 devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz;
342 printk(KERN_INFO "6.875 Hz, ");
343 break;
344 default:
345 printk
346 (KERN_ERR "illegal conversion rate setting!"
347 " Valid numbers are 0..9. Using 9 => 6.875 Hz, ");
348 devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
349 }
350
351 /* Subdevices structures */
352 if (alloc_subdevices(dev, 1) < 0)
353 return -ENOMEM;
354
355 s = dev->subdevices + 0;
356 s->type = COMEDI_SUBD_AI;
357 s->subdev_flags = SDF_READABLE | SDF_DIFF;
358 s->n_chan = 8;
359 switch (it->options[1]) {
360 default:
361 s->maxdata = 0x3FFFFFFF;
362 printk(KERN_INFO "30 bit, ");
363 }
364
365 switch (it->options[1]) {
366 case 0:
367 s->range_table = &range_mpc624_bipolar1;
368 printk(KERN_INFO "1.01V]: ");
369 break;
370 default:
371 s->range_table = &range_mpc624_bipolar10;
372 printk(KERN_INFO "10.1V]: ");
373 }
374 s->len_chanlist = 1;
375 s->insn_read = mpc624_ai_rinsn;
376
377 printk(KERN_INFO "attached\n");
378
379 return 1;
412} 380}
413 381
414static void __exit driver_mpc624_cleanup_module(void) 382static void mpc624_detach(struct comedi_device *dev)
415{ 383{
416 comedi_driver_unregister(&driver_mpc624); 384 if (dev->iobase)
385 release_region(dev->iobase, MPC624_SIZE);
417} 386}
418 387
419module_init(driver_mpc624_init_module); 388static struct comedi_driver mpc624_driver = {
420module_exit(driver_mpc624_cleanup_module); 389 .driver_name = "mpc624",
390 .module = THIS_MODULE,
391 .attach = mpc624_attach,
392 .detach = mpc624_detach
393};
394module_comedi_driver(mpc624_driver);
421 395
422MODULE_AUTHOR("Comedi http://www.comedi.org"); 396MODULE_AUTHOR("Comedi http://www.comedi.org");
423MODULE_DESCRIPTION("Comedi low-level driver"); 397MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/mpc8260cpm.c b/drivers/staging/comedi/drivers/mpc8260cpm.c
index 5f6816a3fe8c..364470e4458f 100644
--- a/drivers/staging/comedi/drivers/mpc8260cpm.c
+++ b/drivers/staging/comedi/drivers/mpc8260cpm.c
@@ -46,75 +46,6 @@ struct mpc8260cpm_private {
46 46
47#define devpriv ((struct mpc8260cpm_private *)dev->private) 47#define devpriv ((struct mpc8260cpm_private *)dev->private)
48 48
49static int mpc8260cpm_attach(struct comedi_device *dev,
50 struct comedi_devconfig *it);
51static int mpc8260cpm_detach(struct comedi_device *dev);
52static struct comedi_driver driver_mpc8260cpm = {
53 .driver_name = "mpc8260cpm",
54 .module = THIS_MODULE,
55 .attach = mpc8260cpm_attach,
56 .detach = mpc8260cpm_detach,
57};
58
59static int __init driver_mpc8260cpm_init_module(void)
60{
61 return comedi_driver_register(&driver_mpc8260cpm);
62}
63
64static void __exit driver_mpc8260cpm_cleanup_module(void)
65{
66 comedi_driver_unregister(&driver_mpc8260cpm);
67}
68
69module_init(driver_mpc8260cpm_init_module);
70module_exit(driver_mpc8260cpm_cleanup_module);
71
72static int mpc8260cpm_dio_config(struct comedi_device *dev,
73 struct comedi_subdevice *s,
74 struct comedi_insn *insn, unsigned int *data);
75static int mpc8260cpm_dio_bits(struct comedi_device *dev,
76 struct comedi_subdevice *s,
77 struct comedi_insn *insn, unsigned int *data);
78
79static int mpc8260cpm_attach(struct comedi_device *dev,
80 struct comedi_devconfig *it)
81{
82 struct comedi_subdevice *s;
83 int i;
84
85 printk("comedi%d: mpc8260cpm: ", dev->minor);
86
87 dev->board_ptr = mpc8260cpm_boards + dev->board;
88
89 dev->board_name = thisboard->name;
90
91 if (alloc_private(dev, sizeof(struct mpc8260cpm_private)) < 0)
92 return -ENOMEM;
93
94 if (alloc_subdevices(dev, 4) < 0)
95 return -ENOMEM;
96
97 for (i = 0; i < 4; i++) {
98 s = dev->subdevices + i;
99 s->type = COMEDI_SUBD_DIO;
100 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
101 s->n_chan = 32;
102 s->maxdata = 1;
103 s->range_table = &range_digital;
104 s->insn_config = mpc8260cpm_dio_config;
105 s->insn_bits = mpc8260cpm_dio_bits;
106 }
107
108 return 1;
109}
110
111static int mpc8260cpm_detach(struct comedi_device *dev)
112{
113 printk("comedi%d: mpc8260cpm: remove\n", dev->minor);
114
115 return 0;
116}
117
118static unsigned long *cpm_pdat(int port) 49static unsigned long *cpm_pdat(int port)
119{ 50{
120 switch (port) { 51 switch (port) {
@@ -184,3 +115,48 @@ static int mpc8260cpm_dio_bits(struct comedi_device *dev,
184 115
185 return 2; 116 return 2;
186} 117}
118
119static int mpc8260cpm_attach(struct comedi_device *dev,
120 struct comedi_devconfig *it)
121{
122 struct comedi_subdevice *s;
123 int i;
124
125 printk("comedi%d: mpc8260cpm: ", dev->minor);
126
127 dev->board_ptr = mpc8260cpm_boards + dev->board;
128
129 dev->board_name = thisboard->name;
130
131 if (alloc_private(dev, sizeof(struct mpc8260cpm_private)) < 0)
132 return -ENOMEM;
133
134 if (alloc_subdevices(dev, 4) < 0)
135 return -ENOMEM;
136
137 for (i = 0; i < 4; i++) {
138 s = dev->subdevices + i;
139 s->type = COMEDI_SUBD_DIO;
140 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
141 s->n_chan = 32;
142 s->maxdata = 1;
143 s->range_table = &range_digital;
144 s->insn_config = mpc8260cpm_dio_config;
145 s->insn_bits = mpc8260cpm_dio_bits;
146 }
147
148 return 1;
149}
150
151static void mpc8260cpm_detach(struct comedi_device *dev)
152{
153 /* Nothing to cleanup */
154}
155
156static struct comedi_driver mpc8260cpm_driver = {
157 .driver_name = "mpc8260cpm",
158 .module = THIS_MODULE,
159 .attach = mpc8260cpm_attach,
160 .detach = mpc8260cpm_detach,
161};
162module_comedi_driver(mpc8260cpm_driver);
diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c
index dace902d3bce..e951e73d66f5 100644
--- a/drivers/staging/comedi/drivers/multiq3.c
+++ b/drivers/staging/comedi/drivers/multiq3.c
@@ -83,29 +83,6 @@ Devices: [Quanser Consulting] MultiQ-3 (multiq3)
83 83
84#define MULTIQ3_TIMEOUT 30 84#define MULTIQ3_TIMEOUT 30
85 85
86static int multiq3_attach(struct comedi_device *dev,
87 struct comedi_devconfig *it);
88static int multiq3_detach(struct comedi_device *dev);
89static struct comedi_driver driver_multiq3 = {
90 .driver_name = "multiq3",
91 .module = THIS_MODULE,
92 .attach = multiq3_attach,
93 .detach = multiq3_detach,
94};
95
96static int __init driver_multiq3_init_module(void)
97{
98 return comedi_driver_register(&driver_multiq3);
99}
100
101static void __exit driver_multiq3_cleanup_module(void)
102{
103 comedi_driver_unregister(&driver_multiq3);
104}
105
106module_init(driver_multiq3_init_module);
107module_exit(driver_multiq3_cleanup_module);
108
109struct multiq3_private { 86struct multiq3_private {
110 unsigned int ao_readback[2]; 87 unsigned int ao_readback[2];
111}; 88};
@@ -338,18 +315,22 @@ static int multiq3_attach(struct comedi_device *dev,
338 return 0; 315 return 0;
339} 316}
340 317
341static int multiq3_detach(struct comedi_device *dev) 318static void multiq3_detach(struct comedi_device *dev)
342{ 319{
343 printk(KERN_INFO "comedi%d: multiq3: remove\n", dev->minor);
344
345 if (dev->iobase) 320 if (dev->iobase)
346 release_region(dev->iobase, MULTIQ3_SIZE); 321 release_region(dev->iobase, MULTIQ3_SIZE);
347 if (dev->irq) 322 if (dev->irq)
348 free_irq(dev->irq, dev); 323 free_irq(dev->irq, dev);
349
350 return 0;
351} 324}
352 325
326static struct comedi_driver multiq3_driver = {
327 .driver_name = "multiq3",
328 .module = THIS_MODULE,
329 .attach = multiq3_attach,
330 .detach = multiq3_detach,
331};
332module_comedi_driver(multiq3_driver);
333
353MODULE_AUTHOR("Comedi http://www.comedi.org"); 334MODULE_AUTHOR("Comedi http://www.comedi.org");
354MODULE_DESCRIPTION("Comedi low-level driver"); 335MODULE_DESCRIPTION("Comedi low-level driver");
355MODULE_LICENSE("GPL"); 336MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index 54741c9e1af5..b02aa0efcd86 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -78,7 +78,7 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800
78 78
79static int ni6527_attach(struct comedi_device *dev, 79static int ni6527_attach(struct comedi_device *dev,
80 struct comedi_devconfig *it); 80 struct comedi_devconfig *it);
81static int ni6527_detach(struct comedi_device *dev); 81static void ni6527_detach(struct comedi_device *dev);
82static struct comedi_driver driver_ni6527 = { 82static struct comedi_driver driver_ni6527 = {
83 .driver_name = "ni6527", 83 .driver_name = "ni6527",
84 .module = THIS_MODULE, 84 .module = THIS_MODULE,
@@ -449,19 +449,15 @@ static int ni6527_attach(struct comedi_device *dev, struct comedi_devconfig *it)
449 return 0; 449 return 0;
450} 450}
451 451
452static int ni6527_detach(struct comedi_device *dev) 452static void ni6527_detach(struct comedi_device *dev)
453{ 453{
454 if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr) 454 if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr)
455 writeb(0x00, 455 writeb(0x00,
456 devpriv->mite->daq_io_addr + Master_Interrupt_Control); 456 devpriv->mite->daq_io_addr + Master_Interrupt_Control);
457
458 if (dev->irq) 457 if (dev->irq)
459 free_irq(dev->irq, dev); 458 free_irq(dev->irq, dev);
460
461 if (devpriv && devpriv->mite) 459 if (devpriv && devpriv->mite)
462 mite_unsetup(devpriv->mite); 460 mite_unsetup(devpriv->mite);
463
464 return 0;
465} 461}
466 462
467static int ni6527_find_device(struct comedi_device *dev, int bus, int slot) 463static int ni6527_find_device(struct comedi_device *dev, int bus, int slot)
@@ -493,7 +489,7 @@ static int ni6527_find_device(struct comedi_device *dev, int bus, int slot)
493static int __devinit driver_ni6527_pci_probe(struct pci_dev *dev, 489static int __devinit driver_ni6527_pci_probe(struct pci_dev *dev,
494 const struct pci_device_id *ent) 490 const struct pci_device_id *ent)
495{ 491{
496 return comedi_pci_auto_config(dev, driver_ni6527.driver_name); 492 return comedi_pci_auto_config(dev, &driver_ni6527);
497} 493}
498 494
499static void __devexit driver_ni6527_pci_remove(struct pci_dev *dev) 495static void __devexit driver_ni6527_pci_remove(struct pci_dev *dev)
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 403fc0997d37..0d27a9323bc0 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -111,7 +111,7 @@ static inline unsigned Filter_Enable(unsigned port)
111 111
112static int ni_65xx_attach(struct comedi_device *dev, 112static int ni_65xx_attach(struct comedi_device *dev,
113 struct comedi_devconfig *it); 113 struct comedi_devconfig *it);
114static int ni_65xx_detach(struct comedi_device *dev); 114static void ni_65xx_detach(struct comedi_device *dev);
115static struct comedi_driver driver_ni_65xx = { 115static struct comedi_driver driver_ni_65xx = {
116 .driver_name = "ni_65xx", 116 .driver_name = "ni_65xx",
117 .module = THIS_MODULE, 117 .module = THIS_MODULE,
@@ -784,7 +784,7 @@ static int ni_65xx_attach(struct comedi_device *dev,
784 return 0; 784 return 0;
785} 785}
786 786
787static int ni_65xx_detach(struct comedi_device *dev) 787static void ni_65xx_detach(struct comedi_device *dev)
788{ 788{
789 if (private(dev) && private(dev)->mite 789 if (private(dev) && private(dev)->mite
790 && private(dev)->mite->daq_io_addr) { 790 && private(dev)->mite->daq_io_addr) {
@@ -792,10 +792,8 @@ static int ni_65xx_detach(struct comedi_device *dev)
792 private(dev)->mite->daq_io_addr + 792 private(dev)->mite->daq_io_addr +
793 Master_Interrupt_Control); 793 Master_Interrupt_Control);
794 } 794 }
795
796 if (dev->irq) 795 if (dev->irq)
797 free_irq(dev->irq, dev); 796 free_irq(dev->irq, dev);
798
799 if (private(dev)) { 797 if (private(dev)) {
800 unsigned i; 798 unsigned i;
801 for (i = 0; i < dev->n_subdevices; ++i) { 799 for (i = 0; i < dev->n_subdevices; ++i) {
@@ -805,7 +803,6 @@ static int ni_65xx_detach(struct comedi_device *dev)
805 if (private(dev)->mite) 803 if (private(dev)->mite)
806 mite_unsetup(private(dev)->mite); 804 mite_unsetup(private(dev)->mite);
807 } 805 }
808 return 0;
809} 806}
810 807
811static int ni_65xx_find_device(struct comedi_device *dev, int bus, int slot) 808static int ni_65xx_find_device(struct comedi_device *dev, int bus, int slot)
@@ -837,7 +834,7 @@ static int ni_65xx_find_device(struct comedi_device *dev, int bus, int slot)
837static int __devinit driver_ni_65xx_pci_probe(struct pci_dev *dev, 834static int __devinit driver_ni_65xx_pci_probe(struct pci_dev *dev,
838 const struct pci_device_id *ent) 835 const struct pci_device_id *ent)
839{ 836{
840 return comedi_pci_auto_config(dev, driver_ni_65xx.driver_name); 837 return comedi_pci_auto_config(dev, &driver_ni_65xx);
841} 838}
842 839
843static void __devexit driver_ni_65xx_pci_remove(struct pci_dev *dev) 840static void __devexit driver_ni_65xx_pci_remove(struct pci_dev *dev)
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 35f3a4749825..8c40730e296a 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -458,7 +458,7 @@ static inline const struct ni_660x_board *board(struct comedi_device *dev)
458 458
459static int ni_660x_attach(struct comedi_device *dev, 459static int ni_660x_attach(struct comedi_device *dev,
460 struct comedi_devconfig *it); 460 struct comedi_devconfig *it);
461static int ni_660x_detach(struct comedi_device *dev); 461static void ni_660x_detach(struct comedi_device *dev);
462static void init_tio_chip(struct comedi_device *dev, int chipset); 462static void init_tio_chip(struct comedi_device *dev, int chipset);
463static void ni_660x_select_pfi_output(struct comedi_device *dev, 463static void ni_660x_select_pfi_output(struct comedi_device *dev,
464 unsigned pfi_channel, 464 unsigned pfi_channel,
@@ -474,7 +474,7 @@ static struct comedi_driver driver_ni_660x = {
474static int __devinit driver_ni_660x_pci_probe(struct pci_dev *dev, 474static int __devinit driver_ni_660x_pci_probe(struct pci_dev *dev,
475 const struct pci_device_id *ent) 475 const struct pci_device_id *ent)
476{ 476{
477 return comedi_pci_auto_config(dev, driver_ni_660x.driver_name); 477 return comedi_pci_auto_config(dev, &driver_ni_660x);
478} 478}
479 479
480static void __devexit driver_ni_660x_pci_remove(struct pci_dev *dev) 480static void __devexit driver_ni_660x_pci_remove(struct pci_dev *dev)
@@ -761,7 +761,7 @@ static inline void ni_660x_write_register(struct comedi_device *dev,
761 unsigned chip_index, unsigned bits, 761 unsigned chip_index, unsigned bits,
762 enum NI_660x_Register reg) 762 enum NI_660x_Register reg)
763{ 763{
764 void *const write_address = 764 void __iomem *write_address =
765 private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + 765 private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] +
766 registerData[reg].offset; 766 registerData[reg].offset;
767 767
@@ -784,7 +784,7 @@ static inline unsigned ni_660x_read_register(struct comedi_device *dev,
784 unsigned chip_index, 784 unsigned chip_index,
785 enum NI_660x_Register reg) 785 enum NI_660x_Register reg)
786{ 786{
787 void *const read_address = 787 void __iomem *read_address =
788 private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + 788 private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] +
789 registerData[reg].offset; 789 registerData[reg].offset;
790 790
@@ -1188,14 +1188,10 @@ static int ni_660x_attach(struct comedi_device *dev,
1188 return 0; 1188 return 0;
1189} 1189}
1190 1190
1191static int ni_660x_detach(struct comedi_device *dev) 1191static void ni_660x_detach(struct comedi_device *dev)
1192{ 1192{
1193 printk(KERN_INFO "comedi%d: ni_660x: remove\n", dev->minor);
1194
1195 /* Free irq */
1196 if (dev->irq) 1193 if (dev->irq)
1197 free_irq(dev->irq, dev); 1194 free_irq(dev->irq, dev);
1198
1199 if (dev->private) { 1195 if (dev->private) {
1200 if (private(dev)->counter_dev) 1196 if (private(dev)->counter_dev)
1201 ni_gpct_device_destroy(private(dev)->counter_dev); 1197 ni_gpct_device_destroy(private(dev)->counter_dev);
@@ -1204,7 +1200,6 @@ static int ni_660x_detach(struct comedi_device *dev)
1204 mite_unsetup(private(dev)->mite); 1200 mite_unsetup(private(dev)->mite);
1205 } 1201 }
1206 } 1202 }
1207 return 0;
1208} 1203}
1209 1204
1210static int 1205static int
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index d8d91f90060e..a9cf94fd0c30 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -111,7 +111,7 @@ struct ni_670x_private {
111 111
112static int ni_670x_attach(struct comedi_device *dev, 112static int ni_670x_attach(struct comedi_device *dev,
113 struct comedi_devconfig *it); 113 struct comedi_devconfig *it);
114static int ni_670x_detach(struct comedi_device *dev); 114static void ni_670x_detach(struct comedi_device *dev);
115 115
116static struct comedi_driver driver_ni_670x = { 116static struct comedi_driver driver_ni_670x = {
117 .driver_name = "ni_670x", 117 .driver_name = "ni_670x",
@@ -123,7 +123,7 @@ static struct comedi_driver driver_ni_670x = {
123static int __devinit driver_ni_670x_pci_probe(struct pci_dev *dev, 123static int __devinit driver_ni_670x_pci_probe(struct pci_dev *dev,
124 const struct pci_device_id *ent) 124 const struct pci_device_id *ent)
125{ 125{
126 return comedi_pci_auto_config(dev, driver_ni_670x.driver_name); 126 return comedi_pci_auto_config(dev, &driver_ni_670x);
127} 127}
128 128
129static void __devexit driver_ni_670x_pci_remove(struct pci_dev *dev) 129static void __devexit driver_ni_670x_pci_remove(struct pci_dev *dev)
@@ -249,19 +249,13 @@ static int ni_670x_attach(struct comedi_device *dev,
249 return 1; 249 return 1;
250} 250}
251 251
252static int ni_670x_detach(struct comedi_device *dev) 252static void ni_670x_detach(struct comedi_device *dev)
253{ 253{
254 printk(KERN_INFO "comedi%d: ni_670x: remove\n", dev->minor);
255
256 kfree(dev->subdevices[0].range_table_list); 254 kfree(dev->subdevices[0].range_table_list);
257
258 if (dev->private && devpriv->mite) 255 if (dev->private && devpriv->mite)
259 mite_unsetup(devpriv->mite); 256 mite_unsetup(devpriv->mite);
260
261 if (dev->irq) 257 if (dev->irq)
262 free_irq(dev->irq, dev); 258 free_irq(dev->irq, dev);
263
264 return 0;
265} 259}
266 260
267static int ni_670x_ao_winsn(struct comedi_device *dev, 261static int ni_670x_ao_winsn(struct comedi_device *dev,
diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index c25e44c1905e..ae896a094150 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -171,46 +171,13 @@ struct a2150_private {
171 171
172#define devpriv ((struct a2150_private *)dev->private) 172#define devpriv ((struct a2150_private *)dev->private)
173 173
174static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it);
175static int a2150_detach(struct comedi_device *dev);
176static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s); 174static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
177 175
178static struct comedi_driver driver_a2150 = {
179 .driver_name = "ni_at_a2150",
180 .module = THIS_MODULE,
181 .attach = a2150_attach,
182 .detach = a2150_detach,
183};
184
185static irqreturn_t a2150_interrupt(int irq, void *d);
186static int a2150_ai_cmdtest(struct comedi_device *dev,
187 struct comedi_subdevice *s, struct comedi_cmd *cmd);
188static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
189static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
190 struct comedi_insn *insn, unsigned int *data);
191static int a2150_get_timing(struct comedi_device *dev, unsigned int *period, 176static int a2150_get_timing(struct comedi_device *dev, unsigned int *period,
192 int flags); 177 int flags);
193static int a2150_probe(struct comedi_device *dev);
194static int a2150_set_chanlist(struct comedi_device *dev, 178static int a2150_set_chanlist(struct comedi_device *dev,
195 unsigned int start_channel, 179 unsigned int start_channel,
196 unsigned int num_channels); 180 unsigned int num_channels);
197/*
198 * A convenient macro that defines init_module() and cleanup_module(),
199 * as necessary.
200 */
201static int __init driver_a2150_init_module(void)
202{
203 return comedi_driver_register(&driver_a2150);
204}
205
206static void __exit driver_a2150_cleanup_module(void)
207{
208 comedi_driver_unregister(&driver_a2150);
209}
210
211module_init(driver_a2150_init_module);
212module_exit(driver_a2150_cleanup_module);
213
214#ifdef A2150_DEBUG 181#ifdef A2150_DEBUG
215 182
216static void ni_dump_regs(struct comedi_device *dev) 183static void ni_dump_regs(struct comedi_device *dev)
@@ -331,161 +298,6 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
331 return IRQ_HANDLED; 298 return IRQ_HANDLED;
332} 299}
333 300
334/* probes board type, returns offset */
335static int a2150_probe(struct comedi_device *dev)
336{
337 int status = inw(dev->iobase + STATUS_REG);
338 return ID_BITS(status);
339}
340
341static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
342{
343 struct comedi_subdevice *s;
344 unsigned long iobase = it->options[0];
345 unsigned int irq = it->options[1];
346 unsigned int dma = it->options[2];
347 static const int timeout = 2000;
348 int i;
349
350 printk("comedi%d: %s: io 0x%lx", dev->minor, driver_a2150.driver_name,
351 iobase);
352 if (irq) {
353 printk(", irq %u", irq);
354 } else {
355 printk(", no irq");
356 }
357 if (dma) {
358 printk(", dma %u", dma);
359 } else {
360 printk(", no dma");
361 }
362 printk("\n");
363
364 /* allocate and initialize dev->private */
365 if (alloc_private(dev, sizeof(struct a2150_private)) < 0)
366 return -ENOMEM;
367
368 if (iobase == 0) {
369 printk(" io base address required\n");
370 return -EINVAL;
371 }
372
373 /* check if io addresses are available */
374 if (!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) {
375 printk(" I/O port conflict\n");
376 return -EIO;
377 }
378 dev->iobase = iobase;
379
380 /* grab our IRQ */
381 if (irq) {
382 /* check that irq is supported */
383 if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
384 printk(" invalid irq line %u\n", irq);
385 return -EINVAL;
386 }
387 if (request_irq(irq, a2150_interrupt, 0,
388 driver_a2150.driver_name, dev)) {
389 printk("unable to allocate irq %u\n", irq);
390 return -EINVAL;
391 }
392 devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
393 dev->irq = irq;
394 }
395 /* initialize dma */
396 if (dma) {
397 if (dma == 4 || dma > 7) {
398 printk(" invalid dma channel %u\n", dma);
399 return -EINVAL;
400 }
401 if (request_dma(dma, driver_a2150.driver_name)) {
402 printk(" failed to allocate dma channel %u\n", dma);
403 return -EINVAL;
404 }
405 devpriv->dma = dma;
406 devpriv->dma_buffer =
407 kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
408 if (devpriv->dma_buffer == NULL)
409 return -ENOMEM;
410
411 disable_dma(dma);
412 set_dma_mode(dma, DMA_MODE_READ);
413
414 devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
415 }
416
417 dev->board_ptr = a2150_boards + a2150_probe(dev);
418 dev->board_name = thisboard->name;
419
420 if (alloc_subdevices(dev, 1) < 0)
421 return -ENOMEM;
422
423 /* analog input subdevice */
424 s = dev->subdevices + 0;
425 dev->read_subdev = s;
426 s->type = COMEDI_SUBD_AI;
427 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
428 s->n_chan = 4;
429 s->len_chanlist = 4;
430 s->maxdata = 0xffff;
431 s->range_table = &range_a2150;
432 s->do_cmd = a2150_ai_cmd;
433 s->do_cmdtest = a2150_ai_cmdtest;
434 s->insn_read = a2150_ai_rinsn;
435 s->cancel = a2150_cancel;
436
437 /* need to do this for software counting of completed conversions, to
438 * prevent hardware count from stopping acquisition */
439 outw(HW_COUNT_DISABLE, dev->iobase + I8253_MODE_REG);
440
441 /* set card's irq and dma levels */
442 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
443
444 /* reset and sync adc clock circuitry */
445 outw_p(DPD_BIT | APD_BIT, dev->iobase + CONFIG_REG);
446 outw_p(DPD_BIT, dev->iobase + CONFIG_REG);
447 /* initialize configuration register */
448 devpriv->config_bits = 0;
449 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
450 /* wait until offset calibration is done, then enable analog inputs */
451 for (i = 0; i < timeout; i++) {
452 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
453 break;
454 udelay(1000);
455 }
456 if (i == timeout) {
457 printk
458 (" timed out waiting for offset calibration to complete\n");
459 return -ETIME;
460 }
461 devpriv->config_bits |= ENABLE0_BIT | ENABLE1_BIT;
462 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
463
464 return 0;
465};
466
467static int a2150_detach(struct comedi_device *dev)
468{
469 printk("comedi%d: %s: remove\n", dev->minor, driver_a2150.driver_name);
470
471 /* only free stuff if it has been allocated by _attach */
472 if (dev->iobase) {
473 /* put board in power-down mode */
474 outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG);
475 release_region(dev->iobase, A2150_SIZE);
476 }
477
478 if (dev->irq)
479 free_irq(dev->irq, dev);
480 if (devpriv) {
481 if (devpriv->dma)
482 free_dma(devpriv->dma);
483 kfree(devpriv->dma_buffer);
484 }
485
486 return 0;
487};
488
489static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 301static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
490{ 302{
491 /* disable dma on card */ 303 /* disable dma on card */
@@ -539,7 +351,10 @@ static int a2150_ai_cmdtest(struct comedi_device *dev,
539 if (err) 351 if (err)
540 return 1; 352 return 1;
541 353
542 /* step 2: make sure trigger sources are unique and mutually compatible */ 354 /*
355 * step 2: make sure trigger sources are unique and mutually
356 * compatible
357 */
543 358
544 if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) 359 if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
545 err++; 360 err++;
@@ -771,7 +586,10 @@ static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
771 /* start acquisition for soft trigger */ 586 /* start acquisition for soft trigger */
772 outw(0, dev->iobase + FIFO_START_REG); 587 outw(0, dev->iobase + FIFO_START_REG);
773 588
774 /* there is a 35.6 sample delay for data to get through the antialias filter */ 589 /*
590 * there is a 35.6 sample delay for data to get through the
591 * antialias filter
592 */
775 for (n = 0; n < filter_delay; n++) { 593 for (n = 0; n < filter_delay; n++) {
776 for (i = 0; i < timeout; i++) { 594 for (i = 0; i < timeout; i++) {
777 if (inw(dev->iobase + STATUS_REG) & FNE_BIT) 595 if (inw(dev->iobase + STATUS_REG) & FNE_BIT)
@@ -812,8 +630,10 @@ static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
812 return n; 630 return n;
813} 631}
814 632
815/* sets bits in devpriv->clock_bits to nearest approximation of requested period, 633/*
816 * adjusts requested period to actual timing. */ 634 * sets bits in devpriv->clock_bits to nearest approximation of requested
635 * period, adjusts requested period to actual timing.
636 */
817static int a2150_get_timing(struct comedi_device *dev, unsigned int *period, 637static int a2150_get_timing(struct comedi_device *dev, unsigned int *period,
818 int flags) 638 int flags)
819{ 639{
@@ -920,6 +740,162 @@ static int a2150_set_chanlist(struct comedi_device *dev,
920 return 0; 740 return 0;
921} 741}
922 742
743/* probes board type, returns offset */
744static int a2150_probe(struct comedi_device *dev)
745{
746 int status = inw(dev->iobase + STATUS_REG);
747 return ID_BITS(status);
748}
749
750static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
751{
752 struct comedi_subdevice *s;
753 unsigned long iobase = it->options[0];
754 unsigned int irq = it->options[1];
755 unsigned int dma = it->options[2];
756 static const int timeout = 2000;
757 int i;
758
759 printk("comedi%d: %s: io 0x%lx", dev->minor, dev->driver->driver_name,
760 iobase);
761 if (irq) {
762 printk(", irq %u", irq);
763 } else {
764 printk(", no irq");
765 }
766 if (dma) {
767 printk(", dma %u", dma);
768 } else {
769 printk(", no dma");
770 }
771 printk("\n");
772
773 /* allocate and initialize dev->private */
774 if (alloc_private(dev, sizeof(struct a2150_private)) < 0)
775 return -ENOMEM;
776
777 if (iobase == 0) {
778 printk(" io base address required\n");
779 return -EINVAL;
780 }
781
782 /* check if io addresses are available */
783 if (!request_region(iobase, A2150_SIZE, dev->driver->driver_name)) {
784 printk(" I/O port conflict\n");
785 return -EIO;
786 }
787 dev->iobase = iobase;
788
789 /* grab our IRQ */
790 if (irq) {
791 /* check that irq is supported */
792 if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
793 printk(" invalid irq line %u\n", irq);
794 return -EINVAL;
795 }
796 if (request_irq(irq, a2150_interrupt, 0,
797 dev->driver->driver_name, dev)) {
798 printk("unable to allocate irq %u\n", irq);
799 return -EINVAL;
800 }
801 devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
802 dev->irq = irq;
803 }
804 /* initialize dma */
805 if (dma) {
806 if (dma == 4 || dma > 7) {
807 printk(" invalid dma channel %u\n", dma);
808 return -EINVAL;
809 }
810 if (request_dma(dma, dev->driver->driver_name)) {
811 printk(" failed to allocate dma channel %u\n", dma);
812 return -EINVAL;
813 }
814 devpriv->dma = dma;
815 devpriv->dma_buffer =
816 kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
817 if (devpriv->dma_buffer == NULL)
818 return -ENOMEM;
819
820 disable_dma(dma);
821 set_dma_mode(dma, DMA_MODE_READ);
822
823 devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
824 }
825
826 dev->board_ptr = a2150_boards + a2150_probe(dev);
827 dev->board_name = thisboard->name;
828
829 if (alloc_subdevices(dev, 1) < 0)
830 return -ENOMEM;
831
832 /* analog input subdevice */
833 s = dev->subdevices + 0;
834 dev->read_subdev = s;
835 s->type = COMEDI_SUBD_AI;
836 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
837 s->n_chan = 4;
838 s->len_chanlist = 4;
839 s->maxdata = 0xffff;
840 s->range_table = &range_a2150;
841 s->do_cmd = a2150_ai_cmd;
842 s->do_cmdtest = a2150_ai_cmdtest;
843 s->insn_read = a2150_ai_rinsn;
844 s->cancel = a2150_cancel;
845
846 /* need to do this for software counting of completed conversions, to
847 * prevent hardware count from stopping acquisition */
848 outw(HW_COUNT_DISABLE, dev->iobase + I8253_MODE_REG);
849
850 /* set card's irq and dma levels */
851 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
852
853 /* reset and sync adc clock circuitry */
854 outw_p(DPD_BIT | APD_BIT, dev->iobase + CONFIG_REG);
855 outw_p(DPD_BIT, dev->iobase + CONFIG_REG);
856 /* initialize configuration register */
857 devpriv->config_bits = 0;
858 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
859 /* wait until offset calibration is done, then enable analog inputs */
860 for (i = 0; i < timeout; i++) {
861 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
862 break;
863 udelay(1000);
864 }
865 if (i == timeout) {
866 printk
867 (" timed out waiting for offset calibration to complete\n");
868 return -ETIME;
869 }
870 devpriv->config_bits |= ENABLE0_BIT | ENABLE1_BIT;
871 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
872
873 return 0;
874};
875
876static void a2150_detach(struct comedi_device *dev)
877{
878 if (dev->iobase) {
879 outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG);
880 release_region(dev->iobase, A2150_SIZE);
881 }
882 if (dev->irq)
883 free_irq(dev->irq, dev);
884 if (devpriv) {
885 if (devpriv->dma)
886 free_dma(devpriv->dma);
887 kfree(devpriv->dma_buffer);
888 }
889};
890
891static struct comedi_driver ni_at_a2150_driver = {
892 .driver_name = "ni_at_a2150",
893 .module = THIS_MODULE,
894 .attach = a2150_attach,
895 .detach = a2150_detach,
896};
897module_comedi_driver(ni_at_a2150_driver);
898
923MODULE_AUTHOR("Comedi http://www.comedi.org"); 899MODULE_AUTHOR("Comedi http://www.comedi.org");
924MODULE_DESCRIPTION("Comedi low-level driver"); 900MODULE_DESCRIPTION("Comedi low-level driver");
925MODULE_LICENSE("GPL"); 901MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c
index 138dcc2275ab..c43dd8ada1da 100644
--- a/drivers/staging/comedi/drivers/ni_at_ao.c
+++ b/drivers/staging/comedi/drivers/ni_at_ao.c
@@ -157,17 +157,6 @@ struct atao_board {
157 int n_ao_chans; 157 int n_ao_chans;
158}; 158};
159 159
160static const struct atao_board atao_boards[] = {
161 {
162 .name = "ai-ao-6",
163 .n_ao_chans = 6,
164 },
165 {
166 .name = "ai-ao-10",
167 .n_ao_chans = 10,
168 },
169};
170
171#define thisboard ((struct atao_board *)dev->board_ptr) 160#define thisboard ((struct atao_board *)dev->board_ptr)
172 161
173struct atao_private { 162struct atao_private {
@@ -182,133 +171,6 @@ struct atao_private {
182 171
183#define devpriv ((struct atao_private *)dev->private) 172#define devpriv ((struct atao_private *)dev->private)
184 173
185static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it);
186static int atao_detach(struct comedi_device *dev);
187static struct comedi_driver driver_atao = {
188 .driver_name = "ni_at_ao",
189 .module = THIS_MODULE,
190 .attach = atao_attach,
191 .detach = atao_detach,
192 .board_name = &atao_boards[0].name,
193 .offset = sizeof(struct atao_board),
194 .num_names = ARRAY_SIZE(atao_boards),
195};
196
197static int __init driver_atao_init_module(void)
198{
199 return comedi_driver_register(&driver_atao);
200}
201
202static void __exit driver_atao_cleanup_module(void)
203{
204 comedi_driver_unregister(&driver_atao);
205}
206
207module_init(driver_atao_init_module);
208module_exit(driver_atao_cleanup_module);
209
210static void atao_reset(struct comedi_device *dev);
211
212static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
213 struct comedi_insn *insn, unsigned int *data);
214static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
215 struct comedi_insn *insn, unsigned int *data);
216static int atao_dio_insn_bits(struct comedi_device *dev,
217 struct comedi_subdevice *s,
218 struct comedi_insn *insn, unsigned int *data);
219static int atao_dio_insn_config(struct comedi_device *dev,
220 struct comedi_subdevice *s,
221 struct comedi_insn *insn, unsigned int *data);
222static int atao_calib_insn_read(struct comedi_device *dev,
223 struct comedi_subdevice *s,
224 struct comedi_insn *insn, unsigned int *data);
225static int atao_calib_insn_write(struct comedi_device *dev,
226 struct comedi_subdevice *s,
227 struct comedi_insn *insn, unsigned int *data);
228
229static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
230{
231 struct comedi_subdevice *s;
232 unsigned long iobase;
233 int ao_unipolar;
234
235 iobase = it->options[0];
236 if (iobase == 0)
237 iobase = 0x1c0;
238 ao_unipolar = it->options[3];
239
240 printk(KERN_INFO "comedi%d: ni_at_ao: 0x%04lx", dev->minor, iobase);
241
242 if (!request_region(iobase, ATAO_SIZE, "ni_at_ao")) {
243 printk(" I/O port conflict\n");
244 return -EIO;
245 }
246 dev->iobase = iobase;
247
248 /* dev->board_ptr = atao_probe(dev); */
249
250 dev->board_name = thisboard->name;
251
252 if (alloc_private(dev, sizeof(struct atao_private)) < 0)
253 return -ENOMEM;
254
255 if (alloc_subdevices(dev, 4) < 0)
256 return -ENOMEM;
257
258 s = dev->subdevices + 0;
259 /* analog output subdevice */
260 s->type = COMEDI_SUBD_AO;
261 s->subdev_flags = SDF_WRITABLE;
262 s->n_chan = thisboard->n_ao_chans;
263 s->maxdata = (1 << 12) - 1;
264 if (ao_unipolar)
265 s->range_table = &range_unipolar10;
266 else
267 s->range_table = &range_bipolar10;
268 s->insn_write = &atao_ao_winsn;
269 s->insn_read = &atao_ao_rinsn;
270
271 s = dev->subdevices + 1;
272 /* digital i/o subdevice */
273 s->type = COMEDI_SUBD_DIO;
274 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
275 s->n_chan = 8;
276 s->maxdata = 1;
277 s->range_table = &range_digital;
278 s->insn_bits = atao_dio_insn_bits;
279 s->insn_config = atao_dio_insn_config;
280
281 s = dev->subdevices + 2;
282 /* caldac subdevice */
283 s->type = COMEDI_SUBD_CALIB;
284 s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
285 s->n_chan = 21;
286 s->maxdata = 0xff;
287 s->insn_read = atao_calib_insn_read;
288 s->insn_write = atao_calib_insn_write;
289
290 s = dev->subdevices + 3;
291 /* eeprom subdevice */
292 /* s->type=COMEDI_SUBD_EEPROM; */
293 s->type = COMEDI_SUBD_UNUSED;
294
295 atao_reset(dev);
296
297 printk(KERN_INFO "\n");
298
299 return 0;
300}
301
302static int atao_detach(struct comedi_device *dev)
303{
304 printk(KERN_INFO "comedi%d: atao: remove\n", dev->minor);
305
306 if (dev->iobase)
307 release_region(dev->iobase, ATAO_SIZE);
308
309 return 0;
310}
311
312static void atao_reset(struct comedi_device *dev) 174static void atao_reset(struct comedi_device *dev)
313{ 175{
314 /* This is the reset sequence described in the manual */ 176 /* This is the reset sequence described in the manual */
@@ -471,6 +333,106 @@ static int atao_calib_insn_write(struct comedi_device *dev,
471 return insn->n; 333 return insn->n;
472} 334}
473 335
336static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
337{
338 struct comedi_subdevice *s;
339 unsigned long iobase;
340 int ao_unipolar;
341
342 iobase = it->options[0];
343 if (iobase == 0)
344 iobase = 0x1c0;
345 ao_unipolar = it->options[3];
346
347 printk(KERN_INFO "comedi%d: ni_at_ao: 0x%04lx", dev->minor, iobase);
348
349 if (!request_region(iobase, ATAO_SIZE, "ni_at_ao")) {
350 printk(" I/O port conflict\n");
351 return -EIO;
352 }
353 dev->iobase = iobase;
354
355 /* dev->board_ptr = atao_probe(dev); */
356
357 dev->board_name = thisboard->name;
358
359 if (alloc_private(dev, sizeof(struct atao_private)) < 0)
360 return -ENOMEM;
361
362 if (alloc_subdevices(dev, 4) < 0)
363 return -ENOMEM;
364
365 s = dev->subdevices + 0;
366 /* analog output subdevice */
367 s->type = COMEDI_SUBD_AO;
368 s->subdev_flags = SDF_WRITABLE;
369 s->n_chan = thisboard->n_ao_chans;
370 s->maxdata = (1 << 12) - 1;
371 if (ao_unipolar)
372 s->range_table = &range_unipolar10;
373 else
374 s->range_table = &range_bipolar10;
375 s->insn_write = &atao_ao_winsn;
376 s->insn_read = &atao_ao_rinsn;
377
378 s = dev->subdevices + 1;
379 /* digital i/o subdevice */
380 s->type = COMEDI_SUBD_DIO;
381 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
382 s->n_chan = 8;
383 s->maxdata = 1;
384 s->range_table = &range_digital;
385 s->insn_bits = atao_dio_insn_bits;
386 s->insn_config = atao_dio_insn_config;
387
388 s = dev->subdevices + 2;
389 /* caldac subdevice */
390 s->type = COMEDI_SUBD_CALIB;
391 s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
392 s->n_chan = 21;
393 s->maxdata = 0xff;
394 s->insn_read = atao_calib_insn_read;
395 s->insn_write = atao_calib_insn_write;
396
397 s = dev->subdevices + 3;
398 /* eeprom subdevice */
399 /* s->type=COMEDI_SUBD_EEPROM; */
400 s->type = COMEDI_SUBD_UNUSED;
401
402 atao_reset(dev);
403
404 printk(KERN_INFO "\n");
405
406 return 0;
407}
408
409static void atao_detach(struct comedi_device *dev)
410{
411 if (dev->iobase)
412 release_region(dev->iobase, ATAO_SIZE);
413}
414
415static const struct atao_board atao_boards[] = {
416 {
417 .name = "ai-ao-6",
418 .n_ao_chans = 6,
419 }, {
420 .name = "ai-ao-10",
421 .n_ao_chans = 10,
422 },
423};
424
425static struct comedi_driver ni_at_ao_driver = {
426 .driver_name = "ni_at_ao",
427 .module = THIS_MODULE,
428 .attach = atao_attach,
429 .detach = atao_detach,
430 .board_name = &atao_boards[0].name,
431 .offset = sizeof(struct atao_board),
432 .num_names = ARRAY_SIZE(atao_boards),
433};
434module_comedi_driver(ni_at_ao_driver);
435
474MODULE_AUTHOR("Comedi http://www.comedi.org"); 436MODULE_AUTHOR("Comedi http://www.comedi.org");
475MODULE_DESCRIPTION("Comedi low-level driver"); 437MODULE_DESCRIPTION("Comedi low-level driver");
476MODULE_LICENSE("GPL"); 438MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ni_atmio.c b/drivers/staging/comedi/drivers/ni_atmio.c
index 647c228abfbf..6448373878ed 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -343,49 +343,8 @@ static struct pnp_device_id device_ids[] = {
343 343
344MODULE_DEVICE_TABLE(pnp, device_ids); 344MODULE_DEVICE_TABLE(pnp, device_ids);
345 345
346static int ni_atmio_attach(struct comedi_device *dev,
347 struct comedi_devconfig *it);
348static int ni_atmio_detach(struct comedi_device *dev);
349static struct comedi_driver driver_atmio = {
350 .driver_name = "ni_atmio",
351 .module = THIS_MODULE,
352 .attach = ni_atmio_attach,
353 .detach = ni_atmio_detach,
354};
355
356static int __init driver_atmio_init_module(void)
357{
358 return comedi_driver_register(&driver_atmio);
359}
360
361static void __exit driver_atmio_cleanup_module(void)
362{
363 comedi_driver_unregister(&driver_atmio);
364}
365
366module_init(driver_atmio_init_module);
367module_exit(driver_atmio_cleanup_module);
368
369#include "ni_mio_common.c" 346#include "ni_mio_common.c"
370 347
371static int ni_getboardtype(struct comedi_device *dev);
372
373/* clean up allocated resources */
374static int ni_atmio_detach(struct comedi_device *dev)
375{
376 mio_common_detach(dev);
377
378 if (dev->iobase)
379 release_region(dev->iobase, NI_SIZE);
380 if (dev->irq)
381 free_irq(dev->irq, dev);
382
383 if (devpriv->isapnp_dev)
384 pnp_device_detach(devpriv->isapnp_dev);
385
386 return 0;
387}
388
389static int ni_isapnp_find_board(struct pnp_dev **dev) 348static int ni_isapnp_find_board(struct pnp_dev **dev)
390{ 349{
391 struct pnp_dev *isapnp_dev = NULL; 350 struct pnp_dev *isapnp_dev = NULL;
@@ -424,6 +383,26 @@ static int ni_isapnp_find_board(struct pnp_dev **dev)
424 return 0; 383 return 0;
425} 384}
426 385
386static int ni_getboardtype(struct comedi_device *dev)
387{
388 int device_id = ni_read_eeprom(dev, 511);
389 int i;
390
391 for (i = 0; i < n_ni_boards; i++) {
392 if (ni_boards[i].device_id == device_id)
393 return i;
394
395 }
396 if (device_id == 255)
397 printk(" can't find board\n");
398 else if (device_id == 0)
399 printk(" EEPROM read error (?) or device not found\n");
400 else
401 printk(" unknown device ID %d -- contact author\n", device_id);
402
403 return -1;
404}
405
427static int ni_atmio_attach(struct comedi_device *dev, 406static int ni_atmio_attach(struct comedi_device *dev,
428 struct comedi_devconfig *it) 407 struct comedi_devconfig *it)
429{ 408{
@@ -518,22 +497,21 @@ static int ni_atmio_attach(struct comedi_device *dev,
518 return 0; 497 return 0;
519} 498}
520 499
521static int ni_getboardtype(struct comedi_device *dev) 500static void ni_atmio_detach(struct comedi_device *dev)
522{ 501{
523 int device_id = ni_read_eeprom(dev, 511); 502 mio_common_detach(dev);
524 int i; 503 if (dev->iobase)
525 504 release_region(dev->iobase, NI_SIZE);
526 for (i = 0; i < n_ni_boards; i++) { 505 if (dev->irq)
527 if (ni_boards[i].device_id == device_id) 506 free_irq(dev->irq, dev);
528 return i; 507 if (devpriv->isapnp_dev)
529 508 pnp_device_detach(devpriv->isapnp_dev);
530 }
531 if (device_id == 255)
532 printk(" can't find board\n");
533 else if (device_id == 0)
534 printk(" EEPROM read error (?) or device not found\n");
535 else
536 printk(" unknown device ID %d -- contact author\n", device_id);
537
538 return -1;
539} 509}
510
511static struct comedi_driver ni_atmio_driver = {
512 .driver_name = "ni_atmio",
513 .module = THIS_MODULE,
514 .attach = ni_atmio_attach,
515 .detach = ni_atmio_detach,
516};
517module_comedi_driver(ni_atmio_driver);
diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c
index 285b933551ab..4f6145326747 100644
--- a/drivers/staging/comedi/drivers/ni_atmio16d.c
+++ b/drivers/staging/comedi/drivers/ni_atmio16d.c
@@ -110,60 +110,8 @@ struct atmio16_board_t {
110 int has_8255; 110 int has_8255;
111}; 111};
112 112
113static const struct atmio16_board_t atmio16_boards[] = {
114 {
115 .name = "atmio16",
116 .has_8255 = 0,
117 },
118 {
119 .name = "atmio16d",
120 .has_8255 = 1,
121 },
122};
123
124#define n_atmio16_boards ARRAY_SIZE(atmio16_boards)
125
126#define boardtype ((const struct atmio16_board_t *)dev->board_ptr) 113#define boardtype ((const struct atmio16_board_t *)dev->board_ptr)
127 114
128/* function prototypes */
129static int atmio16d_attach(struct comedi_device *dev,
130 struct comedi_devconfig *it);
131static int atmio16d_detach(struct comedi_device *dev);
132static irqreturn_t atmio16d_interrupt(int irq, void *d);
133static int atmio16d_ai_cmdtest(struct comedi_device *dev,
134 struct comedi_subdevice *s,
135 struct comedi_cmd *cmd);
136static int atmio16d_ai_cmd(struct comedi_device *dev,
137 struct comedi_subdevice *s);
138static int atmio16d_ai_cancel(struct comedi_device *dev,
139 struct comedi_subdevice *s);
140static void reset_counters(struct comedi_device *dev);
141static void reset_atmio16d(struct comedi_device *dev);
142
143/* main driver struct */
144static struct comedi_driver driver_atmio16d = {
145 .driver_name = "atmio16",
146 .module = THIS_MODULE,
147 .attach = atmio16d_attach,
148 .detach = atmio16d_detach,
149 .board_name = &atmio16_boards[0].name,
150 .num_names = n_atmio16_boards,
151 .offset = sizeof(struct atmio16_board_t),
152};
153
154static int __init driver_atmio16d_init_module(void)
155{
156 return comedi_driver_register(&driver_atmio16d);
157}
158
159static void __exit driver_atmio16d_cleanup_module(void)
160{
161 comedi_driver_unregister(&driver_atmio16d);
162}
163
164module_init(driver_atmio16d_init_module);
165module_exit(driver_atmio16d_cleanup_module);
166
167/* range structs */ 115/* range structs */
168static const struct comedi_lrange range_atmio16d_ai_10_bipolar = { 4, { 116static const struct comedi_lrange range_atmio16d_ai_10_bipolar = { 4, {
169 BIP_RANGE 117 BIP_RANGE
@@ -881,24 +829,38 @@ static int atmio16d_attach(struct comedi_device *dev,
881 return 0; 829 return 0;
882} 830}
883 831
884static int atmio16d_detach(struct comedi_device *dev) 832static void atmio16d_detach(struct comedi_device *dev)
885{ 833{
886 printk(KERN_INFO "comedi%d: atmio16d: remove\n", dev->minor);
887
888 if (dev->subdevices && boardtype->has_8255) 834 if (dev->subdevices && boardtype->has_8255)
889 subdev_8255_cleanup(dev, dev->subdevices + 3); 835 subdev_8255_cleanup(dev, dev->subdevices + 3);
890
891 if (dev->irq) 836 if (dev->irq)
892 free_irq(dev->irq, dev); 837 free_irq(dev->irq, dev);
893
894 reset_atmio16d(dev); 838 reset_atmio16d(dev);
895
896 if (dev->iobase) 839 if (dev->iobase)
897 release_region(dev->iobase, ATMIO16D_SIZE); 840 release_region(dev->iobase, ATMIO16D_SIZE);
898
899 return 0;
900} 841}
901 842
843static const struct atmio16_board_t atmio16_boards[] = {
844 {
845 .name = "atmio16",
846 .has_8255 = 0,
847 }, {
848 .name = "atmio16d",
849 .has_8255 = 1,
850 },
851};
852
853static struct comedi_driver atmio16d_driver = {
854 .driver_name = "atmio16",
855 .module = THIS_MODULE,
856 .attach = atmio16d_attach,
857 .detach = atmio16d_detach,
858 .board_name = &atmio16_boards[0].name,
859 .num_names = ARRAY_SIZE(atmio16_boards),
860 .offset = sizeof(struct atmio16_board_t),
861};
862module_comedi_driver(atmio16d_driver);
863
902MODULE_AUTHOR("Comedi http://www.comedi.org"); 864MODULE_AUTHOR("Comedi http://www.comedi.org");
903MODULE_DESCRIPTION("Comedi low-level driver"); 865MODULE_DESCRIPTION("Comedi low-level driver");
904MODULE_LICENSE("GPL"); 866MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index e2420123db87..75764e8d27eb 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -57,7 +57,7 @@ static struct pcmcia_device *pcmcia_cur_dev;
57 57
58static int dio700_attach(struct comedi_device *dev, 58static int dio700_attach(struct comedi_device *dev,
59 struct comedi_devconfig *it); 59 struct comedi_devconfig *it);
60static int dio700_detach(struct comedi_device *dev); 60static void dio700_detach(struct comedi_device *dev);
61 61
62enum dio700_bustype { pcmcia_bustype }; 62enum dio700_bustype { pcmcia_bustype };
63 63
@@ -419,19 +419,14 @@ static int dio700_attach(struct comedi_device *dev, struct comedi_devconfig *it)
419 return 0; 419 return 0;
420}; 420};
421 421
422static int dio700_detach(struct comedi_device *dev) 422static void dio700_detach(struct comedi_device *dev)
423{ 423{
424 printk(KERN_ERR "comedi%d: ni_daq_700: cs-remove\n", dev->minor);
425
426 if (dev->subdevices) 424 if (dev->subdevices)
427 subdev_700_cleanup(dev, dev->subdevices + 0); 425 subdev_700_cleanup(dev, dev->subdevices + 0);
428
429 if (thisboard->bustype != pcmcia_bustype && dev->iobase) 426 if (thisboard->bustype != pcmcia_bustype && dev->iobase)
430 release_region(dev->iobase, DIO700_SIZE); 427 release_region(dev->iobase, DIO700_SIZE);
431 if (dev->irq) 428 if (dev->irq)
432 free_irq(dev->irq, dev); 429 free_irq(dev->irq, dev);
433
434 return 0;
435}; 430};
436 431
437static void dio700_config(struct pcmcia_device *link); 432static void dio700_config(struct pcmcia_device *link);
@@ -472,18 +467,12 @@ static int dio700_cs_attach(struct pcmcia_device *link)
472 467
473static void dio700_cs_detach(struct pcmcia_device *link) 468static void dio700_cs_detach(struct pcmcia_device *link)
474{ 469{
475
476 printk(KERN_INFO "ni_daq_700: cs-detach!\n");
477
478 dev_dbg(&link->dev, "dio700_cs_detach\n");
479
480 ((struct local_info_t *)link->priv)->stop = 1; 470 ((struct local_info_t *)link->priv)->stop = 1;
481 dio700_release(link); 471 dio700_release(link);
482 472
483 /* This points to the parent struct local_info_t struct */ 473 /* This points to the parent struct local_info_t struct */
484 kfree(link->priv); 474 kfree(link->priv);
485 475}
486} /* dio700_cs_detach */
487 476
488static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev, 477static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev,
489 void *priv_data) 478 void *priv_data)
diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c
index c0423a8c3e36..493a22788637 100644
--- a/drivers/staging/comedi/drivers/ni_daq_dio24.c
+++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c
@@ -57,7 +57,7 @@ static struct pcmcia_device *pcmcia_cur_dev;
57#define DIO24_SIZE 4 /* size of io region used by board */ 57#define DIO24_SIZE 4 /* size of io region used by board */
58 58
59static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it); 59static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it);
60static int dio24_detach(struct comedi_device *dev); 60static void dio24_detach(struct comedi_device *dev);
61 61
62enum dio24_bustype { pcmcia_bustype }; 62enum dio24_bustype { pcmcia_bustype };
63 63
@@ -168,19 +168,14 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it)
168 return 0; 168 return 0;
169}; 169};
170 170
171static int dio24_detach(struct comedi_device *dev) 171static void dio24_detach(struct comedi_device *dev)
172{ 172{
173 dev_info(dev->hw_dev, "comedi%d: ni_daq_dio24: remove\n", dev->minor);
174
175 if (dev->subdevices) 173 if (dev->subdevices)
176 subdev_8255_cleanup(dev, dev->subdevices + 0); 174 subdev_8255_cleanup(dev, dev->subdevices + 0);
177
178 if (thisboard->bustype != pcmcia_bustype && dev->iobase) 175 if (thisboard->bustype != pcmcia_bustype && dev->iobase)
179 release_region(dev->iobase, DIO24_SIZE); 176 release_region(dev->iobase, DIO24_SIZE);
180 if (dev->irq) 177 if (dev->irq)
181 free_irq(dev->irq, dev); 178 free_irq(dev->irq, dev);
182
183 return 0;
184}; 179};
185 180
186static void dio24_config(struct pcmcia_device *link); 181static void dio24_config(struct pcmcia_device *link);
@@ -221,18 +216,12 @@ static int dio24_cs_attach(struct pcmcia_device *link)
221 216
222static void dio24_cs_detach(struct pcmcia_device *link) 217static void dio24_cs_detach(struct pcmcia_device *link)
223{ 218{
224
225 printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - cs-detach!\n");
226
227 dev_dbg(&link->dev, "dio24_cs_detach\n");
228
229 ((struct local_info_t *)link->priv)->stop = 1; 219 ((struct local_info_t *)link->priv)->stop = 1;
230 dio24_release(link); 220 dio24_release(link);
231 221
232 /* This points to the parent local_info_t struct */ 222 /* This points to the parent local_info_t struct */
233 kfree(link->priv); 223 kfree(link->priv);
234 224}
235} /* dio24_cs_detach */
236 225
237static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, 226static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
238 void *priv_data) 227 void *priv_data)
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index 721b2be22500..53349777246b 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -805,13 +805,10 @@ static int labpc_find_device(struct comedi_device *dev, int bus, int slot)
805} 805}
806#endif 806#endif
807 807
808int labpc_common_detach(struct comedi_device *dev) 808void labpc_common_detach(struct comedi_device *dev)
809{ 809{
810 printk(KERN_ERR "comedi%d: ni_labpc: detach\n", dev->minor);
811
812 if (dev->subdevices) 810 if (dev->subdevices)
813 subdev_8255_cleanup(dev, dev->subdevices + 2); 811 subdev_8255_cleanup(dev, dev->subdevices + 2);
814
815#ifdef CONFIG_ISA_DMA_API 812#ifdef CONFIG_ISA_DMA_API
816 /* only free stuff if it has been allocated by _attach */ 813 /* only free stuff if it has been allocated by _attach */
817 kfree(devpriv->dma_buffer); 814 kfree(devpriv->dma_buffer);
@@ -826,8 +823,6 @@ int labpc_common_detach(struct comedi_device *dev)
826 if (devpriv->mite) 823 if (devpriv->mite)
827 mite_unsetup(devpriv->mite); 824 mite_unsetup(devpriv->mite);
828#endif 825#endif
829
830 return 0;
831}; 826};
832EXPORT_SYMBOL_GPL(labpc_common_detach); 827EXPORT_SYMBOL_GPL(labpc_common_detach);
833 828
@@ -2141,7 +2136,7 @@ static void write_caldac(struct comedi_device *dev, unsigned int channel,
2141static int __devinit driver_labpc_pci_probe(struct pci_dev *dev, 2136static int __devinit driver_labpc_pci_probe(struct pci_dev *dev,
2142 const struct pci_device_id *ent) 2137 const struct pci_device_id *ent)
2143{ 2138{
2144 return comedi_pci_auto_config(dev, driver_labpc.driver_name); 2139 return comedi_pci_auto_config(dev, &driver_labpc);
2145} 2140}
2146 2141
2147static void __devexit driver_labpc_pci_remove(struct pci_dev *dev) 2142static void __devexit driver_labpc_pci_remove(struct pci_dev *dev)
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index 422cee58a967..e052ed3ba544 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -103,7 +103,7 @@ struct labpc_private {
103 103
104int labpc_common_attach(struct comedi_device *dev, unsigned long iobase, 104int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
105 unsigned int irq, unsigned int dma); 105 unsigned int irq, unsigned int dma);
106int labpc_common_detach(struct comedi_device *dev); 106void labpc_common_detach(struct comedi_device *dev);
107 107
108extern const int labpc_1200_is_unipolar[]; 108extern const int labpc_1200_is_unipolar[];
109extern const int labpc_1200_ai_gain_bits[]; 109extern const int labpc_1200_ai_gain_bits[];
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index ff3840544dd4..dbb61b6b3ed1 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -188,21 +188,13 @@ static int labpc_cs_attach(struct pcmcia_device *link)
188 188
189static void labpc_cs_detach(struct pcmcia_device *link) 189static void labpc_cs_detach(struct pcmcia_device *link)
190{ 190{
191 dev_dbg(&link->dev, "labpc_cs_detach\n");
192
193 /*
194 If the device is currently configured and active, we won't
195 actually delete it yet. Instead, it is marked so that when
196 the release() function is called, that will trigger a proper
197 detach().
198 */
199 ((struct local_info_t *)link->priv)->stop = 1; 191 ((struct local_info_t *)link->priv)->stop = 1;
200 labpc_release(link); 192 labpc_release(link);
201 193
202 /* This points to the parent local_info_t struct (may be null) */ 194 /* This points to the parent local_info_t struct (may be null) */
203 kfree(link->priv); 195 kfree(link->priv);
204 196
205} /* labpc_cs_detach */ 197}
206 198
207static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, 199static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
208 void *priv_data) 200 void *priv_data)
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c
index 53ec24bb6dce..b85765d266c2 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -227,7 +227,7 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
227 227
228static int mio_cs_attach(struct comedi_device *dev, 228static int mio_cs_attach(struct comedi_device *dev,
229 struct comedi_devconfig *it); 229 struct comedi_devconfig *it);
230static int mio_cs_detach(struct comedi_device *dev); 230static void mio_cs_detach(struct comedi_device *dev);
231static struct comedi_driver driver_ni_mio_cs = { 231static struct comedi_driver driver_ni_mio_cs = {
232 .driver_name = "ni_mio_cs", 232 .driver_name = "ni_mio_cs",
233 .module = THIS_MODULE, 233 .module = THIS_MODULE,
@@ -240,18 +240,11 @@ static struct comedi_driver driver_ni_mio_cs = {
240static int ni_getboardtype(struct comedi_device *dev, 240static int ni_getboardtype(struct comedi_device *dev,
241 struct pcmcia_device *link); 241 struct pcmcia_device *link);
242 242
243/* clean up allocated resources */ 243static void mio_cs_detach(struct comedi_device *dev)
244/* called when driver is removed */
245static int mio_cs_detach(struct comedi_device *dev)
246{ 244{
247 mio_common_detach(dev); 245 mio_common_detach(dev);
248
249 /* PCMCIA layer frees the IO region */
250
251 if (dev->irq) 246 if (dev->irq)
252 free_irq(dev->irq, dev); 247 free_irq(dev->irq, dev);
253
254 return 0;
255} 248}
256 249
257static void mio_cs_config(struct pcmcia_device *link); 250static void mio_cs_config(struct pcmcia_device *link);
@@ -276,8 +269,6 @@ static void cs_release(struct pcmcia_device *link)
276 269
277static void cs_detach(struct pcmcia_device *link) 270static void cs_detach(struct pcmcia_device *link)
278{ 271{
279 DPRINTK("cs_detach(link=%p)\n", link);
280
281 cs_release(link); 272 cs_release(link);
282} 273}
283 274
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index 1df8fcbcd108..37b700830e21 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -293,18 +293,9 @@ enum FPGA_Control_Bits {
293#define IntEn (TransferReady|CountExpired|Waited|PrimaryTC|SecondaryTC) 293#define IntEn (TransferReady|CountExpired|Waited|PrimaryTC|SecondaryTC)
294#endif 294#endif
295 295
296static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it);
297static int nidio_detach(struct comedi_device *dev);
298static int ni_pcidio_cancel(struct comedi_device *dev, 296static int ni_pcidio_cancel(struct comedi_device *dev,
299 struct comedi_subdevice *s); 297 struct comedi_subdevice *s);
300 298
301static struct comedi_driver driver_pcidio = {
302 .driver_name = "ni_pcidio",
303 .module = THIS_MODULE,
304 .attach = nidio_attach,
305 .detach = nidio_detach,
306};
307
308struct nidio_board { 299struct nidio_board {
309 300
310 int dev_id; 301 int dev_id;
@@ -381,22 +372,6 @@ static const struct nidio_board nidio_boards[] = {
381#define n_nidio_boards ARRAY_SIZE(nidio_boards) 372#define n_nidio_boards ARRAY_SIZE(nidio_boards)
382#define this_board ((const struct nidio_board *)dev->board_ptr) 373#define this_board ((const struct nidio_board *)dev->board_ptr)
383 374
384static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = {
385 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150)},
386 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320)},
387 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x12b0)},
388 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0160)},
389 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1630)},
390 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x13c0)},
391 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0400)},
392 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1250)},
393 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x17d0)},
394 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1800)},
395 {0}
396};
397
398MODULE_DEVICE_TABLE(pci, ni_pcidio_pci_table);
399
400struct nidio96_private { 375struct nidio96_private {
401 struct mite_struct *mite; 376 struct mite_struct *mite;
402 int boardtype; 377 int boardtype;
@@ -414,7 +389,6 @@ static int ni_pcidio_cmdtest(struct comedi_device *dev,
414static int ni_pcidio_cmd(struct comedi_device *dev, struct comedi_subdevice *s); 389static int ni_pcidio_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
415static int ni_pcidio_inttrig(struct comedi_device *dev, 390static int ni_pcidio_inttrig(struct comedi_device *dev,
416 struct comedi_subdevice *s, unsigned int trignum); 391 struct comedi_subdevice *s, unsigned int trignum);
417static int nidio_find_device(struct comedi_device *dev, int bus, int slot);
418static int ni_pcidio_ns_to_timer(int *nanosec, int round_mode); 392static int ni_pcidio_ns_to_timer(int *nanosec, int round_mode);
419static int setup_mite_dma(struct comedi_device *dev, 393static int setup_mite_dma(struct comedi_device *dev,
420 struct comedi_subdevice *s); 394 struct comedi_subdevice *s);
@@ -1205,6 +1179,33 @@ static int pci_6534_upload_firmware(struct comedi_device *dev, int options[])
1205 return 0; 1179 return 0;
1206} 1180}
1207 1181
1182static int nidio_find_device(struct comedi_device *dev, int bus, int slot)
1183{
1184 struct mite_struct *mite;
1185 int i;
1186
1187 for (mite = mite_devices; mite; mite = mite->next) {
1188 if (mite->used)
1189 continue;
1190 if (bus || slot) {
1191 if (bus != mite->pcidev->bus->number ||
1192 slot != PCI_SLOT(mite->pcidev->devfn))
1193 continue;
1194 }
1195 for (i = 0; i < n_nidio_boards; i++) {
1196 if (mite_device_id(mite) == nidio_boards[i].dev_id) {
1197 dev->board_ptr = nidio_boards + i;
1198 devpriv->mite = mite;
1199
1200 return 0;
1201 }
1202 }
1203 }
1204 printk(KERN_WARNING "no device found\n");
1205 mite_list_devices();
1206 return -EIO;
1207}
1208
1208static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1209static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1209{ 1210{
1210 struct comedi_subdevice *s; 1211 struct comedi_subdevice *s;
@@ -1306,7 +1307,7 @@ static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1306 return 0; 1307 return 0;
1307} 1308}
1308 1309
1309static int nidio_detach(struct comedi_device *dev) 1310static void nidio_detach(struct comedi_device *dev)
1310{ 1311{
1311 int i; 1312 int i;
1312 1313
@@ -1314,10 +1315,8 @@ static int nidio_detach(struct comedi_device *dev)
1314 for (i = 0; i < this_board->n_8255; i++) 1315 for (i = 0; i < this_board->n_8255; i++)
1315 subdev_8255_cleanup(dev, dev->subdevices + i); 1316 subdev_8255_cleanup(dev, dev->subdevices + i);
1316 } 1317 }
1317
1318 if (dev->irq) 1318 if (dev->irq)
1319 free_irq(dev->irq, dev); 1319 free_irq(dev->irq, dev);
1320
1321 if (devpriv) { 1320 if (devpriv) {
1322 if (devpriv->di_mite_ring) { 1321 if (devpriv->di_mite_ring) {
1323 mite_free_ring(devpriv->di_mite_ring); 1322 mite_free_ring(devpriv->di_mite_ring);
@@ -1326,73 +1325,48 @@ static int nidio_detach(struct comedi_device *dev)
1326 if (devpriv->mite) 1325 if (devpriv->mite)
1327 mite_unsetup(devpriv->mite); 1326 mite_unsetup(devpriv->mite);
1328 } 1327 }
1329 return 0;
1330} 1328}
1331 1329
1332static int nidio_find_device(struct comedi_device *dev, int bus, int slot) 1330static struct comedi_driver ni_pcidio_driver = {
1333{ 1331 .driver_name = "ni_pcidio",
1334 struct mite_struct *mite; 1332 .module = THIS_MODULE,
1335 int i; 1333 .attach = nidio_attach,
1336 1334 .detach = nidio_detach,
1337 for (mite = mite_devices; mite; mite = mite->next) { 1335};
1338 if (mite->used)
1339 continue;
1340 if (bus || slot) {
1341 if (bus != mite->pcidev->bus->number ||
1342 slot != PCI_SLOT(mite->pcidev->devfn))
1343 continue;
1344 }
1345 for (i = 0; i < n_nidio_boards; i++) {
1346 if (mite_device_id(mite) == nidio_boards[i].dev_id) {
1347 dev->board_ptr = nidio_boards + i;
1348 devpriv->mite = mite;
1349
1350 return 0;
1351 }
1352 }
1353 }
1354 printk(KERN_WARNING "no device found\n");
1355 mite_list_devices();
1356 return -EIO;
1357}
1358 1336
1359static int __devinit driver_pcidio_pci_probe(struct pci_dev *dev, 1337static int __devinit ni_pcidio_pci_probe(struct pci_dev *dev,
1360 const struct pci_device_id *ent) 1338 const struct pci_device_id *ent)
1361{ 1339{
1362 return comedi_pci_auto_config(dev, driver_pcidio.driver_name); 1340 return comedi_pci_auto_config(dev, &ni_pcidio_driver);
1363} 1341}
1364 1342
1365static void __devexit driver_pcidio_pci_remove(struct pci_dev *dev) 1343static void __devexit ni_pcidio_pci_remove(struct pci_dev *dev)
1366{ 1344{
1367 comedi_pci_auto_unconfig(dev); 1345 comedi_pci_auto_unconfig(dev);
1368} 1346}
1369 1347
1370static struct pci_driver driver_pcidio_pci_driver = { 1348static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = {
1371 .id_table = ni_pcidio_pci_table, 1349 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) },
1372 .probe = &driver_pcidio_pci_probe, 1350 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) },
1373 .remove = __devexit_p(&driver_pcidio_pci_remove) 1351 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x12b0) },
1352 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0160) },
1353 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1630) },
1354 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x13c0) },
1355 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0400) },
1356 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1250) },
1357 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x17d0) },
1358 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1800) },
1359 { 0 }
1374}; 1360};
1361MODULE_DEVICE_TABLE(pci, ni_pcidio_pci_table);
1375 1362
1376static int __init driver_pcidio_init_module(void) 1363static struct pci_driver ni_pcidio_pci_driver = {
1377{ 1364 .name = "ni_pcidio",
1378 int retval; 1365 .id_table = ni_pcidio_pci_table,
1379 1366 .probe = ni_pcidio_pci_probe,
1380 retval = comedi_driver_register(&driver_pcidio); 1367 .remove = __devexit_p(ni_pcidio_pci_remove),
1381 if (retval < 0) 1368};
1382 return retval; 1369module_comedi_pci_driver(ni_pcidio_driver, ni_pcidio_pci_driver);
1383
1384 driver_pcidio_pci_driver.name = (char *)driver_pcidio.driver_name;
1385 return pci_register_driver(&driver_pcidio_pci_driver);
1386}
1387
1388static void __exit driver_pcidio_cleanup_module(void)
1389{
1390 pci_unregister_driver(&driver_pcidio_pci_driver);
1391 comedi_driver_unregister(&driver_pcidio);
1392}
1393
1394module_init(driver_pcidio_init_module);
1395module_exit(driver_pcidio_cleanup_module);
1396 1370
1397MODULE_AUTHOR("Comedi http://www.comedi.org"); 1371MODULE_AUTHOR("Comedi http://www.comedi.org");
1398MODULE_DESCRIPTION("Comedi low-level driver"); 1372MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index 27baefa32b17..3974c0d98d2a 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -129,66 +129,6 @@ Bugs:
129 129
130#define DRV_NAME "ni_pcimio" 130#define DRV_NAME "ni_pcimio"
131 131
132/* The following two tables must be in the same order */
133static DEFINE_PCI_DEVICE_TABLE(ni_pci_table) = {
134 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162)},
135 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170)},
136 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1180)},
137 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1190)},
138 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11b0)},
139 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11c0)},
140 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11d0)},
141 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1270)},
142 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1330)},
143 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1340)},
144 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1350)},
145 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14e0)},
146 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14f0)},
147 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1580)},
148 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x15b0)},
149 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1880)},
150 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1870)},
151 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18b0)},
152 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18c0)},
153 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2410)},
154 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2420)},
155 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2430)},
156 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2890)},
157 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x28c0)},
158 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a60)},
159 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a70)},
160 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a80)},
161 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ab0)},
162 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b80)},
163 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b90)},
164 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c80)},
165 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ca0)},
166 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70aa)},
167 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ab)},
168 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ac)},
169 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70af)},
170 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b0)},
171 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b4)},
172 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b6)},
173 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b7)},
174 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b8)},
175 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bc)},
176 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bd)},
177 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bf)},
178 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c0)},
179 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70f2)},
180 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x710d)},
181 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716c)},
182 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716d)},
183 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717f)},
184 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71bc)},
185 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717d)},
186 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x72e8)},
187 {0}
188};
189
190MODULE_DEVICE_TABLE(pci, ni_pci_table);
191
192/* These are not all the possible ao ranges for 628x boards. 132/* These are not all the possible ao ranges for 628x boards.
193 They can do OFFSET +- REFERENCE where OFFSET can be 133 They can do OFFSET +- REFERENCE where OFFSET can be
194 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can 134 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can
@@ -1250,54 +1190,6 @@ static const struct ni_board_struct ni_boards[] = {
1250 1190
1251#define n_pcimio_boards ARRAY_SIZE(ni_boards) 1191#define n_pcimio_boards ARRAY_SIZE(ni_boards)
1252 1192
1253static int pcimio_attach(struct comedi_device *dev,
1254 struct comedi_devconfig *it);
1255static int pcimio_detach(struct comedi_device *dev);
1256static struct comedi_driver driver_pcimio = {
1257 .driver_name = DRV_NAME,
1258 .module = THIS_MODULE,
1259 .attach = pcimio_attach,
1260 .detach = pcimio_detach,
1261};
1262
1263static int __devinit driver_pcimio_pci_probe(struct pci_dev *dev,
1264 const struct pci_device_id *ent)
1265{
1266 return comedi_pci_auto_config(dev, driver_pcimio.driver_name);
1267}
1268
1269static void __devexit driver_pcimio_pci_remove(struct pci_dev *dev)
1270{
1271 comedi_pci_auto_unconfig(dev);
1272}
1273
1274static struct pci_driver driver_pcimio_pci_driver = {
1275 .id_table = ni_pci_table,
1276 .probe = &driver_pcimio_pci_probe,
1277 .remove = __devexit_p(&driver_pcimio_pci_remove)
1278};
1279
1280static int __init driver_pcimio_init_module(void)
1281{
1282 int retval;
1283
1284 retval = comedi_driver_register(&driver_pcimio);
1285 if (retval < 0)
1286 return retval;
1287
1288 driver_pcimio_pci_driver.name = (char *)driver_pcimio.driver_name;
1289 return pci_register_driver(&driver_pcimio_pci_driver);
1290}
1291
1292static void __exit driver_pcimio_cleanup_module(void)
1293{
1294 pci_unregister_driver(&driver_pcimio_pci_driver);
1295 comedi_driver_unregister(&driver_pcimio);
1296}
1297
1298module_init(driver_pcimio_init_module);
1299module_exit(driver_pcimio_cleanup_module);
1300
1301struct ni_private { 1193struct ni_private {
1302NI_PRIVATE_COMMON}; 1194NI_PRIVATE_COMMON};
1303#define devpriv ((struct ni_private *)dev->private) 1195#define devpriv ((struct ni_private *)dev->private)
@@ -1681,13 +1573,11 @@ static void init_6143(struct comedi_device *dev)
1681 ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143); 1573 ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143);
1682} 1574}
1683 1575
1684/* cleans up allocated resources */ 1576static void pcimio_detach(struct comedi_device *dev)
1685static int pcimio_detach(struct comedi_device *dev)
1686{ 1577{
1687 mio_common_detach(dev); 1578 mio_common_detach(dev);
1688 if (dev->irq) 1579 if (dev->irq)
1689 free_irq(dev->irq, dev); 1580 free_irq(dev->irq, dev);
1690
1691 if (dev->private) { 1581 if (dev->private) {
1692 mite_free_ring(devpriv->ai_mite_ring); 1582 mite_free_ring(devpriv->ai_mite_ring);
1693 mite_free_ring(devpriv->ao_mite_ring); 1583 mite_free_ring(devpriv->ao_mite_ring);
@@ -1697,8 +1587,6 @@ static int pcimio_detach(struct comedi_device *dev)
1697 if (devpriv->mite) 1587 if (devpriv->mite)
1698 mite_unsetup(devpriv->mite); 1588 mite_unsetup(devpriv->mite);
1699 } 1589 }
1700
1701 return 0;
1702} 1590}
1703 1591
1704static int pcimio_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1592static int pcimio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -1874,6 +1762,90 @@ static int pcimio_dio_change(struct comedi_device *dev,
1874 return 0; 1762 return 0;
1875} 1763}
1876 1764
1765static struct comedi_driver ni_pcimio_driver = {
1766 .driver_name = "ni_pcimio",
1767 .module = THIS_MODULE,
1768 .attach = pcimio_attach,
1769 .detach = pcimio_detach,
1770};
1771
1772static int __devinit ni_pcimio_pci_probe(struct pci_dev *dev,
1773 const struct pci_device_id *ent)
1774{
1775 return comedi_pci_auto_config(dev, &ni_pcimio_driver);
1776}
1777
1778static void __devexit ni_pcimio_pci_remove(struct pci_dev *dev)
1779{
1780 comedi_pci_auto_unconfig(dev);
1781}
1782
1783static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = {
1784 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) },
1785 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) },
1786 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1180) },
1787 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1190) },
1788 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11b0) },
1789 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11c0) },
1790 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11d0) },
1791 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1270) },
1792 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1330) },
1793 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1340) },
1794 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1350) },
1795 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14e0) },
1796 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14f0) },
1797 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1580) },
1798 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x15b0) },
1799 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1880) },
1800 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1870) },
1801 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18b0) },
1802 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18c0) },
1803 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2410) },
1804 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2420) },
1805 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2430) },
1806 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2890) },
1807 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x28c0) },
1808 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a60) },
1809 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a70) },
1810 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a80) },
1811 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ab0) },
1812 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b80) },
1813 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b90) },
1814 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c80) },
1815 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ca0) },
1816 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70aa) },
1817 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ab) },
1818 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ac) },
1819 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70af) },
1820 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b0) },
1821 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b4) },
1822 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b6) },
1823 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b7) },
1824 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b8) },
1825 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bc) },
1826 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bd) },
1827 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bf) },
1828 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c0) },
1829 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70f2) },
1830 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x710d) },
1831 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716c) },
1832 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716d) },
1833 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717f) },
1834 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71bc) },
1835 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717d) },
1836 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x72e8) },
1837 { 0 }
1838};
1839MODULE_DEVICE_TABLE(pci, ni_pcimio_pci_table);
1840
1841static struct pci_driver ni_pcimio_pci_driver = {
1842 .name = "ni_pcimio",
1843 .id_table = ni_pcimio_pci_table,
1844 .probe = ni_pcimio_pci_probe,
1845 .remove = __devexit_p(ni_pcimio_pci_remove)
1846};
1847module_comedi_pci_driver(ni_pcimio_driver, ni_pcimio_pci_driver)
1848
1877MODULE_AUTHOR("Comedi http://www.comedi.org"); 1849MODULE_AUTHOR("Comedi http://www.comedi.org");
1878MODULE_DESCRIPTION("Comedi low-level driver"); 1850MODULE_DESCRIPTION("Comedi low-level driver");
1879MODULE_LICENSE("GPL"); 1851MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/ni_tio_internal.h b/drivers/staging/comedi/drivers/ni_tio_internal.h
index c4ca53785832..5e00212aa022 100644
--- a/drivers/staging/comedi/drivers/ni_tio_internal.h
+++ b/drivers/staging/comedi/drivers/ni_tio_internal.h
@@ -362,8 +362,8 @@ static inline enum ni_gpct_register NITIO_Gi_ABZ_Reg(int counter_index)
362 return 0; 362 return 0;
363} 363}
364 364
365static inline enum ni_gpct_register NITIO_Gi_Interrupt_Acknowledge_Reg(int 365static inline enum ni_gpct_register NITIO_Gi_Interrupt_Acknowledge_Reg(
366 counter_index) 366 int counter_index)
367{ 367{
368 switch (counter_index) { 368 switch (counter_index) {
369 case 0: 369 case 0:
@@ -407,8 +407,8 @@ static inline enum ni_gpct_register NITIO_Gi_Status_Reg(int counter_index)
407 return 0; 407 return 0;
408} 408}
409 409
410static inline enum ni_gpct_register NITIO_Gi_Interrupt_Enable_Reg(int 410static inline enum ni_gpct_register NITIO_Gi_Interrupt_Enable_Reg(
411 counter_index) 411 int counter_index)
412{ 412{
413 switch (counter_index) { 413 switch (counter_index) {
414 case 0: 414 case 0:
@@ -472,15 +472,22 @@ enum Gi_Counting_Mode_Reg_Bits {
472 Gi_Index_Phase_LowA_HighB = 0x1 << Gi_Index_Phase_Bitshift, 472 Gi_Index_Phase_LowA_HighB = 0x1 << Gi_Index_Phase_Bitshift,
473 Gi_Index_Phase_HighA_LowB = 0x2 << Gi_Index_Phase_Bitshift, 473 Gi_Index_Phase_HighA_LowB = 0x2 << Gi_Index_Phase_Bitshift,
474 Gi_Index_Phase_HighA_HighB = 0x3 << Gi_Index_Phase_Bitshift, 474 Gi_Index_Phase_HighA_HighB = 0x3 << Gi_Index_Phase_Bitshift,
475 Gi_HW_Arm_Enable_Bit = 0x80, /* from m-series example code, not documented in 660x register level manual */ 475 /* from m-series example code, not documented in 660x register level
476 Gi_660x_HW_Arm_Select_Mask = 0x7 << Gi_HW_Arm_Select_Shift, /* from m-series example code, not documented in 660x register level manual */ 476 * manual */
477 Gi_HW_Arm_Enable_Bit = 0x80,
478 /* from m-series example code, not documented in 660x register level
479 * manual */
480 Gi_660x_HW_Arm_Select_Mask = 0x7 << Gi_HW_Arm_Select_Shift,
477 Gi_660x_Prescale_X8_Bit = 0x1000, 481 Gi_660x_Prescale_X8_Bit = 0x1000,
478 Gi_M_Series_Prescale_X8_Bit = 0x2000, 482 Gi_M_Series_Prescale_X8_Bit = 0x2000,
479 Gi_M_Series_HW_Arm_Select_Mask = 0x1f << Gi_HW_Arm_Select_Shift, 483 Gi_M_Series_HW_Arm_Select_Mask = 0x1f << Gi_HW_Arm_Select_Shift,
480 /* must be set for clocks over 40MHz, which includes synchronous counting and quadrature modes */ 484 /* must be set for clocks over 40MHz, which includes synchronous
485 * counting and quadrature modes */
481 Gi_660x_Alternate_Sync_Bit = 0x2000, 486 Gi_660x_Alternate_Sync_Bit = 0x2000,
482 Gi_M_Series_Alternate_Sync_Bit = 0x4000, 487 Gi_M_Series_Alternate_Sync_Bit = 0x4000,
483 Gi_660x_Prescale_X2_Bit = 0x4000, /* from m-series example code, not documented in 660x register level manual */ 488 /* from m-series example code, not documented in 660x register level
489 * manual */
490 Gi_660x_Prescale_X2_Bit = 0x4000,
484 Gi_M_Series_Prescale_X2_Bit = 0x8000, 491 Gi_M_Series_Prescale_X2_Bit = 0x8000,
485}; 492};
486 493
@@ -503,7 +510,8 @@ enum Gi_Mode_Bits {
503 Gi_Level_Gating_Bits = 0x1, 510 Gi_Level_Gating_Bits = 0x1,
504 Gi_Rising_Edge_Gating_Bits = 0x2, 511 Gi_Rising_Edge_Gating_Bits = 0x2,
505 Gi_Falling_Edge_Gating_Bits = 0x3, 512 Gi_Falling_Edge_Gating_Bits = 0x3,
506 Gi_Gate_On_Both_Edges_Bit = 0x4, /* used in conjunction with rising edge gating mode */ 513 Gi_Gate_On_Both_Edges_Bit = 0x4, /* used in conjunction with
514 * rising edge gating mode */
507 Gi_Trigger_Mode_for_Edge_Gate_Mask = 0x18, 515 Gi_Trigger_Mode_for_Edge_Gate_Mask = 0x18,
508 Gi_Edge_Gate_Starts_Stops_Bits = 0x0, 516 Gi_Edge_Gate_Starts_Stops_Bits = 0x0,
509 Gi_Edge_Gate_Stops_Starts_Bits = 0x8, 517 Gi_Edge_Gate_Stops_Starts_Bits = 0x8,
@@ -686,11 +694,10 @@ static inline unsigned Gi_Gate_Interrupt_Enable_Bit(unsigned counter_index)
686{ 694{
687 unsigned bit; 695 unsigned bit;
688 696
689 if (counter_index % 2) { 697 if (counter_index % 2)
690 bit = G1_Gate_Interrupt_Enable_Bit; 698 bit = G1_Gate_Interrupt_Enable_Bit;
691 } else { 699 else
692 bit = G0_Gate_Interrupt_Enable_Bit; 700 bit = G0_Gate_Interrupt_Enable_Bit;
693 }
694 return bit; 701 return bit;
695} 702}
696 703
@@ -748,8 +755,9 @@ static inline void ni_tio_set_bits_transient(struct ni_gpct *counter,
748} 755}
749 756
750/* ni_tio_set_bits( ) is for safely writing to registers whose bits may be 757/* ni_tio_set_bits( ) is for safely writing to registers whose bits may be
751twiddled in interrupt context, or whose software copy may be read in interrupt context. 758 * twiddled in interrupt context, or whose software copy may be read in
752*/ 759 * interrupt context.
760 */
753static inline void ni_tio_set_bits(struct ni_gpct *counter, 761static inline void ni_tio_set_bits(struct ni_gpct *counter,
754 enum ni_gpct_register register_index, 762 enum ni_gpct_register register_index,
755 unsigned bit_mask, unsigned bit_values) 763 unsigned bit_mask, unsigned bit_values)
diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c
index b44386a6b636..2e7753f988aa 100644
--- a/drivers/staging/comedi/drivers/pcl711.c
+++ b/drivers/staging/comedi/drivers/pcl711.c
@@ -148,42 +148,8 @@ struct pcl711_board {
148 const struct comedi_lrange *ai_range_type; 148 const struct comedi_lrange *ai_range_type;
149}; 149};
150 150
151static const struct pcl711_board boardtypes[] = {
152 {"pcl711", 0, 0, 0, 5, 8, 1, 0, &range_bipolar5},
153 {"pcl711b", 1, 0, 0, 5, 8, 1, 7, &range_pcl711b_ai},
154 {"acl8112hg", 0, 1, 0, 12, 16, 2, 15, &range_acl8112hg_ai},
155 {"acl8112dg", 0, 1, 1, 9, 16, 2, 15, &range_acl8112dg_ai},
156};
157
158#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl711_board))
159#define this_board ((const struct pcl711_board *)dev->board_ptr) 151#define this_board ((const struct pcl711_board *)dev->board_ptr)
160 152
161static int pcl711_attach(struct comedi_device *dev,
162 struct comedi_devconfig *it);
163static int pcl711_detach(struct comedi_device *dev);
164static struct comedi_driver driver_pcl711 = {
165 .driver_name = "pcl711",
166 .module = THIS_MODULE,
167 .attach = pcl711_attach,
168 .detach = pcl711_detach,
169 .board_name = &boardtypes[0].name,
170 .num_names = n_boardtypes,
171 .offset = sizeof(struct pcl711_board),
172};
173
174static int __init driver_pcl711_init_module(void)
175{
176 return comedi_driver_register(&driver_pcl711);
177}
178
179static void __exit driver_pcl711_cleanup_module(void)
180{
181 comedi_driver_unregister(&driver_pcl711);
182}
183
184module_init(driver_pcl711_init_module);
185module_exit(driver_pcl711_cleanup_module);
186
187struct pcl711_private { 153struct pcl711_private {
188 154
189 int board; 155 int board;
@@ -513,21 +479,6 @@ static int pcl711_do_insn_bits(struct comedi_device *dev,
513 return 2; 479 return 2;
514} 480}
515 481
516/* Free any resources that we have claimed */
517static int pcl711_detach(struct comedi_device *dev)
518{
519 printk(KERN_INFO "comedi%d: pcl711: remove\n", dev->minor);
520
521 if (dev->irq)
522 free_irq(dev->irq, dev);
523
524 if (dev->iobase)
525 release_region(dev->iobase, PCL711_SIZE);
526
527 return 0;
528}
529
530/* Initialization */
531static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it) 482static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it)
532{ 483{
533 int ret; 484 int ret;
@@ -640,6 +591,32 @@ static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it)
640 return 0; 591 return 0;
641} 592}
642 593
594static void pcl711_detach(struct comedi_device *dev)
595{
596 if (dev->irq)
597 free_irq(dev->irq, dev);
598 if (dev->iobase)
599 release_region(dev->iobase, PCL711_SIZE);
600}
601
602static const struct pcl711_board boardtypes[] = {
603 { "pcl711", 0, 0, 0, 5, 8, 1, 0, &range_bipolar5 },
604 { "pcl711b", 1, 0, 0, 5, 8, 1, 7, &range_pcl711b_ai },
605 { "acl8112hg", 0, 1, 0, 12, 16, 2, 15, &range_acl8112hg_ai },
606 { "acl8112dg", 0, 1, 1, 9, 16, 2, 15, &range_acl8112dg_ai },
607};
608
609static struct comedi_driver pcl711_driver = {
610 .driver_name = "pcl711",
611 .module = THIS_MODULE,
612 .attach = pcl711_attach,
613 .detach = pcl711_detach,
614 .board_name = &boardtypes[0].name,
615 .num_names = ARRAY_SIZE(boardtypes),
616 .offset = sizeof(struct pcl711_board),
617};
618module_comedi_driver(pcl711_driver);
619
643MODULE_AUTHOR("Comedi http://www.comedi.org"); 620MODULE_AUTHOR("Comedi http://www.comedi.org");
644MODULE_DESCRIPTION("Comedi low-level driver"); 621MODULE_DESCRIPTION("Comedi low-level driver");
645MODULE_LICENSE("GPL"); 622MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl724.c b/drivers/staging/comedi/drivers/pcl724.c
index 61b075db66ef..1f66fe1c7d5e 100644
--- a/drivers/staging/comedi/drivers/pcl724.c
+++ b/drivers/staging/comedi/drivers/pcl724.c
@@ -56,10 +56,6 @@ See the source for configuration details.
56 56
57/* #define PCL724_IRQ 1 no IRQ support now */ 57/* #define PCL724_IRQ 1 no IRQ support now */
58 58
59static int pcl724_attach(struct comedi_device *dev,
60 struct comedi_devconfig *it);
61static int pcl724_detach(struct comedi_device *dev);
62
63struct pcl724_board { 59struct pcl724_board {
64 60
65 const char *name; /* board name */ 61 const char *name; /* board name */
@@ -71,41 +67,8 @@ struct pcl724_board {
71 char is_pet48; 67 char is_pet48;
72}; 68};
73 69
74static const struct pcl724_board boardtypes[] = {
75 {"pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0,},
76 {"pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0,},
77 {"pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0,},
78 {"acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0,},
79 {"acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0,},
80 {"pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1,},
81};
82
83#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl724_board))
84#define this_board ((const struct pcl724_board *)dev->board_ptr) 70#define this_board ((const struct pcl724_board *)dev->board_ptr)
85 71
86static struct comedi_driver driver_pcl724 = {
87 .driver_name = "pcl724",
88 .module = THIS_MODULE,
89 .attach = pcl724_attach,
90 .detach = pcl724_detach,
91 .board_name = &boardtypes[0].name,
92 .num_names = n_boardtypes,
93 .offset = sizeof(struct pcl724_board),
94};
95
96static int __init driver_pcl724_init_module(void)
97{
98 return comedi_driver_register(&driver_pcl724);
99}
100
101static void __exit driver_pcl724_cleanup_module(void)
102{
103 comedi_driver_unregister(&driver_pcl724);
104}
105
106module_init(driver_pcl724_init_module);
107module_exit(driver_pcl724_cleanup_module);
108
109static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) 72static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
110{ 73{
111 unsigned long iobase = arg; 74 unsigned long iobase = arg;
@@ -214,25 +177,39 @@ static int pcl724_attach(struct comedi_device *dev, struct comedi_devconfig *it)
214 return 0; 177 return 0;
215} 178}
216 179
217static int pcl724_detach(struct comedi_device *dev) 180static void pcl724_detach(struct comedi_device *dev)
218{ 181{
219 int i; 182 int i;
220 183
221 /* printk("comedi%d: pcl724: remove\n",dev->minor); */
222
223 for (i = 0; i < dev->n_subdevices; i++) 184 for (i = 0; i < dev->n_subdevices; i++)
224 subdev_8255_cleanup(dev, dev->subdevices + i); 185 subdev_8255_cleanup(dev, dev->subdevices + i);
225
226#ifdef PCL724_IRQ 186#ifdef PCL724_IRQ
227 if (dev->irq) 187 if (dev->irq)
228 free_irq(dev->irq, dev); 188 free_irq(dev->irq, dev);
229#endif 189#endif
230
231 release_region(dev->iobase, this_board->io_range); 190 release_region(dev->iobase, this_board->io_range);
232
233 return 0;
234} 191}
235 192
193static const struct pcl724_board boardtypes[] = {
194 { "pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
195 { "pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0, },
196 { "pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0, },
197 { "acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0, },
198 { "acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
199 { "pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1, },
200};
201
202static struct comedi_driver pcl724_driver = {
203 .driver_name = "pcl724",
204 .module = THIS_MODULE,
205 .attach = pcl724_attach,
206 .detach = pcl724_detach,
207 .board_name = &boardtypes[0].name,
208 .num_names = ARRAY_SIZE(boardtypes),
209 .offset = sizeof(struct pcl724_board),
210};
211module_comedi_driver(pcl724_driver);
212
236MODULE_AUTHOR("Comedi http://www.comedi.org"); 213MODULE_AUTHOR("Comedi http://www.comedi.org");
237MODULE_DESCRIPTION("Comedi low-level driver"); 214MODULE_DESCRIPTION("Comedi low-level driver");
238MODULE_LICENSE("GPL"); 215MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl725.c b/drivers/staging/comedi/drivers/pcl725.c
index 24b223ca4399..83a6fa53dddd 100644
--- a/drivers/staging/comedi/drivers/pcl725.c
+++ b/drivers/staging/comedi/drivers/pcl725.c
@@ -20,29 +20,6 @@ Devices: [Advantech] PCL-725 (pcl725)
20#define PCL725_DO 0 20#define PCL725_DO 0
21#define PCL725_DI 1 21#define PCL725_DI 1
22 22
23static int pcl725_attach(struct comedi_device *dev,
24 struct comedi_devconfig *it);
25static int pcl725_detach(struct comedi_device *dev);
26static struct comedi_driver driver_pcl725 = {
27 .driver_name = "pcl725",
28 .module = THIS_MODULE,
29 .attach = pcl725_attach,
30 .detach = pcl725_detach,
31};
32
33static int __init driver_pcl725_init_module(void)
34{
35 return comedi_driver_register(&driver_pcl725);
36}
37
38static void __exit driver_pcl725_cleanup_module(void)
39{
40 comedi_driver_unregister(&driver_pcl725);
41}
42
43module_init(driver_pcl725_init_module);
44module_exit(driver_pcl725_cleanup_module);
45
46static int pcl725_do_insn(struct comedi_device *dev, struct comedi_subdevice *s, 23static int pcl725_do_insn(struct comedi_device *dev, struct comedi_subdevice *s,
47 struct comedi_insn *insn, unsigned int *data) 24 struct comedi_insn *insn, unsigned int *data)
48{ 25{
@@ -112,16 +89,20 @@ static int pcl725_attach(struct comedi_device *dev, struct comedi_devconfig *it)
112 return 0; 89 return 0;
113} 90}
114 91
115static int pcl725_detach(struct comedi_device *dev) 92static void pcl725_detach(struct comedi_device *dev)
116{ 93{
117 printk(KERN_INFO "comedi%d: pcl725: remove\n", dev->minor);
118
119 if (dev->iobase) 94 if (dev->iobase)
120 release_region(dev->iobase, PCL725_SIZE); 95 release_region(dev->iobase, PCL725_SIZE);
121
122 return 0;
123} 96}
124 97
98static struct comedi_driver pcl725_driver = {
99 .driver_name = "pcl725",
100 .module = THIS_MODULE,
101 .attach = pcl725_attach,
102 .detach = pcl725_detach,
103};
104module_comedi_driver(pcl725_driver);
105
125MODULE_AUTHOR("Comedi http://www.comedi.org"); 106MODULE_AUTHOR("Comedi http://www.comedi.org");
126MODULE_DESCRIPTION("Comedi low-level driver"); 107MODULE_DESCRIPTION("Comedi low-level driver");
127MODULE_LICENSE("GPL"); 108MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl726.c b/drivers/staging/comedi/drivers/pcl726.c
index 897cd808eeb7..d25c30c694e3 100644
--- a/drivers/staging/comedi/drivers/pcl726.c
+++ b/drivers/staging/comedi/drivers/pcl726.c
@@ -111,10 +111,6 @@ static const struct comedi_lrange *const rangelist_728[] = {
111 &range_4_20mA, &range_0_20mA 111 &range_4_20mA, &range_0_20mA
112}; 112};
113 113
114static int pcl726_attach(struct comedi_device *dev,
115 struct comedi_devconfig *it);
116static int pcl726_detach(struct comedi_device *dev);
117
118struct pcl726_board { 114struct pcl726_board {
119 115
120 const char *name; /* driver name */ 116 const char *name; /* driver name */
@@ -149,32 +145,8 @@ static const struct pcl726_board boardtypes[] = {
149 &rangelist_728[0],}, 145 &rangelist_728[0],},
150}; 146};
151 147
152#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl726_board))
153#define this_board ((const struct pcl726_board *)dev->board_ptr) 148#define this_board ((const struct pcl726_board *)dev->board_ptr)
154 149
155static struct comedi_driver driver_pcl726 = {
156 .driver_name = "pcl726",
157 .module = THIS_MODULE,
158 .attach = pcl726_attach,
159 .detach = pcl726_detach,
160 .board_name = &boardtypes[0].name,
161 .num_names = n_boardtypes,
162 .offset = sizeof(struct pcl726_board),
163};
164
165static int __init driver_pcl726_init_module(void)
166{
167 return comedi_driver_register(&driver_pcl726);
168}
169
170static void __exit driver_pcl726_cleanup_module(void)
171{
172 comedi_driver_unregister(&driver_pcl726);
173}
174
175module_init(driver_pcl726_init_module);
176module_exit(driver_pcl726_cleanup_module);
177
178struct pcl726_private { 150struct pcl726_private {
179 151
180 int bipolar[12]; 152 int bipolar[12];
@@ -378,21 +350,27 @@ static int pcl726_attach(struct comedi_device *dev, struct comedi_devconfig *it)
378 return 0; 350 return 0;
379} 351}
380 352
381static int pcl726_detach(struct comedi_device *dev) 353static void pcl726_detach(struct comedi_device *dev)
382{ 354{
383/* printk("comedi%d: pcl726: remove\n",dev->minor); */
384
385#ifdef ACL6126_IRQ 355#ifdef ACL6126_IRQ
386 if (dev->irq) 356 if (dev->irq)
387 free_irq(dev->irq, dev); 357 free_irq(dev->irq, dev);
388#endif 358#endif
389
390 if (dev->iobase) 359 if (dev->iobase)
391 release_region(dev->iobase, this_board->io_range); 360 release_region(dev->iobase, this_board->io_range);
392
393 return 0;
394} 361}
395 362
363static struct comedi_driver pcl726_driver = {
364 .driver_name = "pcl726",
365 .module = THIS_MODULE,
366 .attach = pcl726_attach,
367 .detach = pcl726_detach,
368 .board_name = &boardtypes[0].name,
369 .num_names = ARRAY_SIZE(boardtypes),
370 .offset = sizeof(struct pcl726_board),
371};
372module_comedi_driver(pcl726_driver);
373
396MODULE_AUTHOR("Comedi http://www.comedi.org"); 374MODULE_AUTHOR("Comedi http://www.comedi.org");
397MODULE_DESCRIPTION("Comedi low-level driver"); 375MODULE_DESCRIPTION("Comedi low-level driver");
398MODULE_LICENSE("GPL"); 376MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl730.c b/drivers/staging/comedi/drivers/pcl730.c
index c9682d614e0e..e11704addedb 100644
--- a/drivers/staging/comedi/drivers/pcl730.c
+++ b/drivers/staging/comedi/drivers/pcl730.c
@@ -26,48 +26,14 @@ The ACL-7130 card have an 8254 timer/counter not supported by this driver.
26#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */ 26#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */
27#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */ 27#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */
28 28
29static int pcl730_attach(struct comedi_device *dev,
30 struct comedi_devconfig *it);
31static int pcl730_detach(struct comedi_device *dev);
32
33struct pcl730_board { 29struct pcl730_board {
34 30
35 const char *name; /* board name */ 31 const char *name; /* board name */
36 unsigned int io_range; /* len of I/O space */ 32 unsigned int io_range; /* len of I/O space */
37}; 33};
38 34
39static const struct pcl730_board boardtypes[] = {
40 {"pcl730", PCL730_SIZE,},
41 {"iso730", PCL730_SIZE,},
42 {"acl7130", ACL7130_SIZE,},
43};
44
45#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl730_board))
46#define this_board ((const struct pcl730_board *)dev->board_ptr) 35#define this_board ((const struct pcl730_board *)dev->board_ptr)
47 36
48static struct comedi_driver driver_pcl730 = {
49 .driver_name = "pcl730",
50 .module = THIS_MODULE,
51 .attach = pcl730_attach,
52 .detach = pcl730_detach,
53 .board_name = &boardtypes[0].name,
54 .num_names = n_boardtypes,
55 .offset = sizeof(struct pcl730_board),
56};
57
58static int __init driver_pcl730_init_module(void)
59{
60 return comedi_driver_register(&driver_pcl730);
61}
62
63static void __exit driver_pcl730_cleanup_module(void)
64{
65 comedi_driver_unregister(&driver_pcl730);
66}
67
68module_init(driver_pcl730_init_module);
69module_exit(driver_pcl730_cleanup_module);
70
71static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s, 37static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s,
72 struct comedi_insn *insn, unsigned int *data) 38 struct comedi_insn *insn, unsigned int *data)
73{ 39{
@@ -168,16 +134,29 @@ static int pcl730_attach(struct comedi_device *dev, struct comedi_devconfig *it)
168 return 0; 134 return 0;
169} 135}
170 136
171static int pcl730_detach(struct comedi_device *dev) 137static void pcl730_detach(struct comedi_device *dev)
172{ 138{
173 printk(KERN_INFO "comedi%d: pcl730: remove\n", dev->minor);
174
175 if (dev->iobase) 139 if (dev->iobase)
176 release_region(dev->iobase, this_board->io_range); 140 release_region(dev->iobase, this_board->io_range);
177
178 return 0;
179} 141}
180 142
143static const struct pcl730_board boardtypes[] = {
144 { "pcl730", PCL730_SIZE, },
145 { "iso730", PCL730_SIZE, },
146 { "acl7130", ACL7130_SIZE, },
147};
148
149static struct comedi_driver pcl730_driver = {
150 .driver_name = "pcl730",
151 .module = THIS_MODULE,
152 .attach = pcl730_attach,
153 .detach = pcl730_detach,
154 .board_name = &boardtypes[0].name,
155 .num_names = ARRAY_SIZE(boardtypes),
156 .offset = sizeof(struct pcl730_board),
157};
158module_comedi_driver(pcl730_driver);
159
181MODULE_AUTHOR("Comedi http://www.comedi.org"); 160MODULE_AUTHOR("Comedi http://www.comedi.org");
182MODULE_DESCRIPTION("Comedi low-level driver"); 161MODULE_DESCRIPTION("Comedi low-level driver");
183MODULE_LICENSE("GPL"); 162MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c
index 6fc74645af2c..51f4ca9f7927 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -316,10 +316,6 @@ static const struct comedi_lrange range_a821pgh_ai = { 4, {
316 } 316 }
317}; 317};
318 318
319static int pcl812_attach(struct comedi_device *dev,
320 struct comedi_devconfig *it);
321static int pcl812_detach(struct comedi_device *dev);
322
323struct pcl812_board { 319struct pcl812_board {
324 320
325 const char *name; /* board name */ 321 const char *name; /* board name */
@@ -340,89 +336,8 @@ struct pcl812_board {
340 unsigned char haveMPC508; /* 1=board use MPC508A multiplexor */ 336 unsigned char haveMPC508; /* 1=board use MPC508A multiplexor */
341}; 337};
342 338
343static const struct pcl812_board boardtypes[] = {
344 {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
345 33000, 500, &range_bipolar10, &range_unipolar5,
346 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
347 {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
348 33000, 500, &range_pcl812pg_ai, &range_unipolar5,
349 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
350 {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
351 10000, 500, &range_pcl812pg_ai, &range_unipolar5,
352 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
353 {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
354 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
355 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
356 {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
357 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
358 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
359 {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
360 10000, 500, &range_pcl813b_ai, &range_unipolar5,
361 0x000c, 0x00, PCLx1x_IORANGE, 0},
362 {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
363 10000, 500, &range_pcl813b_ai, NULL,
364 0x000c, 0x00, PCLx1x_IORANGE, 0},
365 {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
366 10000, 500, &range_a821pgh_ai, &range_unipolar5,
367 0x000c, 0x00, PCLx1x_IORANGE, 0},
368 {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
369 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
370 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
371 {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
372 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
373 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
374 {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
375 8000, 500, &range_acl8112dg_ai, &range_unipolar5,
376 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
377 {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
378 8000, 500, &range_acl8112hg_ai, &range_unipolar5,
379 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
380 {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
381 0, 0, &range_pcl813b_ai, NULL,
382 0x0000, 0x00, PCLx1x_IORANGE, 0},
383 {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff,
384 0, 0, &range_pcl813b_ai, NULL,
385 0x0000, 0x00, PCLx1x_IORANGE, 0},
386 {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff,
387 0, 0, &range_acl8113_1_ai, NULL,
388 0x0000, 0x00, PCLx1x_IORANGE, 0},
389 {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff,
390 0, 0, &range_iso813_1_ai, NULL,
391 0x0000, 0x00, PCLx1x_IORANGE, 0},
392 {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
393 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
394 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
395 {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
396 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
397 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
398};
399
400#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl812_board))
401#define this_board ((const struct pcl812_board *)dev->board_ptr) 339#define this_board ((const struct pcl812_board *)dev->board_ptr)
402 340
403static struct comedi_driver driver_pcl812 = {
404 .driver_name = "pcl812",
405 .module = THIS_MODULE,
406 .attach = pcl812_attach,
407 .detach = pcl812_detach,
408 .board_name = &boardtypes[0].name,
409 .num_names = n_boardtypes,
410 .offset = sizeof(struct pcl812_board),
411};
412
413static int __init driver_pcl812_init_module(void)
414{
415 return comedi_driver_register(&driver_pcl812);
416}
417
418static void __exit driver_pcl812_cleanup_module(void)
419{
420 comedi_driver_unregister(&driver_pcl812);
421}
422
423module_init(driver_pcl812_init_module);
424module_exit(driver_pcl812_cleanup_module);
425
426struct pcl812_private { 341struct pcl812_private {
427 342
428 unsigned char valid; /* =1 device is OK */ 343 unsigned char valid; /* =1 device is OK */
@@ -1356,9 +1271,6 @@ static void pcl812_reset(struct comedi_device *dev)
1356#endif 1271#endif
1357} 1272}
1358 1273
1359/*
1360==============================================================================
1361*/
1362static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1274static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1363{ 1275{
1364 int ret, subdev; 1276 int ret, subdev;
@@ -1702,19 +1614,79 @@ no_dma:
1702 return 0; 1614 return 0;
1703} 1615}
1704 1616
1705/* 1617static void pcl812_detach(struct comedi_device *dev)
1706==============================================================================
1707 */
1708static int pcl812_detach(struct comedi_device *dev)
1709{ 1618{
1710
1711#ifdef PCL812_EXTDEBUG
1712 printk(KERN_DEBUG "comedi%d: pcl812: remove\n", dev->minor);
1713#endif
1714 free_resources(dev); 1619 free_resources(dev);
1715 return 0;
1716} 1620}
1717 1621
1622static const struct pcl812_board boardtypes[] = {
1623 {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
1624 33000, 500, &range_bipolar10, &range_unipolar5,
1625 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1626 {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
1627 33000, 500, &range_pcl812pg_ai, &range_unipolar5,
1628 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1629 {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
1630 10000, 500, &range_pcl812pg_ai, &range_unipolar5,
1631 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1632 {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1633 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
1634 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
1635 {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1636 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
1637 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
1638 {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
1639 10000, 500, &range_pcl813b_ai, &range_unipolar5,
1640 0x000c, 0x00, PCLx1x_IORANGE, 0},
1641 {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
1642 10000, 500, &range_pcl813b_ai, NULL,
1643 0x000c, 0x00, PCLx1x_IORANGE, 0},
1644 {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
1645 10000, 500, &range_a821pgh_ai, &range_unipolar5,
1646 0x000c, 0x00, PCLx1x_IORANGE, 0},
1647 {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1648 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
1649 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1650 {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1651 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
1652 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1653 {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1654 8000, 500, &range_acl8112dg_ai, &range_unipolar5,
1655 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1656 {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
1657 8000, 500, &range_acl8112hg_ai, &range_unipolar5,
1658 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1659 {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
1660 0, 0, &range_pcl813b_ai, NULL,
1661 0x0000, 0x00, PCLx1x_IORANGE, 0},
1662 {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff,
1663 0, 0, &range_pcl813b_ai, NULL,
1664 0x0000, 0x00, PCLx1x_IORANGE, 0},
1665 {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff,
1666 0, 0, &range_acl8113_1_ai, NULL,
1667 0x0000, 0x00, PCLx1x_IORANGE, 0},
1668 {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff,
1669 0, 0, &range_iso813_1_ai, NULL,
1670 0x0000, 0x00, PCLx1x_IORANGE, 0},
1671 {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
1672 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
1673 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
1674 {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
1675 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
1676 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
1677};
1678
1679static struct comedi_driver pcl812_driver = {
1680 .driver_name = "pcl812",
1681 .module = THIS_MODULE,
1682 .attach = pcl812_attach,
1683 .detach = pcl812_detach,
1684 .board_name = &boardtypes[0].name,
1685 .num_names = ARRAY_SIZE(boardtypes),
1686 .offset = sizeof(struct pcl812_board),
1687};
1688module_comedi_driver(pcl812_driver);
1689
1718MODULE_AUTHOR("Comedi http://www.comedi.org"); 1690MODULE_AUTHOR("Comedi http://www.comedi.org");
1719MODULE_DESCRIPTION("Comedi low-level driver"); 1691MODULE_DESCRIPTION("Comedi low-level driver");
1720MODULE_LICENSE("GPL"); 1692MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl816.c b/drivers/staging/comedi/drivers/pcl816.c
index 96cd7ec2ad53..cc67b6d46059 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -125,63 +125,14 @@ struct pcl816_board {
125 int i8254_osc_base; /* 1/frequency of on board oscilator in ns */ 125 int i8254_osc_base; /* 1/frequency of on board oscilator in ns */
126}; 126};
127 127
128static const struct pcl816_board boardtypes[] = {
129 {"pcl816", 8, 16, 10000, 1, 16, 16, &range_pcl816,
130 &range_pcl816, PCLx1x_RANGE,
131 0x00fc, /* IRQ mask */
132 0x0a, /* DMA mask */
133 0xffff, /* 16-bit card */
134 0xffff, /* D/A maxdata */
135 1024,
136 1, /* ao chan list */
137 100},
138 {"pcl814b", 8, 16, 10000, 1, 16, 16, &range_pcl816,
139 &range_pcl816, PCLx1x_RANGE,
140 0x00fc,
141 0x0a,
142 0x3fff, /* 14 bit card */
143 0x3fff,
144 1024,
145 1,
146 100},
147};
148
149#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl816_board))
150#define devpriv ((struct pcl816_private *)dev->private) 128#define devpriv ((struct pcl816_private *)dev->private)
151#define this_board ((const struct pcl816_board *)dev->board_ptr) 129#define this_board ((const struct pcl816_board *)dev->board_ptr)
152 130
153static int pcl816_attach(struct comedi_device *dev,
154 struct comedi_devconfig *it);
155static int pcl816_detach(struct comedi_device *dev);
156
157#ifdef unused 131#ifdef unused
158static int RTC_lock; /* RTC lock */ 132static int RTC_lock; /* RTC lock */
159static int RTC_timer_lock; /* RTC int lock */ 133static int RTC_timer_lock; /* RTC int lock */
160#endif 134#endif
161 135
162static struct comedi_driver driver_pcl816 = {
163 .driver_name = "pcl816",
164 .module = THIS_MODULE,
165 .attach = pcl816_attach,
166 .detach = pcl816_detach,
167 .board_name = &boardtypes[0].name,
168 .num_names = n_boardtypes,
169 .offset = sizeof(struct pcl816_board),
170};
171
172static int __init driver_pcl816_init_module(void)
173{
174 return comedi_driver_register(&driver_pcl816);
175}
176
177static void __exit driver_pcl816_cleanup_module(void)
178{
179 comedi_driver_unregister(&driver_pcl816);
180}
181
182module_init(driver_pcl816_init_module);
183module_exit(driver_pcl816_cleanup_module);
184
185struct pcl816_private { 136struct pcl816_private {
186 137
187 unsigned int dma; /* used DMA, 0=don't use DMA */ 138 unsigned int dma; /* used DMA, 0=don't use DMA */
@@ -1075,46 +1026,6 @@ static int set_rtc_irq_bit(unsigned char bit)
1075} 1026}
1076#endif 1027#endif
1077 1028
1078/*
1079==============================================================================
1080 Free any resources that we have claimed
1081*/
1082static void free_resources(struct comedi_device *dev)
1083{
1084 /* printk("free_resource()\n"); */
1085 if (dev->private) {
1086 pcl816_ai_cancel(dev, devpriv->sub_ai);
1087 pcl816_reset(dev);
1088 if (devpriv->dma)
1089 free_dma(devpriv->dma);
1090 if (devpriv->dmabuf[0])
1091 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1092 if (devpriv->dmabuf[1])
1093 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1094#ifdef unused
1095 if (devpriv->rtc_irq)
1096 free_irq(devpriv->rtc_irq, dev);
1097 if ((devpriv->dma_rtc) && (RTC_lock == 1)) {
1098 if (devpriv->rtc_iobase)
1099 release_region(devpriv->rtc_iobase,
1100 devpriv->rtc_iosize);
1101 }
1102#endif
1103 }
1104
1105 if (dev->irq)
1106 free_irq(dev->irq, dev);
1107 if (dev->iobase)
1108 release_region(dev->iobase, this_board->io_range);
1109 /* printk("free_resource() end\n"); */
1110}
1111
1112/*
1113==============================================================================
1114
1115 Initialization
1116
1117*/
1118static int pcl816_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1029static int pcl816_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1119{ 1030{
1120 int ret; 1031 int ret;
@@ -1340,21 +1251,69 @@ case COMEDI_SUBD_DO:
1340 return 0; 1251 return 0;
1341} 1252}
1342 1253
1343/* 1254static void pcl816_detach(struct comedi_device *dev)
1344==============================================================================
1345 Removes device
1346 */
1347static int pcl816_detach(struct comedi_device *dev)
1348{ 1255{
1349 DEBUG(printk(KERN_INFO "comedi%d: pcl816: remove\n", dev->minor);) 1256 if (dev->private) {
1350 free_resources(dev); 1257 pcl816_ai_cancel(dev, devpriv->sub_ai);
1258 pcl816_reset(dev);
1259 if (devpriv->dma)
1260 free_dma(devpriv->dma);
1261 if (devpriv->dmabuf[0])
1262 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1263 if (devpriv->dmabuf[1])
1264 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1265#ifdef unused
1266 if (devpriv->rtc_irq)
1267 free_irq(devpriv->rtc_irq, dev);
1268 if ((devpriv->dma_rtc) && (RTC_lock == 1)) {
1269 if (devpriv->rtc_iobase)
1270 release_region(devpriv->rtc_iobase,
1271 devpriv->rtc_iosize);
1272 }
1273#endif
1274 }
1275 if (dev->irq)
1276 free_irq(dev->irq, dev);
1277 if (dev->iobase)
1278 release_region(dev->iobase, this_board->io_range);
1351#ifdef unused 1279#ifdef unused
1352 if (devpriv->dma_rtc) 1280 if (devpriv->dma_rtc)
1353 RTC_lock--; 1281 RTC_lock--;
1354#endif 1282#endif
1355 return 0;
1356} 1283}
1357 1284
1285static const struct pcl816_board boardtypes[] = {
1286 {"pcl816", 8, 16, 10000, 1, 16, 16, &range_pcl816,
1287 &range_pcl816, PCLx1x_RANGE,
1288 0x00fc, /* IRQ mask */
1289 0x0a, /* DMA mask */
1290 0xffff, /* 16-bit card */
1291 0xffff, /* D/A maxdata */
1292 1024,
1293 1, /* ao chan list */
1294 100},
1295 {"pcl814b", 8, 16, 10000, 1, 16, 16, &range_pcl816,
1296 &range_pcl816, PCLx1x_RANGE,
1297 0x00fc,
1298 0x0a,
1299 0x3fff, /* 14 bit card */
1300 0x3fff,
1301 1024,
1302 1,
1303 100},
1304};
1305
1306static struct comedi_driver pcl816_driver = {
1307 .driver_name = "pcl816",
1308 .module = THIS_MODULE,
1309 .attach = pcl816_attach,
1310 .detach = pcl816_detach,
1311 .board_name = &boardtypes[0].name,
1312 .num_names = ARRAY_SIZE(boardtypes),
1313 .offset = sizeof(struct pcl816_board),
1314};
1315module_comedi_driver(pcl816_driver);
1316
1358MODULE_AUTHOR("Comedi http://www.comedi.org"); 1317MODULE_AUTHOR("Comedi http://www.comedi.org");
1359MODULE_DESCRIPTION("Comedi low-level driver"); 1318MODULE_DESCRIPTION("Comedi low-level driver");
1360MODULE_LICENSE("GPL"); 1319MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c
index 7344a53a81c4..1406c9720f5d 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -247,10 +247,6 @@ static const struct comedi_lrange range718_bipolar0_5 =
247static const struct comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} }; 247static const struct comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} };
248static const struct comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} }; 248static const struct comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} };
249 249
250static int pcl818_attach(struct comedi_device *dev,
251 struct comedi_devconfig *it);
252static int pcl818_detach(struct comedi_device *dev);
253
254#ifdef unused 250#ifdef unused
255static int RTC_lock; /* RTC lock */ 251static int RTC_lock; /* RTC lock */
256static int RTC_timer_lock; /* RTC int lock */ 252static int RTC_timer_lock; /* RTC int lock */
@@ -277,56 +273,6 @@ struct pcl818_board {
277 int is_818; 273 int is_818;
278}; 274};
279 275
280static const struct pcl818_board boardtypes[] = {
281 {"pcl818l", 4, 16, 8, 25000, 1, 16, 16, &range_pcl818l_l_ai,
282 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
283 0x0a, 0xfff, 0xfff, 0, 1},
284 {"pcl818h", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai,
285 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
286 0x0a, 0xfff, 0xfff, 0, 1},
287 {"pcl818hd", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai,
288 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
289 0x0a, 0xfff, 0xfff, 1, 1},
290 {"pcl818hg", 12, 16, 8, 10000, 1, 16, 16, &range_pcl818hg_ai,
291 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
292 0x0a, 0xfff, 0xfff, 1, 1},
293 {"pcl818", 9, 16, 8, 10000, 2, 16, 16, &range_pcl818h_ai,
294 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
295 0x0a, 0xfff, 0xfff, 0, 1},
296 {"pcl718", 1, 16, 8, 16000, 2, 16, 16, &range_unipolar5,
297 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
298 0x0a, 0xfff, 0xfff, 0, 0},
299 /* pcm3718 */
300 {"pcm3718", 9, 16, 8, 10000, 0, 16, 16, &range_pcl818h_ai,
301 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
302 0x0a, 0xfff, 0xfff, 0, 1 /* XXX ? */ },
303};
304
305#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl818_board))
306
307static struct comedi_driver driver_pcl818 = {
308 .driver_name = "pcl818",
309 .module = THIS_MODULE,
310 .attach = pcl818_attach,
311 .detach = pcl818_detach,
312 .board_name = &boardtypes[0].name,
313 .num_names = n_boardtypes,
314 .offset = sizeof(struct pcl818_board),
315};
316
317static int __init driver_pcl818_init_module(void)
318{
319 return comedi_driver_register(&driver_pcl818);
320}
321
322static void __exit driver_pcl818_cleanup_module(void)
323{
324 comedi_driver_unregister(&driver_pcl818);
325}
326
327module_init(driver_pcl818_init_module);
328module_exit(driver_pcl818_cleanup_module);
329
330struct pcl818_private { 276struct pcl818_private {
331 277
332 unsigned int dma; /* used DMA, 0=don't use DMA */ 278 unsigned int dma; /* used DMA, 0=don't use DMA */
@@ -1688,48 +1634,6 @@ static int rtc_setfreq_irq(int freq)
1688} 1634}
1689#endif 1635#endif
1690 1636
1691/*
1692==============================================================================
1693 Free any resources that we have claimed
1694*/
1695static void free_resources(struct comedi_device *dev)
1696{
1697 /* printk("free_resource()\n"); */
1698 if (dev->private) {
1699 pcl818_ai_cancel(dev, devpriv->sub_ai);
1700 pcl818_reset(dev);
1701 if (devpriv->dma)
1702 free_dma(devpriv->dma);
1703 if (devpriv->dmabuf[0])
1704 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1705 if (devpriv->dmabuf[1])
1706 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1707#ifdef unused
1708 if (devpriv->rtc_irq)
1709 free_irq(devpriv->rtc_irq, dev);
1710 if ((devpriv->dma_rtc) && (RTC_lock == 1)) {
1711 if (devpriv->rtc_iobase)
1712 release_region(devpriv->rtc_iobase,
1713 devpriv->rtc_iosize);
1714 }
1715 if (devpriv->dma_rtc)
1716 RTC_lock--;
1717#endif
1718 }
1719
1720 if (dev->irq)
1721 free_irq(dev->irq, dev);
1722 if (dev->iobase)
1723 release_region(dev->iobase, devpriv->io_range);
1724 /* printk("free_resource() end\n"); */
1725}
1726
1727/*
1728==============================================================================
1729
1730 Initialization
1731
1732*/
1733static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) 1637static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1734{ 1638{
1735 int ret; 1639 int ret;
@@ -2020,17 +1924,71 @@ no_dma:
2020 return 0; 1924 return 0;
2021} 1925}
2022 1926
2023/* 1927static void pcl818_detach(struct comedi_device *dev)
2024==============================================================================
2025 Removes device
2026 */
2027static int pcl818_detach(struct comedi_device *dev)
2028{ 1928{
2029 /* printk("comedi%d: pcl818: remove\n", dev->minor); */ 1929 if (dev->private) {
2030 free_resources(dev); 1930 pcl818_ai_cancel(dev, devpriv->sub_ai);
2031 return 0; 1931 pcl818_reset(dev);
1932 if (devpriv->dma)
1933 free_dma(devpriv->dma);
1934 if (devpriv->dmabuf[0])
1935 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1936 if (devpriv->dmabuf[1])
1937 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1938#ifdef unused
1939 if (devpriv->rtc_irq)
1940 free_irq(devpriv->rtc_irq, dev);
1941 if ((devpriv->dma_rtc) && (RTC_lock == 1)) {
1942 if (devpriv->rtc_iobase)
1943 release_region(devpriv->rtc_iobase,
1944 devpriv->rtc_iosize);
1945 }
1946 if (devpriv->dma_rtc)
1947 RTC_lock--;
1948#endif
1949 }
1950 if (dev->irq)
1951 free_irq(dev->irq, dev);
1952 if (dev->iobase)
1953 release_region(dev->iobase, devpriv->io_range);
2032} 1954}
2033 1955
1956static const struct pcl818_board boardtypes[] = {
1957 {"pcl818l", 4, 16, 8, 25000, 1, 16, 16, &range_pcl818l_l_ai,
1958 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1959 0x0a, 0xfff, 0xfff, 0, 1},
1960 {"pcl818h", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai,
1961 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1962 0x0a, 0xfff, 0xfff, 0, 1},
1963 {"pcl818hd", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai,
1964 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1965 0x0a, 0xfff, 0xfff, 1, 1},
1966 {"pcl818hg", 12, 16, 8, 10000, 1, 16, 16, &range_pcl818hg_ai,
1967 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1968 0x0a, 0xfff, 0xfff, 1, 1},
1969 {"pcl818", 9, 16, 8, 10000, 2, 16, 16, &range_pcl818h_ai,
1970 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1971 0x0a, 0xfff, 0xfff, 0, 1},
1972 {"pcl718", 1, 16, 8, 16000, 2, 16, 16, &range_unipolar5,
1973 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1974 0x0a, 0xfff, 0xfff, 0, 0},
1975 /* pcm3718 */
1976 {"pcm3718", 9, 16, 8, 10000, 0, 16, 16, &range_pcl818h_ai,
1977 &range_unipolar5, PCLx1x_RANGE, 0x00fc,
1978 0x0a, 0xfff, 0xfff, 0, 1 /* XXX ? */ },
1979};
1980
1981static struct comedi_driver pcl818_driver = {
1982 .driver_name = "pcl818",
1983 .module = THIS_MODULE,
1984 .attach = pcl818_attach,
1985 .detach = pcl818_detach,
1986 .board_name = &boardtypes[0].name,
1987 .num_names = ARRAY_SIZE(boardtypes),
1988 .offset = sizeof(struct pcl818_board),
1989};
1990module_comedi_driver(pcl818_driver);
1991
2034MODULE_AUTHOR("Comedi http://www.comedi.org"); 1992MODULE_AUTHOR("Comedi http://www.comedi.org");
2035MODULE_DESCRIPTION("Comedi low-level driver"); 1993MODULE_DESCRIPTION("Comedi low-level driver");
2036MODULE_LICENSE("GPL"); 1994MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c
index f5c0bd17684c..7492b8f1d499 100644
--- a/drivers/staging/comedi/drivers/pcm3724.c
+++ b/drivers/staging/comedi/drivers/pcm3724.c
@@ -62,10 +62,6 @@ Copy/pasted/hacked from pcm724.c
62#define CR_A_MODE(a) ((a)<<5) 62#define CR_A_MODE(a) ((a)<<5)
63#define CR_CW 0x80 63#define CR_CW 0x80
64 64
65static int pcm3724_attach(struct comedi_device *dev,
66 struct comedi_devconfig *it);
67static int pcm3724_detach(struct comedi_device *dev);
68
69struct pcm3724_board { 65struct pcm3724_board {
70 const char *name; /* driver name */ 66 const char *name; /* driver name */
71 int dio; /* num of DIO */ 67 int dio; /* num of DIO */
@@ -80,36 +76,8 @@ struct priv_pcm3724 {
80 int dio_2; 76 int dio_2;
81}; 77};
82 78
83static const struct pcm3724_board boardtypes[] = {
84 {"pcm3724", 48, 2, 0x00fc, PCM3724_SIZE,},
85};
86
87#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcm3724_board))
88#define this_board ((const struct pcm3724_board *)dev->board_ptr) 79#define this_board ((const struct pcm3724_board *)dev->board_ptr)
89 80
90static struct comedi_driver driver_pcm3724 = {
91 .driver_name = "pcm3724",
92 .module = THIS_MODULE,
93 .attach = pcm3724_attach,
94 .detach = pcm3724_detach,
95 .board_name = &boardtypes[0].name,
96 .num_names = n_boardtypes,
97 .offset = sizeof(struct pcm3724_board),
98};
99
100static int __init driver_pcm3724_init_module(void)
101{
102 return comedi_driver_register(&driver_pcm3724);
103}
104
105static void __exit driver_pcm3724_cleanup_module(void)
106{
107 comedi_driver_unregister(&driver_pcm3724);
108}
109
110module_init(driver_pcm3724_init_module);
111module_exit(driver_pcm3724_cleanup_module);
112
113/* (setq c-basic-offset 8) */ 81/* (setq c-basic-offset 8) */
114 82
115static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) 83static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
@@ -305,7 +273,7 @@ static int pcm3724_attach(struct comedi_device *dev,
305 return 0; 273 return 0;
306} 274}
307 275
308static int pcm3724_detach(struct comedi_device *dev) 276static void pcm3724_detach(struct comedi_device *dev)
309{ 277{
310 int i; 278 int i;
311 279
@@ -315,10 +283,23 @@ static int pcm3724_detach(struct comedi_device *dev)
315 } 283 }
316 if (dev->iobase) 284 if (dev->iobase)
317 release_region(dev->iobase, this_board->io_range); 285 release_region(dev->iobase, this_board->io_range);
318
319 return 0;
320} 286}
321 287
288static const struct pcm3724_board boardtypes[] = {
289 { "pcm3724", 48, 2, 0x00fc, PCM3724_SIZE, },
290};
291
292static struct comedi_driver pcm3724_driver = {
293 .driver_name = "pcm3724",
294 .module = THIS_MODULE,
295 .attach = pcm3724_attach,
296 .detach = pcm3724_detach,
297 .board_name = &boardtypes[0].name,
298 .num_names = ARRAY_SIZE(boardtypes),
299 .offset = sizeof(struct pcm3724_board),
300};
301module_comedi_driver(pcm3724_driver);
302
322MODULE_AUTHOR("Comedi http://www.comedi.org"); 303MODULE_AUTHOR("Comedi http://www.comedi.org");
323MODULE_DESCRIPTION("Comedi low-level driver"); 304MODULE_DESCRIPTION("Comedi low-level driver");
324MODULE_LICENSE("GPL"); 305MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcm3730.c b/drivers/staging/comedi/drivers/pcm3730.c
index bada6b236ff1..f8d1c644daf8 100644
--- a/drivers/staging/comedi/drivers/pcm3730.c
+++ b/drivers/staging/comedi/drivers/pcm3730.c
@@ -28,29 +28,6 @@ Configuration options:
28#define PCM3730_DIB 2 28#define PCM3730_DIB 2
29#define PCM3730_DIC 3 29#define PCM3730_DIC 3
30 30
31static int pcm3730_attach(struct comedi_device *dev,
32 struct comedi_devconfig *it);
33static int pcm3730_detach(struct comedi_device *dev);
34static struct comedi_driver driver_pcm3730 = {
35 .driver_name = "pcm3730",
36 .module = THIS_MODULE,
37 .attach = pcm3730_attach,
38 .detach = pcm3730_detach,
39};
40
41static int __init driver_pcm3730_init_module(void)
42{
43 return comedi_driver_register(&driver_pcm3730);
44}
45
46static void __exit driver_pcm3730_cleanup_module(void)
47{
48 comedi_driver_unregister(&driver_pcm3730);
49}
50
51module_init(driver_pcm3730_init_module);
52module_exit(driver_pcm3730_cleanup_module);
53
54static int pcm3730_do_insn_bits(struct comedi_device *dev, 31static int pcm3730_do_insn_bits(struct comedi_device *dev,
55 struct comedi_subdevice *s, 32 struct comedi_subdevice *s,
56 struct comedi_insn *insn, unsigned int *data) 33 struct comedi_insn *insn, unsigned int *data)
@@ -156,16 +133,20 @@ static int pcm3730_attach(struct comedi_device *dev,
156 return 0; 133 return 0;
157} 134}
158 135
159static int pcm3730_detach(struct comedi_device *dev) 136static void pcm3730_detach(struct comedi_device *dev)
160{ 137{
161 printk(KERN_INFO "comedi%d: pcm3730: remove\n", dev->minor);
162
163 if (dev->iobase) 138 if (dev->iobase)
164 release_region(dev->iobase, PCM3730_SIZE); 139 release_region(dev->iobase, PCM3730_SIZE);
165
166 return 0;
167} 140}
168 141
142static struct comedi_driver pcm3730_driver = {
143 .driver_name = "pcm3730",
144 .module = THIS_MODULE,
145 .attach = pcm3730_attach,
146 .detach = pcm3730_detach,
147};
148module_comedi_driver(pcm3730_driver);
149
169MODULE_AUTHOR("Comedi http://www.comedi.org"); 150MODULE_AUTHOR("Comedi http://www.comedi.org");
170MODULE_DESCRIPTION("Comedi low-level driver"); 151MODULE_DESCRIPTION("Comedi low-level driver");
171MODULE_LICENSE("GPL"); 152MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcmad.c b/drivers/staging/comedi/drivers/pcmad.c
index 23b3d777340c..1ec7d5cb346a 100644
--- a/drivers/staging/comedi/drivers/pcmad.c
+++ b/drivers/staging/comedi/drivers/pcmad.c
@@ -57,19 +57,8 @@ struct pcmad_board_struct {
57 const char *name; 57 const char *name;
58 int n_ai_bits; 58 int n_ai_bits;
59}; 59};
60static const struct pcmad_board_struct pcmad_boards[] = {
61 {
62 .name = "pcmad12",
63 .n_ai_bits = 12,
64 },
65 {
66 .name = "pcmad16",
67 .n_ai_bits = 16,
68 },
69};
70 60
71#define this_board ((const struct pcmad_board_struct *)(dev->board_ptr)) 61#define this_board ((const struct pcmad_board_struct *)(dev->board_ptr))
72#define n_pcmad_boards ARRAY_SIZE(pcmad_boards)
73 62
74struct pcmad_priv_struct { 63struct pcmad_priv_struct {
75 int differential; 64 int differential;
@@ -77,31 +66,6 @@ struct pcmad_priv_struct {
77}; 66};
78#define devpriv ((struct pcmad_priv_struct *)dev->private) 67#define devpriv ((struct pcmad_priv_struct *)dev->private)
79 68
80static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it);
81static int pcmad_detach(struct comedi_device *dev);
82static struct comedi_driver driver_pcmad = {
83 .driver_name = "pcmad",
84 .module = THIS_MODULE,
85 .attach = pcmad_attach,
86 .detach = pcmad_detach,
87 .board_name = &pcmad_boards[0].name,
88 .num_names = n_pcmad_boards,
89 .offset = sizeof(pcmad_boards[0]),
90};
91
92static int __init driver_pcmad_init_module(void)
93{
94 return comedi_driver_register(&driver_pcmad);
95}
96
97static void __exit driver_pcmad_cleanup_module(void)
98{
99 comedi_driver_unregister(&driver_pcmad);
100}
101
102module_init(driver_pcmad_init_module);
103module_exit(driver_pcmad_cleanup_module);
104
105#define TIMEOUT 100 69#define TIMEOUT 100
106 70
107static int pcmad_ai_insn_read(struct comedi_device *dev, 71static int pcmad_ai_insn_read(struct comedi_device *dev,
@@ -175,19 +139,34 @@ static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it)
175 return 0; 139 return 0;
176} 140}
177 141
178static int pcmad_detach(struct comedi_device *dev) 142static void pcmad_detach(struct comedi_device *dev)
179{ 143{
180 printk(KERN_INFO "comedi%d: pcmad: remove\n", dev->minor);
181
182 if (dev->irq) 144 if (dev->irq)
183 free_irq(dev->irq, dev); 145 free_irq(dev->irq, dev);
184
185 if (dev->iobase) 146 if (dev->iobase)
186 release_region(dev->iobase, PCMAD_SIZE); 147 release_region(dev->iobase, PCMAD_SIZE);
187
188 return 0;
189} 148}
190 149
150static const struct pcmad_board_struct pcmad_boards[] = {
151 {
152 .name = "pcmad12",
153 .n_ai_bits = 12,
154 }, {
155 .name = "pcmad16",
156 .n_ai_bits = 16,
157 },
158};
159static struct comedi_driver pcmad_driver = {
160 .driver_name = "pcmad",
161 .module = THIS_MODULE,
162 .attach = pcmad_attach,
163 .detach = pcmad_detach,
164 .board_name = &pcmad_boards[0].name,
165 .num_names = ARRAY_SIZE(pcmad_boards),
166 .offset = sizeof(pcmad_boards[0]),
167};
168module_comedi_driver(pcmad_driver);
169
191MODULE_AUTHOR("Comedi http://www.comedi.org"); 170MODULE_AUTHOR("Comedi http://www.comedi.org");
192MODULE_DESCRIPTION("Comedi low-level driver"); 171MODULE_DESCRIPTION("Comedi low-level driver");
193MODULE_LICENSE("GPL"); 172MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c
index 0e9ffa28d745..4786148b4fd0 100644
--- a/drivers/staging/comedi/drivers/pcmda12.c
+++ b/drivers/staging/comedi/drivers/pcmda12.c
@@ -80,12 +80,6 @@ static const struct comedi_lrange pcmda12_ranges = {
80 } 80 }
81}; 81};
82 82
83static const struct pcmda12_board pcmda12_boards[] = {
84 {
85 .name = "pcmda12",
86 },
87};
88
89/* 83/*
90 * Useful for shorthand access to the particular board structure 84 * Useful for shorthand access to the particular board structure
91 */ 85 */
@@ -99,137 +93,6 @@ struct pcmda12_private {
99 93
100#define devpriv ((struct pcmda12_private *)(dev->private)) 94#define devpriv ((struct pcmda12_private *)(dev->private))
101 95
102/*
103 * The struct comedi_driver structure tells the Comedi core module
104 * which functions to call to configure/deconfigure (attach/detach)
105 * the board, and also about the kernel module that contains
106 * the device code.
107 */
108static int pcmda12_attach(struct comedi_device *dev,
109 struct comedi_devconfig *it);
110static int pcmda12_detach(struct comedi_device *dev);
111
112static void zero_chans(struct comedi_device *dev);
113
114static struct comedi_driver driver = {
115 .driver_name = "pcmda12",
116 .module = THIS_MODULE,
117 .attach = pcmda12_attach,
118 .detach = pcmda12_detach,
119/* It is not necessary to implement the following members if you are
120 * writing a driver for a ISA PnP or PCI card */
121 /* Most drivers will support multiple types of boards by
122 * having an array of board structures. These were defined
123 * in pcmda12_boards[] above. Note that the element 'name'
124 * was first in the structure -- Comedi uses this fact to
125 * extract the name of the board without knowing any details
126 * about the structure except for its length.
127 * When a device is attached (by comedi_config), the name
128 * of the device is given to Comedi, and Comedi tries to
129 * match it by going through the list of board names. If
130 * there is a match, the address of the pointer is put
131 * into dev->board_ptr and driver->attach() is called.
132 *
133 * Note that these are not necessary if you can determine
134 * the type of board in software. ISA PnP, PCI, and PCMCIA
135 * devices are such boards.
136 */
137 .board_name = &pcmda12_boards[0].name,
138 .offset = sizeof(struct pcmda12_board),
139 .num_names = ARRAY_SIZE(pcmda12_boards),
140};
141
142static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
143 struct comedi_insn *insn, unsigned int *data);
144static int ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
145 struct comedi_insn *insn, unsigned int *data);
146
147/*
148 * Attach is called by the Comedi core to configure the driver
149 * for a particular board. If you specified a board_name array
150 * in the driver structure, dev->board_ptr contains that
151 * address.
152 */
153static int pcmda12_attach(struct comedi_device *dev,
154 struct comedi_devconfig *it)
155{
156 struct comedi_subdevice *s;
157 unsigned long iobase;
158
159 iobase = it->options[0];
160 printk(KERN_INFO
161 "comedi%d: %s: io: %lx %s ", dev->minor, driver.driver_name,
162 iobase, it->options[1] ? "simultaneous xfer mode enabled" : "");
163
164 if (!request_region(iobase, IOSIZE, driver.driver_name)) {
165 printk("I/O port conflict\n");
166 return -EIO;
167 }
168 dev->iobase = iobase;
169
170/*
171 * Initialize dev->board_name. Note that we can use the "thisboard"
172 * macro now, since we just initialized it in the last line.
173 */
174 dev->board_name = thisboard->name;
175
176/*
177 * Allocate the private structure area. alloc_private() is a
178 * convenient macro defined in comedidev.h.
179 */
180 if (alloc_private(dev, sizeof(struct pcmda12_private)) < 0) {
181 printk(KERN_ERR "cannot allocate private data structure\n");
182 return -ENOMEM;
183 }
184
185 devpriv->simultaneous_xfer_mode = it->options[1];
186
187 /*
188 * Allocate the subdevice structures. alloc_subdevice() is a
189 * convenient macro defined in comedidev.h.
190 *
191 * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the
192 * 96-channel version of the board.
193 */
194 if (alloc_subdevices(dev, 1) < 0) {
195 printk(KERN_ERR "cannot allocate subdevice data structures\n");
196 return -ENOMEM;
197 }
198
199 s = dev->subdevices;
200 s->private = NULL;
201 s->maxdata = (0x1 << BITS) - 1;
202 s->range_table = &pcmda12_ranges;
203 s->type = COMEDI_SUBD_AO;
204 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
205 s->n_chan = CHANS;
206 s->insn_write = &ao_winsn;
207 s->insn_read = &ao_rinsn;
208
209 zero_chans(dev); /* clear out all the registers, basically */
210
211 printk(KERN_INFO "attached\n");
212
213 return 1;
214}
215
216/*
217 * _detach is called to deconfigure a device. It should deallocate
218 * resources.
219 * This function is also called when _attach() fails, so it should be
220 * careful not to release resources that were not necessarily
221 * allocated by _attach(). dev->private and dev->subdevices are
222 * deallocated automatically by the core.
223 */
224static int pcmda12_detach(struct comedi_device *dev)
225{
226 printk(KERN_INFO
227 "comedi%d: %s: remove\n", dev->minor, driver.driver_name);
228 if (dev->iobase)
229 release_region(dev->iobase, IOSIZE);
230 return 0;
231}
232
233static void zero_chans(struct comedi_device *dev) 96static void zero_chans(struct comedi_device *dev)
234{ /* sets up an 97{ /* sets up an
235 ASIC chip to defaults */ 98 ASIC chip to defaults */
@@ -301,22 +164,91 @@ static int ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
301 return i; 164 return i;
302} 165}
303 166
167static int pcmda12_attach(struct comedi_device *dev,
168 struct comedi_devconfig *it)
169{
170 struct comedi_subdevice *s;
171 unsigned long iobase;
172
173 iobase = it->options[0];
174 printk(KERN_INFO
175 "comedi%d: %s: io: %lx %s ", dev->minor, dev->driver->driver_name,
176 iobase, it->options[1] ? "simultaneous xfer mode enabled" : "");
177
178 if (!request_region(iobase, IOSIZE, dev->driver->driver_name)) {
179 printk("I/O port conflict\n");
180 return -EIO;
181 }
182 dev->iobase = iobase;
183
304/* 184/*
305 * A convenient macro that defines init_module() and cleanup_module(), 185 * Initialize dev->board_name. Note that we can use the "thisboard"
306 * as necessary. 186 * macro now, since we just initialized it in the last line.
307 */ 187 */
308static int __init driver_init_module(void) 188 dev->board_name = thisboard->name;
309{ 189
310 return comedi_driver_register(&driver); 190/*
191 * Allocate the private structure area. alloc_private() is a
192 * convenient macro defined in comedidev.h.
193 */
194 if (alloc_private(dev, sizeof(struct pcmda12_private)) < 0) {
195 printk(KERN_ERR "cannot allocate private data structure\n");
196 return -ENOMEM;
197 }
198
199 devpriv->simultaneous_xfer_mode = it->options[1];
200
201 /*
202 * Allocate the subdevice structures. alloc_subdevice() is a
203 * convenient macro defined in comedidev.h.
204 *
205 * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the
206 * 96-channel version of the board.
207 */
208 if (alloc_subdevices(dev, 1) < 0) {
209 printk(KERN_ERR "cannot allocate subdevice data structures\n");
210 return -ENOMEM;
211 }
212
213 s = dev->subdevices;
214 s->private = NULL;
215 s->maxdata = (0x1 << BITS) - 1;
216 s->range_table = &pcmda12_ranges;
217 s->type = COMEDI_SUBD_AO;
218 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
219 s->n_chan = CHANS;
220 s->insn_write = &ao_winsn;
221 s->insn_read = &ao_rinsn;
222
223 zero_chans(dev); /* clear out all the registers, basically */
224
225 printk(KERN_INFO "attached\n");
226
227 return 1;
311} 228}
312 229
313static void __exit driver_cleanup_module(void) 230static void pcmda12_detach(struct comedi_device *dev)
314{ 231{
315 comedi_driver_unregister(&driver); 232 if (dev->iobase)
233 release_region(dev->iobase, IOSIZE);
316} 234}
317 235
318module_init(driver_init_module); 236static const struct pcmda12_board pcmda12_boards[] = {
319module_exit(driver_cleanup_module); 237 {
238 .name = "pcmda12",
239 },
240};
241
242static struct comedi_driver pcmda12_driver = {
243 .driver_name = "pcmda12",
244 .module = THIS_MODULE,
245 .attach = pcmda12_attach,
246 .detach = pcmda12_detach,
247 .board_name = &pcmda12_boards[0].name,
248 .offset = sizeof(struct pcmda12_board),
249 .num_names = ARRAY_SIZE(pcmda12_boards),
250};
251module_comedi_driver(pcmda12_driver);
320 252
321MODULE_AUTHOR("Comedi http://www.comedi.org"); 253MODULE_AUTHOR("Comedi http://www.comedi.org");
322MODULE_DESCRIPTION("Comedi low-level driver"); 254MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index eddac00e4e29..efed168d2bac 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -145,13 +145,6 @@ Configuration Options:
145#define PAGE_ENAB 2 145#define PAGE_ENAB 2
146#define PAGE_INT_ID 3 146#define PAGE_INT_ID 3
147 147
148static int ai_rinsn(struct comedi_device *, struct comedi_subdevice *,
149 struct comedi_insn *, unsigned int *);
150static int ao_rinsn(struct comedi_device *, struct comedi_subdevice *,
151 struct comedi_insn *, unsigned int *);
152static int ao_winsn(struct comedi_device *, struct comedi_subdevice *,
153 struct comedi_insn *, unsigned int *);
154
155/* 148/*
156 * Board descriptions for two imaginary boards. Describing the 149 * Board descriptions for two imaginary boards. Describing the
157 * boards in this way is optional, and completely driver-dependent. 150 * boards in this way is optional, and completely driver-dependent.
@@ -190,23 +183,6 @@ static const struct comedi_lrange ranges_ao = {
190 RANGE(-2.5, 2.5), RANGE(-2.5, 7.5)} 183 RANGE(-2.5, 2.5), RANGE(-2.5, 7.5)}
191}; 184};
192 185
193static const struct pcmmio_board pcmmio_boards[] = {
194 {
195 .name = "pcmmio",
196 .dio_num_asics = 1,
197 .dio_num_ports = 6,
198 .total_iosize = 32,
199 .ai_bits = 16,
200 .ao_bits = 16,
201 .n_ai_chans = 16,
202 .n_ao_chans = 8,
203 .ai_range_table = &ranges_ai,
204 .ao_range_table = &ranges_ao,
205 .ai_rinsn = ai_rinsn,
206 .ao_rinsn = ao_rinsn,
207 .ao_winsn = ao_winsn},
208};
209
210/* 186/*
211 * Useful for shorthand access to the particular board structure 187 * Useful for shorthand access to the particular board structure
212 */ 188 */
@@ -293,312 +269,6 @@ struct pcmmio_private {
293 */ 269 */
294#define devpriv ((struct pcmmio_private *)dev->private) 270#define devpriv ((struct pcmmio_private *)dev->private)
295#define subpriv ((struct pcmmio_subdev_private *)s->private) 271#define subpriv ((struct pcmmio_subdev_private *)s->private)
296/*
297 * The struct comedi_driver structure tells the Comedi core module
298 * which functions to call to configure/deconfigure (attach/detach)
299 * the board, and also about the kernel module that contains
300 * the device code.
301 */
302static int pcmmio_attach(struct comedi_device *dev,
303 struct comedi_devconfig *it);
304static int pcmmio_detach(struct comedi_device *dev);
305
306static struct comedi_driver driver = {
307 .driver_name = "pcmmio",
308 .module = THIS_MODULE,
309 .attach = pcmmio_attach,
310 .detach = pcmmio_detach,
311/* It is not necessary to implement the following members if you are
312 * writing a driver for a ISA PnP or PCI card */
313 /* Most drivers will support multiple types of boards by
314 * having an array of board structures. These were defined
315 * in pcmmio_boards[] above. Note that the element 'name'
316 * was first in the structure -- Comedi uses this fact to
317 * extract the name of the board without knowing any details
318 * about the structure except for its length.
319 * When a device is attached (by comedi_config), the name
320 * of the device is given to Comedi, and Comedi tries to
321 * match it by going through the list of board names. If
322 * there is a match, the address of the pointer is put
323 * into dev->board_ptr and driver->attach() is called.
324 *
325 * Note that these are not necessary if you can determine
326 * the type of board in software. ISA PnP, PCI, and PCMCIA
327 * devices are such boards.
328 */
329 .board_name = &pcmmio_boards[0].name,
330 .offset = sizeof(struct pcmmio_board),
331 .num_names = ARRAY_SIZE(pcmmio_boards),
332};
333
334static int pcmmio_dio_insn_bits(struct comedi_device *dev,
335 struct comedi_subdevice *s,
336 struct comedi_insn *insn, unsigned int *data);
337static int pcmmio_dio_insn_config(struct comedi_device *dev,
338 struct comedi_subdevice *s,
339 struct comedi_insn *insn, unsigned int *data);
340
341static irqreturn_t interrupt_pcmmio(int irq, void *d);
342static void pcmmio_stop_intr(struct comedi_device *, struct comedi_subdevice *);
343static int pcmmio_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
344static int pcmmio_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
345static int pcmmio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
346 struct comedi_cmd *cmd);
347
348/* some helper functions to deal with specifics of this device's registers */
349/* sets up/clears ASIC chips to defaults */
350static void init_asics(struct comedi_device *dev);
351static void switch_page(struct comedi_device *dev, int asic, int page);
352#ifdef notused
353static void lock_port(struct comedi_device *dev, int asic, int port);
354static void unlock_port(struct comedi_device *dev, int asic, int port);
355#endif
356
357/*
358 * Attach is called by the Comedi core to configure the driver
359 * for a particular board. If you specified a board_name array
360 * in the driver structure, dev->board_ptr contains that
361 * address.
362 */
363static int pcmmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
364{
365 struct comedi_subdevice *s;
366 int sdev_no, chans_left, n_dio_subdevs, n_subdevs, port, asic,
367 thisasic_chanct = 0;
368 unsigned long iobase;
369 unsigned int irq[MAX_ASICS];
370
371 iobase = it->options[0];
372 irq[0] = it->options[1];
373
374 printk(KERN_INFO "comedi%d: %s: io: %lx attaching...\n", dev->minor,
375 driver.driver_name, iobase);
376
377 dev->iobase = iobase;
378
379 if (!iobase || !request_region(iobase,
380 thisboard->total_iosize,
381 driver.driver_name)) {
382 printk(KERN_ERR "comedi%d: I/O port conflict\n", dev->minor);
383 return -EIO;
384 }
385
386/*
387 * Initialize dev->board_name. Note that we can use the "thisboard"
388 * macro now, since we just initialized it in the last line.
389 */
390 dev->board_name = thisboard->name;
391
392/*
393 * Allocate the private structure area. alloc_private() is a
394 * convenient macro defined in comedidev.h.
395 */
396 if (alloc_private(dev, sizeof(struct pcmmio_private)) < 0) {
397 printk(KERN_ERR "comedi%d: cannot allocate private data structure\n",
398 dev->minor);
399 return -ENOMEM;
400 }
401
402 for (asic = 0; asic < MAX_ASICS; ++asic) {
403 devpriv->asics[asic].num = asic;
404 devpriv->asics[asic].iobase =
405 dev->iobase + 16 + asic * ASIC_IOSIZE;
406 /*
407 * this gets actually set at the end of this function when we
408 * request_irqs
409 */
410 devpriv->asics[asic].irq = 0;
411 spin_lock_init(&devpriv->asics[asic].spinlock);
412 }
413
414 chans_left = CHANS_PER_ASIC * thisboard->dio_num_asics;
415 n_dio_subdevs = CALC_N_DIO_SUBDEVS(chans_left);
416 n_subdevs = n_dio_subdevs + 2;
417 devpriv->sprivs =
418 kcalloc(n_subdevs, sizeof(struct pcmmio_subdev_private),
419 GFP_KERNEL);
420 if (!devpriv->sprivs) {
421 printk(KERN_ERR "comedi%d: cannot allocate subdevice private data structures\n",
422 dev->minor);
423 return -ENOMEM;
424 }
425 /*
426 * Allocate the subdevice structures. alloc_subdevice() is a
427 * convenient macro defined in comedidev.h.
428 *
429 * Allocate 1 AI + 1 AO + 2 DIO subdevs (24 lines per DIO)
430 */
431 if (alloc_subdevices(dev, n_subdevs) < 0) {
432 printk(KERN_ERR "comedi%d: cannot allocate subdevice data structures\n",
433 dev->minor);
434 return -ENOMEM;
435 }
436
437 /* First, AI */
438 sdev_no = 0;
439 s = dev->subdevices + sdev_no;
440 s->private = devpriv->sprivs + sdev_no;
441 s->maxdata = (1 << thisboard->ai_bits) - 1;
442 s->range_table = thisboard->ai_range_table;
443 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
444 s->type = COMEDI_SUBD_AI;
445 s->n_chan = thisboard->n_ai_chans;
446 s->len_chanlist = s->n_chan;
447 s->insn_read = thisboard->ai_rinsn;
448 subpriv->iobase = dev->iobase + 0;
449 /* initialize the resource enable register by clearing it */
450 outb(0, subpriv->iobase + 3);
451 outb(0, subpriv->iobase + 4 + 3);
452
453 /* Next, AO */
454 ++sdev_no;
455 s = dev->subdevices + sdev_no;
456 s->private = devpriv->sprivs + sdev_no;
457 s->maxdata = (1 << thisboard->ao_bits) - 1;
458 s->range_table = thisboard->ao_range_table;
459 s->subdev_flags = SDF_READABLE;
460 s->type = COMEDI_SUBD_AO;
461 s->n_chan = thisboard->n_ao_chans;
462 s->len_chanlist = s->n_chan;
463 s->insn_read = thisboard->ao_rinsn;
464 s->insn_write = thisboard->ao_winsn;
465 subpriv->iobase = dev->iobase + 8;
466 /* initialize the resource enable register by clearing it */
467 outb(0, subpriv->iobase + 3);
468 outb(0, subpriv->iobase + 4 + 3);
469
470 ++sdev_no;
471 port = 0;
472 asic = 0;
473 for (; sdev_no < (int)dev->n_subdevices; ++sdev_no) {
474 int byte_no;
475
476 s = dev->subdevices + sdev_no;
477 s->private = devpriv->sprivs + sdev_no;
478 s->maxdata = 1;
479 s->range_table = &range_digital;
480 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
481 s->type = COMEDI_SUBD_DIO;
482 s->insn_bits = pcmmio_dio_insn_bits;
483 s->insn_config = pcmmio_dio_insn_config;
484 s->n_chan = min(chans_left, MAX_CHANS_PER_SUBDEV);
485 subpriv->dio.intr.asic = -1;
486 subpriv->dio.intr.first_chan = -1;
487 subpriv->dio.intr.asic_chan = -1;
488 subpriv->dio.intr.num_asic_chans = -1;
489 subpriv->dio.intr.active = 0;
490 s->len_chanlist = 1;
491
492 /* save the ioport address for each 'port' of 8 channels in the
493 subdevice */
494 for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) {
495 if (port >= PORTS_PER_ASIC) {
496 port = 0;
497 ++asic;
498 thisasic_chanct = 0;
499 }
500 subpriv->iobases[byte_no] =
501 devpriv->asics[asic].iobase + port;
502
503 if (thisasic_chanct <
504 CHANS_PER_PORT * INTR_PORTS_PER_ASIC
505 && subpriv->dio.intr.asic < 0) {
506 /*
507 * this is an interrupt subdevice,
508 * so setup the struct
509 */
510 subpriv->dio.intr.asic = asic;
511 subpriv->dio.intr.active = 0;
512 subpriv->dio.intr.stop_count = 0;
513 subpriv->dio.intr.first_chan = byte_no * 8;
514 subpriv->dio.intr.asic_chan = thisasic_chanct;
515 subpriv->dio.intr.num_asic_chans =
516 s->n_chan - subpriv->dio.intr.first_chan;
517 s->cancel = pcmmio_cancel;
518 s->do_cmd = pcmmio_cmd;
519 s->do_cmdtest = pcmmio_cmdtest;
520 s->len_chanlist =
521 subpriv->dio.intr.num_asic_chans;
522 }
523 thisasic_chanct += CHANS_PER_PORT;
524 }
525 spin_lock_init(&subpriv->dio.intr.spinlock);
526
527 chans_left -= s->n_chan;
528
529 if (!chans_left) {
530 /*
531 * reset the asic to our first asic,
532 * to do intr subdevs
533 */
534 asic = 0;
535 port = 0;
536 }
537
538 }
539
540 init_asics(dev); /* clear out all the registers, basically */
541
542 for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) {
543 if (irq[asic]
544 && request_irq(irq[asic], interrupt_pcmmio,
545 IRQF_SHARED, thisboard->name, dev)) {
546 int i;
547 /* unroll the allocated irqs.. */
548 for (i = asic - 1; i >= 0; --i) {
549 free_irq(irq[i], dev);
550 devpriv->asics[i].irq = irq[i] = 0;
551 }
552 irq[asic] = 0;
553 }
554 devpriv->asics[asic].irq = irq[asic];
555 }
556
557 dev->irq = irq[0]; /*
558 * grr.. wish comedi dev struct supported
559 * multiple irqs..
560 */
561
562 if (irq[0]) {
563 printk(KERN_DEBUG "comedi%d: irq: %u\n", dev->minor, irq[0]);
564 if (thisboard->dio_num_asics == 2 && irq[1])
565 printk(KERN_DEBUG "comedi%d: second ASIC irq: %u\n",
566 dev->minor, irq[1]);
567 } else {
568 printk(KERN_INFO "comedi%d: (IRQ mode disabled)\n", dev->minor);
569 }
570
571 printk(KERN_INFO "comedi%d: attached\n", dev->minor);
572
573 return 1;
574}
575
576/*
577 * _detach is called to deconfigure a device. It should deallocate
578 * resources.
579 * This function is also called when _attach() fails, so it should be
580 * careful not to release resources that were not necessarily
581 * allocated by _attach(). dev->private and dev->subdevices are
582 * deallocated automatically by the core.
583 */
584static int pcmmio_detach(struct comedi_device *dev)
585{
586 int i;
587
588 printk(KERN_INFO "comedi%d: %s: remove\n", dev->minor, driver.driver_name);
589 if (dev->iobase)
590 release_region(dev->iobase, thisboard->total_iosize);
591
592 for (i = 0; i < MAX_ASICS; ++i) {
593 if (devpriv && devpriv->asics[i].irq)
594 free_irq(devpriv->asics[i].irq, dev);
595 }
596
597 if (devpriv && devpriv->sprivs)
598 kfree(devpriv->sprivs);
599
600 return 0;
601}
602 272
603/* DIO devices are slightly special. Although it is possible to 273/* DIO devices are slightly special. Although it is possible to
604 * implement the insn_read/insn_write interface, it is much more 274 * implement the insn_read/insn_write interface, it is much more
@@ -667,7 +337,7 @@ static int pcmmio_dio_insn_bits(struct comedi_device *dev,
667 } 337 }
668#ifdef DAMMIT_ITS_BROKEN 338#ifdef DAMMIT_ITS_BROKEN
669 /* DEBUG */ 339 /* DEBUG */
670 printk("data_out_byte %02x\n", (unsigned)byte); 340 printk(KERN_DEBUG "data_out_byte %02x\n", (unsigned)byte);
671#endif 341#endif
672 /* save the digital input lines for this byte.. */ 342 /* save the digital input lines for this byte.. */
673 s->state |= ((unsigned int)byte) << offset; 343 s->state |= ((unsigned int)byte) << offset;
@@ -751,6 +421,21 @@ static int pcmmio_dio_insn_config(struct comedi_device *dev,
751 return insn->n; 421 return insn->n;
752} 422}
753 423
424static void switch_page(struct comedi_device *dev, int asic, int page)
425{
426 if (asic < 0 || asic >= thisboard->dio_num_asics)
427 return; /* paranoia */
428 if (page < 0 || page >= NUM_PAGES)
429 return; /* more paranoia */
430
431 devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK;
432 devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET;
433
434 /* now write out the shadow register */
435 outb(devpriv->asics[asic].pagelock,
436 devpriv->asics[asic].iobase + REG_PAGELOCK);
437}
438
754static void init_asics(struct comedi_device *dev) 439static void init_asics(struct comedi_device *dev)
755{ /* sets up an 440{ /* sets up an
756 ASIC chip to defaults */ 441 ASIC chip to defaults */
@@ -788,21 +473,6 @@ static void init_asics(struct comedi_device *dev)
788 } 473 }
789} 474}
790 475
791static void switch_page(struct comedi_device *dev, int asic, int page)
792{
793 if (asic < 0 || asic >= thisboard->dio_num_asics)
794 return; /* paranoia */
795 if (page < 0 || page >= NUM_PAGES)
796 return; /* more paranoia */
797
798 devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK;
799 devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET;
800
801 /* now write out the shadow register */
802 outb(devpriv->asics[asic].pagelock,
803 devpriv->asics[asic].iobase + REG_PAGELOCK);
804}
805
806#ifdef notused 476#ifdef notused
807static void lock_port(struct comedi_device *dev, int asic, int port) 477static void lock_port(struct comedi_device *dev, int asic, int port)
808{ 478{
@@ -831,6 +501,27 @@ static void unlock_port(struct comedi_device *dev, int asic, int port)
831} 501}
832#endif /* notused */ 502#endif /* notused */
833 503
504static void pcmmio_stop_intr(struct comedi_device *dev,
505 struct comedi_subdevice *s)
506{
507 int nports, firstport, asic, port;
508
509 asic = subpriv->dio.intr.asic;
510 if (asic < 0)
511 return; /* not an interrupt subdev */
512
513 subpriv->dio.intr.enabled_mask = 0;
514 subpriv->dio.intr.active = 0;
515 s->async->inttrig = 0;
516 nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT;
517 firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT;
518 switch_page(dev, asic, PAGE_ENAB);
519 for (port = firstport; port < firstport + nports; ++port) {
520 /* disable all intrs for this subdev.. */
521 outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port);
522 }
523}
524
834static irqreturn_t interrupt_pcmmio(int irq, void *d) 525static irqreturn_t interrupt_pcmmio(int irq, void *d)
835{ 526{
836 int asic, got1 = 0; 527 int asic, got1 = 0;
@@ -991,27 +682,6 @@ static irqreturn_t interrupt_pcmmio(int irq, void *d)
991 return IRQ_HANDLED; 682 return IRQ_HANDLED;
992} 683}
993 684
994static void pcmmio_stop_intr(struct comedi_device *dev,
995 struct comedi_subdevice *s)
996{
997 int nports, firstport, asic, port;
998
999 asic = subpriv->dio.intr.asic;
1000 if (asic < 0)
1001 return; /* not an interrupt subdev */
1002
1003 subpriv->dio.intr.enabled_mask = 0;
1004 subpriv->dio.intr.active = 0;
1005 s->async->inttrig = 0;
1006 nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT;
1007 firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT;
1008 switch_page(dev, asic, PAGE_ENAB);
1009 for (port = firstport; port < firstport + nports; ++port) {
1010 /* disable all intrs for this subdev.. */
1011 outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port);
1012 }
1013}
1014
1015static int pcmmio_start_intr(struct comedi_device *dev, 685static int pcmmio_start_intr(struct comedi_device *dev,
1016 struct comedi_subdevice *s) 686 struct comedi_subdevice *s)
1017{ 687{
@@ -1340,22 +1010,261 @@ static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
1340 return n; 1010 return n;
1341} 1011}
1342 1012
1013static int pcmmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1014{
1015 struct comedi_subdevice *s;
1016 int sdev_no, chans_left, n_dio_subdevs, n_subdevs, port, asic,
1017 thisasic_chanct = 0;
1018 unsigned long iobase;
1019 unsigned int irq[MAX_ASICS];
1020
1021 iobase = it->options[0];
1022 irq[0] = it->options[1];
1023
1024 printk(KERN_INFO "comedi%d: %s: io: %lx attaching...\n", dev->minor,
1025 dev->driver->driver_name, iobase);
1026
1027 dev->iobase = iobase;
1028
1029 if (!iobase || !request_region(iobase,
1030 thisboard->total_iosize,
1031 dev->driver->driver_name)) {
1032 printk(KERN_ERR "comedi%d: I/O port conflict\n", dev->minor);
1033 return -EIO;
1034 }
1035
1343/* 1036/*
1344 * A convenient macro that defines init_module() and cleanup_module(), 1037 * Initialize dev->board_name. Note that we can use the "thisboard"
1345 * as necessary. 1038 * macro now, since we just initialized it in the last line.
1346 */ 1039 */
1347static int __init driver_init_module(void) 1040 dev->board_name = thisboard->name;
1348{ 1041
1349 return comedi_driver_register(&driver); 1042/*
1043 * Allocate the private structure area. alloc_private() is a
1044 * convenient macro defined in comedidev.h.
1045 */
1046 if (alloc_private(dev, sizeof(struct pcmmio_private)) < 0) {
1047 printk(KERN_ERR "comedi%d: cannot allocate private data structure\n",
1048 dev->minor);
1049 return -ENOMEM;
1050 }
1051
1052 for (asic = 0; asic < MAX_ASICS; ++asic) {
1053 devpriv->asics[asic].num = asic;
1054 devpriv->asics[asic].iobase =
1055 dev->iobase + 16 + asic * ASIC_IOSIZE;
1056 /*
1057 * this gets actually set at the end of this function when we
1058 * request_irqs
1059 */
1060 devpriv->asics[asic].irq = 0;
1061 spin_lock_init(&devpriv->asics[asic].spinlock);
1062 }
1063
1064 chans_left = CHANS_PER_ASIC * thisboard->dio_num_asics;
1065 n_dio_subdevs = CALC_N_DIO_SUBDEVS(chans_left);
1066 n_subdevs = n_dio_subdevs + 2;
1067 devpriv->sprivs =
1068 kcalloc(n_subdevs, sizeof(struct pcmmio_subdev_private),
1069 GFP_KERNEL);
1070 if (!devpriv->sprivs) {
1071 printk(KERN_ERR "comedi%d: cannot allocate subdevice private data structures\n",
1072 dev->minor);
1073 return -ENOMEM;
1074 }
1075 /*
1076 * Allocate the subdevice structures. alloc_subdevice() is a
1077 * convenient macro defined in comedidev.h.
1078 *
1079 * Allocate 1 AI + 1 AO + 2 DIO subdevs (24 lines per DIO)
1080 */
1081 if (alloc_subdevices(dev, n_subdevs) < 0) {
1082 printk(KERN_ERR "comedi%d: cannot allocate subdevice data structures\n",
1083 dev->minor);
1084 return -ENOMEM;
1085 }
1086
1087 /* First, AI */
1088 sdev_no = 0;
1089 s = dev->subdevices + sdev_no;
1090 s->private = devpriv->sprivs + sdev_no;
1091 s->maxdata = (1 << thisboard->ai_bits) - 1;
1092 s->range_table = thisboard->ai_range_table;
1093 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
1094 s->type = COMEDI_SUBD_AI;
1095 s->n_chan = thisboard->n_ai_chans;
1096 s->len_chanlist = s->n_chan;
1097 s->insn_read = thisboard->ai_rinsn;
1098 subpriv->iobase = dev->iobase + 0;
1099 /* initialize the resource enable register by clearing it */
1100 outb(0, subpriv->iobase + 3);
1101 outb(0, subpriv->iobase + 4 + 3);
1102
1103 /* Next, AO */
1104 ++sdev_no;
1105 s = dev->subdevices + sdev_no;
1106 s->private = devpriv->sprivs + sdev_no;
1107 s->maxdata = (1 << thisboard->ao_bits) - 1;
1108 s->range_table = thisboard->ao_range_table;
1109 s->subdev_flags = SDF_READABLE;
1110 s->type = COMEDI_SUBD_AO;
1111 s->n_chan = thisboard->n_ao_chans;
1112 s->len_chanlist = s->n_chan;
1113 s->insn_read = thisboard->ao_rinsn;
1114 s->insn_write = thisboard->ao_winsn;
1115 subpriv->iobase = dev->iobase + 8;
1116 /* initialize the resource enable register by clearing it */
1117 outb(0, subpriv->iobase + 3);
1118 outb(0, subpriv->iobase + 4 + 3);
1119
1120 ++sdev_no;
1121 port = 0;
1122 asic = 0;
1123 for (; sdev_no < (int)dev->n_subdevices; ++sdev_no) {
1124 int byte_no;
1125
1126 s = dev->subdevices + sdev_no;
1127 s->private = devpriv->sprivs + sdev_no;
1128 s->maxdata = 1;
1129 s->range_table = &range_digital;
1130 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
1131 s->type = COMEDI_SUBD_DIO;
1132 s->insn_bits = pcmmio_dio_insn_bits;
1133 s->insn_config = pcmmio_dio_insn_config;
1134 s->n_chan = min(chans_left, MAX_CHANS_PER_SUBDEV);
1135 subpriv->dio.intr.asic = -1;
1136 subpriv->dio.intr.first_chan = -1;
1137 subpriv->dio.intr.asic_chan = -1;
1138 subpriv->dio.intr.num_asic_chans = -1;
1139 subpriv->dio.intr.active = 0;
1140 s->len_chanlist = 1;
1141
1142 /* save the ioport address for each 'port' of 8 channels in the
1143 subdevice */
1144 for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) {
1145 if (port >= PORTS_PER_ASIC) {
1146 port = 0;
1147 ++asic;
1148 thisasic_chanct = 0;
1149 }
1150 subpriv->iobases[byte_no] =
1151 devpriv->asics[asic].iobase + port;
1152
1153 if (thisasic_chanct <
1154 CHANS_PER_PORT * INTR_PORTS_PER_ASIC
1155 && subpriv->dio.intr.asic < 0) {
1156 /*
1157 * this is an interrupt subdevice,
1158 * so setup the struct
1159 */
1160 subpriv->dio.intr.asic = asic;
1161 subpriv->dio.intr.active = 0;
1162 subpriv->dio.intr.stop_count = 0;
1163 subpriv->dio.intr.first_chan = byte_no * 8;
1164 subpriv->dio.intr.asic_chan = thisasic_chanct;
1165 subpriv->dio.intr.num_asic_chans =
1166 s->n_chan - subpriv->dio.intr.first_chan;
1167 s->cancel = pcmmio_cancel;
1168 s->do_cmd = pcmmio_cmd;
1169 s->do_cmdtest = pcmmio_cmdtest;
1170 s->len_chanlist =
1171 subpriv->dio.intr.num_asic_chans;
1172 }
1173 thisasic_chanct += CHANS_PER_PORT;
1174 }
1175 spin_lock_init(&subpriv->dio.intr.spinlock);
1176
1177 chans_left -= s->n_chan;
1178
1179 if (!chans_left) {
1180 /*
1181 * reset the asic to our first asic,
1182 * to do intr subdevs
1183 */
1184 asic = 0;
1185 port = 0;
1186 }
1187
1188 }
1189
1190 init_asics(dev); /* clear out all the registers, basically */
1191
1192 for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) {
1193 if (irq[asic]
1194 && request_irq(irq[asic], interrupt_pcmmio,
1195 IRQF_SHARED, thisboard->name, dev)) {
1196 int i;
1197 /* unroll the allocated irqs.. */
1198 for (i = asic - 1; i >= 0; --i) {
1199 free_irq(irq[i], dev);
1200 devpriv->asics[i].irq = irq[i] = 0;
1201 }
1202 irq[asic] = 0;
1203 }
1204 devpriv->asics[asic].irq = irq[asic];
1205 }
1206
1207 dev->irq = irq[0]; /*
1208 * grr.. wish comedi dev struct supported
1209 * multiple irqs..
1210 */
1211
1212 if (irq[0]) {
1213 printk(KERN_DEBUG "comedi%d: irq: %u\n", dev->minor, irq[0]);
1214 if (thisboard->dio_num_asics == 2 && irq[1])
1215 printk(KERN_DEBUG "comedi%d: second ASIC irq: %u\n",
1216 dev->minor, irq[1]);
1217 } else {
1218 printk(KERN_INFO "comedi%d: (IRQ mode disabled)\n", dev->minor);
1219 }
1220
1221 printk(KERN_INFO "comedi%d: attached\n", dev->minor);
1222
1223 return 1;
1350} 1224}
1351 1225
1352static void __exit driver_cleanup_module(void) 1226static void pcmmio_detach(struct comedi_device *dev)
1353{ 1227{
1354 comedi_driver_unregister(&driver); 1228 int i;
1229
1230 if (dev->iobase)
1231 release_region(dev->iobase, thisboard->total_iosize);
1232 for (i = 0; i < MAX_ASICS; ++i) {
1233 if (devpriv && devpriv->asics[i].irq)
1234 free_irq(devpriv->asics[i].irq, dev);
1235 }
1236 if (devpriv && devpriv->sprivs)
1237 kfree(devpriv->sprivs);
1355} 1238}
1356 1239
1357module_init(driver_init_module); 1240static const struct pcmmio_board pcmmio_boards[] = {
1358module_exit(driver_cleanup_module); 1241 {
1242 .name = "pcmmio",
1243 .dio_num_asics = 1,
1244 .dio_num_ports = 6,
1245 .total_iosize = 32,
1246 .ai_bits = 16,
1247 .ao_bits = 16,
1248 .n_ai_chans = 16,
1249 .n_ao_chans = 8,
1250 .ai_range_table = &ranges_ai,
1251 .ao_range_table = &ranges_ao,
1252 .ai_rinsn = ai_rinsn,
1253 .ao_rinsn = ao_rinsn,
1254 .ao_winsn = ao_winsn
1255 },
1256};
1257
1258static struct comedi_driver pcmmio_driver = {
1259 .driver_name = "pcmmio",
1260 .module = THIS_MODULE,
1261 .attach = pcmmio_attach,
1262 .detach = pcmmio_detach,
1263 .board_name = &pcmmio_boards[0].name,
1264 .offset = sizeof(struct pcmmio_board),
1265 .num_names = ARRAY_SIZE(pcmmio_boards),
1266};
1267module_comedi_driver(pcmmio_driver);
1359 1268
1360MODULE_AUTHOR("Comedi http://www.comedi.org"); 1269MODULE_AUTHOR("Comedi http://www.comedi.org");
1361MODULE_DESCRIPTION("Comedi low-level driver"); 1270MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index 661ba2e03892..623381d50dac 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -155,19 +155,6 @@ struct pcmuio_board {
155 const int num_ports; 155 const int num_ports;
156}; 156};
157 157
158static const struct pcmuio_board pcmuio_boards[] = {
159 {
160 .name = "pcmuio48",
161 .num_asics = 1,
162 .num_ports = 6,
163 },
164 {
165 .name = "pcmuio96",
166 .num_asics = 2,
167 .num_ports = 12,
168 },
169};
170
171/* 158/*
172 * Useful for shorthand access to the particular board structure 159 * Useful for shorthand access to the particular board structure
173 */ 160 */
@@ -218,262 +205,6 @@ struct pcmuio_private {
218 */ 205 */
219#define devpriv ((struct pcmuio_private *)dev->private) 206#define devpriv ((struct pcmuio_private *)dev->private)
220#define subpriv ((struct pcmuio_subdev_private *)s->private) 207#define subpriv ((struct pcmuio_subdev_private *)s->private)
221/*
222 * The struct comedi_driver structure tells the Comedi core module
223 * which functions to call to configure/deconfigure (attach/detach)
224 * the board, and also about the kernel module that contains
225 * the device code.
226 */
227static int pcmuio_attach(struct comedi_device *dev,
228 struct comedi_devconfig *it);
229static int pcmuio_detach(struct comedi_device *dev);
230
231static struct comedi_driver driver = {
232 .driver_name = "pcmuio",
233 .module = THIS_MODULE,
234 .attach = pcmuio_attach,
235 .detach = pcmuio_detach,
236/* It is not necessary to implement the following members if you are
237 * writing a driver for a ISA PnP or PCI card */
238 /* Most drivers will support multiple types of boards by
239 * having an array of board structures. These were defined
240 * in pcmuio_boards[] above. Note that the element 'name'
241 * was first in the structure -- Comedi uses this fact to
242 * extract the name of the board without knowing any details
243 * about the structure except for its length.
244 * When a device is attached (by comedi_config), the name
245 * of the device is given to Comedi, and Comedi tries to
246 * match it by going through the list of board names. If
247 * there is a match, the address of the pointer is put
248 * into dev->board_ptr and driver->attach() is called.
249 *
250 * Note that these are not necessary if you can determine
251 * the type of board in software. ISA PnP, PCI, and PCMCIA
252 * devices are such boards.
253 */
254 .board_name = &pcmuio_boards[0].name,
255 .offset = sizeof(struct pcmuio_board),
256 .num_names = ARRAY_SIZE(pcmuio_boards),
257};
258
259static int pcmuio_dio_insn_bits(struct comedi_device *dev,
260 struct comedi_subdevice *s,
261 struct comedi_insn *insn, unsigned int *data);
262static int pcmuio_dio_insn_config(struct comedi_device *dev,
263 struct comedi_subdevice *s,
264 struct comedi_insn *insn, unsigned int *data);
265
266static irqreturn_t interrupt_pcmuio(int irq, void *d);
267static void pcmuio_stop_intr(struct comedi_device *, struct comedi_subdevice *);
268static int pcmuio_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
269static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
270static int pcmuio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
271 struct comedi_cmd *cmd);
272
273/* some helper functions to deal with specifics of this device's registers */
274static void init_asics(struct comedi_device *dev); /* sets up/clears ASIC chips to defaults */
275static void switch_page(struct comedi_device *dev, int asic, int page);
276#ifdef notused
277static void lock_port(struct comedi_device *dev, int asic, int port);
278static void unlock_port(struct comedi_device *dev, int asic, int port);
279#endif
280
281/*
282 * Attach is called by the Comedi core to configure the driver
283 * for a particular board. If you specified a board_name array
284 * in the driver structure, dev->board_ptr contains that
285 * address.
286 */
287static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
288{
289 struct comedi_subdevice *s;
290 int sdev_no, chans_left, n_subdevs, port, asic, thisasic_chanct = 0;
291 unsigned long iobase;
292 unsigned int irq[MAX_ASICS];
293
294 iobase = it->options[0];
295 irq[0] = it->options[1];
296 irq[1] = it->options[2];
297
298 dev_dbg(dev->hw_dev, "comedi%d: %s: io: %lx attached\n", dev->minor,
299 driver.driver_name, iobase);
300
301 dev->iobase = iobase;
302
303 if (!iobase || !request_region(iobase,
304 thisboard->num_asics * ASIC_IOSIZE,
305 driver.driver_name)) {
306 dev_err(dev->hw_dev, "I/O port conflict\n");
307 return -EIO;
308 }
309
310/*
311 * Initialize dev->board_name. Note that we can use the "thisboard"
312 * macro now, since we just initialized it in the last line.
313 */
314 dev->board_name = thisboard->name;
315
316/*
317 * Allocate the private structure area. alloc_private() is a
318 * convenient macro defined in comedidev.h.
319 */
320 if (alloc_private(dev, sizeof(struct pcmuio_private)) < 0) {
321 dev_warn(dev->hw_dev, "cannot allocate private data structure\n");
322 return -ENOMEM;
323 }
324
325 for (asic = 0; asic < MAX_ASICS; ++asic) {
326 devpriv->asics[asic].num = asic;
327 devpriv->asics[asic].iobase = dev->iobase + asic * ASIC_IOSIZE;
328 devpriv->asics[asic].irq = 0; /* this gets actually set at the end of
329 this function when we
330 request_irqs */
331 spin_lock_init(&devpriv->asics[asic].spinlock);
332 }
333
334 chans_left = CHANS_PER_ASIC * thisboard->num_asics;
335 n_subdevs = CALC_N_SUBDEVS(chans_left);
336 devpriv->sprivs =
337 kcalloc(n_subdevs, sizeof(struct pcmuio_subdev_private),
338 GFP_KERNEL);
339 if (!devpriv->sprivs) {
340 dev_warn(dev->hw_dev, "cannot allocate subdevice private data structures\n");
341 return -ENOMEM;
342 }
343 /*
344 * Allocate the subdevice structures. alloc_subdevice() is a
345 * convenient macro defined in comedidev.h.
346 *
347 * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the
348 * 96-channel version of the board.
349 */
350 if (alloc_subdevices(dev, n_subdevs) < 0) {
351 dev_dbg(dev->hw_dev, "cannot allocate subdevice data structures\n");
352 return -ENOMEM;
353 }
354
355 port = 0;
356 asic = 0;
357 for (sdev_no = 0; sdev_no < (int)dev->n_subdevices; ++sdev_no) {
358 int byte_no;
359
360 s = dev->subdevices + sdev_no;
361 s->private = devpriv->sprivs + sdev_no;
362 s->maxdata = 1;
363 s->range_table = &range_digital;
364 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
365 s->type = COMEDI_SUBD_DIO;
366 s->insn_bits = pcmuio_dio_insn_bits;
367 s->insn_config = pcmuio_dio_insn_config;
368 s->n_chan = min(chans_left, MAX_CHANS_PER_SUBDEV);
369 subpriv->intr.asic = -1;
370 subpriv->intr.first_chan = -1;
371 subpriv->intr.asic_chan = -1;
372 subpriv->intr.num_asic_chans = -1;
373 subpriv->intr.active = 0;
374 s->len_chanlist = 1;
375
376 /* save the ioport address for each 'port' of 8 channels in the
377 subdevice */
378 for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) {
379 if (port >= PORTS_PER_ASIC) {
380 port = 0;
381 ++asic;
382 thisasic_chanct = 0;
383 }
384 subpriv->iobases[byte_no] =
385 devpriv->asics[asic].iobase + port;
386
387 if (thisasic_chanct <
388 CHANS_PER_PORT * INTR_PORTS_PER_ASIC
389 && subpriv->intr.asic < 0) {
390 /* this is an interrupt subdevice, so setup the struct */
391 subpriv->intr.asic = asic;
392 subpriv->intr.active = 0;
393 subpriv->intr.stop_count = 0;
394 subpriv->intr.first_chan = byte_no * 8;
395 subpriv->intr.asic_chan = thisasic_chanct;
396 subpriv->intr.num_asic_chans =
397 s->n_chan - subpriv->intr.first_chan;
398 dev->read_subdev = s;
399 s->subdev_flags |= SDF_CMD_READ;
400 s->cancel = pcmuio_cancel;
401 s->do_cmd = pcmuio_cmd;
402 s->do_cmdtest = pcmuio_cmdtest;
403 s->len_chanlist = subpriv->intr.num_asic_chans;
404 }
405 thisasic_chanct += CHANS_PER_PORT;
406 }
407 spin_lock_init(&subpriv->intr.spinlock);
408
409 chans_left -= s->n_chan;
410
411 if (!chans_left) {
412 asic = 0; /* reset the asic to our first asic, to do intr subdevs */
413 port = 0;
414 }
415
416 }
417
418 init_asics(dev); /* clear out all the registers, basically */
419
420 for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) {
421 if (irq[asic]
422 && request_irq(irq[asic], interrupt_pcmuio,
423 IRQF_SHARED, thisboard->name, dev)) {
424 int i;
425 /* unroll the allocated irqs.. */
426 for (i = asic - 1; i >= 0; --i) {
427 free_irq(irq[i], dev);
428 devpriv->asics[i].irq = irq[i] = 0;
429 }
430 irq[asic] = 0;
431 }
432 devpriv->asics[asic].irq = irq[asic];
433 }
434
435 dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple
436 irqs.. */
437
438 if (irq[0]) {
439 dev_dbg(dev->hw_dev, "irq: %u\n", irq[0]);
440 if (irq[1] && thisboard->num_asics == 2)
441 dev_dbg(dev->hw_dev, "second ASIC irq: %u\n", irq[1]);
442 } else {
443 dev_dbg(dev->hw_dev, "(IRQ mode disabled)\n");
444 }
445
446
447 return 1;
448}
449
450/*
451 * _detach is called to deconfigure a device. It should deallocate
452 * resources.
453 * This function is also called when _attach() fails, so it should be
454 * careful not to release resources that were not necessarily
455 * allocated by _attach(). dev->private and dev->subdevices are
456 * deallocated automatically by the core.
457 */
458static int pcmuio_detach(struct comedi_device *dev)
459{
460 int i;
461
462 dev_dbg(dev->hw_dev, "comedi%d: %s: remove\n", dev->minor,
463 driver.driver_name);
464 if (dev->iobase)
465 release_region(dev->iobase, ASIC_IOSIZE * thisboard->num_asics);
466
467 for (i = 0; i < MAX_ASICS; ++i) {
468 if (devpriv->asics[i].irq)
469 free_irq(devpriv->asics[i].irq, dev);
470 }
471
472 if (devpriv && devpriv->sprivs)
473 kfree(devpriv->sprivs);
474
475 return 0;
476}
477 208
478/* DIO devices are slightly special. Although it is possible to 209/* DIO devices are slightly special. Although it is possible to
479 * implement the insn_read/insn_write interface, it is much more 210 * implement the insn_read/insn_write interface, it is much more
@@ -621,6 +352,21 @@ static int pcmuio_dio_insn_config(struct comedi_device *dev,
621 return insn->n; 352 return insn->n;
622} 353}
623 354
355static void switch_page(struct comedi_device *dev, int asic, int page)
356{
357 if (asic < 0 || asic >= thisboard->num_asics)
358 return; /* paranoia */
359 if (page < 0 || page >= NUM_PAGES)
360 return; /* more paranoia */
361
362 devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK;
363 devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET;
364
365 /* now write out the shadow register */
366 outb(devpriv->asics[asic].pagelock,
367 dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK);
368}
369
624static void init_asics(struct comedi_device *dev) 370static void init_asics(struct comedi_device *dev)
625{ /* sets up an 371{ /* sets up an
626 ASIC chip to defaults */ 372 ASIC chip to defaults */
@@ -658,21 +404,6 @@ static void init_asics(struct comedi_device *dev)
658 } 404 }
659} 405}
660 406
661static void switch_page(struct comedi_device *dev, int asic, int page)
662{
663 if (asic < 0 || asic >= thisboard->num_asics)
664 return; /* paranoia */
665 if (page < 0 || page >= NUM_PAGES)
666 return; /* more paranoia */
667
668 devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK;
669 devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET;
670
671 /* now write out the shadow register */
672 outb(devpriv->asics[asic].pagelock,
673 dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK);
674}
675
676#ifdef notused 407#ifdef notused
677static void lock_port(struct comedi_device *dev, int asic, int port) 408static void lock_port(struct comedi_device *dev, int asic, int port)
678{ 409{
@@ -700,6 +431,27 @@ static void unlock_port(struct comedi_device *dev, int asic, int port)
700} 431}
701#endif /* notused */ 432#endif /* notused */
702 433
434static void pcmuio_stop_intr(struct comedi_device *dev,
435 struct comedi_subdevice *s)
436{
437 int nports, firstport, asic, port;
438
439 asic = subpriv->intr.asic;
440 if (asic < 0)
441 return; /* not an interrupt subdev */
442
443 subpriv->intr.enabled_mask = 0;
444 subpriv->intr.active = 0;
445 s->async->inttrig = 0;
446 nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT;
447 firstport = subpriv->intr.asic_chan / CHANS_PER_PORT;
448 switch_page(dev, asic, PAGE_ENAB);
449 for (port = firstport; port < firstport + nports; ++port) {
450 /* disable all intrs for this subdev.. */
451 outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port);
452 }
453}
454
703static irqreturn_t interrupt_pcmuio(int irq, void *d) 455static irqreturn_t interrupt_pcmuio(int irq, void *d)
704{ 456{
705 int asic, got1 = 0; 457 int asic, got1 = 0;
@@ -852,27 +604,6 @@ static irqreturn_t interrupt_pcmuio(int irq, void *d)
852 return IRQ_HANDLED; 604 return IRQ_HANDLED;
853} 605}
854 606
855static void pcmuio_stop_intr(struct comedi_device *dev,
856 struct comedi_subdevice *s)
857{
858 int nports, firstport, asic, port;
859
860 asic = subpriv->intr.asic;
861 if (asic < 0)
862 return; /* not an interrupt subdev */
863
864 subpriv->intr.enabled_mask = 0;
865 subpriv->intr.active = 0;
866 s->async->inttrig = 0;
867 nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT;
868 firstport = subpriv->intr.asic_chan / CHANS_PER_PORT;
869 switch_page(dev, asic, PAGE_ENAB);
870 for (port = firstport; port < firstport + nports; ++port) {
871 /* disable all intrs for this subdev.. */
872 outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port);
873 }
874}
875
876static int pcmuio_start_intr(struct comedi_device *dev, 607static int pcmuio_start_intr(struct comedi_device *dev,
877 struct comedi_subdevice *s) 608 struct comedi_subdevice *s)
878{ 609{
@@ -1014,22 +745,205 @@ pcmuio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
1014 return comedi_pcm_cmdtest(dev, s, cmd); 745 return comedi_pcm_cmdtest(dev, s, cmd);
1015} 746}
1016 747
748static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
749{
750 struct comedi_subdevice *s;
751 int sdev_no, chans_left, n_subdevs, port, asic, thisasic_chanct = 0;
752 unsigned long iobase;
753 unsigned int irq[MAX_ASICS];
754
755 iobase = it->options[0];
756 irq[0] = it->options[1];
757 irq[1] = it->options[2];
758
759 dev_dbg(dev->hw_dev, "comedi%d: %s: io: %lx attached\n", dev->minor,
760 dev->driver->driver_name, iobase);
761
762 dev->iobase = iobase;
763
764 if (!iobase || !request_region(iobase,
765 thisboard->num_asics * ASIC_IOSIZE,
766 dev->driver->driver_name)) {
767 dev_err(dev->hw_dev, "I/O port conflict\n");
768 return -EIO;
769 }
770
1017/* 771/*
1018 * A convenient macro that defines init_module() and cleanup_module(), 772 * Initialize dev->board_name. Note that we can use the "thisboard"
1019 * as necessary. 773 * macro now, since we just initialized it in the last line.
1020 */ 774 */
1021static int __init driver_init_module(void) 775 dev->board_name = thisboard->name;
1022{ 776
1023 return comedi_driver_register(&driver); 777/*
778 * Allocate the private structure area. alloc_private() is a
779 * convenient macro defined in comedidev.h.
780 */
781 if (alloc_private(dev, sizeof(struct pcmuio_private)) < 0) {
782 dev_warn(dev->hw_dev, "cannot allocate private data structure\n");
783 return -ENOMEM;
784 }
785
786 for (asic = 0; asic < MAX_ASICS; ++asic) {
787 devpriv->asics[asic].num = asic;
788 devpriv->asics[asic].iobase = dev->iobase + asic * ASIC_IOSIZE;
789 devpriv->asics[asic].irq = 0; /* this gets actually set at the end of
790 this function when we
791 request_irqs */
792 spin_lock_init(&devpriv->asics[asic].spinlock);
793 }
794
795 chans_left = CHANS_PER_ASIC * thisboard->num_asics;
796 n_subdevs = CALC_N_SUBDEVS(chans_left);
797 devpriv->sprivs =
798 kcalloc(n_subdevs, sizeof(struct pcmuio_subdev_private),
799 GFP_KERNEL);
800 if (!devpriv->sprivs) {
801 dev_warn(dev->hw_dev, "cannot allocate subdevice private data structures\n");
802 return -ENOMEM;
803 }
804 /*
805 * Allocate the subdevice structures. alloc_subdevice() is a
806 * convenient macro defined in comedidev.h.
807 *
808 * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the
809 * 96-channel version of the board.
810 */
811 if (alloc_subdevices(dev, n_subdevs) < 0) {
812 dev_dbg(dev->hw_dev, "cannot allocate subdevice data structures\n");
813 return -ENOMEM;
814 }
815
816 port = 0;
817 asic = 0;
818 for (sdev_no = 0; sdev_no < (int)dev->n_subdevices; ++sdev_no) {
819 int byte_no;
820
821 s = dev->subdevices + sdev_no;
822 s->private = devpriv->sprivs + sdev_no;
823 s->maxdata = 1;
824 s->range_table = &range_digital;
825 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
826 s->type = COMEDI_SUBD_DIO;
827 s->insn_bits = pcmuio_dio_insn_bits;
828 s->insn_config = pcmuio_dio_insn_config;
829 s->n_chan = min(chans_left, MAX_CHANS_PER_SUBDEV);
830 subpriv->intr.asic = -1;
831 subpriv->intr.first_chan = -1;
832 subpriv->intr.asic_chan = -1;
833 subpriv->intr.num_asic_chans = -1;
834 subpriv->intr.active = 0;
835 s->len_chanlist = 1;
836
837 /* save the ioport address for each 'port' of 8 channels in the
838 subdevice */
839 for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) {
840 if (port >= PORTS_PER_ASIC) {
841 port = 0;
842 ++asic;
843 thisasic_chanct = 0;
844 }
845 subpriv->iobases[byte_no] =
846 devpriv->asics[asic].iobase + port;
847
848 if (thisasic_chanct <
849 CHANS_PER_PORT * INTR_PORTS_PER_ASIC
850 && subpriv->intr.asic < 0) {
851 /* this is an interrupt subdevice, so setup the struct */
852 subpriv->intr.asic = asic;
853 subpriv->intr.active = 0;
854 subpriv->intr.stop_count = 0;
855 subpriv->intr.first_chan = byte_no * 8;
856 subpriv->intr.asic_chan = thisasic_chanct;
857 subpriv->intr.num_asic_chans =
858 s->n_chan - subpriv->intr.first_chan;
859 dev->read_subdev = s;
860 s->subdev_flags |= SDF_CMD_READ;
861 s->cancel = pcmuio_cancel;
862 s->do_cmd = pcmuio_cmd;
863 s->do_cmdtest = pcmuio_cmdtest;
864 s->len_chanlist = subpriv->intr.num_asic_chans;
865 }
866 thisasic_chanct += CHANS_PER_PORT;
867 }
868 spin_lock_init(&subpriv->intr.spinlock);
869
870 chans_left -= s->n_chan;
871
872 if (!chans_left) {
873 asic = 0; /* reset the asic to our first asic, to do intr subdevs */
874 port = 0;
875 }
876
877 }
878
879 init_asics(dev); /* clear out all the registers, basically */
880
881 for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) {
882 if (irq[asic]
883 && request_irq(irq[asic], interrupt_pcmuio,
884 IRQF_SHARED, thisboard->name, dev)) {
885 int i;
886 /* unroll the allocated irqs.. */
887 for (i = asic - 1; i >= 0; --i) {
888 free_irq(irq[i], dev);
889 devpriv->asics[i].irq = irq[i] = 0;
890 }
891 irq[asic] = 0;
892 }
893 devpriv->asics[asic].irq = irq[asic];
894 }
895
896 dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple
897 irqs.. */
898
899 if (irq[0]) {
900 dev_dbg(dev->hw_dev, "irq: %u\n", irq[0]);
901 if (irq[1] && thisboard->num_asics == 2)
902 dev_dbg(dev->hw_dev, "second ASIC irq: %u\n", irq[1]);
903 } else {
904 dev_dbg(dev->hw_dev, "(IRQ mode disabled)\n");
905 }
906
907
908 return 1;
1024} 909}
1025 910
1026static void __exit driver_cleanup_module(void) 911static void pcmuio_detach(struct comedi_device *dev)
1027{ 912{
1028 comedi_driver_unregister(&driver); 913 int i;
914
915 if (dev->iobase)
916 release_region(dev->iobase, ASIC_IOSIZE * thisboard->num_asics);
917 for (i = 0; i < MAX_ASICS; ++i) {
918 if (devpriv->asics[i].irq)
919 free_irq(devpriv->asics[i].irq, dev);
920 }
921 if (devpriv && devpriv->sprivs)
922 kfree(devpriv->sprivs);
1029} 923}
1030 924
1031module_init(driver_init_module); 925static const struct pcmuio_board pcmuio_boards[] = {
1032module_exit(driver_cleanup_module); 926 {
927 .name = "pcmuio48",
928 .num_asics = 1,
929 .num_ports = 6,
930 }, {
931 .name = "pcmuio96",
932 .num_asics = 2,
933 .num_ports = 12,
934 },
935};
936
937static struct comedi_driver pcmuio_driver = {
938 .driver_name = "pcmuio",
939 .module = THIS_MODULE,
940 .attach = pcmuio_attach,
941 .detach = pcmuio_detach,
942 .board_name = &pcmuio_boards[0].name,
943 .offset = sizeof(struct pcmuio_board),
944 .num_names = ARRAY_SIZE(pcmuio_boards),
945};
946module_comedi_driver(pcmuio_driver);
1033 947
1034MODULE_AUTHOR("Comedi http://www.comedi.org"); 948MODULE_AUTHOR("Comedi http://www.comedi.org");
1035MODULE_DESCRIPTION("Comedi low-level driver"); 949MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/poc.c b/drivers/staging/comedi/drivers/poc.c
index 831a576c24aa..e7120480687b 100644
--- a/drivers/staging/comedi/drivers/poc.c
+++ b/drivers/staging/comedi/drivers/poc.c
@@ -41,20 +41,6 @@ Configuration options:
41 41
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43 43
44static int poc_attach(struct comedi_device *dev, struct comedi_devconfig *it);
45static int poc_detach(struct comedi_device *dev);
46static int readback_insn(struct comedi_device *dev, struct comedi_subdevice *s,
47 struct comedi_insn *insn, unsigned int *data);
48
49static int dac02_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
50 struct comedi_insn *insn, unsigned int *data);
51static int pcl733_insn_bits(struct comedi_device *dev,
52 struct comedi_subdevice *s,
53 struct comedi_insn *insn, unsigned int *data);
54static int pcl734_insn_bits(struct comedi_device *dev,
55 struct comedi_subdevice *s,
56 struct comedi_insn *insn, unsigned int *data);
57
58struct boarddef_struct { 44struct boarddef_struct {
59 const char *name; 45 const char *name;
60 unsigned int iosize; 46 unsigned int iosize;
@@ -70,108 +56,9 @@ struct boarddef_struct {
70 struct comedi_insn *, unsigned int *); 56 struct comedi_insn *, unsigned int *);
71 const struct comedi_lrange *range; 57 const struct comedi_lrange *range;
72}; 58};
73static const struct boarddef_struct boards[] = {
74 {
75 .name = "dac02",
76 .iosize = 8,
77 /* .setup = dac02_setup, */
78 .type = COMEDI_SUBD_AO,
79 .n_chan = 2,
80 .n_bits = 12,
81 .winsn = dac02_ao_winsn,
82 .rinsn = readback_insn,
83 .range = &range_unknown,
84 },
85 {
86 .name = "pcl733",
87 .iosize = 4,
88 .type = COMEDI_SUBD_DI,
89 .n_chan = 32,
90 .n_bits = 1,
91 .insnbits = pcl733_insn_bits,
92 .range = &range_digital,
93 },
94 {
95 .name = "pcl734",
96 .iosize = 4,
97 .type = COMEDI_SUBD_DO,
98 .n_chan = 32,
99 .n_bits = 1,
100 .insnbits = pcl734_insn_bits,
101 .range = &range_digital,
102 },
103};
104 59
105#define n_boards ARRAY_SIZE(boards)
106#define this_board ((const struct boarddef_struct *)dev->board_ptr) 60#define this_board ((const struct boarddef_struct *)dev->board_ptr)
107 61
108static struct comedi_driver driver_poc = {
109 .driver_name = "poc",
110 .module = THIS_MODULE,
111 .attach = poc_attach,
112 .detach = poc_detach,
113 .board_name = &boards[0].name,
114 .num_names = n_boards,
115 .offset = sizeof(boards[0]),
116};
117
118static int poc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
119{
120 struct comedi_subdevice *s;
121 unsigned long iobase;
122 unsigned int iosize;
123
124 iobase = it->options[0];
125 printk(KERN_INFO "comedi%d: poc: using %s iobase 0x%lx\n", dev->minor,
126 this_board->name, iobase);
127
128 dev->board_name = this_board->name;
129
130 if (iobase == 0) {
131 printk(KERN_ERR "io base address required\n");
132 return -EINVAL;
133 }
134
135 iosize = this_board->iosize;
136 /* check if io addresses are available */
137 if (!request_region(iobase, iosize, "dac02")) {
138 printk(KERN_ERR "I/O port conflict: failed to allocate ports "
139 "0x%lx to 0x%lx\n", iobase, iobase + iosize - 1);
140 return -EIO;
141 }
142 dev->iobase = iobase;
143
144 if (alloc_subdevices(dev, 1) < 0)
145 return -ENOMEM;
146 if (alloc_private(dev, sizeof(unsigned int) * this_board->n_chan) < 0)
147 return -ENOMEM;
148
149 /* analog output subdevice */
150 s = dev->subdevices + 0;
151 s->type = this_board->type;
152 s->n_chan = this_board->n_chan;
153 s->maxdata = (1 << this_board->n_bits) - 1;
154 s->range_table = this_board->range;
155 s->insn_write = this_board->winsn;
156 s->insn_read = this_board->rinsn;
157 s->insn_bits = this_board->insnbits;
158 if (s->type == COMEDI_SUBD_AO || s->type == COMEDI_SUBD_DO)
159 s->subdev_flags = SDF_WRITABLE;
160
161 return 0;
162}
163
164static int poc_detach(struct comedi_device *dev)
165{
166 /* only free stuff if it has been allocated by _attach */
167 if (dev->iobase)
168 release_region(dev->iobase, this_board->iosize);
169
170 printk(KERN_INFO "comedi%d: dac02: remove\n", dev->minor);
171
172 return 0;
173}
174
175static int readback_insn(struct comedi_device *dev, struct comedi_subdevice *s, 62static int readback_insn(struct comedi_device *dev, struct comedi_subdevice *s,
176 struct comedi_insn *insn, unsigned int *data) 63 struct comedi_insn *insn, unsigned int *data)
177{ 64{
@@ -248,18 +135,98 @@ static int pcl734_insn_bits(struct comedi_device *dev,
248 return 2; 135 return 2;
249} 136}
250 137
251static int __init driver_poc_init_module(void) 138static int poc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
252{ 139{
253 return comedi_driver_register(&driver_poc); 140 struct comedi_subdevice *s;
141 unsigned long iobase;
142 unsigned int iosize;
143
144 iobase = it->options[0];
145 printk(KERN_INFO "comedi%d: poc: using %s iobase 0x%lx\n", dev->minor,
146 this_board->name, iobase);
147
148 dev->board_name = this_board->name;
149
150 if (iobase == 0) {
151 printk(KERN_ERR "io base address required\n");
152 return -EINVAL;
153 }
154
155 iosize = this_board->iosize;
156 /* check if io addresses are available */
157 if (!request_region(iobase, iosize, "dac02")) {
158 printk(KERN_ERR "I/O port conflict: failed to allocate ports "
159 "0x%lx to 0x%lx\n", iobase, iobase + iosize - 1);
160 return -EIO;
161 }
162 dev->iobase = iobase;
163
164 if (alloc_subdevices(dev, 1) < 0)
165 return -ENOMEM;
166 if (alloc_private(dev, sizeof(unsigned int) * this_board->n_chan) < 0)
167 return -ENOMEM;
168
169 /* analog output subdevice */
170 s = dev->subdevices + 0;
171 s->type = this_board->type;
172 s->n_chan = this_board->n_chan;
173 s->maxdata = (1 << this_board->n_bits) - 1;
174 s->range_table = this_board->range;
175 s->insn_write = this_board->winsn;
176 s->insn_read = this_board->rinsn;
177 s->insn_bits = this_board->insnbits;
178 if (s->type == COMEDI_SUBD_AO || s->type == COMEDI_SUBD_DO)
179 s->subdev_flags = SDF_WRITABLE;
180
181 return 0;
254} 182}
255 183
256static void __exit driver_poc_cleanup_module(void) 184static void poc_detach(struct comedi_device *dev)
257{ 185{
258 comedi_driver_unregister(&driver_poc); 186 if (dev->iobase)
187 release_region(dev->iobase, this_board->iosize);
259} 188}
260 189
261module_init(driver_poc_init_module); 190static const struct boarddef_struct boards[] = {
262module_exit(driver_poc_cleanup_module); 191 {
192 .name = "dac02",
193 .iosize = 8,
194 /* .setup = dac02_setup, */
195 .type = COMEDI_SUBD_AO,
196 .n_chan = 2,
197 .n_bits = 12,
198 .winsn = dac02_ao_winsn,
199 .rinsn = readback_insn,
200 .range = &range_unknown,
201 }, {
202 .name = "pcl733",
203 .iosize = 4,
204 .type = COMEDI_SUBD_DI,
205 .n_chan = 32,
206 .n_bits = 1,
207 .insnbits = pcl733_insn_bits,
208 .range = &range_digital,
209 }, {
210 .name = "pcl734",
211 .iosize = 4,
212 .type = COMEDI_SUBD_DO,
213 .n_chan = 32,
214 .n_bits = 1,
215 .insnbits = pcl734_insn_bits,
216 .range = &range_digital,
217 },
218};
219
220static struct comedi_driver poc_driver = {
221 .driver_name = "poc",
222 .module = THIS_MODULE,
223 .attach = poc_attach,
224 .detach = poc_detach,
225 .board_name = &boards[0].name,
226 .num_names = ARRAY_SIZE(boards),
227 .offset = sizeof(boards[0]),
228};
229module_comedi_driver(poc_driver);
263 230
264MODULE_AUTHOR("Comedi http://www.comedi.org"); 231MODULE_AUTHOR("Comedi http://www.comedi.org");
265MODULE_DESCRIPTION("Comedi low-level driver"); 232MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index e0bb73445dd8..2f130b3095e9 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -181,7 +181,7 @@ static const struct comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} };
181/* comedi interface code */ 181/* comedi interface code */
182 182
183static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it); 183static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it);
184static int daqp_detach(struct comedi_device *dev); 184static void daqp_detach(struct comedi_device *dev);
185static struct comedi_driver driver_daqp = { 185static struct comedi_driver driver_daqp = {
186 .driver_name = "quatech_daqp_cs", 186 .driver_name = "quatech_daqp_cs",
187 .module = THIS_MODULE, 187 .module = THIS_MODULE,
@@ -922,15 +922,9 @@ static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it)
922 return 1; 922 return 1;
923} 923}
924 924
925/* daqp_detach (called from comedi_comdig) does nothing. If the PCMCIA 925static void daqp_detach(struct comedi_device *dev)
926 * card is removed, daqp_cs_detach() is called by the pcmcia subsystem.
927 */
928
929static int daqp_detach(struct comedi_device *dev)
930{ 926{
931 printk(KERN_INFO "comedi%d: detaching daqp\n", dev->minor); 927 /* Nothing to cleanup */
932
933 return 0;
934} 928}
935 929
936/*==================================================================== 930/*====================================================================
@@ -1010,8 +1004,6 @@ static void daqp_cs_detach(struct pcmcia_device *link)
1010{ 1004{
1011 struct local_info_t *dev = link->priv; 1005 struct local_info_t *dev = link->priv;
1012 1006
1013 dev_dbg(&link->dev, "daqp_cs_detach\n");
1014
1015 dev->stop = 1; 1007 dev->stop = 1;
1016 daqp_cs_release(link); 1008 daqp_cs_release(link);
1017 1009
@@ -1019,7 +1011,7 @@ static void daqp_cs_detach(struct pcmcia_device *link)
1019 dev_table[dev->table_index] = NULL; 1011 dev_table[dev->table_index] = NULL;
1020 kfree(dev); 1012 kfree(dev);
1021 1013
1022} /* daqp_cs_detach */ 1014}
1023 1015
1024static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) 1016static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
1025{ 1017{
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 138441960506..1678a0ccb8c1 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -328,14 +328,6 @@ static const struct rtdBoard rtd520Boards[] = {
328 }, 328 },
329}; 329};
330 330
331static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = {
332 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) },
333 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) },
334 { 0 }
335};
336
337MODULE_DEVICE_TABLE(pci, rtd520_pci_table);
338
339/* 331/*
340 * Useful for shorthand access to the particular board structure 332 * Useful for shorthand access to the particular board structure
341 */ 333 */
@@ -347,13 +339,13 @@ MODULE_DEVICE_TABLE(pci, rtd520_pci_table);
347*/ 339*/
348struct rtdPrivate { 340struct rtdPrivate {
349 /* memory mapped board structures */ 341 /* memory mapped board structures */
350 void *las0; 342 void __iomem *las0;
351 void *las1; 343 void __iomem *las1;
352 void *lcfg; 344 void __iomem *lcfg;
353 345
354 unsigned long intCount; /* interrupt count */ 346 unsigned long intCount; /* interrupt count */
355 long aiCount; /* total transfer size (samples) */ 347 long aiCount; /* total transfer size (samples) */
356 int transCount; /* # to tranfer data. 0->1/2FIFO */ 348 int transCount; /* # to transfer data. 0->1/2FIFO */
357 int flags; /* flag event modes */ 349 int flags; /* flag event modes */
358 350
359 /* PCI device info */ 351 /* PCI device info */
@@ -377,8 +369,11 @@ struct rtdPrivate {
377 u8 utcCtrl[4]; /* crtl mode for 3 utc + read back */ 369 u8 utcCtrl[4]; /* crtl mode for 3 utc + read back */
378 u8 dioStatus; /* could be read back (dio0Ctrl) */ 370 u8 dioStatus; /* could be read back (dio0Ctrl) */
379#ifdef USE_DMA 371#ifdef USE_DMA
380 /* Always DMA 1/2 FIFO. Buffer (dmaBuff?) is (at least) twice that size. 372 /*
381 After transferring, interrupt processes 1/2 FIFO and passes to comedi */ 373 * Always DMA 1/2 FIFO. Buffer (dmaBuff?) is (at least) twice that
374 * size. After transferring, interrupt processes 1/2 FIFO and
375 * passes to comedi
376 */
382 s16 dma0Offset; /* current processing offset (0, 1/2) */ 377 s16 dma0Offset; /* current processing offset (0, 1/2) */
383 uint16_t *dma0Buff[DMA_CHAIN_COUNT]; /* DMA buffers (for ADC) */ 378 uint16_t *dma0Buff[DMA_CHAIN_COUNT]; /* DMA buffers (for ADC) */
384 dma_addr_t dma0BuffPhysAddr[DMA_CHAIN_COUNT]; /* physical addresses */ 379 dma_addr_t dma0BuffPhysAddr[DMA_CHAIN_COUNT]; /* physical addresses */
@@ -581,7 +576,8 @@ struct rtdPrivate {
581 576
582/* User output N source select (write only) */ 577/* User output N source select (write only) */
583#define RtdUsrOutSource(dev, n, v) \ 578#define RtdUsrOutSource(dev, n, v) \
584 writel(v, devpriv->las0+((n <= 0) ? LAS0_UOUT0_SELECT : LAS0_UOUT1_SELECT)) 579 writel(v, devpriv->las0+((n <= 0) ? LAS0_UOUT0_SELECT : \
580 LAS0_UOUT1_SELECT))
585 581
586/* Digital IO */ 582/* Digital IO */
587#define RtdDio0Read(dev) \ 583#define RtdDio0Read(dev) \
@@ -608,7 +604,8 @@ struct rtdPrivate {
608/* Write one data value (sign + 12bit + marker bits) */ 604/* Write one data value (sign + 12bit + marker bits) */
609/* Note: matches what DMA would put. Actual value << 3 */ 605/* Note: matches what DMA would put. Actual value << 3 */
610#define RtdDacFifoPut(dev, n, v) \ 606#define RtdDacFifoPut(dev, n, v) \
611 writew((v), devpriv->las1 + (((n) == 0) ? LAS1_DAC1_FIFO : LAS1_DAC2_FIFO)) 607 writew((v), devpriv->las1 + (((n) == 0) ? LAS1_DAC1_FIFO : \
608 LAS1_DAC2_FIFO))
612 609
613/* Start single DAC conversion */ 610/* Start single DAC conversion */
614#define RtdDacUpdate(dev, n) \ 611#define RtdDacUpdate(dev, n) \
@@ -625,7 +622,8 @@ struct rtdPrivate {
625 622
626/* Reset DAC FIFO */ 623/* Reset DAC FIFO */
627#define RtdDacClearFifo(dev, n) \ 624#define RtdDacClearFifo(dev, n) \
628 writel(0, devpriv->las0+(((n) == 0) ? LAS0_DAC1_RESET : LAS0_DAC2_RESET)) 625 writel(0, devpriv->las0+(((n) == 0) ? LAS0_DAC1_RESET : \
626 LAS0_DAC2_RESET))
629 627
630/* Set source for DMA 0 (write only, shadow?) */ 628/* Set source for DMA 0 (write only, shadow?) */
631#define RtdDma0Source(dev, n) \ 629#define RtdDma0Source(dev, n) \
@@ -705,22 +703,6 @@ struct rtdPrivate {
705#define RtdDma1Status(dev) \ 703#define RtdDma1Status(dev) \
706 readb(devpriv->lcfg+LCFG_DMACSR1) 704 readb(devpriv->lcfg+LCFG_DMACSR1)
707 705
708/*
709 * The struct comedi_driver structure tells the Comedi core module
710 * which functions to call to configure/deconfigure (attac/detach)
711 * the board, and also about the kernel module that contains
712 * the device code.
713 */
714static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it);
715static int rtd_detach(struct comedi_device *dev);
716
717static struct comedi_driver rtd520Driver = {
718 .driver_name = DRV_NAME,
719 .module = THIS_MODULE,
720 .attach = rtd_attach,
721 .detach = rtd_detach,
722};
723
724static int rtd_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, 706static int rtd_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
725 struct comedi_insn *insn, unsigned int *data); 707 struct comedi_insn *insn, unsigned int *data);
726static int rtd_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, 708static int rtd_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -737,7 +719,10 @@ static int rtd_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
737 struct comedi_cmd *cmd); 719 struct comedi_cmd *cmd);
738static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s); 720static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
739static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s); 721static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
740/* static int rtd_ai_poll (struct comedi_device *dev,struct comedi_subdevice *s); */ 722/*
723 * static int rtd_ai_poll(struct comedi_device *dev,
724 * struct comedi_subdevice *s);
725 */
741static int rtd_ns_to_timer(unsigned int *ns, int roundMode); 726static int rtd_ns_to_timer(unsigned int *ns, int roundMode);
742static irqreturn_t rtd_interrupt(int irq, void *d); 727static irqreturn_t rtd_interrupt(int irq, void *d);
743static int rtd520_probe_fifo_depth(struct comedi_device *dev); 728static int rtd520_probe_fifo_depth(struct comedi_device *dev);
@@ -857,7 +842,9 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
857 DPRINTK("rtd520: PCI latency = %d\n", pci_latency); 842 DPRINTK("rtd520: PCI latency = %d\n", pci_latency);
858 } 843 }
859 844
860 /* Undocumented EPLD version (doesn't match RTD driver results) */ 845 /*
846 * Undocumented EPLD version (doesn't match RTD driver results)
847 */
861 /*DPRINTK ("rtd520: Reading epld from %p\n", 848 /*DPRINTK ("rtd520: Reading epld from %p\n",
862 devpriv->las0+0); 849 devpriv->las0+0);
863 epld_version = readl (devpriv->las0+0); 850 epld_version = readl (devpriv->las0+0);
@@ -970,9 +957,11 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
970#ifdef USE_DMA 957#ifdef USE_DMA
971 if (dev->irq > 0) { 958 if (dev->irq > 0) {
972 printk("( DMA buff=%d )\n", DMA_CHAIN_COUNT); 959 printk("( DMA buff=%d )\n", DMA_CHAIN_COUNT);
973 /* The PLX9080 has 2 DMA controllers, but there could be 4 sources: 960 /*
974 ADC, digital, DAC1, and DAC2. Since only the ADC supports cmd mode 961 * The PLX9080 has 2 DMA controllers, but there could be
975 right now, this isn't an issue (yet) */ 962 * 4 sources: ADC, digital, DAC1, and DAC2. Since only the
963 * ADC supports cmd mode right now, this isn't an issue (yet)
964 */
976 devpriv->dma0Offset = 0; 965 devpriv->dma0Offset = 0;
977 966
978 for (index = 0; index < DMA_CHAIN_COUNT; index++) { 967 for (index = 0; index < DMA_CHAIN_COUNT; index++) {
@@ -988,10 +977,14 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
988 } 977 }
989 /*DPRINTK ("buff[%d] @ %p virtual, %x PCI\n", 978 /*DPRINTK ("buff[%d] @ %p virtual, %x PCI\n",
990 index, 979 index,
991 devpriv->dma0Buff[index], devpriv->dma0BuffPhysAddr[index]); */ 980 devpriv->dma0Buff[index],
981 devpriv->dma0BuffPhysAddr[index]); */
992 } 982 }
993 983
994 /* setup DMA descriptor ring (use cpu_to_le32 for byte ordering?) */ 984 /*
985 * setup DMA descriptor ring (use cpu_to_le32 for byte
986 * ordering?)
987 */
995 devpriv->dma0Chain = 988 devpriv->dma0Chain =
996 pci_alloc_consistent(devpriv->pci_dev, 989 pci_alloc_consistent(devpriv->pci_dev,
997 sizeof(struct plx_dma_desc) * 990 sizeof(struct plx_dma_desc) *
@@ -1088,30 +1081,12 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1088#endif 1081#endif
1089} 1082}
1090 1083
1091/* 1084static void rtd_detach(struct comedi_device *dev)
1092 * _detach is called to deconfigure a device. It should deallocate
1093 * resources.
1094 * This function is also called when _attach() fails, so it should be
1095 * careful not to release resources that were not necessarily
1096 * allocated by _attach(). dev->private and dev->subdevices are
1097 * deallocated automatically by the core.
1098 */
1099static int rtd_detach(struct comedi_device *dev)
1100{ 1085{
1101#ifdef USE_DMA 1086#ifdef USE_DMA
1102 int index; 1087 int index;
1103#endif 1088#endif
1104 1089
1105 DPRINTK("comedi%d: rtd520: removing (%ld ints)\n",
1106 dev->minor, (devpriv ? devpriv->intCount : 0L));
1107 if (devpriv && devpriv->lcfg) {
1108 DPRINTK
1109 ("(int status 0x%x, overrun status 0x%x, fifo status 0x%x)...\n",
1110 0xffff & RtdInterruptStatus(dev),
1111 0xffff & RtdInterruptOverrunStatus(dev),
1112 (0xffff & RtdFifoStatus(dev)) ^ 0x6666);
1113 }
1114
1115 if (devpriv) { 1090 if (devpriv) {
1116 /* Shut down any board ops by resetting it */ 1091 /* Shut down any board ops by resetting it */
1117#ifdef USE_DMA 1092#ifdef USE_DMA
@@ -1148,37 +1123,24 @@ static int rtd_detach(struct comedi_device *dev)
1148 devpriv->dma0Chain = NULL; 1123 devpriv->dma0Chain = NULL;
1149 } 1124 }
1150#endif /* USE_DMA */ 1125#endif /* USE_DMA */
1151
1152 /* release IRQ */
1153 if (dev->irq) { 1126 if (dev->irq) {
1154 /* disable interrupt controller */
1155 RtdPlxInterruptWrite(dev, RtdPlxInterruptRead(dev) 1127 RtdPlxInterruptWrite(dev, RtdPlxInterruptRead(dev)
1156 & ~(ICS_PLIE | ICS_DMA0_E | 1128 & ~(ICS_PLIE | ICS_DMA0_E |
1157 ICS_DMA1_E)); 1129 ICS_DMA1_E));
1158 free_irq(dev->irq, dev); 1130 free_irq(dev->irq, dev);
1159 } 1131 }
1160
1161 /* release all regions that were allocated */
1162 if (devpriv->las0) 1132 if (devpriv->las0)
1163 iounmap(devpriv->las0); 1133 iounmap(devpriv->las0);
1164
1165 if (devpriv->las1) 1134 if (devpriv->las1)
1166 iounmap(devpriv->las1); 1135 iounmap(devpriv->las1);
1167
1168 if (devpriv->lcfg) 1136 if (devpriv->lcfg)
1169 iounmap(devpriv->lcfg); 1137 iounmap(devpriv->lcfg);
1170
1171 if (devpriv->pci_dev) { 1138 if (devpriv->pci_dev) {
1172 if (devpriv->got_regions) 1139 if (devpriv->got_regions)
1173 comedi_pci_disable(devpriv->pci_dev); 1140 comedi_pci_disable(devpriv->pci_dev);
1174
1175 pci_dev_put(devpriv->pci_dev); 1141 pci_dev_put(devpriv->pci_dev);
1176 } 1142 }
1177 } 1143 }
1178
1179 printk(KERN_INFO "comedi%d: rtd520: removed.\n", dev->minor);
1180
1181 return 0;
1182} 1144}
1183 1145
1184/* 1146/*
@@ -1278,7 +1240,8 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev)
1278 } 1240 }
1279 } 1241 }
1280 if (i == limit) { 1242 if (i == limit) {
1281 printk(KERN_INFO "\ncomedi: %s: failed to probe fifo size.\n", DRV_NAME); 1243 printk(KERN_INFO "\ncomedi: %s: failed to probe fifo size.\n",
1244 DRV_NAME);
1282 return -EIO; 1245 return -EIO;
1283 } 1246 }
1284 RtdAdcClearFifo(dev); 1247 RtdAdcClearFifo(dev);
@@ -1378,9 +1341,10 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
1378 d = RtdAdcFifoGet(dev); /* get 2s comp value */ 1341 d = RtdAdcFifoGet(dev); /* get 2s comp value */
1379 1342
1380 d = d >> 3; /* low 3 bits are marker lines */ 1343 d = d >> 3; /* low 3 bits are marker lines */
1381 if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) 1344 if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) {
1382 sample = d + 2048; /* convert to comedi unsigned data */ 1345 /* convert to comedi unsigned data */
1383 else 1346 sample = d + 2048;
1347 } else
1384 sample = d; 1348 sample = d;
1385 1349
1386 if (!comedi_buf_put(s->async, sample)) 1350 if (!comedi_buf_put(s->async, sample))
@@ -1406,9 +1370,10 @@ static int ai_read_dregs(struct comedi_device *dev, struct comedi_subdevice *s)
1406 } 1370 }
1407 1371
1408 d = d >> 3; /* low 3 bits are marker lines */ 1372 d = d >> 3; /* low 3 bits are marker lines */
1409 if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) 1373 if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) {
1410 sample = d + 2048; /* convert to comedi unsigned data */ 1374 /* convert to comedi unsigned data */
1411 else 1375 sample = d + 2048;
1376 } else
1412 sample = d; 1377 sample = d;
1413 1378
1414 if (!comedi_buf_put(s->async, sample)) 1379 if (!comedi_buf_put(s->async, sample))
@@ -1525,7 +1490,9 @@ static int ai_process_dma(struct comedi_device *dev, struct comedi_subdevice *s)
1525 comedi_buf_memcpy_to(s->async, 0, dp, n); 1490 comedi_buf_memcpy_to(s->async, 0, dp, n);
1526 comedi_buf_write_free(s->async, n); 1491 comedi_buf_write_free(s->async, n);
1527 1492
1528 /* always at least 1 scan -- 1/2 FIFO is larger than our max scan list */ 1493 /*
1494 * always at least 1 scan -- 1/2 FIFO is larger than our max scan list
1495 */
1529 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 1496 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS;
1530 1497
1531 if (++devpriv->dma0Offset >= DMA_CHAIN_COUNT) { /* next buffer */ 1498 if (++devpriv->dma0Offset >= DMA_CHAIN_COUNT) { /* next buffer */
@@ -1989,7 +1956,7 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1989 (TRANS_TARGET_PERIOD * cmd->chanlist_len) / 1956 (TRANS_TARGET_PERIOD * cmd->chanlist_len) /
1990 cmd->scan_begin_arg; 1957 cmd->scan_begin_arg;
1991 if (devpriv->transCount < cmd->chanlist_len) { 1958 if (devpriv->transCount < cmd->chanlist_len) {
1992 /* tranfer after each scan (and avoid 0) */ 1959 /* transfer after each scan (and avoid 0) */
1993 devpriv->transCount = cmd->chanlist_len; 1960 devpriv->transCount = cmd->chanlist_len;
1994 } else { /* make a multiple of scan length */ 1961 } else { /* make a multiple of scan length */
1995 devpriv->transCount = 1962 devpriv->transCount =
@@ -2005,12 +1972,12 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2005 devpriv->transCount = 0; 1972 devpriv->transCount = 0;
2006 devpriv->flags &= ~SEND_EOS; 1973 devpriv->flags &= ~SEND_EOS;
2007 } else { 1974 } else {
2008 /* interrupt for each tranfer */ 1975 /* interrupt for each transfer */
2009 RtdAboutCounter(dev, devpriv->transCount - 1); 1976 RtdAboutCounter(dev, devpriv->transCount - 1);
2010 } 1977 }
2011 1978
2012 DPRINTK 1979 DPRINTK
2013 ("rtd520: scanLen=%d tranferCount=%d fifoLen=%d\n scanTime(ns)=%d flags=0x%x\n", 1980 ("rtd520: scanLen=%d transferCount=%d fifoLen=%d\n scanTime(ns)=%d flags=0x%x\n",
2014 cmd->chanlist_len, devpriv->transCount, devpriv->fifoLen, 1981 cmd->chanlist_len, devpriv->transCount, devpriv->fifoLen,
2015 cmd->scan_begin_arg, devpriv->flags); 1982 cmd->scan_begin_arg, devpriv->flags);
2016 } else { /* unknown timing, just use 1/2 FIFO */ 1983 } else { /* unknown timing, just use 1/2 FIFO */
@@ -2348,47 +2315,38 @@ static int rtd_dio_insn_config(struct comedi_device *dev,
2348 return 1; 2315 return 1;
2349} 2316}
2350 2317
2351/* 2318static struct comedi_driver rtd520_driver = {
2352 * A convenient macro that defines init_module() and cleanup_module(), 2319 .driver_name = "rtd520",
2353 * as necessary. 2320 .module = THIS_MODULE,
2354 */ 2321 .attach = rtd_attach,
2355static int __devinit rtd520Driver_pci_probe(struct pci_dev *dev, 2322 .detach = rtd_detach,
2356 const struct pci_device_id *ent) 2323};
2324
2325static int __devinit rtd520_pci_probe(struct pci_dev *dev,
2326 const struct pci_device_id *ent)
2357{ 2327{
2358 return comedi_pci_auto_config(dev, rtd520Driver.driver_name); 2328 return comedi_pci_auto_config(dev, &rtd520_driver);
2359} 2329}
2360 2330
2361static void __devexit rtd520Driver_pci_remove(struct pci_dev *dev) 2331static void __devexit rtd520_pci_remove(struct pci_dev *dev)
2362{ 2332{
2363 comedi_pci_auto_unconfig(dev); 2333 comedi_pci_auto_unconfig(dev);
2364} 2334}
2365 2335
2366static struct pci_driver rtd520Driver_pci_driver = { 2336static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = {
2367 .id_table = rtd520_pci_table, 2337 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) },
2368 .probe = &rtd520Driver_pci_probe, 2338 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) },
2369 .remove = __devexit_p(&rtd520Driver_pci_remove) 2339 { 0 }
2370}; 2340};
2341MODULE_DEVICE_TABLE(pci, rtd520_pci_table);
2371 2342
2372static int __init rtd520Driver_init_module(void) 2343static struct pci_driver rtd520_pci_driver = {
2373{ 2344 .name = "rtd520",
2374 int retval; 2345 .id_table = rtd520_pci_table,
2375 2346 .probe = rtd520_pci_probe,
2376 retval = comedi_driver_register(&rtd520Driver); 2347 .remove = __devexit_p(rtd520_pci_remove),
2377 if (retval < 0) 2348};
2378 return retval; 2349module_comedi_pci_driver(rtd520_driver, rtd520_pci_driver);
2379
2380 rtd520Driver_pci_driver.name = (char *)rtd520Driver.driver_name;
2381 return pci_register_driver(&rtd520Driver_pci_driver);
2382}
2383
2384static void __exit rtd520Driver_cleanup_module(void)
2385{
2386 pci_unregister_driver(&rtd520Driver_pci_driver);
2387 comedi_driver_unregister(&rtd520Driver);
2388}
2389
2390module_init(rtd520Driver_init_module);
2391module_exit(rtd520Driver_cleanup_module);
2392 2350
2393MODULE_AUTHOR("Comedi http://www.comedi.org"); 2351MODULE_AUTHOR("Comedi http://www.comedi.org");
2394MODULE_DESCRIPTION("Comedi low-level driver"); 2352MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/rti800.c b/drivers/staging/comedi/drivers/rti800.c
index 72042b818310..f0eb52a77881 100644
--- a/drivers/staging/comedi/drivers/rti800.c
+++ b/drivers/staging/comedi/drivers/rti800.c
@@ -138,39 +138,8 @@ struct rti800_board {
138 int has_ao; 138 int has_ao;
139}; 139};
140 140
141static const struct rti800_board boardtypes[] = {
142 {"rti800", 0},
143 {"rti815", 1},
144};
145
146#define this_board ((const struct rti800_board *)dev->board_ptr) 141#define this_board ((const struct rti800_board *)dev->board_ptr)
147 142
148static int rti800_attach(struct comedi_device *dev,
149 struct comedi_devconfig *it);
150static int rti800_detach(struct comedi_device *dev);
151static struct comedi_driver driver_rti800 = {
152 .driver_name = "rti800",
153 .module = THIS_MODULE,
154 .attach = rti800_attach,
155 .detach = rti800_detach,
156 .num_names = ARRAY_SIZE(boardtypes),
157 .board_name = &boardtypes[0].name,
158 .offset = sizeof(struct rti800_board),
159};
160
161static int __init driver_rti800_init_module(void)
162{
163 return comedi_driver_register(&driver_rti800);
164}
165
166static void __exit driver_rti800_cleanup_module(void)
167{
168 comedi_driver_unregister(&driver_rti800);
169}
170
171module_init(driver_rti800_init_module);
172module_exit(driver_rti800_cleanup_module);
173
174static irqreturn_t rti800_interrupt(int irq, void *dev); 143static irqreturn_t rti800_interrupt(int irq, void *dev);
175 144
176struct rti800_private { 145struct rti800_private {
@@ -474,19 +443,30 @@ static int rti800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
474 return 0; 443 return 0;
475} 444}
476 445
477static int rti800_detach(struct comedi_device *dev) 446static void rti800_detach(struct comedi_device *dev)
478{ 447{
479 printk(KERN_INFO "comedi%d: rti800: remove\n", dev->minor);
480
481 if (dev->iobase) 448 if (dev->iobase)
482 release_region(dev->iobase, RTI800_SIZE); 449 release_region(dev->iobase, RTI800_SIZE);
483
484 if (dev->irq) 450 if (dev->irq)
485 free_irq(dev->irq, dev); 451 free_irq(dev->irq, dev);
486
487 return 0;
488} 452}
489 453
454static const struct rti800_board boardtypes[] = {
455 { "rti800", 0 },
456 { "rti815", 1 },
457};
458
459static struct comedi_driver rti800_driver = {
460 .driver_name = "rti800",
461 .module = THIS_MODULE,
462 .attach = rti800_attach,
463 .detach = rti800_detach,
464 .num_names = ARRAY_SIZE(boardtypes),
465 .board_name = &boardtypes[0].name,
466 .offset = sizeof(struct rti800_board),
467};
468module_comedi_driver(rti800_driver);
469
490MODULE_AUTHOR("Comedi http://www.comedi.org"); 470MODULE_AUTHOR("Comedi http://www.comedi.org");
491MODULE_DESCRIPTION("Comedi low-level driver"); 471MODULE_DESCRIPTION("Comedi low-level driver");
492MODULE_LICENSE("GPL"); 472MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/rti802.c b/drivers/staging/comedi/drivers/rti802.c
index f59cb11590f6..09da5c21858c 100644
--- a/drivers/staging/comedi/drivers/rti802.c
+++ b/drivers/staging/comedi/drivers/rti802.c
@@ -47,29 +47,6 @@ Configuration Options:
47#define RTI802_DATALOW 1 47#define RTI802_DATALOW 1
48#define RTI802_DATAHIGH 2 48#define RTI802_DATAHIGH 2
49 49
50static int rti802_attach(struct comedi_device *dev,
51 struct comedi_devconfig *it);
52static int rti802_detach(struct comedi_device *dev);
53static struct comedi_driver driver_rti802 = {
54 .driver_name = "rti802",
55 .module = THIS_MODULE,
56 .attach = rti802_attach,
57 .detach = rti802_detach,
58};
59
60static int __init driver_rti802_init_module(void)
61{
62 return comedi_driver_register(&driver_rti802);
63}
64
65static void __exit driver_rti802_cleanup_module(void)
66{
67 comedi_driver_unregister(&driver_rti802);
68}
69
70module_init(driver_rti802_init_module);
71module_exit(driver_rti802_cleanup_module);
72
73struct rti802_private { 50struct rti802_private {
74 enum { 51 enum {
75 dac_2comp, dac_straight 52 dac_2comp, dac_straight
@@ -152,16 +129,20 @@ static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it)
152 return 0; 129 return 0;
153} 130}
154 131
155static int rti802_detach(struct comedi_device *dev) 132static void rti802_detach(struct comedi_device *dev)
156{ 133{
157 printk(KERN_INFO "comedi%d: rti802: remove\n", dev->minor);
158
159 if (dev->iobase) 134 if (dev->iobase)
160 release_region(dev->iobase, RTI802_SIZE); 135 release_region(dev->iobase, RTI802_SIZE);
161
162 return 0;
163} 136}
164 137
138static struct comedi_driver rti802_driver = {
139 .driver_name = "rti802",
140 .module = THIS_MODULE,
141 .attach = rti802_attach,
142 .detach = rti802_detach,
143};
144module_comedi_driver(rti802_driver);
145
165MODULE_AUTHOR("Comedi http://www.comedi.org"); 146MODULE_AUTHOR("Comedi http://www.comedi.org");
166MODULE_DESCRIPTION("Comedi low-level driver"); 147MODULE_DESCRIPTION("Comedi low-level driver");
167MODULE_LICENSE("GPL"); 148MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c
index 2b34daedc3d7..7a56434eb224 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -230,287 +230,6 @@ struct s526_private {
230 */ 230 */
231#define devpriv ((struct s526_private *)dev->private) 231#define devpriv ((struct s526_private *)dev->private)
232 232
233/*
234 * The struct comedi_driver structure tells the Comedi core module
235 * which functions to call to configure/deconfigure (attach/detach)
236 * the board, and also about the kernel module that contains
237 * the device code.
238 */
239static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it);
240static int s526_detach(struct comedi_device *dev);
241static struct comedi_driver driver_s526 = {
242 .driver_name = "s526",
243 .module = THIS_MODULE,
244 .attach = s526_attach,
245 .detach = s526_detach,
246/* It is not necessary to implement the following members if you are
247 * writing a driver for a ISA PnP or PCI card */
248 /* Most drivers will support multiple types of boards by
249 * having an array of board structures. These were defined
250 * in s526_boards[] above. Note that the element 'name'
251 * was first in the structure -- Comedi uses this fact to
252 * extract the name of the board without knowing any details
253 * about the structure except for its length.
254 * When a device is attached (by comedi_config), the name
255 * of the device is given to Comedi, and Comedi tries to
256 * match it by going through the list of board names. If
257 * there is a match, the address of the pointer is put
258 * into dev->board_ptr and driver->attach() is called.
259 *
260 * Note that these are not necessary if you can determine
261 * the type of board in software. ISA PnP, PCI, and PCMCIA
262 * devices are such boards.
263 */
264 .board_name = &s526_boards[0].name,
265 .offset = sizeof(struct s526_board),
266 .num_names = ARRAY_SIZE(s526_boards),
267};
268
269static int s526_gpct_rinsn(struct comedi_device *dev,
270 struct comedi_subdevice *s, struct comedi_insn *insn,
271 unsigned int *data);
272static int s526_gpct_insn_config(struct comedi_device *dev,
273 struct comedi_subdevice *s,
274 struct comedi_insn *insn, unsigned int *data);
275static int s526_gpct_winsn(struct comedi_device *dev,
276 struct comedi_subdevice *s, struct comedi_insn *insn,
277 unsigned int *data);
278static int s526_ai_insn_config(struct comedi_device *dev,
279 struct comedi_subdevice *s,
280 struct comedi_insn *insn, unsigned int *data);
281static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
282 struct comedi_insn *insn, unsigned int *data);
283static int s526_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
284 struct comedi_insn *insn, unsigned int *data);
285static int s526_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
286 struct comedi_insn *insn, unsigned int *data);
287static int s526_dio_insn_bits(struct comedi_device *dev,
288 struct comedi_subdevice *s,
289 struct comedi_insn *insn, unsigned int *data);
290static int s526_dio_insn_config(struct comedi_device *dev,
291 struct comedi_subdevice *s,
292 struct comedi_insn *insn, unsigned int *data);
293
294/*
295 * Attach is called by the Comedi core to configure the driver
296 * for a particular board. If you specified a board_name array
297 * in the driver structure, dev->board_ptr contains that
298 * address.
299 */
300static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
301{
302 struct comedi_subdevice *s;
303 int iobase;
304 int i, n;
305/* short value; */
306/* int subdev_channel = 0; */
307 union cmReg cmReg;
308
309 printk(KERN_INFO "comedi%d: s526: ", dev->minor);
310
311 iobase = it->options[0];
312 if (!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)) {
313 comedi_error(dev, "I/O port conflict");
314 return -EIO;
315 }
316 dev->iobase = iobase;
317
318 printk("iobase=0x%lx\n", dev->iobase);
319
320 /*** make it a little quieter, exw, 8/29/06
321 for (i = 0; i < S526_NUM_PORTS; i++) {
322 printk("0x%02x: 0x%04x\n", ADDR_REG(s526_ports[i]),
323 inw(ADDR_REG(s526_ports[i])));
324 }
325 ***/
326
327/*
328 * Initialize dev->board_name. Note that we can use the "thisboard"
329 * macro now, since we just initialized it in the last line.
330 */
331 dev->board_ptr = &s526_boards[0];
332
333 dev->board_name = thisboard->name;
334
335/*
336 * Allocate the private structure area. alloc_private() is a
337 * convenient macro defined in comedidev.h.
338 */
339 if (alloc_private(dev, sizeof(struct s526_private)) < 0)
340 return -ENOMEM;
341
342/*
343 * Allocate the subdevice structures. alloc_subdevice() is a
344 * convenient macro defined in comedidev.h.
345 */
346 dev->n_subdevices = 4;
347 if (alloc_subdevices(dev, dev->n_subdevices) < 0)
348 return -ENOMEM;
349
350 s = dev->subdevices + 0;
351 /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */
352 s->type = COMEDI_SUBD_COUNTER;
353 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
354 /* KG: What does SDF_LSAMPL (see multiq3.c) mean? */
355 s->n_chan = thisboard->gpct_chans;
356 s->maxdata = 0x00ffffff; /* 24 bit counter */
357 s->insn_read = s526_gpct_rinsn;
358 s->insn_config = s526_gpct_insn_config;
359 s->insn_write = s526_gpct_winsn;
360
361 /* Command are not implemented yet, however they are necessary to
362 allocate the necessary memory for the comedi_async struct (used
363 to trigger the GPCT in case of pulsegenerator function */
364 /* s->do_cmd = s526_gpct_cmd; */
365 /* s->do_cmdtest = s526_gpct_cmdtest; */
366 /* s->cancel = s526_gpct_cancel; */
367
368 s = dev->subdevices + 1;
369 /* dev->read_subdev=s; */
370 /* analog input subdevice */
371 s->type = COMEDI_SUBD_AI;
372 /* we support differential */
373 s->subdev_flags = SDF_READABLE | SDF_DIFF;
374 /* channels 0 to 7 are the regular differential inputs */
375 /* channel 8 is "reference 0" (+10V), channel 9 is "reference 1" (0V) */
376 s->n_chan = 10;
377 s->maxdata = 0xffff;
378 s->range_table = &range_bipolar10;
379 s->len_chanlist = 16; /* This is the maximum chanlist length that
380 the board can handle */
381 s->insn_read = s526_ai_rinsn;
382 s->insn_config = s526_ai_insn_config;
383
384 s = dev->subdevices + 2;
385 /* analog output subdevice */
386 s->type = COMEDI_SUBD_AO;
387 s->subdev_flags = SDF_WRITABLE;
388 s->n_chan = 4;
389 s->maxdata = 0xffff;
390 s->range_table = &range_bipolar10;
391 s->insn_write = s526_ao_winsn;
392 s->insn_read = s526_ao_rinsn;
393
394 s = dev->subdevices + 3;
395 /* digital i/o subdevice */
396 if (thisboard->have_dio) {
397 s->type = COMEDI_SUBD_DIO;
398 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
399 s->n_chan = 8;
400 s->maxdata = 1;
401 s->range_table = &range_digital;
402 s->insn_bits = s526_dio_insn_bits;
403 s->insn_config = s526_dio_insn_config;
404 } else {
405 s->type = COMEDI_SUBD_UNUSED;
406 }
407
408 printk(KERN_INFO "attached\n");
409
410 return 1;
411
412#if 0
413 /* Example of Counter Application */
414 /* One-shot (software trigger) */
415 cmReg.reg.coutSource = 0; /* out RCAP */
416 cmReg.reg.coutPolarity = 1; /* Polarity inverted */
417 cmReg.reg.autoLoadResetRcap = 1;/* Auto load 0:disabled, 1:enabled */
418 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */
419 cmReg.reg.ctEnableCtrl = 2; /* Hardware */
420 cmReg.reg.clockSource = 2; /* Internal */
421 cmReg.reg.countDir = 1; /* Down */
422 cmReg.reg.countDirCtrl = 1; /* Software */
423 cmReg.reg.outputRegLatchCtrl = 0; /* latch on read */
424 cmReg.reg.preloadRegSel = 0; /* PR0 */
425 cmReg.reg.reserved = 0;
426
427 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel));
428
429 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel));
430 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel));
431
432 /* Reset the counter */
433 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
434 /* Load the counter from PR0 */
435 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
436 /* Reset RCAP (fires one-shot) */
437 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel));
438
439#else
440
441 /* Set Counter Mode Register */
442 cmReg.reg.coutSource = 0; /* out RCAP */
443 cmReg.reg.coutPolarity = 0; /* Polarity inverted */
444 cmReg.reg.autoLoadResetRcap = 0; /* Auto load disabled */
445 cmReg.reg.hwCtEnableSource = 2; /* NOT RCAP */
446 cmReg.reg.ctEnableCtrl = 1; /* 1: Software, >1 : Hardware */
447 cmReg.reg.clockSource = 3; /* x4 */
448 cmReg.reg.countDir = 0; /* up */
449 cmReg.reg.countDirCtrl = 0; /* quadrature */
450 cmReg.reg.outputRegLatchCtrl = 0; /* latch on read */
451 cmReg.reg.preloadRegSel = 0; /* PR0 */
452 cmReg.reg.reserved = 0;
453
454 n = 0;
455 printk(KERN_INFO "Mode reg=0x%04x, 0x%04lx\n",
456 cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
457 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
458 udelay(1000);
459 printk(KERN_INFO "Read back mode reg=0x%04x\n",
460 inw(ADDR_CHAN_REG(REG_C0M, n)));
461
462 /* Load the pre-load register high word */
463/* value = (short) (0x55); */
464/* outw(value, ADDR_CHAN_REG(REG_C0H, n)); */
465
466 /* Load the pre-load register low word */
467/* value = (short)(0xaa55); */
468/* outw(value, ADDR_CHAN_REG(REG_C0L, n)); */
469
470 /* Write the Counter Control Register */
471/* outw(value, ADDR_CHAN_REG(REG_C0C, 0)); */
472
473 /* Reset the counter if it is software preload */
474 if (cmReg.reg.autoLoadResetRcap == 0) {
475 /* Reset the counter */
476 outw(0x8000, ADDR_CHAN_REG(REG_C0C, n));
477 /* Load the counter from PR0 */
478 outw(0x4000, ADDR_CHAN_REG(REG_C0C, n));
479 }
480
481 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
482 udelay(1000);
483 printk(KERN_INFO "Read back mode reg=0x%04x\n",
484 inw(ADDR_CHAN_REG(REG_C0M, n)));
485
486#endif
487 printk(KERN_INFO "Current registres:\n");
488
489 for (i = 0; i < S526_NUM_PORTS; i++) {
490 printk(KERN_INFO "0x%02lx: 0x%04x\n",
491 ADDR_REG(s526_ports[i]), inw(ADDR_REG(s526_ports[i])));
492 }
493 return 1;
494}
495
496/*
497 * _detach is called to deconfigure a device. It should deallocate
498 * resources.
499 * This function is also called when _attach() fails, so it should be
500 * careful not to release resources that were not necessarily
501 * allocated by _attach(). dev->private and dev->subdevices are
502 * deallocated automatically by the core.
503 */
504static int s526_detach(struct comedi_device *dev)
505{
506 printk(KERN_INFO "comedi%d: s526: remove\n", dev->minor);
507
508 if (dev->iobase > 0)
509 release_region(dev->iobase, S526_IOSIZE);
510
511 return 0;
512}
513
514static int s526_gpct_rinsn(struct comedi_device *dev, 233static int s526_gpct_rinsn(struct comedi_device *dev,
515 struct comedi_subdevice *s, struct comedi_insn *insn, 234 struct comedi_subdevice *s, struct comedi_insn *insn,
516 unsigned int *data) 235 unsigned int *data)
@@ -1023,22 +742,218 @@ static int s526_dio_insn_config(struct comedi_device *dev,
1023 return 1; 742 return 1;
1024} 743}
1025 744
745static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
746{
747 struct comedi_subdevice *s;
748 int iobase;
749 int i, n;
750/* short value; */
751/* int subdev_channel = 0; */
752 union cmReg cmReg;
753
754 printk(KERN_INFO "comedi%d: s526: ", dev->minor);
755
756 iobase = it->options[0];
757 if (!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)) {
758 comedi_error(dev, "I/O port conflict");
759 return -EIO;
760 }
761 dev->iobase = iobase;
762
763 printk("iobase=0x%lx\n", dev->iobase);
764
765 /*** make it a little quieter, exw, 8/29/06
766 for (i = 0; i < S526_NUM_PORTS; i++) {
767 printk("0x%02x: 0x%04x\n", ADDR_REG(s526_ports[i]),
768 inw(ADDR_REG(s526_ports[i])));
769 }
770 ***/
771
1026/* 772/*
1027 * A convenient macro that defines init_module() and cleanup_module(), 773 * Initialize dev->board_name. Note that we can use the "thisboard"
1028 * as necessary. 774 * macro now, since we just initialized it in the last line.
1029 */ 775 */
1030static int __init driver_s526_init_module(void) 776 dev->board_ptr = &s526_boards[0];
1031{ 777
1032 return comedi_driver_register(&driver_s526); 778 dev->board_name = thisboard->name;
779
780/*
781 * Allocate the private structure area. alloc_private() is a
782 * convenient macro defined in comedidev.h.
783 */
784 if (alloc_private(dev, sizeof(struct s526_private)) < 0)
785 return -ENOMEM;
786
787/*
788 * Allocate the subdevice structures. alloc_subdevice() is a
789 * convenient macro defined in comedidev.h.
790 */
791 dev->n_subdevices = 4;
792 if (alloc_subdevices(dev, dev->n_subdevices) < 0)
793 return -ENOMEM;
794
795 s = dev->subdevices + 0;
796 /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */
797 s->type = COMEDI_SUBD_COUNTER;
798 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
799 /* KG: What does SDF_LSAMPL (see multiq3.c) mean? */
800 s->n_chan = thisboard->gpct_chans;
801 s->maxdata = 0x00ffffff; /* 24 bit counter */
802 s->insn_read = s526_gpct_rinsn;
803 s->insn_config = s526_gpct_insn_config;
804 s->insn_write = s526_gpct_winsn;
805
806 /* Command are not implemented yet, however they are necessary to
807 allocate the necessary memory for the comedi_async struct (used
808 to trigger the GPCT in case of pulsegenerator function */
809 /* s->do_cmd = s526_gpct_cmd; */
810 /* s->do_cmdtest = s526_gpct_cmdtest; */
811 /* s->cancel = s526_gpct_cancel; */
812
813 s = dev->subdevices + 1;
814 /* dev->read_subdev=s; */
815 /* analog input subdevice */
816 s->type = COMEDI_SUBD_AI;
817 /* we support differential */
818 s->subdev_flags = SDF_READABLE | SDF_DIFF;
819 /* channels 0 to 7 are the regular differential inputs */
820 /* channel 8 is "reference 0" (+10V), channel 9 is "reference 1" (0V) */
821 s->n_chan = 10;
822 s->maxdata = 0xffff;
823 s->range_table = &range_bipolar10;
824 s->len_chanlist = 16; /* This is the maximum chanlist length that
825 the board can handle */
826 s->insn_read = s526_ai_rinsn;
827 s->insn_config = s526_ai_insn_config;
828
829 s = dev->subdevices + 2;
830 /* analog output subdevice */
831 s->type = COMEDI_SUBD_AO;
832 s->subdev_flags = SDF_WRITABLE;
833 s->n_chan = 4;
834 s->maxdata = 0xffff;
835 s->range_table = &range_bipolar10;
836 s->insn_write = s526_ao_winsn;
837 s->insn_read = s526_ao_rinsn;
838
839 s = dev->subdevices + 3;
840 /* digital i/o subdevice */
841 if (thisboard->have_dio) {
842 s->type = COMEDI_SUBD_DIO;
843 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
844 s->n_chan = 8;
845 s->maxdata = 1;
846 s->range_table = &range_digital;
847 s->insn_bits = s526_dio_insn_bits;
848 s->insn_config = s526_dio_insn_config;
849 } else {
850 s->type = COMEDI_SUBD_UNUSED;
851 }
852
853 printk(KERN_INFO "attached\n");
854
855 return 1;
856
857#if 0
858 /* Example of Counter Application */
859 /* One-shot (software trigger) */
860 cmReg.reg.coutSource = 0; /* out RCAP */
861 cmReg.reg.coutPolarity = 1; /* Polarity inverted */
862 cmReg.reg.autoLoadResetRcap = 1;/* Auto load 0:disabled, 1:enabled */
863 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */
864 cmReg.reg.ctEnableCtrl = 2; /* Hardware */
865 cmReg.reg.clockSource = 2; /* Internal */
866 cmReg.reg.countDir = 1; /* Down */
867 cmReg.reg.countDirCtrl = 1; /* Software */
868 cmReg.reg.outputRegLatchCtrl = 0; /* latch on read */
869 cmReg.reg.preloadRegSel = 0; /* PR0 */
870 cmReg.reg.reserved = 0;
871
872 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel));
873
874 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel));
875 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel));
876
877 /* Reset the counter */
878 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
879 /* Load the counter from PR0 */
880 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
881 /* Reset RCAP (fires one-shot) */
882 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel));
883
884#else
885
886 /* Set Counter Mode Register */
887 cmReg.reg.coutSource = 0; /* out RCAP */
888 cmReg.reg.coutPolarity = 0; /* Polarity inverted */
889 cmReg.reg.autoLoadResetRcap = 0; /* Auto load disabled */
890 cmReg.reg.hwCtEnableSource = 2; /* NOT RCAP */
891 cmReg.reg.ctEnableCtrl = 1; /* 1: Software, >1 : Hardware */
892 cmReg.reg.clockSource = 3; /* x4 */
893 cmReg.reg.countDir = 0; /* up */
894 cmReg.reg.countDirCtrl = 0; /* quadrature */
895 cmReg.reg.outputRegLatchCtrl = 0; /* latch on read */
896 cmReg.reg.preloadRegSel = 0; /* PR0 */
897 cmReg.reg.reserved = 0;
898
899 n = 0;
900 printk(KERN_INFO "Mode reg=0x%04x, 0x%04lx\n",
901 cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
902 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
903 udelay(1000);
904 printk(KERN_INFO "Read back mode reg=0x%04x\n",
905 inw(ADDR_CHAN_REG(REG_C0M, n)));
906
907 /* Load the pre-load register high word */
908/* value = (short) (0x55); */
909/* outw(value, ADDR_CHAN_REG(REG_C0H, n)); */
910
911 /* Load the pre-load register low word */
912/* value = (short)(0xaa55); */
913/* outw(value, ADDR_CHAN_REG(REG_C0L, n)); */
914
915 /* Write the Counter Control Register */
916/* outw(value, ADDR_CHAN_REG(REG_C0C, 0)); */
917
918 /* Reset the counter if it is software preload */
919 if (cmReg.reg.autoLoadResetRcap == 0) {
920 /* Reset the counter */
921 outw(0x8000, ADDR_CHAN_REG(REG_C0C, n));
922 /* Load the counter from PR0 */
923 outw(0x4000, ADDR_CHAN_REG(REG_C0C, n));
924 }
925
926 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
927 udelay(1000);
928 printk(KERN_INFO "Read back mode reg=0x%04x\n",
929 inw(ADDR_CHAN_REG(REG_C0M, n)));
930
931#endif
932 printk(KERN_INFO "Current registres:\n");
933
934 for (i = 0; i < S526_NUM_PORTS; i++) {
935 printk(KERN_INFO "0x%02lx: 0x%04x\n",
936 ADDR_REG(s526_ports[i]), inw(ADDR_REG(s526_ports[i])));
937 }
938 return 1;
1033} 939}
1034 940
1035static void __exit driver_s526_cleanup_module(void) 941static void s526_detach(struct comedi_device *dev)
1036{ 942{
1037 comedi_driver_unregister(&driver_s526); 943 if (dev->iobase > 0)
944 release_region(dev->iobase, S526_IOSIZE);
1038} 945}
1039 946
1040module_init(driver_s526_init_module); 947static struct comedi_driver s526_driver = {
1041module_exit(driver_s526_cleanup_module); 948 .driver_name = "s526",
949 .module = THIS_MODULE,
950 .attach = s526_attach,
951 .detach = s526_detach,
952 .board_name = &s526_boards[0].name,
953 .offset = sizeof(struct s526_board),
954 .num_names = ARRAY_SIZE(s526_boards),
955};
956module_comedi_driver(s526_driver);
1042 957
1043MODULE_AUTHOR("Comedi http://www.comedi.org"); 958MODULE_AUTHOR("Comedi http://www.comedi.org");
1044MODULE_DESCRIPTION("Comedi low-level driver"); 959MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 23fc64b9988e..7beb8f6853af 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -79,12 +79,17 @@ INSN_CONFIG instructions:
79#include "comedi_fc.h" 79#include "comedi_fc.h"
80#include "s626.h" 80#include "s626.h"
81 81
82MODULE_AUTHOR("Gianluca Palli <gpalli@deis.unibo.it>"); 82#define PCI_VENDOR_ID_S626 0x1131
83MODULE_DESCRIPTION("Sensoray 626 Comedi driver module"); 83#define PCI_DEVICE_ID_S626 0x7146
84MODULE_LICENSE("GPL"); 84#define PCI_SUBVENDOR_ID_S626 0x6000
85#define PCI_SUBDEVICE_ID_S626 0x0272
85 86
86struct s626_board { 87struct s626_board {
87 const char *name; 88 const char *name;
89 int vendor_id;
90 int device_id;
91 int subvendor_id;
92 int subdevice_id;
88 int ai_chans; 93 int ai_chans;
89 int ai_bits; 94 int ai_bits;
90 int ao_chans; 95 int ao_chans;
@@ -97,6 +102,10 @@ struct s626_board {
97static const struct s626_board s626_boards[] = { 102static const struct s626_board s626_boards[] = {
98 { 103 {
99 .name = "s626", 104 .name = "s626",
105 .vendor_id = PCI_VENDOR_ID_S626,
106 .device_id = PCI_DEVICE_ID_S626,
107 .subvendor_id = PCI_SUBVENDOR_ID_S626,
108 .subdevice_id = PCI_SUBDEVICE_ID_S626,
100 .ai_chans = S626_ADC_CHANNELS, 109 .ai_chans = S626_ADC_CHANNELS,
101 .ai_bits = 14, 110 .ai_bits = 14,
102 .ao_chans = S626_DAC_CHANNELS, 111 .ao_chans = S626_DAC_CHANNELS,
@@ -108,30 +117,6 @@ static const struct s626_board s626_boards[] = {
108}; 117};
109 118
110#define thisboard ((const struct s626_board *)dev->board_ptr) 119#define thisboard ((const struct s626_board *)dev->board_ptr)
111#define PCI_VENDOR_ID_S626 0x1131
112#define PCI_DEVICE_ID_S626 0x7146
113
114/*
115 * For devices with vendor:device id == 0x1131:0x7146 you must specify
116 * also subvendor:subdevice ids, because otherwise it will conflict with
117 * Philips SAA7146 media/dvb based cards.
118 */
119static DEFINE_PCI_DEVICE_TABLE(s626_pci_table) = {
120 {PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626, 0x6000, 0x0272, 0, 0, 0},
121 {0}
122};
123
124MODULE_DEVICE_TABLE(pci, s626_pci_table);
125
126static int s626_attach(struct comedi_device *dev, struct comedi_devconfig *it);
127static int s626_detach(struct comedi_device *dev);
128
129static struct comedi_driver driver_s626 = {
130 .driver_name = "s626",
131 .module = THIS_MODULE,
132 .attach = s626_attach,
133 .detach = s626_detach,
134};
135 120
136struct s626_private { 121struct s626_private {
137 struct pci_dev *pdev; 122 struct pci_dev *pdev;
@@ -224,44 +209,6 @@ static struct dio_private *dio_private_word[]={
224#define devpriv ((struct s626_private *)dev->private) 209#define devpriv ((struct s626_private *)dev->private)
225#define diopriv ((struct dio_private *)s->private) 210#define diopriv ((struct dio_private *)s->private)
226 211
227static int __devinit driver_s626_pci_probe(struct pci_dev *dev,
228 const struct pci_device_id *ent)
229{
230 return comedi_pci_auto_config(dev, driver_s626.driver_name);
231}
232
233static void __devexit driver_s626_pci_remove(struct pci_dev *dev)
234{
235 comedi_pci_auto_unconfig(dev);
236}
237
238static struct pci_driver driver_s626_pci_driver = {
239 .id_table = s626_pci_table,
240 .probe = &driver_s626_pci_probe,
241 .remove = __devexit_p(&driver_s626_pci_remove)
242};
243
244static int __init driver_s626_init_module(void)
245{
246 int retval;
247
248 retval = comedi_driver_register(&driver_s626);
249 if (retval < 0)
250 return retval;
251
252 driver_s626_pci_driver.name = (char *)driver_s626.driver_name;
253 return pci_register_driver(&driver_s626_pci_driver);
254}
255
256static void __exit driver_s626_cleanup_module(void)
257{
258 pci_unregister_driver(&driver_s626_pci_driver);
259 comedi_driver_unregister(&driver_s626);
260}
261
262module_init(driver_s626_init_module);
263module_exit(driver_s626_cleanup_module);
264
265/* ioctl routines */ 212/* ioctl routines */
266static int s626_ai_insn_config(struct comedi_device *dev, 213static int s626_ai_insn_config(struct comedi_device *dev,
267 struct comedi_subdevice *s, 214 struct comedi_subdevice *s,
@@ -554,17 +501,17 @@ static int s626_attach(struct comedi_device *dev, struct comedi_devconfig *it)
554 resource_size_t resourceStart; 501 resource_size_t resourceStart;
555 dma_addr_t appdma; 502 dma_addr_t appdma;
556 struct comedi_subdevice *s; 503 struct comedi_subdevice *s;
557 const struct pci_device_id *ids;
558 struct pci_dev *pdev = NULL; 504 struct pci_dev *pdev = NULL;
559 505
560 if (alloc_private(dev, sizeof(struct s626_private)) < 0) 506 if (alloc_private(dev, sizeof(struct s626_private)) < 0)
561 return -ENOMEM; 507 return -ENOMEM;
562 508
563 for (i = 0; i < (ARRAY_SIZE(s626_pci_table) - 1) && !pdev; i++) { 509 for (i = 0; i < ARRAY_SIZE(s626_boards) && !pdev; i++) {
564 ids = &s626_pci_table[i];
565 do { 510 do {
566 pdev = pci_get_subsys(ids->vendor, ids->device, 511 pdev = pci_get_subsys(s626_boards[i].vendor_id,
567 ids->subvendor, ids->subdevice, 512 s626_boards[i].device_id,
513 s626_boards[i].subvendor_id,
514 s626_boards[i].subdevice_id,
568 pdev); 515 pdev);
569 516
570 if ((it->options[0] || it->options[1]) && pdev) { 517 if ((it->options[0] || it->options[1]) && pdev) {
@@ -1365,7 +1312,7 @@ static irqreturn_t s626_irq_handler(int irq, void *d)
1365 return IRQ_HANDLED; 1312 return IRQ_HANDLED;
1366} 1313}
1367 1314
1368static int s626_detach(struct comedi_device *dev) 1315static void s626_detach(struct comedi_device *dev)
1369{ 1316{
1370 if (devpriv) { 1317 if (devpriv) {
1371 /* stop ai_command */ 1318 /* stop ai_command */
@@ -1389,20 +1336,14 @@ static int s626_detach(struct comedi_device *dev)
1389 1336
1390 if (dev->irq) 1337 if (dev->irq)
1391 free_irq(dev->irq, dev); 1338 free_irq(dev->irq, dev);
1392
1393 if (devpriv->base_addr) 1339 if (devpriv->base_addr)
1394 iounmap(devpriv->base_addr); 1340 iounmap(devpriv->base_addr);
1395
1396 if (devpriv->pdev) { 1341 if (devpriv->pdev) {
1397 if (devpriv->got_regions) 1342 if (devpriv->got_regions)
1398 comedi_pci_disable(devpriv->pdev); 1343 comedi_pci_disable(devpriv->pdev);
1399 pci_dev_put(devpriv->pdev); 1344 pci_dev_put(devpriv->pdev);
1400 } 1345 }
1401 } 1346 }
1402
1403 DEBUG("s626_detach: S626 detached!\n");
1404
1405 return 0;
1406} 1347}
1407 1348
1408/* 1349/*
@@ -3367,3 +3308,45 @@ static void CountersInit(struct comedi_device *dev)
3367 DEBUG("CountersInit: counters initialized\n"); 3308 DEBUG("CountersInit: counters initialized\n");
3368 3309
3369} 3310}
3311
3312static struct comedi_driver s626_driver = {
3313 .driver_name = "s626",
3314 .module = THIS_MODULE,
3315 .attach = s626_attach,
3316 .detach = s626_detach,
3317};
3318
3319static int __devinit s626_pci_probe(struct pci_dev *dev,
3320 const struct pci_device_id *ent)
3321{
3322 return comedi_pci_auto_config(dev, &s626_driver);
3323}
3324
3325static void __devexit s626_pci_remove(struct pci_dev *dev)
3326{
3327 comedi_pci_auto_unconfig(dev);
3328}
3329
3330/*
3331 * For devices with vendor:device id == 0x1131:0x7146 you must specify
3332 * also subvendor:subdevice ids, because otherwise it will conflict with
3333 * Philips SAA7146 media/dvb based cards.
3334 */
3335static DEFINE_PCI_DEVICE_TABLE(s626_pci_table) = {
3336 { PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626,
3337 PCI_SUBVENDOR_ID_S626, PCI_SUBDEVICE_ID_S626, 0, 0, 0 },
3338 { 0 }
3339};
3340MODULE_DEVICE_TABLE(pci, s626_pci_table);
3341
3342static struct pci_driver s626_pci_driver = {
3343 .name = "s626",
3344 .id_table = s626_pci_table,
3345 .probe = s626_pci_probe,
3346 .remove = __devexit_p(s626_pci_remove),
3347};
3348module_comedi_pci_driver(s626_driver, s626_pci_driver);
3349
3350MODULE_AUTHOR("Gianluca Palli <gpalli@deis.unibo.it>");
3351MODULE_DESCRIPTION("Sensoray 626 Comedi driver module");
3352MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index d880c2f6fbc1..6342bc5ddb3e 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -43,20 +43,10 @@ Status: in development
43#include <linux/serial.h> 43#include <linux/serial.h>
44#include <linux/poll.h> 44#include <linux/poll.h>
45 45
46/*
47 * Board descriptions for two imaginary boards. Describing the
48 * boards in this way is optional, and completely driver-dependent.
49 * Some drivers use arrays such as this, other do not.
50 */
51struct serial2002_board { 46struct serial2002_board {
52 const char *name; 47 const char *name;
53}; 48};
54 49
55static const struct serial2002_board serial2002_boards[] = {
56 {
57 .name = "serial2002"}
58};
59
60/* 50/*
61 * Useful for shorthand access to the particular board structure 51 * Useful for shorthand access to the particular board structure
62 */ 52 */
@@ -89,35 +79,6 @@ struct serial2002_private {
89 */ 79 */
90#define devpriv ((struct serial2002_private *)dev->private) 80#define devpriv ((struct serial2002_private *)dev->private)
91 81
92static int serial2002_attach(struct comedi_device *dev,
93 struct comedi_devconfig *it);
94static int serial2002_detach(struct comedi_device *dev);
95struct comedi_driver driver_serial2002 = {
96 .driver_name = "serial2002",
97 .module = THIS_MODULE,
98 .attach = serial2002_attach,
99 .detach = serial2002_detach,
100 .board_name = &serial2002_boards[0].name,
101 .offset = sizeof(struct serial2002_board),
102 .num_names = ARRAY_SIZE(serial2002_boards),
103};
104
105static int serial2002_di_rinsn(struct comedi_device *dev,
106 struct comedi_subdevice *s,
107 struct comedi_insn *insn, unsigned int *data);
108static int serial2002_do_winsn(struct comedi_device *dev,
109 struct comedi_subdevice *s,
110 struct comedi_insn *insn, unsigned int *data);
111static int serial2002_ai_rinsn(struct comedi_device *dev,
112 struct comedi_subdevice *s,
113 struct comedi_insn *insn, unsigned int *data);
114static int serial2002_ao_winsn(struct comedi_device *dev,
115 struct comedi_subdevice *s,
116 struct comedi_insn *insn, unsigned int *data);
117static int serial2002_ao_rinsn(struct comedi_device *dev,
118 struct comedi_subdevice *s,
119 struct comedi_insn *insn, unsigned int *data);
120
121struct serial_data { 82struct serial_data {
122 enum { is_invalid, is_digital, is_channel } kind; 83 enum { is_invalid, is_digital, is_channel } kind;
123 int index; 84 int index;
@@ -887,32 +848,34 @@ static int serial2002_attach(struct comedi_device *dev,
887 return 1; 848 return 1;
888} 849}
889 850
890static int serial2002_detach(struct comedi_device *dev) 851static void serial2002_detach(struct comedi_device *dev)
891{ 852{
892 struct comedi_subdevice *s; 853 struct comedi_subdevice *s;
893 int i; 854 int i;
894 855
895 dev_dbg(dev->hw_dev, "comedi%d: remove\n", dev->minor);
896 for (i = 0; i < 5; i++) { 856 for (i = 0; i < 5; i++) {
897 s = &dev->subdevices[i]; 857 s = &dev->subdevices[i];
898 kfree(s->maxdata_list); 858 kfree(s->maxdata_list);
899 kfree(s->range_table_list); 859 kfree(s->range_table_list);
900 } 860 }
901 return 0;
902}
903
904static int __init driver_serial2002_init_module(void)
905{
906 return comedi_driver_register(&driver_serial2002);
907} 861}
908 862
909static void __exit driver_serial2002_cleanup_module(void) 863static const struct serial2002_board serial2002_boards[] = {
910{ 864 {
911 comedi_driver_unregister(&driver_serial2002); 865 .name = "serial2002"
912} 866 },
867};
913 868
914module_init(driver_serial2002_init_module); 869static struct comedi_driver serial2002_driver = {
915module_exit(driver_serial2002_cleanup_module); 870 .driver_name = "serial2002",
871 .module = THIS_MODULE,
872 .attach = serial2002_attach,
873 .detach = serial2002_detach,
874 .board_name = &serial2002_boards[0].name,
875 .offset = sizeof(struct serial2002_board),
876 .num_names = ARRAY_SIZE(serial2002_boards),
877};
878module_comedi_driver(serial2002_driver);
916 879
917MODULE_AUTHOR("Comedi http://www.comedi.org"); 880MODULE_AUTHOR("Comedi http://www.comedi.org");
918MODULE_DESCRIPTION("Comedi low-level driver"); 881MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c
index ed69008f0d39..7d13ffa7f4f9 100644
--- a/drivers/staging/comedi/drivers/skel.c
+++ b/drivers/staging/comedi/drivers/skel.c
@@ -156,7 +156,7 @@ struct skel_private {
156 * the device code. 156 * the device code.
157 */ 157 */
158static int skel_attach(struct comedi_device *dev, struct comedi_devconfig *it); 158static int skel_attach(struct comedi_device *dev, struct comedi_devconfig *it);
159static int skel_detach(struct comedi_device *dev); 159static void skel_detach(struct comedi_device *dev);
160static struct comedi_driver driver_skel = { 160static struct comedi_driver driver_skel = {
161 .driver_name = "dummy", 161 .driver_name = "dummy",
162 .module = THIS_MODULE, 162 .module = THIS_MODULE,
@@ -295,11 +295,8 @@ static int skel_attach(struct comedi_device *dev, struct comedi_devconfig *it)
295 * allocated by _attach(). dev->private and dev->subdevices are 295 * allocated by _attach(). dev->private and dev->subdevices are
296 * deallocated automatically by the core. 296 * deallocated automatically by the core.
297 */ 297 */
298static int skel_detach(struct comedi_device *dev) 298static void skel_detach(struct comedi_device *dev)
299{ 299{
300 pr_info("comedi%d: skel: remove\n", dev->minor);
301
302 return 0;
303} 300}
304 301
305/* 302/*
@@ -623,7 +620,7 @@ static int skel_dio_insn_config(struct comedi_device *dev,
623static int __devinit driver_skel_pci_probe(struct pci_dev *dev, 620static int __devinit driver_skel_pci_probe(struct pci_dev *dev,
624 const struct pci_device_id *ent) 621 const struct pci_device_id *ent)
625{ 622{
626 return comedi_pci_auto_config(dev, driver_skel.driver_name); 623 return comedi_pci_auto_config(dev, &driver_skel);
627} 624}
628 625
629static void __devexit driver_skel_pci_remove(struct pci_dev *dev) 626static void __devexit driver_skel_pci_remove(struct pci_dev *dev)
diff --git a/drivers/staging/comedi/drivers/ssv_dnp.c b/drivers/staging/comedi/drivers/ssv_dnp.c
index 526de2efa125..16c4f5a757bb 100644
--- a/drivers/staging/comedi/drivers/ssv_dnp.c
+++ b/drivers/staging/comedi/drivers/ssv_dnp.c
@@ -59,16 +59,6 @@ struct dnp_board {
59 int have_dio; 59 int have_dio;
60}; 60};
61 61
62/* We only support one DNP 'board' variant at the moment */
63static const struct dnp_board dnp_boards[] = {
64{
65 .name = "dnp-1486",
66 .ai_chans = 16,
67 .ai_bits = 12,
68 .have_dio = 1,
69 },
70};
71
72/* Useful for shorthand access to the particular board structure ----------- */ 62/* Useful for shorthand access to the particular board structure ----------- */
73#define thisboard ((const struct dnp_board *)dev->board_ptr) 63#define thisboard ((const struct dnp_board *)dev->board_ptr)
74 64
@@ -81,136 +71,6 @@ struct dnp_private_data {
81#define devpriv ((dnp_private *)dev->private) 71#define devpriv ((dnp_private *)dev->private)
82 72
83/* ------------------------------------------------------------------------- */ 73/* ------------------------------------------------------------------------- */
84/* The struct comedi_driver structure tells the Comedi core module which */
85/* functions to call to configure/deconfigure (attach/detach) the board, and */
86/* also about the kernel module that contains the device code. */
87/* */
88/* In the following section we define the API of this driver. */
89/* ------------------------------------------------------------------------- */
90
91static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it);
92static int dnp_detach(struct comedi_device *dev);
93
94static struct comedi_driver driver_dnp = {
95 .driver_name = "ssv_dnp",
96 .module = THIS_MODULE,
97 .attach = dnp_attach,
98 .detach = dnp_detach,
99 .board_name = &dnp_boards[0].name,
100 /* only necessary for non-PnP devs */
101 .offset = sizeof(struct dnp_board), /* like ISA-PnP, PCI or PCMCIA */
102 .num_names = ARRAY_SIZE(dnp_boards),
103};
104
105static int __init driver_dnp_init_module(void)
106{
107 return comedi_driver_register(&driver_dnp);
108}
109
110static void __exit driver_dnp_cleanup_module(void)
111{
112 comedi_driver_unregister(&driver_dnp);
113}
114
115module_init(driver_dnp_init_module);
116module_exit(driver_dnp_cleanup_module);
117
118static int dnp_dio_insn_bits(struct comedi_device *dev,
119 struct comedi_subdevice *s,
120 struct comedi_insn *insn, unsigned int *data);
121
122static int dnp_dio_insn_config(struct comedi_device *dev,
123 struct comedi_subdevice *s,
124 struct comedi_insn *insn, unsigned int *data);
125
126/* ------------------------------------------------------------------------- */
127/* Attach is called by comedi core to configure the driver for a particular */
128/* board. If you specified a board_name array in the driver structure, */
129/* dev->board_ptr contains that address. */
130/* ------------------------------------------------------------------------- */
131
132static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it)
133{
134
135 struct comedi_subdevice *s;
136
137 printk(KERN_INFO "comedi%d: dnp: ", dev->minor);
138
139 /* Autoprobing: this should find out which board we have. Currently */
140 /* only the 1486 board is supported and autoprobing is not */
141 /* implemented :-) */
142 /* dev->board_ptr = dnp_probe(dev); */
143
144 /* Initialize the name of the board. */
145 /* We can use the "thisboard" macro now. */
146 dev->board_name = thisboard->name;
147
148 /* Allocate the private structure area. alloc_private() is a */
149 /* convenient macro defined in comedidev.h. */
150 if (alloc_private(dev, sizeof(struct dnp_private_data)) < 0)
151 return -ENOMEM;
152
153 /* Allocate the subdevice structures. alloc_subdevice() is a */
154 /* convenient macro defined in comedidev.h. */
155
156 if (alloc_subdevices(dev, 1) < 0)
157 return -ENOMEM;
158
159 s = dev->subdevices + 0;
160 /* digital i/o subdevice */
161 s->type = COMEDI_SUBD_DIO;
162 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
163 s->n_chan = 20;
164 s->maxdata = 1;
165 s->range_table = &range_digital;
166 s->insn_bits = dnp_dio_insn_bits;
167 s->insn_config = dnp_dio_insn_config;
168
169 printk("attached\n");
170
171 /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always
172 * allocated for the primary 8259, so we don't need to allocate them
173 * ourselves. */
174
175 /* configure all ports as input (default) */
176 outb(PAMR, CSCIR);
177 outb(0x00, CSCDR);
178 outb(PBMR, CSCIR);
179 outb(0x00, CSCDR);
180 outb(PCMR, CSCIR);
181 outb((inb(CSCDR) & 0xAA), CSCDR);
182
183 return 1;
184
185}
186
187/* ------------------------------------------------------------------------- */
188/* detach is called to deconfigure a device. It should deallocate the */
189/* resources. This function is also called when _attach() fails, so it */
190/* should be careful not to release resources that were not necessarily */
191/* allocated by _attach(). dev->private and dev->subdevices are */
192/* deallocated automatically by the core. */
193/* ------------------------------------------------------------------------- */
194
195static int dnp_detach(struct comedi_device *dev)
196{
197
198 /* configure all ports as input (default) */
199 outb(PAMR, CSCIR);
200 outb(0x00, CSCDR);
201 outb(PBMR, CSCIR);
202 outb(0x00, CSCDR);
203 outb(PCMR, CSCIR);
204 outb((inb(CSCDR) & 0xAA), CSCDR);
205
206 /* announce that we are finished */
207 printk(KERN_INFO "comedi%d: dnp: remove\n", dev->minor);
208
209 return 0;
210
211}
212
213/* ------------------------------------------------------------------------- */
214/* The insn_bits interface allows packed reading/writing of DIO channels. */ 74/* The insn_bits interface allows packed reading/writing of DIO channels. */
215/* The comedi core can convert between insn_bits and insn_read/write, so you */ 75/* The comedi core can convert between insn_bits and insn_read/write, so you */
216/* are able to use these instructions as well. */ 76/* are able to use these instructions as well. */
@@ -326,6 +186,89 @@ static int dnp_dio_insn_config(struct comedi_device *dev,
326 186
327} 187}
328 188
189static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it)
190{
191 struct comedi_subdevice *s;
192
193 printk(KERN_INFO "comedi%d: dnp: ", dev->minor);
194
195 /* Autoprobing: this should find out which board we have. Currently */
196 /* only the 1486 board is supported and autoprobing is not */
197 /* implemented :-) */
198 /* dev->board_ptr = dnp_probe(dev); */
199
200 /* Initialize the name of the board. */
201 /* We can use the "thisboard" macro now. */
202 dev->board_name = thisboard->name;
203
204 /* Allocate the private structure area. alloc_private() is a */
205 /* convenient macro defined in comedidev.h. */
206 if (alloc_private(dev, sizeof(struct dnp_private_data)) < 0)
207 return -ENOMEM;
208
209 /* Allocate the subdevice structures. alloc_subdevice() is a */
210 /* convenient macro defined in comedidev.h. */
211
212 if (alloc_subdevices(dev, 1) < 0)
213 return -ENOMEM;
214
215 s = dev->subdevices + 0;
216 /* digital i/o subdevice */
217 s->type = COMEDI_SUBD_DIO;
218 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
219 s->n_chan = 20;
220 s->maxdata = 1;
221 s->range_table = &range_digital;
222 s->insn_bits = dnp_dio_insn_bits;
223 s->insn_config = dnp_dio_insn_config;
224
225 printk("attached\n");
226
227 /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always
228 * allocated for the primary 8259, so we don't need to allocate them
229 * ourselves. */
230
231 /* configure all ports as input (default) */
232 outb(PAMR, CSCIR);
233 outb(0x00, CSCDR);
234 outb(PBMR, CSCIR);
235 outb(0x00, CSCDR);
236 outb(PCMR, CSCIR);
237 outb((inb(CSCDR) & 0xAA), CSCDR);
238
239 return 1;
240}
241
242static void dnp_detach(struct comedi_device *dev)
243{
244 outb(PAMR, CSCIR);
245 outb(0x00, CSCDR);
246 outb(PBMR, CSCIR);
247 outb(0x00, CSCDR);
248 outb(PCMR, CSCIR);
249 outb((inb(CSCDR) & 0xAA), CSCDR);
250}
251
252static const struct dnp_board dnp_boards[] = {
253 {
254 .name = "dnp-1486",
255 .ai_chans = 16,
256 .ai_bits = 12,
257 .have_dio = 1,
258 },
259};
260
261static struct comedi_driver dnp_driver = {
262 .driver_name = "ssv_dnp",
263 .module = THIS_MODULE,
264 .attach = dnp_attach,
265 .detach = dnp_detach,
266 .board_name = &dnp_boards[0].name,
267 .offset = sizeof(struct dnp_board),
268 .num_names = ARRAY_SIZE(dnp_boards),
269};
270module_comedi_driver(dnp_driver);
271
329MODULE_AUTHOR("Comedi http://www.comedi.org"); 272MODULE_AUTHOR("Comedi http://www.comedi.org");
330MODULE_DESCRIPTION("Comedi low-level driver"); 273MODULE_DESCRIPTION("Comedi low-level driver");
331MODULE_LICENSE("GPL"); 274MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c
index f45824f0d86b..d5f1f22aa708 100644
--- a/drivers/staging/comedi/drivers/unioxx5.c
+++ b/drivers/staging/comedi/drivers/unioxx5.c
@@ -83,96 +83,188 @@ struct unioxx5_subd_priv {
83 unsigned char usp_prev_cn_val[3]; /* previous channel value */ 83 unsigned char usp_prev_cn_val[3]; /* previous channel value */
84}; 84};
85 85
86static int unioxx5_attach(struct comedi_device *dev, 86static int __unioxx5_define_chan_offset(int chan_num)
87 struct comedi_devconfig *it); 87{
88static int unioxx5_subdev_write(struct comedi_device *dev,
89 struct comedi_subdevice *subdev,
90 struct comedi_insn *insn, unsigned int *data);
91static int unioxx5_subdev_read(struct comedi_device *dev,
92 struct comedi_subdevice *subdev,
93 struct comedi_insn *insn, unsigned int *data);
94static int unioxx5_insn_config(struct comedi_device *dev,
95 struct comedi_subdevice *subdev,
96 struct comedi_insn *insn, unsigned int *data);
97static int unioxx5_detach(struct comedi_device *dev);
98static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
99 int subdev_iobase, int minor);
100static int __unioxx5_digital_write(struct unioxx5_subd_priv *usp,
101 unsigned int *data, int channel, int minor);
102static int __unioxx5_digital_read(struct unioxx5_subd_priv *usp,
103 unsigned int *data, int channel, int minor);
104/* static void __unioxx5_digital_config(struct unioxx5_subd_priv* usp, int mode); */
105static int __unioxx5_analog_write(struct unioxx5_subd_priv *usp,
106 unsigned int *data, int channel, int minor);
107static int __unioxx5_analog_read(struct unioxx5_subd_priv *usp,
108 unsigned int *data, int channel, int minor);
109static int __unioxx5_define_chan_offset(int chan_num);
110static void __unioxx5_analog_config(struct unioxx5_subd_priv *usp, int channel);
111 88
112static struct comedi_driver unioxx5_driver = { 89 if (chan_num < 0 || chan_num > 23)
113 .driver_name = DRIVER_NAME, 90 return -1;
114 .module = THIS_MODULE,
115 .attach = unioxx5_attach,
116 .detach = unioxx5_detach
117};
118 91
119static int __init unioxx5_driver_init_module(void) 92 return (chan_num >> 3) + 1;
93}
94
95#if 0 /* not used? */
96static void __unioxx5_digital_config(struct unioxx5_subd_priv *usp, int mode)
120{ 97{
121 return comedi_driver_register(&unioxx5_driver); 98 int i, mask;
99
100 mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
101 printk("COMEDI: mode = %d\n", mask);
102
103 outb(1, usp->usp_iobase + 0);
104
105 for (i = 0; i < 3; i++)
106 outb(mask, usp->usp_iobase + i);
107
108 outb(0, usp->usp_iobase + 0);
122} 109}
110#endif
123 111
124static void __exit unioxx5_driver_cleanup_module(void) 112/* configure channels for analog i/o (even to output, odd to input) */
113static void __unioxx5_analog_config(struct unioxx5_subd_priv *usp, int channel)
125{ 114{
126 comedi_driver_unregister(&unioxx5_driver); 115 int chan_a, chan_b, conf, channel_offset;
116
117 channel_offset = __unioxx5_define_chan_offset(channel);
118 conf = usp->usp_prev_cn_val[channel_offset - 1];
119 chan_a = chan_b = 1;
120
121 /* setting channel A and channel B mask */
122 if (channel % 2 == 0) {
123 chan_a <<= channel & 0x07;
124 chan_b <<= (channel + 1) & 0x07;
125 } else {
126 chan_a <<= (channel - 1) & 0x07;
127 chan_b <<= channel & 0x07;
128 }
129
130 conf |= chan_a; /* even channel ot output */
131 conf &= ~chan_b; /* odd channel to input */
132
133 outb(1, usp->usp_iobase + 0);
134 outb(conf, usp->usp_iobase + channel_offset);
135 outb(0, usp->usp_iobase + 0);
136
137 usp->usp_prev_cn_val[channel_offset - 1] = conf;
127} 138}
128 139
129module_init(unioxx5_driver_init_module); 140static int __unioxx5_digital_read(struct unioxx5_subd_priv *usp,
130module_exit(unioxx5_driver_cleanup_module); 141 unsigned int *data, int channel, int minor)
142{
143 int channel_offset, mask = 1 << (channel & 0x07);
131 144
132static int unioxx5_attach(struct comedi_device *dev, 145 channel_offset = __unioxx5_define_chan_offset(channel);
133 struct comedi_devconfig *it) 146 if (channel_offset < 0) {
147 printk(KERN_ERR
148 "comedi%d: undefined channel %d. channel range is 0 .. 23\n",
149 minor, channel);
150 return 0;
151 }
152
153 *data = inb(usp->usp_iobase + channel_offset);
154 *data &= mask;
155
156 /* correct the read value to 0 or 1 */
157 if (channel_offset > 1)
158 channel -= 2 << channel_offset;
159 *data >>= channel;
160 return 1;
161}
162
163static int __unioxx5_analog_read(struct unioxx5_subd_priv *usp,
164 unsigned int *data, int channel, int minor)
134{ 165{
135 int iobase, i, n_subd; 166 int module_no, read_ch;
136 int id, num, ba; 167 char control;
137 168
138 iobase = it->options[0]; 169 module_no = channel / 2;
170 read_ch = channel % 2; /* depend on type of channel (A or B) */
139 171
140 dev->board_name = DRIVER_NAME; 172 /* defining if given module can work on input */
141 dev->iobase = iobase; 173 if (usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) {
142 iobase += UNIOXX5_SUBDEV_BASE; 174 printk(KERN_ERR
175 "comedi%d: module in position %d with id 0x%02x is for output only",
176 minor, module_no, usp->usp_module_type[module_no]);
177 return 0;
178 }
143 179
144 /* defining number of subdevices and getting they types (it must be 'g01') */ 180 __unioxx5_analog_config(usp, channel);
145 for (i = n_subd = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) { 181 /* sends module number to card(1 .. 12) */
146 id = inb(ba + 0xE); 182 outb(module_no + 1, usp->usp_iobase + 5);
147 num = inb(ba + 0xF); 183 outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */
184 control = inb(usp->usp_iobase); /* get control register byte */
148 185
149 if (id != 'g' || num != 1) 186 /* waits while reading four bytes will be allowed */
150 continue; 187 while (!((control = inb(usp->usp_iobase + 0)) & Rx4CA))
188 ;
151 189
152 n_subd++; 190 /* if four bytes readding error occurs - return 0(false) */
191 if ((control & Rx4CA_ERR_MASK)) {
192 printk("COMEDI: 4 bytes error\n");
193 return 0;
153 } 194 }
154 195
155 /* unioxx5 can has from two to four subdevices */ 196 if (read_ch)
156 if (n_subd < 2) { 197 *data = inw(usp->usp_iobase + 6); /* channel B */
198 else
199 *data = inw(usp->usp_iobase + 4); /* channel A */
200
201 return 1;
202}
203
204static int __unioxx5_digital_write(struct unioxx5_subd_priv *usp,
205 unsigned int *data, int channel, int minor)
206{
207 int channel_offset, val;
208 int mask = 1 << (channel & 0x07);
209
210 channel_offset = __unioxx5_define_chan_offset(channel);
211 if (channel_offset < 0) {
157 printk(KERN_ERR 212 printk(KERN_ERR
158 "your card must has at least 2 'g01' subdevices\n"); 213 "comedi%d: undefined channel %d. channel range is 0 .. 23\n",
159 return -1; 214 minor, channel);
215 return 0;
160 } 216 }
161 217
162 if (alloc_subdevices(dev, n_subd) < 0) { 218 /* getting previous written value */
163 printk(KERN_ERR "out of memory\n"); 219 val = usp->usp_prev_wr_val[channel_offset - 1];
164 return -ENOMEM; 220
221 if (*data)
222 val |= mask;
223 else
224 val &= ~mask;
225
226 outb(val, usp->usp_iobase + channel_offset);
227 /* saving new written value */
228 usp->usp_prev_wr_val[channel_offset - 1] = val;
229
230 return 1;
231}
232
233static int __unioxx5_analog_write(struct unioxx5_subd_priv *usp,
234 unsigned int *data, int channel, int minor)
235{
236 int module, i;
237
238 module = channel / 2; /* definig module number(0 .. 11) */
239 i = (channel % 2) << 1; /* depends on type of channel (A or B) */
240
241 /* defining if given module can work on output */
242 if (!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) {
243 printk(KERN_ERR
244 "comedi%d: module in position %d with id 0x%0x is for input only!\n",
245 minor, module, usp->usp_module_type[module]);
246 return 0;
165 } 247 }
166 248
167 /* initializing each of for same subdevices */ 249 __unioxx5_analog_config(usp, channel);
168 for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) { 250 /* saving minor byte */
169 if (__unioxx5_subdev_init(&dev->subdevices[i], iobase, 251 usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF);
170 dev->minor) < 0) 252 /* saving major byte */
171 return -1; 253 usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8);
254
255 /* while(!((inb(usp->usp_iobase + 0)) & TxBE)); */
256 /* sending module number to card(1 .. 12) */
257 outb(module + 1, usp->usp_iobase + 5);
258 outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */
259
260 /* sending for bytes to module(one byte per cycle iteration) */
261 for (i = 0; i < 4; i++) {
262 while (!((inb(usp->usp_iobase + 0)) & TxBE))
263 ; /* waits while writting will be allowed */
264 outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6);
172 } 265 }
173 266
174 printk(KERN_INFO "attached\n"); 267 return 1;
175 return 0;
176} 268}
177 269
178static int unioxx5_subdev_read(struct comedi_device *dev, 270static int unioxx5_subdev_read(struct comedi_device *dev,
@@ -275,22 +367,6 @@ static int unioxx5_insn_config(struct comedi_device *dev,
275 return 0; 367 return 0;
276} 368}
277 369
278static int unioxx5_detach(struct comedi_device *dev)
279{
280 int i;
281 struct comedi_subdevice *subdev;
282 struct unioxx5_subd_priv *usp;
283
284 for (i = 0; i < dev->n_subdevices; i++) {
285 subdev = &dev->subdevices[i];
286 usp = subdev->private;
287 release_region(usp->usp_iobase, UNIOXX5_SIZE);
288 kfree(subdev->private);
289 }
290
291 return 0;
292}
293
294/* initializing subdevice with given address */ 370/* initializing subdevice with given address */
295static int __unioxx5_subdev_init(struct comedi_subdevice *subdev, 371static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
296 int subdev_iobase, int minor) 372 int subdev_iobase, int minor)
@@ -362,196 +438,73 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
362 return 0; 438 return 0;
363} 439}
364 440
365static int __unioxx5_digital_write(struct unioxx5_subd_priv *usp, 441static int unioxx5_attach(struct comedi_device *dev,
366 unsigned int *data, int channel, int minor) 442 struct comedi_devconfig *it)
367{ 443{
368 int channel_offset, val; 444 int iobase, i, n_subd;
369 int mask = 1 << (channel & 0x07); 445 int id, num, ba;
370
371 channel_offset = __unioxx5_define_chan_offset(channel);
372 if (channel_offset < 0) {
373 printk(KERN_ERR
374 "comedi%d: undefined channel %d. channel range is 0 .. 23\n",
375 minor, channel);
376 return 0;
377 }
378
379 /* getting previous written value */
380 val = usp->usp_prev_wr_val[channel_offset - 1];
381 446
382 if (*data) 447 iobase = it->options[0];
383 val |= mask;
384 else
385 val &= ~mask;
386 448
387 outb(val, usp->usp_iobase + channel_offset); 449 dev->board_name = DRIVER_NAME;
388 /* saving new written value */ 450 dev->iobase = iobase;
389 usp->usp_prev_wr_val[channel_offset - 1] = val; 451 iobase += UNIOXX5_SUBDEV_BASE;
390 452
391 return 1; 453 /* defining number of subdevices and getting they types (it must be 'g01') */
392} 454 for (i = n_subd = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) {
455 id = inb(ba + 0xE);
456 num = inb(ba + 0xF);
393 457
394/* function for digital reading */ 458 if (id != 'g' || num != 1)
395static int __unioxx5_digital_read(struct unioxx5_subd_priv *usp, 459 continue;
396 unsigned int *data, int channel, int minor)
397{
398 int channel_offset, mask = 1 << (channel & 0x07);
399 460
400 channel_offset = __unioxx5_define_chan_offset(channel); 461 n_subd++;
401 if (channel_offset < 0) {
402 printk(KERN_ERR
403 "comedi%d: undefined channel %d. channel range is 0 .. 23\n",
404 minor, channel);
405 return 0;
406 } 462 }
407 463
408 *data = inb(usp->usp_iobase + channel_offset); 464 /* unioxx5 can has from two to four subdevices */
409 *data &= mask; 465 if (n_subd < 2) {
410
411 if (channel_offset > 1)
412 channel -= 2 << channel_offset; /* this operation is created for correct readed value to 0 or 1 */
413 *data >>= channel;
414 return 1;
415}
416
417#if 0 /* not used? */
418static void __unioxx5_digital_config(struct unioxx5_subd_priv *usp, int mode)
419{
420 int i, mask;
421
422 mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
423 printk("COMEDI: mode = %d\n", mask);
424
425 outb(1, usp->usp_iobase + 0);
426
427 for (i = 0; i < 3; i++)
428 outb(mask, usp->usp_iobase + i);
429
430 outb(0, usp->usp_iobase + 0);
431}
432#endif
433
434static int __unioxx5_analog_write(struct unioxx5_subd_priv *usp,
435 unsigned int *data, int channel, int minor)
436{
437 int module, i;
438
439 module = channel / 2; /* definig module number(0 .. 11) */
440 i = (channel % 2) << 1; /* depends on type of channel (A or B) */
441
442 /* defining if given module can work on output */
443 if (!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) {
444 printk(KERN_ERR 466 printk(KERN_ERR
445 "comedi%d: module in position %d with id 0x%0x is for input only!\n", 467 "your card must has at least 2 'g01' subdevices\n");
446 minor, module, usp->usp_module_type[module]); 468 return -1;
447 return 0;
448 }
449
450 __unioxx5_analog_config(usp, channel);
451 /* saving minor byte */
452 usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF);
453 /* saving major byte */
454 usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8);
455
456 /* while(!((inb(usp->usp_iobase + 0)) & TxBE)); */
457 /* sending module number to card(1 .. 12) */
458 outb(module + 1, usp->usp_iobase + 5);
459 outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */
460
461 /* sending for bytes to module(one byte per cycle iteration) */
462 for (i = 0; i < 4; i++) {
463 while (!((inb(usp->usp_iobase + 0)) & TxBE))
464 ; /* waits while writting will be allowed */
465 outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6);
466 } 469 }
467 470
468 return 1; 471 if (alloc_subdevices(dev, n_subd) < 0) {
469} 472 printk(KERN_ERR "out of memory\n");
470 473 return -ENOMEM;
471static int __unioxx5_analog_read(struct unioxx5_subd_priv *usp,
472 unsigned int *data, int channel, int minor)
473{
474 int module_no, read_ch;
475 char control;
476
477 module_no = channel / 2;
478 read_ch = channel % 2; /* depend on type of channel (A or B) */
479
480 /* defining if given module can work on input */
481 if (usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) {
482 printk(KERN_ERR
483 "comedi%d: module in position %d with id 0x%02x is for output only",
484 minor, module_no, usp->usp_module_type[module_no]);
485 return 0;
486 } 474 }
487 475
488 __unioxx5_analog_config(usp, channel); 476 /* initializing each of for same subdevices */
489 /* sends module number to card(1 .. 12) */ 477 for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) {
490 outb(module_no + 1, usp->usp_iobase + 5); 478 if (__unioxx5_subdev_init(&dev->subdevices[i], iobase,
491 outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */ 479 dev->minor) < 0)
492 control = inb(usp->usp_iobase); /* get control register byte */ 480 return -1;
493
494 /* waits while reading four bytes will be allowed */
495 while (!((control = inb(usp->usp_iobase + 0)) & Rx4CA))
496 ;
497
498 /* if four bytes readding error occurs - return 0(false) */
499 if ((control & Rx4CA_ERR_MASK)) {
500 printk("COMEDI: 4 bytes error\n");
501 return 0;
502 } 481 }
503 482
504 if (read_ch) 483 printk(KERN_INFO "attached\n");
505 *data = inw(usp->usp_iobase + 6); /* channel B */ 484 return 0;
506 else
507 *data = inw(usp->usp_iobase + 4); /* channel A */
508
509 return 1;
510} 485}
511 486
512/* configure channels for analog i/o (even to output, odd to input) */ 487static void unioxx5_detach(struct comedi_device *dev)
513static void __unioxx5_analog_config(struct unioxx5_subd_priv *usp, int channel)
514{ 488{
515 int chan_a, chan_b, conf, channel_offset; 489 int i;
516 490 struct comedi_subdevice *subdev;
517 channel_offset = __unioxx5_define_chan_offset(channel); 491 struct unioxx5_subd_priv *usp;
518 conf = usp->usp_prev_cn_val[channel_offset - 1];
519 chan_a = chan_b = 1;
520 492
521 /* setting channel A and channel B mask */ 493 for (i = 0; i < dev->n_subdevices; i++) {
522 if (channel % 2 == 0) { 494 subdev = &dev->subdevices[i];
523 chan_a <<= channel & 0x07; 495 usp = subdev->private;
524 chan_b <<= (channel + 1) & 0x07; 496 release_region(usp->usp_iobase, UNIOXX5_SIZE);
525 } else { 497 kfree(subdev->private);
526 chan_a <<= (channel - 1) & 0x07;
527 chan_b <<= channel & 0x07;
528 } 498 }
529
530 conf |= chan_a; /* even channel ot output */
531 conf &= ~chan_b; /* odd channel to input */
532
533 outb(1, usp->usp_iobase + 0);
534 outb(conf, usp->usp_iobase + channel_offset);
535 outb(0, usp->usp_iobase + 0);
536
537 usp->usp_prev_cn_val[channel_offset - 1] = conf;
538} 499}
539 500
540/* *\ 501static struct comedi_driver unioxx5_driver = {
541 * this function defines if the given channel number * 502 .driver_name = DRIVER_NAME,
542 * enters in default numeric interspace(from 0 to 23) * 503 .module = THIS_MODULE,
543 * and it returns address offset for usage needed * 504 .attach = unioxx5_attach,
544 * channel. * 505 .detach = unioxx5_detach,
545\* */ 506};
546 507module_comedi_driver(unioxx5_driver);
547static int __unioxx5_define_chan_offset(int chan_num)
548{
549
550 if (chan_num < 0 || chan_num > 23)
551 return -1;
552
553 return (chan_num >> 3) + 1;
554}
555 508
556MODULE_AUTHOR("Comedi http://www.comedi.org"); 509MODULE_AUTHOR("Comedi http://www.comedi.org");
557MODULE_DESCRIPTION("Comedi low-level driver"); 510MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index bf62e0dd6f69..13d9fd3efcfd 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -317,6 +317,8 @@ static struct usbduxsub usbduxsub[NUMUSBDUX];
317 317
318static DEFINE_SEMAPHORE(start_stop_sem); 318static DEFINE_SEMAPHORE(start_stop_sem);
319 319
320static struct comedi_driver driver_usbdux; /* see below for initializer */
321
320/* 322/*
321 * Stops the data acquision 323 * Stops the data acquision
322 * It should be safe to call this function from any context 324 * It should be safe to call this function from any context
@@ -2304,11 +2306,11 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2304 void *context) 2306 void *context)
2305{ 2307{
2306 struct usbduxsub *usbduxsub_tmp = context; 2308 struct usbduxsub *usbduxsub_tmp = context;
2307 struct usb_device *usbdev = usbduxsub_tmp->usbdev; 2309 struct usb_interface *uinterf = usbduxsub_tmp->interface;
2308 int ret; 2310 int ret;
2309 2311
2310 if (fw == NULL) { 2312 if (fw == NULL) {
2311 dev_err(&usbdev->dev, 2313 dev_err(&uinterf->dev,
2312 "Firmware complete handler without firmware!\n"); 2314 "Firmware complete handler without firmware!\n");
2313 return; 2315 return;
2314 } 2316 }
@@ -2320,11 +2322,11 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2320 ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size); 2322 ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size);
2321 2323
2322 if (ret) { 2324 if (ret) {
2323 dev_err(&usbdev->dev, 2325 dev_err(&uinterf->dev,
2324 "Could not upload firmware (err=%d)\n", ret); 2326 "Could not upload firmware (err=%d)\n", ret);
2325 goto out; 2327 goto out;
2326 } 2328 }
2327 comedi_usb_auto_config(usbdev, BOARDNAME); 2329 comedi_usb_auto_config(uinterf, &driver_usbdux);
2328 out: 2330 out:
2329 release_firmware(fw); 2331 release_firmware(fw);
2330} 2332}
@@ -2606,7 +2608,7 @@ static void usbduxsub_disconnect(struct usb_interface *intf)
2606 dev_err(&intf->dev, "comedi_: BUG! called with wrong ptr!!!\n"); 2608 dev_err(&intf->dev, "comedi_: BUG! called with wrong ptr!!!\n");
2607 return; 2609 return;
2608 } 2610 }
2609 comedi_usb_auto_unconfig(udev); 2611 comedi_usb_auto_unconfig(intf);
2610 down(&start_stop_sem); 2612 down(&start_stop_sem);
2611 down(&usbduxsub_tmp->sem); 2613 down(&usbduxsub_tmp->sem);
2612 tidy_up(usbduxsub_tmp); 2614 tidy_up(usbduxsub_tmp);
@@ -2615,46 +2617,21 @@ static void usbduxsub_disconnect(struct usb_interface *intf)
2615 dev_dbg(&intf->dev, "comedi_: disconnected from the usb\n"); 2617 dev_dbg(&intf->dev, "comedi_: disconnected from the usb\n");
2616} 2618}
2617 2619
2618/* is called when comedi-config is called */ 2620/* common part of attach and attach_usb */
2619static int usbdux_attach(struct comedi_device *dev, struct comedi_devconfig *it) 2621static int usbdux_attach_common(struct comedi_device *dev,
2622 struct usbduxsub *udev,
2623 void *aux_data, int aux_len)
2620{ 2624{
2621 int ret; 2625 int ret;
2622 int index;
2623 int i;
2624 struct usbduxsub *udev;
2625
2626 struct comedi_subdevice *s = NULL; 2626 struct comedi_subdevice *s = NULL;
2627 dev->private = NULL;
2628
2629 down(&start_stop_sem);
2630 /* find a valid device which has been detected by the probe function of
2631 * the usb */
2632 index = -1;
2633 for (i = 0; i < NUMUSBDUX; i++) {
2634 if ((usbduxsub[i].probed) && (!usbduxsub[i].attached)) {
2635 index = i;
2636 break;
2637 }
2638 }
2639 2627
2640 if (index < 0) {
2641 printk(KERN_ERR "comedi%d: usbdux: error: attach failed, no "
2642 "usbdux devs connected to the usb bus.\n", dev->minor);
2643 up(&start_stop_sem);
2644 return -ENODEV;
2645 }
2646
2647 udev = &usbduxsub[index];
2648 down(&udev->sem); 2628 down(&udev->sem);
2649 /* pointer back to the corresponding comedi device */ 2629 /* pointer back to the corresponding comedi device */
2650 udev->comedidev = dev; 2630 udev->comedidev = dev;
2651 2631
2652 /* trying to upload the firmware into the chip */ 2632 /* trying to upload the firmware into the chip */
2653 if (comedi_aux_data(it->options, 0) && 2633 if (aux_data)
2654 it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { 2634 firmwareUpload(udev, aux_data, aux_len);
2655 firmwareUpload(udev, comedi_aux_data(it->options, 0),
2656 it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]);
2657 }
2658 2635
2659 dev->board_name = BOARDNAME; 2636 dev->board_name = BOARDNAME;
2660 2637
@@ -2673,13 +2650,9 @@ static int usbdux_attach(struct comedi_device *dev, struct comedi_devconfig *it)
2673 dev_err(&udev->interface->dev, 2650 dev_err(&udev->interface->dev,
2674 "comedi%d: error alloc space for subdev\n", dev->minor); 2651 "comedi%d: error alloc space for subdev\n", dev->minor);
2675 up(&udev->sem); 2652 up(&udev->sem);
2676 up(&start_stop_sem);
2677 return ret; 2653 return ret;
2678 } 2654 }
2679 2655
2680 dev_info(&udev->interface->dev,
2681 "comedi%d: usb-device %d is attached to comedi.\n",
2682 dev->minor, index);
2683 /* private structure is also simply the usb-structure */ 2656 /* private structure is also simply the usb-structure */
2684 dev->private = udev; 2657 dev->private = udev;
2685 2658
@@ -2776,44 +2749,91 @@ static int usbdux_attach(struct comedi_device *dev, struct comedi_devconfig *it)
2776 2749
2777 up(&udev->sem); 2750 up(&udev->sem);
2778 2751
2779 up(&start_stop_sem);
2780
2781 dev_info(&udev->interface->dev, "comedi%d: attached to usbdux.\n", 2752 dev_info(&udev->interface->dev, "comedi%d: attached to usbdux.\n",
2782 dev->minor); 2753 dev->minor);
2783 2754
2784 return 0; 2755 return 0;
2785} 2756}
2786 2757
2787static int usbdux_detach(struct comedi_device *dev) 2758/* is called when comedi-config is called */
2759static int usbdux_attach(struct comedi_device *dev, struct comedi_devconfig *it)
2788{ 2760{
2789 struct usbduxsub *usbduxsub_tmp; 2761 int ret;
2762 int index;
2763 int i;
2764 void *aux_data;
2765 int aux_len;
2790 2766
2791 if (!dev) { 2767 dev->private = NULL;
2792 printk(KERN_ERR 2768
2793 "comedi?: usbdux: detach without dev variable...\n"); 2769 aux_data = comedi_aux_data(it->options, 0);
2794 return -EFAULT; 2770 aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH];
2771 if (aux_data == NULL)
2772 aux_len = 0;
2773 else if (aux_len == 0)
2774 aux_data = NULL;
2775
2776 down(&start_stop_sem);
2777 /* find a valid device which has been detected by the probe function of
2778 * the usb */
2779 index = -1;
2780 for (i = 0; i < NUMUSBDUX; i++) {
2781 if ((usbduxsub[i].probed) && (!usbduxsub[i].attached)) {
2782 index = i;
2783 break;
2784 }
2795 } 2785 }
2796 2786
2797 usbduxsub_tmp = dev->private; 2787 if (index < 0) {
2798 if (!usbduxsub_tmp) {
2799 printk(KERN_ERR 2788 printk(KERN_ERR
2800 "comedi?: usbdux: detach without ptr to usbduxsub[]\n"); 2789 "comedi%d: usbdux: error: attach failed, no usbdux devs connected to the usb bus.\n",
2801 return -EFAULT; 2790 dev->minor);
2802 } 2791 ret = -ENODEV;
2792 } else
2793 ret = usbdux_attach_common(dev, &usbduxsub[index],
2794 aux_data, aux_len);
2795 up(&start_stop_sem);
2796 return ret;
2797}
2803 2798
2804 dev_dbg(&usbduxsub_tmp->interface->dev, "comedi%d: detach usb device\n", 2799/* is called from comedi_usb_auto_config() */
2805 dev->minor); 2800static int usbdux_attach_usb(struct comedi_device *dev,
2801 struct usb_interface *uinterf)
2802{
2803 int ret;
2804 struct usbduxsub *this_usbduxsub;
2806 2805
2807 down(&usbduxsub_tmp->sem);
2808 /* Don't allow detach to free the private structure */
2809 /* It's one entry of of usbduxsub[] */
2810 dev->private = NULL; 2806 dev->private = NULL;
2811 usbduxsub_tmp->attached = 0; 2807
2812 usbduxsub_tmp->comedidev = NULL; 2808 down(&start_stop_sem);
2813 dev_dbg(&usbduxsub_tmp->interface->dev, 2809 this_usbduxsub = usb_get_intfdata(uinterf);
2814 "comedi%d: detach: successfully removed\n", dev->minor); 2810 if (!this_usbduxsub || !this_usbduxsub->probed) {
2815 up(&usbduxsub_tmp->sem); 2811 printk(KERN_ERR
2816 return 0; 2812 "comedi%d: usbdux: error: attach_usb failed, not connected\n",
2813 dev->minor);
2814 ret = -ENODEV;
2815 } else if (this_usbduxsub->attached) {
2816 printk(KERN_ERR
2817 "comedi%d: usbdux: error: attach_usb failed, already attached\n",
2818 dev->minor);
2819 ret = -ENODEV;
2820 } else
2821 ret = usbdux_attach_common(dev, this_usbduxsub, NULL, 0);
2822 up(&start_stop_sem);
2823 return ret;
2824}
2825
2826static void usbdux_detach(struct comedi_device *dev)
2827{
2828 struct usbduxsub *usb = dev->private;
2829
2830 if (usb) {
2831 down(&usb->sem);
2832 dev->private = NULL;
2833 usb->attached = 0;
2834 usb->comedidev = NULL;
2835 up(&usb->sem);
2836 }
2817} 2837}
2818 2838
2819/* main driver struct */ 2839/* main driver struct */
@@ -2822,6 +2842,7 @@ static struct comedi_driver driver_usbdux = {
2822 .module = THIS_MODULE, 2842 .module = THIS_MODULE,
2823 .attach = usbdux_attach, 2843 .attach = usbdux_attach,
2824 .detach = usbdux_detach, 2844 .detach = usbdux_detach,
2845 .attach_usb = usbdux_attach_usb,
2825}; 2846};
2826 2847
2827/* Table with the USB-devices: just now only testing IDs */ 2848/* Table with the USB-devices: just now only testing IDs */
diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index 2a8e725b7859..7b1d21a6fc53 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -201,6 +201,8 @@ static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
201 201
202static DEFINE_SEMAPHORE(start_stop_sem); 202static DEFINE_SEMAPHORE(start_stop_sem);
203 203
204static struct comedi_driver driver_usbduxfast; /* see below for initializer */
205
204/* 206/*
205 * bulk transfers to usbduxfast 207 * bulk transfers to usbduxfast
206 */ 208 */
@@ -453,14 +455,15 @@ static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
453 /* 7f92 to zero */ 455 /* 7f92 to zero */
454 local_transfer_buffer[0] = 0; 456 local_transfer_buffer[0] = 0;
455 /* bRequest, "Firmware" */ 457 /* bRequest, "Firmware" */
456 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), USBDUXFASTSUB_FIRMWARE, 458 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
457 VENDOR_DIR_OUT, /* bmRequestType */ 459 USBDUXFASTSUB_FIRMWARE,
458 USBDUXFASTSUB_CPUCS, /* Value */ 460 VENDOR_DIR_OUT, /* bmRequestType */
459 0x0000, /* Index */ 461 USBDUXFASTSUB_CPUCS, /* Value */
460 /* address of the transfer buffer */ 462 0x0000, /* Index */
461 local_transfer_buffer, 463 /* address of the transfer buffer */
462 1, /* Length */ 464 local_transfer_buffer,
463 EZTIMEOUT); /* Timeout */ 465 1, /* Length */
466 EZTIMEOUT); /* Timeout */
464 if (ret < 0) { 467 if (ret < 0) {
465 printk("comedi_: usbduxfast_: control msg failed (start)\n"); 468 printk("comedi_: usbduxfast_: control msg failed (start)\n");
466 return ret; 469 return ret;
@@ -477,7 +480,8 @@ static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
477 /* 7f92 to one */ 480 /* 7f92 to one */
478 local_transfer_buffer[0] = 1; 481 local_transfer_buffer[0] = 1;
479 /* bRequest, "Firmware" */ 482 /* bRequest, "Firmware" */
480 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), USBDUXFASTSUB_FIRMWARE, 483 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
484 USBDUXFASTSUB_FIRMWARE,
481 VENDOR_DIR_OUT, /* bmRequestType */ 485 VENDOR_DIR_OUT, /* bmRequestType */
482 USBDUXFASTSUB_CPUCS, /* Value */ 486 USBDUXFASTSUB_CPUCS, /* Value */
483 0x0000, /* Index */ 487 0x0000, /* Index */
@@ -504,14 +508,15 @@ static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs,
504 startAddr, local_transfer_buffer[0]); 508 startAddr, local_transfer_buffer[0]);
505#endif 509#endif
506 /* brequest, firmware */ 510 /* brequest, firmware */
507 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), USBDUXFASTSUB_FIRMWARE, 511 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
508 VENDOR_DIR_OUT, /* bmRequestType */ 512 USBDUXFASTSUB_FIRMWARE,
509 startAddr, /* value */ 513 VENDOR_DIR_OUT, /* bmRequestType */
510 0x0000, /* index */ 514 startAddr, /* value */
511 /* our local safe buffer */ 515 0x0000, /* index */
512 local_transfer_buffer, 516 /* our local safe buffer */
513 len, /* length */ 517 local_transfer_buffer,
514 EZTIMEOUT); /* timeout */ 518 len, /* length */
519 EZTIMEOUT); /* timeout */
515 520
516#ifdef CONFIG_COMEDI_DEBUG 521#ifdef CONFIG_COMEDI_DEBUG
517 printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret); 522 printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret);
@@ -1440,7 +1445,7 @@ static void usbduxfast_firmware_request_complete_handler(const struct firmware
1440 *fw, void *context) 1445 *fw, void *context)
1441{ 1446{
1442 struct usbduxfastsub_s *usbduxfastsub_tmp = context; 1447 struct usbduxfastsub_s *usbduxfastsub_tmp = context;
1443 struct usb_device *usbdev = usbduxfastsub_tmp->usbdev; 1448 struct usb_interface *uinterf = usbduxfastsub_tmp->interface;
1444 int ret; 1449 int ret;
1445 1450
1446 if (fw == NULL) 1451 if (fw == NULL)
@@ -1453,12 +1458,12 @@ static void usbduxfast_firmware_request_complete_handler(const struct firmware
1453 ret = firmwareUpload(usbduxfastsub_tmp, fw->data, fw->size); 1458 ret = firmwareUpload(usbduxfastsub_tmp, fw->data, fw->size);
1454 1459
1455 if (ret) { 1460 if (ret) {
1456 dev_err(&usbdev->dev, 1461 dev_err(&uinterf->dev,
1457 "Could not upload firmware (err=%d)\n", ret); 1462 "Could not upload firmware (err=%d)\n", ret);
1458 goto out; 1463 goto out;
1459 } 1464 }
1460 1465
1461 comedi_usb_auto_config(usbdev, BOARDNAME); 1466 comedi_usb_auto_config(uinterf, &driver_usbduxfast);
1462 out: 1467 out:
1463 release_firmware(fw); 1468 release_firmware(fw);
1464} 1469}
@@ -1606,7 +1611,7 @@ static void usbduxfastsub_disconnect(struct usb_interface *intf)
1606 return; 1611 return;
1607 } 1612 }
1608 1613
1609 comedi_usb_auto_unconfig(udev); 1614 comedi_usb_auto_unconfig(intf);
1610 1615
1611 down(&start_stop_sem); 1616 down(&start_stop_sem);
1612 down(&udfs->sem); 1617 down(&udfs->sem);
@@ -1721,43 +1726,19 @@ static int usbduxfast_attach(struct comedi_device *dev,
1721 return 0; 1726 return 0;
1722} 1727}
1723 1728
1724static int usbduxfast_detach(struct comedi_device *dev) 1729static void usbduxfast_detach(struct comedi_device *dev)
1725{ 1730{
1726 struct usbduxfastsub_s *udfs; 1731 struct usbduxfastsub_s *usb = dev->private;
1727 1732
1728 if (!dev) { 1733 if (usb) {
1729 printk(KERN_ERR "comedi?: usbduxfast: detach without dev " 1734 down(&usb->sem);
1730 "variable...\n"); 1735 down(&start_stop_sem);
1731 return -EFAULT; 1736 dev->private = NULL;
1732 } 1737 usb->attached = 0;
1733#ifdef CONFIG_COMEDI_DEBUG 1738 usb->comedidev = NULL;
1734 printk(KERN_DEBUG "comedi%d: usbduxfast: detach usb device\n", 1739 up(&start_stop_sem);
1735 dev->minor); 1740 up(&usb->sem);
1736#endif
1737
1738 udfs = dev->private;
1739 if (!udfs) {
1740 printk(KERN_ERR "comedi?: usbduxfast: detach without ptr to "
1741 "usbduxfastsub[]\n");
1742 return -EFAULT;
1743 } 1741 }
1744
1745 down(&udfs->sem);
1746 down(&start_stop_sem);
1747 /*
1748 * Don't allow detach to free the private structure
1749 * It's one entry of of usbduxfastsub[]
1750 */
1751 dev->private = NULL;
1752 udfs->attached = 0;
1753 udfs->comedidev = NULL;
1754#ifdef CONFIG_COMEDI_DEBUG
1755 printk(KERN_DEBUG "comedi%d: usbduxfast: detach: successfully "
1756 "removed\n", dev->minor);
1757#endif
1758 up(&start_stop_sem);
1759 up(&udfs->sem);
1760 return 0;
1761} 1742}
1762 1743
1763/* 1744/*
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index 63c9b6dbc317..465afbdf4069 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -267,6 +267,8 @@ static struct usbduxsub usbduxsub[NUMUSBDUX];
267 267
268static DEFINE_SEMAPHORE(start_stop_sem); 268static DEFINE_SEMAPHORE(start_stop_sem);
269 269
270static struct comedi_driver driver_usbduxsigma; /* see below for initializer */
271
270/* 272/*
271 * Stops the data acquision 273 * Stops the data acquision
272 * It should be safe to call this function from any context 274 * It should be safe to call this function from any context
@@ -2312,11 +2314,11 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2312 void *context) 2314 void *context)
2313{ 2315{
2314 struct usbduxsub *usbduxsub_tmp = context; 2316 struct usbduxsub *usbduxsub_tmp = context;
2315 struct usb_device *usbdev = usbduxsub_tmp->usbdev; 2317 struct usb_interface *uinterf = usbduxsub_tmp->interface;
2316 int ret; 2318 int ret;
2317 2319
2318 if (fw == NULL) { 2320 if (fw == NULL) {
2319 dev_err(&usbdev->dev, 2321 dev_err(&uinterf->dev,
2320 "Firmware complete handler without firmware!\n"); 2322 "Firmware complete handler without firmware!\n");
2321 return; 2323 return;
2322 } 2324 }
@@ -2328,11 +2330,11 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2328 ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size); 2330 ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size);
2329 2331
2330 if (ret) { 2332 if (ret) {
2331 dev_err(&usbdev->dev, 2333 dev_err(&uinterf->dev,
2332 "Could not upload firmware (err=%d)\n", ret); 2334 "Could not upload firmware (err=%d)\n", ret);
2333 goto out; 2335 goto out;
2334 } 2336 }
2335 comedi_usb_auto_config(usbdev, BOARDNAME); 2337 comedi_usb_auto_config(uinterf, &driver_usbduxsigma);
2336out: 2338out:
2337 release_firmware(fw); 2339 release_firmware(fw);
2338} 2340}
@@ -2623,7 +2625,7 @@ static void usbduxsigma_disconnect(struct usb_interface *intf)
2623 if (usbduxsub_tmp->ao_cmd_running) 2625 if (usbduxsub_tmp->ao_cmd_running)
2624 /* we are still running a command */ 2626 /* we are still running a command */
2625 usbdux_ao_stop(usbduxsub_tmp, 1); 2627 usbdux_ao_stop(usbduxsub_tmp, 1);
2626 comedi_usb_auto_unconfig(udev); 2628 comedi_usb_auto_unconfig(intf);
2627 down(&start_stop_sem); 2629 down(&start_stop_sem);
2628 down(&usbduxsub_tmp->sem); 2630 down(&usbduxsub_tmp->sem);
2629 tidy_up(usbduxsub_tmp); 2631 tidy_up(usbduxsub_tmp);
@@ -2799,37 +2801,17 @@ static int usbduxsigma_attach(struct comedi_device *dev,
2799 return 0; 2801 return 0;
2800} 2802}
2801 2803
2802static int usbduxsigma_detach(struct comedi_device *dev) 2804static void usbduxsigma_detach(struct comedi_device *dev)
2803{ 2805{
2804 struct usbduxsub *usbduxsub_tmp; 2806 struct usbduxsub *usb = dev->private;
2805 2807
2806 if (!dev) { 2808 if (usb) {
2807 printk(KERN_ERR 2809 down(&usb->sem);
2808 "comedi? usbduxsigma detach: dev=NULL\n"); 2810 dev->private = NULL;
2809 return -EFAULT; 2811 usb->attached = 0;
2812 usb->comedidev = NULL;
2813 up(&usb->sem);
2810 } 2814 }
2811
2812 usbduxsub_tmp = dev->private;
2813 if (!usbduxsub_tmp) {
2814 printk(KERN_ERR
2815 "comedi?: usbduxsigma detach: private=NULL\n");
2816 return -EFAULT;
2817 }
2818
2819 dev_dbg(&usbduxsub_tmp->interface->dev,
2820 "comedi%d: detach usb device\n",
2821 dev->minor);
2822
2823 down(&usbduxsub_tmp->sem);
2824 /* Don't allow detach to free the private structure */
2825 /* It's one entry of of usbduxsub[] */
2826 dev->private = NULL;
2827 usbduxsub_tmp->attached = 0;
2828 usbduxsub_tmp->comedidev = NULL;
2829 dev_info(&usbduxsub_tmp->interface->dev,
2830 "comedi%d: successfully detached.\n", dev->minor);
2831 up(&usbduxsub_tmp->sem);
2832 return 0;
2833} 2815}
2834 2816
2835/* main driver struct */ 2817/* main driver struct */
diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c
index 2dba3efdacfa..baee8d767636 100644
--- a/drivers/staging/comedi/drivers/vmk80xx.c
+++ b/drivers/staging/comedi/drivers/vmk80xx.c
@@ -151,27 +151,12 @@ MODULE_DEVICE_TABLE(usb, vmk80xx_id_table);
151#define URB_RCV_FLAG (1 << 0) 151#define URB_RCV_FLAG (1 << 0)
152#define URB_SND_FLAG (1 << 1) 152#define URB_SND_FLAG (1 << 1)
153 153
154#define CONFIG_VMK80XX_DEBUG
155#undef CONFIG_VMK80XX_DEBUG
156
157#ifdef CONFIG_VMK80XX_DEBUG
158static int dbgvm = 1;
159#else
160static int dbgvm;
161#endif
162
163#ifdef CONFIG_COMEDI_DEBUG 154#ifdef CONFIG_COMEDI_DEBUG
164static int dbgcm = 1; 155static int dbgcm = 1;
165#else 156#else
166static int dbgcm; 157static int dbgcm;
167#endif 158#endif
168 159
169#define dbgvm(fmt, arg...) \
170do { \
171 if (dbgvm) \
172 printk(KERN_DEBUG fmt, ##arg); \
173} while (0)
174
175#define dbgcm(fmt, arg...) \ 160#define dbgcm(fmt, arg...) \
176do { \ 161do { \
177 if (dbgcm) \ 162 if (dbgcm) \
@@ -247,13 +232,13 @@ static struct vmk80xx_usb vmb[VMK80XX_MAX_BOARDS];
247 232
248static DEFINE_MUTEX(glb_mutex); 233static DEFINE_MUTEX(glb_mutex);
249 234
235static struct comedi_driver driver_vmk80xx; /* see below for initializer */
236
250static void vmk80xx_tx_callback(struct urb *urb) 237static void vmk80xx_tx_callback(struct urb *urb)
251{ 238{
252 struct vmk80xx_usb *dev = urb->context; 239 struct vmk80xx_usb *dev = urb->context;
253 int stat = urb->status; 240 int stat = urb->status;
254 241
255 dbgvm("vmk80xx: %s\n", __func__);
256
257 if (stat && !(stat == -ENOENT 242 if (stat && !(stat == -ENOENT
258 || stat == -ECONNRESET || stat == -ESHUTDOWN)) 243 || stat == -ECONNRESET || stat == -ESHUTDOWN))
259 dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", 244 dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
@@ -272,8 +257,6 @@ static void vmk80xx_rx_callback(struct urb *urb)
272 struct vmk80xx_usb *dev = urb->context; 257 struct vmk80xx_usb *dev = urb->context;
273 int stat = urb->status; 258 int stat = urb->status;
274 259
275 dbgvm("vmk80xx: %s\n", __func__);
276
277 switch (stat) { 260 switch (stat) {
278 case 0: 261 case 0:
279 break; 262 break;
@@ -314,8 +297,6 @@ static int vmk80xx_check_data_link(struct vmk80xx_usb *dev)
314 unsigned char tx[1]; 297 unsigned char tx[1];
315 unsigned char rx[2]; 298 unsigned char rx[2];
316 299
317 dbgvm("vmk80xx: %s\n", __func__);
318
319 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); 300 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01);
320 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); 301 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81);
321 302
@@ -340,8 +321,6 @@ static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag)
340 unsigned char rx[64]; 321 unsigned char rx[64];
341 int cnt; 322 int cnt;
342 323
343 dbgvm("vmk80xx: %s\n", __func__);
344
345 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); 324 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01);
346 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); 325 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81);
347 326
@@ -369,8 +348,6 @@ static int vmk80xx_reset_device(struct vmk80xx_usb *dev)
369 int ival; 348 int ival;
370 size_t size; 349 size_t size;
371 350
372 dbgvm("vmk80xx: %s\n", __func__);
373
374 urb = usb_alloc_urb(0, GFP_KERNEL); 351 urb = usb_alloc_urb(0, GFP_KERNEL);
375 if (!urb) 352 if (!urb)
376 return -ENOMEM; 353 return -ENOMEM;
@@ -408,8 +385,6 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag)
408 void (*callback) (struct urb *); 385 void (*callback) (struct urb *);
409 int ival; 386 int ival;
410 387
411 dbgvm("vmk80xx: %s\n", __func__);
412
413 if (flag & URB_RCV_FLAG) { 388 if (flag & URB_RCV_FLAG) {
414 rx_addr = dev->ep_rx->bEndpointAddress; 389 rx_addr = dev->ep_rx->bEndpointAddress;
415 pipe = usb_rcvintpipe(dev->udev, rx_addr); 390 pipe = usb_rcvintpipe(dev->udev, rx_addr);
@@ -437,8 +412,6 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev)
437 unsigned int rx_pipe; 412 unsigned int rx_pipe;
438 size_t size; 413 size_t size;
439 414
440 dbgvm("vmk80xx: %s\n", __func__);
441
442 set_bit(TRANS_IN_BUSY, &dev->flags); 415 set_bit(TRANS_IN_BUSY, &dev->flags);
443 set_bit(TRANS_OUT_BUSY, &dev->flags); 416 set_bit(TRANS_OUT_BUSY, &dev->flags);
444 417
@@ -466,8 +439,6 @@ static int vmk80xx_read_packet(struct vmk80xx_usb *dev)
466 struct urb *urb; 439 struct urb *urb;
467 int retval; 440 int retval;
468 441
469 dbgvm("vmk80xx: %s\n", __func__);
470
471 if (!dev->intf) 442 if (!dev->intf)
472 return -ENODEV; 443 return -ENODEV;
473 444
@@ -514,8 +485,6 @@ static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd)
514 struct urb *urb; 485 struct urb *urb;
515 int retval; 486 int retval;
516 487
517 dbgvm("vmk80xx: %s\n", __func__);
518
519 if (!dev->intf) 488 if (!dev->intf)
520 return -ENODEV; 489 return -ENODEV;
521 490
@@ -590,8 +559,6 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev,
590 int reg[2]; 559 int reg[2];
591 int n; 560 int n;
592 561
593 dbgvm("vmk80xx: %s\n", __func__);
594
595 n = rudimentary_check(dev, DIR_IN); 562 n = rudimentary_check(dev, DIR_IN);
596 if (n) 563 if (n)
597 return n; 564 return n;
@@ -643,8 +610,6 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev,
643 int reg; 610 int reg;
644 int n; 611 int n;
645 612
646 dbgvm("vmk80xx: %s\n", __func__);
647
648 n = rudimentary_check(dev, DIR_OUT); 613 n = rudimentary_check(dev, DIR_OUT);
649 if (n) 614 if (n)
650 return n; 615 return n;
@@ -688,8 +653,6 @@ static int vmk80xx_ao_rinsn(struct comedi_device *cdev,
688 int reg; 653 int reg;
689 int n; 654 int n;
690 655
691 dbgvm("vmk80xx: %s\n", __func__);
692
693 n = rudimentary_check(dev, DIR_IN); 656 n = rudimentary_check(dev, DIR_IN);
694 if (n) 657 if (n)
695 return n; 658 return n;
@@ -722,8 +685,6 @@ static int vmk80xx_di_bits(struct comedi_device *cdev,
722 int reg; 685 int reg;
723 int retval; 686 int retval;
724 687
725 dbgvm("vmk80xx: %s\n", __func__);
726
727 retval = rudimentary_check(dev, DIR_IN); 688 retval = rudimentary_check(dev, DIR_IN);
728 if (retval) 689 if (retval)
729 return retval; 690 return retval;
@@ -768,8 +729,6 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev,
768 int inp; 729 int inp;
769 int n; 730 int n;
770 731
771 dbgvm("vmk80xx: %s\n", __func__);
772
773 n = rudimentary_check(dev, DIR_IN); 732 n = rudimentary_check(dev, DIR_IN);
774 if (n) 733 if (n)
775 return n; 734 return n;
@@ -815,8 +774,6 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev,
815 int cmd; 774 int cmd;
816 int n; 775 int n;
817 776
818 dbgvm("vmk80xx: %s\n", __func__);
819
820 n = rudimentary_check(dev, DIR_OUT); 777 n = rudimentary_check(dev, DIR_OUT);
821 if (n) 778 if (n)
822 return n; 779 return n;
@@ -863,8 +820,6 @@ static int vmk80xx_do_rinsn(struct comedi_device *cdev,
863 int reg; 820 int reg;
864 int n; 821 int n;
865 822
866 dbgvm("vmk80xx: %s\n", __func__);
867
868 n = rudimentary_check(dev, DIR_IN); 823 n = rudimentary_check(dev, DIR_IN);
869 if (n) 824 if (n)
870 return n; 825 return n;
@@ -897,8 +852,6 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
897 int dir, reg, cmd; 852 int dir, reg, cmd;
898 int retval; 853 int retval;
899 854
900 dbgvm("vmk80xx: %s\n", __func__);
901
902 dir = 0; 855 dir = 0;
903 856
904 if (data[0]) 857 if (data[0])
@@ -964,8 +917,6 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev,
964 int reg[2]; 917 int reg[2];
965 int n; 918 int n;
966 919
967 dbgvm("vmk80xx: %s\n", __func__);
968
969 n = rudimentary_check(dev, DIR_IN); 920 n = rudimentary_check(dev, DIR_IN);
970 if (n) 921 if (n)
971 return n; 922 return n;
@@ -1014,18 +965,16 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev,
1014 int reg; 965 int reg;
1015 int n; 966 int n;
1016 967
1017 dbgvm("vmk80xx: %s\n", __func__);
1018
1019 n = rudimentary_check(dev, DIR_OUT); 968 n = rudimentary_check(dev, DIR_OUT);
1020 if (n) 969 if (n)
1021 return n; 970 return n;
1022 971
1023 down(&dev->limit_sem);
1024
1025 insn_cmd = data[0]; 972 insn_cmd = data[0];
1026 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) 973 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET)
1027 return -EINVAL; 974 return -EINVAL;
1028 975
976 down(&dev->limit_sem);
977
1029 chan = CR_CHAN(insn->chanspec); 978 chan = CR_CHAN(insn->chanspec);
1030 979
1031 if (dev->board.model == VMK8055_MODEL) { 980 if (dev->board.model == VMK8055_MODEL) {
@@ -1062,8 +1011,6 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev,
1062 int cmd; 1011 int cmd;
1063 int n; 1012 int n;
1064 1013
1065 dbgvm("vmk80xx: %s\n", __func__);
1066
1067 n = rudimentary_check(dev, DIR_OUT); 1014 n = rudimentary_check(dev, DIR_OUT);
1068 if (n) 1015 if (n)
1069 return n; 1016 return n;
@@ -1108,8 +1055,6 @@ static int vmk80xx_pwm_rinsn(struct comedi_device *cdev,
1108 int reg[2]; 1055 int reg[2];
1109 int n; 1056 int n;
1110 1057
1111 dbgvm("vmk80xx: %s\n", __func__);
1112
1113 n = rudimentary_check(dev, DIR_IN); 1058 n = rudimentary_check(dev, DIR_IN);
1114 if (n) 1059 if (n)
1115 return n; 1060 return n;
@@ -1143,8 +1088,6 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev,
1143 int cmd; 1088 int cmd;
1144 int n; 1089 int n;
1145 1090
1146 dbgvm("vmk80xx: %s\n", __func__);
1147
1148 n = rudimentary_check(dev, DIR_OUT); 1091 n = rudimentary_check(dev, DIR_OUT);
1149 if (n) 1092 if (n)
1150 return n; 1093 return n;
@@ -1193,8 +1136,6 @@ static int vmk80xx_attach(struct comedi_device *cdev,
1193 struct comedi_subdevice *s; 1136 struct comedi_subdevice *s;
1194 int minor; 1137 int minor;
1195 1138
1196 dbgvm("vmk80xx: %s\n", __func__);
1197
1198 mutex_lock(&glb_mutex); 1139 mutex_lock(&glb_mutex);
1199 1140
1200 for (i = 0; i < VMK80XX_MAX_BOARDS; i++) 1141 for (i = 0; i < VMK80XX_MAX_BOARDS; i++)
@@ -1309,34 +1250,16 @@ static int vmk80xx_attach(struct comedi_device *cdev,
1309 return 0; 1250 return 0;
1310} 1251}
1311 1252
1312static int vmk80xx_detach(struct comedi_device *cdev) 1253static void vmk80xx_detach(struct comedi_device *dev)
1313{ 1254{
1314 struct vmk80xx_usb *dev; 1255 struct vmk80xx_usb *usb = dev->private;
1315 int minor;
1316
1317 dbgvm("vmk80xx: %s\n", __func__);
1318
1319 if (!cdev)
1320 return -EFAULT;
1321
1322 dev = cdev->private;
1323 if (!dev)
1324 return -EFAULT;
1325 1256
1326 down(&dev->limit_sem); 1257 if (usb) {
1327 1258 down(&usb->limit_sem);
1328 cdev->private = NULL; 1259 dev->private = NULL;
1329 dev->attached = 0; 1260 usb->attached = 0;
1330 1261 up(&usb->limit_sem);
1331 minor = cdev->minor; 1262 }
1332
1333 printk(KERN_INFO
1334 "comedi%d: vmk80xx: board #%d [%s] detached from comedi\n",
1335 minor, dev->count, dev->board.name);
1336
1337 up(&dev->limit_sem);
1338
1339 return 0;
1340} 1263}
1341 1264
1342static int vmk80xx_probe(struct usb_interface *intf, 1265static int vmk80xx_probe(struct usb_interface *intf,
@@ -1348,8 +1271,6 @@ static int vmk80xx_probe(struct usb_interface *intf,
1348 struct usb_endpoint_descriptor *ep_desc; 1271 struct usb_endpoint_descriptor *ep_desc;
1349 size_t size; 1272 size_t size;
1350 1273
1351 dbgvm("vmk80xx: %s\n", __func__);
1352
1353 mutex_lock(&glb_mutex); 1274 mutex_lock(&glb_mutex);
1354 1275
1355 for (i = 0; i < VMK80XX_MAX_BOARDS; i++) 1276 for (i = 0; i < VMK80XX_MAX_BOARDS; i++)
@@ -1484,7 +1405,7 @@ static int vmk80xx_probe(struct usb_interface *intf,
1484 1405
1485 mutex_unlock(&glb_mutex); 1406 mutex_unlock(&glb_mutex);
1486 1407
1487 comedi_usb_auto_config(dev->udev, BOARDNAME); 1408 comedi_usb_auto_config(intf, &driver_vmk80xx);
1488 1409
1489 return 0; 1410 return 0;
1490error: 1411error:
@@ -1497,12 +1418,10 @@ static void vmk80xx_disconnect(struct usb_interface *intf)
1497{ 1418{
1498 struct vmk80xx_usb *dev = usb_get_intfdata(intf); 1419 struct vmk80xx_usb *dev = usb_get_intfdata(intf);
1499 1420
1500 dbgvm("vmk80xx: %s\n", __func__);
1501
1502 if (!dev) 1421 if (!dev)
1503 return; 1422 return;
1504 1423
1505 comedi_usb_auto_unconfig(dev->udev); 1424 comedi_usb_auto_unconfig(intf);
1506 1425
1507 mutex_lock(&glb_mutex); 1426 mutex_lock(&glb_mutex);
1508 down(&dev->limit_sem); 1427 down(&dev->limit_sem);
diff --git a/drivers/staging/comedi/internal.h b/drivers/staging/comedi/internal.h
index 434ce3433368..7ed20a04eef5 100644
--- a/drivers/staging/comedi/internal.h
+++ b/drivers/staging/comedi/internal.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * various internal comedi functions 2 * various internal comedi stuff
3 */ 3 */
4int do_rangeinfo_ioctl(struct comedi_device *dev, 4int do_rangeinfo_ioctl(struct comedi_device *dev,
5 struct comedi_rangeinfo __user *arg); 5 struct comedi_rangeinfo __user *arg);
@@ -7,6 +7,10 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
7 struct comedi_insn *insn, unsigned int *data); 7 struct comedi_insn *insn, unsigned int *data);
8int comedi_alloc_board_minor(struct device *hardware_device); 8int comedi_alloc_board_minor(struct device *hardware_device);
9void comedi_free_board_minor(unsigned minor); 9void comedi_free_board_minor(unsigned minor);
10int comedi_find_board_minor(struct device *hardware_device);
10void comedi_reset_async_buf(struct comedi_async *async); 11void comedi_reset_async_buf(struct comedi_async *async);
11int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, 12int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
12 unsigned long new_size); 13 unsigned long new_size);
14
15extern unsigned int comedi_default_buf_size_kb;
16extern unsigned int comedi_default_buf_maxsize_kb;
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 886f5650444e..5b11c5e3622e 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -1710,7 +1710,8 @@ static int et131x_mdio_read(struct mii_bus *bus, int phy_addr, int reg)
1710 return value; 1710 return value;
1711} 1711}
1712 1712
1713static int et131x_mdio_write(struct mii_bus *bus, int phy_addr, int reg, u16 value) 1713static int et131x_mdio_write(struct mii_bus *bus, int phy_addr,
1714 int reg, u16 value)
1714{ 1715{
1715 struct net_device *netdev = bus->priv; 1716 struct net_device *netdev = bus->priv;
1716 struct et131x_adapter *adapter = netdev_priv(netdev); 1717 struct et131x_adapter *adapter = netdev_priv(netdev);
@@ -4013,7 +4014,7 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
4013 dev_err(&pdev->dev, "Missing PCIe capabilities\n"); 4014 dev_err(&pdev->dev, "Missing PCIe capabilities\n");
4014 goto err_out; 4015 goto err_out;
4015 } 4016 }
4016 4017
4017 /* Let's set up the PORT LOGIC Register. First we need to know what 4018 /* Let's set up the PORT LOGIC Register. First we need to know what
4018 * the max_payload_size is 4019 * the max_payload_size is
4019 */ 4020 */
@@ -4060,7 +4061,7 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
4060 goto err_out; 4061 goto err_out;
4061 } 4062 }
4062 4063
4063 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | ( 0x04 << 12); 4064 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | (0x04 << 12);
4064 4065
4065 if (pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl)) { 4066 if (pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl)) {
4066 dev_err(&pdev->dev, 4067 dev_err(&pdev->dev,
@@ -4824,7 +4825,8 @@ static int et131x_open(struct net_device *netdev)
4824 adapter->error_timer.data = (unsigned long)adapter; 4825 adapter->error_timer.data = (unsigned long)adapter;
4825 add_timer(&adapter->error_timer); 4826 add_timer(&adapter->error_timer);
4826 4827
4827 result = request_irq(irq, et131x_isr, IRQF_SHARED, netdev->name, netdev); 4828 result = request_irq(irq, et131x_isr,
4829 IRQF_SHARED, netdev->name, netdev);
4828 if (result) { 4830 if (result) {
4829 dev_err(&pdev->dev, "could not register IRQ %d\n", irq); 4831 dev_err(&pdev->dev, "could not register IRQ %d\n", irq);
4830 return result; 4832 return result;
diff --git a/drivers/staging/gdm72xx/Kconfig b/drivers/staging/gdm72xx/Kconfig
new file mode 100644
index 000000000000..3c18efe31365
--- /dev/null
+++ b/drivers/staging/gdm72xx/Kconfig
@@ -0,0 +1,46 @@
1#
2# GCT GDM72xx WiMAX driver configuration
3#
4
5menuconfig WIMAX_GDM72XX
6 tristate "GCT GDM72xx WiMAX support"
7 depends on NET
8 help
9 Support for the GCT GDM72xx WiMAX chip
10
11if WIMAX_GDM72XX
12
13config WIMAX_GDM72XX_QOS
14 bool "Enable QoS support"
15 default n
16
17config WIMAX_GDM72XX_K_MODE
18 bool "Enable K mode"
19 default n
20
21config WIMAX_GDM72XX_WIMAX2
22 bool "Enable WIMAX2 support"
23 default n
24
25choice
26 prompt "Select interface"
27
28config WIMAX_GDM72XX_USB
29 bool "USB interface"
30 depends on USB
31
32config WIMAX_GDM72XX_SDIO
33 bool "SDIO interface"
34 depends on MMC
35
36endchoice
37
38if WIMAX_GDM72XX_USB
39
40config WIMAX_GDM72XX_USB_PM
41 bool "Enable power managerment support"
42 depends on USB_SUSPEND
43
44endif # WIMAX_GDM72XX_USB
45
46endif # WIMAX_GDM72XX
diff --git a/drivers/staging/gdm72xx/Makefile b/drivers/staging/gdm72xx/Makefile
new file mode 100644
index 000000000000..35da7b90b19b
--- /dev/null
+++ b/drivers/staging/gdm72xx/Makefile
@@ -0,0 +1,6 @@
1obj-$(CONFIG_WIMAX_GDM72XX) := gdmwm.o
2
3gdmwm-y += gdm_wimax.o netlink_k.o
4gdmwm-$(CONFIG_WIMAX_GDM72XX_QOS) += gdm_qos.o
5gdmwm-$(CONFIG_WIMAX_GDM72XX_SDIO) += gdm_sdio.o sdio_boot.o
6gdmwm-$(CONFIG_WIMAX_GDM72XX_USB) += gdm_usb.o usb_boot.o
diff --git a/drivers/staging/gdm72xx/TODO b/drivers/staging/gdm72xx/TODO
new file mode 100644
index 000000000000..30ac01ab972f
--- /dev/null
+++ b/drivers/staging/gdm72xx/TODO
@@ -0,0 +1,5 @@
1TODO:
2- Replace kernel_thread with kthread in gdm_usb.c
3- Replace hard-coded firmware paths with request_firmware in
4 sdio_boot.c and usb_boot.c
5- Clean up coding style to meet kernel standard.
diff --git a/drivers/staging/gdm72xx/gdm_qos.c b/drivers/staging/gdm72xx/gdm_qos.c
new file mode 100644
index 000000000000..0217680ec545
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_qos.c
@@ -0,0 +1,460 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/version.h>
15#include <linux/etherdevice.h>
16#include <asm/byteorder.h>
17
18#include <linux/ip.h>
19#include <linux/tcp.h>
20#include <linux/if_ether.h>
21
22#include "gdm_wimax.h"
23#include "hci.h"
24#include "gdm_qos.h"
25
26#define B2H(x) __be16_to_cpu(x)
27
28#undef dprintk
29#define dprintk(fmt, args ...) printk(KERN_DEBUG "[QoS] " fmt, ## args)
30#undef wprintk
31#define wprintk(fmt, args ...) \
32 printk(KERN_WARNING "[QoS WARNING] " fmt, ## args)
33#undef eprintk
34#define eprintk(fmt, args ...) printk(KERN_ERR "[QoS ERROR] " fmt, ## args)
35
36
37#define MAX_FREE_LIST_CNT 32
38static struct {
39 struct list_head head;
40 int cnt;
41 spinlock_t lock;
42} qos_free_list;
43
44static void init_qos_entry_list(void)
45{
46 qos_free_list.cnt = 0;
47 INIT_LIST_HEAD(&qos_free_list.head);
48 spin_lock_init(&qos_free_list.lock);
49}
50
51static void *alloc_qos_entry(void)
52{
53 struct qos_entry_s *entry;
54 unsigned long flags;
55
56 spin_lock_irqsave(&qos_free_list.lock, flags);
57 if (qos_free_list.cnt) {
58 entry = list_entry(qos_free_list.head.prev, struct qos_entry_s,
59 list);
60 list_del(&entry->list);
61 qos_free_list.cnt--;
62 spin_unlock_irqrestore(&qos_free_list.lock, flags);
63 return entry;
64 }
65 spin_unlock_irqrestore(&qos_free_list.lock, flags);
66
67 entry = kmalloc(sizeof(struct qos_entry_s), GFP_ATOMIC);
68 return entry;
69}
70
71static void free_qos_entry(void *entry)
72{
73 struct qos_entry_s *qentry = (struct qos_entry_s *) entry;
74 unsigned long flags;
75
76 spin_lock_irqsave(&qos_free_list.lock, flags);
77 if (qos_free_list.cnt < MAX_FREE_LIST_CNT) {
78 list_add(&qentry->list, &qos_free_list.head);
79 qos_free_list.cnt++;
80 spin_unlock_irqrestore(&qos_free_list.lock, flags);
81 return;
82 }
83 spin_unlock_irqrestore(&qos_free_list.lock, flags);
84
85 kfree(entry);
86}
87
88static void free_qos_entry_list(struct list_head *free_list)
89{
90 struct qos_entry_s *entry, *n;
91 int total_free = 0;
92
93 list_for_each_entry_safe(entry, n, free_list, list) {
94 list_del(&entry->list);
95 kfree(entry);
96 total_free++;
97 }
98
99 dprintk("%s: total_free_cnt=%d\n", __func__, total_free);
100}
101
102void gdm_qos_init(void *nic_ptr)
103{
104 struct nic *nic = nic_ptr;
105 struct qos_cb_s *qcb = &nic->qos;
106 int i;
107
108 for (i = 0 ; i < QOS_MAX; i++) {
109 INIT_LIST_HEAD(&qcb->qos_list[i]);
110 qcb->csr[i].QoSBufCount = 0;
111 qcb->csr[i].Enabled = 0;
112 }
113
114 qcb->qos_list_cnt = 0;
115 qcb->qos_null_idx = QOS_MAX-1;
116 qcb->qos_limit_size = 255;
117
118 spin_lock_init(&qcb->qos_lock);
119
120 init_qos_entry_list();
121}
122
123void gdm_qos_release_list(void *nic_ptr)
124{
125 struct nic *nic = nic_ptr;
126 struct qos_cb_s *qcb = &nic->qos;
127 unsigned long flags;
128 struct qos_entry_s *entry, *n;
129 struct list_head free_list;
130 int i;
131
132 INIT_LIST_HEAD(&free_list);
133
134 spin_lock_irqsave(&qcb->qos_lock, flags);
135
136 for (i = 0; i < QOS_MAX; i++) {
137 qcb->csr[i].QoSBufCount = 0;
138 qcb->csr[i].Enabled = 0;
139 }
140
141 qcb->qos_list_cnt = 0;
142 qcb->qos_null_idx = QOS_MAX-1;
143
144 for (i = 0; i < QOS_MAX; i++) {
145 list_for_each_entry_safe(entry, n, &qcb->qos_list[i], list) {
146 list_move_tail(&entry->list, &free_list);
147 }
148 }
149 spin_unlock_irqrestore(&qcb->qos_lock, flags);
150 free_qos_entry_list(&free_list);
151}
152
153static u32 chk_ipv4_rule(struct gdm_wimax_csr_s *csr, u8 *Stream, u8 *port)
154{
155 int i;
156
157 if (csr->ClassifierRuleEnable&IPTYPEOFSERVICE) {
158 if (((Stream[1] & csr->IPToSMask) < csr->IPToSLow) ||
159 ((Stream[1] & csr->IPToSMask) > csr->IPToSHigh))
160 return 1;
161 }
162
163 if (csr->ClassifierRuleEnable&PROTOCOL) {
164 if (Stream[9] != csr->Protocol)
165 return 1;
166 }
167
168 if (csr->ClassifierRuleEnable&IPMASKEDSRCADDRESS) {
169 for (i = 0; i < 4; i++) {
170 if ((Stream[12 + i] & csr->IPSrcAddrMask[i]) !=
171 (csr->IPSrcAddr[i] & csr->IPSrcAddrMask[i]))
172 return 1;
173 }
174 }
175
176 if (csr->ClassifierRuleEnable&IPMASKEDDSTADDRESS) {
177 for (i = 0; i < 4; i++) {
178 if ((Stream[16 + i] & csr->IPDstAddrMask[i]) !=
179 (csr->IPDstAddr[i] & csr->IPDstAddrMask[i]))
180 return 1;
181 }
182 }
183
184 if (csr->ClassifierRuleEnable&PROTOCOLSRCPORTRANGE) {
185 i = ((port[0]<<8)&0xff00)+port[1];
186 if ((i < csr->SrcPortLow) || (i > csr->SrcPortHigh))
187 return 1;
188 }
189
190 if (csr->ClassifierRuleEnable&PROTOCOLDSTPORTRANGE) {
191 i = ((port[2]<<8)&0xff00)+port[3];
192 if ((i < csr->DstPortLow) || (i > csr->DstPortHigh))
193 return 1;
194 }
195
196 return 0;
197}
198
199static u32 get_qos_index(struct nic *nic, u8* iph, u8* tcpudph)
200{
201 u32 IP_Ver, Header_Len, i;
202 struct qos_cb_s *qcb = &nic->qos;
203
204 if (iph == NULL || tcpudph == NULL)
205 return -1;
206
207 IP_Ver = (iph[0]>>4)&0xf;
208 Header_Len = iph[0]&0xf;
209
210 if (IP_Ver == 4) {
211 for (i = 0; i < QOS_MAX; i++) {
212 if (qcb->csr[i].Enabled) {
213 if (qcb->csr[i].ClassifierRuleEnable) {
214 if (chk_ipv4_rule(&qcb->csr[i], iph,
215 tcpudph) == 0)
216 return i;
217 }
218 }
219 }
220 }
221
222 return -1;
223}
224
225static u32 extract_qos_list(struct nic *nic, struct list_head *head)
226{
227 struct qos_cb_s *qcb = &nic->qos;
228 struct qos_entry_s *entry;
229 int i;
230
231 INIT_LIST_HEAD(head);
232
233 for (i = 0; i < QOS_MAX; i++) {
234 if (qcb->csr[i].Enabled) {
235 if (qcb->csr[i].QoSBufCount < qcb->qos_limit_size) {
236 if (!list_empty(&qcb->qos_list[i])) {
237 entry = list_entry(
238 qcb->qos_list[i].prev,
239 struct qos_entry_s, list);
240 list_move_tail(&entry->list, head);
241 qcb->csr[i].QoSBufCount++;
242
243 if (!list_empty(&qcb->qos_list[i]))
244 wprintk("QoS Index(%d) "
245 "is piled!!\n", i);
246 }
247 }
248 }
249 }
250
251 return 0;
252}
253
254static void send_qos_list(struct nic *nic, struct list_head *head)
255{
256 struct qos_entry_s *entry, *n;
257
258 list_for_each_entry_safe(entry, n, head, list) {
259 list_del(&entry->list);
260 free_qos_entry(entry);
261 gdm_wimax_send_tx(entry->skb, entry->dev);
262 }
263}
264
265int gdm_qos_send_hci_pkt(struct sk_buff *skb, struct net_device *dev)
266{
267 struct nic *nic = netdev_priv(dev);
268 int index;
269 struct qos_cb_s *qcb = &nic->qos;
270 unsigned long flags;
271 struct ethhdr *ethh = (struct ethhdr *) (skb->data + HCI_HEADER_SIZE);
272 struct iphdr *iph = (struct iphdr *) ((char *) ethh + ETH_HLEN);
273 struct tcphdr *tcph;
274 struct qos_entry_s *entry = NULL;
275 struct list_head send_list;
276 int ret = 0;
277
278 tcph = (struct tcphdr *) iph + iph->ihl*4;
279
280 if (B2H(ethh->h_proto) == ETH_P_IP) {
281 if (qcb->qos_list_cnt && !qos_free_list.cnt) {
282 entry = alloc_qos_entry();
283 entry->skb = skb;
284 entry->dev = dev;
285 dprintk("qcb->qos_list_cnt=%d\n", qcb->qos_list_cnt);
286 }
287
288 spin_lock_irqsave(&qcb->qos_lock, flags);
289 if (qcb->qos_list_cnt) {
290 index = get_qos_index(nic, (u8 *)iph, (u8 *) tcph);
291 if (index == -1)
292 index = qcb->qos_null_idx;
293
294 if (!entry) {
295 entry = alloc_qos_entry();
296 entry->skb = skb;
297 entry->dev = dev;
298 }
299
300 list_add_tail(&entry->list, &qcb->qos_list[index]);
301 extract_qos_list(nic, &send_list);
302 spin_unlock_irqrestore(&qcb->qos_lock, flags);
303 send_qos_list(nic, &send_list);
304 goto out;
305 }
306 spin_unlock_irqrestore(&qcb->qos_lock, flags);
307 if (entry)
308 free_qos_entry(entry);
309 }
310
311 ret = gdm_wimax_send_tx(skb, dev);
312out:
313 return ret;
314}
315
316static u32 get_csr(struct qos_cb_s *qcb, u32 SFID, int mode)
317{
318 int i;
319
320 for (i = 0; i < qcb->qos_list_cnt; i++) {
321 if (qcb->csr[i].SFID == SFID)
322 return i;
323 }
324
325 if (mode) {
326 for (i = 0; i < QOS_MAX; i++) {
327 if (qcb->csr[i].Enabled == 0) {
328 qcb->csr[i].Enabled = 1;
329 qcb->qos_list_cnt++;
330 return i;
331 }
332 }
333 }
334 return -1;
335}
336
337#define QOS_CHANGE_DEL 0xFC
338#define QOS_ADD 0xFD
339#define QOS_REPORT 0xFE
340
341void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size)
342{
343 struct nic *nic = nic_ptr;
344 u32 i, SFID, index, pos;
345 u8 subCmdEvt;
346 u8 len;
347 struct qos_cb_s *qcb = &nic->qos;
348 struct qos_entry_s *entry, *n;
349 struct list_head send_list;
350 struct list_head free_list;
351 unsigned long flags;
352
353 subCmdEvt = (u8)buf[4];
354
355 if (subCmdEvt == QOS_REPORT) {
356 len = (u8)buf[5];
357
358 spin_lock_irqsave(&qcb->qos_lock, flags);
359 for (i = 0; i < qcb->qos_list_cnt; i++) {
360 SFID = ((buf[(i*5)+6]<<24)&0xff000000);
361 SFID += ((buf[(i*5)+7]<<16)&0xff0000);
362 SFID += ((buf[(i*5)+8]<<8)&0xff00);
363 SFID += (buf[(i*5)+9]);
364 index = get_csr(qcb, SFID, 0);
365 if (index == -1) {
366 spin_unlock_irqrestore(&qcb->qos_lock, flags);
367 eprintk("QoS ERROR: No SF\n");
368 return;
369 }
370 qcb->csr[index].QoSBufCount = buf[(i*5)+10];
371 }
372
373 extract_qos_list(nic, &send_list);
374 spin_unlock_irqrestore(&qcb->qos_lock, flags);
375 send_qos_list(nic, &send_list);
376 return;
377 } else if (subCmdEvt == QOS_ADD) {
378 pos = 5;
379 len = (u8)buf[pos++];
380
381 SFID = ((buf[pos++]<<24)&0xff000000);
382 SFID += ((buf[pos++]<<16)&0xff0000);
383 SFID += ((buf[pos++]<<8)&0xff00);
384 SFID += (buf[pos++]);
385
386 index = get_csr(qcb, SFID, 1);
387 if (index == -1) {
388 eprintk("QoS ERROR: csr Update Error\n");
389 return;
390 }
391
392 dprintk("QOS_ADD SFID = 0x%x, index=%d\n", SFID, index);
393
394 spin_lock_irqsave(&qcb->qos_lock, flags);
395 qcb->csr[index].SFID = SFID;
396 qcb->csr[index].ClassifierRuleEnable = ((buf[pos++]<<8)&0xff00);
397 qcb->csr[index].ClassifierRuleEnable += buf[pos++];
398 if (qcb->csr[index].ClassifierRuleEnable == 0)
399 qcb->qos_null_idx = index;
400 qcb->csr[index].IPToSMask = buf[pos++];
401 qcb->csr[index].IPToSLow = buf[pos++];
402 qcb->csr[index].IPToSHigh = buf[pos++];
403 qcb->csr[index].Protocol = buf[pos++];
404 qcb->csr[index].IPSrcAddrMask[0] = buf[pos++];
405 qcb->csr[index].IPSrcAddrMask[1] = buf[pos++];
406 qcb->csr[index].IPSrcAddrMask[2] = buf[pos++];
407 qcb->csr[index].IPSrcAddrMask[3] = buf[pos++];
408 qcb->csr[index].IPSrcAddr[0] = buf[pos++];
409 qcb->csr[index].IPSrcAddr[1] = buf[pos++];
410 qcb->csr[index].IPSrcAddr[2] = buf[pos++];
411 qcb->csr[index].IPSrcAddr[3] = buf[pos++];
412 qcb->csr[index].IPDstAddrMask[0] = buf[pos++];
413 qcb->csr[index].IPDstAddrMask[1] = buf[pos++];
414 qcb->csr[index].IPDstAddrMask[2] = buf[pos++];
415 qcb->csr[index].IPDstAddrMask[3] = buf[pos++];
416 qcb->csr[index].IPDstAddr[0] = buf[pos++];
417 qcb->csr[index].IPDstAddr[1] = buf[pos++];
418 qcb->csr[index].IPDstAddr[2] = buf[pos++];
419 qcb->csr[index].IPDstAddr[3] = buf[pos++];
420 qcb->csr[index].SrcPortLow = ((buf[pos++]<<8)&0xff00);
421 qcb->csr[index].SrcPortLow += buf[pos++];
422 qcb->csr[index].SrcPortHigh = ((buf[pos++]<<8)&0xff00);
423 qcb->csr[index].SrcPortHigh += buf[pos++];
424 qcb->csr[index].DstPortLow = ((buf[pos++]<<8)&0xff00);
425 qcb->csr[index].DstPortLow += buf[pos++];
426 qcb->csr[index].DstPortHigh = ((buf[pos++]<<8)&0xff00);
427 qcb->csr[index].DstPortHigh += buf[pos++];
428
429 qcb->qos_limit_size = 254/qcb->qos_list_cnt;
430 spin_unlock_irqrestore(&qcb->qos_lock, flags);
431 } else if (subCmdEvt == QOS_CHANGE_DEL) {
432 pos = 5;
433 len = (u8)buf[pos++];
434 SFID = ((buf[pos++]<<24)&0xff000000);
435 SFID += ((buf[pos++]<<16)&0xff0000);
436 SFID += ((buf[pos++]<<8)&0xff00);
437 SFID += (buf[pos++]);
438 index = get_csr(qcb, SFID, 1);
439 if (index == -1) {
440 eprintk("QoS ERROR: Wrong index(%d)\n", index);
441 return;
442 }
443
444 dprintk("QOS_CHANGE_DEL SFID = 0x%x, index=%d\n", SFID, index);
445
446 INIT_LIST_HEAD(&free_list);
447
448 spin_lock_irqsave(&qcb->qos_lock, flags);
449 qcb->csr[index].Enabled = 0;
450 qcb->qos_list_cnt--;
451 qcb->qos_limit_size = 254/qcb->qos_list_cnt;
452
453 list_for_each_entry_safe(entry, n, &qcb->qos_list[index],
454 list) {
455 list_move_tail(&entry->list, &free_list);
456 }
457 spin_unlock_irqrestore(&qcb->qos_lock, flags);
458 free_qos_entry_list(&free_list);
459 }
460}
diff --git a/drivers/staging/gdm72xx/gdm_qos.h b/drivers/staging/gdm72xx/gdm_qos.h
new file mode 100644
index 000000000000..33f2bd4cee32
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_qos.h
@@ -0,0 +1,93 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#if !defined(GDM_QOS_H_20090403)
15#define GDM_QOS_H_20090403
16
17#include <linux/types.h>
18#include <linux/usb.h>
19#include <linux/list.h>
20
21#define BOOLEAN u8
22
23#define QOS_MAX 16
24#define IPTYPEOFSERVICE 0x8000
25#define PROTOCOL 0x4000
26#define IPMASKEDSRCADDRESS 0x2000
27#define IPMASKEDDSTADDRESS 0x1000
28#define PROTOCOLSRCPORTRANGE 0x800
29#define PROTOCOLDSTPORTRANGE 0x400
30#define DSTMACADDR 0x200
31#define SRCMACADDR 0x100
32#define ETHERTYPE 0x80
33#define IEEE802_1DUSERPRIORITY 0x40
34#define IEEE802_1QVLANID 0x10
35
36struct gdm_wimax_csr_s {
37 /* union{
38 U16 all;
39 struct _CS_CLASSIFIER_RULE_ENABLE{
40 IPTypeOfService:1,
41 Protocol:1,
42 IPMaskedSrcAddress:1,
43 IPMaskedDstAddress:1,
44 ProtocolSrcPortRange:1,
45 ProtocolDstPortRange:1,
46 DstMacAddr:1,
47 SrcMacAddr:1,
48 Ethertype:1,
49 IEEE802_1DUserPriority:1,
50 IEEE802_1QVLANID:1,
51 Reserved:5;
52 } fields;
53 } */
54 BOOLEAN Enabled;
55 u32 SFID;
56 u8 QoSBufCount;
57 u16 ClassifierRuleEnable;
58 u8 IPToSLow;
59 u8 IPToSHigh;
60 u8 IPToSMask;
61 u8 Protocol;
62 u8 IPSrcAddr[16];
63 u8 IPSrcAddrMask[16];
64 u8 IPDstAddr[16];
65 u8 IPDstAddrMask[16];
66 u16 SrcPortLow;
67 u16 SrcPortHigh;
68 u16 DstPortLow;
69 u16 DstPortHigh;
70};
71
72struct qos_entry_s {
73 struct list_head list;
74 struct sk_buff *skb;
75 struct net_device *dev;
76
77};
78
79struct qos_cb_s {
80 struct list_head qos_list[QOS_MAX];
81 u32 qos_list_cnt;
82 u32 qos_null_idx;
83 struct gdm_wimax_csr_s csr[QOS_MAX];
84 spinlock_t qos_lock;
85 u32 qos_limit_size;
86};
87
88void gdm_qos_init(void *nic_ptr);
89void gdm_qos_release_list(void *nic_ptr);
90int gdm_qos_send_hci_pkt(struct sk_buff *skb, struct net_device *dev);
91void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size);
92
93#endif
diff --git a/drivers/staging/gdm72xx/gdm_sdio.c b/drivers/staging/gdm72xx/gdm_sdio.c
new file mode 100644
index 000000000000..e1a3dd2fc4af
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_sdio.c
@@ -0,0 +1,754 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/version.h>
18
19#include <linux/mmc/core.h>
20#include <linux/mmc/card.h>
21#include <linux/mmc/sdio_func.h>
22#include <linux/mmc/sdio_ids.h>
23
24#include "gdm_sdio.h"
25#include "gdm_wimax.h"
26#include "sdio_boot.h"
27#include "hci.h"
28
29#define TYPE_A_HEADER_SIZE 4
30#define TYPE_A_LOOKAHEAD_SIZE 16
31
32#define MAX_NR_RX_BUF 4
33
34#define SDU_TX_BUF_SIZE 2048
35#define TX_BUF_SIZE 2048
36#define TX_CHUNK_SIZE (2048 - TYPE_A_HEADER_SIZE)
37#define RX_BUF_SIZE (25*1024)
38
39#define TX_HZ 2000
40#define TX_INTERVAL (1000000/TX_HZ)
41
42/*#define DEBUG*/
43
44static int init_sdio(struct sdiowm_dev *sdev);
45static void release_sdio(struct sdiowm_dev *sdev);
46
47#ifdef DEBUG
48static void hexdump(char *title, u8 *data, int len)
49{
50 int i;
51
52 printk(KERN_DEBUG "%s: length = %d\n", title, len);
53 for (i = 0; i < len; i++) {
54 printk(KERN_DEBUG "%02x ", data[i]);
55 if ((i & 0xf) == 0xf)
56 printk(KERN_DEBUG "\n");
57 }
58 printk(KERN_DEBUG "\n");
59}
60#endif
61
62static struct sdio_tx *alloc_tx_struct(struct tx_cxt *tx)
63{
64 struct sdio_tx *t = NULL;
65
66 t = kmalloc(sizeof(*t), GFP_ATOMIC);
67 if (t == NULL)
68 goto out;
69
70 memset(t, 0, sizeof(*t));
71
72 t->buf = kmalloc(TX_BUF_SIZE, GFP_ATOMIC);
73 if (t->buf == NULL)
74 goto out;
75
76 t->tx_cxt = tx;
77
78 return t;
79out:
80 if (t) {
81 kfree(t->buf);
82 kfree(t);
83 }
84 return NULL;
85}
86
87static void free_tx_struct(struct sdio_tx *t)
88{
89 if (t) {
90 kfree(t->buf);
91 kfree(t);
92 }
93}
94
95static struct sdio_rx *alloc_rx_struct(struct rx_cxt *rx)
96{
97 struct sdio_rx *r = NULL;
98
99 r = kmalloc(sizeof(*r), GFP_ATOMIC);
100 if (r == NULL)
101 goto out;
102
103 memset(r, 0, sizeof(*r));
104
105 r->rx_cxt = rx;
106
107 return r;
108out:
109 kfree(r);
110 return NULL;
111}
112
113static void free_rx_struct(struct sdio_rx *r)
114{
115 kfree(r);
116}
117
118/* Before this function is called, spin lock should be locked. */
119static struct sdio_tx *get_tx_struct(struct tx_cxt *tx, int *no_spc)
120{
121 struct sdio_tx *t;
122
123 if (list_empty(&tx->free_list))
124 return NULL;
125
126 t = list_entry(tx->free_list.prev, struct sdio_tx, list);
127 list_del(&t->list);
128
129 *no_spc = list_empty(&tx->free_list) ? 1 : 0;
130
131 return t;
132}
133
134/* Before this function is called, spin lock should be locked. */
135static void put_tx_struct(struct tx_cxt *tx, struct sdio_tx *t)
136{
137 list_add_tail(&t->list, &tx->free_list);
138}
139
140/* Before this function is called, spin lock should be locked. */
141static struct sdio_rx *get_rx_struct(struct rx_cxt *rx)
142{
143 struct sdio_rx *r;
144
145 if (list_empty(&rx->free_list))
146 return NULL;
147
148 r = list_entry(rx->free_list.prev, struct sdio_rx, list);
149 list_del(&r->list);
150
151 return r;
152}
153
154/* Before this function is called, spin lock should be locked. */
155static void put_rx_struct(struct rx_cxt *rx, struct sdio_rx *r)
156{
157 list_add_tail(&r->list, &rx->free_list);
158}
159
160static int init_sdio(struct sdiowm_dev *sdev)
161{
162 int ret = 0, i;
163 struct tx_cxt *tx = &sdev->tx;
164 struct rx_cxt *rx = &sdev->rx;
165 struct sdio_tx *t;
166 struct sdio_rx *r;
167
168 INIT_LIST_HEAD(&tx->free_list);
169 INIT_LIST_HEAD(&tx->sdu_list);
170 INIT_LIST_HEAD(&tx->hci_list);
171
172 spin_lock_init(&tx->lock);
173
174 tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL);
175 if (tx->sdu_buf == NULL) {
176 printk(KERN_ERR "Failed to allocate SDU tx buffer.\n");
177 goto fail;
178 }
179
180 for (i = 0; i < MAX_NR_SDU_BUF; i++) {
181 t = alloc_tx_struct(tx);
182 if (t == NULL) {
183 ret = -ENOMEM;
184 goto fail;
185 }
186 list_add(&t->list, &tx->free_list);
187 }
188
189 INIT_LIST_HEAD(&rx->free_list);
190 INIT_LIST_HEAD(&rx->req_list);
191
192 spin_lock_init(&rx->lock);
193
194 for (i = 0; i < MAX_NR_RX_BUF; i++) {
195 r = alloc_rx_struct(rx);
196 if (r == NULL) {
197 ret = -ENOMEM;
198 goto fail;
199 }
200 list_add(&r->list, &rx->free_list);
201 }
202
203 rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
204 if (rx->rx_buf == NULL) {
205 printk(KERN_ERR "Failed to allocate rx buffer.\n");
206 goto fail;
207 }
208
209 return 0;
210
211fail:
212 release_sdio(sdev);
213 return ret;
214}
215
216static void release_sdio(struct sdiowm_dev *sdev)
217{
218 struct tx_cxt *tx = &sdev->tx;
219 struct rx_cxt *rx = &sdev->rx;
220 struct sdio_tx *t, *t_next;
221 struct sdio_rx *r, *r_next;
222
223 kfree(tx->sdu_buf);
224
225 list_for_each_entry_safe(t, t_next, &tx->free_list, list) {
226 list_del(&t->list);
227 free_tx_struct(t);
228 }
229
230 list_for_each_entry_safe(t, t_next, &tx->sdu_list, list) {
231 list_del(&t->list);
232 free_tx_struct(t);
233 }
234
235 list_for_each_entry_safe(t, t_next, &tx->hci_list, list) {
236 list_del(&t->list);
237 free_tx_struct(t);
238 }
239
240 kfree(rx->rx_buf);
241
242 list_for_each_entry_safe(r, r_next, &rx->free_list, list) {
243 list_del(&r->list);
244 free_rx_struct(r);
245 }
246
247 list_for_each_entry_safe(r, r_next, &rx->req_list, list) {
248 list_del(&r->list);
249 free_rx_struct(r);
250 }
251}
252
253static void send_sdio_pkt(struct sdio_func *func, u8 *data, int len)
254{
255 int n, blocks, ret, remain;
256
257 sdio_claim_host(func);
258
259 blocks = len / func->cur_blksize;
260 n = blocks * func->cur_blksize;
261 if (blocks) {
262 ret = sdio_memcpy_toio(func, 0, data, n);
263 if (ret < 0) {
264 if (ret != -ENOMEDIUM)
265 printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
266 __func__, ret);
267 goto end_io;
268 }
269 }
270
271 remain = len - n;
272 remain = (remain + 3) & ~3;
273
274 if (remain) {
275 ret = sdio_memcpy_toio(func, 0, data + n, remain);
276 if (ret < 0) {
277 if (ret != -ENOMEDIUM)
278 printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
279 __func__, ret);
280 goto end_io;
281 }
282 }
283
284end_io:
285 sdio_release_host(func);
286}
287
288static void send_sdu(struct sdio_func *func, struct tx_cxt *tx)
289{
290 struct list_head *l, *next;
291 struct hci_s *hci;
292 struct sdio_tx *t;
293 int pos, len, i, estlen, aggr_num = 0, aggr_len;
294 u8 *buf;
295 unsigned long flags;
296
297 spin_lock_irqsave(&tx->lock, flags);
298
299 pos = TYPE_A_HEADER_SIZE + HCI_HEADER_SIZE;
300 list_for_each_entry(t, &tx->sdu_list, list) {
301 estlen = ((t->len + 3) & ~3) + 4;
302 if ((pos + estlen) > SDU_TX_BUF_SIZE)
303 break;
304
305 aggr_num++;
306 memcpy(tx->sdu_buf + pos, t->buf, t->len);
307 memset(tx->sdu_buf + pos + t->len, 0, estlen - t->len);
308 pos += estlen;
309 }
310 aggr_len = pos;
311
312 hci = (struct hci_s *)(tx->sdu_buf + TYPE_A_HEADER_SIZE);
313 hci->cmd_evt = H2B(WIMAX_TX_SDU_AGGR);
314 hci->length = H2B(aggr_len - TYPE_A_HEADER_SIZE - HCI_HEADER_SIZE);
315
316 spin_unlock_irqrestore(&tx->lock, flags);
317
318#ifdef DEBUG
319 hexdump("sdio_send", tx->sdu_buf + TYPE_A_HEADER_SIZE,
320 aggr_len - TYPE_A_HEADER_SIZE);
321#endif
322
323 for (pos = TYPE_A_HEADER_SIZE; pos < aggr_len; pos += TX_CHUNK_SIZE) {
324 len = aggr_len - pos;
325 len = len > TX_CHUNK_SIZE ? TX_CHUNK_SIZE : len;
326 buf = tx->sdu_buf + pos - TYPE_A_HEADER_SIZE;
327
328 buf[0] = len & 0xff;
329 buf[1] = (len >> 8) & 0xff;
330 buf[2] = (len >> 16) & 0xff;
331 buf[3] = (pos + len) >= aggr_len ? 0 : 1;
332 send_sdio_pkt(func, buf, len + TYPE_A_HEADER_SIZE);
333 }
334
335 spin_lock_irqsave(&tx->lock, flags);
336
337 for (l = tx->sdu_list.next, i = 0; i < aggr_num; i++, l = next) {
338 next = l->next;
339 t = list_entry(l, struct sdio_tx, list);
340 if (t->callback)
341 t->callback(t->cb_data);
342
343 list_del(l);
344 put_tx_struct(t->tx_cxt, t);
345 }
346
347 do_gettimeofday(&tx->sdu_stamp);
348 spin_unlock_irqrestore(&tx->lock, flags);
349}
350
351static void send_hci(struct sdio_func *func, struct tx_cxt *tx,
352 struct sdio_tx *t)
353{
354 unsigned long flags;
355
356#ifdef DEBUG
357 hexdump("sdio_send", t->buf + TYPE_A_HEADER_SIZE,
358 t->len - TYPE_A_HEADER_SIZE);
359#endif
360 send_sdio_pkt(func, t->buf, t->len);
361
362 spin_lock_irqsave(&tx->lock, flags);
363 if (t->callback)
364 t->callback(t->cb_data);
365 free_tx_struct(t);
366 spin_unlock_irqrestore(&tx->lock, flags);
367}
368
369static void do_tx(struct work_struct *work)
370{
371 struct sdiowm_dev *sdev = container_of(work, struct sdiowm_dev, ws);
372 struct sdio_func *func = sdev->func;
373 struct tx_cxt *tx = &sdev->tx;
374 struct sdio_tx *t = NULL;
375 struct timeval now, *before;
376 int is_sdu = 0;
377 long diff;
378 unsigned long flags;
379
380 spin_lock_irqsave(&tx->lock, flags);
381 if (!tx->can_send) {
382 spin_unlock_irqrestore(&tx->lock, flags);
383 return;
384 }
385
386 if (!list_empty(&tx->hci_list)) {
387 t = list_entry(tx->hci_list.next, struct sdio_tx, list);
388 list_del(&t->list);
389 is_sdu = 0;
390 } else if (!tx->stop_sdu_tx && !list_empty(&tx->sdu_list)) {
391 do_gettimeofday(&now);
392 before = &tx->sdu_stamp;
393
394 diff = (now.tv_sec - before->tv_sec) * 1000000 +
395 (now.tv_usec - before->tv_usec);
396 if (diff >= 0 && diff < TX_INTERVAL) {
397 schedule_work(&sdev->ws);
398 spin_unlock_irqrestore(&tx->lock, flags);
399 return;
400 }
401 is_sdu = 1;
402 }
403
404 if (!is_sdu && t == NULL) {
405 spin_unlock_irqrestore(&tx->lock, flags);
406 return;
407 }
408
409 tx->can_send = 0;
410
411 spin_unlock_irqrestore(&tx->lock, flags);
412
413 if (is_sdu)
414 send_sdu(func, tx);
415 else
416 send_hci(func, tx, t);
417}
418
419static int gdm_sdio_send(void *priv_dev, void *data, int len,
420 void (*cb)(void *data), void *cb_data)
421{
422 struct sdiowm_dev *sdev = priv_dev;
423 struct tx_cxt *tx = &sdev->tx;
424 struct sdio_tx *t;
425 u8 *pkt = data;
426 int no_spc = 0;
427 u16 cmd_evt;
428 unsigned long flags;
429
430 BUG_ON(len > TX_BUF_SIZE - TYPE_A_HEADER_SIZE);
431
432 spin_lock_irqsave(&tx->lock, flags);
433
434 cmd_evt = (pkt[0] << 8) | pkt[1];
435 if (cmd_evt == WIMAX_TX_SDU) {
436 t = get_tx_struct(tx, &no_spc);
437 if (t == NULL) {
438 /* This case must not happen. */
439 spin_unlock_irqrestore(&tx->lock, flags);
440 return -ENOSPC;
441 }
442 list_add_tail(&t->list, &tx->sdu_list);
443
444 memcpy(t->buf, data, len);
445
446 t->len = len;
447 t->callback = cb;
448 t->cb_data = cb_data;
449 } else {
450 t = alloc_tx_struct(tx);
451 if (t == NULL) {
452 spin_unlock_irqrestore(&tx->lock, flags);
453 return -ENOMEM;
454 }
455 list_add_tail(&t->list, &tx->hci_list);
456
457 t->buf[0] = len & 0xff;
458 t->buf[1] = (len >> 8) & 0xff;
459 t->buf[2] = (len >> 16) & 0xff;
460 t->buf[3] = 2;
461 memcpy(t->buf + TYPE_A_HEADER_SIZE, data, len);
462
463 t->len = len + TYPE_A_HEADER_SIZE;
464 t->callback = cb;
465 t->cb_data = cb_data;
466 }
467
468 if (tx->can_send)
469 schedule_work(&sdev->ws);
470
471 spin_unlock_irqrestore(&tx->lock, flags);
472
473 if (no_spc)
474 return -ENOSPC;
475
476 return 0;
477}
478
479/*
480 * Handle the HCI, WIMAX_SDU_TX_FLOW.
481 */
482static int control_sdu_tx_flow(struct sdiowm_dev *sdev, u8 *hci_data, int len)
483{
484 struct tx_cxt *tx = &sdev->tx;
485 u16 cmd_evt;
486 unsigned long flags;
487
488 spin_lock_irqsave(&tx->lock, flags);
489
490 cmd_evt = (hci_data[0] << 8) | (hci_data[1]);
491 if (cmd_evt != WIMAX_SDU_TX_FLOW)
492 goto out;
493
494 if (hci_data[4] == 0) {
495#ifdef DEBUG
496 printk(KERN_DEBUG "WIMAX ==> STOP SDU TX\n");
497#endif
498 tx->stop_sdu_tx = 1;
499 } else if (hci_data[4] == 1) {
500#ifdef DEBUG
501 printk(KERN_DEBUG "WIMAX ==> START SDU TX\n");
502#endif
503 tx->stop_sdu_tx = 0;
504 if (tx->can_send)
505 schedule_work(&sdev->ws);
506 /*
507 * If free buffer for sdu tx doesn't exist, then tx queue
508 * should not be woken. For this reason, don't pass the command,
509 * START_SDU_TX.
510 */
511 if (list_empty(&tx->free_list))
512 len = 0;
513 }
514
515out:
516 spin_unlock_irqrestore(&tx->lock, flags);
517 return len;
518}
519
520static void gdm_sdio_irq(struct sdio_func *func)
521{
522 struct phy_dev *phy_dev = sdio_get_drvdata(func);
523 struct sdiowm_dev *sdev = phy_dev->priv_dev;
524 struct tx_cxt *tx = &sdev->tx;
525 struct rx_cxt *rx = &sdev->rx;
526 struct sdio_rx *r;
527 unsigned long flags;
528 u8 val, hdr[TYPE_A_LOOKAHEAD_SIZE], *buf;
529 u32 len, blocks, n;
530 int ret, remain;
531
532 /* Check interrupt */
533 val = sdio_readb(func, 0x13, &ret);
534 if (val & 0x01)
535 sdio_writeb(func, 0x01, 0x13, &ret); /* clear interrupt */
536 else
537 return;
538
539 ret = sdio_memcpy_fromio(func, hdr, 0x0, TYPE_A_LOOKAHEAD_SIZE);
540 if (ret) {
541 printk(KERN_ERR "Cannot read from function %d\n", func->num);
542 goto done;
543 }
544
545 len = (hdr[2] << 16) | (hdr[1] << 8) | hdr[0];
546 if (len > (RX_BUF_SIZE - TYPE_A_HEADER_SIZE)) {
547 printk(KERN_ERR "Too big Type-A size: %d\n", len);
548 goto done;
549 }
550
551 if (hdr[3] == 1) { /* Ack */
552#ifdef DEBUG
553 u32 *ack_seq = (u32 *)&hdr[4];
554#endif
555 spin_lock_irqsave(&tx->lock, flags);
556 tx->can_send = 1;
557
558 if (!list_empty(&tx->sdu_list) || !list_empty(&tx->hci_list))
559 schedule_work(&sdev->ws);
560 spin_unlock_irqrestore(&tx->lock, flags);
561#ifdef DEBUG
562 printk(KERN_DEBUG "Ack... %0x\n", ntohl(*ack_seq));
563#endif
564 goto done;
565 }
566
567 memcpy(rx->rx_buf, hdr + TYPE_A_HEADER_SIZE,
568 TYPE_A_LOOKAHEAD_SIZE - TYPE_A_HEADER_SIZE);
569
570 buf = rx->rx_buf + TYPE_A_LOOKAHEAD_SIZE - TYPE_A_HEADER_SIZE;
571 remain = len - TYPE_A_LOOKAHEAD_SIZE + TYPE_A_HEADER_SIZE;
572 if (remain <= 0)
573 goto end_io;
574
575 blocks = remain / func->cur_blksize;
576
577 if (blocks) {
578 n = blocks * func->cur_blksize;
579 ret = sdio_memcpy_fromio(func, buf, 0x0, n);
580 if (ret) {
581 printk(KERN_ERR "Cannot read from function %d\n",
582 func->num);
583 goto done;
584 }
585 buf += n;
586 remain -= n;
587 }
588
589 if (remain) {
590 ret = sdio_memcpy_fromio(func, buf, 0x0, remain);
591 if (ret) {
592 printk(KERN_ERR "Cannot read from function %d\n",
593 func->num);
594 goto done;
595 }
596 }
597
598end_io:
599#ifdef DEBUG
600 hexdump("sdio_receive", rx->rx_buf, len);
601#endif
602 len = control_sdu_tx_flow(sdev, rx->rx_buf, len);
603
604 spin_lock_irqsave(&rx->lock, flags);
605
606 if (!list_empty(&rx->req_list)) {
607 r = list_entry(rx->req_list.next, struct sdio_rx, list);
608 spin_unlock_irqrestore(&rx->lock, flags);
609 if (r->callback)
610 r->callback(r->cb_data, rx->rx_buf, len);
611 spin_lock_irqsave(&rx->lock, flags);
612 list_del(&r->list);
613 put_rx_struct(rx, r);
614 }
615
616 spin_unlock_irqrestore(&rx->lock, flags);
617
618done:
619 sdio_writeb(func, 0x00, 0x10, &ret); /* PCRRT */
620 if (!phy_dev->netdev)
621 register_wimax_device(phy_dev, &func->dev);
622}
623
624static int gdm_sdio_receive(void *priv_dev,
625 void (*cb)(void *cb_data, void *data, int len),
626 void *cb_data)
627{
628 struct sdiowm_dev *sdev = priv_dev;
629 struct rx_cxt *rx = &sdev->rx;
630 struct sdio_rx *r;
631 unsigned long flags;
632
633 spin_lock_irqsave(&rx->lock, flags);
634 r = get_rx_struct(rx);
635 if (r == NULL) {
636 spin_unlock_irqrestore(&rx->lock, flags);
637 return -ENOMEM;
638 }
639
640 r->callback = cb;
641 r->cb_data = cb_data;
642
643 list_add_tail(&r->list, &rx->req_list);
644 spin_unlock_irqrestore(&rx->lock, flags);
645
646 return 0;
647}
648
649static int sdio_wimax_probe(struct sdio_func *func,
650 const struct sdio_device_id *id)
651{
652 int ret;
653 struct phy_dev *phy_dev = NULL;
654 struct sdiowm_dev *sdev = NULL;
655
656 printk(KERN_INFO "Found GDM SDIO VID = 0x%04x PID = 0x%04x...\n",
657 func->vendor, func->device);
658 printk(KERN_INFO "GCT WiMax driver version %s\n", DRIVER_VERSION);
659
660 sdio_claim_host(func);
661 sdio_enable_func(func);
662 sdio_claim_irq(func, gdm_sdio_irq);
663
664 ret = sdio_boot(func);
665 if (ret)
666 return ret;
667
668 phy_dev = kmalloc(sizeof(*phy_dev), GFP_KERNEL);
669 if (phy_dev == NULL) {
670 ret = -ENOMEM;
671 goto out;
672 }
673 sdev = kmalloc(sizeof(*sdev), GFP_KERNEL);
674 if (sdev == NULL) {
675 ret = -ENOMEM;
676 goto out;
677 }
678
679 memset(phy_dev, 0, sizeof(*phy_dev));
680 memset(sdev, 0, sizeof(*sdev));
681
682 phy_dev->priv_dev = (void *)sdev;
683 phy_dev->send_func = gdm_sdio_send;
684 phy_dev->rcv_func = gdm_sdio_receive;
685
686 ret = init_sdio(sdev);
687 if (sdev < 0)
688 goto out;
689
690 sdev->func = func;
691
692 sdio_writeb(func, 1, 0x14, &ret); /* Enable interrupt */
693 sdio_release_host(func);
694
695 INIT_WORK(&sdev->ws, do_tx);
696
697 sdio_set_drvdata(func, phy_dev);
698out:
699 if (ret) {
700 kfree(phy_dev);
701 kfree(sdev);
702 }
703
704 return ret;
705}
706
707static void sdio_wimax_remove(struct sdio_func *func)
708{
709 struct phy_dev *phy_dev = sdio_get_drvdata(func);
710 struct sdiowm_dev *sdev = phy_dev->priv_dev;
711
712 if (phy_dev->netdev)
713 unregister_wimax_device(phy_dev);
714 sdio_claim_host(func);
715 sdio_release_irq(func);
716 sdio_disable_func(func);
717 sdio_release_host(func);
718 release_sdio(sdev);
719
720 kfree(sdev);
721 kfree(phy_dev);
722}
723
724static const struct sdio_device_id sdio_wimax_ids[] = {
725 { SDIO_DEVICE(0x0296, 0x5347) },
726 {0}
727};
728
729MODULE_DEVICE_TABLE(sdio, sdio_wimax_ids);
730
731static struct sdio_driver sdio_wimax_driver = {
732 .probe = sdio_wimax_probe,
733 .remove = sdio_wimax_remove,
734 .name = "sdio_wimax",
735 .id_table = sdio_wimax_ids,
736};
737
738static int __init sdio_gdm_wimax_init(void)
739{
740 return sdio_register_driver(&sdio_wimax_driver);
741}
742
743static void __exit sdio_gdm_wimax_exit(void)
744{
745 sdio_unregister_driver(&sdio_wimax_driver);
746}
747
748module_init(sdio_gdm_wimax_init);
749module_exit(sdio_gdm_wimax_exit);
750
751MODULE_VERSION(DRIVER_VERSION);
752MODULE_DESCRIPTION("GCT WiMax SDIO Device Driver");
753MODULE_AUTHOR("Ethan Park");
754MODULE_LICENSE("GPL");
diff --git a/drivers/staging/gdm72xx/gdm_sdio.h b/drivers/staging/gdm72xx/gdm_sdio.h
new file mode 100644
index 000000000000..216e98f31bae
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_sdio.h
@@ -0,0 +1,72 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __GDM_SDIO_H__
15#define __GDM_SDIO_H__
16
17#include <linux/types.h>
18#include <linux/time.h>
19
20#define MAX_NR_SDU_BUF 64
21
22struct sdio_tx {
23 struct list_head list;
24 struct tx_cxt *tx_cxt;
25
26 u8 *buf;
27 int len;
28
29 void (*callback)(void *cb_data);
30 void *cb_data;
31};
32
33struct tx_cxt {
34 struct list_head free_list;
35 struct list_head sdu_list;
36 struct list_head hci_list;
37 struct timeval sdu_stamp;
38
39 u8 *sdu_buf;
40
41 spinlock_t lock;
42 int can_send;
43 int stop_sdu_tx;
44};
45
46struct sdio_rx {
47 struct list_head list;
48 struct rx_cxt *rx_cxt;
49
50 void (*callback)(void *cb_data, void *data, int len);
51 void *cb_data;
52};
53
54struct rx_cxt {
55 struct list_head free_list;
56 struct list_head req_list;
57
58 u8 *rx_buf;
59
60 spinlock_t lock;
61};
62
63struct sdiowm_dev {
64 struct sdio_func *func;
65
66 struct tx_cxt tx;
67 struct rx_cxt rx;
68
69 struct work_struct ws;
70};
71
72#endif /* __GDM_SDIO_H__ */
diff --git a/drivers/staging/gdm72xx/gdm_usb.c b/drivers/staging/gdm72xx/gdm_usb.c
new file mode 100644
index 000000000000..1e9dc0d90362
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_usb.c
@@ -0,0 +1,798 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/module.h>
15#include <linux/version.h>
16#include <linux/kernel.h>
17#include <linux/usb.h>
18#include <asm/byteorder.h>
19
20#include "gdm_usb.h"
21#include "gdm_wimax.h"
22#include "usb_boot.h"
23#include "hci.h"
24
25#include "usb_ids.h"
26
27MODULE_DEVICE_TABLE(usb, id_table);
28
29#define TX_BUF_SIZE 2048
30#if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
31#define RX_BUF_SIZE (128*1024) /* For packet aggregation */
32#else
33#define RX_BUF_SIZE 2048
34#endif
35
36#define GDM7205_PADDING 256
37
38#define H2B(x) __cpu_to_be16(x)
39#define B2H(x) __be16_to_cpu(x)
40#define DB2H(x) __be32_to_cpu(x)
41
42#define DOWNLOAD_CONF_VALUE 0x21
43
44#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
45
46static DECLARE_WAIT_QUEUE_HEAD(k_wait);
47static LIST_HEAD(k_list);
48static DEFINE_SPINLOCK(k_lock);
49static int k_mode_stop;
50
51#define K_WAIT_TIME (2 * HZ / 100)
52
53#endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
54
55static int init_usb(struct usbwm_dev *udev);
56static void release_usb(struct usbwm_dev *udev);
57
58/*#define DEBUG */
59#ifdef DEBUG
60static void hexdump(char *title, u8 *data, int len)
61{
62 int i;
63
64 printk(KERN_DEBUG "%s: length = %d\n", title, len);
65 for (i = 0; i < len; i++) {
66 printk(KERN_DEBUG "%02x ", data[i]);
67 if ((i & 0xf) == 0xf)
68 printk(KERN_DEBUG "\n");
69 }
70 printk(KERN_DEBUG "\n");
71}
72#endif
73
74static struct usb_tx *alloc_tx_struct(struct tx_cxt *tx)
75{
76 struct usb_tx *t = NULL;
77
78 t = kmalloc(sizeof(*t), GFP_ATOMIC);
79 if (t == NULL)
80 goto out;
81
82 memset(t, 0, sizeof(*t));
83
84 t->urb = usb_alloc_urb(0, GFP_ATOMIC);
85 t->buf = kmalloc(TX_BUF_SIZE, GFP_ATOMIC);
86 if (t->urb == NULL || t->buf == NULL)
87 goto out;
88
89 t->tx_cxt = tx;
90
91 return t;
92out:
93 if (t) {
94 usb_free_urb(t->urb);
95 kfree(t->buf);
96 kfree(t);
97 }
98 return NULL;
99}
100
101static void free_tx_struct(struct usb_tx *t)
102{
103 if (t) {
104 usb_free_urb(t->urb);
105 kfree(t->buf);
106 kfree(t);
107 }
108}
109
110static struct usb_rx *alloc_rx_struct(struct rx_cxt *rx)
111{
112 struct usb_rx *r = NULL;
113
114 r = kmalloc(sizeof(*r), GFP_ATOMIC);
115 if (r == NULL)
116 goto out;
117
118 memset(r, 0, sizeof(*r));
119
120 r->urb = usb_alloc_urb(0, GFP_ATOMIC);
121 r->buf = kmalloc(RX_BUF_SIZE, GFP_ATOMIC);
122 if (r->urb == NULL || r->buf == NULL)
123 goto out;
124
125 r->rx_cxt = rx;
126 return r;
127out:
128 if (r) {
129 usb_free_urb(r->urb);
130 kfree(r->buf);
131 kfree(r);
132 }
133 return NULL;
134}
135
136static void free_rx_struct(struct usb_rx *r)
137{
138 if (r) {
139 usb_free_urb(r->urb);
140 kfree(r->buf);
141 kfree(r);
142 }
143}
144
145/* Before this function is called, spin lock should be locked. */
146static struct usb_tx *get_tx_struct(struct tx_cxt *tx, int *no_spc)
147{
148 struct usb_tx *t;
149
150 if (list_empty(&tx->free_list)) {
151 *no_spc = 1;
152 return NULL;
153 }
154
155 t = list_entry(tx->free_list.next, struct usb_tx, list);
156 list_del(&t->list);
157
158 *no_spc = list_empty(&tx->free_list) ? 1 : 0;
159
160 return t;
161}
162
163/* Before this function is called, spin lock should be locked. */
164static void put_tx_struct(struct tx_cxt *tx, struct usb_tx *t)
165{
166 list_add_tail(&t->list, &tx->free_list);
167}
168
169/* Before this function is called, spin lock should be locked. */
170static struct usb_rx *get_rx_struct(struct rx_cxt *rx)
171{
172 struct usb_rx *r;
173
174 if (list_empty(&rx->free_list)) {
175 r = alloc_rx_struct(rx);
176 if (r == NULL)
177 return NULL;
178
179 list_add(&r->list, &rx->free_list);
180 }
181
182 r = list_entry(rx->free_list.next, struct usb_rx, list);
183 list_del(&r->list);
184 list_add_tail(&r->list, &rx->used_list);
185
186 return r;
187}
188
189/* Before this function is called, spin lock should be locked. */
190static void put_rx_struct(struct rx_cxt *rx, struct usb_rx *r)
191{
192 list_del(&r->list);
193 list_add(&r->list, &rx->free_list);
194}
195
196static int init_usb(struct usbwm_dev *udev)
197{
198 int ret = 0, i;
199 struct tx_cxt *tx = &udev->tx;
200 struct rx_cxt *rx = &udev->rx;
201 struct usb_tx *t;
202 struct usb_rx *r;
203
204 INIT_LIST_HEAD(&tx->free_list);
205 INIT_LIST_HEAD(&tx->sdu_list);
206 INIT_LIST_HEAD(&tx->hci_list);
207#if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
208 INIT_LIST_HEAD(&tx->pending_list);
209#endif
210
211 INIT_LIST_HEAD(&rx->free_list);
212 INIT_LIST_HEAD(&rx->used_list);
213
214 spin_lock_init(&tx->lock);
215 spin_lock_init(&rx->lock);
216
217 for (i = 0; i < MAX_NR_SDU_BUF; i++) {
218 t = alloc_tx_struct(tx);
219 if (t == NULL) {
220 ret = -ENOMEM;
221 goto fail;
222 }
223 list_add(&t->list, &tx->free_list);
224 }
225
226 r = alloc_rx_struct(rx);
227 if (r == NULL) {
228 ret = -ENOMEM;
229 goto fail;
230 }
231
232 list_add(&r->list, &rx->free_list);
233 return ret;
234
235fail:
236 release_usb(udev);
237 return ret;
238}
239
240static void release_usb(struct usbwm_dev *udev)
241{
242 struct tx_cxt *tx = &udev->tx;
243 struct rx_cxt *rx = &udev->rx;
244 struct usb_tx *t, *t_next;
245 struct usb_rx *r, *r_next;
246
247 list_for_each_entry_safe(t, t_next, &tx->sdu_list, list) {
248 list_del(&t->list);
249 free_tx_struct(t);
250 }
251
252 list_for_each_entry_safe(t, t_next, &tx->hci_list, list) {
253 list_del(&t->list);
254 free_tx_struct(t);
255 }
256
257 list_for_each_entry_safe(t, t_next, &tx->free_list, list) {
258 list_del(&t->list);
259 free_tx_struct(t);
260 }
261
262 list_for_each_entry_safe(r, r_next, &rx->free_list, list) {
263 list_del(&r->list);
264 free_rx_struct(r);
265 }
266
267 list_for_each_entry_safe(r, r_next, &rx->used_list, list) {
268 list_del(&r->list);
269 free_rx_struct(r);
270 }
271}
272
273static void gdm_usb_send_complete(struct urb *urb)
274{
275 struct usb_tx *t = urb->context;
276 struct tx_cxt *tx = t->tx_cxt;
277 u8 *pkt = t->buf;
278 u16 cmd_evt;
279 unsigned long flags;
280
281 /* Completion by usb_unlink_urb */
282 if (urb->status == -ECONNRESET)
283 return;
284
285 spin_lock_irqsave(&tx->lock, flags);
286
287 if (t->callback)
288 t->callback(t->cb_data);
289
290 /* Delete from sdu list or hci list. */
291 list_del(&t->list);
292
293 cmd_evt = (pkt[0] << 8) | pkt[1];
294 if (cmd_evt == WIMAX_TX_SDU)
295 put_tx_struct(tx, t);
296 else
297 free_tx_struct(t);
298
299 spin_unlock_irqrestore(&tx->lock, flags);
300}
301
302static int gdm_usb_send(void *priv_dev, void *data, int len,
303 void (*cb)(void *data), void *cb_data)
304{
305 struct usbwm_dev *udev = priv_dev;
306 struct usb_device *usbdev = udev->usbdev;
307 struct tx_cxt *tx = &udev->tx;
308 struct usb_tx *t;
309 int padding = udev->padding;
310 int no_spc = 0, ret;
311 u8 *pkt = data;
312 u16 cmd_evt;
313 unsigned long flags;
314
315 if (!udev->usbdev) {
316 printk(KERN_ERR "%s: No such device\n", __func__);
317 return -ENODEV;
318 }
319
320 BUG_ON(len > TX_BUF_SIZE - padding - 1);
321
322 spin_lock_irqsave(&tx->lock, flags);
323
324 cmd_evt = (pkt[0] << 8) | pkt[1];
325 if (cmd_evt == WIMAX_TX_SDU) {
326 t = get_tx_struct(tx, &no_spc);
327 if (t == NULL) {
328 /* This case must not happen. */
329 spin_unlock_irqrestore(&tx->lock, flags);
330 return -ENOSPC;
331 }
332 list_add_tail(&t->list, &tx->sdu_list);
333 } else {
334 t = alloc_tx_struct(tx);
335 if (t == NULL) {
336 spin_unlock_irqrestore(&tx->lock, flags);
337 return -ENOMEM;
338 }
339 list_add_tail(&t->list, &tx->hci_list);
340 }
341
342 memcpy(t->buf + padding, data, len);
343 t->callback = cb;
344 t->cb_data = cb_data;
345
346 /*
347 * In some cases, USB Module of WiMax is blocked when data size is
348 * the multiple of 512. So, increment length by one in that case.
349 */
350 if ((len % 512) == 0)
351 len++;
352
353 usb_fill_bulk_urb(t->urb,
354 usbdev,
355 usb_sndbulkpipe(usbdev, 1),
356 t->buf,
357 len + padding,
358 gdm_usb_send_complete,
359 t);
360
361#ifdef DEBUG
362 hexdump("usb_send", t->buf, len + padding);
363#endif
364#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
365 if (usbdev->state & USB_STATE_SUSPENDED) {
366 list_add_tail(&t->p_list, &tx->pending_list);
367 schedule_work(&udev->pm_ws);
368 goto out;
369 }
370#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
371
372#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
373 if (udev->bw_switch) {
374 list_add_tail(&t->p_list, &tx->pending_list);
375 goto out;
376 } else if (cmd_evt == WIMAX_SCAN) {
377 struct rx_cxt *rx;
378 struct usb_rx *r;
379
380 rx = &udev->rx;
381
382 list_for_each_entry(r, &rx->used_list, list)
383 usb_unlink_urb(r->urb);
384 udev->bw_switch = 1;
385
386 spin_lock(&k_lock);
387 list_add_tail(&udev->list, &k_list);
388 spin_unlock(&k_lock);
389
390 wake_up(&k_wait);
391 }
392#endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
393
394 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
395 if (ret)
396 goto send_fail;
397
398#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
399 usb_mark_last_busy(usbdev);
400#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
401
402#if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
403out:
404#endif
405 spin_unlock_irqrestore(&tx->lock, flags);
406
407 if (no_spc)
408 return -ENOSPC;
409
410 return 0;
411
412send_fail:
413 t->callback = NULL;
414 gdm_usb_send_complete(t->urb);
415 spin_unlock_irqrestore(&tx->lock, flags);
416 return ret;
417}
418
419static void gdm_usb_rcv_complete(struct urb *urb)
420{
421 struct usb_rx *r = urb->context;
422 struct rx_cxt *rx = r->rx_cxt;
423 struct usbwm_dev *udev = container_of(r->rx_cxt, struct usbwm_dev, rx);
424 struct tx_cxt *tx = &udev->tx;
425 struct usb_tx *t;
426 u16 cmd_evt;
427 unsigned long flags;
428
429#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
430 struct usb_device *dev = urb->dev;
431#endif
432
433 /* Completion by usb_unlink_urb */
434 if (urb->status == -ECONNRESET)
435 return;
436
437 spin_lock_irqsave(&tx->lock, flags);
438
439 if (!urb->status) {
440 cmd_evt = (r->buf[0] << 8) | (r->buf[1]);
441#ifdef DEBUG
442 hexdump("usb_receive", r->buf, urb->actual_length);
443#endif
444 if (cmd_evt == WIMAX_SDU_TX_FLOW) {
445 if (r->buf[4] == 0) {
446#ifdef DEBUG
447 printk(KERN_DEBUG "WIMAX ==> STOP SDU TX\n");
448#endif
449 list_for_each_entry(t, &tx->sdu_list, list)
450 usb_unlink_urb(t->urb);
451 } else if (r->buf[4] == 1) {
452#ifdef DEBUG
453 printk(KERN_DEBUG "WIMAX ==> START SDU TX\n");
454#endif
455 list_for_each_entry(t, &tx->sdu_list, list) {
456 usb_submit_urb(t->urb, GFP_ATOMIC);
457 }
458 /*
459 * If free buffer for sdu tx doesn't
460 * exist, then tx queue should not be
461 * woken. For this reason, don't pass
462 * the command, START_SDU_TX.
463 */
464 if (list_empty(&tx->free_list))
465 urb->actual_length = 0;
466 }
467 }
468 }
469
470 if (!urb->status && r->callback)
471 r->callback(r->cb_data, r->buf, urb->actual_length);
472
473 spin_lock(&rx->lock);
474 put_rx_struct(rx, r);
475 spin_unlock(&rx->lock);
476
477 spin_unlock_irqrestore(&tx->lock, flags);
478
479#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
480 usb_mark_last_busy(dev);
481#endif
482}
483
484static int gdm_usb_receive(void *priv_dev,
485 void (*cb)(void *cb_data, void *data, int len),
486 void *cb_data)
487{
488 struct usbwm_dev *udev = priv_dev;
489 struct usb_device *usbdev = udev->usbdev;
490 struct rx_cxt *rx = &udev->rx;
491 struct usb_rx *r;
492 unsigned long flags;
493
494 if (!udev->usbdev) {
495 printk(KERN_ERR "%s: No such device\n", __func__);
496 return -ENODEV;
497 }
498
499 spin_lock_irqsave(&rx->lock, flags);
500 r = get_rx_struct(rx);
501 spin_unlock_irqrestore(&rx->lock, flags);
502
503 if (r == NULL)
504 return -ENOMEM;
505
506 r->callback = cb;
507 r->cb_data = cb_data;
508
509 usb_fill_bulk_urb(r->urb,
510 usbdev,
511 usb_rcvbulkpipe(usbdev, 0x82),
512 r->buf,
513 RX_BUF_SIZE,
514 gdm_usb_rcv_complete,
515 r);
516
517 return usb_submit_urb(r->urb, GFP_ATOMIC);
518}
519
520#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
521static void do_pm_control(struct work_struct *work)
522{
523 struct usbwm_dev *udev = container_of(work, struct usbwm_dev, pm_ws);
524 struct tx_cxt *tx = &udev->tx;
525 int ret;
526 unsigned long flags;
527
528 ret = usb_autopm_get_interface(udev->intf);
529 if (!ret)
530 usb_autopm_put_interface(udev->intf);
531
532 spin_lock_irqsave(&tx->lock, flags);
533 if (!(udev->usbdev->state & USB_STATE_SUSPENDED)
534 && (!list_empty(&tx->hci_list) || !list_empty(&tx->sdu_list))) {
535 struct usb_tx *t, *temp;
536
537 list_for_each_entry_safe(t, temp, &tx->pending_list, p_list) {
538 list_del(&t->p_list);
539 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
540
541 if (ret) {
542 t->callback = NULL;
543 gdm_usb_send_complete(t->urb);
544 }
545 }
546 }
547 spin_unlock_irqrestore(&tx->lock, flags);
548}
549#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
550
551static int gdm_usb_probe(struct usb_interface *intf,
552 const struct usb_device_id *id)
553{
554 int ret = 0;
555 u8 bConfigurationValue;
556 struct phy_dev *phy_dev = NULL;
557 struct usbwm_dev *udev = NULL;
558 u16 idVendor, idProduct, bcdDevice;
559
560 struct usb_device *usbdev = interface_to_usbdev(intf);
561
562 usb_get_dev(usbdev);
563 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
564
565 /*USB description is set up with Little-Endian*/
566 idVendor = L2H(usbdev->descriptor.idVendor);
567 idProduct = L2H(usbdev->descriptor.idProduct);
568 bcdDevice = L2H(usbdev->descriptor.bcdDevice);
569
570 printk(KERN_INFO "Found GDM USB VID = 0x%04x PID = 0x%04x...\n",
571 idVendor, idProduct);
572 printk(KERN_INFO "GCT WiMax driver version %s\n", DRIVER_VERSION);
573
574
575 if (idProduct == EMERGENCY_PID) {
576 ret = usb_emergency(usbdev);
577 goto out;
578 }
579
580 /* Support for EEPROM bootloader */
581 if (bConfigurationValue == DOWNLOAD_CONF_VALUE ||
582 idProduct & B_DOWNLOAD) {
583 ret = usb_boot(usbdev, bcdDevice);
584 goto out;
585 }
586
587 phy_dev = kmalloc(sizeof(*phy_dev), GFP_KERNEL);
588 if (phy_dev == NULL) {
589 ret = -ENOMEM;
590 goto out;
591 }
592 udev = kmalloc(sizeof(*udev), GFP_KERNEL);
593 if (udev == NULL) {
594 ret = -ENOMEM;
595 goto out;
596 }
597
598 memset(phy_dev, 0, sizeof(*phy_dev));
599 memset(udev, 0, sizeof(*udev));
600
601 if (idProduct == 0x7205 || idProduct == 0x7206)
602 udev->padding = GDM7205_PADDING;
603 else
604 udev->padding = 0;
605
606 phy_dev->priv_dev = (void *)udev;
607 phy_dev->send_func = gdm_usb_send;
608 phy_dev->rcv_func = gdm_usb_receive;
609
610 ret = init_usb(udev);
611 if (ret < 0)
612 goto out;
613
614 udev->usbdev = usbdev;
615
616#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
617 udev->intf = intf;
618
619 intf->needs_remote_wakeup = 1;
620 device_init_wakeup(&intf->dev, 1);
621
622 pm_runtime_set_autosuspend_delay(&usbdev->dev, 10 * 1000); /* msec */
623
624 INIT_WORK(&udev->pm_ws, do_pm_control);
625#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
626
627 ret = register_wimax_device(phy_dev, &intf->dev);
628
629out:
630 if (ret) {
631 kfree(phy_dev);
632 kfree(udev);
633 }
634 usb_set_intfdata(intf, phy_dev);
635 return ret;
636}
637
638static void gdm_usb_disconnect(struct usb_interface *intf)
639{
640 u8 bConfigurationValue;
641 struct phy_dev *phy_dev;
642 struct usbwm_dev *udev;
643 u16 idProduct;
644 struct usb_device *usbdev = interface_to_usbdev(intf);
645
646 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
647 phy_dev = usb_get_intfdata(intf);
648
649 /*USB description is set up with Little-Endian*/
650 idProduct = L2H(usbdev->descriptor.idProduct);
651
652 if (idProduct != EMERGENCY_PID &&
653 bConfigurationValue != DOWNLOAD_CONF_VALUE &&
654 (idProduct & B_DOWNLOAD) == 0) {
655 udev = phy_dev->priv_dev;
656 udev->usbdev = NULL;
657
658 unregister_wimax_device(phy_dev);
659 release_usb(udev);
660 kfree(udev);
661 kfree(phy_dev);
662 }
663
664 usb_put_dev(usbdev);
665}
666
667#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
668static int gdm_suspend(struct usb_interface *intf, pm_message_t pm_msg)
669{
670 struct phy_dev *phy_dev;
671 struct usbwm_dev *udev;
672 struct rx_cxt *rx;
673 struct usb_rx *r;
674
675 phy_dev = usb_get_intfdata(intf);
676 udev = phy_dev->priv_dev;
677 rx = &udev->rx;
678
679 list_for_each_entry(r, &rx->used_list, list)
680 usb_unlink_urb(r->urb);
681
682 return 0;
683}
684
685static int gdm_resume(struct usb_interface *intf)
686{
687 struct phy_dev *phy_dev;
688 struct usbwm_dev *udev;
689 struct rx_cxt *rx;
690 struct usb_rx *r;
691
692 phy_dev = usb_get_intfdata(intf);
693 udev = phy_dev->priv_dev;
694 rx = &udev->rx;
695
696 list_for_each_entry(r, &rx->used_list, list)
697 usb_submit_urb(r->urb, GFP_ATOMIC);
698
699 return 0;
700}
701
702#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
703
704#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
705static int k_mode_thread(void *arg)
706{
707 struct usbwm_dev *udev;
708 struct tx_cxt *tx;
709 struct rx_cxt *rx;
710 struct usb_tx *t, *temp;
711 struct usb_rx *r;
712 unsigned long flags, flags2, expire;
713 int ret;
714
715 daemonize("k_mode_wimax");
716
717 while (!k_mode_stop) {
718
719 spin_lock_irqsave(&k_lock, flags2);
720 while (!list_empty(&k_list)) {
721
722 udev = list_entry(k_list.next, struct usbwm_dev, list);
723 tx = &udev->tx;
724 rx = &udev->rx;
725
726 list_del(&udev->list);
727 spin_unlock_irqrestore(&k_lock, flags2);
728
729 expire = jiffies + K_WAIT_TIME;
730 while (jiffies < expire)
731 schedule_timeout(K_WAIT_TIME);
732
733 list_for_each_entry(r, &rx->used_list, list)
734 usb_submit_urb(r->urb, GFP_ATOMIC);
735
736 spin_lock_irqsave(&tx->lock, flags);
737
738 list_for_each_entry_safe(t, temp, &tx->pending_list,
739 p_list) {
740 list_del(&t->p_list);
741 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
742
743 if (ret) {
744 t->callback = NULL;
745 gdm_usb_send_complete(t->urb);
746 }
747 }
748
749 udev->bw_switch = 0;
750 spin_unlock_irqrestore(&tx->lock, flags);
751
752 spin_lock_irqsave(&k_lock, flags2);
753 }
754 spin_unlock_irqrestore(&k_lock, flags2);
755
756 interruptible_sleep_on(&k_wait);
757 }
758 return 0;
759}
760#endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
761
762static struct usb_driver gdm_usb_driver = {
763 .name = "gdm_wimax",
764 .probe = gdm_usb_probe,
765 .disconnect = gdm_usb_disconnect,
766 .id_table = id_table,
767#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
768 .supports_autosuspend = 1,
769 .suspend = gdm_suspend,
770 .resume = gdm_resume,
771 .reset_resume = gdm_resume,
772#endif
773};
774
775static int __init usb_gdm_wimax_init(void)
776{
777#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
778 kernel_thread(k_mode_thread, NULL, CLONE_KERNEL);
779#endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
780 return usb_register(&gdm_usb_driver);
781}
782
783static void __exit usb_gdm_wimax_exit(void)
784{
785#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
786 k_mode_stop = 1;
787 wake_up(&k_wait);
788#endif
789 usb_deregister(&gdm_usb_driver);
790}
791
792module_init(usb_gdm_wimax_init);
793module_exit(usb_gdm_wimax_exit);
794
795MODULE_VERSION(DRIVER_VERSION);
796MODULE_DESCRIPTION("GCT WiMax Device Driver");
797MODULE_AUTHOR("Ethan Park");
798MODULE_LICENSE("GPL");
diff --git a/drivers/staging/gdm72xx/gdm_usb.h b/drivers/staging/gdm72xx/gdm_usb.h
new file mode 100644
index 000000000000..ecb891f6a599
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_usb.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __GDM_USB_H__
15#define __GDM_USB_H__
16
17#include <linux/types.h>
18#include <linux/usb.h>
19#include <linux/list.h>
20
21#define B_DIFF_DL_DRV (1<<4)
22#define B_DOWNLOAD (1 << 5)
23#define MAX_NR_SDU_BUF 64
24
25struct usb_tx {
26 struct list_head list;
27#if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
28 struct list_head p_list;
29#endif
30 struct tx_cxt *tx_cxt;
31
32 struct urb *urb;
33 u8 *buf;
34
35 void (*callback)(void *cb_data);
36 void *cb_data;
37};
38
39struct tx_cxt {
40 struct list_head free_list;
41 struct list_head sdu_list;
42 struct list_head hci_list;
43#if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
44 struct list_head pending_list;
45#endif
46
47 spinlock_t lock;
48};
49
50struct usb_rx {
51 struct list_head list;
52 struct rx_cxt *rx_cxt;
53
54 struct urb *urb;
55 u8 *buf;
56
57 void (*callback)(void *cb_data, void *data, int len);
58 void *cb_data;
59};
60
61struct rx_cxt {
62 struct list_head free_list;
63 struct list_head used_list;
64 spinlock_t lock;
65};
66
67struct usbwm_dev {
68 struct usb_device *usbdev;
69#ifdef CONFIG_WIMAX_GDM72XX_USB_PM
70 struct work_struct pm_ws;
71
72 struct usb_interface *intf;
73#endif
74#ifdef CONFIG_WIMAX_GDM72XX_K_MODE
75 int bw_switch;
76 struct list_head list;
77#endif
78
79 struct tx_cxt tx;
80 struct rx_cxt rx;
81
82 int padding;
83};
84
85#endif /* __GDM_USB_H__ */
diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c
new file mode 100644
index 000000000000..f1936b92533b
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -0,0 +1,1026 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/version.h>
15#include <linux/etherdevice.h>
16#include <asm/byteorder.h>
17#include <linux/ip.h>
18#include <linux/ipv6.h>
19#include <linux/udp.h>
20#include <linux/in.h>
21
22#include "gdm_wimax.h"
23#include "hci.h"
24#include "wm_ioctl.h"
25#include "netlink_k.h"
26
27#define gdm_wimax_send(n, d, l) \
28 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, NULL, NULL)
29#define gdm_wimax_send_with_cb(n, d, l, c, b) \
30 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, c, b)
31#define gdm_wimax_rcv_with_cb(n, c, b) \
32 (n->phy_dev->rcv_func)(n->phy_dev->priv_dev, c, b)
33
34#define EVT_MAX_SIZE 2048
35
36struct evt_entry {
37 struct list_head list;
38 struct net_device *dev;
39 char evt_data[EVT_MAX_SIZE];
40 int size;
41};
42
43static void __gdm_wimax_event_send(struct work_struct *work);
44static inline struct evt_entry *alloc_event_entry(void);
45static inline void free_event_entry(struct evt_entry *e);
46static struct evt_entry *get_event_entry(void);
47static void put_event_entry(struct evt_entry *e);
48
49static struct {
50 int ref_cnt;
51 struct sock *sock;
52 struct list_head evtq;
53 spinlock_t evt_lock;
54
55 struct list_head freeq;
56 struct work_struct ws;
57} wm_event;
58
59static u8 gdm_wimax_macaddr[6] = {0x00, 0x0a, 0x3b, 0xf0, 0x01, 0x30};
60
61static void gdm_wimax_ind_fsm_update(struct net_device *dev, struct fsm_s *fsm);
62static void gdm_wimax_ind_if_updown(struct net_device *dev, int if_up);
63
64#if defined(DEBUG_SDU)
65static void printk_hex(u8 *buf, u32 size)
66{
67 int i;
68
69 for (i = 0; i < size; i++) {
70 if (i && i % 16 == 0)
71 printk(KERN_DEBUG "\n%02x ", *buf++);
72 else
73 printk(KERN_DEBUG "%02x ", *buf++);
74 }
75
76 printk(KERN_DEBUG "\n");
77}
78
79static const char *get_protocol_name(u16 protocol)
80{
81 static char buf[32];
82 const char *name = "-";
83
84 switch (protocol) {
85 case ETH_P_ARP:
86 name = "ARP";
87 break;
88 case ETH_P_IP:
89 name = "IP";
90 break;
91 case ETH_P_IPV6:
92 name = "IPv6";
93 break;
94 }
95
96 sprintf(buf, "0x%04x(%s)", protocol, name);
97 return buf;
98}
99
100static const char *get_ip_protocol_name(u8 ip_protocol)
101{
102 static char buf[32];
103 const char *name = "-";
104
105 switch (ip_protocol) {
106 case IPPROTO_TCP:
107 name = "TCP";
108 break;
109 case IPPROTO_UDP:
110 name = "UDP";
111 break;
112 case IPPROTO_ICMP:
113 name = "ICMP";
114 break;
115 }
116
117 sprintf(buf, "%u(%s)", ip_protocol, name);
118 return buf;
119}
120
121static const char *get_port_name(u16 port)
122{
123 static char buf[32];
124 const char *name = "-";
125
126 switch (port) {
127 case 67:
128 name = "DHCP-Server";
129 break;
130 case 68:
131 name = "DHCP-Client";
132 break;
133 case 69:
134 name = "TFTP";
135 break;
136 }
137
138 sprintf(buf, "%u(%s)", port, name);
139 return buf;
140}
141
142static void dump_eth_packet(const char *title, u8 *data, int len)
143{
144 struct iphdr *ih = NULL;
145 struct udphdr *uh = NULL;
146 u16 protocol = 0;
147 u8 ip_protocol = 0;
148 u16 port = 0;
149
150 protocol = (data[12]<<8) | data[13];
151 ih = (struct iphdr *) (data+ETH_HLEN);
152
153 if (protocol == ETH_P_IP) {
154 uh = (struct udphdr *) ((char *)ih + sizeof(struct iphdr));
155 ip_protocol = ih->protocol;
156 port = ntohs(uh->dest);
157 } else if (protocol == ETH_P_IPV6) {
158 struct ipv6hdr *i6h = (struct ipv6hdr *) data;
159 uh = (struct udphdr *) ((char *)i6h + sizeof(struct ipv6hdr));
160 ip_protocol = i6h->nexthdr;
161 port = ntohs(uh->dest);
162 }
163
164 printk(KERN_DEBUG "[%s] len=%d, %s, %s, %s\n",
165 title, len,
166 get_protocol_name(protocol),
167 get_ip_protocol_name(ip_protocol),
168 get_port_name(port));
169
170 #if 1
171 if (!(data[0] == 0xff && data[1] == 0xff)) {
172 if (protocol == ETH_P_IP) {
173 printk(KERN_DEBUG " src=%u.%u.%u.%u\n",
174 NIPQUAD(ih->saddr));
175 } else if (protocol == ETH_P_IPV6) {
176 #ifdef NIP6
177 printk(KERN_DEBUG " src=%x:%x:%x:%x:%x:%x:%x:%x\n",
178 NIP6(ih->saddr));
179 #else
180 printk(KERN_DEBUG " src=%pI6\n", &ih->saddr);
181 #endif
182 }
183 }
184 #endif
185
186 #if (DUMP_PACKET & DUMP_SDU_ALL)
187 printk_hex(data, len);
188 #else
189 #if (DUMP_PACKET & DUMP_SDU_ARP)
190 if (protocol == ETH_P_ARP)
191 printk_hex(data, len);
192 #endif
193 #if (DUMP_PACKET & DUMP_SDU_IP)
194 if (protocol == ETH_P_IP || protocol == ETH_P_IPV6)
195 printk_hex(data, len);
196 #else
197 #if (DUMP_PACKET & DUMP_SDU_IP_TCP)
198 if (ip_protocol == IPPROTO_TCP)
199 printk_hex(data, len);
200 #endif
201 #if (DUMP_PACKET & DUMP_SDU_IP_UDP)
202 if (ip_protocol == IPPROTO_UDP)
203 printk_hex(data, len);
204 #endif
205 #if (DUMP_PACKET & DUMP_SDU_IP_ICMP)
206 if (ip_protocol == IPPROTO_ICMP)
207 printk_hex(data, len);
208 #endif
209 #endif
210 #endif
211}
212#endif
213
214
215static inline int gdm_wimax_header(struct sk_buff **pskb)
216{
217 u16 buf[HCI_HEADER_SIZE / sizeof(u16)];
218 struct sk_buff *skb = *pskb;
219 int ret = 0;
220
221 if (unlikely(skb_headroom(skb) < HCI_HEADER_SIZE)) {
222 struct sk_buff *skb2;
223
224 skb2 = skb_realloc_headroom(skb, HCI_HEADER_SIZE);
225 if (skb2 == NULL)
226 return -ENOMEM;
227 if (skb->sk)
228 skb_set_owner_w(skb2, skb->sk);
229 kfree_skb(skb);
230 skb = skb2;
231 }
232
233 skb_push(skb, HCI_HEADER_SIZE);
234 buf[0] = H2B(WIMAX_TX_SDU);
235 buf[1] = H2B(skb->len - HCI_HEADER_SIZE);
236 memcpy(skb->data, buf, HCI_HEADER_SIZE);
237
238 *pskb = skb;
239 return ret;
240}
241
242static void gdm_wimax_event_rcv(struct net_device *dev, u16 type, void *msg,
243 int len)
244{
245 struct nic *nic = netdev_priv(dev);
246
247 #if defined(DEBUG_HCI)
248 u8 *buf = (u8 *) msg;
249 u16 hci_cmd = (buf[0]<<8) | buf[1];
250 u16 hci_len = (buf[2]<<8) | buf[3];
251 printk(KERN_DEBUG "H=>D: 0x%04x(%d)\n", hci_cmd, hci_len);
252 #endif
253
254 gdm_wimax_send(nic, msg, len);
255}
256
257static int gdm_wimax_event_init(void)
258{
259 if (wm_event.ref_cnt == 0) {
260 wm_event.sock = netlink_init(NETLINK_WIMAX,
261 gdm_wimax_event_rcv);
262 INIT_LIST_HEAD(&wm_event.evtq);
263 INIT_LIST_HEAD(&wm_event.freeq);
264 INIT_WORK(&wm_event.ws, __gdm_wimax_event_send);
265 spin_lock_init(&wm_event.evt_lock);
266 }
267
268 if (wm_event.sock) {
269 wm_event.ref_cnt++;
270 return 0;
271 }
272
273 printk(KERN_ERR "Creating WiMax Event netlink is failed\n");
274 return -1;
275}
276
277static void gdm_wimax_event_exit(void)
278{
279 if (wm_event.sock && --wm_event.ref_cnt == 0) {
280 struct evt_entry *e, *temp;
281 unsigned long flags;
282
283 spin_lock_irqsave(&wm_event.evt_lock, flags);
284
285 list_for_each_entry_safe(e, temp, &wm_event.evtq, list) {
286 list_del(&e->list);
287 free_event_entry(e);
288 }
289 list_for_each_entry_safe(e, temp, &wm_event.freeq, list) {
290 list_del(&e->list);
291 free_event_entry(e);
292 }
293
294 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
295 netlink_exit(wm_event.sock);
296 wm_event.sock = NULL;
297 }
298}
299
300static inline struct evt_entry *alloc_event_entry(void)
301{
302 return kmalloc(sizeof(struct evt_entry), GFP_ATOMIC);
303}
304
305static inline void free_event_entry(struct evt_entry *e)
306{
307 kfree(e);
308}
309
310static struct evt_entry *get_event_entry(void)
311{
312 struct evt_entry *e;
313
314 if (list_empty(&wm_event.freeq))
315 e = alloc_event_entry();
316 else {
317 e = list_entry(wm_event.freeq.next, struct evt_entry, list);
318 list_del(&e->list);
319 }
320
321 return e;
322}
323
324static void put_event_entry(struct evt_entry *e)
325{
326 BUG_ON(!e);
327
328 list_add_tail(&e->list, &wm_event.freeq);
329}
330
331static void __gdm_wimax_event_send(struct work_struct *work)
332{
333 int idx;
334 unsigned long flags;
335 struct evt_entry *e;
336
337 spin_lock_irqsave(&wm_event.evt_lock, flags);
338
339 while (!list_empty(&wm_event.evtq)) {
340 e = list_entry(wm_event.evtq.next, struct evt_entry, list);
341 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
342
343 sscanf(e->dev->name, "wm%d", &idx);
344 netlink_send(wm_event.sock, idx, 0, e->evt_data, e->size);
345
346 spin_lock_irqsave(&wm_event.evt_lock, flags);
347 list_del(&e->list);
348 put_event_entry(e);
349 }
350
351 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
352}
353
354static int gdm_wimax_event_send(struct net_device *dev, char *buf, int size)
355{
356 struct evt_entry *e;
357 unsigned long flags;
358
359 #if defined(DEBUG_HCI)
360 u16 hci_cmd = ((u8)buf[0]<<8) | (u8)buf[1];
361 u16 hci_len = ((u8)buf[2]<<8) | (u8)buf[3];
362 printk(KERN_DEBUG "D=>H: 0x%04x(%d)\n", hci_cmd, hci_len);
363 #endif
364
365 spin_lock_irqsave(&wm_event.evt_lock, flags);
366
367 e = get_event_entry();
368 if (!e) {
369 printk(KERN_ERR "%s: No memory for event\n", __func__);
370 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
371 return -ENOMEM;
372 }
373
374 e->dev = dev;
375 e->size = size;
376 memcpy(e->evt_data, buf, size);
377
378 list_add_tail(&e->list, &wm_event.evtq);
379 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
380
381 schedule_work(&wm_event.ws);
382
383 return 0;
384}
385
386static void tx_complete(void *arg)
387{
388 struct nic *nic = arg;
389
390 if (netif_queue_stopped(nic->netdev))
391 netif_wake_queue(nic->netdev);
392}
393
394int gdm_wimax_send_tx(struct sk_buff *skb, struct net_device *dev)
395{
396 int ret = 0;
397 struct nic *nic = netdev_priv(dev);
398
399 ret = gdm_wimax_send_with_cb(nic, skb->data, skb->len, tx_complete,
400 nic);
401 if (ret == -ENOSPC) {
402 netif_stop_queue(dev);
403 ret = 0;
404 }
405
406 if (ret) {
407 skb_pull(skb, HCI_HEADER_SIZE);
408 return ret;
409 }
410
411 nic->stats.tx_packets++;
412 nic->stats.tx_bytes += skb->len - HCI_HEADER_SIZE;
413 kfree_skb(skb);
414 return ret;
415}
416
417static int gdm_wimax_tx(struct sk_buff *skb, struct net_device *dev)
418{
419 int ret = 0;
420 struct nic *nic = netdev_priv(dev);
421 struct fsm_s *fsm = (struct fsm_s *) nic->sdk_data[SIOC_DATA_FSM].buf;
422
423 #if defined(DEBUG_SDU)
424 dump_eth_packet("TX", skb->data, skb->len);
425 #endif
426
427 ret = gdm_wimax_header(&skb);
428 if (ret < 0) {
429 skb_pull(skb, HCI_HEADER_SIZE);
430 return ret;
431 }
432
433 #if !defined(LOOPBACK_TEST)
434 if (!fsm)
435 printk(KERN_ERR "ASSERTION ERROR: fsm is NULL!!\n");
436 else if (fsm->m_status != M_CONNECTED) {
437 printk(KERN_EMERG "ASSERTION ERROR: Device is NOT ready. status=%d\n",
438 fsm->m_status);
439 kfree_skb(skb);
440 return 0;
441 }
442 #endif
443
444#if defined(CONFIG_WIMAX_GDM72XX_QOS)
445 ret = gdm_qos_send_hci_pkt(skb, dev);
446#else
447 ret = gdm_wimax_send_tx(skb, dev);
448#endif
449 return ret;
450}
451
452static int gdm_wimax_set_config(struct net_device *dev, struct ifmap *map)
453{
454 if (dev->flags & IFF_UP)
455 return -EBUSY;
456
457 return 0;
458}
459
460static void __gdm_wimax_set_mac_addr(struct net_device *dev, char *mac_addr)
461{
462 u16 hci_pkt_buf[32 / sizeof(u16)];
463 u8 *pkt = (u8 *) &hci_pkt_buf[0];
464 struct nic *nic = netdev_priv(dev);
465
466 /* Since dev is registered as a ethernet device,
467 * ether_setup has made dev->addr_len to be ETH_ALEN
468 */
469 memcpy(dev->dev_addr, mac_addr, dev->addr_len);
470
471 /* Let lower layer know of this change by sending
472 * SetInformation(MAC Address)
473 */
474 hci_pkt_buf[0] = H2B(WIMAX_SET_INFO); /* cmd_evt */
475 hci_pkt_buf[1] = H2B(8); /* size */
476 pkt[4] = 0; /* T */
477 pkt[5] = 6; /* L */
478 memcpy(pkt + 6, mac_addr, dev->addr_len); /* V */
479
480 gdm_wimax_send(nic, pkt, HCI_HEADER_SIZE + 8);
481}
482
483/* A driver function */
484static int gdm_wimax_set_mac_addr(struct net_device *dev, void *p)
485{
486 struct sockaddr *addr = p;
487
488 if (netif_running(dev))
489 return -EBUSY;
490
491 if (!is_valid_ether_addr(addr->sa_data))
492 return -EADDRNOTAVAIL;
493
494 __gdm_wimax_set_mac_addr(dev, addr->sa_data);
495
496 return 0;
497}
498
499static struct net_device_stats *gdm_wimax_stats(struct net_device *dev)
500{
501 struct nic *nic = netdev_priv(dev);
502
503 return &nic->stats;
504}
505
506static int gdm_wimax_open(struct net_device *dev)
507{
508 struct nic *nic = netdev_priv(dev);
509 struct fsm_s *fsm = (struct fsm_s *) nic->sdk_data[SIOC_DATA_FSM].buf;
510
511 netif_start_queue(dev);
512
513 if (fsm && fsm->m_status != M_INIT)
514 gdm_wimax_ind_if_updown(dev, 1);
515 return 0;
516}
517
518static int gdm_wimax_close(struct net_device *dev)
519{
520 struct nic *nic = netdev_priv(dev);
521 struct fsm_s *fsm = (struct fsm_s *) nic->sdk_data[SIOC_DATA_FSM].buf;
522
523 netif_stop_queue(dev);
524
525 if (fsm && fsm->m_status != M_INIT)
526 gdm_wimax_ind_if_updown(dev, 0);
527 return 0;
528}
529
530static void kdelete(void **buf)
531{
532 if (buf && *buf) {
533 kfree(*buf);
534 *buf = NULL;
535 }
536}
537
538static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
539{
540 int size;
541
542 size = dst->size < src->size ? dst->size : src->size;
543
544 dst->size = size;
545 if (src->size) {
546 if (!dst->buf)
547 return -EINVAL;
548 if (copy_to_user(dst->buf, src->buf, size))
549 return -EFAULT;
550 }
551 return 0;
552}
553
554static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src)
555{
556 if (!src->size) {
557 dst->size = 0;
558 return 0;
559 }
560
561 if (!src->buf)
562 return -EINVAL;
563
564 if (!(dst->buf && dst->size == src->size)) {
565 kdelete(&dst->buf);
566 dst->buf = kmalloc(src->size, GFP_KERNEL);
567 if (dst->buf == NULL)
568 return -ENOMEM;
569 }
570
571 if (copy_from_user(dst->buf, src->buf, src->size)) {
572 kdelete(&dst->buf);
573 return -EFAULT;
574 }
575 dst->size = src->size;
576 return 0;
577}
578
579static void gdm_wimax_cleanup_ioctl(struct net_device *dev)
580{
581 struct nic *nic = netdev_priv(dev);
582 int i;
583
584 for (i = 0; i < SIOC_DATA_MAX; i++)
585 kdelete(&nic->sdk_data[i].buf);
586}
587
588static void gdm_update_fsm(struct net_device *dev, struct fsm_s *new_fsm)
589{
590 struct nic *nic = netdev_priv(dev);
591 struct fsm_s *cur_fsm =
592 (struct fsm_s *) nic->sdk_data[SIOC_DATA_FSM].buf;
593
594 if (!cur_fsm)
595 return;
596
597 if (cur_fsm->m_status != new_fsm->m_status ||
598 cur_fsm->c_status != new_fsm->c_status) {
599 if (new_fsm->m_status == M_CONNECTED)
600 netif_carrier_on(dev);
601 else if (cur_fsm->m_status == M_CONNECTED) {
602 netif_carrier_off(dev);
603 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
604 gdm_qos_release_list(nic);
605 #endif
606 }
607 gdm_wimax_ind_fsm_update(dev, new_fsm);
608 }
609}
610
611static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
612{
613 struct wm_req_s *req = (struct wm_req_s *) ifr;
614 struct nic *nic = netdev_priv(dev);
615 int ret;
616
617 if (cmd != SIOCWMIOCTL)
618 return -EOPNOTSUPP;
619
620 switch (req->cmd) {
621 case SIOCG_DATA:
622 case SIOCS_DATA:
623 if (req->data_id >= SIOC_DATA_MAX) {
624 printk(KERN_ERR
625 "%s error: data-index(%d) is invalid!!\n",
626 __func__, req->data_id);
627 return -EOPNOTSUPP;
628 }
629 if (req->cmd == SIOCG_DATA) {
630 ret = gdm_wimax_ioctl_get_data(&req->data,
631 &nic->sdk_data[req->data_id]);
632 if (ret < 0)
633 return ret;
634 } else if (req->cmd == SIOCS_DATA) {
635 if (req->data_id == SIOC_DATA_FSM) {
636 /*NOTE: gdm_update_fsm should be called
637 before gdm_wimax_ioctl_set_data is called*/
638 gdm_update_fsm(dev,
639 (struct fsm_s *) req->data.buf);
640 }
641 ret = gdm_wimax_ioctl_set_data(
642 &nic->sdk_data[req->data_id], &req->data);
643 if (ret < 0)
644 return ret;
645 }
646 break;
647 default:
648 printk(KERN_ERR "%s: %x unknown ioctl\n", __func__, cmd);
649 return -EOPNOTSUPP;
650 }
651
652 return 0;
653}
654
655static void gdm_wimax_prepare_device(struct net_device *dev)
656{
657 struct nic *nic = netdev_priv(dev);
658 u16 buf[32 / sizeof(u16)];
659 struct hci_s *hci = (struct hci_s *) buf;
660 u16 len = 0;
661 u32 val = 0;
662
663 #define BIT_MULTI_CS 0
664 #define BIT_WIMAX 1
665 #define BIT_QOS 2
666 #define BIT_AGGREGATION 3
667
668 /* GetInformation mac address */
669 len = 0;
670 hci->cmd_evt = H2B(WIMAX_GET_INFO);
671 hci->data[len++] = TLV_T(T_MAC_ADDRESS);
672 hci->length = H2B(len);
673 gdm_wimax_send(nic, hci, HCI_HEADER_SIZE+len);
674
675 val = (1<<BIT_WIMAX) | (1<<BIT_MULTI_CS);
676 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
677 val |= (1<<BIT_QOS);
678 #endif
679 #if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
680 val |= (1<<BIT_AGGREGATION);
681 #endif
682
683 /* Set capability */
684 len = 0;
685 hci->cmd_evt = H2B(WIMAX_SET_INFO);
686 hci->data[len++] = TLV_T(T_CAPABILITY);
687 hci->data[len++] = TLV_L(T_CAPABILITY);
688 val = DH2B(val);
689 memcpy(&hci->data[len], &val, TLV_L(T_CAPABILITY));
690 len += TLV_L(T_CAPABILITY);
691 hci->length = H2B(len);
692 gdm_wimax_send(nic, hci, HCI_HEADER_SIZE+len);
693
694 printk(KERN_INFO "GDM WiMax Set CAPABILITY: 0x%08X\n", DB2H(val));
695}
696
697static int gdm_wimax_hci_get_tlv(u8 *buf, u8 *T, u16 *L, u8 **V)
698{
699 #define __U82U16(b) ((u16)((u8 *)(b))[0] | ((u16)((u8 *)(b))[1] << 8))
700 int next_pos;
701
702 *T = buf[0];
703 if (buf[1] == 0x82) {
704 *L = B2H(__U82U16(&buf[2]));
705 next_pos = 1/*type*/+3/*len*/;
706 } else {
707 *L = buf[1];
708 next_pos = 1/*type*/+1/*len*/;
709 }
710 *V = &buf[next_pos];
711
712 next_pos += *L/*length of val*/;
713 return next_pos;
714}
715
716static int gdm_wimax_get_prepared_info(struct net_device *dev, char *buf,
717 int len)
718{
719 u8 T, *V;
720 u16 L;
721 u16 cmd_evt, cmd_len;
722 int pos = HCI_HEADER_SIZE;
723
724 cmd_evt = B2H(*(u16 *)&buf[0]);
725 cmd_len = B2H(*(u16 *)&buf[2]);
726
727 if (len < cmd_len + HCI_HEADER_SIZE) {
728 printk(KERN_ERR "%s: invalid length [%d/%d]\n", __func__,
729 cmd_len + HCI_HEADER_SIZE, len);
730 return -1;
731 }
732
733 if (cmd_evt == WIMAX_GET_INFO_RESULT) {
734 if (cmd_len < 2) {
735 printk(KERN_ERR "%s: len is too short [%x/%d]\n",
736 __func__, cmd_evt, len);
737 return -1;
738 }
739
740 pos += gdm_wimax_hci_get_tlv(&buf[pos], &T, &L, &V);
741 if (T == TLV_T(T_MAC_ADDRESS)) {
742 if (L != dev->addr_len) {
743 printk(KERN_ERR
744 "%s Invalid inofrmation result T/L "
745 "[%x/%d]\n", __func__, T, L);
746 return -1;
747 }
748 printk(KERN_INFO
749 "MAC change [%02x:%02x:%02x:%02x:%02x:%02x]"
750 "->[%02x:%02x:%02x:%02x:%02x:%02x]\n",
751 dev->dev_addr[0], dev->dev_addr[1],
752 dev->dev_addr[2], dev->dev_addr[3],
753 dev->dev_addr[4], dev->dev_addr[5],
754 V[0], V[1], V[2], V[3], V[4], V[5]);
755 memcpy(dev->dev_addr, V, dev->addr_len);
756 return 1;
757 }
758 }
759
760 gdm_wimax_event_send(dev, buf, len);
761 return 0;
762}
763
764static void gdm_wimax_netif_rx(struct net_device *dev, char *buf, int len)
765{
766 struct nic *nic = netdev_priv(dev);
767 struct sk_buff *skb;
768 int ret;
769
770 #if defined(DEBUG_SDU)
771 dump_eth_packet("RX", buf, len);
772 #endif
773
774 skb = dev_alloc_skb(len + 2);
775 if (!skb) {
776 printk(KERN_ERR "%s: dev_alloc_skb failed!\n", __func__);
777 return;
778 }
779 skb_reserve(skb, 2);
780
781 nic->stats.rx_packets++;
782 nic->stats.rx_bytes += len;
783
784 memcpy(skb_put(skb, len), buf, len);
785
786 skb->dev = dev;
787 skb->protocol = eth_type_trans(skb, dev); /* what will happen? */
788
789 ret = in_interrupt() ? netif_rx(skb) : netif_rx_ni(skb);
790 if (ret == NET_RX_DROP)
791 printk(KERN_ERR "%s skb dropped\n", __func__);
792}
793
794static void gdm_wimax_transmit_aggr_pkt(struct net_device *dev, char *buf,
795 int len)
796{
797 #define HCI_PADDING_BYTE 4
798 #define HCI_RESERVED_BYTE 4
799 struct hci_s *hci;
800 int length;
801
802 while (len > 0) {
803 hci = (struct hci_s *) buf;
804
805 if (B2H(hci->cmd_evt) != WIMAX_RX_SDU) {
806 printk(KERN_ERR "Wrong cmd_evt(0x%04X)\n",
807 B2H(hci->cmd_evt));
808 break;
809 }
810
811 length = B2H(hci->length);
812 gdm_wimax_netif_rx(dev, hci->data, length);
813
814 if (length & 0x3) {
815 /* Add padding size */
816 length += HCI_PADDING_BYTE - (length & 0x3);
817 }
818
819 length += HCI_HEADER_SIZE + HCI_RESERVED_BYTE;
820 len -= length;
821 buf += length;
822 }
823}
824
825static void gdm_wimax_transmit_pkt(struct net_device *dev, char *buf, int len)
826{
827 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
828 struct nic *nic = netdev_priv(dev);
829 #endif
830 u16 cmd_evt, cmd_len;
831
832 /* This code is added for certain rx packet to be ignored. */
833 if (len == 0)
834 return;
835
836 cmd_evt = B2H(*(u16 *)&buf[0]);
837 cmd_len = B2H(*(u16 *)&buf[2]);
838
839 if (len < cmd_len + HCI_HEADER_SIZE) {
840 if (len)
841 printk(KERN_ERR "%s: invalid length [%d/%d]\n",
842 __func__, cmd_len + HCI_HEADER_SIZE, len);
843 return;
844 }
845
846 switch (cmd_evt) {
847 case WIMAX_RX_SDU_AGGR:
848 gdm_wimax_transmit_aggr_pkt(dev, &buf[HCI_HEADER_SIZE],
849 cmd_len);
850 break;
851 case WIMAX_RX_SDU:
852 gdm_wimax_netif_rx(dev, &buf[HCI_HEADER_SIZE], cmd_len);
853 break;
854 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
855 case WIMAX_EVT_MODEM_REPORT:
856 gdm_recv_qos_hci_packet(nic, buf, len);
857 break;
858 #endif
859 case WIMAX_SDU_TX_FLOW:
860 if (buf[4] == 0) {
861 if (!netif_queue_stopped(dev))
862 netif_stop_queue(dev);
863 } else if (buf[4] == 1) {
864 if (netif_queue_stopped(dev))
865 netif_wake_queue(dev);
866 }
867 break;
868 default:
869 gdm_wimax_event_send(dev, buf, len);
870 break;
871 }
872}
873
874static void gdm_wimax_ind_fsm_update(struct net_device *dev, struct fsm_s *fsm)
875{
876 u16 buf[32 / sizeof(u16)];
877 u8 *hci_pkt_buf = (u8 *)&buf[0];
878
879 /* Indicate updating fsm */
880 buf[0] = H2B(WIMAX_FSM_UPDATE);
881 buf[1] = H2B(sizeof(struct fsm_s));
882 memcpy(&hci_pkt_buf[HCI_HEADER_SIZE], fsm, sizeof(struct fsm_s));
883
884 gdm_wimax_event_send(dev, hci_pkt_buf,
885 HCI_HEADER_SIZE + sizeof(struct fsm_s));
886}
887
888static void gdm_wimax_ind_if_updown(struct net_device *dev, int if_up)
889{
890 u16 buf[32 / sizeof(u16)];
891 struct hci_s *hci = (struct hci_s *) buf;
892 unsigned char up_down;
893
894 up_down = if_up ? WIMAX_IF_UP : WIMAX_IF_DOWN;
895
896 /* Indicate updating fsm */
897 hci->cmd_evt = H2B(WIMAX_IF_UPDOWN);
898 hci->length = H2B(sizeof(up_down));
899 hci->data[0] = up_down;
900
901 gdm_wimax_event_send(dev, (char *)hci, HCI_HEADER_SIZE+sizeof(up_down));
902}
903
904static void rx_complete(void *arg, void *data, int len)
905{
906 struct nic *nic = arg;
907
908 gdm_wimax_transmit_pkt(nic->netdev, data, len);
909 gdm_wimax_rcv_with_cb(nic, rx_complete, nic);
910}
911
912static void prepare_rx_complete(void *arg, void *data, int len)
913{
914 struct nic *nic = arg;
915 int ret;
916
917 ret = gdm_wimax_get_prepared_info(nic->netdev, data, len);
918 if (ret == 1)
919 gdm_wimax_rcv_with_cb(nic, rx_complete, nic);
920 else {
921 if (ret < 0)
922 printk(KERN_ERR "get_prepared_info failed(%d)\n", ret);
923 gdm_wimax_rcv_with_cb(nic, prepare_rx_complete, nic);
924 #if 0
925 /* Re-prepare WiMax device */
926 gdm_wimax_prepare_device(nic->netdev);
927 #endif
928 }
929}
930
931static void start_rx_proc(struct nic *nic)
932{
933 gdm_wimax_rcv_with_cb(nic, prepare_rx_complete, nic);
934}
935
936static struct net_device_ops gdm_netdev_ops = {
937 .ndo_open = gdm_wimax_open,
938 .ndo_stop = gdm_wimax_close,
939 .ndo_set_config = gdm_wimax_set_config,
940 .ndo_start_xmit = gdm_wimax_tx,
941 .ndo_get_stats = gdm_wimax_stats,
942 .ndo_set_mac_address = gdm_wimax_set_mac_addr,
943 .ndo_do_ioctl = gdm_wimax_ioctl,
944};
945
946int register_wimax_device(struct phy_dev *phy_dev, struct device *pdev)
947{
948 struct nic *nic = NULL;
949 struct net_device *dev;
950 int ret;
951
952 dev = (struct net_device *)alloc_netdev(sizeof(*nic),
953 "wm%d", ether_setup);
954
955 if (dev == NULL) {
956 printk(KERN_ERR "alloc_etherdev failed\n");
957 return -ENOMEM;
958 }
959
960 SET_NETDEV_DEV(dev, pdev);
961 dev->mtu = 1400;
962 dev->netdev_ops = &gdm_netdev_ops;
963 dev->flags &= ~IFF_MULTICAST;
964 memcpy(dev->dev_addr, gdm_wimax_macaddr, sizeof(gdm_wimax_macaddr));
965
966 nic = netdev_priv(dev);
967 memset(nic, 0, sizeof(*nic));
968
969 nic->netdev = dev;
970 nic->phy_dev = phy_dev;
971 phy_dev->netdev = dev;
972
973 /* event socket init */
974 ret = gdm_wimax_event_init();
975 if (ret < 0) {
976 printk(KERN_ERR "Cannot create event.\n");
977 goto cleanup;
978 }
979
980 ret = register_netdev(dev);
981 if (ret)
982 goto cleanup;
983
984 #if defined(LOOPBACK_TEST)
985 netif_start_queue(dev);
986 netif_carrier_on(dev);
987 #else
988 netif_carrier_off(dev);
989 #endif
990
991#ifdef CONFIG_WIMAX_GDM72XX_QOS
992 gdm_qos_init(nic);
993#endif
994
995 start_rx_proc(nic);
996
997 /* Prepare WiMax device */
998 gdm_wimax_prepare_device(dev);
999
1000 return 0;
1001
1002cleanup:
1003 printk(KERN_ERR "register_netdev failed\n");
1004 free_netdev(dev);
1005 return ret;
1006}
1007
1008void unregister_wimax_device(struct phy_dev *phy_dev)
1009{
1010 struct nic *nic = netdev_priv(phy_dev->netdev);
1011 struct fsm_s *fsm = (struct fsm_s *) nic->sdk_data[SIOC_DATA_FSM].buf;
1012
1013 if (fsm)
1014 fsm->m_status = M_INIT;
1015 unregister_netdev(nic->netdev);
1016
1017 gdm_wimax_event_exit();
1018
1019#if defined(CONFIG_WIMAX_GDM72XX_QOS)
1020 gdm_qos_release_list(nic);
1021#endif
1022
1023 gdm_wimax_cleanup_ioctl(phy_dev->netdev);
1024
1025 free_netdev(nic->netdev);
1026}
diff --git a/drivers/staging/gdm72xx/gdm_wimax.h b/drivers/staging/gdm72xx/gdm_wimax.h
new file mode 100644
index 000000000000..023e6492e33d
--- /dev/null
+++ b/drivers/staging/gdm72xx/gdm_wimax.h
@@ -0,0 +1,92 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __GDM_WIMAX_H__
15#define __GDM_WIMAX_H__
16
17#include <linux/netdevice.h>
18#include <linux/version.h>
19#include <linux/types.h>
20#include "wm_ioctl.h"
21#if defined(CONFIG_WIMAX_GDM72XX_QOS)
22#include "gdm_qos.h"
23#endif
24
25#define DRIVER_VERSION "3.2.3"
26
27/*#define ETH_P_IP 0x0800 */
28/*#define ETH_P_ARP 0x0806 */
29/*#define ETH_P_IPV6 0x86DD */
30
31#define H2L(x) __cpu_to_le16(x)
32#define L2H(x) __le16_to_cpu(x)
33#define DH2L(x) __cpu_to_le32(x)
34#define DL2H(x) __le32_to_cpu(x)
35
36#define H2B(x) __cpu_to_be16(x)
37#define B2H(x) __be16_to_cpu(x)
38#define DH2B(x) __cpu_to_be32(x)
39#define DB2H(x) __be32_to_cpu(x)
40
41struct phy_dev {
42 void *priv_dev;
43 struct net_device *netdev;
44
45 int (*send_func)(void *priv_dev, void *data, int len,
46 void (*cb)(void *cb_data), void *cb_data);
47 int (*rcv_func)(void *priv_dev,
48 void (*cb)(void *cb_data, void *data, int len),
49 void *cb_data);
50};
51
52struct nic {
53 struct net_device *netdev;
54 struct phy_dev *phy_dev;
55
56 struct net_device_stats stats;
57
58 struct data_s sdk_data[SIOC_DATA_MAX];
59
60#if defined(CONFIG_WIMAX_GDM72XX_QOS)
61 struct qos_cb_s qos;
62#endif
63
64};
65
66
67#if 0
68#define dprintk(fmt, args ...) printk(KERN_DEBUG " [GDM] " fmt, ## args)
69#else
70#define dprintk(...)
71#endif
72
73/*#define DEBUG_SDU */
74#if defined(DEBUG_SDU)
75#define DUMP_SDU_ALL (1<<0)
76#define DUMP_SDU_ARP (1<<1)
77#define DUMP_SDU_IP (1<<2)
78#define DUMP_SDU_IP_TCP (1<<8)
79#define DUMP_SDU_IP_UDP (1<<9)
80#define DUMP_SDU_IP_ICMP (1<<10)
81#define DUMP_PACKET (DUMP_SDU_ALL)
82#endif
83
84/*#define DEBUG_HCI */
85
86/*#define LOOPBACK_TEST */
87
88extern int register_wimax_device(struct phy_dev *phy_dev, struct device *pdev);
89extern int gdm_wimax_send_tx(struct sk_buff *skb, struct net_device *dev);
90extern void unregister_wimax_device(struct phy_dev *phy_dev);
91
92#endif
diff --git a/drivers/staging/gdm72xx/hci.h b/drivers/staging/gdm72xx/hci.h
new file mode 100644
index 000000000000..0e0676622f1d
--- /dev/null
+++ b/drivers/staging/gdm72xx/hci.h
@@ -0,0 +1,218 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef HCI_H_20080801
15#define HCI_H_20080801
16
17#define HCI_HEADER_SIZE 4
18#define HCI_VALUE_OFFS (HCI_HEADER_SIZE)
19#define HCI_MAX_PACKET 2048
20#define HCI_MAX_PARAM (HCI_MAX_PACKET-HCI_HEADER_SIZE)
21#define HCI_MAX_TLV 32
22
23/* CMD-EVT */
24
25/* Category 0 */
26#define WIMAX_RESET 0x0000
27#define WIMAX_SET_INFO 0x0001
28#define WIMAX_GET_INFO 0x0002
29#define WIMAX_GET_INFO_RESULT 0x8003
30#define WIMAX_RADIO_OFF 0x0004
31#define WIMAX_RADIO_ON 0x0006
32#define WIMAX_WIMAX_RESET 0x0007 /* Is this still here */
33
34/* Category 1 */
35#define WIMAX_NET_ENTRY 0x0100
36#define WIMAX_NET_DISCONN 0x0102
37#define WIMAX_ENTER_SLEEP 0x0103
38#define WIMAX_EXIT_SLEEP 0x0104
39#define WIMAX_ENTER_IDLE 0x0105
40#define WIMAX_EXIT_IDLE 0x0106
41#define WIMAX_MODE_CHANGE 0x8108
42#define WIMAX_HANDOVER 0x8109 /* obsolete */
43
44#define WIMAX_SCAN 0x010d
45#define WIMAX_SCAN_COMPLETE 0x810e
46#define WIMAX_SCAN_RESULT 0x810f
47
48#define WIMAX_CONNECT 0x0110
49#define WIMAX_CONNECT_START 0x8111
50#define WIMAX_CONNECT_COMPLETE 0x8112
51#define WIMAX_ASSOC_START 0x8113
52#define WIMAX_ASSOC_COMPLETE 0x8114
53#define WIMAX_DISCONN_IND 0x8115
54#define WIMAX_ENTRY_IND 0x8116
55#define WIMAX_HO_START 0x8117
56#define WIMAX_HO_COMPLETE 0x8118
57#define WIMAX_RADIO_STATE_IND 0x8119
58#define WIMAX_IP_RENEW_IND 0x811a
59
60#define WIMAX_DISCOVER_NSP 0x011d
61#define WIMAX_DISCOVER_NSP_RESULT 0x811e
62
63#define WIMAX_SDU_TX_FLOW 0x8125
64
65/* Category 2 */
66#define WIMAX_TX_EAP 0x0200
67#define WIMAX_RX_EAP 0x8201
68#define WIMAX_TX_SDU 0x0202
69#define WIMAX_RX_SDU 0x8203
70#define WIMAX_RX_SDU_AGGR 0x8204
71#define WIMAX_TX_SDU_AGGR 0x0205
72
73/* Category 3 */
74#define WIMAX_DM_CMD 0x030a
75#define WIMAX_DM_RSP 0x830b
76
77#define WIMAX_CLI_CMD 0x030c
78#define WIMAX_CLI_RSP 0x830d
79
80#define WIMAX_DL_IMAGE 0x0310
81#define WIMAX_DL_IMAGE_STATUS 0x8311
82#define WIMAX_UL_IMAGE 0x0312
83#define WIMAX_UL_IMAGE_RESULT 0x8313
84#define WIMAX_UL_IMAGE_STATUS 0x0314
85
86#define WIMAX_EVT_MODEM_REPORT 0x8325
87
88/* Category 0xF */
89#define WIMAX_FSM_UPDATE 0x8F01
90#define WIMAX_IF_UPDOWN 0x8F02
91 #define WIMAX_IF_UP 1
92 #define WIMAX_IF_DOWN 2
93
94/* WIMAX mode */
95#define W_NULL 0
96#define W_STANDBY 1
97#define W_OOZ 2
98#define W_AWAKE 3
99#define W_IDLE 4
100#define W_SLEEP 5
101#define W_WAIT 6
102
103#define W_NET_ENTRY_RNG 0x80
104#define W_NET_ENTRY_SBC 0x81
105#define W_NET_ENTRY_PKM 0x82
106#define W_NET_ENTRY_REG 0x83
107#define W_NET_ENTRY_DSX 0x84
108
109#define W_NET_ENTRY_RNG_FAIL 0x1100100
110#define W_NET_ENTRY_SBC_FAIL 0x1100200
111#define W_NET_ENTRY_PKM_FAIL 0x1102000
112#define W_NET_ENTRY_REG_FAIL 0x1103000
113#define W_NET_ENTRY_DSX_FAIL 0x1104000
114
115/* Scan Type */
116#define W_SCAN_ALL_CHANNEL 0
117#define W_SCAN_ALL_SUBSCRIPTION 1
118#define W_SCAN_SPECIFIED_SUBSCRIPTION 2
119
120/*
121 * TLV
122 *
123 * [31:31] indicates the type is composite.
124 * [30:16] is the length of the type. 0 length means length is variable.
125 * [15:0] is the actual type.
126 *
127 */
128#define TLV_L(x) (((x) >> 16) & 0xff)
129#define TLV_T(x) ((x) & 0xff)
130#define TLV_COMPOSITE(x) ((x) >> 31)
131
132/* GENERAL */
133#define T_MAC_ADDRESS (0x00 | (6 << 16))
134#define T_BSID (0x01 | (6 << 16))
135#define T_MSK (0x02 | (64 << 16))
136#define T_RSSI_THRSHLD (0x03 | (1 << 16))
137#define T_FREQUENCY (0x04 | (4 << 16))
138#define T_CONN_CS_TYPE (0x05 | (1 << 16))
139#define T_HOST_IP_VER (0x06 | (1 << 16))
140#define T_STBY_SCAN_INTERVAL (0x07 | (4 << 16))
141#define T_OOZ_SCAN_INTERVAL (0x08 | (4 << 16))
142#define T_IMEI (0x09 | (8 << 16))
143#define T_PID (0x0a | (12 << 16))
144
145#define T_CAPABILITY (0x1a | (4 << 16))
146#define T_RELEASE_NUMBER (0x1b | (4 << 16))
147#define T_DRIVER_REVISION (0x1c | (4 << 16))
148#define T_FW_REVISION (0x1d | (4 << 16))
149#define T_MAC_HW_REVISION (0x1e | (4 << 16))
150#define T_PHY_HW_REVISION (0x1f | (4 << 16))
151
152/* HANDOVER */
153#define T_SCAN_INTERVAL (0x20 | (1 << 16))
154
155#define T_RSC_RETAIN_TIME (0x2f | (2 << 16))
156
157/* SLEEP */
158#define T_TYPE1_ISW (0x40 | (1 << 16))
159
160#define T_SLP_START_TO (0x4a | (2 << 16))
161
162/* IDLE */
163#define T_IDLE_MODE_TO (0x50 | (2 << 16))
164
165#define T_IDLE_START_TO (0x54 | (2 << 16))
166
167/* MONITOR */
168#define T_RSSI (0x60 | (1 << 16))
169#define T_CINR (0x61 | (1 << 16))
170#define T_TX_POWER (0x6a | (1 << 16))
171#define T_CUR_FREQ (0x7f | (4 << 16))
172
173
174/* WIMAX */
175#define T_MAX_SUBSCRIPTION (0xa1 | (1 << 16))
176#define T_MAX_SF (0xa2 | (1 << 16))
177#define T_PHY_TYPE (0xa3 | (1 << 16))
178#define T_PKM (0xa4 | (1 << 16))
179#define T_AUTH_POLICY (0xa5 | (1 << 16))
180#define T_CS_TYPE (0xa6 | (2 << 16))
181#define T_VENDOR_NAME (0xa7 | (0 << 16))
182#define T_MOD_NAME (0xa8 | (0 << 16))
183#define T_PACKET_FILTER (0xa9 | (1 << 16))
184#define T_NSP_CHANGE_COUNT (0xaa | (4 << 16))
185#define T_RADIO_STATE (0xab | (1 << 16))
186#define T_URI_CONTACT_TYPE (0xac | (1 << 16))
187#define T_URI_TEXT (0xad | (0 << 16))
188#define T_URI (0xae | (0 << 16))
189#define T_ENABLE_AUTH (0xaf | (1 << 16))
190#define T_TIMEOUT (0xb0 | (2 << 16))
191#define T_RUN_MODE (0xb1 | (1 << 16))
192#define T_OMADMT_VER (0xb2 | (4 << 16))
193/* This is measured in seconds from 00:00:00 GMT January 1, 1970. */
194#define T_RTC_TIME (0xb3 | (4 << 16))
195#define T_CERT_STATUS (0xb4 | (4 << 16))
196#define T_CERT_MASK (0xb5 | (4 << 16))
197#define T_EMSK (0xb6 | (64 << 16))
198
199/* Subscription TLV */
200#define T_SUBSCRIPTION_LIST (0xd1 | (0 << 16) | (1 << 31))
201#define T_H_NSPID (0xd2 | (3 << 16))
202#define T_NSP_NAME (0xd3 | (0 << 16))
203#define T_SUBSCRIPTION_NAME (0xd4 | (0 << 16))
204#define T_SUBSCRIPTION_FLAG (0xd5 | (2 << 16))
205#define T_V_NSPID (0xd6 | (3 << 16))
206#define T_NAP_ID (0xd7 | (3 << 16))
207#define T_PREAMBLES (0xd8 | (15 << 16))
208#define T_BW (0xd9 | (4 << 16))
209#define T_FFTSIZE (0xda | (4 << 16))
210#define T_DUPLEX_MODE (0xdb | (4 << 16))
211
212struct hci_s {
213 unsigned short cmd_evt;
214 unsigned short length;
215 unsigned char data[0];
216} __packed;
217
218#endif
diff --git a/drivers/staging/gdm72xx/netlink_k.c b/drivers/staging/gdm72xx/netlink_k.c
new file mode 100644
index 000000000000..292af0f7f451
--- /dev/null
+++ b/drivers/staging/gdm72xx/netlink_k.c
@@ -0,0 +1,150 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/version.h>
15#include <linux/module.h>
16#include <linux/etherdevice.h>
17#include <linux/netlink.h>
18#include <asm/byteorder.h>
19#include <net/sock.h>
20
21#if !defined(NLMSG_HDRLEN)
22#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
23#endif
24
25#define ND_MAX_GROUP 30
26#define ND_IFINDEX_LEN sizeof(int)
27#define ND_NLMSG_SPACE(len) (NLMSG_SPACE(len) + ND_IFINDEX_LEN)
28#define ND_NLMSG_DATA(nlh) \
29 ((void *)((char *)NLMSG_DATA(nlh) + ND_IFINDEX_LEN))
30#define ND_NLMSG_S_LEN(len) (len+ND_IFINDEX_LEN)
31#define ND_NLMSG_R_LEN(nlh) (nlh->nlmsg_len-ND_IFINDEX_LEN)
32#define ND_NLMSG_IFIDX(nlh) NLMSG_DATA(nlh)
33#define ND_MAX_MSG_LEN 8096
34
35#if defined(DEFINE_MUTEX)
36static DEFINE_MUTEX(netlink_mutex);
37#else
38static struct semaphore netlink_mutex;
39#define mutex_lock(x) down(x)
40#define mutex_unlock(x) up(x)
41#endif
42
43static void (*rcv_cb)(struct net_device *dev, u16 type, void *msg, int len);
44
45static void netlink_rcv_cb(struct sk_buff *skb)
46{
47 struct nlmsghdr *nlh;
48 struct net_device *dev;
49 u32 mlen;
50 void *msg;
51 int ifindex;
52
53 if (skb->len >= NLMSG_SPACE(0)) {
54 nlh = (struct nlmsghdr *)skb->data;
55
56 if (skb->len < nlh->nlmsg_len ||
57 nlh->nlmsg_len > ND_MAX_MSG_LEN) {
58 printk(KERN_ERR "Invalid length (%d,%d)\n", skb->len,
59 nlh->nlmsg_len);
60 return;
61 }
62
63 memcpy(&ifindex, ND_NLMSG_IFIDX(nlh), ND_IFINDEX_LEN);
64 msg = ND_NLMSG_DATA(nlh);
65 mlen = ND_NLMSG_R_LEN(nlh);
66
67 if (rcv_cb) {
68 dev = dev_get_by_index(&init_net, ifindex);
69 if (dev) {
70 rcv_cb(dev, nlh->nlmsg_type, msg, mlen);
71 dev_put(dev);
72 } else
73 printk(KERN_ERR "dev_get_by_index(%d) "
74 "is not found.\n", ifindex);
75 } else
76 printk(KERN_ERR "Unregistered Callback\n");
77 }
78}
79
80static void netlink_rcv(struct sk_buff *skb)
81{
82 mutex_lock(&netlink_mutex);
83 netlink_rcv_cb(skb);
84 mutex_unlock(&netlink_mutex);
85}
86
87struct sock *netlink_init(int unit, void (*cb)(struct net_device *dev, u16 type,
88 void *msg, int len))
89{
90 struct sock *sock;
91
92#if !defined(DEFINE_MUTEX)
93 init_MUTEX(&netlink_mutex);
94#endif
95
96 sock = netlink_kernel_create(&init_net, unit, 0, netlink_rcv, NULL,
97 THIS_MODULE);
98
99 if (sock)
100 rcv_cb = cb;
101
102 return sock;
103}
104
105void netlink_exit(struct sock *sock)
106{
107 sock_release(sock->sk_socket);
108}
109
110int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
111{
112 static u32 seq;
113 struct sk_buff *skb = NULL;
114 struct nlmsghdr *nlh;
115 int ret = 0;
116
117 if (group > ND_MAX_GROUP) {
118 printk(KERN_ERR "Group %d is invalied.\n", group);
119 printk(KERN_ERR "Valid group is 0 ~ %d.\n", ND_MAX_GROUP);
120 return -EINVAL;
121 }
122
123 skb = alloc_skb(NLMSG_SPACE(len), GFP_ATOMIC);
124 if (!skb) {
125 printk(KERN_ERR "netlink_broadcast ret=%d\n", ret);
126 return -ENOMEM;
127 }
128
129 seq++;
130 nlh = NLMSG_PUT(skb, 0, seq, type, len);
131 memcpy(NLMSG_DATA(nlh), msg, len);
132
133 NETLINK_CB(skb).pid = 0;
134 NETLINK_CB(skb).dst_group = 0;
135
136 ret = netlink_broadcast(sock, skb, 0, group+1, GFP_ATOMIC);
137
138 if (!ret)
139 return len;
140 else {
141 if (ret != -ESRCH) {
142 printk(KERN_ERR "netlink_broadcast g=%d, t=%d, l=%d, r=%d\n",
143 group, type, len, ret);
144 }
145 ret = 0;
146 }
147
148nlmsg_failure:
149 return ret;
150}
diff --git a/drivers/staging/gdm72xx/netlink_k.h b/drivers/staging/gdm72xx/netlink_k.h
new file mode 100644
index 000000000000..1dffaa6156e4
--- /dev/null
+++ b/drivers/staging/gdm72xx/netlink_k.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#if !defined(NETLINK_H_20081202)
15#define NETLINK_H_20081202
16#include <linux/netdevice.h>
17#include <net/sock.h>
18
19struct sock *netlink_init(int unit,
20 void (*cb)(struct net_device *dev, u16 type, void *msg, int len));
21void netlink_exit(struct sock *sock);
22int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len);
23
24#endif
diff --git a/drivers/staging/gdm72xx/sdio_boot.c b/drivers/staging/gdm72xx/sdio_boot.c
new file mode 100644
index 000000000000..6ff4dc372522
--- /dev/null
+++ b/drivers/staging/gdm72xx/sdio_boot.c
@@ -0,0 +1,159 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/module.h>
15#include <linux/version.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/mm.h>
19#include <linux/uaccess.h>
20#include <linux/fs.h>
21#include <linux/sched.h>
22#include <linux/slab.h>
23
24#include <linux/mmc/core.h>
25#include <linux/mmc/card.h>
26#include <linux/mmc/sdio_func.h>
27
28#include "gdm_sdio.h"
29
30#define TYPE_A_HEADER_SIZE 4
31#define TYPE_A_LOOKAHEAD_SIZE 16
32#define YMEM0_SIZE 0x8000 /* 32kbytes */
33#define DOWNLOAD_SIZE (YMEM0_SIZE - TYPE_A_HEADER_SIZE)
34
35#define KRN_PATH "/lib/firmware/gdm72xx/gdmskrn.bin"
36#define RFS_PATH "/lib/firmware/gdm72xx/gdmsrfs.bin"
37
38static u8 *tx_buf;
39
40static int ack_ready(struct sdio_func *func)
41{
42 unsigned long start = jiffies;
43 u8 val;
44 int ret;
45
46 while ((jiffies - start) < HZ) {
47 val = sdio_readb(func, 0x13, &ret);
48 if (val & 0x01)
49 return 1;
50 schedule();
51 }
52
53 return 0;
54}
55
56static int download_image(struct sdio_func *func, char *img_name)
57{
58 int ret = 0, len, size, pno;
59 struct file *filp = NULL;
60 struct inode *inode = NULL;
61 u8 *buf = tx_buf;
62 loff_t pos = 0;
63
64 filp = filp_open(img_name, O_RDONLY | O_LARGEFILE, 0);
65 if (IS_ERR(filp)) {
66 printk(KERN_ERR "Can't find %s.\n", img_name);
67 return -ENOENT;
68 }
69
70 if (filp->f_dentry)
71 inode = filp->f_dentry->d_inode;
72 if (!inode || !S_ISREG(inode->i_mode)) {
73 printk(KERN_ERR "Invalid file type: %s\n", img_name);
74 ret = -EINVAL;
75 goto out;
76 }
77
78 size = i_size_read(inode->i_mapping->host);
79 if (size <= 0) {
80 printk(KERN_ERR "Unable to find file size: %s\n", img_name);
81 ret = size;
82 goto out;
83 }
84
85 pno = 0;
86 while ((len = filp->f_op->read(filp, buf + TYPE_A_HEADER_SIZE,
87 DOWNLOAD_SIZE, &pos))) {
88 if (len < 0) {
89 ret = -1;
90 goto out;
91 }
92
93 buf[0] = len & 0xff;
94 buf[1] = (len >> 8) & 0xff;
95 buf[2] = (len >> 16) & 0xff;
96
97 if (pos >= size) /* The last packet */
98 buf[3] = 2;
99 else
100 buf[3] = 0;
101
102 ret = sdio_memcpy_toio(func, 0, buf, len + TYPE_A_HEADER_SIZE);
103 if (ret < 0) {
104 printk(KERN_ERR "gdmwm: send image error: "
105 "packet number = %d ret = %d\n", pno, ret);
106 goto out;
107 }
108 if (buf[3] == 2) /* The last packet */
109 break;
110 if (!ack_ready(func)) {
111 ret = -EIO;
112 printk(KERN_ERR "gdmwm: Ack is not ready.\n");
113 goto out;
114 }
115 ret = sdio_memcpy_fromio(func, buf, 0, TYPE_A_LOOKAHEAD_SIZE);
116 if (ret < 0) {
117 printk(KERN_ERR "gdmwm: receive ack error: "
118 "packet number = %d ret = %d\n", pno, ret);
119 goto out;
120 }
121 sdio_writeb(func, 0x01, 0x13, &ret);
122 sdio_writeb(func, 0x00, 0x10, &ret); /* PCRRT */
123
124 pno++;
125 }
126out:
127 filp_close(filp, current->files);
128 return ret;
129}
130
131int sdio_boot(struct sdio_func *func)
132{
133 static mm_segment_t fs;
134 int ret;
135
136 tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL);
137 if (tx_buf == NULL) {
138 printk(KERN_ERR "Error: kmalloc: %s %d\n", __func__, __LINE__);
139 return -ENOMEM;
140 }
141
142 fs = get_fs();
143 set_fs(get_ds());
144
145 ret = download_image(func, KRN_PATH);
146 if (ret)
147 goto restore_fs;
148 printk(KERN_INFO "GCT: Kernel download success.\n");
149
150 ret = download_image(func, RFS_PATH);
151 if (ret)
152 goto restore_fs;
153 printk(KERN_INFO "GCT: Filesystem download success.\n");
154
155restore_fs:
156 set_fs(fs);
157 kfree(tx_buf);
158 return ret;
159}
diff --git a/drivers/staging/gdm72xx/sdio_boot.h b/drivers/staging/gdm72xx/sdio_boot.h
new file mode 100644
index 000000000000..373ac28063c6
--- /dev/null
+++ b/drivers/staging/gdm72xx/sdio_boot.h
@@ -0,0 +1,21 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __SDIO_BOOT_H__
15#define __SDIO_BOOT_H__
16
17struct sdio_func;
18
19extern int sdio_boot(struct sdio_func *func);
20
21#endif /* __SDIO_BOOT_H__ */
diff --git a/drivers/staging/gdm72xx/usb_boot.c b/drivers/staging/gdm72xx/usb_boot.c
new file mode 100644
index 000000000000..5a0e030220dc
--- /dev/null
+++ b/drivers/staging/gdm72xx/usb_boot.c
@@ -0,0 +1,404 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#include <linux/uaccess.h>
15#include <linux/module.h>
16#include <linux/version.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/usb.h>
20#include <linux/unistd.h>
21#include <linux/slab.h>
22
23#include <asm/byteorder.h>
24#include "gdm_usb.h"
25#include "usb_boot.h"
26
27#define DN_KERNEL_MAGIC_NUMBER 0x10760001
28#define DN_ROOTFS_MAGIC_NUMBER 0x10760002
29
30#define DOWNLOAD_SIZE 1024
31
32#define DH2B(x) __cpu_to_be32(x)
33#define DL2H(x) __le32_to_cpu(x)
34
35#define MIN(a, b) ((a) > (b) ? (b) : (a))
36
37#define MAX_IMG_CNT 16
38#define UIMG_PATH "/lib/firmware/gdm72xx/gdmuimg.bin"
39#define KERN_PATH "/lib/firmware/gdm72xx/zImage"
40#define FS_PATH "/lib/firmware/gdm72xx/ramdisk.jffs2"
41
42struct dn_header {
43 u32 magic_num;
44 u32 file_size;
45};
46
47struct img_header {
48 u32 magic_code;
49 u32 count;
50 u32 len;
51 u32 offset[MAX_IMG_CNT];
52 char hostname[32];
53 char date[32];
54};
55
56struct fw_info {
57 u32 id;
58 u32 len;
59 u32 kernel_len;
60 u32 rootfs_len;
61 u32 kernel_offset;
62 u32 rootfs_offset;
63 u32 fw_ver;
64 u32 mac_ver;
65 char hostname[32];
66 char userid[16];
67 char date[32];
68 char user_desc[128];
69};
70
71static void array_le32_to_cpu(u32 *arr, int num)
72{
73 int i;
74 for (i = 0; i < num; i++, arr++)
75 *arr = DL2H(*arr);
76}
77
78static u8 *tx_buf;
79
80static int gdm_wibro_send(struct usb_device *usbdev, void *data, int len)
81{
82 int ret;
83 int actual;
84
85 ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), data, len,
86 &actual, 1000);
87
88 if (ret < 0) {
89 printk(KERN_ERR "Error : usb_bulk_msg ( result = %d )\n", ret);
90 return ret;
91 }
92 return 0;
93}
94
95static int gdm_wibro_recv(struct usb_device *usbdev, void *data, int len)
96{
97 int ret;
98 int actual;
99
100 ret = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), data, len,
101 &actual, 5000);
102
103 if (ret < 0) {
104 printk(KERN_ERR "Error : usb_bulk_msg(recv) ( result = %d )\n",
105 ret);
106 return ret;
107 }
108 return 0;
109}
110
111static int download_image(struct usb_device *usbdev, struct file *filp,
112 loff_t *pos, u32 img_len, u32 magic_num)
113{
114 struct dn_header h;
115 int ret = 0;
116 u32 size;
117 int len, readn;
118
119 size = (img_len + DOWNLOAD_SIZE - 1) & ~(DOWNLOAD_SIZE - 1);
120 h.magic_num = DH2B(magic_num);
121 h.file_size = DH2B(size);
122
123 ret = gdm_wibro_send(usbdev, &h, sizeof(h));
124 if (ret < 0)
125 goto out;
126
127 readn = 0;
128 while ((len = filp->f_op->read(filp, tx_buf, DOWNLOAD_SIZE, pos))) {
129
130 if (len < 0) {
131 ret = -1;
132 goto out;
133 }
134 readn += len;
135
136 ret = gdm_wibro_send(usbdev, tx_buf, DOWNLOAD_SIZE);
137 if (ret < 0)
138 goto out;
139 if (readn >= img_len)
140 break;
141 }
142
143 if (readn < img_len) {
144 printk(KERN_ERR "gdmwm: Cannot read to the requested size. "
145 "Read = %d Requested = %d\n", readn, img_len);
146 ret = -EIO;
147 }
148out:
149
150 return ret;
151}
152
153int usb_boot(struct usb_device *usbdev, u16 pid)
154{
155 int i, ret = 0;
156 struct file *filp = NULL;
157 struct inode *inode = NULL;
158 static mm_segment_t fs;
159 struct img_header hdr;
160 struct fw_info fw_info;
161 loff_t pos = 0;
162 char *img_name = UIMG_PATH;
163 int len;
164
165 tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL);
166 if (tx_buf == NULL) {
167 printk(KERN_ERR "Error: kmalloc\n");
168 return -ENOMEM;
169 }
170
171 fs = get_fs();
172 set_fs(get_ds());
173
174 filp = filp_open(img_name, O_RDONLY | O_LARGEFILE, 0);
175 if (IS_ERR(filp)) {
176 printk(KERN_ERR "Can't find %s.\n", img_name);
177 set_fs(fs);
178 ret = -ENOENT;
179 goto restore_fs;
180 }
181
182 if (filp->f_dentry)
183 inode = filp->f_dentry->d_inode;
184 if (!inode || !S_ISREG(inode->i_mode)) {
185 printk(KERN_ERR "Invalid file type: %s\n", img_name);
186 ret = -EINVAL;
187 goto out;
188 }
189
190 len = filp->f_op->read(filp, (u8 *)&hdr, sizeof(hdr), &pos);
191 if (len != sizeof(hdr)) {
192 printk(KERN_ERR "gdmwm: Cannot read the image info.\n");
193 ret = -EIO;
194 goto out;
195 }
196
197 array_le32_to_cpu((u32 *)&hdr, 19);
198#if 0
199 if (hdr.magic_code != 0x10767fff) {
200 printk(KERN_ERR "gdmwm: Invalid magic code 0x%08x\n",
201 hdr.magic_code);
202 ret = -EINVAL;
203 goto out;
204 }
205#endif
206 if (hdr.count > MAX_IMG_CNT) {
207 printk(KERN_ERR "gdmwm: Too many images. %d\n", hdr.count);
208 ret = -EINVAL;
209 goto out;
210 }
211
212 for (i = 0; i < hdr.count; i++) {
213 if (hdr.offset[i] > hdr.len) {
214 printk(KERN_ERR "gdmwm: Invalid offset. "
215 "Entry = %d Offset = 0x%08x "
216 "Image length = 0x%08x\n",
217 i, hdr.offset[i], hdr.len);
218 ret = -EINVAL;
219 goto out;
220 }
221
222 pos = hdr.offset[i];
223 len = filp->f_op->read(filp, (u8 *)&fw_info, sizeof(fw_info),
224 &pos);
225 if (len != sizeof(fw_info)) {
226 printk(KERN_ERR "gdmwm: Cannot read the FW info.\n");
227 ret = -EIO;
228 goto out;
229 }
230
231 array_le32_to_cpu((u32 *)&fw_info, 8);
232#if 0
233 if ((fw_info.id & 0xfffff000) != 0x10767000) {
234 printk(KERN_ERR "gdmwm: Invalid FW id. 0x%08x\n",
235 fw_info.id);
236 ret = -EIO;
237 goto out;
238 }
239#endif
240
241 if ((fw_info.id & 0xffff) != pid)
242 continue;
243
244 pos = hdr.offset[i] + fw_info.kernel_offset;
245 ret = download_image(usbdev, filp, &pos, fw_info.kernel_len,
246 DN_KERNEL_MAGIC_NUMBER);
247 if (ret < 0)
248 goto out;
249 printk(KERN_INFO "GCT: Kernel download success.\n");
250
251 pos = hdr.offset[i] + fw_info.rootfs_offset;
252 ret = download_image(usbdev, filp, &pos, fw_info.rootfs_len,
253 DN_ROOTFS_MAGIC_NUMBER);
254 if (ret < 0)
255 goto out;
256 printk(KERN_INFO "GCT: Filesystem download success.\n");
257
258 break;
259 }
260
261 if (i == hdr.count) {
262 printk(KERN_ERR "Firmware for gsk%x is not installed.\n", pid);
263 ret = -EINVAL;
264 }
265out:
266 filp_close(filp, current->files);
267
268restore_fs:
269 set_fs(fs);
270 kfree(tx_buf);
271 return ret;
272}
273
274/*#define GDM7205_PADDING 256 */
275#define DOWNLOAD_CHUCK 2048
276#define KERNEL_TYPE_STRING "linux"
277#define FS_TYPE_STRING "rootfs"
278
279static int em_wait_ack(struct usb_device *usbdev, int send_zlp)
280{
281 int ack;
282 int ret = -1;
283
284 if (send_zlp) {
285 /*Send ZLP*/
286 ret = gdm_wibro_send(usbdev, NULL, 0);
287 if (ret < 0)
288 goto out;
289 }
290
291 /*Wait for ACK*/
292 ret = gdm_wibro_recv(usbdev, &ack, sizeof(ack));
293 if (ret < 0)
294 goto out;
295out:
296 return ret;
297}
298
299static int em_download_image(struct usb_device *usbdev, char *path,
300 char *type_string)
301{
302 struct file *filp;
303 struct inode *inode;
304 static mm_segment_t fs;
305 char *buf = NULL;
306 loff_t pos = 0;
307 int ret = 0;
308 int len, readn = 0;
309 #if defined(GDM7205_PADDING)
310 const int pad_size = GDM7205_PADDING;
311 #else
312 const int pad_size = 0;
313 #endif
314
315 fs = get_fs();
316 set_fs(get_ds());
317
318 filp = filp_open(path, O_RDONLY | O_LARGEFILE, 0);
319 if (IS_ERR(filp)) {
320 printk(KERN_ERR "Can't find %s.\n", path);
321 set_fs(fs);
322 ret = -ENOENT;
323 goto restore_fs;
324 }
325
326 if (filp->f_dentry) {
327 inode = filp->f_dentry->d_inode;
328 if (!inode || !S_ISREG(inode->i_mode)) {
329 printk(KERN_ERR "Invalid file type: %s\n", path);
330 ret = -EINVAL;
331 goto out;
332 }
333 }
334
335 buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL);
336 if (buf == NULL) {
337 printk(KERN_ERR "Error: kmalloc\n");
338 return -ENOMEM;
339 }
340
341 strcpy(buf+pad_size, type_string);
342 ret = gdm_wibro_send(usbdev, buf, strlen(type_string)+pad_size);
343 if (ret < 0)
344 goto out;
345
346 while ((len = filp->f_op->read(filp, buf+pad_size, DOWNLOAD_CHUCK,
347 &pos))) {
348 if (len < 0) {
349 ret = -1;
350 goto out;
351 }
352 readn += len;
353
354 ret = gdm_wibro_send(usbdev, buf, len+pad_size);
355 if (ret < 0)
356 goto out;
357
358 ret = em_wait_ack(usbdev, ((len+pad_size) % 512 == 0));
359 if (ret < 0)
360 goto out;
361 }
362
363 ret = em_wait_ack(usbdev, 1);
364 if (ret < 0)
365 goto out;
366
367out:
368 filp_close(filp, current->files);
369
370restore_fs:
371 set_fs(fs);
372
373 kfree(buf);
374
375 return ret;
376}
377
378static int em_fw_reset(struct usb_device *usbdev)
379{
380 int ret;
381
382 /*Send ZLP*/
383 ret = gdm_wibro_send(usbdev, NULL, 0);
384 return ret;
385}
386
387int usb_emergency(struct usb_device *usbdev)
388{
389 int ret;
390
391 ret = em_download_image(usbdev, KERN_PATH, KERNEL_TYPE_STRING);
392 if (ret < 0)
393 goto out;
394 printk(KERN_INFO "GCT Emergency: Kernel download success.\n");
395
396 ret = em_download_image(usbdev, FS_PATH, FS_TYPE_STRING);
397 if (ret < 0)
398 goto out;
399 printk(KERN_INFO "GCT Emergency: Filesystem download success.\n");
400
401 ret = em_fw_reset(usbdev);
402out:
403 return ret;
404}
diff --git a/drivers/staging/gdm72xx/usb_boot.h b/drivers/staging/gdm72xx/usb_boot.h
new file mode 100644
index 000000000000..c715cd3cd300
--- /dev/null
+++ b/drivers/staging/gdm72xx/usb_boot.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __USB_BOOT_H__
15#define __USB_BOOT_H__
16
17struct usb_device;
18
19extern int usb_boot(struct usb_device *usbdev, u16 pid);
20extern int usb_emergency(struct usb_device *usbdev);
21
22#endif /* __USB_BOOT_H__ */
diff --git a/drivers/staging/gdm72xx/usb_ids.h b/drivers/staging/gdm72xx/usb_ids.h
new file mode 100644
index 000000000000..b34616b7203f
--- /dev/null
+++ b/drivers/staging/gdm72xx/usb_ids.h
@@ -0,0 +1,82 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#ifndef __USB_IDS_H__
15#define __USB_IDS_H__
16
17/*You can replace vendor-ID as yours.*/
18#define GCT_VID 0x1076
19
20/*You can replace product-ID as yours.*/
21#define GCT_PID1 0x7e00
22#define GCT_PID2 0x7f00
23
24#define USB_DEVICE_ID_MATCH_DEVICE_INTERFACE \
25 (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_CLASS)
26
27#define USB_DEVICE_INTF(vend, prod, intf) \
28 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_INTERFACE, \
29 .idVendor = (vend), .idProduct = (prod), .bInterfaceClass = (intf)
30
31#define EMERGENCY_PID 0x720f
32#define BL_PID_MASK 0xffc0
33
34#define USB_DEVICE_BOOTLOADER(vid, pid) \
35 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD)}, \
36 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD|B_DIFF_DL_DRV)}
37
38#define USB_DEVICE_CDC_DATA(vid, pid) \
39 {USB_DEVICE_INTF((vid), (pid), USB_CLASS_CDC_DATA)}
40
41static const struct usb_device_id id_table[] = {
42 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID1),
43 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1),
44 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x1),
45 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x2),
46 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x3),
47 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x4),
48 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x5),
49 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x6),
50 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x7),
51 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x8),
52 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x9),
53 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xa),
54 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xb),
55 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xc),
56 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xd),
57 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xe),
58 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xf),
59
60 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID2),
61 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2),
62 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x1),
63 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x2),
64 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x3),
65 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x4),
66 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x5),
67 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x6),
68 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x7),
69 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x8),
70 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x9),
71 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xa),
72 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xb),
73 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xc),
74 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xd),
75 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xe),
76 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0xf),
77
78 {USB_DEVICE(GCT_VID, EMERGENCY_PID)},
79 { }
80};
81
82#endif /* __USB_IDS_H__ */
diff --git a/drivers/staging/gdm72xx/wm_ioctl.h b/drivers/staging/gdm72xx/wm_ioctl.h
new file mode 100644
index 000000000000..9f46e06f2303
--- /dev/null
+++ b/drivers/staging/gdm72xx/wm_ioctl.h
@@ -0,0 +1,97 @@
1/*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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 */
13
14#if !defined(WM_IOCTL_H_20080714)
15#define WM_IOCTL_H_20080714
16#if !defined(__KERNEL__)
17#include <net/if.h>
18#endif
19
20#define NETLINK_WIMAX 31
21
22#define SIOCWMIOCTL SIOCDEVPRIVATE
23
24#define SIOCG_DATA 0x8D10
25#define SIOCS_DATA 0x8D11
26
27enum {
28 SIOC_DATA_FSM,
29 SIOC_DATA_NETLIST,
30 SIOC_DATA_CONNNSP,
31 SIOC_DATA_CONNCOMP,
32 SIOC_DATA_PROFILEID,
33
34 SIOC_DATA_END
35};
36
37#define SIOC_DATA_MAX 16
38
39/* FSM */
40enum {
41 M_INIT = 0,
42 M_OPEN_OFF,
43 M_OPEN_ON,
44 M_SCAN,
45 M_CONNECTING,
46 M_CONNECTED,
47 M_FSM_END,
48
49 C_INIT = 0,
50 C_CONNSTART,
51 C_ASSOCSTART,
52 C_RNG,
53 C_SBC,
54 C_AUTH,
55 C_REG,
56 C_DSX,
57 C_ASSOCCOMPLETE,
58 C_CONNCOMPLETE,
59 C_FSM_END,
60
61 D_INIT = 0,
62 D_READY,
63 D_LISTEN,
64 D_IPACQUISITION,
65
66 END_FSM
67};
68
69struct fsm_s {
70 int m_status; /*main status*/
71 int c_status; /*connection status*/
72 int d_status; /*oma-dm status*/
73};
74
75struct data_s {
76 int size;
77 void *buf;
78};
79
80struct wm_req_s {
81 union {
82 char ifrn_name[IFNAMSIZ];
83 } ifr_ifrn;
84
85 unsigned short cmd;
86
87 unsigned short data_id;
88 struct data_s data;
89
90/* NOTE: sizeof(struct wm_req_s) must be less than sizeof(struct ifreq). */
91};
92
93#ifndef ifr_name
94#define ifr_name ifr_ifrn.ifrn_name
95#endif
96
97#endif
diff --git a/drivers/staging/iio/Documentation/device.txt b/drivers/staging/iio/Documentation/device.txt
index 8926f2448cc9..0338c7cd0a8b 100644
--- a/drivers/staging/iio/Documentation/device.txt
+++ b/drivers/staging/iio/Documentation/device.txt
@@ -8,7 +8,7 @@ The crucial structure for device drivers in iio is iio_dev.
8 8
9First allocate one using: 9First allocate one using:
10 10
11struct iio_dev *indio_dev = iio_allocate_device(sizeof(struct chip_state)); 11struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
12where chip_state is a structure of local state data for this instance of 12where chip_state is a structure of local state data for this instance of
13the chip. 13the chip.
14 14
@@ -78,4 +78,4 @@ be registered afterwards (otherwise the whole parentage of devices
78gets confused) 78gets confused)
79 79
80On remove, iio_device_unregister(indio_dev) will remove the device from 80On remove, iio_device_unregister(indio_dev) will remove the device from
81the core, and iio_free_device will clean up. 81the core, and iio_device_free will clean up.
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c
index 69a05b9456d6..bf553356fdad 100644
--- a/drivers/staging/iio/Documentation/generic_buffer.c
+++ b/drivers/staging/iio/Documentation/generic_buffer.c
@@ -60,9 +60,9 @@ void print2byte(int input, struct iio_channel_info *info)
60 /* First swap if incorrect endian */ 60 /* First swap if incorrect endian */
61 61
62 if (info->be) 62 if (info->be)
63 input = be16toh((uint_16t)input); 63 input = be16toh((uint16_t)input);
64 else 64 else
65 input = le16toh((uint_16t)input); 65 input = le16toh((uint16_t)input);
66 66
67 /* shift before conversion to avoid sign extension 67 /* shift before conversion to avoid sign extension
68 of left aligned data */ 68 of left aligned data */
diff --git a/drivers/staging/iio/Documentation/iio_event_monitor.c b/drivers/staging/iio/Documentation/iio_event_monitor.c
index 0d21a277305f..22275845fb12 100644
--- a/drivers/staging/iio/Documentation/iio_event_monitor.c
+++ b/drivers/staging/iio/Documentation/iio_event_monitor.c
@@ -27,7 +27,7 @@
27#include <fcntl.h> 27#include <fcntl.h>
28#include <sys/ioctl.h> 28#include <sys/ioctl.h>
29#include "iio_utils.h" 29#include "iio_utils.h"
30#include "../events.h" 30#include <linux/iio/events.h>
31 31
32static const char * const iio_chan_type_name_spec[] = { 32static const char * const iio_chan_type_name_spec[] = {
33 [IIO_VOLTAGE] = "voltage", 33 [IIO_VOLTAGE] = "voltage",
diff --git a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
new file mode 100755
index 000000000000..470f7ad9c073
--- /dev/null
+++ b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
@@ -0,0 +1,6 @@
1What: /sys/bus/iio/devices/device[n]/in_illuminance0_calibrate
2KernelVersion: 2.6.37
3Contact: linux-iio@vger.kernel.org
4Description:
5 This property causes an internal calibration of the als gain trim
6 value which is later used in calculating illuminance in lux.
diff --git a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x
new file mode 100755
index 000000000000..b2798b258bf7
--- /dev/null
+++ b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x
@@ -0,0 +1,13 @@
1What: /sys/bus/iio/devices/device[n]/in_illuminance0_calibrate
2KernelVersion: 3.3-rc1
3Contact: linux-iio@vger.kernel.org
4Description:
5 Causes an internal calibration of the als gain trim
6 value which is later used in calculating illuminance in lux.
7
8What: /sys/bus/iio/devices/device[n]/in_proximity0_calibrate
9KernelVersion: 3.3-rc1
10Contact: linux-iio@vger.kernel.org
11Description:
12 Causes a recalculation and adjustment to the
13 proximity_thresh_rising_value.
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192 b/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192
new file mode 100644
index 000000000000..1c35c507cc05
--- /dev/null
+++ b/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192
@@ -0,0 +1,20 @@
1What: /sys/.../iio:deviceX/ac_excitation_en
2KernelVersion: 3.1.0
3Contact: linux-iio@vger.kernel.org
4Description:
5 This attribute, if available, is used to enable the AC
6 excitation mode found on some converters. In ac excitation mode,
7 the polarity of the excitation voltage is reversed on
8 alternate cycles, to eliminate DC errors.
9
10What: /sys/.../iio:deviceX/bridge_switch_en
11KernelVersion: 3.1.0
12Contact: linux-iio@vger.kernel.org
13Description:
14 This attribute, if available, is used to close or open the
15 bridge power down switch found on some converters.
16 In bridge applications, such as strain gauges and load cells,
17 the bridge itself consumes the majority of the current in the
18 system. To minimize the current consumption of the system,
19 the bridge can be disconnected (when it is not being used
20 using the bridge_switch_en attribute.
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-dds b/drivers/staging/iio/Documentation/sysfs-bus-iio-dds
index ffdd5478a35d..ee8c509c6733 100644
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio-dds
+++ b/drivers/staging/iio/Documentation/sysfs-bus-iio-dds
@@ -1,83 +1,86 @@
1 1
2What: /sys/bus/iio/devices/.../ddsX_freqY 2What: /sys/bus/iio/devices/.../out_altvoltageX_frequencyY
3KernelVersion: 2.6.37 3KernelVersion: 2.6.37
4Contact: linux-iio@vger.kernel.org 4Contact: linux-iio@vger.kernel.org
5Description: 5Description:
6 Stores frequency into tuning word Y. 6 Stores frequency into tuning word Y.
7 There will be more than one ddsX_freqY file, which allows for 7 There will be more than one out_altvoltageX_frequencyY file,
8 pin controlled FSK Frequency Shift Keying 8 which allows for pin controlled FSK Frequency Shift Keying
9 (ddsX_pincontrol_freq_en is active) or the user can control 9 (out_altvoltageX_pincontrol_frequency_en is active) or the user
10 the desired active tuning word by writing Y to the 10 can control the desired active tuning word by writing Y to the
11 ddsX_freqsymbol file. 11 out_altvoltageX_frequencysymbol file.
12 12
13What: /sys/bus/iio/devices/.../ddsX_freqY_scale 13What: /sys/bus/iio/devices/.../out_altvoltageX_frequencyY_scale
14KernelVersion: 2.6.37 14KernelVersion: 2.6.37
15Contact: linux-iio@vger.kernel.org 15Contact: linux-iio@vger.kernel.org
16Description: 16Description:
17 Scale to be applied to ddsX_freqY in order to obtain the 17 Scale to be applied to out_altvoltageX_frequencyY in order to
18 desired value in Hz. If shared across all frequency registers 18 obtain the desired value in Hz. If shared across all frequency
19 Y is not present. It is also possible X is not present if 19 registers Y is not present. It is also possible X is not present
20 shared across all channels. 20 if shared across all channels.
21 21
22What: /sys/bus/iio/devices/.../ddsX_freqsymbol 22What: /sys/bus/iio/devices/.../out_altvoltageX_frequencysymbol
23KernelVersion: 2.6.37 23KernelVersion: 2.6.37
24Contact: linux-iio@vger.kernel.org 24Contact: linux-iio@vger.kernel.org
25Description: 25Description:
26 Specifies the active output frequency tuning word. The value 26 Specifies the active output frequency tuning word. The value
27 corresponds to the Y in ddsX_freqY. To exit this mode the user 27 corresponds to the Y in out_altvoltageX_frequencyY.
28 can write ddsX_pincontrol_freq_en or ddsX_out_enable file. 28 To exit this mode the user can write
29 out_altvoltageX_pincontrol_frequency_en or
30 out_altvoltageX_out_enable file.
29 31
30What: /sys/bus/iio/devices/.../ddsX_phaseY 32What: /sys/bus/iio/devices/.../out_altvoltageX_phaseY
31KernelVersion: 2.6.37 33KernelVersion: 2.6.37
32Contact: linux-iio@vger.kernel.org 34Contact: linux-iio@vger.kernel.org
33Description: 35Description:
34 Stores phase into Y. 36 Stores phase into Y.
35 There will be more than one ddsX_phaseY file, which allows for 37 There will be more than one out_altvoltageX_phaseY file, which
36 pin controlled PSK Phase Shift Keying 38 allows for pin controlled PSK Phase Shift Keying
37 (ddsX_pincontrol_phase_en is active) or the user can 39 (out_altvoltageX_pincontrol_phase_en is active) or the user can
38 control the desired phase Y which is added to the phase 40 control the desired phase Y which is added to the phase
39 accumulator output by writing Y to the en_phase file. 41 accumulator output by writing Y to the phase_en file.
40 42
41What: /sys/bus/iio/devices/.../ddsX_phaseY_scale 43What: /sys/bus/iio/devices/.../out_altvoltageX_phaseY_scale
42KernelVersion: 2.6.37 44KernelVersion: 2.6.37
43Contact: linux-iio@vger.kernel.org 45Contact: linux-iio@vger.kernel.org
44Description: 46Description:
45 Scale to be applied to ddsX_phaseY in order to obtain the 47 Scale to be applied to out_altvoltageX_phaseY in order to obtain
46 desired value in rad. If shared across all phase registers 48 the desired value in rad. If shared across all phase registers
47 Y is not present. It is also possible X is not present if 49 Y is not present. It is also possible X is not present if
48 shared across all channels. 50 shared across all channels.
49 51
50What: /sys/bus/iio/devices/.../ddsX_phasesymbol 52What: /sys/bus/iio/devices/.../out_altvoltageX_phasesymbol
51KernelVersion: 2.6.37 53KernelVersion: 2.6.37
52Contact: linux-iio@vger.kernel.org 54Contact: linux-iio@vger.kernel.org
53Description: 55Description:
54 Specifies the active phase Y which is added to the phase 56 Specifies the active phase Y which is added to the phase
55 accumulator output. The value corresponds to the Y in 57 accumulator output. The value corresponds to the Y in
56 ddsX_phaseY. To exit this mode the user can write 58 out_altvoltageX_phaseY. To exit this mode the user can write
57 ddsX_pincontrol_phase_en or disable file. 59 out_altvoltageX_pincontrol_phase_en or disable file.
58 60
59What: /sys/bus/iio/devices/.../ddsX_pincontrol_en 61What: /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_en
60What: /sys/bus/iio/devices/.../ddsX_pincontrol_freq_en 62What: /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_frequency_en
61What: /sys/bus/iio/devices/.../ddsX_pincontrol_phase_en 63What: /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_phase_en
62KernelVersion: 2.6.37 64KernelVersion: 2.6.37
63Contact: linux-iio@vger.kernel.org 65Contact: linux-iio@vger.kernel.org
64Description: 66Description:
65 ddsX_pincontrol_en: Both, the active frequency and phase is 67 out_altvoltageX_pincontrol_en: Both, the active frequency and
66 controlled by the respective phase and frequency control inputs. 68 phase is controlled by the respective phase and frequency
67 In case the device in question allows to independent controls, 69 control inputs. In case the device in features independent
68 then there are dedicated files (ddsX_pincontrol_freq_en, 70 controls, then there are dedicated files
69 ddsX_pincontrol_phase_en). 71 (out_altvoltageX_pincontrol_frequency_en,
72 out_altvoltageX_pincontrol_phase_en).
70 73
71What: /sys/bus/iio/devices/.../ddsX_out_enable 74What: /sys/bus/iio/devices/.../out_altvoltageX_out_enable
72What: /sys/bus/iio/devices/.../ddsX_outY_enable 75What: /sys/bus/iio/devices/.../out_altvoltageX_outY_enable
73KernelVersion: 2.6.37 76KernelVersion: 2.6.37
74Contact: linux-iio@vger.kernel.org 77Contact: linux-iio@vger.kernel.org
75Description: 78Description:
76 ddsX_outY_enable controls signal generation on output Y of 79 out_altvoltageX_outY_enable controls signal generation on
77 channel X. Y may be suppressed if all channels are 80 output Y of channel X. Y may be suppressed if all channels are
78 controlled together. 81 controlled together.
79 82
80What: /sys/bus/iio/devices/.../ddsX_outY_wavetype 83What: /sys/bus/iio/devices/.../out_altvoltageX_outY_wavetype
81KernelVersion: 2.6.37 84KernelVersion: 2.6.37
82Contact: linux-iio@vger.kernel.org 85Contact: linux-iio@vger.kernel.org
83Description: 86Description:
@@ -86,7 +89,7 @@ Description:
86 For a list of available output waveform options read 89 For a list of available output waveform options read
87 available_output_modes. 90 available_output_modes.
88 91
89What: /sys/bus/iio/devices/.../ddsX_outY_wavetype_available 92What: /sys/bus/iio/devices/.../out_altvoltageX_outY_wavetype_available
90KernelVersion: 2.6.37 93KernelVersion: 2.6.37
91Contact: linux-iio@vger.kernel.org 94Contact: linux-iio@vger.kernel.org
92Description: 95Description:
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-light b/drivers/staging/iio/Documentation/sysfs-bus-iio-light
index edbf470e4e30..715c74dcb53a 100644
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio-light
+++ b/drivers/staging/iio/Documentation/sysfs-bus-iio-light
@@ -26,7 +26,7 @@ Description:
26 Hardware dependent list of possible values supported for the 26 Hardware dependent list of possible values supported for the
27 adc_resolution of the given sensor. 27 adc_resolution of the given sensor.
28 28
29What: /sys/bus/iio/devices/device[n]/illuminance0[_input|_raw] 29What: /sys/bus/iio/devices/device[n]/in_illuminance0[_input|_raw]
30KernelVersion: 2.6.35 30KernelVersion: 2.6.35
31Contact: linux-iio@vger.kernel.org 31Contact: linux-iio@vger.kernel.org
32Description: 32Description:
@@ -45,7 +45,7 @@ Description:
45 do this calculation manually by reading the infrared sensor 45 do this calculation manually by reading the infrared sensor
46 value and doing the negation in sw. 46 value and doing the negation in sw.
47 47
48What: /sys/bus/iio/devices/device[n]/proximity[_input|_raw] 48What: /sys/bus/iio/devices/device[n]/in_proximity[_input|_raw]
49KernelVersion: 2.6.37 49KernelVersion: 2.6.37
50Contact: linux-iio@vger.kernel.org 50Contact: linux-iio@vger.kernel.org
51Description: 51Description:
@@ -63,23 +63,22 @@ Description:
63 and if expressed in SI units, should include _input. If this 63 and if expressed in SI units, should include _input. If this
64 value is not in SI units, then it should include _raw. 64 value is not in SI units, then it should include _raw.
65 65
66What: /sys/bus/iio/devices/device[n]/illuminance0_target 66What: /sys/bus/iio/devices/device[n]/in_illuminance0_target
67KernelVersion: 2.6.37 67KernelVersion: 2.6.37
68Contact: linux-iio@vger.kernel.org 68Contact: linux-iio@vger.kernel.org
69Description: 69Description:
70 This property gets/sets the last known external 70 This property gets/sets the last known external
71 lux measurement used in/for calibration. 71 lux measurement used in/for calibration.
72 72
73What: /sys/bus/iio/devices/device[n]/illuminance0_integration_time 73What: /sys/bus/iio/devices/device[n]/in_illuminance0_integration_time
74KernelVersion: 2.6.37 74KernelVersion: 2.6.37
75Contact: linux-iio@vger.kernel.org 75Contact: linux-iio@vger.kernel.org
76Description: 76Description:
77 This property gets/sets the sensors ADC analog integration time. 77 This property gets/sets the sensors ADC analog integration time.
78 78
79What: /sys/bus/iio/devices/device[n]/illuminance0_calibscale 79What: /sys/bus/iio/devices/device[n]/in_illuminance0_lux_table
80KernelVersion: 2.6.37 80KernelVersion: 2.6.37
81Contact: linux-iio@vger.kernel.org 81Contact: linux-iio@vger.kernel.org
82Description: 82Description:
83 Hardware or software applied calibration scale factor assumed 83 This property gets/sets the table of coefficients
84 to account for attenuation due to industrial design (glass 84 used in calculating illuminance in lux.
85 filters or aperture holes).
diff --git a/drivers/staging/iio/Documentation/trigger.txt b/drivers/staging/iio/Documentation/trigger.txt
index fc2012ebc100..75cc37ff1ed0 100644
--- a/drivers/staging/iio/Documentation/trigger.txt
+++ b/drivers/staging/iio/Documentation/trigger.txt
@@ -5,7 +5,7 @@ an IIO device. Whilst this can create device specific complexities
5such triggers are registered with the core in the same way as 5such triggers are registered with the core in the same way as
6stand-alone triggers. 6stand-alone triggers.
7 7
8struct iio_trig *trig = iio_allocate_trigger("<trigger format string>", ...); 8struct iio_trig *trig = iio_trigger_alloc("<trigger format string>", ...);
9 9
10allocates a trigger structure. The key elements to then fill in within 10allocates a trigger structure. The key elements to then fill in within
11a driver are: 11a driver are:
diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig
index fe1586718880..3c8e5ec26ac1 100644
--- a/drivers/staging/iio/Kconfig
+++ b/drivers/staging/iio/Kconfig
@@ -1,16 +1,9 @@
1# 1#
2# Industrial I/O subsytem configuration 2# Industrial I/O subsytem configuration
3# 3#
4menu "IIO staging drivers"
5 depends on IIO
4 6
5menuconfig IIO
6 tristate "Industrial I/O support"
7 depends on GENERIC_HARDIRQS
8 help
9 The industrial I/O subsystem provides a unified framework for
10 drivers for many different types of embedded sensors using a
11 number of different physical interfaces (i2c, spi, etc). See
12 drivers/staging/iio/Documentation for more information.
13if IIO
14config IIO_ST_HWMON 7config IIO_ST_HWMON
15 tristate "Hwmon driver that uses channels specified via iio maps" 8 tristate "Hwmon driver that uses channels specified via iio maps"
16 depends on HWMON 9 depends on HWMON
@@ -19,12 +12,6 @@ config IIO_ST_HWMON
19 map allows IIO devices to provide basic hwmon functionality 12 map allows IIO devices to provide basic hwmon functionality
20 for those channels specified in the map. 13 for those channels specified in the map.
21 14
22config IIO_BUFFER
23 bool "Enable buffer support within IIO"
24 help
25 Provide core support for various buffer based data
26 acquisition methods.
27
28if IIO_BUFFER 15if IIO_BUFFER
29 16
30config IIO_SW_RING 17config IIO_SW_RING
@@ -36,39 +23,14 @@ config IIO_SW_RING
36 with the intention that some devices would be able to write 23 with the intention that some devices would be able to write
37 in interrupt context. 24 in interrupt context.
38 25
39config IIO_KFIFO_BUF
40 select IIO_TRIGGER
41 tristate "Industrial I/O buffering based on kfifo"
42 help
43 A simple fifo based on kfifo. Use this if you want a fifo
44 rather than a ring buffer. Note that this currently provides
45 no buffer events so it is up to userspace to work out how
46 often to read from the buffer.
47
48endif # IIO_BUFFER 26endif # IIO_BUFFER
49 27
50config IIO_TRIGGER
51 boolean "Enable triggered sampling support"
52 help
53 Provides IIO core support for triggers. Currently these
54 are used to initialize capture of samples to push into
55 ring buffers. The triggers are effectively a 'capture
56 data now' interrupt.
57
58config IIO_CONSUMERS_PER_TRIGGER
59 int "Maximum number of consumers per trigger"
60 depends on IIO_TRIGGER
61 default "2"
62 help
63 This value controls the maximum number of consumers that a
64 given trigger may handle. Default is 2.
65
66source "drivers/staging/iio/accel/Kconfig" 28source "drivers/staging/iio/accel/Kconfig"
67source "drivers/staging/iio/adc/Kconfig" 29source "drivers/staging/iio/adc/Kconfig"
68source "drivers/staging/iio/addac/Kconfig" 30source "drivers/staging/iio/addac/Kconfig"
69source "drivers/staging/iio/cdc/Kconfig" 31source "drivers/staging/iio/cdc/Kconfig"
70source "drivers/staging/iio/dac/Kconfig" 32source "drivers/staging/iio/dac/Kconfig"
71source "drivers/staging/iio/dds/Kconfig" 33source "drivers/staging/iio/frequency/Kconfig"
72source "drivers/staging/iio/gyro/Kconfig" 34source "drivers/staging/iio/gyro/Kconfig"
73source "drivers/staging/iio/impedance-analyzer/Kconfig" 35source "drivers/staging/iio/impedance-analyzer/Kconfig"
74source "drivers/staging/iio/imu/Kconfig" 36source "drivers/staging/iio/imu/Kconfig"
@@ -104,4 +66,4 @@ config IIO_SIMPLE_DUMMY_BUFFER
104 66
105endif # IIO_SIMPLE_DUMMY 67endif # IIO_SIMPLE_DUMMY
106 68
107endif # IIO 69endmenu
diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile
index 5075291dda7a..6a46d5afb380 100644
--- a/drivers/staging/iio/Makefile
+++ b/drivers/staging/iio/Makefile
@@ -2,13 +2,7 @@
2# Makefile for the industrial I/O core. 2# Makefile for the industrial I/O core.
3# 3#
4 4
5obj-$(CONFIG_IIO) += industrialio.o
6industrialio-y := industrialio-core.o industrialio-event.o inkern.o
7industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
8industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
9
10obj-$(CONFIG_IIO_SW_RING) += ring_sw.o 5obj-$(CONFIG_IIO_SW_RING) += ring_sw.o
11obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
12 6
13obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o 7obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o
14iio_dummy-y := iio_simple_dummy.o 8iio_dummy-y := iio_simple_dummy.o
@@ -24,7 +18,7 @@ obj-y += adc/
24obj-y += addac/ 18obj-y += addac/
25obj-y += cdc/ 19obj-y += cdc/
26obj-y += dac/ 20obj-y += dac/
27obj-y += dds/ 21obj-y += frequency/
28obj-y += gyro/ 22obj-y += gyro/
29obj-y += impedance-analyzer/ 23obj-y += impedance-analyzer/
30obj-y += imu/ 24obj-y += imu/
diff --git a/drivers/staging/iio/TODO b/drivers/staging/iio/TODO
index d1ad35e24abb..cf3f9489b9da 100644
--- a/drivers/staging/iio/TODO
+++ b/drivers/staging/iio/TODO
@@ -67,7 +67,7 @@ e-mailing the normal IIO list (see below).
67 67
68Documentation 68Documentation
691) Lots of cleanup and expansion. 691) Lots of cleanup and expansion.
702) Some device require indvidual docs. 702) Some device require individual docs.
71 71
72Contact: Jonathan Cameron <jic23@cam.ac.uk>. 72Contact: Jonathan Cameron <jic23@cam.ac.uk>.
73Mailing list: linux-iio@vger.kernel.org 73Mailing list: linux-iio@vger.kernel.org
diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
index d439e45d07fa..02b340919c0e 100644
--- a/drivers/staging/iio/accel/adis16201_core.c
+++ b/drivers/staging/iio/accel/adis16201_core.c
@@ -15,9 +15,9 @@
15#include <linux/sysfs.h> 15#include <linux/sysfs.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../buffer.h" 20#include <linux/iio/buffer.h>
21 21
22#include "adis16201.h" 22#include "adis16201.h"
23 23
@@ -171,7 +171,7 @@ static ssize_t adis16201_write_reset(struct device *dev,
171 ret = strtobool(buf, &res); 171 ret = strtobool(buf, &res);
172 if (ret || !res) 172 if (ret || !res)
173 return ret; 173 return ret;
174 return adis16201_reset(dev_get_drvdata(dev)); 174 return adis16201_reset(dev_to_iio_dev(dev));
175} 175}
176 176
177int adis16201_set_irq(struct iio_dev *indio_dev, bool enable) 177int adis16201_set_irq(struct iio_dev *indio_dev, bool enable)
@@ -298,7 +298,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
298 s16 val16; 298 s16 val16;
299 299
300 switch (mask) { 300 switch (mask) {
301 case 0: 301 case IIO_CHAN_INFO_RAW:
302 mutex_lock(&indio_dev->mlock); 302 mutex_lock(&indio_dev->mlock);
303 addr = adis16201_addresses[chan->address][0]; 303 addr = adis16201_addresses[chan->address][0];
304 ret = adis16201_spi_read_reg_16(indio_dev, addr, &val16); 304 ret = adis16201_spi_read_reg_16(indio_dev, addr, &val16);
@@ -406,39 +406,104 @@ static int adis16201_write_raw(struct iio_dev *indio_dev,
406} 406}
407 407
408static struct iio_chan_spec adis16201_channels[] = { 408static struct iio_chan_spec adis16201_channels[] = {
409 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "supply", 0, 0, 409 {
410 .type = IIO_VOLTAGE,
411 .indexed = 1,
412 .channel = 0,
413 .extend_name = "supply",
414 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
410 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 415 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
411 in_supply, ADIS16201_SCAN_SUPPLY, 416 .address = in_supply,
412 IIO_ST('u', 12, 16, 0), 0), 417 .scan_index = ADIS16201_SCAN_SUPPLY,
413 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 418 .scan_type = {
419 .sign = 'u',
420 .realbits = 12,
421 .storagebits = 16,
422 },
423 }, {
424 .type = IIO_TEMP,
425 .indexed = 1,
426 .channel = 0,
427 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
414 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 428 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
415 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, 429 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
416 temp, ADIS16201_SCAN_TEMP, 430 .address = temp,
417 IIO_ST('u', 12, 16, 0), 0), 431 .scan_index = ADIS16201_SCAN_TEMP,
418 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, 432 .scan_type = {
433 .sign = 'u',
434 .realbits = 12,
435 .storagebits = 16,
436 },
437 }, {
438 .type = IIO_ACCEL,
439 .modified = 1,
440 .channel2 = IIO_MOD_X,
441 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
419 IIO_CHAN_INFO_SCALE_SHARED_BIT | 442 IIO_CHAN_INFO_SCALE_SHARED_BIT |
420 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 443 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
421 accel_x, ADIS16201_SCAN_ACC_X, 444 .address = accel_x,
422 IIO_ST('s', 14, 16, 0), 0), 445 .scan_index = ADIS16201_SCAN_ACC_X,
423 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, 446 .scan_type = {
447 .sign = 's',
448 .realbits = 14,
449 .storagebits = 16,
450 },
451 }, {
452 .type = IIO_ACCEL,
453 .modified = 1,
454 .channel2 = IIO_MOD_Y,
455 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
424 IIO_CHAN_INFO_SCALE_SHARED_BIT | 456 IIO_CHAN_INFO_SCALE_SHARED_BIT |
425 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 457 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
426 accel_y, ADIS16201_SCAN_ACC_Y, 458 .address = accel_y,
427 IIO_ST('s', 14, 16, 0), 0), 459 .scan_index = ADIS16201_SCAN_ACC_Y,
428 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 460 .scan_type = {
461 .sign = 's',
462 .realbits = 14,
463 .storagebits = 16,
464 },
465 }, {
466 .type = IIO_VOLTAGE,
467 .indexed = 1,
468 .channel = 1,
469 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
429 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 470 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
430 in_aux, ADIS16201_SCAN_AUX_ADC, 471 .address = in_aux,
431 IIO_ST('u', 12, 16, 0), 0), 472 .scan_index = ADIS16201_SCAN_AUX_ADC,
432 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_X, 473 .scan_type = {
474 .sign = 'u',
475 .realbits = 12,
476 .storagebits = 16,
477 },
478 }, {
479 .type = IIO_INCLI,
480 .modified = 1,
481 .channel2 = IIO_MOD_X,
482 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
433 IIO_CHAN_INFO_SCALE_SHARED_BIT | 483 IIO_CHAN_INFO_SCALE_SHARED_BIT |
434 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 484 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
435 incli_x, ADIS16201_SCAN_INCLI_X, 485 .address = incli_x,
436 IIO_ST('s', 14, 16, 0), 0), 486 .scan_index = ADIS16201_SCAN_INCLI_X,
437 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_Y, 487 .scan_type = {
488 .sign = 's',
489 .realbits = 14,
490 .storagebits = 16,
491 },
492 }, {
493 .type = IIO_INCLI,
494 .modified = 1,
495 .channel2 = IIO_MOD_Y,
496 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
438 IIO_CHAN_INFO_SCALE_SHARED_BIT | 497 IIO_CHAN_INFO_SCALE_SHARED_BIT |
439 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 498 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
440 incli_y, ADIS16201_SCAN_INCLI_Y, 499 .address = incli_y,
441 IIO_ST('s', 14, 16, 0), 0), 500 .scan_index = ADIS16201_SCAN_INCLI_Y,
501 .scan_type = {
502 .sign = 's',
503 .realbits = 14,
504 .storagebits = 16,
505 },
506 },
442 IIO_CHAN_SOFT_TIMESTAMP(7) 507 IIO_CHAN_SOFT_TIMESTAMP(7)
443}; 508};
444 509
@@ -467,7 +532,7 @@ static int __devinit adis16201_probe(struct spi_device *spi)
467 struct iio_dev *indio_dev; 532 struct iio_dev *indio_dev;
468 533
469 /* setup the industrialio driver allocated elements */ 534 /* setup the industrialio driver allocated elements */
470 indio_dev = iio_allocate_device(sizeof(*st)); 535 indio_dev = iio_device_alloc(sizeof(*st));
471 if (indio_dev == NULL) { 536 if (indio_dev == NULL) {
472 ret = -ENOMEM; 537 ret = -ENOMEM;
473 goto error_ret; 538 goto error_ret;
@@ -522,7 +587,7 @@ error_uninitialize_ring:
522error_unreg_ring_funcs: 587error_unreg_ring_funcs:
523 adis16201_unconfigure_ring(indio_dev); 588 adis16201_unconfigure_ring(indio_dev);
524error_free_dev: 589error_free_dev:
525 iio_free_device(indio_dev); 590 iio_device_free(indio_dev);
526error_ret: 591error_ret:
527 return ret; 592 return ret;
528} 593}
@@ -535,7 +600,7 @@ static int adis16201_remove(struct spi_device *spi)
535 adis16201_remove_trigger(indio_dev); 600 adis16201_remove_trigger(indio_dev);
536 iio_buffer_unregister(indio_dev); 601 iio_buffer_unregister(indio_dev);
537 adis16201_unconfigure_ring(indio_dev); 602 adis16201_unconfigure_ring(indio_dev);
538 iio_free_device(indio_dev); 603 iio_device_free(indio_dev);
539 604
540 return 0; 605 return 0;
541} 606}
diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index 97f9e6b159d9..247602a8e54c 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -5,9 +5,9 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16201.h" 11#include "adis16201.h"
12 12
13 13
@@ -66,9 +66,8 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
66 66
67 int i = 0; 67 int i = 0;
68 s16 *data; 68 s16 *data;
69 size_t datasize = ring->access->get_bytes_per_datum(ring);
70 69
71 data = kmalloc(datasize, GFP_KERNEL); 70 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
72 if (data == NULL) { 71 if (data == NULL) {
73 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 72 dev_err(&st->us->dev, "memory alloc failed in ring bh");
74 return -ENOMEM; 73 return -ENOMEM;
@@ -81,7 +80,7 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
81 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 80 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
82 81
83 /* Guaranteed to be aligned with 8 byte boundary */ 82 /* Guaranteed to be aligned with 8 byte boundary */
84 if (ring->scan_timestamp) 83 if (indio_dev->scan_timestamp)
85 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 84 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
86 85
87 ring->access->store_to(ring, (u8 *)data, pf->timestamp); 86 ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16201_trigger.c b/drivers/staging/iio/accel/adis16201_trigger.c
index bce505e716d0..96fdabbac201 100644
--- a/drivers/staging/iio/accel/adis16201_trigger.c
+++ b/drivers/staging/iio/accel/adis16201_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16201.h" 8#include "adis16201.h"
9 9
10/** 10/**
@@ -29,7 +29,7 @@ int adis16201_probe_trigger(struct iio_dev *indio_dev)
29 int ret; 29 int ret;
30 struct adis16201_state *st = iio_priv(indio_dev); 30 struct adis16201_state *st = iio_priv(indio_dev);
31 31
32 st->trig = iio_allocate_trigger("adis16201-dev%d", indio_dev->id); 32 st->trig = iio_trigger_alloc("adis16201-dev%d", indio_dev->id);
33 if (st->trig == NULL) { 33 if (st->trig == NULL) {
34 ret = -ENOMEM; 34 ret = -ENOMEM;
35 goto error_ret; 35 goto error_ret;
@@ -56,7 +56,7 @@ int adis16201_probe_trigger(struct iio_dev *indio_dev)
56error_free_irq: 56error_free_irq:
57 free_irq(st->us->irq, st->trig); 57 free_irq(st->us->irq, st->trig);
58error_free_trig: 58error_free_trig:
59 iio_free_trigger(st->trig); 59 iio_trigger_free(st->trig);
60error_ret: 60error_ret:
61 return ret; 61 return ret;
62} 62}
@@ -67,5 +67,5 @@ void adis16201_remove_trigger(struct iio_dev *indio_dev)
67 67
68 iio_trigger_unregister(state->trig); 68 iio_trigger_unregister(state->trig);
69 free_irq(state->us->irq, state->trig); 69 free_irq(state->us->irq, state->trig);
70 iio_free_trigger(state->trig); 70 iio_trigger_free(state->trig);
71} 71}
diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c
index 1a5140f9e3f4..15d46bfd1b42 100644
--- a/drivers/staging/iio/accel/adis16203_core.c
+++ b/drivers/staging/iio/accel/adis16203_core.c
@@ -15,9 +15,9 @@
15#include <linux/sysfs.h> 15#include <linux/sysfs.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../buffer.h" 20#include <linux/iio/buffer.h>
21 21
22#include "adis16203.h" 22#include "adis16203.h"
23 23
@@ -182,7 +182,7 @@ static ssize_t adis16203_write_reset(struct device *dev,
182 struct device_attribute *attr, 182 struct device_attribute *attr,
183 const char *buf, size_t len) 183 const char *buf, size_t len)
184{ 184{
185 struct iio_dev *indio_dev = dev_get_drvdata(dev); 185 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
186 if (len < 1) 186 if (len < 1)
187 return -EINVAL; 187 return -EINVAL;
188 switch (buf[0]) { 188 switch (buf[0]) {
@@ -305,7 +305,7 @@ static int adis16203_read_raw(struct iio_dev *indio_dev,
305 u8 addr; 305 u8 addr;
306 s16 val16; 306 s16 val16;
307 switch (mask) { 307 switch (mask) {
308 case 0: 308 case IIO_CHAN_INFO_RAW:
309 mutex_lock(&indio_dev->mlock); 309 mutex_lock(&indio_dev->mlock);
310 addr = adis16203_addresses[chan->address][0]; 310 addr = adis16203_addresses[chan->address][0];
311 ret = adis16203_spi_read_reg_16(indio_dev, addr, &val16); 311 ret = adis16203_spi_read_reg_16(indio_dev, addr, &val16);
@@ -372,29 +372,75 @@ static int adis16203_read_raw(struct iio_dev *indio_dev,
372} 372}
373 373
374static struct iio_chan_spec adis16203_channels[] = { 374static struct iio_chan_spec adis16203_channels[] = {
375 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "supply", 0, 0, 375 {
376 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 376 .type = IIO_VOLTAGE,
377 in_supply, ADIS16203_SCAN_SUPPLY, 377 .indexed = 1,
378 IIO_ST('u', 12, 16, 0), 0), 378 .channel = 0,
379 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 379 .extend_name = "supply",
380 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 380 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
381 in_aux, ADIS16203_SCAN_AUX_ADC, 381 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
382 IIO_ST('u', 12, 16, 0), 0), 382 .address = in_supply,
383 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_X, 383 .scan_index = ADIS16203_SCAN_SUPPLY,
384 IIO_CHAN_INFO_SCALE_SHARED_BIT | 384 .scan_type = {
385 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 385 .sign = 'u',
386 incli_x, ADIS16203_SCAN_INCLI_X, 386 .realbits = 12,
387 IIO_ST('s', 14, 16, 0), 0), 387 .storagebits = 16,
388 /* Fixme: Not what it appears to be - see data sheet */ 388 },
389 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_Y, 389 }, {
390 IIO_CHAN_INFO_SCALE_SHARED_BIT, 390 .type = IIO_VOLTAGE,
391 incli_y, ADIS16203_SCAN_INCLI_Y, 391 .indexed = 1,
392 IIO_ST('s', 14, 16, 0), 0), 392 .channel = 1,
393 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 393 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
394 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 394 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
395 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, 395 .address = in_aux,
396 temp, ADIS16203_SCAN_TEMP, 396 .scan_index = ADIS16203_SCAN_AUX_ADC,
397 IIO_ST('u', 12, 16, 0), 0), 397 .scan_type = {
398 .sign = 'u',
399 .realbits = 12,
400 .storagebits = 16,
401 },
402 }, {
403 .type = IIO_INCLI,
404 .modified = 1,
405 .channel2 = IIO_MOD_X,
406 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
407 IIO_CHAN_INFO_SCALE_SHARED_BIT |
408 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
409 .address = incli_x,
410 .scan_index = ADIS16203_SCAN_INCLI_X,
411 .scan_type = {
412 .sign = 's',
413 .realbits = 14,
414 .storagebits = 16,
415 },
416 }, { /* Fixme: Not what it appears to be - see data sheet */
417 .type = IIO_INCLI,
418 .modified = 1,
419 .channel2 = IIO_MOD_Y,
420 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
421 IIO_CHAN_INFO_SCALE_SHARED_BIT,
422 .address = incli_y,
423 .scan_index = ADIS16203_SCAN_INCLI_Y,
424 .scan_type = {
425 .sign = 's',
426 .realbits = 14,
427 .storagebits = 16,
428 },
429 }, {
430 .type = IIO_TEMP,
431 .indexed = 1,
432 .channel = 0,
433 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
434 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
435 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
436 .address = temp,
437 .scan_index = ADIS16203_SCAN_TEMP,
438 .scan_type = {
439 .sign = 'u',
440 .realbits = 12,
441 .storagebits = 16,
442 },
443 },
398 IIO_CHAN_SOFT_TIMESTAMP(5), 444 IIO_CHAN_SOFT_TIMESTAMP(5),
399}; 445};
400 446
@@ -423,7 +469,7 @@ static int __devinit adis16203_probe(struct spi_device *spi)
423 struct adis16203_state *st; 469 struct adis16203_state *st;
424 470
425 /* setup the industrialio driver allocated elements */ 471 /* setup the industrialio driver allocated elements */
426 indio_dev = iio_allocate_device(sizeof(*st)); 472 indio_dev = iio_device_alloc(sizeof(*st));
427 if (indio_dev == NULL) { 473 if (indio_dev == NULL) {
428 ret = -ENOMEM; 474 ret = -ENOMEM;
429 goto error_ret; 475 goto error_ret;
@@ -477,7 +523,7 @@ error_uninitialize_ring:
477error_unreg_ring_funcs: 523error_unreg_ring_funcs:
478 adis16203_unconfigure_ring(indio_dev); 524 adis16203_unconfigure_ring(indio_dev);
479error_free_dev: 525error_free_dev:
480 iio_free_device(indio_dev); 526 iio_device_free(indio_dev);
481error_ret: 527error_ret:
482 return ret; 528 return ret;
483} 529}
@@ -490,7 +536,7 @@ static int adis16203_remove(struct spi_device *spi)
490 adis16203_remove_trigger(indio_dev); 536 adis16203_remove_trigger(indio_dev);
491 iio_buffer_unregister(indio_dev); 537 iio_buffer_unregister(indio_dev);
492 adis16203_unconfigure_ring(indio_dev); 538 adis16203_unconfigure_ring(indio_dev);
493 iio_free_device(indio_dev); 539 iio_device_free(indio_dev);
494 540
495 return 0; 541 return 0;
496} 542}
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
index 6a8963db4f60..7bbd2c2bbd19 100644
--- a/drivers/staging/iio/accel/adis16203_ring.c
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -5,20 +5,19 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16203.h" 11#include "adis16203.h"
12 12
13/** 13/**
14 * adis16203_read_ring_data() read data registers which will be placed into ring 14 * adis16203_read_ring_data() read data registers which will be placed into ring
15 * @dev: device associated with child of actual device (iio_dev or iio_trig) 15 * @indio_dev: the IIO device
16 * @rx: somewhere to pass back the value read 16 * @rx: somewhere to pass back the value read
17 **/ 17 **/
18static int adis16203_read_ring_data(struct device *dev, u8 *rx) 18static int adis16203_read_ring_data(struct iio_dev *indio_dev, u8 *rx)
19{ 19{
20 struct spi_message msg; 20 struct spi_message msg;
21 struct iio_dev *indio_dev = dev_get_drvdata(dev);
22 struct adis16203_state *st = iio_priv(indio_dev); 21 struct adis16203_state *st = iio_priv(indio_dev);
23 struct spi_transfer xfers[ADIS16203_OUTPUTS + 1]; 22 struct spi_transfer xfers[ADIS16203_OUTPUTS + 1];
24 int ret; 23 int ret;
@@ -66,22 +65,21 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
66 65
67 int i = 0; 66 int i = 0;
68 s16 *data; 67 s16 *data;
69 size_t datasize = ring->access->get_bytes_per_datum(ring);
70 68
71 data = kmalloc(datasize, GFP_KERNEL); 69 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
72 if (data == NULL) { 70 if (data == NULL) {
73 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 71 dev_err(&st->us->dev, "memory alloc failed in ring bh");
74 return -ENOMEM; 72 return -ENOMEM;
75 } 73 }
76 74
77 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && 75 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
78 adis16203_read_ring_data(&indio_dev->dev, st->rx) >= 0) 76 adis16203_read_ring_data(indio_dev, st->rx) >= 0)
79 for (; i < bitmap_weight(indio_dev->active_scan_mask, 77 for (; i < bitmap_weight(indio_dev->active_scan_mask,
80 indio_dev->masklength); i++) 78 indio_dev->masklength); i++)
81 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 79 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
82 80
83 /* Guaranteed to be aligned with 8 byte boundary */ 81 /* Guaranteed to be aligned with 8 byte boundary */
84 if (ring->scan_timestamp) 82 if (indio_dev->scan_timestamp)
85 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 83 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
86 84
87 ring->access->store_to(ring, 85 ring->access->store_to(ring,
diff --git a/drivers/staging/iio/accel/adis16203_trigger.c b/drivers/staging/iio/accel/adis16203_trigger.c
index 24bcb8e15c55..b8a04073d6d7 100644
--- a/drivers/staging/iio/accel/adis16203_trigger.c
+++ b/drivers/staging/iio/accel/adis16203_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16203.h" 8#include "adis16203.h"
9 9
10/** 10/**
@@ -29,7 +29,7 @@ int adis16203_probe_trigger(struct iio_dev *indio_dev)
29 int ret; 29 int ret;
30 struct adis16203_state *st = iio_priv(indio_dev); 30 struct adis16203_state *st = iio_priv(indio_dev);
31 31
32 st->trig = iio_allocate_trigger("adis16203-dev%d", indio_dev->id); 32 st->trig = iio_trigger_alloc("adis16203-dev%d", indio_dev->id);
33 if (st->trig == NULL) { 33 if (st->trig == NULL) {
34 ret = -ENOMEM; 34 ret = -ENOMEM;
35 goto error_ret; 35 goto error_ret;
@@ -58,7 +58,7 @@ int adis16203_probe_trigger(struct iio_dev *indio_dev)
58error_free_irq: 58error_free_irq:
59 free_irq(st->us->irq, st->trig); 59 free_irq(st->us->irq, st->trig);
60error_free_trig: 60error_free_trig:
61 iio_free_trigger(st->trig); 61 iio_trigger_free(st->trig);
62error_ret: 62error_ret:
63 return ret; 63 return ret;
64} 64}
@@ -69,5 +69,5 @@ void adis16203_remove_trigger(struct iio_dev *indio_dev)
69 69
70 iio_trigger_unregister(st->trig); 70 iio_trigger_unregister(st->trig);
71 free_irq(st->us->irq, st->trig); 71 free_irq(st->us->irq, st->trig);
72 iio_free_trigger(st->trig); 72 iio_trigger_free(st->trig);
73} 73}
diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c
index fa89364b841e..ac9d95e4ea47 100644
--- a/drivers/staging/iio/accel/adis16204_core.c
+++ b/drivers/staging/iio/accel/adis16204_core.c
@@ -18,9 +18,9 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24 24
25#include "adis16204.h" 25#include "adis16204.h"
26 26
@@ -173,7 +173,7 @@ static ssize_t adis16204_read_14bit_signed(struct device *dev,
173 struct device_attribute *attr, 173 struct device_attribute *attr,
174 char *buf) 174 char *buf)
175{ 175{
176 struct iio_dev *indio_dev = dev_get_drvdata(dev); 176 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
177 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 177 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
178 s16 val = 0; 178 s16 val = 0;
179 ssize_t ret; 179 ssize_t ret;
@@ -211,7 +211,7 @@ static ssize_t adis16204_write_reset(struct device *dev,
211 struct device_attribute *attr, 211 struct device_attribute *attr,
212 const char *buf, size_t len) 212 const char *buf, size_t len)
213{ 213{
214 struct iio_dev *indio_dev = dev_get_drvdata(dev); 214 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
215 215
216 if (len < 1) 216 if (len < 1)
217 return -EINVAL; 217 return -EINVAL;
@@ -342,7 +342,7 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
342 int addrind; 342 int addrind;
343 343
344 switch (mask) { 344 switch (mask) {
345 case 0: 345 case IIO_CHAN_INFO_RAW:
346 mutex_lock(&indio_dev->mlock); 346 mutex_lock(&indio_dev->mlock);
347 addr = adis16204_addresses[chan->address][0]; 347 addr = adis16204_addresses[chan->address][0];
348 ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16); 348 ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16);
@@ -444,31 +444,78 @@ static int adis16204_write_raw(struct iio_dev *indio_dev,
444} 444}
445 445
446static struct iio_chan_spec adis16204_channels[] = { 446static struct iio_chan_spec adis16204_channels[] = {
447 IIO_CHAN(IIO_VOLTAGE, 0, 0, 0, "supply", 0, 0, 447 {
448 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 448 .type = IIO_VOLTAGE,
449 in_supply, ADIS16204_SCAN_SUPPLY, 449 .indexed = 1, /* Note was not previously indexed */
450 IIO_ST('u', 12, 16, 0), 0), 450 .channel = 0,
451 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 451 .extend_name = "supply",
452 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 452 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
453 in_aux, ADIS16204_SCAN_AUX_ADC, 453 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
454 IIO_ST('u', 12, 16, 0), 0), 454 .address = in_supply,
455 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 455 .scan_index = ADIS16204_SCAN_SUPPLY,
456 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 456 .scan_type = {
457 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, 457 .sign = 'u',
458 temp, ADIS16204_SCAN_TEMP, 458 .realbits = 12,
459 IIO_ST('u', 12, 16, 0), 0), 459 .storagebits = 16,
460 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, 460 },
461 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 461 }, {
462 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 462 .type = IIO_VOLTAGE,
463 IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 463 .indexed = 1,
464 accel_x, ADIS16204_SCAN_ACC_X, 464 .channel = 1,
465 IIO_ST('s', 14, 16, 0), 0), 465 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
466 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, 466 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
467 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 467 .address = in_aux,
468 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 468 .scan_index = ADIS16204_SCAN_AUX_ADC,
469 IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 469 .scan_type = {
470 accel_y, ADIS16204_SCAN_ACC_Y, 470 .sign = 'u',
471 IIO_ST('s', 14, 16, 0), 0), 471 .realbits = 12,
472 .storagebits = 16,
473 },
474 }, {
475 .type = IIO_TEMP,
476 .indexed = 1,
477 .channel = 0,
478 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
479 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
480 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
481 .address = temp,
482 .scan_index = ADIS16204_SCAN_TEMP,
483 .scan_type = {
484 .sign = 'u',
485 .realbits = 12,
486 .storagebits = 16,
487 },
488 }, {
489 .type = IIO_ACCEL,
490 .modified = 1,
491 .channel2 = IIO_MOD_X,
492 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
493 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
494 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
495 IIO_CHAN_INFO_PEAK_SEPARATE_BIT,
496 .address = accel_x,
497 .scan_index = ADIS16204_SCAN_ACC_X,
498 .scan_type = {
499 .sign = 's',
500 .realbits = 14,
501 .storagebits = 16,
502 },
503 }, {
504 .type = IIO_ACCEL,
505 .modified = 1,
506 .channel2 = IIO_MOD_Y,
507 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
508 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
509 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
510 IIO_CHAN_INFO_PEAK_SEPARATE_BIT,
511 .address = accel_y,
512 .scan_index = ADIS16204_SCAN_ACC_Y,
513 .scan_type = {
514 .sign = 's',
515 .realbits = 14,
516 .storagebits = 16,
517 },
518 },
472 IIO_CHAN_SOFT_TIMESTAMP(5), 519 IIO_CHAN_SOFT_TIMESTAMP(5),
473}; 520};
474 521
@@ -498,7 +545,7 @@ static int __devinit adis16204_probe(struct spi_device *spi)
498 struct iio_dev *indio_dev; 545 struct iio_dev *indio_dev;
499 546
500 /* setup the industrialio driver allocated elements */ 547 /* setup the industrialio driver allocated elements */
501 indio_dev = iio_allocate_device(sizeof(*st)); 548 indio_dev = iio_device_alloc(sizeof(*st));
502 if (indio_dev == NULL) { 549 if (indio_dev == NULL) {
503 ret = -ENOMEM; 550 ret = -ENOMEM;
504 goto error_ret; 551 goto error_ret;
@@ -551,7 +598,7 @@ error_uninitialize_ring:
551error_unreg_ring_funcs: 598error_unreg_ring_funcs:
552 adis16204_unconfigure_ring(indio_dev); 599 adis16204_unconfigure_ring(indio_dev);
553error_free_dev: 600error_free_dev:
554 iio_free_device(indio_dev); 601 iio_device_free(indio_dev);
555error_ret: 602error_ret:
556 return ret; 603 return ret;
557} 604}
@@ -564,7 +611,7 @@ static int adis16204_remove(struct spi_device *spi)
564 adis16204_remove_trigger(indio_dev); 611 adis16204_remove_trigger(indio_dev);
565 iio_buffer_unregister(indio_dev); 612 iio_buffer_unregister(indio_dev);
566 adis16204_unconfigure_ring(indio_dev); 613 adis16204_unconfigure_ring(indio_dev);
567 iio_free_device(indio_dev); 614 iio_device_free(indio_dev);
568 615
569 return 0; 616 return 0;
570} 617}
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
index 5c8ab7338864..f73518bc6587 100644
--- a/drivers/staging/iio/accel/adis16204_ring.c
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -5,20 +5,19 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16204.h" 11#include "adis16204.h"
12 12
13/** 13/**
14 * adis16204_read_ring_data() read data registers which will be placed into ring 14 * adis16204_read_ring_data() read data registers which will be placed into ring
15 * @dev: device associated with child of actual device (iio_dev or iio_trig) 15 * @indio_dev: the IIO device
16 * @rx: somewhere to pass back the value read 16 * @rx: somewhere to pass back the value read
17 **/ 17 **/
18static int adis16204_read_ring_data(struct device *dev, u8 *rx) 18static int adis16204_read_ring_data(struct iio_dev *indio_dev, u8 *rx)
19{ 19{
20 struct spi_message msg; 20 struct spi_message msg;
21 struct iio_dev *indio_dev = dev_get_drvdata(dev);
22 struct adis16204_state *st = iio_priv(indio_dev); 21 struct adis16204_state *st = iio_priv(indio_dev);
23 struct spi_transfer xfers[ADIS16204_OUTPUTS + 1]; 22 struct spi_transfer xfers[ADIS16204_OUTPUTS + 1];
24 int ret; 23 int ret;
@@ -63,22 +62,21 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
63 struct iio_buffer *ring = indio_dev->buffer; 62 struct iio_buffer *ring = indio_dev->buffer;
64 int i = 0; 63 int i = 0;
65 s16 *data; 64 s16 *data;
66 size_t datasize = ring->access->get_bytes_per_datum(ring);
67 65
68 data = kmalloc(datasize, GFP_KERNEL); 66 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
69 if (data == NULL) { 67 if (data == NULL) {
70 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 68 dev_err(&st->us->dev, "memory alloc failed in ring bh");
71 return -ENOMEM; 69 return -ENOMEM;
72 } 70 }
73 71
74 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && 72 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
75 adis16204_read_ring_data(&indio_dev->dev, st->rx) >= 0) 73 adis16204_read_ring_data(indio_dev, st->rx) >= 0)
76 for (; i < bitmap_weight(indio_dev->active_scan_mask, 74 for (; i < bitmap_weight(indio_dev->active_scan_mask,
77 indio_dev->masklength); i++) 75 indio_dev->masklength); i++)
78 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 76 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
79 77
80 /* Guaranteed to be aligned with 8 byte boundary */ 78 /* Guaranteed to be aligned with 8 byte boundary */
81 if (ring->scan_timestamp) 79 if (indio_dev->scan_timestamp)
82 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 80 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
83 81
84 ring->access->store_to(ring, (u8 *)data, pf->timestamp); 82 ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16204_trigger.c b/drivers/staging/iio/accel/adis16204_trigger.c
index 6e542af02c09..408a1682368e 100644
--- a/drivers/staging/iio/accel/adis16204_trigger.c
+++ b/drivers/staging/iio/accel/adis16204_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16204.h" 8#include "adis16204.h"
9 9
10/** 10/**
@@ -29,7 +29,7 @@ int adis16204_probe_trigger(struct iio_dev *indio_dev)
29 int ret; 29 int ret;
30 struct adis16204_state *st = iio_priv(indio_dev); 30 struct adis16204_state *st = iio_priv(indio_dev);
31 31
32 st->trig = iio_allocate_trigger("adis16204-dev%d", indio_dev->id); 32 st->trig = iio_trigger_alloc("adis16204-dev%d", indio_dev->id);
33 if (st->trig == NULL) { 33 if (st->trig == NULL) {
34 ret = -ENOMEM; 34 ret = -ENOMEM;
35 goto error_ret; 35 goto error_ret;
@@ -58,7 +58,7 @@ int adis16204_probe_trigger(struct iio_dev *indio_dev)
58error_free_irq: 58error_free_irq:
59 free_irq(st->us->irq, st->trig); 59 free_irq(st->us->irq, st->trig);
60error_free_trig: 60error_free_trig:
61 iio_free_trigger(st->trig); 61 iio_trigger_free(st->trig);
62error_ret: 62error_ret:
63 return ret; 63 return ret;
64} 64}
@@ -69,5 +69,5 @@ void adis16204_remove_trigger(struct iio_dev *indio_dev)
69 69
70 iio_trigger_unregister(state->trig); 70 iio_trigger_unregister(state->trig);
71 free_irq(state->us->irq, state->trig); 71 free_irq(state->us->irq, state->trig);
72 iio_free_trigger(state->trig); 72 iio_trigger_free(state->trig);
73} 73}
diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c
index a98715f6bd6d..f6fd0d31d4f0 100644
--- a/drivers/staging/iio/accel/adis16209_core.c
+++ b/drivers/staging/iio/accel/adis16209_core.c
@@ -16,9 +16,9 @@
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../buffer.h" 21#include <linux/iio/buffer.h>
22 22
23#include "adis16209.h" 23#include "adis16209.h"
24 24
@@ -157,7 +157,7 @@ static ssize_t adis16209_write_reset(struct device *dev,
157 struct device_attribute *attr, 157 struct device_attribute *attr,
158 const char *buf, size_t len) 158 const char *buf, size_t len)
159{ 159{
160 struct iio_dev *indio_dev = dev_get_drvdata(dev); 160 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
161 161
162 if (len < 1) 162 if (len < 1)
163 return -EINVAL; 163 return -EINVAL;
@@ -331,7 +331,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
331 s16 val16; 331 s16 val16;
332 332
333 switch (mask) { 333 switch (mask) {
334 case 0: 334 case IIO_CHAN_INFO_RAW:
335 mutex_lock(&indio_dev->mlock); 335 mutex_lock(&indio_dev->mlock);
336 addr = adis16209_addresses[chan->address][0]; 336 addr = adis16209_addresses[chan->address][0];
337 ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16); 337 ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16);
@@ -408,41 +408,114 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
408} 408}
409 409
410static struct iio_chan_spec adis16209_channels[] = { 410static struct iio_chan_spec adis16209_channels[] = {
411 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 411 {
412 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 412 .type = IIO_VOLTAGE,
413 in_supply, ADIS16209_SCAN_SUPPLY, 413 .indexed = 1,
414 IIO_ST('u', 14, 16, 0), 0), 414 .channel = 0,
415 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 415 .extend_name = "supply",
416 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 416 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
417 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, 417 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
418 temp, ADIS16209_SCAN_TEMP, 418 .address = in_supply,
419 IIO_ST('u', 12, 16, 0), 0), 419 .scan_index = ADIS16209_SCAN_SUPPLY,
420 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, 420 .scan_type = {
421 IIO_CHAN_INFO_SCALE_SHARED_BIT | 421 .sign = 'u',
422 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 422 .realbits = 14,
423 accel_x, ADIS16209_SCAN_ACC_X, 423 .storagebits = 16,
424 IIO_ST('s', 14, 16, 0), 0), 424 },
425 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, 425 }, {
426 IIO_CHAN_INFO_SCALE_SHARED_BIT | 426 .type = IIO_TEMP,
427 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 427 .indexed = 0,
428 accel_y, ADIS16209_SCAN_ACC_Y, 428 .channel = 0,
429 IIO_ST('s', 14, 16, 0), 0), 429 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
430 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 430 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
431 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 431 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
432 in_aux, ADIS16209_SCAN_AUX_ADC, 432 .address = temp,
433 IIO_ST('u', 12, 16, 0), 0), 433 .scan_index = ADIS16209_SCAN_TEMP,
434 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_X, 434 .scan_type = {
435 IIO_CHAN_INFO_SCALE_SHARED_BIT, 435 .sign = 'u',
436 incli_x, ADIS16209_SCAN_INCLI_X, 436 .realbits = 12,
437 IIO_ST('s', 14, 16, 0), 0), 437 .storagebits = 16,
438 IIO_CHAN(IIO_INCLI, 1, 0, 0, NULL, 0, IIO_MOD_Y, 438 },
439 IIO_CHAN_INFO_SCALE_SHARED_BIT, 439 }, {
440 incli_y, ADIS16209_SCAN_INCLI_Y, 440 .type = IIO_ACCEL,
441 IIO_ST('s', 14, 16, 0), 0), 441 .modified = 1,
442 IIO_CHAN(IIO_ROT, 0, 1, 0, NULL, 0, IIO_MOD_X, 442 .channel2 = IIO_MOD_X,
443 0, 443 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
444 rot, ADIS16209_SCAN_ROT, 444 IIO_CHAN_INFO_SCALE_SHARED_BIT |
445 IIO_ST('s', 14, 16, 0), 0), 445 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
446 .address = accel_x,
447 .scan_index = ADIS16209_SCAN_ACC_X,
448 .scan_type = {
449 .sign = 's',
450 .realbits = 14,
451 .storagebits = 16,
452 },
453 }, {
454 .type = IIO_ACCEL,
455 .modified = 1,
456 .channel2 = IIO_MOD_Y,
457 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
458 IIO_CHAN_INFO_SCALE_SHARED_BIT |
459 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
460 .address = accel_y,
461 .scan_index = ADIS16209_SCAN_ACC_Y,
462 .scan_type = {
463 .sign = 's',
464 .realbits = 14,
465 .storagebits = 16,
466 },
467 }, {
468 .type = IIO_VOLTAGE,
469 .indexed = 1,
470 .channel = 1,
471 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
472 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
473 .address = in_aux,
474 .scan_index = ADIS16209_SCAN_AUX_ADC,
475 .scan_type = {
476 .sign = 'u',
477 .realbits = 12,
478 .storagebits = 16,
479 },
480 }, {
481 .type = IIO_INCLI,
482 .modified = 1,
483 .channel2 = IIO_MOD_X,
484 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
485 IIO_CHAN_INFO_SCALE_SHARED_BIT,
486 .address = incli_x,
487 .scan_index = ADIS16209_SCAN_INCLI_X,
488 .scan_type = {
489 .sign = 's',
490 .realbits = 14,
491 .storagebits = 16,
492 },
493 }, {
494 .type = IIO_INCLI,
495 .modified = 1,
496 .channel2 = IIO_MOD_Y,
497 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
498 IIO_CHAN_INFO_SCALE_SHARED_BIT,
499 .address = incli_y,
500 .scan_index = ADIS16209_SCAN_INCLI_Y,
501 .scan_type = {
502 .sign = 's',
503 .realbits = 14,
504 .storagebits = 16,
505 },
506 }, {
507 .type = IIO_ROT,
508 .modified = 1,
509 .channel2 = IIO_MOD_X,
510 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
511 .address = rot,
512 .scan_index = ADIS16209_SCAN_ROT,
513 .scan_type = {
514 .sign = 's',
515 .realbits = 14,
516 .storagebits = 16,
517 },
518 },
446 IIO_CHAN_SOFT_TIMESTAMP(8) 519 IIO_CHAN_SOFT_TIMESTAMP(8)
447}; 520};
448 521
@@ -471,7 +544,7 @@ static int __devinit adis16209_probe(struct spi_device *spi)
471 struct iio_dev *indio_dev; 544 struct iio_dev *indio_dev;
472 545
473 /* setup the industrialio driver allocated elements */ 546 /* setup the industrialio driver allocated elements */
474 indio_dev = iio_allocate_device(sizeof(*st)); 547 indio_dev = iio_device_alloc(sizeof(*st));
475 if (indio_dev == NULL) { 548 if (indio_dev == NULL) {
476 ret = -ENOMEM; 549 ret = -ENOMEM;
477 goto error_ret; 550 goto error_ret;
@@ -524,7 +597,7 @@ error_uninitialize_ring:
524error_unreg_ring_funcs: 597error_unreg_ring_funcs:
525 adis16209_unconfigure_ring(indio_dev); 598 adis16209_unconfigure_ring(indio_dev);
526error_free_dev: 599error_free_dev:
527 iio_free_device(indio_dev); 600 iio_device_free(indio_dev);
528error_ret: 601error_ret:
529 return ret; 602 return ret;
530} 603}
@@ -539,7 +612,7 @@ static int adis16209_remove(struct spi_device *spi)
539 adis16209_remove_trigger(indio_dev); 612 adis16209_remove_trigger(indio_dev);
540 iio_buffer_unregister(indio_dev); 613 iio_buffer_unregister(indio_dev);
541 adis16209_unconfigure_ring(indio_dev); 614 adis16209_unconfigure_ring(indio_dev);
542 iio_free_device(indio_dev); 615 iio_device_free(indio_dev);
543 616
544 return 0; 617 return 0;
545} 618}
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 57254b6b38b7..090607504c93 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -5,20 +5,19 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16209.h" 11#include "adis16209.h"
12 12
13/** 13/**
14 * adis16209_read_ring_data() read data registers which will be placed into ring 14 * adis16209_read_ring_data() read data registers which will be placed into ring
15 * @dev: device associated with child of actual device (iio_dev or iio_trig) 15 * @indio_dev: the IIO device
16 * @rx: somewhere to pass back the value read 16 * @rx: somewhere to pass back the value read
17 **/ 17 **/
18static int adis16209_read_ring_data(struct device *dev, u8 *rx) 18static int adis16209_read_ring_data(struct iio_dev *indio_dev, u8 *rx)
19{ 19{
20 struct spi_message msg; 20 struct spi_message msg;
21 struct iio_dev *indio_dev = dev_get_drvdata(dev);
22 struct adis16209_state *st = iio_priv(indio_dev); 21 struct adis16209_state *st = iio_priv(indio_dev);
23 struct spi_transfer xfers[ADIS16209_OUTPUTS + 1]; 22 struct spi_transfer xfers[ADIS16209_OUTPUTS + 1];
24 int ret; 23 int ret;
@@ -61,25 +60,23 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
61 struct iio_dev *indio_dev = pf->indio_dev; 60 struct iio_dev *indio_dev = pf->indio_dev;
62 struct adis16209_state *st = iio_priv(indio_dev); 61 struct adis16209_state *st = iio_priv(indio_dev);
63 struct iio_buffer *ring = indio_dev->buffer; 62 struct iio_buffer *ring = indio_dev->buffer;
64
65 int i = 0; 63 int i = 0;
66 s16 *data; 64 s16 *data;
67 size_t datasize = ring->access->get_bytes_per_datum(ring);
68 65
69 data = kmalloc(datasize , GFP_KERNEL); 66 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
70 if (data == NULL) { 67 if (data == NULL) {
71 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 68 dev_err(&st->us->dev, "memory alloc failed in ring bh");
72 return -ENOMEM; 69 return -ENOMEM;
73 } 70 }
74 71
75 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && 72 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
76 adis16209_read_ring_data(&indio_dev->dev, st->rx) >= 0) 73 adis16209_read_ring_data(indio_dev, st->rx) >= 0)
77 for (; i < bitmap_weight(indio_dev->active_scan_mask, 74 for (; i < bitmap_weight(indio_dev->active_scan_mask,
78 indio_dev->masklength); i++) 75 indio_dev->masklength); i++)
79 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 76 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
80 77
81 /* Guaranteed to be aligned with 8 byte boundary */ 78 /* Guaranteed to be aligned with 8 byte boundary */
82 if (ring->scan_timestamp) 79 if (indio_dev->scan_timestamp)
83 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 80 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
84 81
85 ring->access->store_to(ring, (u8 *)data, pf->timestamp); 82 ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16209_trigger.c b/drivers/staging/iio/accel/adis16209_trigger.c
index c5d82c1a55d9..2ad93dcaf40d 100644
--- a/drivers/staging/iio/accel/adis16209_trigger.c
+++ b/drivers/staging/iio/accel/adis16209_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16209.h" 8#include "adis16209.h"
9 9
10/** 10/**
@@ -38,7 +38,7 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev)
38 int ret; 38 int ret;
39 struct adis16209_state *st = iio_priv(indio_dev); 39 struct adis16209_state *st = iio_priv(indio_dev);
40 40
41 st->trig = iio_allocate_trigger("adis16209-dev%d", indio_dev->id); 41 st->trig = iio_trigger_alloc("adis16209-dev%d", indio_dev->id);
42 if (st->trig == NULL) { 42 if (st->trig == NULL) {
43 ret = -ENOMEM; 43 ret = -ENOMEM;
44 goto error_ret; 44 goto error_ret;
@@ -66,7 +66,7 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev)
66error_free_irq: 66error_free_irq:
67 free_irq(st->us->irq, st->trig); 67 free_irq(st->us->irq, st->trig);
68error_free_trig: 68error_free_trig:
69 iio_free_trigger(st->trig); 69 iio_trigger_free(st->trig);
70error_ret: 70error_ret:
71 return ret; 71 return ret;
72} 72}
@@ -77,5 +77,5 @@ void adis16209_remove_trigger(struct iio_dev *indio_dev)
77 77
78 iio_trigger_unregister(st->trig); 78 iio_trigger_unregister(st->trig);
79 free_irq(st->us->irq, st->trig); 79 free_irq(st->us->irq, st->trig);
80 iio_free_trigger(st->trig); 80 iio_trigger_free(st->trig);
81} 81}
diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c
index 51a852d45482..6a9ac898cb01 100644
--- a/drivers/staging/iio/accel/adis16220_core.c
+++ b/drivers/staging/iio/accel/adis16220_core.c
@@ -15,8 +15,8 @@
15#include <linux/sysfs.h> 15#include <linux/sysfs.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20 20
21#include "adis16220.h" 21#include "adis16220.h"
22 22
@@ -145,7 +145,7 @@ static ssize_t adis16220_read_16bit(struct device *dev,
145 char *buf) 145 char *buf)
146{ 146{
147 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 147 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
148 struct iio_dev *indio_dev = dev_get_drvdata(dev); 148 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
149 ssize_t ret; 149 ssize_t ret;
150 s16 val = 0; 150 s16 val = 0;
151 151
@@ -164,7 +164,7 @@ static ssize_t adis16220_write_16bit(struct device *dev,
164 const char *buf, 164 const char *buf,
165 size_t len) 165 size_t len)
166{ 166{
167 struct iio_dev *indio_dev = dev_get_drvdata(dev); 167 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
168 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 168 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
169 int ret; 169 int ret;
170 u16 val; 170 u16 val;
@@ -208,7 +208,7 @@ static ssize_t adis16220_write_reset(struct device *dev,
208 struct device_attribute *attr, 208 struct device_attribute *attr,
209 const char *buf, size_t len) 209 const char *buf, size_t len)
210{ 210{
211 struct iio_dev *indio_dev = dev_get_drvdata(dev); 211 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
212 bool val; 212 bool val;
213 int ret; 213 int ret;
214 214
@@ -228,7 +228,7 @@ static ssize_t adis16220_write_capture(struct device *dev,
228 struct device_attribute *attr, 228 struct device_attribute *attr,
229 const char *buf, size_t len) 229 const char *buf, size_t len)
230{ 230{
231 struct iio_dev *indio_dev = dev_get_drvdata(dev); 231 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
232 bool val; 232 bool val;
233 int ret; 233 int ret;
234 234
@@ -393,7 +393,7 @@ static ssize_t adis16220_accel_bin_read(struct file *filp, struct kobject *kobj,
393 size_t count) 393 size_t count)
394{ 394{
395 struct device *dev = container_of(kobj, struct device, kobj); 395 struct device *dev = container_of(kobj, struct device, kobj);
396 struct iio_dev *indio_dev = dev_get_drvdata(dev); 396 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
397 397
398 return adis16220_capture_buffer_read(indio_dev, buf, 398 return adis16220_capture_buffer_read(indio_dev, buf,
399 off, count, 399 off, count,
@@ -415,7 +415,7 @@ static ssize_t adis16220_adc1_bin_read(struct file *filp, struct kobject *kobj,
415 size_t count) 415 size_t count)
416{ 416{
417 struct device *dev = container_of(kobj, struct device, kobj); 417 struct device *dev = container_of(kobj, struct device, kobj);
418 struct iio_dev *indio_dev = dev_get_drvdata(dev); 418 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
419 419
420 return adis16220_capture_buffer_read(indio_dev, buf, 420 return adis16220_capture_buffer_read(indio_dev, buf,
421 off, count, 421 off, count,
@@ -437,7 +437,7 @@ static ssize_t adis16220_adc2_bin_read(struct file *filp, struct kobject *kobj,
437 size_t count) 437 size_t count)
438{ 438{
439 struct device *dev = container_of(kobj, struct device, kobj); 439 struct device *dev = container_of(kobj, struct device, kobj);
440 struct iio_dev *indio_dev = dev_get_drvdata(dev); 440 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
441 441
442 return adis16220_capture_buffer_read(indio_dev, buf, 442 return adis16220_capture_buffer_read(indio_dev, buf,
443 off, count, 443 off, count,
@@ -507,7 +507,7 @@ static int adis16220_read_raw(struct iio_dev *indio_dev,
507 u8 bits; 507 u8 bits;
508 508
509 switch (mask) { 509 switch (mask) {
510 case 0: 510 case IIO_CHAN_INFO_RAW:
511 addrind = 0; 511 addrind = 0;
512 break; 512 break;
513 case IIO_CHAN_INFO_OFFSET: 513 case IIO_CHAN_INFO_OFFSET:
@@ -575,11 +575,13 @@ static const struct iio_chan_spec adis16220_channels[] = {
575 .indexed = 1, 575 .indexed = 1,
576 .channel = 0, 576 .channel = 0,
577 .extend_name = "supply", 577 .extend_name = "supply",
578 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 578 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
579 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
579 .address = in_supply, 580 .address = in_supply,
580 }, { 581 }, {
581 .type = IIO_ACCEL, 582 .type = IIO_ACCEL,
582 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 583 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
584 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
583 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 585 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
584 IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 586 IIO_CHAN_INFO_PEAK_SEPARATE_BIT,
585 .address = accel, 587 .address = accel,
@@ -587,20 +589,23 @@ static const struct iio_chan_spec adis16220_channels[] = {
587 .type = IIO_TEMP, 589 .type = IIO_TEMP,
588 .indexed = 1, 590 .indexed = 1,
589 .channel = 0, 591 .channel = 0,
590 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 592 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
593 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
591 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 594 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
592 .address = temp, 595 .address = temp,
593 }, { 596 }, {
594 .type = IIO_VOLTAGE, 597 .type = IIO_VOLTAGE,
595 .indexed = 1, 598 .indexed = 1,
596 .channel = 1, 599 .channel = 1,
597 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 600 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
601 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
598 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 602 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
599 .address = in_1, 603 .address = in_1,
600 }, { 604 }, {
601 .type = IIO_VOLTAGE, 605 .type = IIO_VOLTAGE,
602 .indexed = 1, 606 .indexed = 1,
603 .channel = 2, 607 .channel = 2,
608 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
604 .address = in_2, 609 .address = in_2,
605 } 610 }
606}; 611};
@@ -629,7 +634,7 @@ static int __devinit adis16220_probe(struct spi_device *spi)
629 struct iio_dev *indio_dev; 634 struct iio_dev *indio_dev;
630 635
631 /* setup the industrialio driver allocated elements */ 636 /* setup the industrialio driver allocated elements */
632 indio_dev = iio_allocate_device(sizeof(*st)); 637 indio_dev = iio_device_alloc(sizeof(*st));
633 if (indio_dev == NULL) { 638 if (indio_dev == NULL) {
634 ret = -ENOMEM; 639 ret = -ENOMEM;
635 goto error_ret; 640 goto error_ret;
@@ -680,7 +685,7 @@ error_rm_accel_bin:
680error_unregister_dev: 685error_unregister_dev:
681 iio_device_unregister(indio_dev); 686 iio_device_unregister(indio_dev);
682error_free_dev: 687error_free_dev:
683 iio_free_device(indio_dev); 688 iio_device_free(indio_dev);
684error_ret: 689error_ret:
685 return ret; 690 return ret;
686} 691}
@@ -695,7 +700,7 @@ static int adis16220_remove(struct spi_device *spi)
695 sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin); 700 sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin);
696 sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); 701 sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin);
697 iio_device_unregister(indio_dev); 702 iio_device_unregister(indio_dev);
698 iio_free_device(indio_dev); 703 iio_device_free(indio_dev);
699 704
700 return 0; 705 return 0;
701} 706}
diff --git a/drivers/staging/iio/accel/adis16240_core.c b/drivers/staging/iio/accel/adis16240_core.c
index 17f77fef7f2b..8b15eaea3381 100644
--- a/drivers/staging/iio/accel/adis16240_core.c
+++ b/drivers/staging/iio/accel/adis16240_core.c
@@ -19,9 +19,9 @@
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22#include "../iio.h" 22#include <linux/iio/iio.h>
23#include "../sysfs.h" 23#include <linux/iio/sysfs.h>
24#include "../buffer.h" 24#include <linux/iio/buffer.h>
25 25
26#include "adis16240.h" 26#include "adis16240.h"
27 27
@@ -154,7 +154,7 @@ static ssize_t adis16240_spi_read_signed(struct device *dev,
154 char *buf, 154 char *buf,
155 unsigned bits) 155 unsigned bits)
156{ 156{
157 struct iio_dev *indio_dev = dev_get_drvdata(dev); 157 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
158 int ret; 158 int ret;
159 s16 val = 0; 159 s16 val = 0;
160 unsigned shift = 16 - bits; 160 unsigned shift = 16 - bits;
@@ -177,7 +177,7 @@ static ssize_t adis16240_read_12bit_signed(struct device *dev,
177 char *buf) 177 char *buf)
178{ 178{
179 ssize_t ret; 179 ssize_t ret;
180 struct iio_dev *indio_dev = dev_get_drvdata(dev); 180 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
181 181
182 /* Take the iio_dev status lock */ 182 /* Take the iio_dev status lock */
183 mutex_lock(&indio_dev->mlock); 183 mutex_lock(&indio_dev->mlock);
@@ -203,7 +203,7 @@ static ssize_t adis16240_write_reset(struct device *dev,
203 struct device_attribute *attr, 203 struct device_attribute *attr,
204 const char *buf, size_t len) 204 const char *buf, size_t len)
205{ 205{
206 struct iio_dev *indio_dev = dev_get_drvdata(dev); 206 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
207 207
208 if (len < 1) 208 if (len < 1)
209 return -EINVAL; 209 return -EINVAL;
@@ -365,7 +365,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev,
365 s16 val16; 365 s16 val16;
366 366
367 switch (mask) { 367 switch (mask) {
368 case 0: 368 case IIO_CHAN_INFO_RAW:
369 mutex_lock(&indio_dev->mlock); 369 mutex_lock(&indio_dev->mlock);
370 addr = adis16240_addresses[chan->address][0]; 370 addr = adis16240_addresses[chan->address][0];
371 ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); 371 ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16);
@@ -468,33 +468,88 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
468} 468}
469 469
470static struct iio_chan_spec adis16240_channels[] = { 470static struct iio_chan_spec adis16240_channels[] = {
471 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "supply", 0, 0, 471 {
472 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 472 .type = IIO_VOLTAGE,
473 in_supply, ADIS16240_SCAN_SUPPLY, 473 .indexed = 1,
474 IIO_ST('u', 10, 16, 0), 0), 474 .channel = 0,
475 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 475 .extend_name = "supply",
476 0, 476 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
477 in_aux, ADIS16240_SCAN_AUX_ADC, 477 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
478 IIO_ST('u', 10, 16, 0), 0), 478 .address = in_supply,
479 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, 479 .scan_index = ADIS16240_SCAN_SUPPLY,
480 IIO_CHAN_INFO_SCALE_SHARED_BIT | 480 .scan_type = {
481 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 481 .sign = 'u',
482 accel_x, ADIS16240_SCAN_ACC_X, 482 .realbits = 10,
483 IIO_ST('s', 10, 16, 0), 0), 483 .storagebits = 16,
484 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, 484 },
485 IIO_CHAN_INFO_SCALE_SHARED_BIT | 485 }, {
486 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 486 .type = IIO_VOLTAGE,
487 accel_y, ADIS16240_SCAN_ACC_Y, 487 .indexed = 1,
488 IIO_ST('s', 10, 16, 0), 0), 488 .channel = 1,
489 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Z, 489 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
490 IIO_CHAN_INFO_SCALE_SHARED_BIT | 490 .address = in_aux,
491 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 491 .scan_index = ADIS16240_SCAN_AUX_ADC,
492 accel_z, ADIS16240_SCAN_ACC_Z, 492 .scan_type = {
493 IIO_ST('s', 10, 16, 0), 0), 493 .sign = 'u',
494 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 494 .realbits = 10,
495 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 495 .storagebits = 16,
496 temp, ADIS16240_SCAN_TEMP, 496 },
497 IIO_ST('u', 10, 16, 0), 0), 497 }, {
498 .type = IIO_ACCEL,
499 .modified = 1,
500 .channel2 = IIO_MOD_X,
501 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
502 IIO_CHAN_INFO_SCALE_SHARED_BIT |
503 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
504 .address = accel_x,
505 .scan_index = ADIS16240_SCAN_ACC_X,
506 .scan_type = {
507 .sign = 's',
508 .realbits = 10,
509 .storagebits = 16,
510 },
511 }, {
512 .type = IIO_ACCEL,
513 .modified = 1,
514 .channel2 = IIO_MOD_Y,
515 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
516 IIO_CHAN_INFO_SCALE_SHARED_BIT |
517 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
518 .address = accel_y,
519 .scan_index = ADIS16240_SCAN_ACC_Y,
520 .scan_type = {
521 .sign = 's',
522 .realbits = 10,
523 .storagebits = 16,
524 },
525 }, {
526 .type = IIO_ACCEL,
527 .modified = 1,
528 .channel2 = IIO_MOD_Z,
529 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
530 IIO_CHAN_INFO_SCALE_SHARED_BIT |
531 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
532 .address = accel_z,
533 .scan_index = ADIS16240_SCAN_ACC_Z,
534 .scan_type = {
535 .sign = 's',
536 .realbits = 10,
537 .storagebits = 16,
538 },
539 }, {
540 .type = IIO_TEMP,
541 .indexed = 1,
542 .channel = 0,
543 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
544 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
545 .address = temp,
546 .scan_index = ADIS16240_SCAN_TEMP,
547 .scan_type = {
548 .sign = 'u',
549 .realbits = 10,
550 .storagebits = 16,
551 },
552 },
498 IIO_CHAN_SOFT_TIMESTAMP(6) 553 IIO_CHAN_SOFT_TIMESTAMP(6)
499}; 554};
500 555
@@ -523,7 +578,7 @@ static int __devinit adis16240_probe(struct spi_device *spi)
523 struct iio_dev *indio_dev; 578 struct iio_dev *indio_dev;
524 579
525 /* setup the industrialio driver allocated elements */ 580 /* setup the industrialio driver allocated elements */
526 indio_dev = iio_allocate_device(sizeof(*st)); 581 indio_dev = iio_device_alloc(sizeof(*st));
527 if (indio_dev == NULL) { 582 if (indio_dev == NULL) {
528 ret = -ENOMEM; 583 ret = -ENOMEM;
529 goto error_ret; 584 goto error_ret;
@@ -576,7 +631,7 @@ error_uninitialize_ring:
576error_unreg_ring_funcs: 631error_unreg_ring_funcs:
577 adis16240_unconfigure_ring(indio_dev); 632 adis16240_unconfigure_ring(indio_dev);
578error_free_dev: 633error_free_dev:
579 iio_free_device(indio_dev); 634 iio_device_free(indio_dev);
580error_ret: 635error_ret:
581 return ret; 636 return ret;
582} 637}
@@ -592,7 +647,7 @@ static int adis16240_remove(struct spi_device *spi)
592 adis16240_remove_trigger(indio_dev); 647 adis16240_remove_trigger(indio_dev);
593 iio_buffer_unregister(indio_dev); 648 iio_buffer_unregister(indio_dev);
594 adis16240_unconfigure_ring(indio_dev); 649 adis16240_unconfigure_ring(indio_dev);
595 iio_free_device(indio_dev); 650 iio_device_free(indio_dev);
596 651
597 return 0; 652 return 0;
598} 653}
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index 43ba84e993ad..86a2a4757ea7 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -5,20 +5,19 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16240.h" 11#include "adis16240.h"
12 12
13/** 13/**
14 * adis16240_read_ring_data() read data registers which will be placed into ring 14 * adis16240_read_ring_data() read data registers which will be placed into ring
15 * @dev: device associated with child of actual device (iio_dev or iio_trig) 15 * @indio_dev: the IIO device
16 * @rx: somewhere to pass back the value read 16 * @rx: somewhere to pass back the value read
17 **/ 17 **/
18static int adis16240_read_ring_data(struct device *dev, u8 *rx) 18static int adis16240_read_ring_data(struct iio_dev *indio_dev, u8 *rx)
19{ 19{
20 struct spi_message msg; 20 struct spi_message msg;
21 struct iio_dev *indio_dev = dev_get_drvdata(dev);
22 struct adis16240_state *st = iio_priv(indio_dev); 21 struct adis16240_state *st = iio_priv(indio_dev);
23 struct spi_transfer xfers[ADIS16240_OUTPUTS + 1]; 22 struct spi_transfer xfers[ADIS16240_OUTPUTS + 1];
24 int ret; 23 int ret;
@@ -61,22 +60,21 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
61 60
62 int i = 0; 61 int i = 0;
63 s16 *data; 62 s16 *data;
64 size_t datasize = ring->access->get_bytes_per_datum(ring);
65 63
66 data = kmalloc(datasize, GFP_KERNEL); 64 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
67 if (data == NULL) { 65 if (data == NULL) {
68 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 66 dev_err(&st->us->dev, "memory alloc failed in ring bh");
69 return -ENOMEM; 67 return -ENOMEM;
70 } 68 }
71 69
72 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && 70 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
73 adis16240_read_ring_data(&indio_dev->dev, st->rx) >= 0) 71 adis16240_read_ring_data(indio_dev, st->rx) >= 0)
74 for (; i < bitmap_weight(indio_dev->active_scan_mask, 72 for (; i < bitmap_weight(indio_dev->active_scan_mask,
75 indio_dev->masklength); i++) 73 indio_dev->masklength); i++)
76 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 74 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
77 75
78 /* Guaranteed to be aligned with 8 byte boundary */ 76 /* Guaranteed to be aligned with 8 byte boundary */
79 if (ring->scan_timestamp) 77 if (indio_dev->scan_timestamp)
80 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 78 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
81 79
82 ring->access->store_to(ring, (u8 *)data, pf->timestamp); 80 ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16240_trigger.c b/drivers/staging/iio/accel/adis16240_trigger.c
index 8e0ce568e64c..fa90a22b143e 100644
--- a/drivers/staging/iio/accel/adis16240_trigger.c
+++ b/drivers/staging/iio/accel/adis16240_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16240.h" 8#include "adis16240.h"
9 9
10/** 10/**
@@ -38,7 +38,7 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev)
38 int ret; 38 int ret;
39 struct adis16240_state *st = iio_priv(indio_dev); 39 struct adis16240_state *st = iio_priv(indio_dev);
40 40
41 st->trig = iio_allocate_trigger("adis16240-dev%d", indio_dev->id); 41 st->trig = iio_trigger_alloc("adis16240-dev%d", indio_dev->id);
42 if (st->trig == NULL) { 42 if (st->trig == NULL) {
43 ret = -ENOMEM; 43 ret = -ENOMEM;
44 goto error_ret; 44 goto error_ret;
@@ -67,7 +67,7 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev)
67error_free_irq: 67error_free_irq:
68 free_irq(st->us->irq, st->trig); 68 free_irq(st->us->irq, st->trig);
69error_free_trig: 69error_free_trig:
70 iio_free_trigger(st->trig); 70 iio_trigger_free(st->trig);
71error_ret: 71error_ret:
72 return ret; 72 return ret;
73} 73}
@@ -78,5 +78,5 @@ void adis16240_remove_trigger(struct iio_dev *indio_dev)
78 78
79 iio_trigger_unregister(st->trig); 79 iio_trigger_unregister(st->trig);
80 free_irq(st->us->irq, st->trig); 80 free_irq(st->us->irq, st->trig);
81 iio_free_trigger(st->trig); 81 iio_trigger_free(st->trig);
82} 82}
diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c
index d13d7215ff6e..8cf7cd943c90 100644
--- a/drivers/staging/iio/accel/kxsd9.c
+++ b/drivers/staging/iio/accel/kxsd9.c
@@ -23,8 +23,8 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h> 24#include <linux/module.h>
25 25
26#include "../iio.h" 26#include <linux/iio/iio.h>
27#include "../sysfs.h" 27#include <linux/iio/sysfs.h>
28 28
29#define KXSD9_REG_X 0x00 29#define KXSD9_REG_X 0x00
30#define KXSD9_REG_Y 0x02 30#define KXSD9_REG_Y 0x02
@@ -158,7 +158,7 @@ static int kxsd9_read_raw(struct iio_dev *indio_dev,
158 struct kxsd9_state *st = iio_priv(indio_dev); 158 struct kxsd9_state *st = iio_priv(indio_dev);
159 159
160 switch (mask) { 160 switch (mask) {
161 case 0: 161 case IIO_CHAN_INFO_RAW:
162 ret = kxsd9_read(indio_dev, chan->address); 162 ret = kxsd9_read(indio_dev, chan->address);
163 if (ret < 0) 163 if (ret < 0)
164 goto error_ret; 164 goto error_ret;
@@ -181,7 +181,8 @@ error_ret:
181 .type = IIO_ACCEL, \ 181 .type = IIO_ACCEL, \
182 .modified = 1, \ 182 .modified = 1, \
183 .channel2 = IIO_MOD_##axis, \ 183 .channel2 = IIO_MOD_##axis, \
184 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 184 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
185 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
185 .address = KXSD9_REG_##axis, \ 186 .address = KXSD9_REG_##axis, \
186 } 187 }
187 188
@@ -189,6 +190,7 @@ static struct iio_chan_spec kxsd9_channels[] = {
189 KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z), 190 KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z),
190 { 191 {
191 .type = IIO_VOLTAGE, 192 .type = IIO_VOLTAGE,
193 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
192 .indexed = 1, 194 .indexed = 1,
193 .address = KXSD9_REG_AUX, 195 .address = KXSD9_REG_AUX,
194 } 196 }
@@ -226,7 +228,7 @@ static int __devinit kxsd9_probe(struct spi_device *spi)
226 struct kxsd9_state *st; 228 struct kxsd9_state *st;
227 int ret = 0; 229 int ret = 0;
228 230
229 indio_dev = iio_allocate_device(sizeof(*st)); 231 indio_dev = iio_device_alloc(sizeof(*st));
230 if (indio_dev == NULL) { 232 if (indio_dev == NULL) {
231 ret = -ENOMEM; 233 ret = -ENOMEM;
232 goto error_ret; 234 goto error_ret;
@@ -254,7 +256,7 @@ static int __devinit kxsd9_probe(struct spi_device *spi)
254 return 0; 256 return 0;
255 257
256error_free_dev: 258error_free_dev:
257 iio_free_device(indio_dev); 259 iio_device_free(indio_dev);
258error_ret: 260error_ret:
259 return ret; 261 return ret;
260} 262}
@@ -262,7 +264,7 @@ error_ret:
262static int __devexit kxsd9_remove(struct spi_device *spi) 264static int __devexit kxsd9_remove(struct spi_device *spi)
263{ 265{
264 iio_device_unregister(spi_get_drvdata(spi)); 266 iio_device_unregister(spi_get_drvdata(spi));
265 iio_free_device(spi_get_drvdata(spi)); 267 iio_device_free(spi_get_drvdata(spi));
266 268
267 return 0; 269 return 0;
268} 270}
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index 376da5137967..9d263484fb86 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -23,10 +23,10 @@
23#include <linux/sysfs.h> 23#include <linux/sysfs.h>
24#include <linux/module.h> 24#include <linux/module.h>
25 25
26#include "../iio.h" 26#include <linux/iio/iio.h>
27#include "../sysfs.h" 27#include <linux/iio/sysfs.h>
28#include "../events.h" 28#include <linux/iio/events.h>
29#include "../buffer.h" 29#include <linux/iio/buffer.h>
30 30
31#include "lis3l02dq.h" 31#include "lis3l02dq.h"
32 32
@@ -257,7 +257,7 @@ static int lis3l02dq_read_raw(struct iio_dev *indio_dev,
257 u8 reg; 257 u8 reg;
258 258
259 switch (mask) { 259 switch (mask) {
260 case 0: 260 case IIO_CHAN_INFO_RAW:
261 /* Take the iio_dev status lock */ 261 /* Take the iio_dev status lock */
262 mutex_lock(&indio_dev->mlock); 262 mutex_lock(&indio_dev->mlock);
263 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 263 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
@@ -297,7 +297,7 @@ static ssize_t lis3l02dq_read_frequency(struct device *dev,
297 struct device_attribute *attr, 297 struct device_attribute *attr,
298 char *buf) 298 char *buf)
299{ 299{
300 struct iio_dev *indio_dev = dev_get_drvdata(dev); 300 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
301 int ret, len = 0; 301 int ret, len = 0;
302 s8 t; 302 s8 t;
303 ret = lis3l02dq_spi_read_reg_8(indio_dev, 303 ret = lis3l02dq_spi_read_reg_8(indio_dev,
@@ -328,7 +328,7 @@ static ssize_t lis3l02dq_write_frequency(struct device *dev,
328 const char *buf, 328 const char *buf,
329 size_t len) 329 size_t len)
330{ 330{
331 struct iio_dev *indio_dev = dev_get_drvdata(dev); 331 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
332 unsigned long val; 332 unsigned long val;
333 int ret; 333 int ret;
334 u8 t; 334 u8 t;
@@ -513,7 +513,8 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
513} 513}
514 514
515#define LIS3L02DQ_INFO_MASK \ 515#define LIS3L02DQ_INFO_MASK \
516 (IIO_CHAN_INFO_SCALE_SHARED_BIT | \ 516 (IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
517 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
517 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ 518 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
518 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT) 519 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT)
519 520
@@ -521,13 +522,26 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
521 (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \ 522 (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
522 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) 523 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
523 524
525#define LIS3L02DQ_CHAN(index, mod) \
526 { \
527 .type = IIO_ACCEL, \
528 .modified = 1, \
529 .channel2 = mod, \
530 .info_mask = LIS3L02DQ_INFO_MASK, \
531 .address = index, \
532 .scan_index = index, \
533 .scan_type = { \
534 .sign = 's', \
535 .realbits = 12, \
536 .storagebits = 16, \
537 }, \
538 .event_mask = LIS3L02DQ_EVENT_MASK, \
539 }
540
524static struct iio_chan_spec lis3l02dq_channels[] = { 541static struct iio_chan_spec lis3l02dq_channels[] = {
525 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, LIS3L02DQ_INFO_MASK, 542 LIS3L02DQ_CHAN(0, IIO_MOD_X),
526 0, 0, IIO_ST('s', 12, 16, 0), LIS3L02DQ_EVENT_MASK), 543 LIS3L02DQ_CHAN(1, IIO_MOD_Y),
527 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, LIS3L02DQ_INFO_MASK, 544 LIS3L02DQ_CHAN(2, IIO_MOD_Z),
528 1, 1, IIO_ST('s', 12, 16, 0), LIS3L02DQ_EVENT_MASK),
529 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Z, LIS3L02DQ_INFO_MASK,
530 2, 2, IIO_ST('s', 12, 16, 0), LIS3L02DQ_EVENT_MASK),
531 IIO_CHAN_SOFT_TIMESTAMP(3) 545 IIO_CHAN_SOFT_TIMESTAMP(3)
532}; 546};
533 547
@@ -666,7 +680,7 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
666 struct lis3l02dq_state *st; 680 struct lis3l02dq_state *st;
667 struct iio_dev *indio_dev; 681 struct iio_dev *indio_dev;
668 682
669 indio_dev = iio_allocate_device(sizeof *st); 683 indio_dev = iio_device_alloc(sizeof *st);
670 if (indio_dev == NULL) { 684 if (indio_dev == NULL) {
671 ret = -ENOMEM; 685 ret = -ENOMEM;
672 goto error_ret; 686 goto error_ret;
@@ -724,7 +738,7 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
724 return 0; 738 return 0;
725 739
726error_remove_trigger: 740error_remove_trigger:
727 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) 741 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)))
728 lis3l02dq_remove_trigger(indio_dev); 742 lis3l02dq_remove_trigger(indio_dev);
729error_free_interrupt: 743error_free_interrupt:
730 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) 744 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
@@ -734,7 +748,7 @@ error_uninitialize_buffer:
734error_unreg_buffer_funcs: 748error_unreg_buffer_funcs:
735 lis3l02dq_unconfigure_buffer(indio_dev); 749 lis3l02dq_unconfigure_buffer(indio_dev);
736error_free_dev: 750error_free_dev:
737 iio_free_device(indio_dev); 751 iio_device_free(indio_dev);
738error_ret: 752error_ret:
739 return ret; 753 return ret;
740} 754}
@@ -789,7 +803,7 @@ static int lis3l02dq_remove(struct spi_device *spi)
789 iio_buffer_unregister(indio_dev); 803 iio_buffer_unregister(indio_dev);
790 lis3l02dq_unconfigure_buffer(indio_dev); 804 lis3l02dq_unconfigure_buffer(indio_dev);
791 805
792 iio_free_device(indio_dev); 806 iio_device_free(indio_dev);
793err_ret: 807err_ret:
794 return ret; 808 return ret;
795} 809}
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 0fc3973f32ae..51b00dfc0465 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -6,11 +6,11 @@
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/export.h> 7#include <linux/export.h>
8 8
9#include "../iio.h" 9#include <linux/iio/iio.h>
10#include "../ring_sw.h" 10#include "../ring_sw.h"
11#include "../kfifo_buf.h" 11#include <linux/iio/kfifo_buf.h>
12#include "../trigger.h" 12#include <linux/iio/trigger.h>
13#include "../trigger_consumer.h" 13#include <linux/iio/trigger_consumer.h>
14#include "lis3l02dq.h" 14#include "lis3l02dq.h"
15 15
16/** 16/**
@@ -137,9 +137,9 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
137 struct iio_dev *indio_dev = pf->indio_dev; 137 struct iio_dev *indio_dev = pf->indio_dev;
138 struct iio_buffer *buffer = indio_dev->buffer; 138 struct iio_buffer *buffer = indio_dev->buffer;
139 int len = 0; 139 int len = 0;
140 size_t datasize = buffer->access->get_bytes_per_datum(buffer); 140 char *data;
141 char *data = kmalloc(datasize, GFP_KERNEL);
142 141
142 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
143 if (data == NULL) { 143 if (data == NULL) {
144 dev_err(indio_dev->dev.parent, 144 dev_err(indio_dev->dev.parent,
145 "memory alloc failed in buffer bh"); 145 "memory alloc failed in buffer bh");
@@ -150,7 +150,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
150 len = lis3l02dq_get_buffer_element(indio_dev, data); 150 len = lis3l02dq_get_buffer_element(indio_dev, data);
151 151
152 /* Guaranteed to be aligned with 8 byte boundary */ 152 /* Guaranteed to be aligned with 8 byte boundary */
153 if (buffer->scan_timestamp) 153 if (indio_dev->scan_timestamp)
154 *(s64 *)(((phys_addr_t)data + len 154 *(s64 *)(((phys_addr_t)data + len
155 + sizeof(s64) - 1) & ~(sizeof(s64) - 1)) 155 + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
156 = pf->timestamp; 156 = pf->timestamp;
@@ -163,12 +163,11 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
163 163
164/* Caller responsible for locking as necessary. */ 164/* Caller responsible for locking as necessary. */
165static int 165static int
166__lis3l02dq_write_data_ready_config(struct device *dev, bool state) 166__lis3l02dq_write_data_ready_config(struct iio_dev *indio_dev, bool state)
167{ 167{
168 int ret; 168 int ret;
169 u8 valold; 169 u8 valold;
170 bool currentlyset; 170 bool currentlyset;
171 struct iio_dev *indio_dev = dev_get_drvdata(dev);
172 struct lis3l02dq_state *st = iio_priv(indio_dev); 171 struct lis3l02dq_state *st = iio_priv(indio_dev);
173 172
174/* Get the current event mask register */ 173/* Get the current event mask register */
@@ -236,7 +235,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
236 int ret = 0; 235 int ret = 0;
237 u8 t; 236 u8 t;
238 237
239 __lis3l02dq_write_data_ready_config(&indio_dev->dev, state); 238 __lis3l02dq_write_data_ready_config(indio_dev, state);
240 if (state == false) { 239 if (state == false) {
241 /* 240 /*
242 * A possible quirk with the handler is currently worked around 241 * A possible quirk with the handler is currently worked around
@@ -286,7 +285,7 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
286 int ret; 285 int ret;
287 struct lis3l02dq_state *st = iio_priv(indio_dev); 286 struct lis3l02dq_state *st = iio_priv(indio_dev);
288 287
289 st->trig = iio_allocate_trigger("lis3l02dq-dev%d", indio_dev->id); 288 st->trig = iio_trigger_alloc("lis3l02dq-dev%d", indio_dev->id);
290 if (!st->trig) { 289 if (!st->trig) {
291 ret = -ENOMEM; 290 ret = -ENOMEM;
292 goto error_ret; 291 goto error_ret;
@@ -302,7 +301,7 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
302 return 0; 301 return 0;
303 302
304error_free_trig: 303error_free_trig:
305 iio_free_trigger(st->trig); 304 iio_trigger_free(st->trig);
306error_ret: 305error_ret:
307 return ret; 306 return ret;
308} 307}
@@ -312,7 +311,7 @@ void lis3l02dq_remove_trigger(struct iio_dev *indio_dev)
312 struct lis3l02dq_state *st = iio_priv(indio_dev); 311 struct lis3l02dq_state *st = iio_priv(indio_dev);
313 312
314 iio_trigger_unregister(st->trig); 313 iio_trigger_unregister(st->trig);
315 iio_free_trigger(st->trig); 314 iio_trigger_free(st->trig);
316} 315}
317 316
318void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev) 317void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev)
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index 49764fb7181c..6ec5c204ff1d 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -18,10 +18,10 @@
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/sysfs.h> 19#include <linux/sysfs.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../events.h" 23#include <linux/iio/events.h>
24#include "../buffer.h" 24#include <linux/iio/buffer.h>
25 25
26#include "sca3000.h" 26#include "sca3000.h"
27 27
@@ -241,7 +241,7 @@ error_ret:
241static int sca3000_check_status(struct device *dev) 241static int sca3000_check_status(struct device *dev)
242{ 242{
243 int ret; 243 int ret;
244 struct iio_dev *indio_dev = dev_get_drvdata(dev); 244 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
245 struct sca3000_state *st = iio_priv(indio_dev); 245 struct sca3000_state *st = iio_priv(indio_dev);
246 246
247 mutex_lock(&st->lock); 247 mutex_lock(&st->lock);
@@ -268,7 +268,7 @@ static ssize_t sca3000_show_rev(struct device *dev,
268 char *buf) 268 char *buf)
269{ 269{
270 int len = 0, ret; 270 int len = 0, ret;
271 struct iio_dev *indio_dev = dev_get_drvdata(dev); 271 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
272 struct sca3000_state *st = iio_priv(indio_dev); 272 struct sca3000_state *st = iio_priv(indio_dev);
273 273
274 mutex_lock(&st->lock); 274 mutex_lock(&st->lock);
@@ -296,7 +296,7 @@ sca3000_show_available_measurement_modes(struct device *dev,
296 struct device_attribute *attr, 296 struct device_attribute *attr,
297 char *buf) 297 char *buf)
298{ 298{
299 struct iio_dev *indio_dev = dev_get_drvdata(dev); 299 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
300 struct sca3000_state *st = iio_priv(indio_dev); 300 struct sca3000_state *st = iio_priv(indio_dev);
301 int len = 0; 301 int len = 0;
302 302
@@ -328,7 +328,7 @@ sca3000_show_measurement_mode(struct device *dev,
328 struct device_attribute *attr, 328 struct device_attribute *attr,
329 char *buf) 329 char *buf)
330{ 330{
331 struct iio_dev *indio_dev = dev_get_drvdata(dev); 331 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
332 struct sca3000_state *st = iio_priv(indio_dev); 332 struct sca3000_state *st = iio_priv(indio_dev);
333 int len = 0, ret; 333 int len = 0, ret;
334 334
@@ -379,7 +379,7 @@ sca3000_store_measurement_mode(struct device *dev,
379 const char *buf, 379 const char *buf,
380 size_t len) 380 size_t len)
381{ 381{
382 struct iio_dev *indio_dev = dev_get_drvdata(dev); 382 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
383 struct sca3000_state *st = iio_priv(indio_dev); 383 struct sca3000_state *st = iio_priv(indio_dev);
384 int ret; 384 int ret;
385 u8 mask = 0x03; 385 u8 mask = 0x03;
@@ -429,17 +429,31 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
429static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0); 429static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
430 430
431#define SCA3000_INFO_MASK \ 431#define SCA3000_INFO_MASK \
432 IIO_CHAN_INFO_SCALE_SHARED_BIT 432 IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT
433#define SCA3000_EVENT_MASK \ 433#define SCA3000_EVENT_MASK \
434 (IIO_EV_BIT(IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING)) 434 (IIO_EV_BIT(IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING))
435 435
436#define SCA3000_CHAN(index, mod) \
437 { \
438 .type = IIO_ACCEL, \
439 .modified = 1, \
440 .channel2 = mod, \
441 .info_mask = SCA3000_INFO_MASK, \
442 .address = index, \
443 .scan_index = index, \
444 .scan_type = { \
445 .sign = 's', \
446 .realbits = 11, \
447 .storagebits = 16, \
448 .shift = 5, \
449 }, \
450 .event_mask = SCA3000_EVENT_MASK, \
451 }
452
436static struct iio_chan_spec sca3000_channels[] = { 453static struct iio_chan_spec sca3000_channels[] = {
437 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X, SCA3000_INFO_MASK, 454 SCA3000_CHAN(0, IIO_MOD_X),
438 0, 0, IIO_ST('s', 11, 16, 5), SCA3000_EVENT_MASK), 455 SCA3000_CHAN(1, IIO_MOD_Y),
439 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Y, SCA3000_INFO_MASK, 456 SCA3000_CHAN(2, IIO_MOD_Z),
440 1, 1, IIO_ST('s', 11, 16, 5), SCA3000_EVENT_MASK),
441 IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_Z, SCA3000_INFO_MASK,
442 2, 2, IIO_ST('s', 11, 16, 5), SCA3000_EVENT_MASK),
443}; 457};
444 458
445static u8 sca3000_addresses[3][3] = { 459static u8 sca3000_addresses[3][3] = {
@@ -462,7 +476,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
462 u8 address; 476 u8 address;
463 477
464 switch (mask) { 478 switch (mask) {
465 case 0: 479 case IIO_CHAN_INFO_RAW:
466 mutex_lock(&st->lock); 480 mutex_lock(&st->lock);
467 if (st->mo_det_use_count) { 481 if (st->mo_det_use_count) {
468 mutex_unlock(&st->lock); 482 mutex_unlock(&st->lock);
@@ -503,7 +517,7 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
503 struct device_attribute *attr, 517 struct device_attribute *attr,
504 char *buf) 518 char *buf)
505{ 519{
506 struct iio_dev *indio_dev = dev_get_drvdata(dev); 520 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
507 struct sca3000_state *st = iio_priv(indio_dev); 521 struct sca3000_state *st = iio_priv(indio_dev);
508 int len = 0, ret, val; 522 int len = 0, ret, val;
509 523
@@ -574,7 +588,7 @@ static ssize_t sca3000_read_frequency(struct device *dev,
574 struct device_attribute *attr, 588 struct device_attribute *attr,
575 char *buf) 589 char *buf)
576{ 590{
577 struct iio_dev *indio_dev = dev_get_drvdata(dev); 591 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
578 struct sca3000_state *st = iio_priv(indio_dev); 592 struct sca3000_state *st = iio_priv(indio_dev);
579 int ret, len = 0, base_freq = 0, val; 593 int ret, len = 0, base_freq = 0, val;
580 594
@@ -616,7 +630,7 @@ static ssize_t sca3000_set_frequency(struct device *dev,
616 const char *buf, 630 const char *buf,
617 size_t len) 631 size_t len)
618{ 632{
619 struct iio_dev *indio_dev = dev_get_drvdata(dev); 633 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
620 struct sca3000_state *st = iio_priv(indio_dev); 634 struct sca3000_state *st = iio_priv(indio_dev);
621 int ret, base_freq = 0; 635 int ret, base_freq = 0;
622 int ctrlval; 636 int ctrlval;
@@ -676,7 +690,7 @@ static ssize_t sca3000_read_temp(struct device *dev,
676 struct device_attribute *attr, 690 struct device_attribute *attr,
677 char *buf) 691 char *buf)
678{ 692{
679 struct iio_dev *indio_dev = dev_get_drvdata(dev); 693 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
680 struct sca3000_state *st = iio_priv(indio_dev); 694 struct sca3000_state *st = iio_priv(indio_dev);
681 int ret; 695 int ret;
682 int val; 696 int val;
@@ -897,7 +911,7 @@ static ssize_t sca3000_query_free_fall_mode(struct device *dev,
897 char *buf) 911 char *buf)
898{ 912{
899 int ret, len; 913 int ret, len;
900 struct iio_dev *indio_dev = dev_get_drvdata(dev); 914 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
901 struct sca3000_state *st = iio_priv(indio_dev); 915 struct sca3000_state *st = iio_priv(indio_dev);
902 int val; 916 int val;
903 917
@@ -925,7 +939,7 @@ static ssize_t sca3000_set_free_fall_mode(struct device *dev,
925 const char *buf, 939 const char *buf,
926 size_t len) 940 size_t len)
927{ 941{
928 struct iio_dev *indio_dev = dev_get_drvdata(dev); 942 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
929 struct sca3000_state *st = iio_priv(indio_dev); 943 struct sca3000_state *st = iio_priv(indio_dev);
930 long val; 944 long val;
931 int ret; 945 int ret;
@@ -1131,7 +1145,7 @@ static int __devinit sca3000_probe(struct spi_device *spi)
1131 struct sca3000_state *st; 1145 struct sca3000_state *st;
1132 struct iio_dev *indio_dev; 1146 struct iio_dev *indio_dev;
1133 1147
1134 indio_dev = iio_allocate_device(sizeof(*st)); 1148 indio_dev = iio_device_alloc(sizeof(*st));
1135 if (indio_dev == NULL) { 1149 if (indio_dev == NULL) {
1136 ret = -ENOMEM; 1150 ret = -ENOMEM;
1137 goto error_ret; 1151 goto error_ret;
@@ -1195,7 +1209,7 @@ error_unregister_ring:
1195error_unregister_dev: 1209error_unregister_dev:
1196 iio_device_unregister(indio_dev); 1210 iio_device_unregister(indio_dev);
1197error_free_dev: 1211error_free_dev:
1198 iio_free_device(indio_dev); 1212 iio_device_free(indio_dev);
1199 1213
1200error_ret: 1214error_ret:
1201 return ret; 1215 return ret;
@@ -1233,7 +1247,7 @@ static int sca3000_remove(struct spi_device *spi)
1233 iio_device_unregister(indio_dev); 1247 iio_device_unregister(indio_dev);
1234 iio_buffer_unregister(indio_dev); 1248 iio_buffer_unregister(indio_dev);
1235 sca3000_unconfigure_ring(indio_dev); 1249 sca3000_unconfigure_ring(indio_dev);
1236 iio_free_device(indio_dev); 1250 iio_device_free(indio_dev);
1237 1251
1238 return 0; 1252 return 0;
1239} 1253}
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
index 6b824a11f7f4..b7e1a002630a 100644
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ b/drivers/staging/iio/accel/sca3000_ring.c
@@ -18,9 +18,9 @@
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/poll.h> 19#include <linux/poll.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24#include "../ring_hw.h" 24#include "../ring_hw.h"
25#include "sca3000.h" 25#include "sca3000.h"
26 26
@@ -157,7 +157,7 @@ static ssize_t sca3000_query_ring_int(struct device *dev,
157{ 157{
158 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 158 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
159 int ret, val; 159 int ret, val;
160 struct iio_dev *indio_dev = dev_get_drvdata(dev); 160 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
161 struct sca3000_state *st = iio_priv(indio_dev); 161 struct sca3000_state *st = iio_priv(indio_dev);
162 162
163 mutex_lock(&st->lock); 163 mutex_lock(&st->lock);
@@ -178,7 +178,7 @@ static ssize_t sca3000_set_ring_int(struct device *dev,
178 const char *buf, 178 const char *buf,
179 size_t len) 179 size_t len)
180{ 180{
181 struct iio_dev *indio_dev = dev_get_drvdata(dev); 181 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
182 struct sca3000_state *st = iio_priv(indio_dev); 182 struct sca3000_state *st = iio_priv(indio_dev);
183 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 183 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
184 long val; 184 long val;
@@ -219,7 +219,7 @@ static ssize_t sca3000_show_buffer_scale(struct device *dev,
219 struct device_attribute *attr, 219 struct device_attribute *attr,
220 char *buf) 220 char *buf)
221{ 221{
222 struct iio_dev *indio_dev = dev_get_drvdata(dev); 222 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
223 struct sca3000_state *st = iio_priv(indio_dev); 223 struct sca3000_state *st = iio_priv(indio_dev);
224 224
225 return sprintf(buf, "0.%06d\n", 4*st->info->scale); 225 return sprintf(buf, "0.%06d\n", 4*st->info->scale);
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 592eabd85f36..2490dd25093b 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -25,7 +25,7 @@ config AD7606
25 depends on GPIOLIB 25 depends on GPIOLIB
26 select IIO_BUFFER 26 select IIO_BUFFER
27 select IIO_TRIGGER 27 select IIO_TRIGGER
28 select IIO_SW_RING 28 select IIO_KFIFO_BUF
29 help 29 help
30 Say yes here to build support for Analog Devices: 30 Say yes here to build support for Analog Devices:
31 ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). 31 ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
@@ -63,7 +63,7 @@ config AD799X_RING_BUFFER
63 bool "Analog Devices AD799x: use ring buffer" 63 bool "Analog Devices AD799x: use ring buffer"
64 depends on AD799X 64 depends on AD799X
65 select IIO_BUFFER 65 select IIO_BUFFER
66 select IIO_SW_RING 66 select IIO_KFIFO_BUF
67 help 67 help
68 Say yes here to include ring buffer support in the AD799X 68 Say yes here to include ring buffer support in the AD799X
69 ADC driver. 69 ADC driver.
@@ -72,7 +72,7 @@ config AD7476
72 tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver" 72 tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver"
73 depends on SPI 73 depends on SPI
74 select IIO_BUFFER 74 select IIO_BUFFER
75 select IIO_SW_RING 75 select IIO_KFIFO_BUF
76 select IIO_TRIGGER 76 select IIO_TRIGGER
77 help 77 help
78 Say yes here to build support for Analog Devices 78 Say yes here to build support for Analog Devices
@@ -87,7 +87,7 @@ config AD7887
87 tristate "Analog Devices AD7887 ADC driver" 87 tristate "Analog Devices AD7887 ADC driver"
88 depends on SPI 88 depends on SPI
89 select IIO_BUFFER 89 select IIO_BUFFER
90 select IIO_SW_RING 90 select IIO_KFIFO_BUF
91 select IIO_TRIGGER 91 select IIO_TRIGGER
92 help 92 help
93 Say yes here to build support for Analog Devices 93 Say yes here to build support for Analog Devices
@@ -113,7 +113,7 @@ config AD7793
113 tristate "Analog Devices AD7792 AD7793 ADC driver" 113 tristate "Analog Devices AD7792 AD7793 ADC driver"
114 depends on SPI 114 depends on SPI
115 select IIO_BUFFER 115 select IIO_BUFFER
116 select IIO_SW_RING 116 select IIO_KFIFO_BUF
117 select IIO_TRIGGER 117 select IIO_TRIGGER
118 help 118 help
119 Say yes here to build support for Analog Devices 119 Say yes here to build support for Analog Devices
@@ -135,7 +135,7 @@ config AD7192
135 tristate "Analog Devices AD7190 AD7192 AD7195 ADC driver" 135 tristate "Analog Devices AD7190 AD7192 AD7195 ADC driver"
136 depends on SPI 136 depends on SPI
137 select IIO_BUFFER 137 select IIO_BUFFER
138 select IIO_SW_RING 138 select IIO_KFIFO_BUF
139 select IIO_TRIGGER 139 select IIO_TRIGGER
140 help 140 help
141 Say yes here to build support for Analog Devices AD7190, 141 Say yes here to build support for Analog Devices AD7190,
@@ -195,11 +195,20 @@ config MAX1363_RING_BUFFER
195 195
196config LPC32XX_ADC 196config LPC32XX_ADC
197 tristate "NXP LPC32XX ADC" 197 tristate "NXP LPC32XX ADC"
198 depends on ARCH_LPC32XX && !TOUCHSCREEN_LPC32XX 198 depends on ARCH_LPC32XX
199 help 199 help
200 Say yes here to build support for the integrated ADC inside the 200 Say yes here to build support for the integrated ADC inside the
201 LPC32XX SoC. Note that this feature uses the same hardware as the 201 LPC32XX SoC. Note that this feature uses the same hardware as the
202 touchscreen driver, so you can only select one of the two drivers 202 touchscreen driver, so you should either select only one of the two
203 (lpc32xx_adc or lpc32xx_ts). Provides direct access via sysfs. 203 drivers (lpc32xx_adc or lpc32xx_ts) or, in the OpenFirmware case,
204 activate only one via device tree selection. Provides direct access
205 via sysfs.
206
207config SPEAR_ADC
208 tristate "ST SPEAr ADC"
209 depends on PLAT_SPEAR
210 help
211 Say yes here to build support for the integrated ADC inside the
212 ST SPEAr SoC. Provides direct access via sysfs.
204 213
205endmenu 214endmenu
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index f83ab9551d8e..14e98b62b70a 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -38,3 +38,4 @@ obj-$(CONFIG_ADT7310) += adt7310.o
38obj-$(CONFIG_ADT7410) += adt7410.o 38obj-$(CONFIG_ADT7410) += adt7410.o
39obj-$(CONFIG_AD7280) += ad7280a.o 39obj-$(CONFIG_AD7280) += ad7280a.o
40obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 40obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
41obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 9fd6d63d2999..5eaeaf1f0ae8 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AD7190 AD7192 AD7195 SPI ADC driver 2 * AD7190 AD7192 AD7195 SPI ADC driver
3 * 3 *
4 * Copyright 2011 Analog Devices Inc. 4 * Copyright 2011-2012 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2. 6 * Licensed under the GPL-2.
7 */ 7 */
@@ -17,12 +17,12 @@
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19 19
20#include "../iio.h" 20#include <linux/iio/iio.h>
21#include "../sysfs.h" 21#include <linux/iio/sysfs.h>
22#include "../buffer.h" 22#include <linux/iio/buffer.h>
23#include "../ring_sw.h" 23#include <linux/iio/kfifo_buf.h>
24#include "../trigger.h" 24#include <linux/iio/trigger.h>
25#include "../trigger_consumer.h" 25#include <linux/iio/trigger_consumer.h>
26 26
27#include "ad7192.h" 27#include "ad7192.h"
28 28
@@ -456,31 +456,19 @@ out:
456static int ad7192_ring_preenable(struct iio_dev *indio_dev) 456static int ad7192_ring_preenable(struct iio_dev *indio_dev)
457{ 457{
458 struct ad7192_state *st = iio_priv(indio_dev); 458 struct ad7192_state *st = iio_priv(indio_dev);
459 struct iio_buffer *ring = indio_dev->buffer;
460 size_t d_size;
461 unsigned channel; 459 unsigned channel;
460 int ret;
462 461
463 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 462 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
464 return -EINVAL; 463 return -EINVAL;
465 464
465 ret = iio_sw_buffer_preenable(indio_dev);
466 if (ret < 0)
467 return ret;
468
466 channel = find_first_bit(indio_dev->active_scan_mask, 469 channel = find_first_bit(indio_dev->active_scan_mask,
467 indio_dev->masklength); 470 indio_dev->masklength);
468 471
469 d_size = bitmap_weight(indio_dev->active_scan_mask,
470 indio_dev->masklength) *
471 indio_dev->channels[0].scan_type.storagebits / 8;
472
473 if (ring->scan_timestamp) {
474 d_size += sizeof(s64);
475
476 if (d_size % sizeof(s64))
477 d_size += sizeof(s64) - (d_size % sizeof(s64));
478 }
479
480 if (indio_dev->buffer->access->set_bytes_per_datum)
481 indio_dev->buffer->access->
482 set_bytes_per_datum(indio_dev->buffer, d_size);
483
484 st->mode = (st->mode & ~AD7192_MODE_SEL(-1)) | 472 st->mode = (st->mode & ~AD7192_MODE_SEL(-1)) |
485 AD7192_MODE_SEL(AD7192_MODE_CONT); 473 AD7192_MODE_SEL(AD7192_MODE_CONT);
486 st->conf = (st->conf & ~AD7192_CONF_CHAN(-1)) | 474 st->conf = (st->conf & ~AD7192_CONF_CHAN(-1)) |
@@ -533,7 +521,7 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p)
533 indio_dev->channels[0].scan_type.realbits/8); 521 indio_dev->channels[0].scan_type.realbits/8);
534 522
535 /* Guaranteed to be aligned with 8 byte boundary */ 523 /* Guaranteed to be aligned with 8 byte boundary */
536 if (ring->scan_timestamp) 524 if (indio_dev->scan_timestamp)
537 dat64[1] = pf->timestamp; 525 dat64[1] = pf->timestamp;
538 526
539 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp); 527 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
@@ -556,7 +544,7 @@ static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
556{ 544{
557 int ret; 545 int ret;
558 546
559 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 547 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
560 if (!indio_dev->buffer) { 548 if (!indio_dev->buffer) {
561 ret = -ENOMEM; 549 ret = -ENOMEM;
562 goto error_ret; 550 goto error_ret;
@@ -569,7 +557,7 @@ static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
569 indio_dev->id); 557 indio_dev->id);
570 if (indio_dev->pollfunc == NULL) { 558 if (indio_dev->pollfunc == NULL) {
571 ret = -ENOMEM; 559 ret = -ENOMEM;
572 goto error_deallocate_sw_rb; 560 goto error_deallocate_kfifo;
573 } 561 }
574 562
575 /* Ring buffer functions - here trigger setup related */ 563 /* Ring buffer functions - here trigger setup related */
@@ -579,8 +567,8 @@ static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
579 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 567 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
580 return 0; 568 return 0;
581 569
582error_deallocate_sw_rb: 570error_deallocate_kfifo:
583 iio_sw_rb_free(indio_dev->buffer); 571 iio_kfifo_free(indio_dev->buffer);
584error_ret: 572error_ret:
585 return ret; 573 return ret;
586} 574}
@@ -588,7 +576,7 @@ error_ret:
588static void ad7192_ring_cleanup(struct iio_dev *indio_dev) 576static void ad7192_ring_cleanup(struct iio_dev *indio_dev)
589{ 577{
590 iio_dealloc_pollfunc(indio_dev->pollfunc); 578 iio_dealloc_pollfunc(indio_dev->pollfunc);
591 iio_sw_rb_free(indio_dev->buffer); 579 iio_kfifo_free(indio_dev->buffer);
592} 580}
593 581
594/** 582/**
@@ -616,7 +604,7 @@ static int ad7192_probe_trigger(struct iio_dev *indio_dev)
616 struct ad7192_state *st = iio_priv(indio_dev); 604 struct ad7192_state *st = iio_priv(indio_dev);
617 int ret; 605 int ret;
618 606
619 st->trig = iio_allocate_trigger("%s-dev%d", 607 st->trig = iio_trigger_alloc("%s-dev%d",
620 spi_get_device_id(st->spi)->name, 608 spi_get_device_id(st->spi)->name,
621 indio_dev->id); 609 indio_dev->id);
622 if (st->trig == NULL) { 610 if (st->trig == NULL) {
@@ -649,7 +637,7 @@ static int ad7192_probe_trigger(struct iio_dev *indio_dev)
649error_free_irq: 637error_free_irq:
650 free_irq(st->spi->irq, indio_dev); 638 free_irq(st->spi->irq, indio_dev);
651error_free_trig: 639error_free_trig:
652 iio_free_trigger(st->trig); 640 iio_trigger_free(st->trig);
653error_ret: 641error_ret:
654 return ret; 642 return ret;
655} 643}
@@ -660,14 +648,14 @@ static void ad7192_remove_trigger(struct iio_dev *indio_dev)
660 648
661 iio_trigger_unregister(st->trig); 649 iio_trigger_unregister(st->trig);
662 free_irq(st->spi->irq, indio_dev); 650 free_irq(st->spi->irq, indio_dev);
663 iio_free_trigger(st->trig); 651 iio_trigger_free(st->trig);
664} 652}
665 653
666static ssize_t ad7192_read_frequency(struct device *dev, 654static ssize_t ad7192_read_frequency(struct device *dev,
667 struct device_attribute *attr, 655 struct device_attribute *attr,
668 char *buf) 656 char *buf)
669{ 657{
670 struct iio_dev *indio_dev = dev_get_drvdata(dev); 658 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
671 struct ad7192_state *st = iio_priv(indio_dev); 659 struct ad7192_state *st = iio_priv(indio_dev);
672 660
673 return sprintf(buf, "%d\n", st->mclk / 661 return sprintf(buf, "%d\n", st->mclk /
@@ -679,7 +667,7 @@ static ssize_t ad7192_write_frequency(struct device *dev,
679 const char *buf, 667 const char *buf,
680 size_t len) 668 size_t len)
681{ 669{
682 struct iio_dev *indio_dev = dev_get_drvdata(dev); 670 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
683 struct ad7192_state *st = iio_priv(indio_dev); 671 struct ad7192_state *st = iio_priv(indio_dev);
684 unsigned long lval; 672 unsigned long lval;
685 int div, ret; 673 int div, ret;
@@ -718,7 +706,7 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
718static ssize_t ad7192_show_scale_available(struct device *dev, 706static ssize_t ad7192_show_scale_available(struct device *dev,
719 struct device_attribute *attr, char *buf) 707 struct device_attribute *attr, char *buf)
720{ 708{
721 struct iio_dev *indio_dev = dev_get_drvdata(dev); 709 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
722 struct ad7192_state *st = iio_priv(indio_dev); 710 struct ad7192_state *st = iio_priv(indio_dev);
723 int i, len = 0; 711 int i, len = 0;
724 712
@@ -742,7 +730,7 @@ static ssize_t ad7192_show_ac_excitation(struct device *dev,
742 struct device_attribute *attr, 730 struct device_attribute *attr,
743 char *buf) 731 char *buf)
744{ 732{
745 struct iio_dev *indio_dev = dev_get_drvdata(dev); 733 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
746 struct ad7192_state *st = iio_priv(indio_dev); 734 struct ad7192_state *st = iio_priv(indio_dev);
747 735
748 return sprintf(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX)); 736 return sprintf(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX));
@@ -752,7 +740,7 @@ static ssize_t ad7192_show_bridge_switch(struct device *dev,
752 struct device_attribute *attr, 740 struct device_attribute *attr,
753 char *buf) 741 char *buf)
754{ 742{
755 struct iio_dev *indio_dev = dev_get_drvdata(dev); 743 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
756 struct ad7192_state *st = iio_priv(indio_dev); 744 struct ad7192_state *st = iio_priv(indio_dev);
757 745
758 return sprintf(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW)); 746 return sprintf(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW));
@@ -763,7 +751,7 @@ static ssize_t ad7192_set(struct device *dev,
763 const char *buf, 751 const char *buf,
764 size_t len) 752 size_t len)
765{ 753{
766 struct iio_dev *indio_dev = dev_get_drvdata(dev); 754 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
767 struct ad7192_state *st = iio_priv(indio_dev); 755 struct ad7192_state *st = iio_priv(indio_dev);
768 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 756 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
769 int ret; 757 int ret;
@@ -849,7 +837,7 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
849 bool unipolar = !!(st->conf & AD7192_CONF_UNIPOLAR); 837 bool unipolar = !!(st->conf & AD7192_CONF_UNIPOLAR);
850 838
851 switch (m) { 839 switch (m) {
852 case 0: 840 case IIO_CHAN_INFO_RAW:
853 mutex_lock(&indio_dev->mlock); 841 mutex_lock(&indio_dev->mlock);
854 if (iio_buffer_enabled(indio_dev)) 842 if (iio_buffer_enabled(indio_dev))
855 ret = -EBUSY; 843 ret = -EBUSY;
@@ -981,7 +969,8 @@ static const struct iio_info ad7195_info = {
981 .extend_name = _name, \ 969 .extend_name = _name, \
982 .channel = _chan, \ 970 .channel = _chan, \
983 .channel2 = _chan2, \ 971 .channel2 = _chan2, \
984 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 972 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
973 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
985 .address = _address, \ 974 .address = _address, \
986 .scan_index = _si, \ 975 .scan_index = _si, \
987 .scan_type = IIO_ST('s', 24, 32, 0)} 976 .scan_type = IIO_ST('s', 24, 32, 0)}
@@ -990,7 +979,8 @@ static const struct iio_info ad7195_info = {
990 { .type = IIO_VOLTAGE, \ 979 { .type = IIO_VOLTAGE, \
991 .indexed = 1, \ 980 .indexed = 1, \
992 .channel = _chan, \ 981 .channel = _chan, \
993 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 982 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
983 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
994 .address = _address, \ 984 .address = _address, \
995 .scan_index = _si, \ 985 .scan_index = _si, \
996 .scan_type = IIO_ST('s', 24, 32, 0)} 986 .scan_type = IIO_ST('s', 24, 32, 0)}
@@ -999,7 +989,8 @@ static const struct iio_info ad7195_info = {
999 { .type = IIO_TEMP, \ 989 { .type = IIO_TEMP, \
1000 .indexed = 1, \ 990 .indexed = 1, \
1001 .channel = _chan, \ 991 .channel = _chan, \
1002 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 992 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
993 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
1003 .address = _address, \ 994 .address = _address, \
1004 .scan_index = _si, \ 995 .scan_index = _si, \
1005 .scan_type = IIO_ST('s', 24, 32, 0)} 996 .scan_type = IIO_ST('s', 24, 32, 0)}
@@ -1033,7 +1024,7 @@ static int __devinit ad7192_probe(struct spi_device *spi)
1033 return -ENODEV; 1024 return -ENODEV;
1034 } 1025 }
1035 1026
1036 indio_dev = iio_allocate_device(sizeof(*st)); 1027 indio_dev = iio_device_alloc(sizeof(*st));
1037 if (indio_dev == NULL) 1028 if (indio_dev == NULL)
1038 return -ENOMEM; 1029 return -ENOMEM;
1039 1030
@@ -1114,7 +1105,7 @@ error_put_reg:
1114 if (!IS_ERR(st->reg)) 1105 if (!IS_ERR(st->reg))
1115 regulator_put(st->reg); 1106 regulator_put(st->reg);
1116 1107
1117 iio_free_device(indio_dev); 1108 iio_device_free(indio_dev);
1118 1109
1119 return ret; 1110 return ret;
1120} 1111}
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index 7dbd6812c240..cfc39a703126 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -16,9 +16,9 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../events.h" 21#include <linux/iio/events.h>
22 22
23#include "ad7280a.h" 23#include "ad7280a.h"
24 24
@@ -384,7 +384,7 @@ static ssize_t ad7280_show_balance_sw(struct device *dev,
384 struct device_attribute *attr, 384 struct device_attribute *attr,
385 char *buf) 385 char *buf)
386{ 386{
387 struct iio_dev *indio_dev = dev_get_drvdata(dev); 387 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
388 struct ad7280_state *st = iio_priv(indio_dev); 388 struct ad7280_state *st = iio_priv(indio_dev);
389 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 389 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
390 390
@@ -398,7 +398,7 @@ static ssize_t ad7280_store_balance_sw(struct device *dev,
398 const char *buf, 398 const char *buf,
399 size_t len) 399 size_t len)
400{ 400{
401 struct iio_dev *indio_dev = dev_get_drvdata(dev); 401 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
402 struct ad7280_state *st = iio_priv(indio_dev); 402 struct ad7280_state *st = iio_priv(indio_dev);
403 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 403 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
404 bool readin; 404 bool readin;
@@ -429,7 +429,7 @@ static ssize_t ad7280_show_balance_timer(struct device *dev,
429 struct device_attribute *attr, 429 struct device_attribute *attr,
430 char *buf) 430 char *buf)
431{ 431{
432 struct iio_dev *indio_dev = dev_get_drvdata(dev); 432 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
433 struct ad7280_state *st = iio_priv(indio_dev); 433 struct ad7280_state *st = iio_priv(indio_dev);
434 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 434 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
435 int ret; 435 int ret;
@@ -453,7 +453,7 @@ static ssize_t ad7280_store_balance_timer(struct device *dev,
453 const char *buf, 453 const char *buf,
454 size_t len) 454 size_t len)
455{ 455{
456 struct iio_dev *indio_dev = dev_get_drvdata(dev); 456 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
457 struct ad7280_state *st = iio_priv(indio_dev); 457 struct ad7280_state *st = iio_priv(indio_dev);
458 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 458 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
459 unsigned long val; 459 unsigned long val;
@@ -508,6 +508,7 @@ static int ad7280_channel_init(struct ad7280_state *st)
508 } 508 }
509 st->channels[cnt].indexed = 1; 509 st->channels[cnt].indexed = 1;
510 st->channels[cnt].info_mask = 510 st->channels[cnt].info_mask =
511 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
511 IIO_CHAN_INFO_SCALE_SHARED_BIT; 512 IIO_CHAN_INFO_SCALE_SHARED_BIT;
512 st->channels[cnt].address = 513 st->channels[cnt].address =
513 AD7280A_DEVADDR(dev) << 8 | ch; 514 AD7280A_DEVADDR(dev) << 8 | ch;
@@ -524,7 +525,9 @@ static int ad7280_channel_init(struct ad7280_state *st)
524 st->channels[cnt].channel2 = dev * 6; 525 st->channels[cnt].channel2 = dev * 6;
525 st->channels[cnt].address = AD7280A_ALL_CELLS; 526 st->channels[cnt].address = AD7280A_ALL_CELLS;
526 st->channels[cnt].indexed = 1; 527 st->channels[cnt].indexed = 1;
527 st->channels[cnt].info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT; 528 st->channels[cnt].info_mask =
529 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
530 IIO_CHAN_INFO_SCALE_SHARED_BIT;
528 st->channels[cnt].scan_index = cnt; 531 st->channels[cnt].scan_index = cnt;
529 st->channels[cnt].scan_type.sign = 'u'; 532 st->channels[cnt].scan_type.sign = 'u';
530 st->channels[cnt].scan_type.realbits = 32; 533 st->channels[cnt].scan_type.realbits = 32;
@@ -596,7 +599,7 @@ static ssize_t ad7280_read_channel_config(struct device *dev,
596 struct device_attribute *attr, 599 struct device_attribute *attr,
597 char *buf) 600 char *buf)
598{ 601{
599 struct iio_dev *indio_dev = dev_get_drvdata(dev); 602 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
600 struct ad7280_state *st = iio_priv(indio_dev); 603 struct ad7280_state *st = iio_priv(indio_dev);
601 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 604 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
602 unsigned val; 605 unsigned val;
@@ -626,7 +629,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev,
626 const char *buf, 629 const char *buf,
627 size_t len) 630 size_t len)
628{ 631{
629 struct iio_dev *indio_dev = dev_get_drvdata(dev); 632 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
630 struct ad7280_state *st = iio_priv(indio_dev); 633 struct ad7280_state *st = iio_priv(indio_dev);
631 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 634 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
632 635
@@ -788,7 +791,7 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
788 int ret; 791 int ret;
789 792
790 switch (m) { 793 switch (m) {
791 case 0: 794 case IIO_CHAN_INFO_RAW:
792 mutex_lock(&indio_dev->mlock); 795 mutex_lock(&indio_dev->mlock);
793 if (chan->address == AD7280A_ALL_CELLS) 796 if (chan->address == AD7280A_ALL_CELLS)
794 ret = ad7280_read_all_channels(st, st->scan_cnt, NULL); 797 ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
@@ -836,7 +839,7 @@ static int __devinit ad7280_probe(struct spi_device *spi)
836 int ret; 839 int ret;
837 const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890}; 840 const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890};
838 const unsigned short nAVG[4] = {1, 2, 4, 8}; 841 const unsigned short nAVG[4] = {1, 2, 4, 8};
839 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 842 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
840 843
841 if (indio_dev == NULL) 844 if (indio_dev == NULL)
842 return -ENOMEM; 845 return -ENOMEM;
@@ -942,7 +945,7 @@ error_free_channels:
942 kfree(st->channels); 945 kfree(st->channels);
943 946
944error_free_device: 947error_free_device:
945 iio_free_device(indio_dev); 948 iio_device_free(indio_dev);
946 949
947 return ret; 950 return ret;
948} 951}
@@ -961,7 +964,7 @@ static int __devexit ad7280_remove(struct spi_device *spi)
961 964
962 kfree(st->channels); 965 kfree(st->channels);
963 kfree(st->iio_attr); 966 kfree(st->iio_attr);
964 iio_free_device(indio_dev); 967 iio_device_free(indio_dev);
965 968
966 return 0; 969 return 0;
967} 970}
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 81d6b6128cb0..029b39c0ba60 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -17,9 +17,9 @@
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/err.h> 18#include <linux/err.h>
19 19
20#include "../iio.h" 20#include <linux/iio/iio.h>
21#include "../sysfs.h" 21#include <linux/iio/sysfs.h>
22#include "../events.h" 22#include <linux/iio/events.h>
23 23
24/* 24/*
25 * Simplified handling 25 * Simplified handling
@@ -132,7 +132,7 @@ static ssize_t ad7291_store_reset(struct device *dev,
132 const char *buf, 132 const char *buf,
133 size_t len) 133 size_t len)
134{ 134{
135 struct iio_dev *indio_dev = dev_get_drvdata(dev); 135 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
136 struct ad7291_chip_info *chip = iio_priv(indio_dev); 136 struct ad7291_chip_info *chip = iio_priv(indio_dev);
137 137
138 return ad7291_i2c_write(chip, AD7291_COMMAND, 138 return ad7291_i2c_write(chip, AD7291_COMMAND,
@@ -214,7 +214,7 @@ static inline ssize_t ad7291_show_hyst(struct device *dev,
214 struct device_attribute *attr, 214 struct device_attribute *attr,
215 char *buf) 215 char *buf)
216{ 216{
217 struct iio_dev *indio_dev = dev_get_drvdata(dev); 217 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
218 struct ad7291_chip_info *chip = iio_priv(indio_dev); 218 struct ad7291_chip_info *chip = iio_priv(indio_dev);
219 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 219 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
220 u16 data; 220 u16 data;
@@ -232,7 +232,7 @@ static inline ssize_t ad7291_set_hyst(struct device *dev,
232 const char *buf, 232 const char *buf,
233 size_t len) 233 size_t len)
234{ 234{
235 struct iio_dev *indio_dev = dev_get_drvdata(dev); 235 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
236 struct ad7291_chip_info *chip = iio_priv(indio_dev); 236 struct ad7291_chip_info *chip = iio_priv(indio_dev);
237 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 237 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
238 u16 data; 238 u16 data;
@@ -461,7 +461,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
461 s16 signval; 461 s16 signval;
462 462
463 switch (mask) { 463 switch (mask) {
464 case 0: 464 case IIO_CHAN_INFO_RAW:
465 switch (chan->type) { 465 switch (chan->type) {
466 case IIO_VOLTAGE: 466 case IIO_VOLTAGE:
467 mutex_lock(&chip->state_lock); 467 mutex_lock(&chip->state_lock);
@@ -536,7 +536,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
536#define AD7291_VOLTAGE_CHAN(_chan) \ 536#define AD7291_VOLTAGE_CHAN(_chan) \
537{ \ 537{ \
538 .type = IIO_VOLTAGE, \ 538 .type = IIO_VOLTAGE, \
539 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 539 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
540 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
540 .indexed = 1, \ 541 .indexed = 1, \
541 .channel = _chan, \ 542 .channel = _chan, \
542 .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\ 543 .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
@@ -554,7 +555,8 @@ static const struct iio_chan_spec ad7291_channels[] = {
554 AD7291_VOLTAGE_CHAN(7), 555 AD7291_VOLTAGE_CHAN(7),
555 { 556 {
556 .type = IIO_TEMP, 557 .type = IIO_TEMP,
557 .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT | 558 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
559 IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT |
558 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 560 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
559 .indexed = 1, 561 .indexed = 1,
560 .channel = 0, 562 .channel = 0,
@@ -585,7 +587,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
585 struct iio_dev *indio_dev; 587 struct iio_dev *indio_dev;
586 int ret = 0, voltage_uv = 0; 588 int ret = 0, voltage_uv = 0;
587 589
588 indio_dev = iio_allocate_device(sizeof(*chip)); 590 indio_dev = iio_device_alloc(sizeof(*chip));
589 if (indio_dev == NULL) { 591 if (indio_dev == NULL) {
590 ret = -ENOMEM; 592 ret = -ENOMEM;
591 goto error_ret; 593 goto error_ret;
@@ -667,7 +669,7 @@ error_put_reg:
667 if (!IS_ERR(chip->reg)) 669 if (!IS_ERR(chip->reg))
668 regulator_put(chip->reg); 670 regulator_put(chip->reg);
669 671
670 iio_free_device(indio_dev); 672 iio_device_free(indio_dev);
671error_ret: 673error_ret:
672 return ret; 674 return ret;
673} 675}
@@ -687,7 +689,7 @@ static int __devexit ad7291_remove(struct i2c_client *client)
687 regulator_put(chip->reg); 689 regulator_put(chip->reg);
688 } 690 }
689 691
690 iio_free_device(indio_dev); 692 iio_device_free(indio_dev);
691 693
692 return 0; 694 return 0;
693} 695}
diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
index a0e5dea415ef..5051a7e4d4fd 100644
--- a/drivers/staging/iio/adc/ad7298.h
+++ b/drivers/staging/iio/adc/ad7298.h
@@ -38,7 +38,6 @@ struct ad7298_platform_data {
38struct ad7298_state { 38struct ad7298_state {
39 struct spi_device *spi; 39 struct spi_device *spi;
40 struct regulator *reg; 40 struct regulator *reg;
41 size_t d_size;
42 u16 int_vref_mv; 41 u16 int_vref_mv;
43 unsigned ext_ref; 42 unsigned ext_ref;
44 struct spi_transfer ring_xfer[10]; 43 struct spi_transfer ring_xfer[10];
diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c
index 8dd6aa9cf928..c90f2b3e661f 100644
--- a/drivers/staging/iio/adc/ad7298_core.c
+++ b/drivers/staging/iio/adc/ad7298_core.c
@@ -16,40 +16,51 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../buffer.h" 21#include <linux/iio/buffer.h>
22 22
23#include "ad7298.h" 23#include "ad7298.h"
24 24
25#define AD7298_V_CHAN(index) \
26 { \
27 .type = IIO_VOLTAGE, \
28 .indexed = 1, \
29 .channel = index, \
30 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
31 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
32 .address = index, \
33 .scan_index = index, \
34 .scan_type = { \
35 .sign = 'u', \
36 .realbits = 12, \
37 .storagebits = 16, \
38 }, \
39 }
40
25static struct iio_chan_spec ad7298_channels[] = { 41static struct iio_chan_spec ad7298_channels[] = {
26 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, 42 {
27 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 43 .type = IIO_TEMP,
28 9, AD7298_CH_TEMP, IIO_ST('s', 32, 32, 0), 0), 44 .indexed = 1,
29 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 45 .channel = 0,
30 IIO_CHAN_INFO_SCALE_SHARED_BIT, 46 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
31 0, 0, IIO_ST('u', 12, 16, 0), 0), 47 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
32 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, 48 .address = 9,
33 IIO_CHAN_INFO_SCALE_SHARED_BIT, 49 .scan_index = AD7298_CH_TEMP,
34 1, 1, IIO_ST('u', 12, 16, 0), 0), 50 .scan_type = {
35 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 2, 0, 51 .sign = 's',
36 IIO_CHAN_INFO_SCALE_SHARED_BIT, 52 .realbits = 32,
37 2, 2, IIO_ST('u', 12, 16, 0), 0), 53 .storagebits = 32,
38 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 3, 0, 54 },
39 IIO_CHAN_INFO_SCALE_SHARED_BIT, 55 },
40 3, 3, IIO_ST('u', 12, 16, 0), 0), 56 AD7298_V_CHAN(0),
41 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 4, 0, 57 AD7298_V_CHAN(1),
42 IIO_CHAN_INFO_SCALE_SHARED_BIT, 58 AD7298_V_CHAN(2),
43 4, 4, IIO_ST('u', 12, 16, 0), 0), 59 AD7298_V_CHAN(3),
44 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 5, 0, 60 AD7298_V_CHAN(4),
45 IIO_CHAN_INFO_SCALE_SHARED_BIT, 61 AD7298_V_CHAN(5),
46 5, 5, IIO_ST('u', 12, 16, 0), 0), 62 AD7298_V_CHAN(6),
47 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 6, 0, 63 AD7298_V_CHAN(7),
48 IIO_CHAN_INFO_SCALE_SHARED_BIT,
49 6, 6, IIO_ST('u', 12, 16, 0), 0),
50 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 7, 0,
51 IIO_CHAN_INFO_SCALE_SHARED_BIT,
52 7, 7, IIO_ST('u', 12, 16, 0), 0),
53 IIO_CHAN_SOFT_TIMESTAMP(8), 64 IIO_CHAN_SOFT_TIMESTAMP(8),
54}; 65};
55 66
@@ -121,7 +132,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
121 unsigned int scale_uv; 132 unsigned int scale_uv;
122 133
123 switch (m) { 134 switch (m) {
124 case 0: 135 case IIO_CHAN_INFO_RAW:
125 mutex_lock(&indio_dev->mlock); 136 mutex_lock(&indio_dev->mlock);
126 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 137 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
127 ret = -EBUSY; 138 ret = -EBUSY;
@@ -168,7 +179,7 @@ static int __devinit ad7298_probe(struct spi_device *spi)
168 struct ad7298_platform_data *pdata = spi->dev.platform_data; 179 struct ad7298_platform_data *pdata = spi->dev.platform_data;
169 struct ad7298_state *st; 180 struct ad7298_state *st;
170 int ret; 181 int ret;
171 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 182 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
172 183
173 if (indio_dev == NULL) 184 if (indio_dev == NULL)
174 return -ENOMEM; 185 return -ENOMEM;
@@ -241,7 +252,7 @@ error_disable_reg:
241error_put_reg: 252error_put_reg:
242 if (!IS_ERR(st->reg)) 253 if (!IS_ERR(st->reg))
243 regulator_put(st->reg); 254 regulator_put(st->reg);
244 iio_free_device(indio_dev); 255 iio_device_free(indio_dev);
245 256
246 return ret; 257 return ret;
247} 258}
@@ -258,7 +269,7 @@ static int __devexit ad7298_remove(struct spi_device *spi)
258 regulator_disable(st->reg); 269 regulator_disable(st->reg);
259 regulator_put(st->reg); 270 regulator_put(st->reg);
260 } 271 }
261 iio_free_device(indio_dev); 272 iio_device_free(indio_dev);
262 273
263 return 0; 274 return 0;
264} 275}
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index feeb0eeba59a..908a3e5609df 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AD7298 SPI ADC driver 2 * AD7298 SPI ADC driver
3 * 3 *
4 * Copyright 2011 Analog Devices Inc. 4 * Copyright 2011-2012 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2. 6 * Licensed under the GPL-2.
7 */ 7 */
@@ -11,10 +11,10 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/spi/spi.h> 12#include <linux/spi/spi.h>
13 13
14#include "../iio.h" 14#include <linux/iio/iio.h>
15#include "../buffer.h" 15#include <linux/iio/buffer.h>
16#include "../ring_sw.h" 16#include <linux/iio/kfifo_buf.h>
17#include "../trigger_consumer.h" 17#include <linux/iio/trigger_consumer.h>
18 18
19#include "ad7298.h" 19#include "ad7298.h"
20 20
@@ -28,25 +28,17 @@
28static int ad7298_ring_preenable(struct iio_dev *indio_dev) 28static int ad7298_ring_preenable(struct iio_dev *indio_dev)
29{ 29{
30 struct ad7298_state *st = iio_priv(indio_dev); 30 struct ad7298_state *st = iio_priv(indio_dev);
31 struct iio_buffer *ring = indio_dev->buffer;
32 size_t d_size;
33 int i, m; 31 int i, m;
34 unsigned short command; 32 unsigned short command;
35 int scan_count = bitmap_weight(indio_dev->active_scan_mask, 33 int scan_count, ret;
36 indio_dev->masklength);
37 d_size = scan_count * (AD7298_STORAGE_BITS / 8);
38
39 if (ring->scan_timestamp) {
40 d_size += sizeof(s64);
41
42 if (d_size % sizeof(s64))
43 d_size += sizeof(s64) - (d_size % sizeof(s64));
44 }
45 34
46 if (ring->access->set_bytes_per_datum) 35 ret = iio_sw_buffer_preenable(indio_dev);
47 ring->access->set_bytes_per_datum(ring, d_size); 36 if (ret < 0)
37 return ret;
48 38
49 st->d_size = d_size; 39 /* Now compute overall size */
40 scan_count = bitmap_weight(indio_dev->active_scan_mask,
41 indio_dev->masklength);
50 42
51 command = AD7298_WRITE | st->ext_ref; 43 command = AD7298_WRITE | st->ext_ref;
52 44
@@ -100,9 +92,9 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
100 if (b_sent) 92 if (b_sent)
101 return b_sent; 93 return b_sent;
102 94
103 if (ring->scan_timestamp) { 95 if (indio_dev->scan_timestamp) {
104 time_ns = iio_get_time_ns(); 96 time_ns = iio_get_time_ns();
105 memcpy((u8 *)buf + st->d_size - sizeof(s64), 97 memcpy((u8 *)buf + indio_dev->scan_bytes - sizeof(s64),
106 &time_ns, sizeof(time_ns)); 98 &time_ns, sizeof(time_ns));
107 } 99 }
108 100
@@ -126,7 +118,7 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
126{ 118{
127 int ret; 119 int ret;
128 120
129 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 121 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
130 if (!indio_dev->buffer) { 122 if (!indio_dev->buffer) {
131 ret = -ENOMEM; 123 ret = -ENOMEM;
132 goto error_ret; 124 goto error_ret;
@@ -140,7 +132,7 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
140 132
141 if (indio_dev->pollfunc == NULL) { 133 if (indio_dev->pollfunc == NULL) {
142 ret = -ENOMEM; 134 ret = -ENOMEM;
143 goto error_deallocate_sw_rb; 135 goto error_deallocate_kfifo;
144 } 136 }
145 137
146 /* Ring buffer functions - here trigger setup related */ 138 /* Ring buffer functions - here trigger setup related */
@@ -151,8 +143,8 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
151 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 143 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
152 return 0; 144 return 0;
153 145
154error_deallocate_sw_rb: 146error_deallocate_kfifo:
155 iio_sw_rb_free(indio_dev->buffer); 147 iio_kfifo_free(indio_dev->buffer);
156error_ret: 148error_ret:
157 return ret; 149 return ret;
158} 150}
@@ -160,5 +152,5 @@ error_ret:
160void ad7298_ring_cleanup(struct iio_dev *indio_dev) 152void ad7298_ring_cleanup(struct iio_dev *indio_dev)
161{ 153{
162 iio_dealloc_pollfunc(indio_dev->pollfunc); 154 iio_dealloc_pollfunc(indio_dev->pollfunc);
163 iio_sw_rb_free(indio_dev->buffer); 155 iio_kfifo_free(indio_dev->buffer);
164} 156}
diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h
index 27f696c75cc4..b1dd9317fe1f 100644
--- a/drivers/staging/iio/adc/ad7476.h
+++ b/drivers/staging/iio/adc/ad7476.h
@@ -27,7 +27,6 @@ struct ad7476_state {
27 struct spi_device *spi; 27 struct spi_device *spi;
28 const struct ad7476_chip_info *chip_info; 28 const struct ad7476_chip_info *chip_info;
29 struct regulator *reg; 29 struct regulator *reg;
30 size_t d_size;
31 u16 int_vref_mv; 30 u16 int_vref_mv;
32 struct spi_transfer xfer; 31 struct spi_transfer xfer;
33 struct spi_message msg; 32 struct spi_message msg;
diff --git a/drivers/staging/iio/adc/ad7476_core.c b/drivers/staging/iio/adc/ad7476_core.c
index 0c064d1c3927..be1c260cf165 100644
--- a/drivers/staging/iio/adc/ad7476_core.c
+++ b/drivers/staging/iio/adc/ad7476_core.c
@@ -15,9 +15,9 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../buffer.h" 20#include <linux/iio/buffer.h>
21 21
22#include "ad7476.h" 22#include "ad7476.h"
23 23
@@ -43,7 +43,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
43 unsigned int scale_uv; 43 unsigned int scale_uv;
44 44
45 switch (m) { 45 switch (m) {
46 case 0: 46 case IIO_CHAN_INFO_RAW:
47 mutex_lock(&indio_dev->mlock); 47 mutex_lock(&indio_dev->mlock);
48 if (iio_buffer_enabled(indio_dev)) 48 if (iio_buffer_enabled(indio_dev))
49 ret = -EBUSY; 49 ret = -EBUSY;
@@ -66,53 +66,51 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
66 return -EINVAL; 66 return -EINVAL;
67} 67}
68 68
69#define AD7476_CHAN(bits) \
70 { \
71 .type = IIO_VOLTAGE, \
72 .indexed = 1, \
73 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
74 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
75 .scan_type = { \
76 .sign = 'u', \
77 .realbits = bits, \
78 .storagebits = 16, \
79 .shift = 12 - bits, \
80 }, \
81}
82
69static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { 83static const struct ad7476_chip_info ad7476_chip_info_tbl[] = {
70 [ID_AD7466] = { 84 [ID_AD7466] = {
71 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 85 .channel[0] = AD7476_CHAN(12),
72 IIO_CHAN_INFO_SCALE_SHARED_BIT,
73 0, 0, IIO_ST('u', 12, 16, 0), 0),
74 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 86 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
75 }, 87 },
76 [ID_AD7467] = { 88 [ID_AD7467] = {
77 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 89 .channel[0] = AD7476_CHAN(10),
78 IIO_CHAN_INFO_SCALE_SHARED_BIT,
79 0, 0, IIO_ST('u', 10, 16, 2), 0),
80 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 90 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
81 }, 91 },
82 [ID_AD7468] = { 92 [ID_AD7468] = {
83 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1 , 0, NULL, 0, 0, 93 .channel[0] = AD7476_CHAN(8),
84 IIO_CHAN_INFO_SCALE_SHARED_BIT,
85 0, 0, IIO_ST('u', 8, 16, 4), 0),
86 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 94 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
87 }, 95 },
88 [ID_AD7475] = { 96 [ID_AD7475] = {
89 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 97 .channel[0] = AD7476_CHAN(12),
90 IIO_CHAN_INFO_SCALE_SHARED_BIT,
91 0, 0, IIO_ST('u', 12, 16, 0), 0),
92 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 98 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
93 }, 99 },
94 [ID_AD7476] = { 100 [ID_AD7476] = {
95 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 101 .channel[0] = AD7476_CHAN(12),
96 IIO_CHAN_INFO_SCALE_SHARED_BIT,
97 0, 0, IIO_ST('u', 12, 16, 0), 0),
98 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 102 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
99 }, 103 },
100 [ID_AD7477] = { 104 [ID_AD7477] = {
101 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 105 .channel[0] = AD7476_CHAN(10),
102 IIO_CHAN_INFO_SCALE_SHARED_BIT,
103 0, 0, IIO_ST('u', 10, 16, 2), 0),
104 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 106 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
105 }, 107 },
106 [ID_AD7478] = { 108 [ID_AD7478] = {
107 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 109 .channel[0] = AD7476_CHAN(8),
108 IIO_CHAN_INFO_SCALE_SHARED_BIT,
109 0, 0, IIO_ST('u', 8, 16, 4), 0),
110 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 110 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
111 }, 111 },
112 [ID_AD7495] = { 112 [ID_AD7495] = {
113 .channel[0] = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 113 .channel[0] = AD7476_CHAN(12),
114 IIO_CHAN_INFO_SCALE_SHARED_BIT,
115 0, 0, IIO_ST('u', 12, 16, 0), 0),
116 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 114 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
117 .int_vref_mv = 2500, 115 .int_vref_mv = 2500,
118 }, 116 },
@@ -130,7 +128,7 @@ static int __devinit ad7476_probe(struct spi_device *spi)
130 struct iio_dev *indio_dev; 128 struct iio_dev *indio_dev;
131 int ret, voltage_uv = 0; 129 int ret, voltage_uv = 0;
132 130
133 indio_dev = iio_allocate_device(sizeof(*st)); 131 indio_dev = iio_device_alloc(sizeof(*st));
134 if (indio_dev == NULL) { 132 if (indio_dev == NULL) {
135 ret = -ENOMEM; 133 ret = -ENOMEM;
136 goto error_ret; 134 goto error_ret;
@@ -200,7 +198,7 @@ error_disable_reg:
200error_put_reg: 198error_put_reg:
201 if (!IS_ERR(st->reg)) 199 if (!IS_ERR(st->reg))
202 regulator_put(st->reg); 200 regulator_put(st->reg);
203 iio_free_device(indio_dev); 201 iio_device_free(indio_dev);
204 202
205error_ret: 203error_ret:
206 return ret; 204 return ret;
@@ -218,7 +216,7 @@ static int ad7476_remove(struct spi_device *spi)
218 regulator_disable(st->reg); 216 regulator_disable(st->reg);
219 regulator_put(st->reg); 217 regulator_put(st->reg);
220 } 218 }
221 iio_free_device(indio_dev); 219 iio_device_free(indio_dev);
222 220
223 return 0; 221 return 0;
224} 222}
diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
index d6af6c05ce1c..383611b05764 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2010 Analog Devices Inc. 2 * Copyright 2010-2012 Analog Devices Inc.
3 * Copyright (C) 2008 Jonathan Cameron 3 * Copyright (C) 2008 Jonathan Cameron
4 * 4 *
5 * Licensed under the GPL-2 or later. 5 * Licensed under the GPL-2 or later.
@@ -13,43 +13,13 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/spi/spi.h> 14#include <linux/spi/spi.h>
15 15
16#include "../iio.h" 16#include <linux/iio/iio.h>
17#include "../buffer.h" 17#include <linux/iio/buffer.h>
18#include "../ring_sw.h" 18#include <linux/iio/kfifo_buf.h>
19#include "../trigger_consumer.h" 19#include <linux/iio/trigger_consumer.h>
20 20
21#include "ad7476.h" 21#include "ad7476.h"
22 22
23/**
24 * ad7476_ring_preenable() setup the parameters of the ring before enabling
25 *
26 * The complex nature of the setting of the number of bytes per datum is due
27 * to this driver currently ensuring that the timestamp is stored at an 8
28 * byte boundary.
29 **/
30static int ad7476_ring_preenable(struct iio_dev *indio_dev)
31{
32 struct ad7476_state *st = iio_priv(indio_dev);
33 struct iio_buffer *ring = indio_dev->buffer;
34
35 st->d_size = bitmap_weight(indio_dev->active_scan_mask,
36 indio_dev->masklength) *
37 st->chip_info->channel[0].scan_type.storagebits / 8;
38
39 if (ring->scan_timestamp) {
40 st->d_size += sizeof(s64);
41
42 if (st->d_size % sizeof(s64))
43 st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
44 }
45
46 if (indio_dev->buffer->access->set_bytes_per_datum)
47 indio_dev->buffer->access->
48 set_bytes_per_datum(indio_dev->buffer, st->d_size);
49
50 return 0;
51}
52
53static irqreturn_t ad7476_trigger_handler(int irq, void *p) 23static irqreturn_t ad7476_trigger_handler(int irq, void *p)
54{ 24{
55 struct iio_poll_func *pf = p; 25 struct iio_poll_func *pf = p;
@@ -59,7 +29,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p)
59 __u8 *rxbuf; 29 __u8 *rxbuf;
60 int b_sent; 30 int b_sent;
61 31
62 rxbuf = kzalloc(st->d_size, GFP_KERNEL); 32 rxbuf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
63 if (rxbuf == NULL) 33 if (rxbuf == NULL)
64 return -ENOMEM; 34 return -ENOMEM;
65 35
@@ -70,8 +40,8 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p)
70 40
71 time_ns = iio_get_time_ns(); 41 time_ns = iio_get_time_ns();
72 42
73 if (indio_dev->buffer->scan_timestamp) 43 if (indio_dev->scan_timestamp)
74 memcpy(rxbuf + st->d_size - sizeof(s64), 44 memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
75 &time_ns, sizeof(time_ns)); 45 &time_ns, sizeof(time_ns));
76 46
77 indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns); 47 indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns);
@@ -83,7 +53,7 @@ done:
83} 53}
84 54
85static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = { 55static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = {
86 .preenable = &ad7476_ring_preenable, 56 .preenable = &iio_sw_buffer_preenable,
87 .postenable = &iio_triggered_buffer_postenable, 57 .postenable = &iio_triggered_buffer_postenable,
88 .predisable = &iio_triggered_buffer_predisable, 58 .predisable = &iio_triggered_buffer_predisable,
89}; 59};
@@ -93,7 +63,7 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
93 struct ad7476_state *st = iio_priv(indio_dev); 63 struct ad7476_state *st = iio_priv(indio_dev);
94 int ret = 0; 64 int ret = 0;
95 65
96 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 66 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
97 if (!indio_dev->buffer) { 67 if (!indio_dev->buffer) {
98 ret = -ENOMEM; 68 ret = -ENOMEM;
99 goto error_ret; 69 goto error_ret;
@@ -108,7 +78,7 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
108 indio_dev->id); 78 indio_dev->id);
109 if (indio_dev->pollfunc == NULL) { 79 if (indio_dev->pollfunc == NULL) {
110 ret = -ENOMEM; 80 ret = -ENOMEM;
111 goto error_deallocate_sw_rb; 81 goto error_deallocate_kfifo;
112 } 82 }
113 83
114 /* Ring buffer functions - here trigger setup related */ 84 /* Ring buffer functions - here trigger setup related */
@@ -119,8 +89,8 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
119 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 89 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
120 return 0; 90 return 0;
121 91
122error_deallocate_sw_rb: 92error_deallocate_kfifo:
123 iio_sw_rb_free(indio_dev->buffer); 93 iio_kfifo_free(indio_dev->buffer);
124error_ret: 94error_ret:
125 return ret; 95 return ret;
126} 96}
@@ -128,5 +98,5 @@ error_ret:
128void ad7476_ring_cleanup(struct iio_dev *indio_dev) 98void ad7476_ring_cleanup(struct iio_dev *indio_dev)
129{ 99{
130 iio_dealloc_pollfunc(indio_dev->pollfunc); 100 iio_dealloc_pollfunc(indio_dev->pollfunc);
131 iio_sw_rb_free(indio_dev->buffer); 101 iio_kfifo_free(indio_dev->buffer);
132} 102}
diff --git a/drivers/staging/iio/adc/ad7606_core.c b/drivers/staging/iio/adc/ad7606_core.c
index 97e8d3d4471e..10ab6dc823b9 100644
--- a/drivers/staging/iio/adc/ad7606_core.c
+++ b/drivers/staging/iio/adc/ad7606_core.c
@@ -18,9 +18,9 @@
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24 24
25#include "ad7606.h" 25#include "ad7606.h"
26 26
@@ -88,7 +88,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
88 unsigned int scale_uv; 88 unsigned int scale_uv;
89 89
90 switch (m) { 90 switch (m) {
91 case 0: 91 case IIO_CHAN_INFO_RAW:
92 mutex_lock(&indio_dev->mlock); 92 mutex_lock(&indio_dev->mlock);
93 if (iio_buffer_enabled(indio_dev)) 93 if (iio_buffer_enabled(indio_dev))
94 ret = -EBUSY; 94 ret = -EBUSY;
@@ -113,7 +113,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
113static ssize_t ad7606_show_range(struct device *dev, 113static ssize_t ad7606_show_range(struct device *dev,
114 struct device_attribute *attr, char *buf) 114 struct device_attribute *attr, char *buf)
115{ 115{
116 struct iio_dev *indio_dev = dev_get_drvdata(dev); 116 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
117 struct ad7606_state *st = iio_priv(indio_dev); 117 struct ad7606_state *st = iio_priv(indio_dev);
118 118
119 return sprintf(buf, "%u\n", st->range); 119 return sprintf(buf, "%u\n", st->range);
@@ -122,7 +122,7 @@ static ssize_t ad7606_show_range(struct device *dev,
122static ssize_t ad7606_store_range(struct device *dev, 122static ssize_t ad7606_store_range(struct device *dev,
123 struct device_attribute *attr, const char *buf, size_t count) 123 struct device_attribute *attr, const char *buf, size_t count)
124{ 124{
125 struct iio_dev *indio_dev = dev_get_drvdata(dev); 125 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
126 struct ad7606_state *st = iio_priv(indio_dev); 126 struct ad7606_state *st = iio_priv(indio_dev);
127 unsigned long lval; 127 unsigned long lval;
128 128
@@ -147,7 +147,7 @@ static IIO_CONST_ATTR(in_voltage_range_available, "5000 10000");
147static ssize_t ad7606_show_oversampling_ratio(struct device *dev, 147static ssize_t ad7606_show_oversampling_ratio(struct device *dev,
148 struct device_attribute *attr, char *buf) 148 struct device_attribute *attr, char *buf)
149{ 149{
150 struct iio_dev *indio_dev = dev_get_drvdata(dev); 150 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
151 struct ad7606_state *st = iio_priv(indio_dev); 151 struct ad7606_state *st = iio_priv(indio_dev);
152 152
153 return sprintf(buf, "%u\n", st->oversampling); 153 return sprintf(buf, "%u\n", st->oversampling);
@@ -168,7 +168,7 @@ static int ad7606_oversampling_get_index(unsigned val)
168static ssize_t ad7606_store_oversampling_ratio(struct device *dev, 168static ssize_t ad7606_store_oversampling_ratio(struct device *dev,
169 struct device_attribute *attr, const char *buf, size_t count) 169 struct device_attribute *attr, const char *buf, size_t count)
170{ 170{
171 struct iio_dev *indio_dev = dev_get_drvdata(dev); 171 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
172 struct ad7606_state *st = iio_priv(indio_dev); 172 struct ad7606_state *st = iio_priv(indio_dev);
173 unsigned long lval; 173 unsigned long lval;
174 int ret; 174 int ret;
@@ -229,14 +229,15 @@ static const struct attribute_group ad7606_attribute_group_range = {
229 .attrs = ad7606_attributes_range, 229 .attrs = ad7606_attributes_range,
230}; 230};
231 231
232#define AD7606_CHANNEL(num) \ 232#define AD7606_CHANNEL(num) \
233 { \ 233 { \
234 .type = IIO_VOLTAGE, \ 234 .type = IIO_VOLTAGE, \
235 .indexed = 1, \ 235 .indexed = 1, \
236 .channel = num, \ 236 .channel = num, \
237 .address = num, \ 237 .address = num, \
238 .scan_index = num, \ 238 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
239 .scan_type = IIO_ST('s', 16, 16, 0), \ 239 .scan_index = num, \
240 .scan_type = IIO_ST('s', 16, 16, 0), \
240 } 241 }
241 242
242static struct iio_chan_spec ad7606_8_channels[] = { 243static struct iio_chan_spec ad7606_8_channels[] = {
@@ -460,7 +461,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
460 struct ad7606_platform_data *pdata = dev->platform_data; 461 struct ad7606_platform_data *pdata = dev->platform_data;
461 struct ad7606_state *st; 462 struct ad7606_state *st;
462 int ret; 463 int ret;
463 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 464 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
464 465
465 if (indio_dev == NULL) { 466 if (indio_dev == NULL) {
466 ret = -ENOMEM; 467 ret = -ENOMEM;
@@ -559,7 +560,7 @@ error_disable_reg:
559error_put_reg: 560error_put_reg:
560 if (!IS_ERR(st->reg)) 561 if (!IS_ERR(st->reg))
561 regulator_put(st->reg); 562 regulator_put(st->reg);
562 iio_free_device(indio_dev); 563 iio_device_free(indio_dev);
563error_ret: 564error_ret:
564 return ERR_PTR(ret); 565 return ERR_PTR(ret);
565} 566}
@@ -579,7 +580,7 @@ int ad7606_remove(struct iio_dev *indio_dev, int irq)
579 } 580 }
580 581
581 ad7606_free_gpios(st); 582 ad7606_free_gpios(st);
582 iio_free_device(indio_dev); 583 iio_device_free(indio_dev);
583 584
584 return 0; 585 return 0;
585} 586}
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index bb152a8e8c92..a53faafec070 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -12,7 +12,7 @@
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/io.h> 13#include <linux/io.h>
14 14
15#include "../iio.h" 15#include <linux/iio/iio.h>
16#include "ad7606.h" 16#include "ad7606.h"
17 17
18static int ad7606_par16_read_block(struct device *dev, 18static int ad7606_par16_read_block(struct device *dev,
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index 1ef9fbcaf2de..24ce8fc71646 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2011 Analog Devices Inc. 2 * Copyright 2011-2012 Analog Devices Inc.
3 * 3 *
4 * Licensed under the GPL-2. 4 * Licensed under the GPL-2.
5 * 5 *
@@ -11,10 +11,10 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13 13
14#include "../iio.h" 14#include <linux/iio/iio.h>
15#include "../buffer.h" 15#include <linux/iio/buffer.h>
16#include "../ring_sw.h" 16#include <linux/iio/kfifo_buf.h>
17#include "../trigger_consumer.h" 17#include <linux/iio/trigger_consumer.h>
18 18
19#include "ad7606.h" 19#include "ad7606.h"
20 20
@@ -51,8 +51,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
51 __u8 *buf; 51 __u8 *buf;
52 int ret; 52 int ret;
53 53
54 buf = kzalloc(ring->access->get_bytes_per_datum(ring), 54 buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
55 GFP_KERNEL);
56 if (buf == NULL) 55 if (buf == NULL)
57 return; 56 return;
58 57
@@ -82,9 +81,8 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
82 81
83 time_ns = iio_get_time_ns(); 82 time_ns = iio_get_time_ns();
84 83
85 if (ring->scan_timestamp) 84 if (indio_dev->scan_timestamp)
86 *((s64 *)(buf + ring->access->get_bytes_per_datum(ring) - 85 *((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns;
87 sizeof(s64))) = time_ns;
88 86
89 ring->access->store_to(indio_dev->buffer, buf, time_ns); 87 ring->access->store_to(indio_dev->buffer, buf, time_ns);
90done: 88done:
@@ -104,7 +102,7 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
104 struct ad7606_state *st = iio_priv(indio_dev); 102 struct ad7606_state *st = iio_priv(indio_dev);
105 int ret; 103 int ret;
106 104
107 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 105 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
108 if (!indio_dev->buffer) { 106 if (!indio_dev->buffer) {
109 ret = -ENOMEM; 107 ret = -ENOMEM;
110 goto error_ret; 108 goto error_ret;
@@ -119,13 +117,13 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
119 indio_dev->id); 117 indio_dev->id);
120 if (indio_dev->pollfunc == NULL) { 118 if (indio_dev->pollfunc == NULL) {
121 ret = -ENOMEM; 119 ret = -ENOMEM;
122 goto error_deallocate_sw_rb; 120 goto error_deallocate_kfifo;
123 } 121 }
124 122
125 /* Ring buffer functions - here trigger setup related */ 123 /* Ring buffer functions - here trigger setup related */
126 124
127 indio_dev->setup_ops = &ad7606_ring_setup_ops; 125 indio_dev->setup_ops = &ad7606_ring_setup_ops;
128 indio_dev->buffer->scan_timestamp = true ; 126 indio_dev->buffer->scan_timestamp = true;
129 127
130 INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring); 128 INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
131 129
@@ -133,8 +131,8 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
133 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 131 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
134 return 0; 132 return 0;
135 133
136error_deallocate_sw_rb: 134error_deallocate_kfifo:
137 iio_sw_rb_free(indio_dev->buffer); 135 iio_kfifo_free(indio_dev->buffer);
138error_ret: 136error_ret:
139 return ret; 137 return ret;
140} 138}
@@ -142,5 +140,5 @@ error_ret:
142void ad7606_ring_cleanup(struct iio_dev *indio_dev) 140void ad7606_ring_cleanup(struct iio_dev *indio_dev)
143{ 141{
144 iio_dealloc_pollfunc(indio_dev->pollfunc); 142 iio_dealloc_pollfunc(indio_dev->pollfunc);
145 iio_sw_rb_free(indio_dev->buffer); 143 iio_kfifo_free(indio_dev->buffer);
146} 144}
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index 237f1c44d296..099d347da52d 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -11,7 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/err.h> 12#include <linux/err.h>
13 13
14#include "../iio.h" 14#include <linux/iio/iio.h>
15#include "ad7606.h" 15#include "ad7606.h"
16 16
17#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */ 17#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index a13e58c814e6..1ece2ac8de56 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -18,8 +18,8 @@
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23 23
24#include "ad7780.h" 24#include "ad7780.h"
25 25
@@ -94,7 +94,7 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
94 unsigned long scale_uv; 94 unsigned long scale_uv;
95 95
96 switch (m) { 96 switch (m) {
97 case 0: 97 case IIO_CHAN_INFO_RAW:
98 mutex_lock(&indio_dev->mlock); 98 mutex_lock(&indio_dev->mlock);
99 ret = ad7780_read(st, &smpl); 99 ret = ad7780_read(st, &smpl);
100 mutex_unlock(&indio_dev->mlock); 100 mutex_unlock(&indio_dev->mlock);
@@ -126,14 +126,34 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
126 126
127static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { 127static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
128 [ID_AD7780] = { 128 [ID_AD7780] = {
129 .channel = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 129 .channel = {
130 IIO_CHAN_INFO_SCALE_SHARED_BIT, 130 .type = IIO_VOLTAGE,
131 0, 0, IIO_ST('s', 24, 32, 8), 0), 131 .indexed = 1,
132 .channel = 0,
133 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
134 IIO_CHAN_INFO_SCALE_SHARED_BIT,
135 .scan_type = {
136 .sign = 's',
137 .realbits = 24,
138 .storagebits = 32,
139 .shift = 8,
140 },
141 },
132 }, 142 },
133 [ID_AD7781] = { 143 [ID_AD7781] = {
134 .channel = IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0, 144 .channel = {
135 IIO_CHAN_INFO_SCALE_SHARED_BIT, 145 .type = IIO_VOLTAGE,
136 0, 0, IIO_ST('s', 20, 32, 12), 0), 146 .indexed = 1,
147 .channel = 0,
148 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
149 IIO_CHAN_INFO_SCALE_SHARED_BIT,
150 .scan_type = {
151 .sign = 's',
152 .realbits = 20,
153 .storagebits = 32,
154 .shift = 12,
155 },
156 },
137 }, 157 },
138}; 158};
139 159
@@ -167,7 +187,7 @@ static int __devinit ad7780_probe(struct spi_device *spi)
167 return -ENODEV; 187 return -ENODEV;
168 } 188 }
169 189
170 indio_dev = iio_allocate_device(sizeof(*st)); 190 indio_dev = iio_device_alloc(sizeof(*st));
171 if (indio_dev == NULL) 191 if (indio_dev == NULL)
172 return -ENOMEM; 192 return -ENOMEM;
173 193
@@ -245,7 +265,7 @@ error_put_reg:
245 if (!IS_ERR(st->reg)) 265 if (!IS_ERR(st->reg))
246 regulator_put(st->reg); 266 regulator_put(st->reg);
247 267
248 iio_free_device(indio_dev); 268 iio_device_free(indio_dev);
249 269
250 return ret; 270 return ret;
251} 271}
@@ -262,7 +282,7 @@ static int ad7780_remove(struct spi_device *spi)
262 regulator_disable(st->reg); 282 regulator_disable(st->reg);
263 regulator_put(st->reg); 283 regulator_put(st->reg);
264 } 284 }
265 iio_free_device(indio_dev); 285 iio_device_free(indio_dev);
266 286
267 return 0; 287 return 0;
268} 288}
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index 84ecde1ad042..b36556fa2957 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AD7792/AD7793 SPI ADC driver 2 * AD7792/AD7793 SPI ADC driver
3 * 3 *
4 * Copyright 2011 Analog Devices Inc. 4 * Copyright 2011-2012 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2. 6 * Licensed under the GPL-2.
7 */ 7 */
@@ -18,12 +18,12 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24#include "../ring_sw.h" 24#include <linux/iio/kfifo_buf.h>
25#include "../trigger.h" 25#include <linux/iio/trigger.h>
26#include "../trigger_consumer.h" 26#include <linux/iio/trigger_consumer.h>
27 27
28#include "ad7793.h" 28#include "ad7793.h"
29 29
@@ -319,31 +319,18 @@ out:
319static int ad7793_ring_preenable(struct iio_dev *indio_dev) 319static int ad7793_ring_preenable(struct iio_dev *indio_dev)
320{ 320{
321 struct ad7793_state *st = iio_priv(indio_dev); 321 struct ad7793_state *st = iio_priv(indio_dev);
322 struct iio_buffer *ring = indio_dev->buffer;
323 size_t d_size;
324 unsigned channel; 322 unsigned channel;
323 int ret;
325 324
326 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 325 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
327 return -EINVAL; 326 return -EINVAL;
327 ret = iio_sw_buffer_preenable(indio_dev);
328 if (ret < 0)
329 return ret;
328 330
329 channel = find_first_bit(indio_dev->active_scan_mask, 331 channel = find_first_bit(indio_dev->active_scan_mask,
330 indio_dev->masklength); 332 indio_dev->masklength);
331 333
332 d_size = bitmap_weight(indio_dev->active_scan_mask,
333 indio_dev->masklength) *
334 indio_dev->channels[0].scan_type.storagebits / 8;
335
336 if (ring->scan_timestamp) {
337 d_size += sizeof(s64);
338
339 if (d_size % sizeof(s64))
340 d_size += sizeof(s64) - (d_size % sizeof(s64));
341 }
342
343 if (indio_dev->buffer->access->set_bytes_per_datum)
344 indio_dev->buffer->access->
345 set_bytes_per_datum(indio_dev->buffer, d_size);
346
347 st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | 334 st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) |
348 AD7793_MODE_SEL(AD7793_MODE_CONT); 335 AD7793_MODE_SEL(AD7793_MODE_CONT);
349 st->conf = (st->conf & ~AD7793_CONF_CHAN(-1)) | 336 st->conf = (st->conf & ~AD7793_CONF_CHAN(-1)) |
@@ -399,7 +386,7 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p)
399 indio_dev->channels[0].scan_type.realbits/8); 386 indio_dev->channels[0].scan_type.realbits/8);
400 387
401 /* Guaranteed to be aligned with 8 byte boundary */ 388 /* Guaranteed to be aligned with 8 byte boundary */
402 if (ring->scan_timestamp) 389 if (indio_dev->scan_timestamp)
403 dat64[1] = pf->timestamp; 390 dat64[1] = pf->timestamp;
404 391
405 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp); 392 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
@@ -422,7 +409,7 @@ static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
422{ 409{
423 int ret; 410 int ret;
424 411
425 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 412 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
426 if (!indio_dev->buffer) { 413 if (!indio_dev->buffer) {
427 ret = -ENOMEM; 414 ret = -ENOMEM;
428 goto error_ret; 415 goto error_ret;
@@ -435,7 +422,7 @@ static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
435 indio_dev->id); 422 indio_dev->id);
436 if (indio_dev->pollfunc == NULL) { 423 if (indio_dev->pollfunc == NULL) {
437 ret = -ENOMEM; 424 ret = -ENOMEM;
438 goto error_deallocate_sw_rb; 425 goto error_deallocate_kfifo;
439 } 426 }
440 427
441 /* Ring buffer functions - here trigger setup related */ 428 /* Ring buffer functions - here trigger setup related */
@@ -445,8 +432,8 @@ static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
445 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 432 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
446 return 0; 433 return 0;
447 434
448error_deallocate_sw_rb: 435error_deallocate_kfifo:
449 iio_sw_rb_free(indio_dev->buffer); 436 iio_kfifo_free(indio_dev->buffer);
450error_ret: 437error_ret:
451 return ret; 438 return ret;
452} 439}
@@ -454,7 +441,7 @@ error_ret:
454static void ad7793_ring_cleanup(struct iio_dev *indio_dev) 441static void ad7793_ring_cleanup(struct iio_dev *indio_dev)
455{ 442{
456 iio_dealloc_pollfunc(indio_dev->pollfunc); 443 iio_dealloc_pollfunc(indio_dev->pollfunc);
457 iio_sw_rb_free(indio_dev->buffer); 444 iio_kfifo_free(indio_dev->buffer);
458} 445}
459 446
460/** 447/**
@@ -482,7 +469,7 @@ static int ad7793_probe_trigger(struct iio_dev *indio_dev)
482 struct ad7793_state *st = iio_priv(indio_dev); 469 struct ad7793_state *st = iio_priv(indio_dev);
483 int ret; 470 int ret;
484 471
485 st->trig = iio_allocate_trigger("%s-dev%d", 472 st->trig = iio_trigger_alloc("%s-dev%d",
486 spi_get_device_id(st->spi)->name, 473 spi_get_device_id(st->spi)->name,
487 indio_dev->id); 474 indio_dev->id);
488 if (st->trig == NULL) { 475 if (st->trig == NULL) {
@@ -516,7 +503,7 @@ static int ad7793_probe_trigger(struct iio_dev *indio_dev)
516error_free_irq: 503error_free_irq:
517 free_irq(st->spi->irq, indio_dev); 504 free_irq(st->spi->irq, indio_dev);
518error_free_trig: 505error_free_trig:
519 iio_free_trigger(st->trig); 506 iio_trigger_free(st->trig);
520error_ret: 507error_ret:
521 return ret; 508 return ret;
522} 509}
@@ -527,7 +514,7 @@ static void ad7793_remove_trigger(struct iio_dev *indio_dev)
527 514
528 iio_trigger_unregister(st->trig); 515 iio_trigger_unregister(st->trig);
529 free_irq(st->spi->irq, indio_dev); 516 free_irq(st->spi->irq, indio_dev);
530 iio_free_trigger(st->trig); 517 iio_trigger_free(st->trig);
531} 518}
532 519
533static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19, 520static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19,
@@ -537,7 +524,7 @@ static ssize_t ad7793_read_frequency(struct device *dev,
537 struct device_attribute *attr, 524 struct device_attribute *attr,
538 char *buf) 525 char *buf)
539{ 526{
540 struct iio_dev *indio_dev = dev_get_drvdata(dev); 527 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
541 struct ad7793_state *st = iio_priv(indio_dev); 528 struct ad7793_state *st = iio_priv(indio_dev);
542 529
543 return sprintf(buf, "%d\n", 530 return sprintf(buf, "%d\n",
@@ -549,7 +536,7 @@ static ssize_t ad7793_write_frequency(struct device *dev,
549 const char *buf, 536 const char *buf,
550 size_t len) 537 size_t len)
551{ 538{
552 struct iio_dev *indio_dev = dev_get_drvdata(dev); 539 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
553 struct ad7793_state *st = iio_priv(indio_dev); 540 struct ad7793_state *st = iio_priv(indio_dev);
554 long lval; 541 long lval;
555 int i, ret; 542 int i, ret;
@@ -591,7 +578,7 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
591static ssize_t ad7793_show_scale_available(struct device *dev, 578static ssize_t ad7793_show_scale_available(struct device *dev,
592 struct device_attribute *attr, char *buf) 579 struct device_attribute *attr, char *buf)
593{ 580{
594 struct iio_dev *indio_dev = dev_get_drvdata(dev); 581 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
595 struct ad7793_state *st = iio_priv(indio_dev); 582 struct ad7793_state *st = iio_priv(indio_dev);
596 int i, len = 0; 583 int i, len = 0;
597 584
@@ -630,7 +617,7 @@ static int ad7793_read_raw(struct iio_dev *indio_dev,
630 bool unipolar = !!(st->conf & AD7793_CONF_UNIPOLAR); 617 bool unipolar = !!(st->conf & AD7793_CONF_UNIPOLAR);
631 618
632 switch (m) { 619 switch (m) {
633 case 0: 620 case IIO_CHAN_INFO_RAW:
634 mutex_lock(&indio_dev->mlock); 621 mutex_lock(&indio_dev->mlock);
635 if (iio_buffer_enabled(indio_dev)) 622 if (iio_buffer_enabled(indio_dev))
636 ret = -EBUSY; 623 ret = -EBUSY;
@@ -760,7 +747,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
760 .channel = 0, 747 .channel = 0,
761 .channel2 = 0, 748 .channel2 = 0,
762 .address = AD7793_CH_AIN1P_AIN1M, 749 .address = AD7793_CH_AIN1P_AIN1M,
763 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 750 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
751 IIO_CHAN_INFO_SCALE_SHARED_BIT,
764 .scan_index = 0, 752 .scan_index = 0,
765 .scan_type = IIO_ST('s', 24, 32, 0) 753 .scan_type = IIO_ST('s', 24, 32, 0)
766 }, 754 },
@@ -771,7 +759,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
771 .channel = 1, 759 .channel = 1,
772 .channel2 = 1, 760 .channel2 = 1,
773 .address = AD7793_CH_AIN2P_AIN2M, 761 .address = AD7793_CH_AIN2P_AIN2M,
774 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 762 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
763 IIO_CHAN_INFO_SCALE_SHARED_BIT,
775 .scan_index = 1, 764 .scan_index = 1,
776 .scan_type = IIO_ST('s', 24, 32, 0) 765 .scan_type = IIO_ST('s', 24, 32, 0)
777 }, 766 },
@@ -782,7 +771,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
782 .channel = 2, 771 .channel = 2,
783 .channel2 = 2, 772 .channel2 = 2,
784 .address = AD7793_CH_AIN3P_AIN3M, 773 .address = AD7793_CH_AIN3P_AIN3M,
785 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 774 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
775 IIO_CHAN_INFO_SCALE_SHARED_BIT,
786 .scan_index = 2, 776 .scan_index = 2,
787 .scan_type = IIO_ST('s', 24, 32, 0) 777 .scan_type = IIO_ST('s', 24, 32, 0)
788 }, 778 },
@@ -794,7 +784,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
794 .channel = 2, 784 .channel = 2,
795 .channel2 = 2, 785 .channel2 = 2,
796 .address = AD7793_CH_AIN1M_AIN1M, 786 .address = AD7793_CH_AIN1M_AIN1M,
797 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 787 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
788 IIO_CHAN_INFO_SCALE_SHARED_BIT,
798 .scan_index = 2, 789 .scan_index = 2,
799 .scan_type = IIO_ST('s', 24, 32, 0) 790 .scan_type = IIO_ST('s', 24, 32, 0)
800 }, 791 },
@@ -803,7 +794,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
803 .indexed = 1, 794 .indexed = 1,
804 .channel = 0, 795 .channel = 0,
805 .address = AD7793_CH_TEMP, 796 .address = AD7793_CH_TEMP,
806 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 797 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
798 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
807 .scan_index = 4, 799 .scan_index = 4,
808 .scan_type = IIO_ST('s', 24, 32, 0), 800 .scan_type = IIO_ST('s', 24, 32, 0),
809 }, 801 },
@@ -813,7 +805,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
813 .indexed = 1, 805 .indexed = 1,
814 .channel = 4, 806 .channel = 4,
815 .address = AD7793_CH_AVDD_MONITOR, 807 .address = AD7793_CH_AVDD_MONITOR,
816 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 808 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
809 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
817 .scan_index = 5, 810 .scan_index = 5,
818 .scan_type = IIO_ST('s', 24, 32, 0), 811 .scan_type = IIO_ST('s', 24, 32, 0),
819 }, 812 },
@@ -827,7 +820,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
827 .channel = 0, 820 .channel = 0,
828 .channel2 = 0, 821 .channel2 = 0,
829 .address = AD7793_CH_AIN1P_AIN1M, 822 .address = AD7793_CH_AIN1P_AIN1M,
830 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 823 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
824 IIO_CHAN_INFO_SCALE_SHARED_BIT,
831 .scan_index = 0, 825 .scan_index = 0,
832 .scan_type = IIO_ST('s', 16, 32, 0) 826 .scan_type = IIO_ST('s', 16, 32, 0)
833 }, 827 },
@@ -838,7 +832,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
838 .channel = 1, 832 .channel = 1,
839 .channel2 = 1, 833 .channel2 = 1,
840 .address = AD7793_CH_AIN2P_AIN2M, 834 .address = AD7793_CH_AIN2P_AIN2M,
841 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 835 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
836 IIO_CHAN_INFO_SCALE_SHARED_BIT,
842 .scan_index = 1, 837 .scan_index = 1,
843 .scan_type = IIO_ST('s', 16, 32, 0) 838 .scan_type = IIO_ST('s', 16, 32, 0)
844 }, 839 },
@@ -849,7 +844,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
849 .channel = 2, 844 .channel = 2,
850 .channel2 = 2, 845 .channel2 = 2,
851 .address = AD7793_CH_AIN3P_AIN3M, 846 .address = AD7793_CH_AIN3P_AIN3M,
852 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 847 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
848 IIO_CHAN_INFO_SCALE_SHARED_BIT,
853 .scan_index = 2, 849 .scan_index = 2,
854 .scan_type = IIO_ST('s', 16, 32, 0) 850 .scan_type = IIO_ST('s', 16, 32, 0)
855 }, 851 },
@@ -861,7 +857,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
861 .channel = 2, 857 .channel = 2,
862 .channel2 = 2, 858 .channel2 = 2,
863 .address = AD7793_CH_AIN1M_AIN1M, 859 .address = AD7793_CH_AIN1M_AIN1M,
864 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 860 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
861 IIO_CHAN_INFO_SCALE_SHARED_BIT,
865 .scan_index = 2, 862 .scan_index = 2,
866 .scan_type = IIO_ST('s', 16, 32, 0) 863 .scan_type = IIO_ST('s', 16, 32, 0)
867 }, 864 },
@@ -870,7 +867,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
870 .indexed = 1, 867 .indexed = 1,
871 .channel = 0, 868 .channel = 0,
872 .address = AD7793_CH_TEMP, 869 .address = AD7793_CH_TEMP,
873 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 870 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
871 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
874 .scan_index = 4, 872 .scan_index = 4,
875 .scan_type = IIO_ST('s', 16, 32, 0), 873 .scan_type = IIO_ST('s', 16, 32, 0),
876 }, 874 },
@@ -880,7 +878,8 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
880 .indexed = 1, 878 .indexed = 1,
881 .channel = 4, 879 .channel = 4,
882 .address = AD7793_CH_AVDD_MONITOR, 880 .address = AD7793_CH_AVDD_MONITOR,
883 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 881 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
882 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
884 .scan_index = 5, 883 .scan_index = 5,
885 .scan_type = IIO_ST('s', 16, 32, 0), 884 .scan_type = IIO_ST('s', 16, 32, 0),
886 }, 885 },
@@ -905,7 +904,7 @@ static int __devinit ad7793_probe(struct spi_device *spi)
905 return -ENODEV; 904 return -ENODEV;
906 } 905 }
907 906
908 indio_dev = iio_allocate_device(sizeof(*st)); 907 indio_dev = iio_device_alloc(sizeof(*st));
909 if (indio_dev == NULL) 908 if (indio_dev == NULL)
910 return -ENOMEM; 909 return -ENOMEM;
911 910
@@ -989,7 +988,7 @@ error_put_reg:
989 if (!IS_ERR(st->reg)) 988 if (!IS_ERR(st->reg))
990 regulator_put(st->reg); 989 regulator_put(st->reg);
991 990
992 iio_free_device(indio_dev); 991 iio_device_free(indio_dev);
993 992
994 return ret; 993 return ret;
995} 994}
@@ -1009,7 +1008,7 @@ static int ad7793_remove(struct spi_device *spi)
1009 regulator_put(st->reg); 1008 regulator_put(st->reg);
1010 } 1009 }
1011 1010
1012 iio_free_device(indio_dev); 1011 iio_device_free(indio_dev);
1013 1012
1014 return 0; 1013 return 0;
1015} 1014}
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 52b720e2b03a..5356b091b08f 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -16,9 +16,9 @@
16#include <linux/spi/spi.h> 16#include <linux/spi/spi.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../events.h" 21#include <linux/iio/events.h>
22 22
23/* 23/*
24 * AD7816 config masks 24 * AD7816 config masks
@@ -113,7 +113,7 @@ static ssize_t ad7816_show_mode(struct device *dev,
113 struct device_attribute *attr, 113 struct device_attribute *attr,
114 char *buf) 114 char *buf)
115{ 115{
116 struct iio_dev *indio_dev = dev_get_drvdata(dev); 116 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
117 struct ad7816_chip_info *chip = iio_priv(indio_dev); 117 struct ad7816_chip_info *chip = iio_priv(indio_dev);
118 118
119 if (chip->mode) 119 if (chip->mode)
@@ -127,7 +127,7 @@ static ssize_t ad7816_store_mode(struct device *dev,
127 const char *buf, 127 const char *buf,
128 size_t len) 128 size_t len)
129{ 129{
130 struct iio_dev *indio_dev = dev_get_drvdata(dev); 130 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
131 struct ad7816_chip_info *chip = iio_priv(indio_dev); 131 struct ad7816_chip_info *chip = iio_priv(indio_dev);
132 132
133 if (strcmp(buf, "full")) { 133 if (strcmp(buf, "full")) {
@@ -159,7 +159,7 @@ static ssize_t ad7816_show_channel(struct device *dev,
159 struct device_attribute *attr, 159 struct device_attribute *attr,
160 char *buf) 160 char *buf)
161{ 161{
162 struct iio_dev *indio_dev = dev_get_drvdata(dev); 162 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
163 struct ad7816_chip_info *chip = iio_priv(indio_dev); 163 struct ad7816_chip_info *chip = iio_priv(indio_dev);
164 164
165 return sprintf(buf, "%d\n", chip->channel_id); 165 return sprintf(buf, "%d\n", chip->channel_id);
@@ -170,7 +170,7 @@ static ssize_t ad7816_store_channel(struct device *dev,
170 const char *buf, 170 const char *buf,
171 size_t len) 171 size_t len)
172{ 172{
173 struct iio_dev *indio_dev = dev_get_drvdata(dev); 173 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
174 struct ad7816_chip_info *chip = iio_priv(indio_dev); 174 struct ad7816_chip_info *chip = iio_priv(indio_dev);
175 unsigned long data; 175 unsigned long data;
176 int ret; 176 int ret;
@@ -208,7 +208,7 @@ static ssize_t ad7816_show_value(struct device *dev,
208 struct device_attribute *attr, 208 struct device_attribute *attr,
209 char *buf) 209 char *buf)
210{ 210{
211 struct iio_dev *indio_dev = dev_get_drvdata(dev); 211 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
212 struct ad7816_chip_info *chip = iio_priv(indio_dev); 212 struct ad7816_chip_info *chip = iio_priv(indio_dev);
213 u16 data; 213 u16 data;
214 s8 value; 214 s8 value;
@@ -263,7 +263,7 @@ static ssize_t ad7816_show_oti(struct device *dev,
263 struct device_attribute *attr, 263 struct device_attribute *attr,
264 char *buf) 264 char *buf)
265{ 265{
266 struct iio_dev *indio_dev = dev_get_drvdata(dev); 266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267 struct ad7816_chip_info *chip = iio_priv(indio_dev); 267 struct ad7816_chip_info *chip = iio_priv(indio_dev);
268 int value; 268 int value;
269 269
@@ -284,7 +284,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev,
284 const char *buf, 284 const char *buf,
285 size_t len) 285 size_t len)
286{ 286{
287 struct iio_dev *indio_dev = dev_get_drvdata(dev); 287 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
288 struct ad7816_chip_info *chip = iio_priv(indio_dev); 288 struct ad7816_chip_info *chip = iio_priv(indio_dev);
289 long value; 289 long value;
290 u8 data; 290 u8 data;
@@ -354,7 +354,7 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
354 return -EINVAL; 354 return -EINVAL;
355 } 355 }
356 356
357 indio_dev = iio_allocate_device(sizeof(*chip)); 357 indio_dev = iio_device_alloc(sizeof(*chip));
358 if (indio_dev == NULL) { 358 if (indio_dev == NULL) {
359 ret = -ENOMEM; 359 ret = -ENOMEM;
360 goto error_ret; 360 goto error_ret;
@@ -426,7 +426,7 @@ error_free_gpio_convert:
426error_free_gpio_rdwr: 426error_free_gpio_rdwr:
427 gpio_free(chip->rdwr_pin); 427 gpio_free(chip->rdwr_pin);
428error_free_device: 428error_free_device:
429 iio_free_device(indio_dev); 429 iio_device_free(indio_dev);
430error_ret: 430error_ret:
431 return ret; 431 return ret;
432} 432}
@@ -443,7 +443,7 @@ static int __devexit ad7816_remove(struct spi_device *spi_dev)
443 gpio_free(chip->busy_pin); 443 gpio_free(chip->busy_pin);
444 gpio_free(chip->convert_pin); 444 gpio_free(chip->convert_pin);
445 gpio_free(chip->rdwr_pin); 445 gpio_free(chip->rdwr_pin);
446 iio_free_device(indio_dev); 446 iio_device_free(indio_dev);
447 447
448 return 0; 448 return 0;
449} 449}
diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
index bc53b6532121..2e09e54fc9c5 100644
--- a/drivers/staging/iio/adc/ad7887.h
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -63,7 +63,6 @@ struct ad7887_state {
63 struct spi_device *spi; 63 struct spi_device *spi;
64 const struct ad7887_chip_info *chip_info; 64 const struct ad7887_chip_info *chip_info;
65 struct regulator *reg; 65 struct regulator *reg;
66 size_t d_size;
67 u16 int_vref_mv; 66 u16 int_vref_mv;
68 struct spi_transfer xfer[4]; 67 struct spi_transfer xfer[4];
69 struct spi_message msg[3]; 68 struct spi_message msg[3];
diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
index e9bbc3eed15d..7186074deeb3 100644
--- a/drivers/staging/iio/adc/ad7887_core.c
+++ b/drivers/staging/iio/adc/ad7887_core.c
@@ -15,9 +15,9 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../buffer.h" 20#include <linux/iio/buffer.h>
21 21
22 22
23#include "ad7887.h" 23#include "ad7887.h"
@@ -42,7 +42,7 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
42 unsigned int scale_uv; 42 unsigned int scale_uv;
43 43
44 switch (m) { 44 switch (m) {
45 case 0: 45 case IIO_CHAN_INFO_RAW:
46 mutex_lock(&indio_dev->mlock); 46 mutex_lock(&indio_dev->mlock);
47 if (iio_buffer_enabled(indio_dev)) 47 if (iio_buffer_enabled(indio_dev))
48 ret = -EBUSY; 48 ret = -EBUSY;
@@ -75,7 +75,8 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
75 .type = IIO_VOLTAGE, 75 .type = IIO_VOLTAGE,
76 .indexed = 1, 76 .indexed = 1,
77 .channel = 1, 77 .channel = 1,
78 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 78 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
79 IIO_CHAN_INFO_SCALE_SHARED_BIT,
79 .address = 1, 80 .address = 1,
80 .scan_index = 1, 81 .scan_index = 1,
81 .scan_type = IIO_ST('u', 12, 16, 0), 82 .scan_type = IIO_ST('u', 12, 16, 0),
@@ -84,7 +85,8 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
84 .type = IIO_VOLTAGE, 85 .type = IIO_VOLTAGE,
85 .indexed = 1, 86 .indexed = 1,
86 .channel = 0, 87 .channel = 0,
87 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 88 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
89 IIO_CHAN_INFO_SCALE_SHARED_BIT,
88 .address = 0, 90 .address = 0,
89 .scan_index = 0, 91 .scan_index = 0,
90 .scan_type = IIO_ST('u', 12, 16, 0), 92 .scan_type = IIO_ST('u', 12, 16, 0),
@@ -104,7 +106,7 @@ static int __devinit ad7887_probe(struct spi_device *spi)
104 struct ad7887_platform_data *pdata = spi->dev.platform_data; 106 struct ad7887_platform_data *pdata = spi->dev.platform_data;
105 struct ad7887_state *st; 107 struct ad7887_state *st;
106 int ret, voltage_uv = 0; 108 int ret, voltage_uv = 0;
107 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 109 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
108 110
109 if (indio_dev == NULL) 111 if (indio_dev == NULL)
110 return -ENOMEM; 112 return -ENOMEM;
@@ -220,7 +222,7 @@ error_disable_reg:
220error_put_reg: 222error_put_reg:
221 if (!IS_ERR(st->reg)) 223 if (!IS_ERR(st->reg))
222 regulator_put(st->reg); 224 regulator_put(st->reg);
223 iio_free_device(indio_dev); 225 iio_device_free(indio_dev);
224 226
225 return ret; 227 return ret;
226} 228}
@@ -237,7 +239,7 @@ static int ad7887_remove(struct spi_device *spi)
237 regulator_disable(st->reg); 239 regulator_disable(st->reg);
238 regulator_put(st->reg); 240 regulator_put(st->reg);
239 } 241 }
240 iio_free_device(indio_dev); 242 iio_device_free(indio_dev);
241 243
242 return 0; 244 return 0;
243} 245}
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index d1809079b63d..fd91384db894 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2010-2011 Analog Devices Inc. 2 * Copyright 2010-2012 Analog Devices Inc.
3 * Copyright (C) 2008 Jonathan Cameron 3 * Copyright (C) 2008 Jonathan Cameron
4 * 4 *
5 * Licensed under the GPL-2. 5 * Licensed under the GPL-2.
@@ -12,10 +12,10 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/spi/spi.h> 13#include <linux/spi/spi.h>
14 14
15#include "../iio.h" 15#include <linux/iio/iio.h>
16#include "../buffer.h" 16#include <linux/iio/buffer.h>
17#include "../ring_sw.h" 17#include <linux/iio/kfifo_buf.h>
18#include "../trigger_consumer.h" 18#include <linux/iio/trigger_consumer.h>
19 19
20#include "ad7887.h" 20#include "ad7887.h"
21 21
@@ -29,22 +29,11 @@
29static int ad7887_ring_preenable(struct iio_dev *indio_dev) 29static int ad7887_ring_preenable(struct iio_dev *indio_dev)
30{ 30{
31 struct ad7887_state *st = iio_priv(indio_dev); 31 struct ad7887_state *st = iio_priv(indio_dev);
32 struct iio_buffer *ring = indio_dev->buffer; 32 int ret;
33
34 st->d_size = bitmap_weight(indio_dev->active_scan_mask,
35 indio_dev->masklength) *
36 st->chip_info->channel[0].scan_type.storagebits / 8;
37
38 if (ring->scan_timestamp) {
39 st->d_size += sizeof(s64);
40
41 if (st->d_size % sizeof(s64))
42 st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
43 }
44 33
45 if (indio_dev->buffer->access->set_bytes_per_datum) 34 ret = iio_sw_buffer_preenable(indio_dev);
46 indio_dev->buffer->access-> 35 if (ret < 0)
47 set_bytes_per_datum(indio_dev->buffer, st->d_size); 36 return ret;
48 37
49 /* We know this is a single long so can 'cheat' */ 38 /* We know this is a single long so can 'cheat' */
50 switch (*indio_dev->active_scan_mask) { 39 switch (*indio_dev->active_scan_mask) {
@@ -83,7 +72,6 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
83 struct iio_poll_func *pf = p; 72 struct iio_poll_func *pf = p;
84 struct iio_dev *indio_dev = pf->indio_dev; 73 struct iio_dev *indio_dev = pf->indio_dev;
85 struct ad7887_state *st = iio_priv(indio_dev); 74 struct ad7887_state *st = iio_priv(indio_dev);
86 struct iio_buffer *ring = indio_dev->buffer;
87 s64 time_ns; 75 s64 time_ns;
88 __u8 *buf; 76 __u8 *buf;
89 int b_sent; 77 int b_sent;
@@ -92,7 +80,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
92 indio_dev->masklength) * 80 indio_dev->masklength) *
93 st->chip_info->channel[0].scan_type.storagebits / 8; 81 st->chip_info->channel[0].scan_type.storagebits / 8;
94 82
95 buf = kzalloc(st->d_size, GFP_KERNEL); 83 buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
96 if (buf == NULL) 84 if (buf == NULL)
97 return -ENOMEM; 85 return -ENOMEM;
98 86
@@ -103,8 +91,8 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
103 time_ns = iio_get_time_ns(); 91 time_ns = iio_get_time_ns();
104 92
105 memcpy(buf, st->data, bytes); 93 memcpy(buf, st->data, bytes);
106 if (ring->scan_timestamp) 94 if (indio_dev->scan_timestamp)
107 memcpy(buf + st->d_size - sizeof(s64), 95 memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
108 &time_ns, sizeof(time_ns)); 96 &time_ns, sizeof(time_ns));
109 97
110 indio_dev->buffer->access->store_to(indio_dev->buffer, buf, time_ns); 98 indio_dev->buffer->access->store_to(indio_dev->buffer, buf, time_ns);
@@ -126,7 +114,7 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
126{ 114{
127 int ret; 115 int ret;
128 116
129 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 117 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
130 if (!indio_dev->buffer) { 118 if (!indio_dev->buffer) {
131 ret = -ENOMEM; 119 ret = -ENOMEM;
132 goto error_ret; 120 goto error_ret;
@@ -139,7 +127,7 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
139 indio_dev->id); 127 indio_dev->id);
140 if (indio_dev->pollfunc == NULL) { 128 if (indio_dev->pollfunc == NULL) {
141 ret = -ENOMEM; 129 ret = -ENOMEM;
142 goto error_deallocate_sw_rb; 130 goto error_deallocate_kfifo;
143 } 131 }
144 /* Ring buffer functions - here trigger setup related */ 132 /* Ring buffer functions - here trigger setup related */
145 indio_dev->setup_ops = &ad7887_ring_setup_ops; 133 indio_dev->setup_ops = &ad7887_ring_setup_ops;
@@ -148,8 +136,8 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
148 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 136 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
149 return 0; 137 return 0;
150 138
151error_deallocate_sw_rb: 139error_deallocate_kfifo:
152 iio_sw_rb_free(indio_dev->buffer); 140 iio_kfifo_free(indio_dev->buffer);
153error_ret: 141error_ret:
154 return ret; 142 return ret;
155} 143}
@@ -157,5 +145,5 @@ error_ret:
157void ad7887_ring_cleanup(struct iio_dev *indio_dev) 145void ad7887_ring_cleanup(struct iio_dev *indio_dev)
158{ 146{
159 iio_dealloc_pollfunc(indio_dev->pollfunc); 147 iio_dealloc_pollfunc(indio_dev->pollfunc);
160 iio_sw_rb_free(indio_dev->buffer); 148 iio_kfifo_free(indio_dev->buffer);
161} 149}
diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index 356f690a76fb..99f8abe9731b 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -104,7 +104,6 @@ struct ad799x_chip_info {
104struct ad799x_state { 104struct ad799x_state {
105 struct i2c_client *client; 105 struct i2c_client *client;
106 const struct ad799x_chip_info *chip_info; 106 const struct ad799x_chip_info *chip_info;
107 size_t d_size;
108 struct iio_trigger *trig; 107 struct iio_trigger *trig;
109 struct regulator *reg; 108 struct regulator *reg;
110 u16 int_vref_mv; 109 u16 int_vref_mv;
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index a8458669350f..80e0c6e25a9b 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -33,10 +33,10 @@
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/module.h> 34#include <linux/module.h>
35 35
36#include "../iio.h" 36#include <linux/iio/iio.h>
37#include "../sysfs.h" 37#include <linux/iio/sysfs.h>
38#include "../events.h" 38#include <linux/iio/events.h>
39#include "../buffer.h" 39#include <linux/iio/buffer.h>
40 40
41#include "ad799x.h" 41#include "ad799x.h"
42 42
@@ -148,7 +148,7 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
148 unsigned int scale_uv; 148 unsigned int scale_uv;
149 149
150 switch (m) { 150 switch (m) {
151 case 0: 151 case IIO_CHAN_INFO_RAW:
152 mutex_lock(&indio_dev->mlock); 152 mutex_lock(&indio_dev->mlock);
153 if (iio_buffer_enabled(indio_dev)) 153 if (iio_buffer_enabled(indio_dev))
154 ret = -EBUSY; 154 ret = -EBUSY;
@@ -182,7 +182,7 @@ static ssize_t ad799x_read_frequency(struct device *dev,
182 struct device_attribute *attr, 182 struct device_attribute *attr,
183 char *buf) 183 char *buf)
184{ 184{
185 struct iio_dev *indio_dev = dev_get_drvdata(dev); 185 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
186 struct ad799x_state *st = iio_priv(indio_dev); 186 struct ad799x_state *st = iio_priv(indio_dev);
187 187
188 int ret; 188 int ret;
@@ -201,7 +201,7 @@ static ssize_t ad799x_write_frequency(struct device *dev,
201 const char *buf, 201 const char *buf,
202 size_t len) 202 size_t len)
203{ 203{
204 struct iio_dev *indio_dev = dev_get_drvdata(dev); 204 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
205 struct ad799x_state *st = iio_priv(indio_dev); 205 struct ad799x_state *st = iio_priv(indio_dev);
206 206
207 long val; 207 long val;
@@ -294,7 +294,7 @@ static ssize_t ad799x_read_channel_config(struct device *dev,
294 struct device_attribute *attr, 294 struct device_attribute *attr,
295 char *buf) 295 char *buf)
296{ 296{
297 struct iio_dev *indio_dev = dev_get_drvdata(dev); 297 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
298 struct ad799x_state *st = iio_priv(indio_dev); 298 struct ad799x_state *st = iio_priv(indio_dev);
299 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 299 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
300 300
@@ -312,7 +312,7 @@ static ssize_t ad799x_write_channel_config(struct device *dev,
312 const char *buf, 312 const char *buf,
313 size_t len) 313 size_t len)
314{ 314{
315 struct iio_dev *indio_dev = dev_get_drvdata(dev); 315 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
316 struct ad799x_state *st = iio_priv(indio_dev); 316 struct ad799x_state *st = iio_priv(indio_dev);
317 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 317 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
318 318
@@ -454,6 +454,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
454 .type = IIO_VOLTAGE, 454 .type = IIO_VOLTAGE,
455 .indexed = 1, 455 .indexed = 1,
456 .channel = 0, 456 .channel = 0,
457 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
457 .scan_index = 0, 458 .scan_index = 0,
458 .scan_type = IIO_ST('u', 12, 16, 0), 459 .scan_type = IIO_ST('u', 12, 16, 0),
459 }, 460 },
@@ -461,6 +462,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
461 .type = IIO_VOLTAGE, 462 .type = IIO_VOLTAGE,
462 .indexed = 1, 463 .indexed = 1,
463 .channel = 1, 464 .channel = 1,
465 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
464 .scan_index = 1, 466 .scan_index = 1,
465 .scan_type = IIO_ST('u', 12, 16, 0), 467 .scan_type = IIO_ST('u', 12, 16, 0),
466 }, 468 },
@@ -468,6 +470,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
468 .type = IIO_VOLTAGE, 470 .type = IIO_VOLTAGE,
469 .indexed = 1, 471 .indexed = 1,
470 .channel = 2, 472 .channel = 2,
473 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
471 .scan_index = 2, 474 .scan_index = 2,
472 .scan_type = IIO_ST('u', 12, 16, 0), 475 .scan_type = IIO_ST('u', 12, 16, 0),
473 }, 476 },
@@ -475,6 +478,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
475 .type = IIO_VOLTAGE, 478 .type = IIO_VOLTAGE,
476 .indexed = 1, 479 .indexed = 1,
477 .channel = 3, 480 .channel = 3,
481 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
478 .scan_index = 3, 482 .scan_index = 3,
479 .scan_type = IIO_ST('u', 12, 16, 0), 483 .scan_type = IIO_ST('u', 12, 16, 0),
480 }, 484 },
@@ -490,6 +494,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
490 .type = IIO_VOLTAGE, 494 .type = IIO_VOLTAGE,
491 .indexed = 1, 495 .indexed = 1,
492 .channel = 0, 496 .channel = 0,
497 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
493 .scan_index = 0, 498 .scan_index = 0,
494 .scan_type = IIO_ST('u', 10, 16, 2), 499 .scan_type = IIO_ST('u', 10, 16, 2),
495 }, 500 },
@@ -497,6 +502,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
497 .type = IIO_VOLTAGE, 502 .type = IIO_VOLTAGE,
498 .indexed = 1, 503 .indexed = 1,
499 .channel = 1, 504 .channel = 1,
505 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
500 .scan_index = 1, 506 .scan_index = 1,
501 .scan_type = IIO_ST('u', 10, 16, 2), 507 .scan_type = IIO_ST('u', 10, 16, 2),
502 }, 508 },
@@ -504,6 +510,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
504 .type = IIO_VOLTAGE, 510 .type = IIO_VOLTAGE,
505 .indexed = 1, 511 .indexed = 1,
506 .channel = 2, 512 .channel = 2,
513 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
507 .scan_index = 2, 514 .scan_index = 2,
508 .scan_type = IIO_ST('u', 10, 16, 2), 515 .scan_type = IIO_ST('u', 10, 16, 2),
509 }, 516 },
@@ -511,6 +518,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
511 .type = IIO_VOLTAGE, 518 .type = IIO_VOLTAGE,
512 .indexed = 1, 519 .indexed = 1,
513 .channel = 3, 520 .channel = 3,
521 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
514 .scan_index = 3, 522 .scan_index = 3,
515 .scan_type = IIO_ST('u', 10, 16, 2), 523 .scan_type = IIO_ST('u', 10, 16, 2),
516 }, 524 },
@@ -526,6 +534,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
526 .type = IIO_VOLTAGE, 534 .type = IIO_VOLTAGE,
527 .indexed = 1, 535 .indexed = 1,
528 .channel = 0, 536 .channel = 0,
537 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
529 .scan_index = 0, 538 .scan_index = 0,
530 .scan_type = IIO_ST('u', 8, 16, 4), 539 .scan_type = IIO_ST('u', 8, 16, 4),
531 }, 540 },
@@ -533,6 +542,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
533 .type = IIO_VOLTAGE, 542 .type = IIO_VOLTAGE,
534 .indexed = 1, 543 .indexed = 1,
535 .channel = 1, 544 .channel = 1,
545 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
536 .scan_index = 1, 546 .scan_index = 1,
537 .scan_type = IIO_ST('u', 8, 16, 4), 547 .scan_type = IIO_ST('u', 8, 16, 4),
538 }, 548 },
@@ -540,6 +550,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
540 .type = IIO_VOLTAGE, 550 .type = IIO_VOLTAGE,
541 .indexed = 1, 551 .indexed = 1,
542 .channel = 2, 552 .channel = 2,
553 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
543 .scan_index = 2, 554 .scan_index = 2,
544 .scan_type = IIO_ST('u', 8, 16, 4), 555 .scan_type = IIO_ST('u', 8, 16, 4),
545 }, 556 },
@@ -547,6 +558,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
547 .type = IIO_VOLTAGE, 558 .type = IIO_VOLTAGE,
548 .indexed = 1, 559 .indexed = 1,
549 .channel = 3, 560 .channel = 3,
561 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
550 .scan_index = 3, 562 .scan_index = 3,
551 .scan_type = IIO_ST('u', 8, 16, 4), 563 .scan_type = IIO_ST('u', 8, 16, 4),
552 }, 564 },
@@ -562,6 +574,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
562 .type = IIO_VOLTAGE, 574 .type = IIO_VOLTAGE,
563 .indexed = 1, 575 .indexed = 1,
564 .channel = 0, 576 .channel = 0,
577 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
565 .scan_index = 0, 578 .scan_index = 0,
566 .scan_type = IIO_ST('u', 12, 16, 0), 579 .scan_type = IIO_ST('u', 12, 16, 0),
567 .event_mask = AD799X_EV_MASK, 580 .event_mask = AD799X_EV_MASK,
@@ -570,6 +583,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
570 .type = IIO_VOLTAGE, 583 .type = IIO_VOLTAGE,
571 .indexed = 1, 584 .indexed = 1,
572 .channel = 1, 585 .channel = 1,
586 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
573 .scan_index = 1, 587 .scan_index = 1,
574 .scan_type = IIO_ST('u', 12, 16, 0), 588 .scan_type = IIO_ST('u', 12, 16, 0),
575 .event_mask = AD799X_EV_MASK, 589 .event_mask = AD799X_EV_MASK,
@@ -587,6 +601,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
587 .type = IIO_VOLTAGE, 601 .type = IIO_VOLTAGE,
588 .indexed = 1, 602 .indexed = 1,
589 .channel = 0, 603 .channel = 0,
604 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
590 .scan_index = 0, 605 .scan_index = 0,
591 .scan_type = IIO_ST('u', 10, 16, 2), 606 .scan_type = IIO_ST('u', 10, 16, 2),
592 .event_mask = AD799X_EV_MASK, 607 .event_mask = AD799X_EV_MASK,
@@ -596,6 +611,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
596 .indexed = 1, 611 .indexed = 1,
597 .channel = 1, 612 .channel = 1,
598 .scan_index = 1, 613 .scan_index = 1,
614 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
599 .scan_type = IIO_ST('u', 10, 16, 2), 615 .scan_type = IIO_ST('u', 10, 16, 2),
600 .event_mask = AD799X_EV_MASK, 616 .event_mask = AD799X_EV_MASK,
601 }, 617 },
@@ -603,6 +619,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
603 .type = IIO_VOLTAGE, 619 .type = IIO_VOLTAGE,
604 .indexed = 1, 620 .indexed = 1,
605 .channel = 2, 621 .channel = 2,
622 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
606 .scan_index = 2, 623 .scan_index = 2,
607 .scan_type = IIO_ST('u', 10, 16, 2), 624 .scan_type = IIO_ST('u', 10, 16, 2),
608 .event_mask = AD799X_EV_MASK, 625 .event_mask = AD799X_EV_MASK,
@@ -611,6 +628,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
611 .type = IIO_VOLTAGE, 628 .type = IIO_VOLTAGE,
612 .indexed = 1, 629 .indexed = 1,
613 .channel = 3, 630 .channel = 3,
631 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
614 .scan_index = 3, 632 .scan_index = 3,
615 .scan_type = IIO_ST('u', 10, 16, 2), 633 .scan_type = IIO_ST('u', 10, 16, 2),
616 .event_mask = AD799X_EV_MASK, 634 .event_mask = AD799X_EV_MASK,
@@ -628,6 +646,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
628 .type = IIO_VOLTAGE, 646 .type = IIO_VOLTAGE,
629 .indexed = 1, 647 .indexed = 1,
630 .channel = 0, 648 .channel = 0,
649 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
631 .scan_index = 0, 650 .scan_index = 0,
632 .scan_type = IIO_ST('u', 12, 16, 0), 651 .scan_type = IIO_ST('u', 12, 16, 0),
633 .event_mask = AD799X_EV_MASK, 652 .event_mask = AD799X_EV_MASK,
@@ -636,6 +655,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
636 .type = IIO_VOLTAGE, 655 .type = IIO_VOLTAGE,
637 .indexed = 1, 656 .indexed = 1,
638 .channel = 1, 657 .channel = 1,
658 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
639 .scan_index = 1, 659 .scan_index = 1,
640 .scan_type = IIO_ST('u', 12, 16, 0), 660 .scan_type = IIO_ST('u', 12, 16, 0),
641 .event_mask = AD799X_EV_MASK, 661 .event_mask = AD799X_EV_MASK,
@@ -644,6 +664,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
644 .type = IIO_VOLTAGE, 664 .type = IIO_VOLTAGE,
645 .indexed = 1, 665 .indexed = 1,
646 .channel = 2, 666 .channel = 2,
667 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
647 .scan_index = 2, 668 .scan_index = 2,
648 .scan_type = IIO_ST('u', 12, 16, 0), 669 .scan_type = IIO_ST('u', 12, 16, 0),
649 .event_mask = AD799X_EV_MASK, 670 .event_mask = AD799X_EV_MASK,
@@ -652,6 +673,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
652 .type = IIO_VOLTAGE, 673 .type = IIO_VOLTAGE,
653 .indexed = 1, 674 .indexed = 1,
654 .channel = 3, 675 .channel = 3,
676 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
655 .scan_index = 3, 677 .scan_index = 3,
656 .scan_type = IIO_ST('u', 12, 16, 0), 678 .scan_type = IIO_ST('u', 12, 16, 0),
657 .event_mask = AD799X_EV_MASK, 679 .event_mask = AD799X_EV_MASK,
@@ -669,6 +691,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
669 .type = IIO_VOLTAGE, 691 .type = IIO_VOLTAGE,
670 .indexed = 1, 692 .indexed = 1,
671 .channel = 0, 693 .channel = 0,
694 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
672 .scan_index = 0, 695 .scan_index = 0,
673 .scan_type = IIO_ST('u', 10, 16, 2), 696 .scan_type = IIO_ST('u', 10, 16, 2),
674 .event_mask = AD799X_EV_MASK, 697 .event_mask = AD799X_EV_MASK,
@@ -677,6 +700,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
677 .type = IIO_VOLTAGE, 700 .type = IIO_VOLTAGE,
678 .indexed = 1, 701 .indexed = 1,
679 .channel = 1, 702 .channel = 1,
703 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
680 .scan_index = 1, 704 .scan_index = 1,
681 .scan_type = IIO_ST('u', 10, 16, 2), 705 .scan_type = IIO_ST('u', 10, 16, 2),
682 .event_mask = AD799X_EV_MASK, 706 .event_mask = AD799X_EV_MASK,
@@ -685,6 +709,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
685 .type = IIO_VOLTAGE, 709 .type = IIO_VOLTAGE,
686 .indexed = 1, 710 .indexed = 1,
687 .channel = 2, 711 .channel = 2,
712 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
688 .scan_index = 2, 713 .scan_index = 2,
689 .scan_type = IIO_ST('u', 10, 16, 2), 714 .scan_type = IIO_ST('u', 10, 16, 2),
690 .event_mask = AD799X_EV_MASK, 715 .event_mask = AD799X_EV_MASK,
@@ -693,6 +718,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
693 .type = IIO_VOLTAGE, 718 .type = IIO_VOLTAGE,
694 .indexed = 1, 719 .indexed = 1,
695 .channel = 3, 720 .channel = 3,
721 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
696 .scan_index = 3, 722 .scan_index = 3,
697 .scan_type = IIO_ST('u', 10, 16, 2), 723 .scan_type = IIO_ST('u', 10, 16, 2),
698 .event_mask = AD799X_EV_MASK, 724 .event_mask = AD799X_EV_MASK,
@@ -701,6 +727,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
701 .type = IIO_VOLTAGE, 727 .type = IIO_VOLTAGE,
702 .indexed = 1, 728 .indexed = 1,
703 .channel = 4, 729 .channel = 4,
730 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
704 .scan_index = 4, 731 .scan_index = 4,
705 .scan_type = IIO_ST('u', 10, 16, 2), 732 .scan_type = IIO_ST('u', 10, 16, 2),
706 }, 733 },
@@ -708,6 +735,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
708 .type = IIO_VOLTAGE, 735 .type = IIO_VOLTAGE,
709 .indexed = 1, 736 .indexed = 1,
710 .channel = 5, 737 .channel = 5,
738 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
711 .scan_index = 5, 739 .scan_index = 5,
712 .scan_type = IIO_ST('u', 10, 16, 2), 740 .scan_type = IIO_ST('u', 10, 16, 2),
713 }, 741 },
@@ -715,6 +743,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
715 .type = IIO_VOLTAGE, 743 .type = IIO_VOLTAGE,
716 .indexed = 1, 744 .indexed = 1,
717 .channel = 6, 745 .channel = 6,
746 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
718 .scan_index = 6, 747 .scan_index = 6,
719 .scan_type = IIO_ST('u', 10, 16, 2), 748 .scan_type = IIO_ST('u', 10, 16, 2),
720 }, 749 },
@@ -722,6 +751,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
722 .type = IIO_VOLTAGE, 751 .type = IIO_VOLTAGE,
723 .indexed = 1, 752 .indexed = 1,
724 .channel = 7, 753 .channel = 7,
754 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
725 .scan_index = 7, 755 .scan_index = 7,
726 .scan_type = IIO_ST('u', 10, 16, 2), 756 .scan_type = IIO_ST('u', 10, 16, 2),
727 }, 757 },
@@ -738,6 +768,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
738 .type = IIO_VOLTAGE, 768 .type = IIO_VOLTAGE,
739 .indexed = 1, 769 .indexed = 1,
740 .channel = 0, 770 .channel = 0,
771 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
741 .scan_index = 0, 772 .scan_index = 0,
742 .scan_type = IIO_ST('u', 12, 16, 0), 773 .scan_type = IIO_ST('u', 12, 16, 0),
743 .event_mask = AD799X_EV_MASK, 774 .event_mask = AD799X_EV_MASK,
@@ -746,6 +777,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
746 .type = IIO_VOLTAGE, 777 .type = IIO_VOLTAGE,
747 .indexed = 1, 778 .indexed = 1,
748 .channel = 1, 779 .channel = 1,
780 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
749 .scan_index = 1, 781 .scan_index = 1,
750 .scan_type = IIO_ST('u', 12, 16, 0), 782 .scan_type = IIO_ST('u', 12, 16, 0),
751 .event_mask = AD799X_EV_MASK, 783 .event_mask = AD799X_EV_MASK,
@@ -754,6 +786,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
754 .type = IIO_VOLTAGE, 786 .type = IIO_VOLTAGE,
755 .indexed = 1, 787 .indexed = 1,
756 .channel = 2, 788 .channel = 2,
789 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
757 .scan_index = 2, 790 .scan_index = 2,
758 .scan_type = IIO_ST('u', 12, 16, 0), 791 .scan_type = IIO_ST('u', 12, 16, 0),
759 .event_mask = AD799X_EV_MASK, 792 .event_mask = AD799X_EV_MASK,
@@ -762,6 +795,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
762 .type = IIO_VOLTAGE, 795 .type = IIO_VOLTAGE,
763 .indexed = 1, 796 .indexed = 1,
764 .channel = 3, 797 .channel = 3,
798 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
765 .scan_index = 3, 799 .scan_index = 3,
766 .scan_type = IIO_ST('u', 12, 16, 0), 800 .scan_type = IIO_ST('u', 12, 16, 0),
767 .event_mask = AD799X_EV_MASK, 801 .event_mask = AD799X_EV_MASK,
@@ -770,6 +804,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
770 .type = IIO_VOLTAGE, 804 .type = IIO_VOLTAGE,
771 .indexed = 1, 805 .indexed = 1,
772 .channel = 4, 806 .channel = 4,
807 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
773 .scan_index = 4, 808 .scan_index = 4,
774 .scan_type = IIO_ST('u', 12, 16, 0), 809 .scan_type = IIO_ST('u', 12, 16, 0),
775 }, 810 },
@@ -777,6 +812,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
777 .type = IIO_VOLTAGE, 812 .type = IIO_VOLTAGE,
778 .indexed = 1, 813 .indexed = 1,
779 .channel = 5, 814 .channel = 5,
815 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
780 .scan_index = 5, 816 .scan_index = 5,
781 .scan_type = IIO_ST('u', 12, 16, 0), 817 .scan_type = IIO_ST('u', 12, 16, 0),
782 }, 818 },
@@ -784,6 +820,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
784 .type = IIO_VOLTAGE, 820 .type = IIO_VOLTAGE,
785 .indexed = 1, 821 .indexed = 1,
786 .channel = 6, 822 .channel = 6,
823 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
787 .scan_index = 6, 824 .scan_index = 6,
788 .scan_type = IIO_ST('u', 12, 16, 0), 825 .scan_type = IIO_ST('u', 12, 16, 0),
789 }, 826 },
@@ -791,6 +828,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
791 .type = IIO_VOLTAGE, 828 .type = IIO_VOLTAGE,
792 .indexed = 1, 829 .indexed = 1,
793 .channel = 7, 830 .channel = 7,
831 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
794 .scan_index = 7, 832 .scan_index = 7,
795 .scan_type = IIO_ST('u', 12, 16, 0), 833 .scan_type = IIO_ST('u', 12, 16, 0),
796 }, 834 },
@@ -809,7 +847,7 @@ static int __devinit ad799x_probe(struct i2c_client *client,
809 int ret; 847 int ret;
810 struct ad799x_platform_data *pdata = client->dev.platform_data; 848 struct ad799x_platform_data *pdata = client->dev.platform_data;
811 struct ad799x_state *st; 849 struct ad799x_state *st;
812 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 850 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
813 851
814 if (indio_dev == NULL) 852 if (indio_dev == NULL)
815 return -ENOMEM; 853 return -ENOMEM;
@@ -882,7 +920,7 @@ error_disable_reg:
882error_put_reg: 920error_put_reg:
883 if (!IS_ERR(st->reg)) 921 if (!IS_ERR(st->reg))
884 regulator_put(st->reg); 922 regulator_put(st->reg);
885 iio_free_device(indio_dev); 923 iio_device_free(indio_dev);
886 924
887 return ret; 925 return ret;
888} 926}
@@ -902,7 +940,7 @@ static __devexit int ad799x_remove(struct i2c_client *client)
902 regulator_disable(st->reg); 940 regulator_disable(st->reg);
903 regulator_put(st->reg); 941 regulator_put(st->reg);
904 } 942 }
905 iio_free_device(indio_dev); 943 iio_device_free(indio_dev);
906 944
907 return 0; 945 return 0;
908} 946}
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 069765cab275..1c7ff4423db4 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc. 2 * Copyright (C) 2010-2012 Michael Hennerich, Analog Devices Inc.
3 * Copyright (C) 2008-2010 Jonathan Cameron 3 * Copyright (C) 2008-2010 Jonathan Cameron
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -16,10 +16,10 @@
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../buffer.h" 20#include <linux/iio/buffer.h>
21#include "../ring_sw.h" 21#include <linux/iio/kfifo_buf.h>
22#include "../trigger_consumer.h" 22#include <linux/iio/trigger_consumer.h>
23 23
24#include "ad799x.h" 24#include "ad799x.h"
25 25
@@ -32,9 +32,7 @@
32 **/ 32 **/
33static int ad799x_ring_preenable(struct iio_dev *indio_dev) 33static int ad799x_ring_preenable(struct iio_dev *indio_dev)
34{ 34{
35 struct iio_buffer *ring = indio_dev->buffer;
36 struct ad799x_state *st = iio_priv(indio_dev); 35 struct ad799x_state *st = iio_priv(indio_dev);
37
38 /* 36 /*
39 * Need to figure out the current mode based upon the requested 37 * Need to figure out the current mode based upon the requested
40 * scan mask in iio_dev 38 * scan mask in iio_dev
@@ -43,21 +41,7 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)
43 if (st->id == ad7997 || st->id == ad7998) 41 if (st->id == ad7997 || st->id == ad7998)
44 ad7997_8_set_scan_mode(st, *indio_dev->active_scan_mask); 42 ad7997_8_set_scan_mode(st, *indio_dev->active_scan_mask);
45 43
46 st->d_size = bitmap_weight(indio_dev->active_scan_mask, 44 return iio_sw_buffer_preenable(indio_dev);
47 indio_dev->masklength) * 2;
48
49 if (ring->scan_timestamp) {
50 st->d_size += sizeof(s64);
51
52 if (st->d_size % sizeof(s64))
53 st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
54 }
55
56 if (indio_dev->buffer->access->set_bytes_per_datum)
57 indio_dev->buffer->access->
58 set_bytes_per_datum(indio_dev->buffer, st->d_size);
59
60 return 0;
61} 45}
62 46
63/** 47/**
@@ -78,7 +62,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
78 int b_sent; 62 int b_sent;
79 u8 cmd; 63 u8 cmd;
80 64
81 rxbuf = kmalloc(st->d_size, GFP_KERNEL); 65 rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
82 if (rxbuf == NULL) 66 if (rxbuf == NULL)
83 goto out; 67 goto out;
84 68
@@ -111,8 +95,8 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
111 95
112 time_ns = iio_get_time_ns(); 96 time_ns = iio_get_time_ns();
113 97
114 if (ring->scan_timestamp) 98 if (indio_dev->scan_timestamp)
115 memcpy(rxbuf + st->d_size - sizeof(s64), 99 memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
116 &time_ns, sizeof(time_ns)); 100 &time_ns, sizeof(time_ns));
117 101
118 ring->access->store_to(indio_dev->buffer, rxbuf, time_ns); 102 ring->access->store_to(indio_dev->buffer, rxbuf, time_ns);
@@ -136,7 +120,7 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
136{ 120{
137 int ret = 0; 121 int ret = 0;
138 122
139 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 123 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
140 if (!indio_dev->buffer) { 124 if (!indio_dev->buffer) {
141 ret = -ENOMEM; 125 ret = -ENOMEM;
142 goto error_ret; 126 goto error_ret;
@@ -150,7 +134,7 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
150 indio_dev->id); 134 indio_dev->id);
151 if (indio_dev->pollfunc == NULL) { 135 if (indio_dev->pollfunc == NULL) {
152 ret = -ENOMEM; 136 ret = -ENOMEM;
153 goto error_deallocate_sw_rb; 137 goto error_deallocate_kfifo;
154 } 138 }
155 139
156 /* Ring buffer functions - here trigger setup related */ 140 /* Ring buffer functions - here trigger setup related */
@@ -161,8 +145,8 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
161 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 145 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
162 return 0; 146 return 0;
163 147
164error_deallocate_sw_rb: 148error_deallocate_kfifo:
165 iio_sw_rb_free(indio_dev->buffer); 149 iio_kfifo_free(indio_dev->buffer);
166error_ret: 150error_ret:
167 return ret; 151 return ret;
168} 152}
@@ -170,5 +154,5 @@ error_ret:
170void ad799x_ring_cleanup(struct iio_dev *indio_dev) 154void ad799x_ring_cleanup(struct iio_dev *indio_dev)
171{ 155{
172 iio_dealloc_pollfunc(indio_dev->pollfunc); 156 iio_dealloc_pollfunc(indio_dev->pollfunc);
173 iio_sw_rb_free(indio_dev->buffer); 157 iio_kfifo_free(indio_dev->buffer);
174} 158}
diff --git a/drivers/staging/iio/adc/adt7310.c b/drivers/staging/iio/adc/adt7310.c
index caf57c1169b1..e5f1ed7f8696 100644
--- a/drivers/staging/iio/adc/adt7310.c
+++ b/drivers/staging/iio/adc/adt7310.c
@@ -15,9 +15,9 @@
15#include <linux/spi/spi.h> 15#include <linux/spi/spi.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../events.h" 20#include <linux/iio/events.h>
21/* 21/*
22 * ADT7310 registers definition 22 * ADT7310 registers definition
23 */ 23 */
@@ -175,7 +175,7 @@ static ssize_t adt7310_show_mode(struct device *dev,
175 struct device_attribute *attr, 175 struct device_attribute *attr,
176 char *buf) 176 char *buf)
177{ 177{
178 struct iio_dev *dev_info = dev_get_drvdata(dev); 178 struct iio_dev *dev_info = dev_to_iio_dev(dev);
179 struct adt7310_chip_info *chip = iio_priv(dev_info); 179 struct adt7310_chip_info *chip = iio_priv(dev_info);
180 u8 config; 180 u8 config;
181 181
@@ -198,7 +198,7 @@ static ssize_t adt7310_store_mode(struct device *dev,
198 const char *buf, 198 const char *buf,
199 size_t len) 199 size_t len)
200{ 200{
201 struct iio_dev *dev_info = dev_get_drvdata(dev); 201 struct iio_dev *dev_info = dev_to_iio_dev(dev);
202 struct adt7310_chip_info *chip = iio_priv(dev_info); 202 struct adt7310_chip_info *chip = iio_priv(dev_info);
203 u16 config; 203 u16 config;
204 int ret; 204 int ret;
@@ -242,7 +242,7 @@ static ssize_t adt7310_show_resolution(struct device *dev,
242 struct device_attribute *attr, 242 struct device_attribute *attr,
243 char *buf) 243 char *buf)
244{ 244{
245 struct iio_dev *dev_info = dev_get_drvdata(dev); 245 struct iio_dev *dev_info = dev_to_iio_dev(dev);
246 struct adt7310_chip_info *chip = iio_priv(dev_info); 246 struct adt7310_chip_info *chip = iio_priv(dev_info);
247 int ret; 247 int ret;
248 int bits; 248 int bits;
@@ -264,7 +264,7 @@ static ssize_t adt7310_store_resolution(struct device *dev,
264 const char *buf, 264 const char *buf,
265 size_t len) 265 size_t len)
266{ 266{
267 struct iio_dev *dev_info = dev_get_drvdata(dev); 267 struct iio_dev *dev_info = dev_to_iio_dev(dev);
268 struct adt7310_chip_info *chip = iio_priv(dev_info); 268 struct adt7310_chip_info *chip = iio_priv(dev_info);
269 unsigned long data; 269 unsigned long data;
270 u16 config; 270 u16 config;
@@ -300,7 +300,7 @@ static ssize_t adt7310_show_id(struct device *dev,
300 struct device_attribute *attr, 300 struct device_attribute *attr,
301 char *buf) 301 char *buf)
302{ 302{
303 struct iio_dev *dev_info = dev_get_drvdata(dev); 303 struct iio_dev *dev_info = dev_to_iio_dev(dev);
304 struct adt7310_chip_info *chip = iio_priv(dev_info); 304 struct adt7310_chip_info *chip = iio_priv(dev_info);
305 u8 id; 305 u8 id;
306 int ret; 306 int ret;
@@ -350,7 +350,7 @@ static ssize_t adt7310_show_value(struct device *dev,
350 struct device_attribute *attr, 350 struct device_attribute *attr,
351 char *buf) 351 char *buf)
352{ 352{
353 struct iio_dev *dev_info = dev_get_drvdata(dev); 353 struct iio_dev *dev_info = dev_to_iio_dev(dev);
354 struct adt7310_chip_info *chip = iio_priv(dev_info); 354 struct adt7310_chip_info *chip = iio_priv(dev_info);
355 u8 status; 355 u8 status;
356 u16 data; 356 u16 data;
@@ -424,7 +424,7 @@ static ssize_t adt7310_show_event_mode(struct device *dev,
424 struct device_attribute *attr, 424 struct device_attribute *attr,
425 char *buf) 425 char *buf)
426{ 426{
427 struct iio_dev *dev_info = dev_get_drvdata(dev); 427 struct iio_dev *dev_info = dev_to_iio_dev(dev);
428 struct adt7310_chip_info *chip = iio_priv(dev_info); 428 struct adt7310_chip_info *chip = iio_priv(dev_info);
429 int ret; 429 int ret;
430 430
@@ -443,7 +443,7 @@ static ssize_t adt7310_set_event_mode(struct device *dev,
443 const char *buf, 443 const char *buf,
444 size_t len) 444 size_t len)
445{ 445{
446 struct iio_dev *dev_info = dev_get_drvdata(dev); 446 struct iio_dev *dev_info = dev_to_iio_dev(dev);
447 struct adt7310_chip_info *chip = iio_priv(dev_info); 447 struct adt7310_chip_info *chip = iio_priv(dev_info);
448 u16 config; 448 u16 config;
449 int ret; 449 int ret;
@@ -476,7 +476,7 @@ static ssize_t adt7310_show_fault_queue(struct device *dev,
476 struct device_attribute *attr, 476 struct device_attribute *attr,
477 char *buf) 477 char *buf)
478{ 478{
479 struct iio_dev *dev_info = dev_get_drvdata(dev); 479 struct iio_dev *dev_info = dev_to_iio_dev(dev);
480 struct adt7310_chip_info *chip = iio_priv(dev_info); 480 struct adt7310_chip_info *chip = iio_priv(dev_info);
481 int ret; 481 int ret;
482 482
@@ -492,7 +492,7 @@ static ssize_t adt7310_set_fault_queue(struct device *dev,
492 const char *buf, 492 const char *buf,
493 size_t len) 493 size_t len)
494{ 494{
495 struct iio_dev *dev_info = dev_get_drvdata(dev); 495 struct iio_dev *dev_info = dev_to_iio_dev(dev);
496 struct adt7310_chip_info *chip = iio_priv(dev_info); 496 struct adt7310_chip_info *chip = iio_priv(dev_info);
497 unsigned long data; 497 unsigned long data;
498 int ret; 498 int ret;
@@ -522,7 +522,7 @@ static inline ssize_t adt7310_show_t_bound(struct device *dev,
522 u8 bound_reg, 522 u8 bound_reg,
523 char *buf) 523 char *buf)
524{ 524{
525 struct iio_dev *dev_info = dev_get_drvdata(dev); 525 struct iio_dev *dev_info = dev_to_iio_dev(dev);
526 struct adt7310_chip_info *chip = iio_priv(dev_info); 526 struct adt7310_chip_info *chip = iio_priv(dev_info);
527 u16 data; 527 u16 data;
528 int ret; 528 int ret;
@@ -540,7 +540,7 @@ static inline ssize_t adt7310_set_t_bound(struct device *dev,
540 const char *buf, 540 const char *buf,
541 size_t len) 541 size_t len)
542{ 542{
543 struct iio_dev *dev_info = dev_get_drvdata(dev); 543 struct iio_dev *dev_info = dev_to_iio_dev(dev);
544 struct adt7310_chip_info *chip = iio_priv(dev_info); 544 struct adt7310_chip_info *chip = iio_priv(dev_info);
545 long tmp1, tmp2; 545 long tmp1, tmp2;
546 u16 data; 546 u16 data;
@@ -660,7 +660,7 @@ static ssize_t adt7310_show_t_hyst(struct device *dev,
660 struct device_attribute *attr, 660 struct device_attribute *attr,
661 char *buf) 661 char *buf)
662{ 662{
663 struct iio_dev *dev_info = dev_get_drvdata(dev); 663 struct iio_dev *dev_info = dev_to_iio_dev(dev);
664 struct adt7310_chip_info *chip = iio_priv(dev_info); 664 struct adt7310_chip_info *chip = iio_priv(dev_info);
665 int ret; 665 int ret;
666 u8 t_hyst; 666 u8 t_hyst;
@@ -677,7 +677,7 @@ static inline ssize_t adt7310_set_t_hyst(struct device *dev,
677 const char *buf, 677 const char *buf,
678 size_t len) 678 size_t len)
679{ 679{
680 struct iio_dev *dev_info = dev_get_drvdata(dev); 680 struct iio_dev *dev_info = dev_to_iio_dev(dev);
681 struct adt7310_chip_info *chip = iio_priv(dev_info); 681 struct adt7310_chip_info *chip = iio_priv(dev_info);
682 int ret; 682 int ret;
683 unsigned long data; 683 unsigned long data;
@@ -753,7 +753,7 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
753 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data; 753 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data;
754 unsigned long irq_flags; 754 unsigned long irq_flags;
755 755
756 indio_dev = iio_allocate_device(sizeof(*chip)); 756 indio_dev = iio_device_alloc(sizeof(*chip));
757 if (indio_dev == NULL) { 757 if (indio_dev == NULL) {
758 ret = -ENOMEM; 758 ret = -ENOMEM;
759 goto error_ret; 759 goto error_ret;
@@ -833,7 +833,7 @@ error_unreg_int_irq:
833error_unreg_ct_irq: 833error_unreg_ct_irq:
834 free_irq(spi_dev->irq, indio_dev); 834 free_irq(spi_dev->irq, indio_dev);
835error_free_dev: 835error_free_dev:
836 iio_free_device(indio_dev); 836 iio_device_free(indio_dev);
837error_ret: 837error_ret:
838 return ret; 838 return ret;
839} 839}
@@ -849,7 +849,7 @@ static int __devexit adt7310_remove(struct spi_device *spi_dev)
849 free_irq(adt7310_platform_data[0], indio_dev); 849 free_irq(adt7310_platform_data[0], indio_dev);
850 if (spi_dev->irq) 850 if (spi_dev->irq)
851 free_irq(spi_dev->irq, indio_dev); 851 free_irq(spi_dev->irq, indio_dev);
852 iio_free_device(indio_dev); 852 iio_device_free(indio_dev);
853 853
854 return 0; 854 return 0;
855} 855}
diff --git a/drivers/staging/iio/adc/adt7410.c b/drivers/staging/iio/adc/adt7410.c
index dff3e8ca2d78..917b6921e24d 100644
--- a/drivers/staging/iio/adc/adt7410.c
+++ b/drivers/staging/iio/adc/adt7410.c
@@ -15,9 +15,9 @@
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20#include "../events.h" 20#include <linux/iio/events.h>
21 21
22/* 22/*
23 * ADT7410 registers definition 23 * ADT7410 registers definition
@@ -144,7 +144,7 @@ static ssize_t adt7410_show_mode(struct device *dev,
144 struct device_attribute *attr, 144 struct device_attribute *attr,
145 char *buf) 145 char *buf)
146{ 146{
147 struct iio_dev *dev_info = dev_get_drvdata(dev); 147 struct iio_dev *dev_info = dev_to_iio_dev(dev);
148 struct adt7410_chip_info *chip = iio_priv(dev_info); 148 struct adt7410_chip_info *chip = iio_priv(dev_info);
149 u8 config; 149 u8 config;
150 150
@@ -167,7 +167,7 @@ static ssize_t adt7410_store_mode(struct device *dev,
167 const char *buf, 167 const char *buf,
168 size_t len) 168 size_t len)
169{ 169{
170 struct iio_dev *dev_info = dev_get_drvdata(dev); 170 struct iio_dev *dev_info = dev_to_iio_dev(dev);
171 struct adt7410_chip_info *chip = iio_priv(dev_info); 171 struct adt7410_chip_info *chip = iio_priv(dev_info);
172 u16 config; 172 u16 config;
173 int ret; 173 int ret;
@@ -211,7 +211,7 @@ static ssize_t adt7410_show_resolution(struct device *dev,
211 struct device_attribute *attr, 211 struct device_attribute *attr,
212 char *buf) 212 char *buf)
213{ 213{
214 struct iio_dev *dev_info = dev_get_drvdata(dev); 214 struct iio_dev *dev_info = dev_to_iio_dev(dev);
215 struct adt7410_chip_info *chip = iio_priv(dev_info); 215 struct adt7410_chip_info *chip = iio_priv(dev_info);
216 int ret; 216 int ret;
217 int bits; 217 int bits;
@@ -233,7 +233,7 @@ static ssize_t adt7410_store_resolution(struct device *dev,
233 const char *buf, 233 const char *buf,
234 size_t len) 234 size_t len)
235{ 235{
236 struct iio_dev *dev_info = dev_get_drvdata(dev); 236 struct iio_dev *dev_info = dev_to_iio_dev(dev);
237 struct adt7410_chip_info *chip = iio_priv(dev_info); 237 struct adt7410_chip_info *chip = iio_priv(dev_info);
238 unsigned long data; 238 unsigned long data;
239 u16 config; 239 u16 config;
@@ -269,7 +269,7 @@ static ssize_t adt7410_show_id(struct device *dev,
269 struct device_attribute *attr, 269 struct device_attribute *attr,
270 char *buf) 270 char *buf)
271{ 271{
272 struct iio_dev *dev_info = dev_get_drvdata(dev); 272 struct iio_dev *dev_info = dev_to_iio_dev(dev);
273 struct adt7410_chip_info *chip = iio_priv(dev_info); 273 struct adt7410_chip_info *chip = iio_priv(dev_info);
274 u8 id; 274 u8 id;
275 int ret; 275 int ret;
@@ -319,7 +319,7 @@ static ssize_t adt7410_show_value(struct device *dev,
319 struct device_attribute *attr, 319 struct device_attribute *attr,
320 char *buf) 320 char *buf)
321{ 321{
322 struct iio_dev *dev_info = dev_get_drvdata(dev); 322 struct iio_dev *dev_info = dev_to_iio_dev(dev);
323 struct adt7410_chip_info *chip = iio_priv(dev_info); 323 struct adt7410_chip_info *chip = iio_priv(dev_info);
324 u8 status; 324 u8 status;
325 u16 data; 325 u16 data;
@@ -392,7 +392,7 @@ static ssize_t adt7410_show_event_mode(struct device *dev,
392 struct device_attribute *attr, 392 struct device_attribute *attr,
393 char *buf) 393 char *buf)
394{ 394{
395 struct iio_dev *dev_info = dev_get_drvdata(dev); 395 struct iio_dev *dev_info = dev_to_iio_dev(dev);
396 struct adt7410_chip_info *chip = iio_priv(dev_info); 396 struct adt7410_chip_info *chip = iio_priv(dev_info);
397 int ret; 397 int ret;
398 398
@@ -411,7 +411,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev,
411 const char *buf, 411 const char *buf,
412 size_t len) 412 size_t len)
413{ 413{
414 struct iio_dev *dev_info = dev_get_drvdata(dev); 414 struct iio_dev *dev_info = dev_to_iio_dev(dev);
415 struct adt7410_chip_info *chip = iio_priv(dev_info); 415 struct adt7410_chip_info *chip = iio_priv(dev_info);
416 u16 config; 416 u16 config;
417 int ret; 417 int ret;
@@ -444,7 +444,7 @@ static ssize_t adt7410_show_fault_queue(struct device *dev,
444 struct device_attribute *attr, 444 struct device_attribute *attr,
445 char *buf) 445 char *buf)
446{ 446{
447 struct iio_dev *dev_info = dev_get_drvdata(dev); 447 struct iio_dev *dev_info = dev_to_iio_dev(dev);
448 struct adt7410_chip_info *chip = iio_priv(dev_info); 448 struct adt7410_chip_info *chip = iio_priv(dev_info);
449 int ret; 449 int ret;
450 450
@@ -460,7 +460,7 @@ static ssize_t adt7410_set_fault_queue(struct device *dev,
460 const char *buf, 460 const char *buf,
461 size_t len) 461 size_t len)
462{ 462{
463 struct iio_dev *dev_info = dev_get_drvdata(dev); 463 struct iio_dev *dev_info = dev_to_iio_dev(dev);
464 struct adt7410_chip_info *chip = iio_priv(dev_info); 464 struct adt7410_chip_info *chip = iio_priv(dev_info);
465 unsigned long data; 465 unsigned long data;
466 int ret; 466 int ret;
@@ -490,7 +490,7 @@ static inline ssize_t adt7410_show_t_bound(struct device *dev,
490 u8 bound_reg, 490 u8 bound_reg,
491 char *buf) 491 char *buf)
492{ 492{
493 struct iio_dev *dev_info = dev_get_drvdata(dev); 493 struct iio_dev *dev_info = dev_to_iio_dev(dev);
494 struct adt7410_chip_info *chip = iio_priv(dev_info); 494 struct adt7410_chip_info *chip = iio_priv(dev_info);
495 u16 data; 495 u16 data;
496 int ret; 496 int ret;
@@ -508,7 +508,7 @@ static inline ssize_t adt7410_set_t_bound(struct device *dev,
508 const char *buf, 508 const char *buf,
509 size_t len) 509 size_t len)
510{ 510{
511 struct iio_dev *dev_info = dev_get_drvdata(dev); 511 struct iio_dev *dev_info = dev_to_iio_dev(dev);
512 struct adt7410_chip_info *chip = iio_priv(dev_info); 512 struct adt7410_chip_info *chip = iio_priv(dev_info);
513 long tmp1, tmp2; 513 long tmp1, tmp2;
514 u16 data; 514 u16 data;
@@ -628,7 +628,7 @@ static ssize_t adt7410_show_t_hyst(struct device *dev,
628 struct device_attribute *attr, 628 struct device_attribute *attr,
629 char *buf) 629 char *buf)
630{ 630{
631 struct iio_dev *dev_info = dev_get_drvdata(dev); 631 struct iio_dev *dev_info = dev_to_iio_dev(dev);
632 struct adt7410_chip_info *chip = iio_priv(dev_info); 632 struct adt7410_chip_info *chip = iio_priv(dev_info);
633 int ret; 633 int ret;
634 u8 t_hyst; 634 u8 t_hyst;
@@ -645,7 +645,7 @@ static inline ssize_t adt7410_set_t_hyst(struct device *dev,
645 const char *buf, 645 const char *buf,
646 size_t len) 646 size_t len)
647{ 647{
648 struct iio_dev *dev_info = dev_get_drvdata(dev); 648 struct iio_dev *dev_info = dev_to_iio_dev(dev);
649 struct adt7410_chip_info *chip = iio_priv(dev_info); 649 struct adt7410_chip_info *chip = iio_priv(dev_info);
650 int ret; 650 int ret;
651 unsigned long data; 651 unsigned long data;
@@ -721,7 +721,7 @@ static int __devinit adt7410_probe(struct i2c_client *client,
721 int ret = 0; 721 int ret = 0;
722 unsigned long *adt7410_platform_data = client->dev.platform_data; 722 unsigned long *adt7410_platform_data = client->dev.platform_data;
723 723
724 indio_dev = iio_allocate_device(sizeof(*chip)); 724 indio_dev = iio_device_alloc(sizeof(*chip));
725 if (indio_dev == NULL) { 725 if (indio_dev == NULL) {
726 ret = -ENOMEM; 726 ret = -ENOMEM;
727 goto error_ret; 727 goto error_ret;
@@ -797,7 +797,7 @@ error_unreg_int_irq:
797error_unreg_ct_irq: 797error_unreg_ct_irq:
798 free_irq(client->irq, indio_dev); 798 free_irq(client->irq, indio_dev);
799error_free_dev: 799error_free_dev:
800 iio_free_device(indio_dev); 800 iio_device_free(indio_dev);
801error_ret: 801error_ret:
802 return ret; 802 return ret;
803} 803}
@@ -812,7 +812,7 @@ static int __devexit adt7410_remove(struct i2c_client *client)
812 free_irq(adt7410_platform_data[0], indio_dev); 812 free_irq(adt7410_platform_data[0], indio_dev);
813 if (client->irq) 813 if (client->irq)
814 free_irq(client->irq, indio_dev); 814 free_irq(client->irq, indio_dev);
815 iio_free_device(indio_dev); 815 iio_device_free(indio_dev);
816 816
817 return 0; 817 return 0;
818} 818}
diff --git a/drivers/staging/iio/adc/lpc32xx_adc.c b/drivers/staging/iio/adc/lpc32xx_adc.c
index dfc9033843a3..9690306d1f8f 100644
--- a/drivers/staging/iio/adc/lpc32xx_adc.c
+++ b/drivers/staging/iio/adc/lpc32xx_adc.c
@@ -30,9 +30,10 @@
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/completion.h> 32#include <linux/completion.h>
33#include <linux/of.h>
33 34
34#include "../iio.h" 35#include <linux/iio/iio.h>
35#include "../sysfs.h" 36#include <linux/iio/sysfs.h>
36 37
37/* 38/*
38 * LPC32XX registers definitions 39 * LPC32XX registers definitions
@@ -73,7 +74,7 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev,
73{ 74{
74 struct lpc32xx_adc_info *info = iio_priv(indio_dev); 75 struct lpc32xx_adc_info *info = iio_priv(indio_dev);
75 76
76 if (mask == 0) { 77 if (mask == IIO_CHAN_INFO_RAW) {
77 mutex_lock(&indio_dev->mlock); 78 mutex_lock(&indio_dev->mlock);
78 clk_enable(info->clk); 79 clk_enable(info->clk);
79 /* Measurement setup */ 80 /* Measurement setup */
@@ -98,12 +99,13 @@ static const struct iio_info lpc32xx_adc_iio_info = {
98 .driver_module = THIS_MODULE, 99 .driver_module = THIS_MODULE,
99}; 100};
100 101
101#define LPC32XX_ADC_CHANNEL(_index) { \ 102#define LPC32XX_ADC_CHANNEL(_index) { \
102 .type = IIO_VOLTAGE, \ 103 .type = IIO_VOLTAGE, \
103 .indexed = 1, \ 104 .indexed = 1, \
104 .channel = _index, \ 105 .channel = _index, \
105 .address = AD_IN * _index, \ 106 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
106 .scan_index = _index, \ 107 .address = AD_IN * _index, \
108 .scan_index = _index, \
107} 109}
108 110
109static struct iio_chan_spec lpc32xx_adc_iio_channels[] = { 111static struct iio_chan_spec lpc32xx_adc_iio_channels[] = {
@@ -139,7 +141,7 @@ static int __devinit lpc32xx_adc_probe(struct platform_device *pdev)
139 goto errout1; 141 goto errout1;
140 } 142 }
141 143
142 iodev = iio_allocate_device(sizeof(struct lpc32xx_adc_info)); 144 iodev = iio_device_alloc(sizeof(struct lpc32xx_adc_info));
143 if (!iodev) { 145 if (!iodev) {
144 dev_err(&pdev->dev, "failed allocating iio device\n"); 146 dev_err(&pdev->dev, "failed allocating iio device\n");
145 retval = -ENOMEM; 147 retval = -ENOMEM;
@@ -200,7 +202,7 @@ errout4:
200errout3: 202errout3:
201 iounmap(info->adc_base); 203 iounmap(info->adc_base);
202errout2: 204errout2:
203 iio_free_device(iodev); 205 iio_device_free(iodev);
204errout1: 206errout1:
205 return retval; 207 return retval;
206} 208}
@@ -216,17 +218,26 @@ static int __devexit lpc32xx_adc_remove(struct platform_device *pdev)
216 platform_set_drvdata(pdev, NULL); 218 platform_set_drvdata(pdev, NULL);
217 clk_put(info->clk); 219 clk_put(info->clk);
218 iounmap(info->adc_base); 220 iounmap(info->adc_base);
219 iio_free_device(iodev); 221 iio_device_free(iodev);
220 222
221 return 0; 223 return 0;
222} 224}
223 225
226#ifdef CONFIG_OF
227static const struct of_device_id lpc32xx_adc_match[] = {
228 { .compatible = "nxp,lpc3220-adc" },
229 {},
230};
231MODULE_DEVICE_TABLE(of, lpc32xx_adc_match);
232#endif
233
224static struct platform_driver lpc32xx_adc_driver = { 234static struct platform_driver lpc32xx_adc_driver = {
225 .probe = lpc32xx_adc_probe, 235 .probe = lpc32xx_adc_probe,
226 .remove = __devexit_p(lpc32xx_adc_remove), 236 .remove = __devexit_p(lpc32xx_adc_remove),
227 .driver = { 237 .driver = {
228 .name = MOD_NAME, 238 .name = MOD_NAME,
229 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
240 .of_match_table = of_match_ptr(lpc32xx_adc_match),
230 }, 241 },
231}; 242};
232 243
diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c
index cf3e2ca7e314..6799ce23a395 100644
--- a/drivers/staging/iio/adc/max1363_core.c
+++ b/drivers/staging/iio/adc/max1363_core.c
@@ -32,10 +32,11 @@
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/module.h> 33#include <linux/module.h>
34 34
35#include "../iio.h" 35#include <linux/iio/iio.h>
36#include "../sysfs.h" 36#include <linux/iio/sysfs.h>
37#include "../events.h" 37#include <linux/iio/events.h>
38#include "../buffer.h" 38#include <linux/iio/buffer.h>
39#include <linux/iio/driver.h>
39 40
40#include "max1363.h" 41#include "max1363.h"
41 42
@@ -248,7 +249,7 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
248 struct max1363_state *st = iio_priv(indio_dev); 249 struct max1363_state *st = iio_priv(indio_dev);
249 int ret; 250 int ret;
250 switch (m) { 251 switch (m) {
251 case 0: 252 case IIO_CHAN_INFO_RAW:
252 ret = max1363_read_single_chan(indio_dev, chan, val, m); 253 ret = max1363_read_single_chan(indio_dev, chan, val, m);
253 if (ret < 0) 254 if (ret < 0)
254 return ret; 255 return ret;
@@ -281,7 +282,8 @@ static const enum max1363_modes max1363_mode_list[] = {
281#define MAX1363_EV_M \ 282#define MAX1363_EV_M \
282 (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) \ 283 (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) \
283 | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) 284 | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
284#define MAX1363_INFO_MASK IIO_CHAN_INFO_SCALE_SHARED_BIT 285#define MAX1363_INFO_MASK (IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
286 IIO_CHAN_INFO_SCALE_SHARED_BIT)
285#define MAX1363_CHAN_U(num, addr, si, bits, evmask) \ 287#define MAX1363_CHAN_U(num, addr, si, bits, evmask) \
286 { \ 288 { \
287 .type = IIO_VOLTAGE, \ 289 .type = IIO_VOLTAGE, \
@@ -497,7 +499,7 @@ static ssize_t max1363_monitor_show_freq(struct device *dev,
497 struct device_attribute *attr, 499 struct device_attribute *attr,
498 char *buf) 500 char *buf)
499{ 501{
500 struct max1363_state *st = iio_priv(dev_get_drvdata(dev)); 502 struct max1363_state *st = iio_priv(dev_to_iio_dev(dev));
501 return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); 503 return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]);
502} 504}
503 505
@@ -506,7 +508,7 @@ static ssize_t max1363_monitor_store_freq(struct device *dev,
506 const char *buf, 508 const char *buf,
507 size_t len) 509 size_t len)
508{ 510{
509 struct iio_dev *indio_dev = dev_get_drvdata(dev); 511 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
510 struct max1363_state *st = iio_priv(indio_dev); 512 struct max1363_state *st = iio_priv(indio_dev);
511 int i, ret; 513 int i, ret;
512 unsigned long val; 514 unsigned long val;
@@ -830,6 +832,7 @@ static struct attribute_group max1363_event_attribute_group = {
830static const struct iio_info max1238_info = { 832static const struct iio_info max1238_info = {
831 .read_raw = &max1363_read_raw, 833 .read_raw = &max1363_read_raw,
832 .driver_module = THIS_MODULE, 834 .driver_module = THIS_MODULE,
835 .update_scan_mode = &max1363_update_scan_mode,
833}; 836};
834 837
835static const struct iio_info max1363_info = { 838static const struct iio_info max1363_info = {
@@ -1284,11 +1287,14 @@ static int __devinit max1363_probe(struct i2c_client *client,
1284 if (ret) 1287 if (ret)
1285 goto error_put_reg; 1288 goto error_put_reg;
1286 1289
1287 indio_dev = iio_allocate_device(sizeof(struct max1363_state)); 1290 indio_dev = iio_device_alloc(sizeof(struct max1363_state));
1288 if (indio_dev == NULL) { 1291 if (indio_dev == NULL) {
1289 ret = -ENOMEM; 1292 ret = -ENOMEM;
1290 goto error_disable_reg; 1293 goto error_disable_reg;
1291 } 1294 }
1295 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
1296 if (ret < 0)
1297 goto error_free_device;
1292 st = iio_priv(indio_dev); 1298 st = iio_priv(indio_dev);
1293 st->reg = reg; 1299 st->reg = reg;
1294 /* this is only used for device removal purposes */ 1300 /* this is only used for device removal purposes */
@@ -1299,7 +1305,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
1299 1305
1300 ret = max1363_alloc_scan_masks(indio_dev); 1306 ret = max1363_alloc_scan_masks(indio_dev);
1301 if (ret) 1307 if (ret)
1302 goto error_free_device; 1308 goto error_unregister_map;
1303 1309
1304 /* Estabilish that the iio_dev is a child of the i2c device */ 1310 /* Estabilish that the iio_dev is a child of the i2c device */
1305 indio_dev->dev.parent = &client->dev; 1311 indio_dev->dev.parent = &client->dev;
@@ -1349,8 +1355,10 @@ error_cleanup_ring:
1349 max1363_ring_cleanup(indio_dev); 1355 max1363_ring_cleanup(indio_dev);
1350error_free_available_scan_masks: 1356error_free_available_scan_masks:
1351 kfree(indio_dev->available_scan_masks); 1357 kfree(indio_dev->available_scan_masks);
1358error_unregister_map:
1359 iio_map_array_unregister(indio_dev, client->dev.platform_data);
1352error_free_device: 1360error_free_device:
1353 iio_free_device(indio_dev); 1361 iio_device_free(indio_dev);
1354error_disable_reg: 1362error_disable_reg:
1355 regulator_disable(reg); 1363 regulator_disable(reg);
1356error_put_reg: 1364error_put_reg:
@@ -1375,7 +1383,8 @@ static int max1363_remove(struct i2c_client *client)
1375 regulator_disable(reg); 1383 regulator_disable(reg);
1376 regulator_put(reg); 1384 regulator_put(reg);
1377 } 1385 }
1378 iio_free_device(indio_dev); 1386 iio_map_array_unregister(indio_dev, client->dev.platform_data);
1387 iio_device_free(indio_dev);
1379 1388
1380 return 0; 1389 return 0;
1381} 1390}
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index d0a60a382930..b30201300121 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -14,10 +14,10 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16 16
17#include "../iio.h" 17#include <linux/iio/iio.h>
18#include "../buffer.h" 18#include <linux/iio/buffer.h>
19#include "../ring_sw.h" 19#include "../ring_sw.h"
20#include "../trigger_consumer.h" 20#include <linux/iio/trigger_consumer.h>
21 21
22#include "max1363.h" 22#include "max1363.h"
23 23
@@ -54,7 +54,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
54 d_size = numvals*2; 54 d_size = numvals*2;
55 else 55 else
56 d_size = numvals; 56 d_size = numvals;
57 if (indio_dev->buffer->scan_timestamp) { 57 if (indio_dev->scan_timestamp) {
58 d_size += sizeof(s64); 58 d_size += sizeof(s64);
59 if (d_size % sizeof(s64)) 59 if (d_size % sizeof(s64))
60 d_size += sizeof(s64) - (d_size % sizeof(s64)); 60 d_size += sizeof(s64) - (d_size % sizeof(s64));
@@ -78,7 +78,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
78 78
79 time_ns = iio_get_time_ns(); 79 time_ns = iio_get_time_ns();
80 80
81 if (indio_dev->buffer->scan_timestamp) 81 if (indio_dev->scan_timestamp)
82 memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); 82 memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
83 iio_push_to_buffer(indio_dev->buffer, rxbuf, time_ns); 83 iio_push_to_buffer(indio_dev->buffer, rxbuf, time_ns);
84 84
diff --git a/drivers/staging/iio/adc/spear_adc.c b/drivers/staging/iio/adc/spear_adc.c
new file mode 100644
index 000000000000..64d630e6fe29
--- /dev/null
+++ b/drivers/staging/iio/adc/spear_adc.c
@@ -0,0 +1,448 @@
1/*
2 * ST SPEAr ADC driver
3 *
4 * Copyright 2012 Stefan Roese <sr@denx.de>
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/interrupt.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/io.h>
16#include <linux/clk.h>
17#include <linux/err.h>
18#include <linux/completion.h>
19#include <linux/of.h>
20#include <linux/of_address.h>
21
22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
24
25/*
26 * SPEAR registers definitions
27 */
28
29#define SCAN_RATE_LO(x) ((x) & 0xFFFF)
30#define SCAN_RATE_HI(x) (((x) >> 0x10) & 0xFFFF)
31#define CLK_LOW(x) (((x) & 0xf) << 0)
32#define CLK_HIGH(x) (((x) & 0xf) << 4)
33
34/* Bit definitions for SPEAR_ADC_STATUS */
35#define START_CONVERSION (1 << 0)
36#define CHANNEL_NUM(x) ((x) << 1)
37#define ADC_ENABLE (1 << 4)
38#define AVG_SAMPLE(x) ((x) << 5)
39#define VREF_INTERNAL (1 << 9)
40
41#define DATA_MASK 0x03ff
42#define DATA_BITS 10
43
44#define MOD_NAME "spear-adc"
45
46#define ADC_CHANNEL_NUM 8
47
48#define CLK_MIN 2500000
49#define CLK_MAX 20000000
50
51struct adc_regs_spear3xx {
52 u32 status;
53 u32 average;
54 u32 scan_rate;
55 u32 clk; /* Not avail for 1340 & 1310 */
56 u32 ch_ctrl[ADC_CHANNEL_NUM];
57 u32 ch_data[ADC_CHANNEL_NUM];
58};
59
60struct chan_data {
61 u32 lsb;
62 u32 msb;
63};
64
65struct adc_regs_spear6xx {
66 u32 status;
67 u32 pad[2];
68 u32 clk;
69 u32 ch_ctrl[ADC_CHANNEL_NUM];
70 struct chan_data ch_data[ADC_CHANNEL_NUM];
71 u32 scan_rate_lo;
72 u32 scan_rate_hi;
73 struct chan_data average;
74};
75
76struct spear_adc_info {
77 struct device_node *np;
78 struct adc_regs_spear3xx __iomem *adc_base_spear3xx;
79 struct adc_regs_spear6xx __iomem *adc_base_spear6xx;
80 struct clk *clk;
81 struct completion completion;
82 u32 current_clk;
83 u32 sampling_freq;
84 u32 avg_samples;
85 u32 vref_external;
86 u32 value;
87};
88
89/*
90 * Functions to access some SPEAr ADC register. Abstracted into
91 * static inline functions, because of different register offsets
92 * on different SoC variants (SPEAr300 vs SPEAr600 etc).
93 */
94static void spear_adc_set_status(struct spear_adc_info *info, u32 val)
95{
96 __raw_writel(val, &info->adc_base_spear6xx->status);
97}
98
99static void spear_adc_set_clk(struct spear_adc_info *info, u32 val)
100{
101 u32 clk_high, clk_low, count;
102 u32 apb_clk = clk_get_rate(info->clk);
103
104 count = (apb_clk + val - 1) / val;
105 clk_low = count / 2;
106 clk_high = count - clk_low;
107 info->current_clk = apb_clk / count;
108
109 __raw_writel(CLK_LOW(clk_low) | CLK_HIGH(clk_high),
110 &info->adc_base_spear6xx->clk);
111}
112
113static void spear_adc_set_ctrl(struct spear_adc_info *info, int n,
114 u32 val)
115{
116 __raw_writel(val, &info->adc_base_spear6xx->ch_ctrl[n]);
117}
118
119static u32 spear_adc_get_average(struct spear_adc_info *info)
120{
121 if (of_device_is_compatible(info->np, "st,spear600-adc")) {
122 return __raw_readl(&info->adc_base_spear6xx->average.msb) &
123 DATA_MASK;
124 } else {
125 return __raw_readl(&info->adc_base_spear3xx->average) &
126 DATA_MASK;
127 }
128}
129
130static void spear_adc_set_scanrate(struct spear_adc_info *info, u32 rate)
131{
132 if (of_device_is_compatible(info->np, "st,spear600-adc")) {
133 __raw_writel(SCAN_RATE_LO(rate),
134 &info->adc_base_spear6xx->scan_rate_lo);
135 __raw_writel(SCAN_RATE_HI(rate),
136 &info->adc_base_spear6xx->scan_rate_hi);
137 } else {
138 __raw_writel(rate, &info->adc_base_spear3xx->scan_rate);
139 }
140}
141
142static int spear_read_raw(struct iio_dev *indio_dev,
143 struct iio_chan_spec const *chan,
144 int *val,
145 int *val2,
146 long mask)
147{
148 struct spear_adc_info *info = iio_priv(indio_dev);
149 u32 scale_mv;
150 u32 status;
151
152 switch (mask) {
153 case IIO_CHAN_INFO_RAW:
154 mutex_lock(&indio_dev->mlock);
155
156 status = CHANNEL_NUM(chan->channel) |
157 AVG_SAMPLE(info->avg_samples) |
158 START_CONVERSION | ADC_ENABLE;
159 if (info->vref_external == 0)
160 status |= VREF_INTERNAL;
161
162 spear_adc_set_status(info, status);
163 wait_for_completion(&info->completion); /* set by ISR */
164 *val = info->value;
165
166 mutex_unlock(&indio_dev->mlock);
167
168 return IIO_VAL_INT;
169
170 case IIO_CHAN_INFO_SCALE:
171 scale_mv = (info->vref_external * 1000) >> DATA_BITS;
172 *val = scale_mv / 1000;
173 *val2 = (scale_mv % 1000) * 1000;
174 return IIO_VAL_INT_PLUS_MICRO;
175 }
176
177 return -EINVAL;
178}
179
180#define SPEAR_ADC_CHAN(idx) { \
181 .type = IIO_VOLTAGE, \
182 .indexed = 1, \
183 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
184 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
185 .channel = idx, \
186 .scan_type = { \
187 .sign = 'u', \
188 .storagebits = 16, \
189 }, \
190}
191
192static struct iio_chan_spec spear_adc_iio_channels[] = {
193 SPEAR_ADC_CHAN(0),
194 SPEAR_ADC_CHAN(1),
195 SPEAR_ADC_CHAN(2),
196 SPEAR_ADC_CHAN(3),
197 SPEAR_ADC_CHAN(4),
198 SPEAR_ADC_CHAN(5),
199 SPEAR_ADC_CHAN(6),
200 SPEAR_ADC_CHAN(7),
201};
202
203static irqreturn_t spear_adc_isr(int irq, void *dev_id)
204{
205 struct spear_adc_info *info = (struct spear_adc_info *)dev_id;
206
207 /* Read value to clear IRQ */
208 info->value = spear_adc_get_average(info);
209 complete(&info->completion);
210
211 return IRQ_HANDLED;
212}
213
214static int spear_adc_configure(struct spear_adc_info *info)
215{
216 int i;
217
218 /* Reset ADC core */
219 spear_adc_set_status(info, 0);
220 __raw_writel(0, &info->adc_base_spear6xx->clk);
221 for (i = 0; i < 8; i++)
222 spear_adc_set_ctrl(info, i, 0);
223 spear_adc_set_scanrate(info, 0);
224
225 spear_adc_set_clk(info, info->sampling_freq);
226
227 return 0;
228}
229
230static ssize_t spear_adc_read_frequency(struct device *dev,
231 struct device_attribute *attr,
232 char *buf)
233{
234 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
235 struct spear_adc_info *info = iio_priv(indio_dev);
236
237 return sprintf(buf, "%d\n", info->current_clk);
238}
239
240static ssize_t spear_adc_write_frequency(struct device *dev,
241 struct device_attribute *attr,
242 const char *buf,
243 size_t len)
244{
245 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
246 struct spear_adc_info *info = iio_priv(indio_dev);
247 u32 clk_high, clk_low, count;
248 u32 apb_clk = clk_get_rate(info->clk);
249 unsigned long lval;
250 int ret;
251
252 ret = kstrtoul(buf, 10, &lval);
253 if (ret)
254 return ret;
255
256 mutex_lock(&indio_dev->mlock);
257
258 if ((lval < CLK_MIN) || (lval > CLK_MAX)) {
259 ret = -EINVAL;
260 goto out;
261 }
262
263 count = (apb_clk + lval - 1) / lval;
264 clk_low = count / 2;
265 clk_high = count - clk_low;
266 info->current_clk = apb_clk / count;
267 spear_adc_set_clk(info, lval);
268
269out:
270 mutex_unlock(&indio_dev->mlock);
271
272 return ret ? ret : len;
273}
274
275static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
276 spear_adc_read_frequency,
277 spear_adc_write_frequency);
278
279static struct attribute *spear_attributes[] = {
280 &iio_dev_attr_sampling_frequency.dev_attr.attr,
281 NULL
282};
283
284static const struct attribute_group spear_attribute_group = {
285 .attrs = spear_attributes,
286};
287
288static const struct iio_info spear_adc_iio_info = {
289 .read_raw = &spear_read_raw,
290 .attrs = &spear_attribute_group,
291 .driver_module = THIS_MODULE,
292};
293
294static int __devinit spear_adc_probe(struct platform_device *pdev)
295{
296 struct device_node *np = pdev->dev.of_node;
297 struct device *dev = &pdev->dev;
298 struct spear_adc_info *info;
299 struct iio_dev *iodev = NULL;
300 int ret = -ENODEV;
301 int irq;
302
303 iodev = iio_device_alloc(sizeof(struct spear_adc_info));
304 if (!iodev) {
305 dev_err(dev, "failed allocating iio device\n");
306 ret = -ENOMEM;
307 goto errout1;
308 }
309
310 info = iio_priv(iodev);
311 info->np = np;
312
313 /*
314 * SPEAr600 has a different register layout than other SPEAr SoC's
315 * (e.g. SPEAr3xx). Let's provide two register base addresses
316 * to support multi-arch kernels.
317 */
318 info->adc_base_spear6xx = of_iomap(np, 0);
319 if (!info->adc_base_spear6xx) {
320 dev_err(dev, "failed mapping memory\n");
321 ret = -ENOMEM;
322 goto errout2;
323 }
324 info->adc_base_spear3xx =
325 (struct adc_regs_spear3xx *)info->adc_base_spear6xx;
326
327 info->clk = clk_get(dev, NULL);
328 if (IS_ERR(info->clk)) {
329 dev_err(dev, "failed getting clock\n");
330 goto errout3;
331 }
332
333 ret = clk_prepare(info->clk);
334 if (ret) {
335 dev_err(dev, "failed preparing clock\n");
336 goto errout4;
337 }
338
339 ret = clk_enable(info->clk);
340 if (ret) {
341 dev_err(dev, "failed enabling clock\n");
342 goto errout5;
343 }
344
345 irq = platform_get_irq(pdev, 0);
346 if ((irq < 0) || (irq >= NR_IRQS)) {
347 dev_err(dev, "failed getting interrupt resource\n");
348 ret = -EINVAL;
349 goto errout6;
350 }
351
352 ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info);
353 if (ret < 0) {
354 dev_err(dev, "failed requesting interrupt\n");
355 goto errout6;
356 }
357
358 if (of_property_read_u32(np, "sampling-frequency",
359 &info->sampling_freq)) {
360 dev_err(dev, "sampling-frequency missing in DT\n");
361 ret = -EINVAL;
362 goto errout6;
363 }
364
365 /*
366 * Optional avg_samples defaults to 0, resulting in single data
367 * conversion
368 */
369 of_property_read_u32(np, "average-samples", &info->avg_samples);
370
371 /*
372 * Optional vref_external defaults to 0, resulting in internal vref
373 * selection
374 */
375 of_property_read_u32(np, "vref-external", &info->vref_external);
376
377 spear_adc_configure(info);
378
379 platform_set_drvdata(pdev, iodev);
380
381 init_completion(&info->completion);
382
383 iodev->name = MOD_NAME;
384 iodev->dev.parent = dev;
385 iodev->info = &spear_adc_iio_info;
386 iodev->modes = INDIO_DIRECT_MODE;
387 iodev->channels = spear_adc_iio_channels;
388 iodev->num_channels = ARRAY_SIZE(spear_adc_iio_channels);
389
390 ret = iio_device_register(iodev);
391 if (ret)
392 goto errout6;
393
394 dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq);
395
396 return 0;
397
398errout6:
399 clk_disable(info->clk);
400errout5:
401 clk_unprepare(info->clk);
402errout4:
403 clk_put(info->clk);
404errout3:
405 iounmap(info->adc_base_spear6xx);
406errout2:
407 iio_device_free(iodev);
408errout1:
409 return ret;
410}
411
412static int __devexit spear_adc_remove(struct platform_device *pdev)
413{
414 struct iio_dev *iodev = platform_get_drvdata(pdev);
415 struct spear_adc_info *info = iio_priv(iodev);
416
417 iio_device_unregister(iodev);
418 platform_set_drvdata(pdev, NULL);
419 clk_disable(info->clk);
420 clk_unprepare(info->clk);
421 clk_put(info->clk);
422 iounmap(info->adc_base_spear6xx);
423 iio_device_free(iodev);
424
425 return 0;
426}
427
428static const struct of_device_id spear_adc_dt_ids[] = {
429 { .compatible = "st,spear600-adc", },
430 { /* sentinel */ }
431};
432MODULE_DEVICE_TABLE(of, spear_adc_dt_ids);
433
434static struct platform_driver spear_adc_driver = {
435 .probe = spear_adc_probe,
436 .remove = __devexit_p(spear_adc_remove),
437 .driver = {
438 .name = MOD_NAME,
439 .owner = THIS_MODULE,
440 .of_match_table = of_match_ptr(spear_adc_dt_ids),
441 },
442};
443
444module_platform_driver(spear_adc_driver);
445
446MODULE_AUTHOR("Stefan Roese <sr@denx.de>");
447MODULE_DESCRIPTION("SPEAr ADC driver");
448MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index fd6a45444058..8fb014a046a2 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -19,9 +19,9 @@
19#include <linux/rtc.h> 19#include <linux/rtc.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22#include "../iio.h" 22#include <linux/iio/iio.h>
23#include "../events.h" 23#include <linux/iio/events.h>
24#include "../sysfs.h" 24#include <linux/iio/sysfs.h>
25#include "adt7316.h" 25#include "adt7316.h"
26 26
27/* 27/*
@@ -220,7 +220,7 @@ static ssize_t adt7316_show_enabled(struct device *dev,
220 struct device_attribute *attr, 220 struct device_attribute *attr,
221 char *buf) 221 char *buf)
222{ 222{
223 struct iio_dev *dev_info = dev_get_drvdata(dev); 223 struct iio_dev *dev_info = dev_to_iio_dev(dev);
224 struct adt7316_chip_info *chip = iio_priv(dev_info); 224 struct adt7316_chip_info *chip = iio_priv(dev_info);
225 225
226 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_EN)); 226 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_EN));
@@ -252,7 +252,7 @@ static ssize_t adt7316_store_enabled(struct device *dev,
252 const char *buf, 252 const char *buf,
253 size_t len) 253 size_t len)
254{ 254{
255 struct iio_dev *dev_info = dev_get_drvdata(dev); 255 struct iio_dev *dev_info = dev_to_iio_dev(dev);
256 struct adt7316_chip_info *chip = iio_priv(dev_info); 256 struct adt7316_chip_info *chip = iio_priv(dev_info);
257 int enable; 257 int enable;
258 258
@@ -276,7 +276,7 @@ static ssize_t adt7316_show_select_ex_temp(struct device *dev,
276 struct device_attribute *attr, 276 struct device_attribute *attr,
277 char *buf) 277 char *buf)
278{ 278{
279 struct iio_dev *dev_info = dev_get_drvdata(dev); 279 struct iio_dev *dev_info = dev_to_iio_dev(dev);
280 struct adt7316_chip_info *chip = iio_priv(dev_info); 280 struct adt7316_chip_info *chip = iio_priv(dev_info);
281 281
282 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX) 282 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
@@ -290,7 +290,7 @@ static ssize_t adt7316_store_select_ex_temp(struct device *dev,
290 const char *buf, 290 const char *buf,
291 size_t len) 291 size_t len)
292{ 292{
293 struct iio_dev *dev_info = dev_get_drvdata(dev); 293 struct iio_dev *dev_info = dev_to_iio_dev(dev);
294 struct adt7316_chip_info *chip = iio_priv(dev_info); 294 struct adt7316_chip_info *chip = iio_priv(dev_info);
295 u8 config1; 295 u8 config1;
296 int ret; 296 int ret;
@@ -320,7 +320,7 @@ static ssize_t adt7316_show_mode(struct device *dev,
320 struct device_attribute *attr, 320 struct device_attribute *attr,
321 char *buf) 321 char *buf)
322{ 322{
323 struct iio_dev *dev_info = dev_get_drvdata(dev); 323 struct iio_dev *dev_info = dev_to_iio_dev(dev);
324 struct adt7316_chip_info *chip = iio_priv(dev_info); 324 struct adt7316_chip_info *chip = iio_priv(dev_info);
325 325
326 if (chip->config2 & ADT7316_AD_SINGLE_CH_MODE) 326 if (chip->config2 & ADT7316_AD_SINGLE_CH_MODE)
@@ -334,7 +334,7 @@ static ssize_t adt7316_store_mode(struct device *dev,
334 const char *buf, 334 const char *buf,
335 size_t len) 335 size_t len)
336{ 336{
337 struct iio_dev *dev_info = dev_get_drvdata(dev); 337 struct iio_dev *dev_info = dev_to_iio_dev(dev);
338 struct adt7316_chip_info *chip = iio_priv(dev_info); 338 struct adt7316_chip_info *chip = iio_priv(dev_info);
339 u8 config2; 339 u8 config2;
340 int ret; 340 int ret;
@@ -370,7 +370,7 @@ static ssize_t adt7316_show_ad_channel(struct device *dev,
370 struct device_attribute *attr, 370 struct device_attribute *attr,
371 char *buf) 371 char *buf)
372{ 372{
373 struct iio_dev *dev_info = dev_get_drvdata(dev); 373 struct iio_dev *dev_info = dev_to_iio_dev(dev);
374 struct adt7316_chip_info *chip = iio_priv(dev_info); 374 struct adt7316_chip_info *chip = iio_priv(dev_info);
375 375
376 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE)) 376 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE))
@@ -409,7 +409,7 @@ static ssize_t adt7316_store_ad_channel(struct device *dev,
409 const char *buf, 409 const char *buf,
410 size_t len) 410 size_t len)
411{ 411{
412 struct iio_dev *dev_info = dev_get_drvdata(dev); 412 struct iio_dev *dev_info = dev_to_iio_dev(dev);
413 struct adt7316_chip_info *chip = iio_priv(dev_info); 413 struct adt7316_chip_info *chip = iio_priv(dev_info);
414 u8 config2; 414 u8 config2;
415 unsigned long data = 0; 415 unsigned long data = 0;
@@ -455,7 +455,7 @@ static ssize_t adt7316_show_all_ad_channels(struct device *dev,
455 struct device_attribute *attr, 455 struct device_attribute *attr,
456 char *buf) 456 char *buf)
457{ 457{
458 struct iio_dev *dev_info = dev_get_drvdata(dev); 458 struct iio_dev *dev_info = dev_to_iio_dev(dev);
459 struct adt7316_chip_info *chip = iio_priv(dev_info); 459 struct adt7316_chip_info *chip = iio_priv(dev_info);
460 460
461 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE)) 461 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE))
@@ -477,7 +477,7 @@ static ssize_t adt7316_show_disable_averaging(struct device *dev,
477 struct device_attribute *attr, 477 struct device_attribute *attr,
478 char *buf) 478 char *buf)
479{ 479{
480 struct iio_dev *dev_info = dev_get_drvdata(dev); 480 struct iio_dev *dev_info = dev_to_iio_dev(dev);
481 struct adt7316_chip_info *chip = iio_priv(dev_info); 481 struct adt7316_chip_info *chip = iio_priv(dev_info);
482 482
483 return sprintf(buf, "%d\n", 483 return sprintf(buf, "%d\n",
@@ -489,7 +489,7 @@ static ssize_t adt7316_store_disable_averaging(struct device *dev,
489 const char *buf, 489 const char *buf,
490 size_t len) 490 size_t len)
491{ 491{
492 struct iio_dev *dev_info = dev_get_drvdata(dev); 492 struct iio_dev *dev_info = dev_to_iio_dev(dev);
493 struct adt7316_chip_info *chip = iio_priv(dev_info); 493 struct adt7316_chip_info *chip = iio_priv(dev_info);
494 u8 config2; 494 u8 config2;
495 int ret; 495 int ret;
@@ -516,7 +516,7 @@ static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev,
516 struct device_attribute *attr, 516 struct device_attribute *attr,
517 char *buf) 517 char *buf)
518{ 518{
519 struct iio_dev *dev_info = dev_get_drvdata(dev); 519 struct iio_dev *dev_info = dev_to_iio_dev(dev);
520 struct adt7316_chip_info *chip = iio_priv(dev_info); 520 struct adt7316_chip_info *chip = iio_priv(dev_info);
521 521
522 return sprintf(buf, "%d\n", 522 return sprintf(buf, "%d\n",
@@ -528,7 +528,7 @@ static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
528 const char *buf, 528 const char *buf,
529 size_t len) 529 size_t len)
530{ 530{
531 struct iio_dev *dev_info = dev_get_drvdata(dev); 531 struct iio_dev *dev_info = dev_to_iio_dev(dev);
532 struct adt7316_chip_info *chip = iio_priv(dev_info); 532 struct adt7316_chip_info *chip = iio_priv(dev_info);
533 u8 config2; 533 u8 config2;
534 int ret; 534 int ret;
@@ -557,7 +557,7 @@ static ssize_t adt7316_store_reset(struct device *dev,
557 const char *buf, 557 const char *buf,
558 size_t len) 558 size_t len)
559{ 559{
560 struct iio_dev *dev_info = dev_get_drvdata(dev); 560 struct iio_dev *dev_info = dev_to_iio_dev(dev);
561 struct adt7316_chip_info *chip = iio_priv(dev_info); 561 struct adt7316_chip_info *chip = iio_priv(dev_info);
562 u8 config2; 562 u8 config2;
563 int ret; 563 int ret;
@@ -580,7 +580,7 @@ static ssize_t adt7316_show_powerdown(struct device *dev,
580 struct device_attribute *attr, 580 struct device_attribute *attr,
581 char *buf) 581 char *buf)
582{ 582{
583 struct iio_dev *dev_info = dev_get_drvdata(dev); 583 struct iio_dev *dev_info = dev_to_iio_dev(dev);
584 struct adt7316_chip_info *chip = iio_priv(dev_info); 584 struct adt7316_chip_info *chip = iio_priv(dev_info);
585 585
586 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_PD)); 586 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_PD));
@@ -591,7 +591,7 @@ static ssize_t adt7316_store_powerdown(struct device *dev,
591 const char *buf, 591 const char *buf,
592 size_t len) 592 size_t len)
593{ 593{
594 struct iio_dev *dev_info = dev_get_drvdata(dev); 594 struct iio_dev *dev_info = dev_to_iio_dev(dev);
595 struct adt7316_chip_info *chip = iio_priv(dev_info); 595 struct adt7316_chip_info *chip = iio_priv(dev_info);
596 u8 config1; 596 u8 config1;
597 int ret; 597 int ret;
@@ -618,7 +618,7 @@ static ssize_t adt7316_show_fast_ad_clock(struct device *dev,
618 struct device_attribute *attr, 618 struct device_attribute *attr,
619 char *buf) 619 char *buf)
620{ 620{
621 struct iio_dev *dev_info = dev_get_drvdata(dev); 621 struct iio_dev *dev_info = dev_to_iio_dev(dev);
622 struct adt7316_chip_info *chip = iio_priv(dev_info); 622 struct adt7316_chip_info *chip = iio_priv(dev_info);
623 623
624 return sprintf(buf, "%d\n", !!(chip->config3 & ADT7316_ADCLK_22_5)); 624 return sprintf(buf, "%d\n", !!(chip->config3 & ADT7316_ADCLK_22_5));
@@ -629,7 +629,7 @@ static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
629 const char *buf, 629 const char *buf,
630 size_t len) 630 size_t len)
631{ 631{
632 struct iio_dev *dev_info = dev_get_drvdata(dev); 632 struct iio_dev *dev_info = dev_to_iio_dev(dev);
633 struct adt7316_chip_info *chip = iio_priv(dev_info); 633 struct adt7316_chip_info *chip = iio_priv(dev_info);
634 u8 config3; 634 u8 config3;
635 int ret; 635 int ret;
@@ -656,7 +656,7 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev,
656 struct device_attribute *attr, 656 struct device_attribute *attr,
657 char *buf) 657 char *buf)
658{ 658{
659 struct iio_dev *dev_info = dev_get_drvdata(dev); 659 struct iio_dev *dev_info = dev_to_iio_dev(dev);
660 struct adt7316_chip_info *chip = iio_priv(dev_info); 660 struct adt7316_chip_info *chip = iio_priv(dev_info);
661 661
662 if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) { 662 if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) {
@@ -674,7 +674,7 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
674 const char *buf, 674 const char *buf,
675 size_t len) 675 size_t len)
676{ 676{
677 struct iio_dev *dev_info = dev_get_drvdata(dev); 677 struct iio_dev *dev_info = dev_to_iio_dev(dev);
678 struct adt7316_chip_info *chip = iio_priv(dev_info); 678 struct adt7316_chip_info *chip = iio_priv(dev_info);
679 u8 config3; 679 u8 config3;
680 int ret; 680 int ret;
@@ -708,7 +708,7 @@ static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev,
708 struct device_attribute *attr, 708 struct device_attribute *attr,
709 char *buf) 709 char *buf)
710{ 710{
711 struct iio_dev *dev_info = dev_get_drvdata(dev); 711 struct iio_dev *dev_info = dev_to_iio_dev(dev);
712 struct adt7316_chip_info *chip = iio_priv(dev_info); 712 struct adt7316_chip_info *chip = iio_priv(dev_info);
713 713
714 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX) 714 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
@@ -723,7 +723,7 @@ static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
723 const char *buf, 723 const char *buf,
724 size_t len) 724 size_t len)
725{ 725{
726 struct iio_dev *dev_info = dev_get_drvdata(dev); 726 struct iio_dev *dev_info = dev_to_iio_dev(dev);
727 struct adt7316_chip_info *chip = iio_priv(dev_info); 727 struct adt7316_chip_info *chip = iio_priv(dev_info);
728 u8 config3; 728 u8 config3;
729 int ret; 729 int ret;
@@ -755,7 +755,7 @@ static ssize_t adt7316_show_enable_prop_DACA(struct device *dev,
755 struct device_attribute *attr, 755 struct device_attribute *attr,
756 char *buf) 756 char *buf)
757{ 757{
758 struct iio_dev *dev_info = dev_get_drvdata(dev); 758 struct iio_dev *dev_info = dev_to_iio_dev(dev);
759 struct adt7316_chip_info *chip = iio_priv(dev_info); 759 struct adt7316_chip_info *chip = iio_priv(dev_info);
760 760
761 return sprintf(buf, "%d\n", 761 return sprintf(buf, "%d\n",
@@ -767,7 +767,7 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
767 const char *buf, 767 const char *buf,
768 size_t len) 768 size_t len)
769{ 769{
770 struct iio_dev *dev_info = dev_get_drvdata(dev); 770 struct iio_dev *dev_info = dev_to_iio_dev(dev);
771 struct adt7316_chip_info *chip = iio_priv(dev_info); 771 struct adt7316_chip_info *chip = iio_priv(dev_info);
772 u8 config3; 772 u8 config3;
773 int ret; 773 int ret;
@@ -794,7 +794,7 @@ static ssize_t adt7316_show_enable_prop_DACB(struct device *dev,
794 struct device_attribute *attr, 794 struct device_attribute *attr,
795 char *buf) 795 char *buf)
796{ 796{
797 struct iio_dev *dev_info = dev_get_drvdata(dev); 797 struct iio_dev *dev_info = dev_to_iio_dev(dev);
798 struct adt7316_chip_info *chip = iio_priv(dev_info); 798 struct adt7316_chip_info *chip = iio_priv(dev_info);
799 799
800 return sprintf(buf, "%d\n", 800 return sprintf(buf, "%d\n",
@@ -806,7 +806,7 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
806 const char *buf, 806 const char *buf,
807 size_t len) 807 size_t len)
808{ 808{
809 struct iio_dev *dev_info = dev_get_drvdata(dev); 809 struct iio_dev *dev_info = dev_to_iio_dev(dev);
810 struct adt7316_chip_info *chip = iio_priv(dev_info); 810 struct adt7316_chip_info *chip = iio_priv(dev_info);
811 u8 config3; 811 u8 config3;
812 int ret; 812 int ret;
@@ -833,7 +833,7 @@ static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev,
833 struct device_attribute *attr, 833 struct device_attribute *attr,
834 char *buf) 834 char *buf)
835{ 835{
836 struct iio_dev *dev_info = dev_get_drvdata(dev); 836 struct iio_dev *dev_info = dev_to_iio_dev(dev);
837 struct adt7316_chip_info *chip = iio_priv(dev_info); 837 struct adt7316_chip_info *chip = iio_priv(dev_info);
838 838
839 return sprintf(buf, "0x%x\n", 839 return sprintf(buf, "0x%x\n",
@@ -845,7 +845,7 @@ static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev,
845 const char *buf, 845 const char *buf,
846 size_t len) 846 size_t len)
847{ 847{
848 struct iio_dev *dev_info = dev_get_drvdata(dev); 848 struct iio_dev *dev_info = dev_to_iio_dev(dev);
849 struct adt7316_chip_info *chip = iio_priv(dev_info); 849 struct adt7316_chip_info *chip = iio_priv(dev_info);
850 u8 dac_config; 850 u8 dac_config;
851 unsigned long data = 0; 851 unsigned long data = 0;
@@ -876,7 +876,7 @@ static ssize_t adt7316_show_DAC_update_mode(struct device *dev,
876 struct device_attribute *attr, 876 struct device_attribute *attr,
877 char *buf) 877 char *buf)
878{ 878{
879 struct iio_dev *dev_info = dev_get_drvdata(dev); 879 struct iio_dev *dev_info = dev_to_iio_dev(dev);
880 struct adt7316_chip_info *chip = iio_priv(dev_info); 880 struct adt7316_chip_info *chip = iio_priv(dev_info);
881 881
882 if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)) 882 if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA))
@@ -900,7 +900,7 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
900 const char *buf, 900 const char *buf,
901 size_t len) 901 size_t len)
902{ 902{
903 struct iio_dev *dev_info = dev_get_drvdata(dev); 903 struct iio_dev *dev_info = dev_to_iio_dev(dev);
904 struct adt7316_chip_info *chip = iio_priv(dev_info); 904 struct adt7316_chip_info *chip = iio_priv(dev_info);
905 u8 dac_config; 905 u8 dac_config;
906 unsigned long data; 906 unsigned long data;
@@ -934,7 +934,7 @@ static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev,
934 struct device_attribute *attr, 934 struct device_attribute *attr,
935 char *buf) 935 char *buf)
936{ 936{
937 struct iio_dev *dev_info = dev_get_drvdata(dev); 937 struct iio_dev *dev_info = dev_to_iio_dev(dev);
938 struct adt7316_chip_info *chip = iio_priv(dev_info); 938 struct adt7316_chip_info *chip = iio_priv(dev_info);
939 939
940 if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA) 940 if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)
@@ -955,7 +955,7 @@ static ssize_t adt7316_store_update_DAC(struct device *dev,
955 const char *buf, 955 const char *buf,
956 size_t len) 956 size_t len)
957{ 957{
958 struct iio_dev *dev_info = dev_get_drvdata(dev); 958 struct iio_dev *dev_info = dev_to_iio_dev(dev);
959 struct adt7316_chip_info *chip = iio_priv(dev_info); 959 struct adt7316_chip_info *chip = iio_priv(dev_info);
960 u8 ldac_config; 960 u8 ldac_config;
961 unsigned long data; 961 unsigned long data;
@@ -994,7 +994,7 @@ static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev,
994 struct device_attribute *attr, 994 struct device_attribute *attr,
995 char *buf) 995 char *buf)
996{ 996{
997 struct iio_dev *dev_info = dev_get_drvdata(dev); 997 struct iio_dev *dev_info = dev_to_iio_dev(dev);
998 struct adt7316_chip_info *chip = iio_priv(dev_info); 998 struct adt7316_chip_info *chip = iio_priv(dev_info);
999 999
1000 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) 1000 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
@@ -1009,7 +1009,7 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
1009 const char *buf, 1009 const char *buf,
1010 size_t len) 1010 size_t len)
1011{ 1011{
1012 struct iio_dev *dev_info = dev_get_drvdata(dev); 1012 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1013 struct adt7316_chip_info *chip = iio_priv(dev_info); 1013 struct adt7316_chip_info *chip = iio_priv(dev_info);
1014 u8 dac_config; 1014 u8 dac_config;
1015 int ret; 1015 int ret;
@@ -1039,7 +1039,7 @@ static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev,
1039 struct device_attribute *attr, 1039 struct device_attribute *attr,
1040 char *buf) 1040 char *buf)
1041{ 1041{
1042 struct iio_dev *dev_info = dev_get_drvdata(dev); 1042 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1043 struct adt7316_chip_info *chip = iio_priv(dev_info); 1043 struct adt7316_chip_info *chip = iio_priv(dev_info);
1044 1044
1045 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) 1045 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
@@ -1054,7 +1054,7 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
1054 const char *buf, 1054 const char *buf,
1055 size_t len) 1055 size_t len)
1056{ 1056{
1057 struct iio_dev *dev_info = dev_get_drvdata(dev); 1057 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1058 struct adt7316_chip_info *chip = iio_priv(dev_info); 1058 struct adt7316_chip_info *chip = iio_priv(dev_info);
1059 u8 dac_config; 1059 u8 dac_config;
1060 int ret; 1060 int ret;
@@ -1084,7 +1084,7 @@ static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev,
1084 struct device_attribute *attr, 1084 struct device_attribute *attr,
1085 char *buf) 1085 char *buf)
1086{ 1086{
1087 struct iio_dev *dev_info = dev_get_drvdata(dev); 1087 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1088 struct adt7316_chip_info *chip = iio_priv(dev_info); 1088 struct adt7316_chip_info *chip = iio_priv(dev_info);
1089 1089
1090 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) 1090 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
@@ -1101,7 +1101,7 @@ static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev,
1101 const char *buf, 1101 const char *buf,
1102 size_t len) 1102 size_t len)
1103{ 1103{
1104 struct iio_dev *dev_info = dev_get_drvdata(dev); 1104 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1105 struct adt7316_chip_info *chip = iio_priv(dev_info); 1105 struct adt7316_chip_info *chip = iio_priv(dev_info);
1106 u8 ldac_config; 1106 u8 ldac_config;
1107 unsigned long data; 1107 unsigned long data;
@@ -1220,7 +1220,7 @@ static ssize_t adt7316_show_VDD(struct device *dev,
1220 struct device_attribute *attr, 1220 struct device_attribute *attr,
1221 char *buf) 1221 char *buf)
1222{ 1222{
1223 struct iio_dev *dev_info = dev_get_drvdata(dev); 1223 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1224 struct adt7316_chip_info *chip = iio_priv(dev_info); 1224 struct adt7316_chip_info *chip = iio_priv(dev_info);
1225 1225
1226 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_VDD, buf); 1226 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_VDD, buf);
@@ -1231,7 +1231,7 @@ static ssize_t adt7316_show_in_temp(struct device *dev,
1231 struct device_attribute *attr, 1231 struct device_attribute *attr,
1232 char *buf) 1232 char *buf)
1233{ 1233{
1234 struct iio_dev *dev_info = dev_get_drvdata(dev); 1234 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1235 struct adt7316_chip_info *chip = iio_priv(dev_info); 1235 struct adt7316_chip_info *chip = iio_priv(dev_info);
1236 1236
1237 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_IN, buf); 1237 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_IN, buf);
@@ -1243,7 +1243,7 @@ static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev,
1243 struct device_attribute *attr, 1243 struct device_attribute *attr,
1244 char *buf) 1244 char *buf)
1245{ 1245{
1246 struct iio_dev *dev_info = dev_get_drvdata(dev); 1246 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1247 struct adt7316_chip_info *chip = iio_priv(dev_info); 1247 struct adt7316_chip_info *chip = iio_priv(dev_info);
1248 1248
1249 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_EX, buf); 1249 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_EX, buf);
@@ -1256,7 +1256,7 @@ static ssize_t adt7316_show_AIN2(struct device *dev,
1256 struct device_attribute *attr, 1256 struct device_attribute *attr,
1257 char *buf) 1257 char *buf)
1258{ 1258{
1259 struct iio_dev *dev_info = dev_get_drvdata(dev); 1259 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1260 struct adt7316_chip_info *chip = iio_priv(dev_info); 1260 struct adt7316_chip_info *chip = iio_priv(dev_info);
1261 1261
1262 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN2, buf); 1262 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN2, buf);
@@ -1267,7 +1267,7 @@ static ssize_t adt7316_show_AIN3(struct device *dev,
1267 struct device_attribute *attr, 1267 struct device_attribute *attr,
1268 char *buf) 1268 char *buf)
1269{ 1269{
1270 struct iio_dev *dev_info = dev_get_drvdata(dev); 1270 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1271 struct adt7316_chip_info *chip = iio_priv(dev_info); 1271 struct adt7316_chip_info *chip = iio_priv(dev_info);
1272 1272
1273 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN3, buf); 1273 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN3, buf);
@@ -1278,7 +1278,7 @@ static ssize_t adt7316_show_AIN4(struct device *dev,
1278 struct device_attribute *attr, 1278 struct device_attribute *attr,
1279 char *buf) 1279 char *buf)
1280{ 1280{
1281 struct iio_dev *dev_info = dev_get_drvdata(dev); 1281 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1282 struct adt7316_chip_info *chip = iio_priv(dev_info); 1282 struct adt7316_chip_info *chip = iio_priv(dev_info);
1283 1283
1284 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN4, buf); 1284 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN4, buf);
@@ -1330,7 +1330,7 @@ static ssize_t adt7316_show_in_temp_offset(struct device *dev,
1330 struct device_attribute *attr, 1330 struct device_attribute *attr,
1331 char *buf) 1331 char *buf)
1332{ 1332{
1333 struct iio_dev *dev_info = dev_get_drvdata(dev); 1333 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1334 struct adt7316_chip_info *chip = iio_priv(dev_info); 1334 struct adt7316_chip_info *chip = iio_priv(dev_info);
1335 1335
1336 return adt7316_show_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf); 1336 return adt7316_show_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf);
@@ -1341,7 +1341,7 @@ static ssize_t adt7316_store_in_temp_offset(struct device *dev,
1341 const char *buf, 1341 const char *buf,
1342 size_t len) 1342 size_t len)
1343{ 1343{
1344 struct iio_dev *dev_info = dev_get_drvdata(dev); 1344 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1345 struct adt7316_chip_info *chip = iio_priv(dev_info); 1345 struct adt7316_chip_info *chip = iio_priv(dev_info);
1346 1346
1347 return adt7316_store_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf, len); 1347 return adt7316_store_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf, len);
@@ -1355,7 +1355,7 @@ static ssize_t adt7316_show_ex_temp_offset(struct device *dev,
1355 struct device_attribute *attr, 1355 struct device_attribute *attr,
1356 char *buf) 1356 char *buf)
1357{ 1357{
1358 struct iio_dev *dev_info = dev_get_drvdata(dev); 1358 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1359 struct adt7316_chip_info *chip = iio_priv(dev_info); 1359 struct adt7316_chip_info *chip = iio_priv(dev_info);
1360 1360
1361 return adt7316_show_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf); 1361 return adt7316_show_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf);
@@ -1366,7 +1366,7 @@ static ssize_t adt7316_store_ex_temp_offset(struct device *dev,
1366 const char *buf, 1366 const char *buf,
1367 size_t len) 1367 size_t len)
1368{ 1368{
1369 struct iio_dev *dev_info = dev_get_drvdata(dev); 1369 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1370 struct adt7316_chip_info *chip = iio_priv(dev_info); 1370 struct adt7316_chip_info *chip = iio_priv(dev_info);
1371 1371
1372 return adt7316_store_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf, len); 1372 return adt7316_store_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf, len);
@@ -1380,7 +1380,7 @@ static ssize_t adt7316_show_in_analog_temp_offset(struct device *dev,
1380 struct device_attribute *attr, 1380 struct device_attribute *attr,
1381 char *buf) 1381 char *buf)
1382{ 1382{
1383 struct iio_dev *dev_info = dev_get_drvdata(dev); 1383 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1384 struct adt7316_chip_info *chip = iio_priv(dev_info); 1384 struct adt7316_chip_info *chip = iio_priv(dev_info);
1385 1385
1386 return adt7316_show_temp_offset(chip, 1386 return adt7316_show_temp_offset(chip,
@@ -1392,7 +1392,7 @@ static ssize_t adt7316_store_in_analog_temp_offset(struct device *dev,
1392 const char *buf, 1392 const char *buf,
1393 size_t len) 1393 size_t len)
1394{ 1394{
1395 struct iio_dev *dev_info = dev_get_drvdata(dev); 1395 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1396 struct adt7316_chip_info *chip = iio_priv(dev_info); 1396 struct adt7316_chip_info *chip = iio_priv(dev_info);
1397 1397
1398 return adt7316_store_temp_offset(chip, 1398 return adt7316_store_temp_offset(chip,
@@ -1407,7 +1407,7 @@ static ssize_t adt7316_show_ex_analog_temp_offset(struct device *dev,
1407 struct device_attribute *attr, 1407 struct device_attribute *attr,
1408 char *buf) 1408 char *buf)
1409{ 1409{
1410 struct iio_dev *dev_info = dev_get_drvdata(dev); 1410 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1411 struct adt7316_chip_info *chip = iio_priv(dev_info); 1411 struct adt7316_chip_info *chip = iio_priv(dev_info);
1412 1412
1413 return adt7316_show_temp_offset(chip, 1413 return adt7316_show_temp_offset(chip,
@@ -1419,7 +1419,7 @@ static ssize_t adt7316_store_ex_analog_temp_offset(struct device *dev,
1419 const char *buf, 1419 const char *buf,
1420 size_t len) 1420 size_t len)
1421{ 1421{
1422 struct iio_dev *dev_info = dev_get_drvdata(dev); 1422 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1423 struct adt7316_chip_info *chip = iio_priv(dev_info); 1423 struct adt7316_chip_info *chip = iio_priv(dev_info);
1424 1424
1425 return adt7316_store_temp_offset(chip, 1425 return adt7316_store_temp_offset(chip,
@@ -1504,7 +1504,7 @@ static ssize_t adt7316_show_DAC_A(struct device *dev,
1504 struct device_attribute *attr, 1504 struct device_attribute *attr,
1505 char *buf) 1505 char *buf)
1506{ 1506{
1507 struct iio_dev *dev_info = dev_get_drvdata(dev); 1507 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1508 struct adt7316_chip_info *chip = iio_priv(dev_info); 1508 struct adt7316_chip_info *chip = iio_priv(dev_info);
1509 1509
1510 return adt7316_show_DAC(chip, 0, buf); 1510 return adt7316_show_DAC(chip, 0, buf);
@@ -1515,7 +1515,7 @@ static ssize_t adt7316_store_DAC_A(struct device *dev,
1515 const char *buf, 1515 const char *buf,
1516 size_t len) 1516 size_t len)
1517{ 1517{
1518 struct iio_dev *dev_info = dev_get_drvdata(dev); 1518 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1519 struct adt7316_chip_info *chip = iio_priv(dev_info); 1519 struct adt7316_chip_info *chip = iio_priv(dev_info);
1520 1520
1521 return adt7316_store_DAC(chip, 0, buf, len); 1521 return adt7316_store_DAC(chip, 0, buf, len);
@@ -1528,7 +1528,7 @@ static ssize_t adt7316_show_DAC_B(struct device *dev,
1528 struct device_attribute *attr, 1528 struct device_attribute *attr,
1529 char *buf) 1529 char *buf)
1530{ 1530{
1531 struct iio_dev *dev_info = dev_get_drvdata(dev); 1531 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1532 struct adt7316_chip_info *chip = iio_priv(dev_info); 1532 struct adt7316_chip_info *chip = iio_priv(dev_info);
1533 1533
1534 return adt7316_show_DAC(chip, 1, buf); 1534 return adt7316_show_DAC(chip, 1, buf);
@@ -1539,7 +1539,7 @@ static ssize_t adt7316_store_DAC_B(struct device *dev,
1539 const char *buf, 1539 const char *buf,
1540 size_t len) 1540 size_t len)
1541{ 1541{
1542 struct iio_dev *dev_info = dev_get_drvdata(dev); 1542 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1543 struct adt7316_chip_info *chip = iio_priv(dev_info); 1543 struct adt7316_chip_info *chip = iio_priv(dev_info);
1544 1544
1545 return adt7316_store_DAC(chip, 1, buf, len); 1545 return adt7316_store_DAC(chip, 1, buf, len);
@@ -1552,7 +1552,7 @@ static ssize_t adt7316_show_DAC_C(struct device *dev,
1552 struct device_attribute *attr, 1552 struct device_attribute *attr,
1553 char *buf) 1553 char *buf)
1554{ 1554{
1555 struct iio_dev *dev_info = dev_get_drvdata(dev); 1555 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1556 struct adt7316_chip_info *chip = iio_priv(dev_info); 1556 struct adt7316_chip_info *chip = iio_priv(dev_info);
1557 1557
1558 return adt7316_show_DAC(chip, 2, buf); 1558 return adt7316_show_DAC(chip, 2, buf);
@@ -1563,7 +1563,7 @@ static ssize_t adt7316_store_DAC_C(struct device *dev,
1563 const char *buf, 1563 const char *buf,
1564 size_t len) 1564 size_t len)
1565{ 1565{
1566 struct iio_dev *dev_info = dev_get_drvdata(dev); 1566 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1567 struct adt7316_chip_info *chip = iio_priv(dev_info); 1567 struct adt7316_chip_info *chip = iio_priv(dev_info);
1568 1568
1569 return adt7316_store_DAC(chip, 2, buf, len); 1569 return adt7316_store_DAC(chip, 2, buf, len);
@@ -1576,7 +1576,7 @@ static ssize_t adt7316_show_DAC_D(struct device *dev,
1576 struct device_attribute *attr, 1576 struct device_attribute *attr,
1577 char *buf) 1577 char *buf)
1578{ 1578{
1579 struct iio_dev *dev_info = dev_get_drvdata(dev); 1579 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1580 struct adt7316_chip_info *chip = iio_priv(dev_info); 1580 struct adt7316_chip_info *chip = iio_priv(dev_info);
1581 1581
1582 return adt7316_show_DAC(chip, 3, buf); 1582 return adt7316_show_DAC(chip, 3, buf);
@@ -1587,7 +1587,7 @@ static ssize_t adt7316_store_DAC_D(struct device *dev,
1587 const char *buf, 1587 const char *buf,
1588 size_t len) 1588 size_t len)
1589{ 1589{
1590 struct iio_dev *dev_info = dev_get_drvdata(dev); 1590 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1591 struct adt7316_chip_info *chip = iio_priv(dev_info); 1591 struct adt7316_chip_info *chip = iio_priv(dev_info);
1592 1592
1593 return adt7316_store_DAC(chip, 3, buf, len); 1593 return adt7316_store_DAC(chip, 3, buf, len);
@@ -1600,7 +1600,7 @@ static ssize_t adt7316_show_device_id(struct device *dev,
1600 struct device_attribute *attr, 1600 struct device_attribute *attr,
1601 char *buf) 1601 char *buf)
1602{ 1602{
1603 struct iio_dev *dev_info = dev_get_drvdata(dev); 1603 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1604 struct adt7316_chip_info *chip = iio_priv(dev_info); 1604 struct adt7316_chip_info *chip = iio_priv(dev_info);
1605 u8 id; 1605 u8 id;
1606 int ret; 1606 int ret;
@@ -1618,7 +1618,7 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev,
1618 struct device_attribute *attr, 1618 struct device_attribute *attr,
1619 char *buf) 1619 char *buf)
1620{ 1620{
1621 struct iio_dev *dev_info = dev_get_drvdata(dev); 1621 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1622 struct adt7316_chip_info *chip = iio_priv(dev_info); 1622 struct adt7316_chip_info *chip = iio_priv(dev_info);
1623 u8 id; 1623 u8 id;
1624 int ret; 1624 int ret;
@@ -1637,7 +1637,7 @@ static ssize_t adt7316_show_device_rev(struct device *dev,
1637 struct device_attribute *attr, 1637 struct device_attribute *attr,
1638 char *buf) 1638 char *buf)
1639{ 1639{
1640 struct iio_dev *dev_info = dev_get_drvdata(dev); 1640 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1641 struct adt7316_chip_info *chip = iio_priv(dev_info); 1641 struct adt7316_chip_info *chip = iio_priv(dev_info);
1642 u8 rev; 1642 u8 rev;
1643 int ret; 1643 int ret;
@@ -1655,7 +1655,7 @@ static ssize_t adt7316_show_bus_type(struct device *dev,
1655 struct device_attribute *attr, 1655 struct device_attribute *attr,
1656 char *buf) 1656 char *buf)
1657{ 1657{
1658 struct iio_dev *dev_info = dev_get_drvdata(dev); 1658 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1659 struct adt7316_chip_info *chip = iio_priv(dev_info); 1659 struct adt7316_chip_info *chip = iio_priv(dev_info);
1660 u8 stat; 1660 u8 stat;
1661 int ret; 1661 int ret;
@@ -1841,7 +1841,7 @@ static ssize_t adt7316_show_int_mask(struct device *dev,
1841 struct device_attribute *attr, 1841 struct device_attribute *attr,
1842 char *buf) 1842 char *buf)
1843{ 1843{
1844 struct iio_dev *dev_info = dev_get_drvdata(dev); 1844 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1845 struct adt7316_chip_info *chip = iio_priv(dev_info); 1845 struct adt7316_chip_info *chip = iio_priv(dev_info);
1846 1846
1847 return sprintf(buf, "0x%x\n", chip->int_mask); 1847 return sprintf(buf, "0x%x\n", chip->int_mask);
@@ -1855,7 +1855,7 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
1855 const char *buf, 1855 const char *buf,
1856 size_t len) 1856 size_t len)
1857{ 1857{
1858 struct iio_dev *dev_info = dev_get_drvdata(dev); 1858 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1859 struct adt7316_chip_info *chip = iio_priv(dev_info); 1859 struct adt7316_chip_info *chip = iio_priv(dev_info);
1860 unsigned long data; 1860 unsigned long data;
1861 int ret; 1861 int ret;
@@ -1895,7 +1895,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
1895 char *buf) 1895 char *buf)
1896{ 1896{
1897 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 1897 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
1898 struct iio_dev *dev_info = dev_get_drvdata(dev); 1898 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1899 struct adt7316_chip_info *chip = iio_priv(dev_info); 1899 struct adt7316_chip_info *chip = iio_priv(dev_info);
1900 u8 val; 1900 u8 val;
1901 int data; 1901 int data;
@@ -1926,7 +1926,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev,
1926 size_t len) 1926 size_t len)
1927{ 1927{
1928 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 1928 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
1929 struct iio_dev *dev_info = dev_get_drvdata(dev); 1929 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1930 struct adt7316_chip_info *chip = iio_priv(dev_info); 1930 struct adt7316_chip_info *chip = iio_priv(dev_info);
1931 long data; 1931 long data;
1932 u8 val; 1932 u8 val;
@@ -1965,7 +1965,7 @@ static ssize_t adt7316_show_int_enabled(struct device *dev,
1965 struct device_attribute *attr, 1965 struct device_attribute *attr,
1966 char *buf) 1966 char *buf)
1967{ 1967{
1968 struct iio_dev *dev_info = dev_get_drvdata(dev); 1968 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1969 struct adt7316_chip_info *chip = iio_priv(dev_info); 1969 struct adt7316_chip_info *chip = iio_priv(dev_info);
1970 1970
1971 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_INT_EN)); 1971 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_INT_EN));
@@ -1976,7 +1976,7 @@ static ssize_t adt7316_set_int_enabled(struct device *dev,
1976 const char *buf, 1976 const char *buf,
1977 size_t len) 1977 size_t len)
1978{ 1978{
1979 struct iio_dev *dev_info = dev_get_drvdata(dev); 1979 struct iio_dev *dev_info = dev_to_iio_dev(dev);
1980 struct adt7316_chip_info *chip = iio_priv(dev_info); 1980 struct adt7316_chip_info *chip = iio_priv(dev_info);
1981 u8 config1; 1981 u8 config1;
1982 int ret; 1982 int ret;
@@ -2133,7 +2133,7 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
2133 unsigned short *adt7316_platform_data = dev->platform_data; 2133 unsigned short *adt7316_platform_data = dev->platform_data;
2134 int ret = 0; 2134 int ret = 0;
2135 2135
2136 indio_dev = iio_allocate_device(sizeof(*chip)); 2136 indio_dev = iio_device_alloc(sizeof(*chip));
2137 if (indio_dev == NULL) { 2137 if (indio_dev == NULL) {
2138 ret = -ENOMEM; 2138 ret = -ENOMEM;
2139 goto error_ret; 2139 goto error_ret;
@@ -2210,7 +2210,7 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
2210error_unreg_irq: 2210error_unreg_irq:
2211 free_irq(chip->bus.irq, indio_dev); 2211 free_irq(chip->bus.irq, indio_dev);
2212error_free_dev: 2212error_free_dev:
2213 iio_free_device(indio_dev); 2213 iio_device_free(indio_dev);
2214error_ret: 2214error_ret:
2215 return ret; 2215 return ret;
2216} 2216}
@@ -2224,7 +2224,7 @@ int __devexit adt7316_remove(struct device *dev)
2224 iio_device_unregister(indio_dev); 2224 iio_device_unregister(indio_dev);
2225 if (chip->bus.irq) 2225 if (chip->bus.irq)
2226 free_irq(chip->bus.irq, indio_dev); 2226 free_irq(chip->bus.irq, indio_dev);
2227 iio_free_device(indio_dev); 2227 iio_device_free(indio_dev);
2228 2228
2229 return 0; 2229 return 0;
2230} 2230}
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index e4a08dc9b6f5..a16d1a22db0a 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -13,9 +13,9 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/module.h> 14#include <linux/module.h>
15 15
16#include "../iio.h" 16#include <linux/iio/iio.h>
17#include "../sysfs.h" 17#include <linux/iio/sysfs.h>
18#include "../events.h" 18#include <linux/iio/events.h>
19/* 19/*
20 * AD7150 registers definition 20 * AD7150 registers definition
21 */ 21 */
@@ -104,7 +104,7 @@ static int ad7150_read_raw(struct iio_dev *indio_dev,
104 struct ad7150_chip_info *chip = iio_priv(indio_dev); 104 struct ad7150_chip_info *chip = iio_priv(indio_dev);
105 105
106 switch (mask) { 106 switch (mask) {
107 case 0: 107 case IIO_CHAN_INFO_RAW:
108 ret = i2c_smbus_read_word_data(chip->client, 108 ret = i2c_smbus_read_word_data(chip->client,
109 ad7150_addresses[chan->channel][0]); 109 ad7150_addresses[chan->channel][0]);
110 if (ret < 0) 110 if (ret < 0)
@@ -341,7 +341,7 @@ static ssize_t ad7150_show_timeout(struct device *dev,
341 struct device_attribute *attr, 341 struct device_attribute *attr,
342 char *buf) 342 char *buf)
343{ 343{
344 struct iio_dev *indio_dev = dev_get_drvdata(dev); 344 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
345 struct ad7150_chip_info *chip = iio_priv(indio_dev); 345 struct ad7150_chip_info *chip = iio_priv(indio_dev);
346 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 346 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
347 u8 value; 347 u8 value;
@@ -370,7 +370,7 @@ static ssize_t ad7150_store_timeout(struct device *dev,
370 const char *buf, 370 const char *buf,
371 size_t len) 371 size_t len)
372{ 372{
373 struct iio_dev *indio_dev = dev_get_drvdata(dev); 373 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
374 struct ad7150_chip_info *chip = iio_priv(indio_dev); 374 struct ad7150_chip_info *chip = iio_priv(indio_dev);
375 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 375 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
376 int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); 376 int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
@@ -429,7 +429,8 @@ static const struct iio_chan_spec ad7150_channels[] = {
429 .type = IIO_CAPACITANCE, 429 .type = IIO_CAPACITANCE,
430 .indexed = 1, 430 .indexed = 1,
431 .channel = 0, 431 .channel = 0,
432 .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT, 432 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
433 IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT,
433 .event_mask = 434 .event_mask =
434 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | 435 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
435 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) | 436 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
@@ -441,7 +442,8 @@ static const struct iio_chan_spec ad7150_channels[] = {
441 .type = IIO_CAPACITANCE, 442 .type = IIO_CAPACITANCE,
442 .indexed = 1, 443 .indexed = 1,
443 .channel = 1, 444 .channel = 1,
444 .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT, 445 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
446 IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT,
445 .event_mask = 447 .event_mask =
446 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | 448 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
447 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) | 449 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
@@ -556,7 +558,7 @@ static int __devinit ad7150_probe(struct i2c_client *client,
556 struct ad7150_chip_info *chip; 558 struct ad7150_chip_info *chip;
557 struct iio_dev *indio_dev; 559 struct iio_dev *indio_dev;
558 560
559 indio_dev = iio_allocate_device(sizeof(*chip)); 561 indio_dev = iio_device_alloc(sizeof(*chip));
560 if (indio_dev == NULL) { 562 if (indio_dev == NULL) {
561 ret = -ENOMEM; 563 ret = -ENOMEM;
562 goto error_ret; 564 goto error_ret;
@@ -619,7 +621,7 @@ error_free_irq:
619 if (client->irq) 621 if (client->irq)
620 free_irq(client->irq, indio_dev); 622 free_irq(client->irq, indio_dev);
621error_free_dev: 623error_free_dev:
622 iio_free_device(indio_dev); 624 iio_device_free(indio_dev);
623error_ret: 625error_ret:
624 return ret; 626 return ret;
625} 627}
@@ -635,7 +637,7 @@ static int __devexit ad7150_remove(struct i2c_client *client)
635 if (client->dev.platform_data) 637 if (client->dev.platform_data)
636 free_irq(*(unsigned int *)client->dev.platform_data, indio_dev); 638 free_irq(*(unsigned int *)client->dev.platform_data, indio_dev);
637 639
638 iio_free_device(indio_dev); 640 iio_device_free(indio_dev);
639 641
640 return 0; 642 return 0;
641} 643}
diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
index fdb83c35e6dd..98c3015116aa 100644
--- a/drivers/staging/iio/cdc/ad7152.c
+++ b/drivers/staging/iio/cdc/ad7152.c
@@ -15,8 +15,8 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20 20
21/* 21/*
22 * TODO: Check compliance of calibbias with abi (units) 22 * TODO: Check compliance of calibbias with abi (units)
@@ -97,7 +97,7 @@ static inline ssize_t ad7152_start_calib(struct device *dev,
97 size_t len, 97 size_t len,
98 u8 regval) 98 u8 regval)
99{ 99{
100 struct iio_dev *indio_dev = dev_get_drvdata(dev); 100 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
101 struct ad7152_chip_info *chip = iio_priv(indio_dev); 101 struct ad7152_chip_info *chip = iio_priv(indio_dev);
102 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 102 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
103 bool doit; 103 bool doit;
@@ -169,7 +169,7 @@ static ssize_t ad7152_show_filter_rate_setup(struct device *dev,
169 struct device_attribute *attr, 169 struct device_attribute *attr,
170 char *buf) 170 char *buf)
171{ 171{
172 struct iio_dev *indio_dev = dev_get_drvdata(dev); 172 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
173 struct ad7152_chip_info *chip = iio_priv(indio_dev); 173 struct ad7152_chip_info *chip = iio_priv(indio_dev);
174 174
175 return sprintf(buf, "%d\n", 175 return sprintf(buf, "%d\n",
@@ -181,7 +181,7 @@ static ssize_t ad7152_store_filter_rate_setup(struct device *dev,
181 const char *buf, 181 const char *buf,
182 size_t len) 182 size_t len)
183{ 183{
184 struct iio_dev *indio_dev = dev_get_drvdata(dev); 184 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
185 struct ad7152_chip_info *chip = iio_priv(indio_dev); 185 struct ad7152_chip_info *chip = iio_priv(indio_dev);
186 u8 data; 186 u8 data;
187 int ret, i; 187 int ret, i;
@@ -329,7 +329,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev,
329 mutex_lock(&indio_dev->mlock); 329 mutex_lock(&indio_dev->mlock);
330 330
331 switch (mask) { 331 switch (mask) {
332 case 0: 332 case IIO_CHAN_INFO_RAW:
333 /* First set whether in differential mode */ 333 /* First set whether in differential mode */
334 334
335 regval = chip->setup[chan->channel]; 335 regval = chip->setup[chan->channel];
@@ -436,7 +436,8 @@ static const struct iio_chan_spec ad7152_channels[] = {
436 .type = IIO_CAPACITANCE, 436 .type = IIO_CAPACITANCE,
437 .indexed = 1, 437 .indexed = 1,
438 .channel = 0, 438 .channel = 0,
439 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 439 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
440 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
440 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 441 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
441 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 442 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
442 }, { 443 }, {
@@ -445,14 +446,16 @@ static const struct iio_chan_spec ad7152_channels[] = {
445 .indexed = 1, 446 .indexed = 1,
446 .channel = 0, 447 .channel = 0,
447 .channel2 = 2, 448 .channel2 = 2,
448 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 449 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
450 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
449 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 451 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
450 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 452 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
451 }, { 453 }, {
452 .type = IIO_CAPACITANCE, 454 .type = IIO_CAPACITANCE,
453 .indexed = 1, 455 .indexed = 1,
454 .channel = 1, 456 .channel = 1,
455 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 457 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
458 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
456 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 459 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
457 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 460 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
458 }, { 461 }, {
@@ -461,7 +464,8 @@ static const struct iio_chan_spec ad7152_channels[] = {
461 .indexed = 1, 464 .indexed = 1,
462 .channel = 1, 465 .channel = 1,
463 .channel2 = 3, 466 .channel2 = 3,
464 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 467 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
468 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
465 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 469 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
466 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 470 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
467 } 471 }
@@ -477,7 +481,7 @@ static int __devinit ad7152_probe(struct i2c_client *client,
477 struct ad7152_chip_info *chip; 481 struct ad7152_chip_info *chip;
478 struct iio_dev *indio_dev; 482 struct iio_dev *indio_dev;
479 483
480 indio_dev = iio_allocate_device(sizeof(*chip)); 484 indio_dev = iio_device_alloc(sizeof(*chip));
481 if (indio_dev == NULL) { 485 if (indio_dev == NULL) {
482 ret = -ENOMEM; 486 ret = -ENOMEM;
483 goto error_ret; 487 goto error_ret;
@@ -509,7 +513,7 @@ static int __devinit ad7152_probe(struct i2c_client *client,
509 return 0; 513 return 0;
510 514
511error_free_dev: 515error_free_dev:
512 iio_free_device(indio_dev); 516 iio_device_free(indio_dev);
513error_ret: 517error_ret:
514 return ret; 518 return ret;
515} 519}
@@ -519,7 +523,7 @@ static int __devexit ad7152_remove(struct i2c_client *client)
519 struct iio_dev *indio_dev = i2c_get_clientdata(client); 523 struct iio_dev *indio_dev = i2c_get_clientdata(client);
520 524
521 iio_device_unregister(indio_dev); 525 iio_device_unregister(indio_dev);
522 iio_free_device(indio_dev); 526 iio_device_free(indio_dev);
523 527
524 return 0; 528 return 0;
525} 529}
diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index 40b8512cbc32..754e11e87193 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/stat.h> 17#include <linux/stat.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#include "ad7746.h" 22#include "ad7746.h"
23 23
@@ -123,7 +123,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
123 .type = IIO_VOLTAGE, 123 .type = IIO_VOLTAGE,
124 .indexed = 1, 124 .indexed = 1,
125 .channel = 0, 125 .channel = 0,
126 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 126 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
127 IIO_CHAN_INFO_SCALE_SHARED_BIT,
127 .address = AD7746_REG_VT_DATA_HIGH << 8 | 128 .address = AD7746_REG_VT_DATA_HIGH << 8 |
128 AD7746_VTSETUP_VTMD_EXT_VIN, 129 AD7746_VTSETUP_VTMD_EXT_VIN,
129 }, 130 },
@@ -132,7 +133,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
132 .indexed = 1, 133 .indexed = 1,
133 .channel = 1, 134 .channel = 1,
134 .extend_name = "supply", 135 .extend_name = "supply",
135 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 136 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
137 IIO_CHAN_INFO_SCALE_SHARED_BIT,
136 .address = AD7746_REG_VT_DATA_HIGH << 8 | 138 .address = AD7746_REG_VT_DATA_HIGH << 8 |
137 AD7746_VTSETUP_VTMD_VDD_MON, 139 AD7746_VTSETUP_VTMD_VDD_MON,
138 }, 140 },
@@ -140,7 +142,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
140 .type = IIO_TEMP, 142 .type = IIO_TEMP,
141 .indexed = 1, 143 .indexed = 1,
142 .channel = 0, 144 .channel = 0,
143 .processed_val = IIO_PROCESSED, 145 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
144 .address = AD7746_REG_VT_DATA_HIGH << 8 | 146 .address = AD7746_REG_VT_DATA_HIGH << 8 |
145 AD7746_VTSETUP_VTMD_INT_TEMP, 147 AD7746_VTSETUP_VTMD_INT_TEMP,
146 }, 148 },
@@ -148,7 +150,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
148 .type = IIO_TEMP, 150 .type = IIO_TEMP,
149 .indexed = 1, 151 .indexed = 1,
150 .channel = 1, 152 .channel = 1,
151 .processed_val = IIO_PROCESSED, 153 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
152 .address = AD7746_REG_VT_DATA_HIGH << 8 | 154 .address = AD7746_REG_VT_DATA_HIGH << 8 |
153 AD7746_VTSETUP_VTMD_EXT_TEMP, 155 AD7746_VTSETUP_VTMD_EXT_TEMP,
154 }, 156 },
@@ -156,7 +158,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
156 .type = IIO_CAPACITANCE, 158 .type = IIO_CAPACITANCE,
157 .indexed = 1, 159 .indexed = 1,
158 .channel = 0, 160 .channel = 0,
159 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 161 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
162 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
160 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT | 163 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
161 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 164 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
162 IIO_CHAN_INFO_SCALE_SHARED_BIT, 165 IIO_CHAN_INFO_SCALE_SHARED_BIT,
@@ -168,7 +171,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
168 .indexed = 1, 171 .indexed = 1,
169 .channel = 0, 172 .channel = 0,
170 .channel2 = 2, 173 .channel2 = 2,
171 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 174 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
175 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
172 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT | 176 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
173 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 177 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
174 IIO_CHAN_INFO_SCALE_SHARED_BIT, 178 IIO_CHAN_INFO_SCALE_SHARED_BIT,
@@ -179,7 +183,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
179 .type = IIO_CAPACITANCE, 183 .type = IIO_CAPACITANCE,
180 .indexed = 1, 184 .indexed = 1,
181 .channel = 1, 185 .channel = 1,
182 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 186 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
187 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
183 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT | 188 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
184 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 189 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
185 IIO_CHAN_INFO_SCALE_SHARED_BIT, 190 IIO_CHAN_INFO_SCALE_SHARED_BIT,
@@ -192,7 +197,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
192 .indexed = 1, 197 .indexed = 1,
193 .channel = 1, 198 .channel = 1,
194 .channel2 = 3, 199 .channel2 = 3,
195 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 200 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
201 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
196 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT | 202 IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
197 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 203 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
198 IIO_CHAN_INFO_SCALE_SHARED_BIT, 204 IIO_CHAN_INFO_SCALE_SHARED_BIT,
@@ -280,7 +286,7 @@ static inline ssize_t ad7746_start_calib(struct device *dev,
280 size_t len, 286 size_t len,
281 u8 regval) 287 u8 regval)
282{ 288{
283 struct iio_dev *indio_dev = dev_get_drvdata(dev); 289 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
284 struct ad7746_chip_info *chip = iio_priv(indio_dev); 290 struct ad7746_chip_info *chip = iio_priv(indio_dev);
285 bool doit; 291 bool doit;
286 int ret, timeout = 10; 292 int ret, timeout = 10;
@@ -319,7 +325,7 @@ static ssize_t ad7746_start_offset_calib(struct device *dev,
319 const char *buf, 325 const char *buf,
320 size_t len) 326 size_t len)
321{ 327{
322 struct iio_dev *indio_dev = dev_get_drvdata(dev); 328 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
323 int ret = ad7746_select_channel(indio_dev, 329 int ret = ad7746_select_channel(indio_dev,
324 &ad7746_channels[to_iio_dev_attr(attr)->address]); 330 &ad7746_channels[to_iio_dev_attr(attr)->address]);
325 if (ret < 0) 331 if (ret < 0)
@@ -334,7 +340,7 @@ static ssize_t ad7746_start_gain_calib(struct device *dev,
334 const char *buf, 340 const char *buf,
335 size_t len) 341 size_t len)
336{ 342{
337 struct iio_dev *indio_dev = dev_get_drvdata(dev); 343 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
338 int ret = ad7746_select_channel(indio_dev, 344 int ret = ad7746_select_channel(indio_dev,
339 &ad7746_channels[to_iio_dev_attr(attr)->address]); 345 &ad7746_channels[to_iio_dev_attr(attr)->address]);
340 if (ret < 0) 346 if (ret < 0)
@@ -359,7 +365,7 @@ static ssize_t ad7746_show_cap_filter_rate_setup(struct device *dev,
359 struct device_attribute *attr, 365 struct device_attribute *attr,
360 char *buf) 366 char *buf)
361{ 367{
362 struct iio_dev *indio_dev = dev_get_drvdata(dev); 368 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
363 struct ad7746_chip_info *chip = iio_priv(indio_dev); 369 struct ad7746_chip_info *chip = iio_priv(indio_dev);
364 370
365 return sprintf(buf, "%d\n", ad7746_cap_filter_rate_table[ 371 return sprintf(buf, "%d\n", ad7746_cap_filter_rate_table[
@@ -371,7 +377,7 @@ static ssize_t ad7746_store_cap_filter_rate_setup(struct device *dev,
371 const char *buf, 377 const char *buf,
372 size_t len) 378 size_t len)
373{ 379{
374 struct iio_dev *indio_dev = dev_get_drvdata(dev); 380 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
375 struct ad7746_chip_info *chip = iio_priv(indio_dev); 381 struct ad7746_chip_info *chip = iio_priv(indio_dev);
376 u8 data; 382 u8 data;
377 int ret, i; 383 int ret, i;
@@ -399,7 +405,7 @@ static ssize_t ad7746_show_vt_filter_rate_setup(struct device *dev,
399 struct device_attribute *attr, 405 struct device_attribute *attr,
400 char *buf) 406 char *buf)
401{ 407{
402 struct iio_dev *indio_dev = dev_get_drvdata(dev); 408 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
403 struct ad7746_chip_info *chip = iio_priv(indio_dev); 409 struct ad7746_chip_info *chip = iio_priv(indio_dev);
404 410
405 return sprintf(buf, "%d\n", ad7746_vt_filter_rate_table[ 411 return sprintf(buf, "%d\n", ad7746_vt_filter_rate_table[
@@ -411,7 +417,7 @@ static ssize_t ad7746_store_vt_filter_rate_setup(struct device *dev,
411 const char *buf, 417 const char *buf,
412 size_t len) 418 size_t len)
413{ 419{
414 struct iio_dev *indio_dev = dev_get_drvdata(dev); 420 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
415 struct ad7746_chip_info *chip = iio_priv(indio_dev); 421 struct ad7746_chip_info *chip = iio_priv(indio_dev);
416 u8 data; 422 u8 data;
417 int ret, i; 423 int ret, i;
@@ -572,7 +578,8 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
572 mutex_lock(&indio_dev->mlock); 578 mutex_lock(&indio_dev->mlock);
573 579
574 switch (mask) { 580 switch (mask) {
575 case 0: 581 case IIO_CHAN_INFO_RAW:
582 case IIO_CHAN_INFO_PROCESSED:
576 ret = ad7746_select_channel(indio_dev, chan); 583 ret = ad7746_select_channel(indio_dev, chan);
577 if (ret < 0) 584 if (ret < 0)
578 goto out; 585 goto out;
@@ -696,7 +703,7 @@ static int __devinit ad7746_probe(struct i2c_client *client,
696 int ret = 0; 703 int ret = 0;
697 unsigned char regval = 0; 704 unsigned char regval = 0;
698 705
699 indio_dev = iio_allocate_device(sizeof(*chip)); 706 indio_dev = iio_device_alloc(sizeof(*chip));
700 if (indio_dev == NULL) { 707 if (indio_dev == NULL) {
701 ret = -ENOMEM; 708 ret = -ENOMEM;
702 goto error_ret; 709 goto error_ret;
@@ -756,7 +763,7 @@ static int __devinit ad7746_probe(struct i2c_client *client,
756 return 0; 763 return 0;
757 764
758error_free_dev: 765error_free_dev:
759 iio_free_device(indio_dev); 766 iio_device_free(indio_dev);
760error_ret: 767error_ret:
761 return ret; 768 return ret;
762} 769}
@@ -766,7 +773,7 @@ static int __devexit ad7746_remove(struct i2c_client *client)
766 struct iio_dev *indio_dev = i2c_get_clientdata(client); 773 struct iio_dev *indio_dev = i2c_get_clientdata(client);
767 774
768 iio_device_unregister(indio_dev); 775 iio_device_unregister(indio_dev);
769 iio_free_device(indio_dev); 776 iio_device_free(indio_dev);
770 777
771 return 0; 778 return 0;
772} 779}
diff --git a/drivers/staging/iio/dac/Kconfig b/drivers/staging/iio/dac/Kconfig
index a57803a5d1a7..a626f03871ec 100644
--- a/drivers/staging/iio/dac/Kconfig
+++ b/drivers/staging/iio/dac/Kconfig
@@ -56,12 +56,12 @@ config AD5624R_SPI
56 AD5664R converters (DAC). This driver uses the common SPI interface. 56 AD5664R converters (DAC). This driver uses the common SPI interface.
57 57
58config AD5446 58config AD5446
59 tristate "Analog Devices AD5444/6, AD5620/40/60 and AD5542A/12A DAC SPI driver" 59 tristate "Analog Devices AD5446 and similar single channel DACs driver"
60 depends on SPI 60 depends on SPI
61 help 61 help
62 Say yes here to build support for Analog Devices AD5444, AD5446, 62 Say yes here to build support for Analog Devices AD5444, AD5446,
63 AD5512A, AD5542A, AD5543, AD5553, AD5601, AD5611, AD5620, AD5621, 63 AD5512A, AD5541A, AD5542A, AD5543, AD5553, AD5601, AD5611, AD5620,
64 AD5640, AD5660, AD5662 DACs. 64 AD5621, AD5640, AD5660, AD5662 DACs.
65 65
66 To compile this driver as a module, choose M here: the 66 To compile this driver as a module, choose M here: the
67 module will be called ad5446. 67 module will be called ad5446.
diff --git a/drivers/staging/iio/dac/ad5064.c b/drivers/staging/iio/dac/ad5064.c
index 06b162745a3e..047148aa66b2 100644
--- a/drivers/staging/iio/dac/ad5064.c
+++ b/drivers/staging/iio/dac/ad5064.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dac.h" 21#include "dac.h"
22 22
23#define AD5064_MAX_DAC_CHANNELS 8 23#define AD5064_MAX_DAC_CHANNELS 8
@@ -144,14 +144,14 @@ static const char ad5064_powerdown_modes[][15] = {
144}; 144};
145 145
146static ssize_t ad5064_read_powerdown_mode_available(struct iio_dev *indio_dev, 146static ssize_t ad5064_read_powerdown_mode_available(struct iio_dev *indio_dev,
147 const struct iio_chan_spec *chan, char *buf) 147 uintptr_t private, const struct iio_chan_spec *chan, char *buf)
148{ 148{
149 return sprintf(buf, "%s %s %s\n", ad5064_powerdown_modes[1], 149 return sprintf(buf, "%s %s %s\n", ad5064_powerdown_modes[1],
150 ad5064_powerdown_modes[2], ad5064_powerdown_modes[3]); 150 ad5064_powerdown_modes[2], ad5064_powerdown_modes[3]);
151} 151}
152 152
153static ssize_t ad5064_read_powerdown_mode(struct iio_dev *indio_dev, 153static ssize_t ad5064_read_powerdown_mode(struct iio_dev *indio_dev,
154 const struct iio_chan_spec *chan, char *buf) 154 uintptr_t private, const struct iio_chan_spec *chan, char *buf)
155{ 155{
156 struct ad5064_state *st = iio_priv(indio_dev); 156 struct ad5064_state *st = iio_priv(indio_dev);
157 157
@@ -160,7 +160,8 @@ static ssize_t ad5064_read_powerdown_mode(struct iio_dev *indio_dev,
160} 160}
161 161
162static ssize_t ad5064_write_powerdown_mode(struct iio_dev *indio_dev, 162static ssize_t ad5064_write_powerdown_mode(struct iio_dev *indio_dev,
163 const struct iio_chan_spec *chan, const char *buf, size_t len) 163 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
164 size_t len)
164{ 165{
165 struct ad5064_state *st = iio_priv(indio_dev); 166 struct ad5064_state *st = iio_priv(indio_dev);
166 unsigned int mode, i; 167 unsigned int mode, i;
@@ -187,7 +188,7 @@ static ssize_t ad5064_write_powerdown_mode(struct iio_dev *indio_dev,
187} 188}
188 189
189static ssize_t ad5064_read_dac_powerdown(struct iio_dev *indio_dev, 190static ssize_t ad5064_read_dac_powerdown(struct iio_dev *indio_dev,
190 const struct iio_chan_spec *chan, char *buf) 191 uintptr_t private, const struct iio_chan_spec *chan, char *buf)
191{ 192{
192 struct ad5064_state *st = iio_priv(indio_dev); 193 struct ad5064_state *st = iio_priv(indio_dev);
193 194
@@ -195,7 +196,8 @@ static ssize_t ad5064_read_dac_powerdown(struct iio_dev *indio_dev,
195} 196}
196 197
197static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev, 198static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev,
198 const struct iio_chan_spec *chan, const char *buf, size_t len) 199 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
200 size_t len)
199{ 201{
200 struct ad5064_state *st = iio_priv(indio_dev); 202 struct ad5064_state *st = iio_priv(indio_dev);
201 bool pwr_down; 203 bool pwr_down;
@@ -235,7 +237,7 @@ static int ad5064_read_raw(struct iio_dev *indio_dev,
235 int scale_uv; 237 int scale_uv;
236 238
237 switch (m) { 239 switch (m) {
238 case 0: 240 case IIO_CHAN_INFO_RAW:
239 *val = st->dac_cache[chan->channel]; 241 *val = st->dac_cache[chan->channel];
240 return IIO_VAL_INT; 242 return IIO_VAL_INT;
241 case IIO_CHAN_INFO_SCALE: 243 case IIO_CHAN_INFO_SCALE:
@@ -260,7 +262,7 @@ static int ad5064_write_raw(struct iio_dev *indio_dev,
260 int ret; 262 int ret;
261 263
262 switch (mask) { 264 switch (mask) {
263 case 0: 265 case IIO_CHAN_INFO_RAW:
264 if (val > (1 << chan->scan_type.realbits) || val < 0) 266 if (val > (1 << chan->scan_type.realbits) || val < 0)
265 return -EINVAL; 267 return -EINVAL;
266 268
@@ -308,7 +310,8 @@ static struct iio_chan_spec_ext_info ad5064_ext_info[] = {
308 .indexed = 1, \ 310 .indexed = 1, \
309 .output = 1, \ 311 .output = 1, \
310 .channel = (chan), \ 312 .channel = (chan), \
311 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 313 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
314 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
312 .address = AD5064_ADDR_DAC(chan), \ 315 .address = AD5064_ADDR_DAC(chan), \
313 .scan_type = IIO_ST('u', (bits), 16, 20 - (bits)), \ 316 .scan_type = IIO_ST('u', (bits), 16, 20 - (bits)), \
314 .ext_info = ad5064_ext_info, \ 317 .ext_info = ad5064_ext_info, \
@@ -442,7 +445,7 @@ static int __devinit ad5064_probe(struct spi_device *spi)
442 unsigned int i; 445 unsigned int i;
443 int ret; 446 int ret;
444 447
445 indio_dev = iio_allocate_device(sizeof(*st)); 448 indio_dev = iio_device_alloc(sizeof(*st));
446 if (indio_dev == NULL) 449 if (indio_dev == NULL)
447 return -ENOMEM; 450 return -ENOMEM;
448 451
@@ -499,7 +502,7 @@ error_free_reg:
499 if (!st->use_internal_vref) 502 if (!st->use_internal_vref)
500 regulator_bulk_free(ad5064_num_vref(st), st->vref_reg); 503 regulator_bulk_free(ad5064_num_vref(st), st->vref_reg);
501error_free: 504error_free:
502 iio_free_device(indio_dev); 505 iio_device_free(indio_dev);
503 506
504 return ret; 507 return ret;
505} 508}
@@ -517,7 +520,7 @@ static int __devexit ad5064_remove(struct spi_device *spi)
517 regulator_bulk_free(ad5064_num_vref(st), st->vref_reg); 520 regulator_bulk_free(ad5064_num_vref(st), st->vref_reg);
518 } 521 }
519 522
520 iio_free_device(indio_dev); 523 iio_device_free(indio_dev);
521 524
522 return 0; 525 return 0;
523} 526}
diff --git a/drivers/staging/iio/dac/ad5360.c b/drivers/staging/iio/dac/ad5360.c
index cec3693b50a3..38660efca78a 100644
--- a/drivers/staging/iio/dac/ad5360.c
+++ b/drivers/staging/iio/dac/ad5360.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dac.h" 21#include "dac.h"
22 22
23#define AD5360_CMD(x) ((x) << 22) 23#define AD5360_CMD(x) ((x) << 22)
@@ -103,7 +103,8 @@ enum ad5360_type {
103 .type = IIO_VOLTAGE, \ 103 .type = IIO_VOLTAGE, \
104 .indexed = 1, \ 104 .indexed = 1, \
105 .output = 1, \ 105 .output = 1, \
106 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ 106 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
107 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
107 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ 108 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
108 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ 109 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
109 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ 110 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \
@@ -250,7 +251,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
250 struct device_attribute *attr, 251 struct device_attribute *attr,
251 char *buf) 252 char *buf)
252{ 253{
253 struct iio_dev *indio_dev = dev_get_drvdata(dev); 254 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
254 struct ad5360_state *st = iio_priv(indio_dev); 255 struct ad5360_state *st = iio_priv(indio_dev);
255 256
256 return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN)); 257 return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
@@ -278,7 +279,7 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set,
278static ssize_t ad5360_write_dac_powerdown(struct device *dev, 279static ssize_t ad5360_write_dac_powerdown(struct device *dev,
279 struct device_attribute *attr, const char *buf, size_t len) 280 struct device_attribute *attr, const char *buf, size_t len)
280{ 281{
281 struct iio_dev *indio_dev = dev_get_drvdata(dev); 282 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
282 bool pwr_down; 283 bool pwr_down;
283 int ret; 284 int ret;
284 285
@@ -319,7 +320,7 @@ static int ad5360_write_raw(struct iio_dev *indio_dev,
319 unsigned int ofs_index; 320 unsigned int ofs_index;
320 321
321 switch (mask) { 322 switch (mask) {
322 case 0: 323 case IIO_CHAN_INFO_RAW:
323 if (val >= max_val || val < 0) 324 if (val >= max_val || val < 0)
324 return -EINVAL; 325 return -EINVAL;
325 326
@@ -376,7 +377,7 @@ static int ad5360_read_raw(struct iio_dev *indio_dev,
376 int ret; 377 int ret;
377 378
378 switch (m) { 379 switch (m) {
379 case 0: 380 case IIO_CHAN_INFO_RAW:
380 ret = ad5360_read(indio_dev, AD5360_READBACK_X1A, 381 ret = ad5360_read(indio_dev, AD5360_READBACK_X1A,
381 chan->address); 382 chan->address);
382 if (ret < 0) 383 if (ret < 0)
@@ -464,7 +465,7 @@ static int __devinit ad5360_probe(struct spi_device *spi)
464 unsigned int i; 465 unsigned int i;
465 int ret; 466 int ret;
466 467
467 indio_dev = iio_allocate_device(sizeof(*st)); 468 indio_dev = iio_device_alloc(sizeof(*st));
468 if (indio_dev == NULL) { 469 if (indio_dev == NULL) {
469 dev_err(&spi->dev, "Failed to allocate iio device\n"); 470 dev_err(&spi->dev, "Failed to allocate iio device\n");
470 return -ENOMEM; 471 return -ENOMEM;
@@ -519,7 +520,7 @@ error_free_reg:
519error_free_channels: 520error_free_channels:
520 kfree(indio_dev->channels); 521 kfree(indio_dev->channels);
521error_free: 522error_free:
522 iio_free_device(indio_dev); 523 iio_device_free(indio_dev);
523 524
524 return ret; 525 return ret;
525} 526}
@@ -536,7 +537,7 @@ static int __devexit ad5360_remove(struct spi_device *spi)
536 regulator_bulk_disable(st->chip_info->num_vrefs, st->vref_reg); 537 regulator_bulk_disable(st->chip_info->num_vrefs, st->vref_reg);
537 regulator_bulk_free(st->chip_info->num_vrefs, st->vref_reg); 538 regulator_bulk_free(st->chip_info->num_vrefs, st->vref_reg);
538 539
539 iio_free_device(indio_dev); 540 iio_device_free(indio_dev);
540 541
541 return 0; 542 return 0;
542} 543}
diff --git a/drivers/staging/iio/dac/ad5380.c b/drivers/staging/iio/dac/ad5380.c
index 4c50716fa801..370d2842190e 100644
--- a/drivers/staging/iio/dac/ad5380.c
+++ b/drivers/staging/iio/dac/ad5380.c
@@ -18,8 +18,8 @@
18#include <linux/regmap.h> 18#include <linux/regmap.h>
19#include <linux/regulator/consumer.h> 19#include <linux/regulator/consumer.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "dac.h" 23#include "dac.h"
24 24
25 25
@@ -85,7 +85,8 @@ enum ad5380_type {
85 .type = IIO_VOLTAGE, \ 85 .type = IIO_VOLTAGE, \
86 .indexed = 1, \ 86 .indexed = 1, \
87 .output = 1, \ 87 .output = 1, \
88 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | \ 88 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
89 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
89 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ 90 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
90 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ 91 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \
91 .scan_type = IIO_ST('u', (_bits), 16, 14 - (_bits)) \ 92 .scan_type = IIO_ST('u', (_bits), 16, 14 - (_bits)) \
@@ -167,7 +168,7 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = {
167static ssize_t ad5380_read_dac_powerdown(struct device *dev, 168static ssize_t ad5380_read_dac_powerdown(struct device *dev,
168 struct device_attribute *attr, char *buf) 169 struct device_attribute *attr, char *buf)
169{ 170{
170 struct iio_dev *indio_dev = dev_get_drvdata(dev); 171 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
171 struct ad5380_state *st = iio_priv(indio_dev); 172 struct ad5380_state *st = iio_priv(indio_dev);
172 173
173 return sprintf(buf, "%d\n", st->pwr_down); 174 return sprintf(buf, "%d\n", st->pwr_down);
@@ -176,7 +177,7 @@ static ssize_t ad5380_read_dac_powerdown(struct device *dev,
176static ssize_t ad5380_write_dac_powerdown(struct device *dev, 177static ssize_t ad5380_write_dac_powerdown(struct device *dev,
177 struct device_attribute *attr, const char *buf, size_t len) 178 struct device_attribute *attr, const char *buf, size_t len)
178{ 179{
179 struct iio_dev *indio_dev = dev_get_drvdata(dev); 180 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
180 struct ad5380_state *st = iio_priv(indio_dev); 181 struct ad5380_state *st = iio_priv(indio_dev);
181 bool pwr_down; 182 bool pwr_down;
182 int ret; 183 int ret;
@@ -212,7 +213,7 @@ static const char ad5380_powerdown_modes[][15] = {
212static ssize_t ad5380_read_powerdown_mode(struct device *dev, 213static ssize_t ad5380_read_powerdown_mode(struct device *dev,
213 struct device_attribute *attr, char *buf) 214 struct device_attribute *attr, char *buf)
214{ 215{
215 struct iio_dev *indio_dev = dev_get_drvdata(dev); 216 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
216 struct ad5380_state *st = iio_priv(indio_dev); 217 struct ad5380_state *st = iio_priv(indio_dev);
217 unsigned int mode; 218 unsigned int mode;
218 int ret; 219 int ret;
@@ -229,7 +230,7 @@ static ssize_t ad5380_read_powerdown_mode(struct device *dev,
229static ssize_t ad5380_write_powerdown_mode(struct device *dev, 230static ssize_t ad5380_write_powerdown_mode(struct device *dev,
230 struct device_attribute *attr, const char *buf, size_t len) 231 struct device_attribute *attr, const char *buf, size_t len)
231{ 232{
232 struct iio_dev *indio_dev = dev_get_drvdata(dev); 233 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
233 struct ad5380_state *st = iio_priv(indio_dev); 234 struct ad5380_state *st = iio_priv(indio_dev);
234 unsigned int i; 235 unsigned int i;
235 int ret; 236 int ret;
@@ -292,7 +293,7 @@ static int ad5380_write_raw(struct iio_dev *indio_dev,
292 struct ad5380_state *st = iio_priv(indio_dev); 293 struct ad5380_state *st = iio_priv(indio_dev);
293 294
294 switch (info) { 295 switch (info) {
295 case 0: 296 case IIO_CHAN_INFO_RAW:
296 case IIO_CHAN_INFO_CALIBSCALE: 297 case IIO_CHAN_INFO_CALIBSCALE:
297 if (val >= max_val || val < 0) 298 if (val >= max_val || val < 0)
298 return -EINVAL; 299 return -EINVAL;
@@ -322,7 +323,7 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
322 int ret; 323 int ret;
323 324
324 switch (info) { 325 switch (info) {
325 case 0: 326 case IIO_CHAN_INFO_RAW:
326 case IIO_CHAN_INFO_CALIBSCALE: 327 case IIO_CHAN_INFO_CALIBSCALE:
327 ret = regmap_read(st->regmap, ad5380_info_to_reg(chan, info), 328 ret = regmap_read(st->regmap, ad5380_info_to_reg(chan, info),
328 val); 329 val);
@@ -388,7 +389,7 @@ static int __devinit ad5380_probe(struct device *dev, struct regmap *regmap,
388 unsigned int ctrl = 0; 389 unsigned int ctrl = 0;
389 int ret; 390 int ret;
390 391
391 indio_dev = iio_allocate_device(sizeof(*st)); 392 indio_dev = iio_device_alloc(sizeof(*st));
392 if (indio_dev == NULL) { 393 if (indio_dev == NULL) {
393 dev_err(dev, "Failed to allocate iio device\n"); 394 dev_err(dev, "Failed to allocate iio device\n");
394 ret = -ENOMEM; 395 ret = -ENOMEM;
@@ -454,7 +455,7 @@ error_free_reg:
454 455
455 kfree(indio_dev->channels); 456 kfree(indio_dev->channels);
456error_free: 457error_free:
457 iio_free_device(indio_dev); 458 iio_device_free(indio_dev);
458error_regmap_exit: 459error_regmap_exit:
459 regmap_exit(regmap); 460 regmap_exit(regmap);
460 461
@@ -476,7 +477,7 @@ static int __devexit ad5380_remove(struct device *dev)
476 } 477 }
477 478
478 regmap_exit(st->regmap); 479 regmap_exit(st->regmap);
479 iio_free_device(indio_dev); 480 iio_device_free(indio_dev);
480 481
481 return 0; 482 return 0;
482} 483}
diff --git a/drivers/staging/iio/dac/ad5421.c b/drivers/staging/iio/dac/ad5421.c
index 0b040b204697..ffbd4c234f57 100644
--- a/drivers/staging/iio/dac/ad5421.c
+++ b/drivers/staging/iio/dac/ad5421.c
@@ -16,9 +16,9 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/sysfs.h> 17#include <linux/sysfs.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../events.h" 21#include <linux/iio/events.h>
22#include "dac.h" 22#include "dac.h"
23#include "ad5421.h" 23#include "ad5421.h"
24 24
@@ -87,7 +87,8 @@ static const struct iio_chan_spec ad5421_channels[] = {
87 .indexed = 1, 87 .indexed = 1,
88 .output = 1, 88 .output = 1,
89 .channel = 0, 89 .channel = 0,
90 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | 90 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
91 IIO_CHAN_INFO_SCALE_SHARED_BIT |
91 IIO_CHAN_INFO_OFFSET_SHARED_BIT | 92 IIO_CHAN_INFO_OFFSET_SHARED_BIT |
92 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | 93 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
93 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 94 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
@@ -304,7 +305,7 @@ static int ad5421_read_raw(struct iio_dev *indio_dev,
304 return -EINVAL; 305 return -EINVAL;
305 306
306 switch (m) { 307 switch (m) {
307 case 0: 308 case IIO_CHAN_INFO_RAW:
308 ret = ad5421_read(indio_dev, AD5421_REG_DAC_DATA); 309 ret = ad5421_read(indio_dev, AD5421_REG_DAC_DATA);
309 if (ret < 0) 310 if (ret < 0)
310 return ret; 311 return ret;
@@ -340,7 +341,7 @@ static int ad5421_write_raw(struct iio_dev *indio_dev,
340 const unsigned int max_val = 1 << 16; 341 const unsigned int max_val = 1 << 16;
341 342
342 switch (mask) { 343 switch (mask) {
343 case 0: 344 case IIO_CHAN_INFO_RAW:
344 if (val >= max_val || val < 0) 345 if (val >= max_val || val < 0)
345 return -EINVAL; 346 return -EINVAL;
346 347
@@ -456,7 +457,7 @@ static int __devinit ad5421_probe(struct spi_device *spi)
456 struct ad5421_state *st; 457 struct ad5421_state *st;
457 int ret; 458 int ret;
458 459
459 indio_dev = iio_allocate_device(sizeof(*st)); 460 indio_dev = iio_device_alloc(sizeof(*st));
460 if (indio_dev == NULL) { 461 if (indio_dev == NULL) {
461 dev_err(&spi->dev, "Failed to allocate iio device\n"); 462 dev_err(&spi->dev, "Failed to allocate iio device\n");
462 return -ENOMEM; 463 return -ENOMEM;
@@ -511,7 +512,7 @@ error_free_irq:
511 if (spi->irq) 512 if (spi->irq)
512 free_irq(spi->irq, indio_dev); 513 free_irq(spi->irq, indio_dev);
513error_free: 514error_free:
514 iio_free_device(indio_dev); 515 iio_device_free(indio_dev);
515 516
516 return ret; 517 return ret;
517} 518}
@@ -523,7 +524,7 @@ static int __devexit ad5421_remove(struct spi_device *spi)
523 iio_device_unregister(indio_dev); 524 iio_device_unregister(indio_dev);
524 if (spi->irq) 525 if (spi->irq)
525 free_irq(spi->irq, indio_dev); 526 free_irq(spi->irq, indio_dev);
526 iio_free_device(indio_dev); 527 iio_device_free(indio_dev);
527 528
528 return 0; 529 return 0;
529} 530}
diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
index 633ffbb21814..daa65b384c13 100644
--- a/drivers/staging/iio/dac/ad5446.c
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -18,229 +18,212 @@
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "dac.h" 23#include "dac.h"
24 24
25#include "ad5446.h" 25#include "ad5446.h"
26 26
27static void ad5446_store_sample(struct ad5446_state *st, unsigned val) 27static int ad5446_write(struct ad5446_state *st, unsigned val)
28{ 28{
29 st->data.d16 = cpu_to_be16(AD5446_LOAD | val); 29 __be16 data = cpu_to_be16(val);
30 return spi_write(st->spi, &data, sizeof(data));
30} 31}
31 32
32static void ad5542_store_sample(struct ad5446_state *st, unsigned val) 33static int ad5660_write(struct ad5446_state *st, unsigned val)
33{ 34{
34 st->data.d16 = cpu_to_be16(val); 35 uint8_t data[3];
35}
36 36
37static void ad5620_store_sample(struct ad5446_state *st, unsigned val) 37 data[0] = (val >> 16) & 0xFF;
38{ 38 data[1] = (val >> 8) & 0xFF;
39 st->data.d16 = cpu_to_be16(AD5620_LOAD | val); 39 data[2] = val & 0xFF;
40}
41 40
42static void ad5660_store_sample(struct ad5446_state *st, unsigned val) 41 return spi_write(st->spi, data, sizeof(data));
43{
44 val |= AD5660_LOAD;
45 st->data.d24[0] = (val >> 16) & 0xFF;
46 st->data.d24[1] = (val >> 8) & 0xFF;
47 st->data.d24[2] = val & 0xFF;
48} 42}
49 43
50static void ad5620_store_pwr_down(struct ad5446_state *st, unsigned mode) 44static const char * const ad5446_powerdown_modes[] = {
51{ 45 "", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"
52 st->data.d16 = cpu_to_be16(mode << 14); 46};
53}
54 47
55static void ad5660_store_pwr_down(struct ad5446_state *st, unsigned mode) 48static ssize_t ad5446_read_powerdown_mode_available(struct iio_dev *indio_dev,
49 uintptr_t private, const struct iio_chan_spec *chan, char *buf)
56{ 50{
57 unsigned val = mode << 16; 51 return sprintf(buf, "%s %s %s\n", ad5446_powerdown_modes[1],
58 52 ad5446_powerdown_modes[2], ad5446_powerdown_modes[3]);
59 st->data.d24[0] = (val >> 16) & 0xFF;
60 st->data.d24[1] = (val >> 8) & 0xFF;
61 st->data.d24[2] = val & 0xFF;
62} 53}
63 54
64static ssize_t ad5446_write_powerdown_mode(struct device *dev, 55static ssize_t ad5446_write_powerdown_mode(struct iio_dev *indio_dev,
65 struct device_attribute *attr, 56 uintptr_t private,
66 const char *buf, size_t len) 57 const struct iio_chan_spec *chan,
58 const char *buf, size_t len)
67{ 59{
68 struct iio_dev *indio_dev = dev_get_drvdata(dev);
69 struct ad5446_state *st = iio_priv(indio_dev); 60 struct ad5446_state *st = iio_priv(indio_dev);
61 int i;
70 62
71 if (sysfs_streq(buf, "1kohm_to_gnd")) 63 for (i = 1; i < ARRAY_SIZE(ad5446_powerdown_modes); i++) {
72 st->pwr_down_mode = MODE_PWRDWN_1k; 64 if (sysfs_streq(buf, ad5446_powerdown_modes[i])) {
73 else if (sysfs_streq(buf, "100kohm_to_gnd")) 65 st->pwr_down_mode = i;
74 st->pwr_down_mode = MODE_PWRDWN_100k; 66 break;
75 else if (sysfs_streq(buf, "three_state")) 67 }
76 st->pwr_down_mode = MODE_PWRDWN_TRISTATE; 68 }
77 else 69
70 if (i == ARRAY_SIZE(ad5446_powerdown_modes))
78 return -EINVAL; 71 return -EINVAL;
79 72
80 return len; 73 return len;
81} 74}
82 75
83static ssize_t ad5446_read_powerdown_mode(struct device *dev, 76static ssize_t ad5446_read_powerdown_mode(struct iio_dev *indio_dev,
84 struct device_attribute *attr, char *buf) 77 uintptr_t private,
78 const struct iio_chan_spec *chan,
79 char *buf)
85{ 80{
86 struct iio_dev *indio_dev = dev_get_drvdata(dev);
87 struct ad5446_state *st = iio_priv(indio_dev); 81 struct ad5446_state *st = iio_priv(indio_dev);
88 82
89 char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"}; 83 return sprintf(buf, "%s\n", ad5446_powerdown_modes[st->pwr_down_mode]);
90
91 return sprintf(buf, "%s\n", mode[st->pwr_down_mode]);
92} 84}
93 85
94static ssize_t ad5446_read_dac_powerdown(struct device *dev, 86static ssize_t ad5446_read_dac_powerdown(struct iio_dev *indio_dev,
95 struct device_attribute *attr, 87 uintptr_t private,
88 const struct iio_chan_spec *chan,
96 char *buf) 89 char *buf)
97{ 90{
98 struct iio_dev *indio_dev = dev_get_drvdata(dev);
99 struct ad5446_state *st = iio_priv(indio_dev); 91 struct ad5446_state *st = iio_priv(indio_dev);
100 92
101 return sprintf(buf, "%d\n", st->pwr_down); 93 return sprintf(buf, "%d\n", st->pwr_down);
102} 94}
103 95
104static ssize_t ad5446_write_dac_powerdown(struct device *dev, 96static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev,
105 struct device_attribute *attr, 97 uintptr_t private,
98 const struct iio_chan_spec *chan,
106 const char *buf, size_t len) 99 const char *buf, size_t len)
107{ 100{
108 struct iio_dev *indio_dev = dev_get_drvdata(dev);
109 struct ad5446_state *st = iio_priv(indio_dev); 101 struct ad5446_state *st = iio_priv(indio_dev);
110 unsigned long readin; 102 unsigned int shift;
103 unsigned int val;
104 bool powerdown;
111 int ret; 105 int ret;
112 106
113 ret = strict_strtol(buf, 10, &readin); 107 ret = strtobool(buf, &powerdown);
114 if (ret) 108 if (ret)
115 return ret; 109 return ret;
116 110
117 if (readin > 1)
118 ret = -EINVAL;
119
120 mutex_lock(&indio_dev->mlock); 111 mutex_lock(&indio_dev->mlock);
121 st->pwr_down = readin; 112 st->pwr_down = powerdown;
122 113
123 if (st->pwr_down) 114 if (st->pwr_down) {
124 st->chip_info->store_pwr_down(st, st->pwr_down_mode); 115 shift = chan->scan_type.realbits + chan->scan_type.shift;
125 else 116 val = st->pwr_down_mode << shift;
126 st->chip_info->store_sample(st, st->cached_val); 117 } else {
118 val = st->cached_val;
119 }
127 120
128 ret = spi_sync(st->spi, &st->msg); 121 ret = st->chip_info->write(st, val);
129 mutex_unlock(&indio_dev->mlock); 122 mutex_unlock(&indio_dev->mlock);
130 123
131 return ret ? ret : len; 124 return ret ? ret : len;
132} 125}
133 126
134static IIO_DEVICE_ATTR(out_voltage_powerdown_mode, S_IRUGO | S_IWUSR, 127static const struct iio_chan_spec_ext_info ad5064_ext_info_powerdown[] = {
135 ad5446_read_powerdown_mode, 128 {
136 ad5446_write_powerdown_mode, 0); 129 .name = "powerdown",
137 130 .read = ad5446_read_dac_powerdown,
138static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, 131 .write = ad5446_write_dac_powerdown,
139 "1kohm_to_gnd 100kohm_to_gnd three_state"); 132 }, {
140 133 .name = "powerdown_mode",
141static IIO_DEVICE_ATTR(out_voltage0_powerdown, S_IRUGO | S_IWUSR, 134 .read = ad5446_read_powerdown_mode,
142 ad5446_read_dac_powerdown, 135 .write = ad5446_write_powerdown_mode,
143 ad5446_write_dac_powerdown, 0); 136 }, {
144 137 .name = "powerdown_mode_available",
145static struct attribute *ad5446_attributes[] = { 138 .shared = true,
146 &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, 139 .read = ad5446_read_powerdown_mode_available,
147 &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, 140 },
148 &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, 141 { },
149 NULL,
150};
151
152static const struct attribute_group ad5446_attribute_group = {
153 .attrs = ad5446_attributes,
154}; 142};
155 143
156#define AD5446_CHANNEL(bits, storage, shift) { \ 144#define _AD5446_CHANNEL(bits, storage, shift, ext) { \
157 .type = IIO_VOLTAGE, \ 145 .type = IIO_VOLTAGE, \
158 .indexed = 1, \ 146 .indexed = 1, \
159 .output = 1, \ 147 .output = 1, \
160 .channel = 0, \ 148 .channel = 0, \
161 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 149 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
162 .scan_type = IIO_ST('u', (bits), (storage), (shift)) \ 150 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
151 .scan_type = IIO_ST('u', (bits), (storage), (shift)), \
152 .ext_info = (ext), \
163} 153}
164 154
155#define AD5446_CHANNEL(bits, storage, shift) \
156 _AD5446_CHANNEL(bits, storage, shift, NULL)
157
158#define AD5446_CHANNEL_POWERDOWN(bits, storage, shift) \
159 _AD5446_CHANNEL(bits, storage, shift, ad5064_ext_info_powerdown)
160
165static const struct ad5446_chip_info ad5446_chip_info_tbl[] = { 161static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
166 [ID_AD5444] = { 162 [ID_AD5444] = {
167 .channel = AD5446_CHANNEL(12, 16, 2), 163 .channel = AD5446_CHANNEL(12, 16, 2),
168 .store_sample = ad5446_store_sample, 164 .write = ad5446_write,
169 }, 165 },
170 [ID_AD5446] = { 166 [ID_AD5446] = {
171 .channel = AD5446_CHANNEL(14, 16, 0), 167 .channel = AD5446_CHANNEL(14, 16, 0),
172 .store_sample = ad5446_store_sample, 168 .write = ad5446_write,
173 }, 169 },
174 [ID_AD5541A] = { 170 [ID_AD5541A] = {
175 .channel = AD5446_CHANNEL(16, 16, 0), 171 .channel = AD5446_CHANNEL(16, 16, 0),
176 .store_sample = ad5542_store_sample, 172 .write = ad5446_write,
177 },
178 [ID_AD5542A] = {
179 .channel = AD5446_CHANNEL(16, 16, 0),
180 .store_sample = ad5542_store_sample,
181 },
182 [ID_AD5543] = {
183 .channel = AD5446_CHANNEL(16, 16, 0),
184 .store_sample = ad5542_store_sample,
185 }, 173 },
186 [ID_AD5512A] = { 174 [ID_AD5512A] = {
187 .channel = AD5446_CHANNEL(12, 16, 4), 175 .channel = AD5446_CHANNEL(12, 16, 4),
188 .store_sample = ad5542_store_sample, 176 .write = ad5446_write,
189 }, 177 },
190 [ID_AD5553] = { 178 [ID_AD5553] = {
191 .channel = AD5446_CHANNEL(14, 16, 0), 179 .channel = AD5446_CHANNEL(14, 16, 0),
192 .store_sample = ad5542_store_sample, 180 .write = ad5446_write,
193 }, 181 },
194 [ID_AD5601] = { 182 [ID_AD5601] = {
195 .channel = AD5446_CHANNEL(8, 16, 6), 183 .channel = AD5446_CHANNEL_POWERDOWN(8, 16, 6),
196 .store_sample = ad5542_store_sample, 184 .write = ad5446_write,
197 .store_pwr_down = ad5620_store_pwr_down,
198 }, 185 },
199 [ID_AD5611] = { 186 [ID_AD5611] = {
200 .channel = AD5446_CHANNEL(10, 16, 4), 187 .channel = AD5446_CHANNEL_POWERDOWN(10, 16, 4),
201 .store_sample = ad5542_store_sample, 188 .write = ad5446_write,
202 .store_pwr_down = ad5620_store_pwr_down,
203 }, 189 },
204 [ID_AD5621] = { 190 [ID_AD5621] = {
205 .channel = AD5446_CHANNEL(12, 16, 2), 191 .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2),
206 .store_sample = ad5542_store_sample, 192 .write = ad5446_write,
207 .store_pwr_down = ad5620_store_pwr_down,
208 }, 193 },
209 [ID_AD5620_2500] = { 194 [ID_AD5620_2500] = {
210 .channel = AD5446_CHANNEL(12, 16, 2), 195 .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2),
211 .int_vref_mv = 2500, 196 .int_vref_mv = 2500,
212 .store_sample = ad5620_store_sample, 197 .write = ad5446_write,
213 .store_pwr_down = ad5620_store_pwr_down,
214 }, 198 },
215 [ID_AD5620_1250] = { 199 [ID_AD5620_1250] = {
216 .channel = AD5446_CHANNEL(12, 16, 2), 200 .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2),
217 .int_vref_mv = 1250, 201 .int_vref_mv = 1250,
218 .store_sample = ad5620_store_sample, 202 .write = ad5446_write,
219 .store_pwr_down = ad5620_store_pwr_down,
220 }, 203 },
221 [ID_AD5640_2500] = { 204 [ID_AD5640_2500] = {
222 .channel = AD5446_CHANNEL(14, 16, 0), 205 .channel = AD5446_CHANNEL_POWERDOWN(14, 16, 0),
223 .int_vref_mv = 2500, 206 .int_vref_mv = 2500,
224 .store_sample = ad5620_store_sample, 207 .write = ad5446_write,
225 .store_pwr_down = ad5620_store_pwr_down,
226 }, 208 },
227 [ID_AD5640_1250] = { 209 [ID_AD5640_1250] = {
228 .channel = AD5446_CHANNEL(14, 16, 0), 210 .channel = AD5446_CHANNEL_POWERDOWN(14, 16, 0),
229 .int_vref_mv = 1250, 211 .int_vref_mv = 1250,
230 .store_sample = ad5620_store_sample, 212 .write = ad5446_write,
231 .store_pwr_down = ad5620_store_pwr_down,
232 }, 213 },
233 [ID_AD5660_2500] = { 214 [ID_AD5660_2500] = {
234 .channel = AD5446_CHANNEL(16, 16, 0), 215 .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0),
235 .int_vref_mv = 2500, 216 .int_vref_mv = 2500,
236 .store_sample = ad5660_store_sample, 217 .write = ad5660_write,
237 .store_pwr_down = ad5660_store_pwr_down,
238 }, 218 },
239 [ID_AD5660_1250] = { 219 [ID_AD5660_1250] = {
240 .channel = AD5446_CHANNEL(16, 16, 0), 220 .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0),
241 .int_vref_mv = 1250, 221 .int_vref_mv = 1250,
242 .store_sample = ad5660_store_sample, 222 .write = ad5660_write,
243 .store_pwr_down = ad5660_store_pwr_down, 223 },
224 [ID_AD5662] = {
225 .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0),
226 .write = ad5660_write,
244 }, 227 },
245}; 228};
246 229
@@ -254,6 +237,9 @@ static int ad5446_read_raw(struct iio_dev *indio_dev,
254 unsigned long scale_uv; 237 unsigned long scale_uv;
255 238
256 switch (m) { 239 switch (m) {
240 case IIO_CHAN_INFO_RAW:
241 *val = st->cached_val;
242 return IIO_VAL_INT;
257 case IIO_CHAN_INFO_SCALE: 243 case IIO_CHAN_INFO_SCALE:
258 scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits; 244 scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits;
259 *val = scale_uv / 1000; 245 *val = scale_uv / 1000;
@@ -271,18 +257,18 @@ static int ad5446_write_raw(struct iio_dev *indio_dev,
271 long mask) 257 long mask)
272{ 258{
273 struct ad5446_state *st = iio_priv(indio_dev); 259 struct ad5446_state *st = iio_priv(indio_dev);
274 int ret; 260 int ret = 0;
275 261
276 switch (mask) { 262 switch (mask) {
277 case 0: 263 case IIO_CHAN_INFO_RAW:
278 if (val >= (1 << chan->scan_type.realbits) || val < 0) 264 if (val >= (1 << chan->scan_type.realbits) || val < 0)
279 return -EINVAL; 265 return -EINVAL;
280 266
281 val <<= chan->scan_type.shift; 267 val <<= chan->scan_type.shift;
282 mutex_lock(&indio_dev->mlock); 268 mutex_lock(&indio_dev->mlock);
283 st->cached_val = val; 269 st->cached_val = val;
284 st->chip_info->store_sample(st, val); 270 if (!st->pwr_down)
285 ret = spi_sync(st->spi, &st->msg); 271 ret = st->chip_info->write(st, val);
286 mutex_unlock(&indio_dev->mlock); 272 mutex_unlock(&indio_dev->mlock);
287 break; 273 break;
288 default: 274 default:
@@ -295,13 +281,6 @@ static int ad5446_write_raw(struct iio_dev *indio_dev,
295static const struct iio_info ad5446_info = { 281static const struct iio_info ad5446_info = {
296 .read_raw = ad5446_read_raw, 282 .read_raw = ad5446_read_raw,
297 .write_raw = ad5446_write_raw, 283 .write_raw = ad5446_write_raw,
298 .attrs = &ad5446_attribute_group,
299 .driver_module = THIS_MODULE,
300};
301
302static const struct iio_info ad5446_info_no_pwr_down = {
303 .read_raw = ad5446_read_raw,
304 .write_raw = ad5446_write_raw,
305 .driver_module = THIS_MODULE, 284 .driver_module = THIS_MODULE,
306}; 285};
307 286
@@ -321,7 +300,7 @@ static int __devinit ad5446_probe(struct spi_device *spi)
321 voltage_uv = regulator_get_voltage(reg); 300 voltage_uv = regulator_get_voltage(reg);
322 } 301 }
323 302
324 indio_dev = iio_allocate_device(sizeof(*st)); 303 indio_dev = iio_device_alloc(sizeof(*st));
325 if (indio_dev == NULL) { 304 if (indio_dev == NULL) {
326 ret = -ENOMEM; 305 ret = -ENOMEM;
327 goto error_disable_reg; 306 goto error_disable_reg;
@@ -337,38 +316,17 @@ static int __devinit ad5446_probe(struct spi_device *spi)
337 /* Establish that the iio_dev is a child of the spi device */ 316 /* Establish that the iio_dev is a child of the spi device */
338 indio_dev->dev.parent = &spi->dev; 317 indio_dev->dev.parent = &spi->dev;
339 indio_dev->name = spi_get_device_id(spi)->name; 318 indio_dev->name = spi_get_device_id(spi)->name;
340 if (st->chip_info->store_pwr_down) 319 indio_dev->info = &ad5446_info;
341 indio_dev->info = &ad5446_info;
342 else
343 indio_dev->info = &ad5446_info_no_pwr_down;
344 indio_dev->modes = INDIO_DIRECT_MODE; 320 indio_dev->modes = INDIO_DIRECT_MODE;
345 indio_dev->channels = &st->chip_info->channel; 321 indio_dev->channels = &st->chip_info->channel;
346 indio_dev->num_channels = 1; 322 indio_dev->num_channels = 1;
347 323
348 /* Setup default message */ 324 if (st->chip_info->int_vref_mv)
349
350 st->xfer.tx_buf = &st->data;
351 st->xfer.len = st->chip_info->channel.scan_type.storagebits / 8;
352
353 spi_message_init(&st->msg);
354 spi_message_add_tail(&st->xfer, &st->msg);
355
356 switch (spi_get_device_id(spi)->driver_data) {
357 case ID_AD5620_2500:
358 case ID_AD5620_1250:
359 case ID_AD5640_2500:
360 case ID_AD5640_1250:
361 case ID_AD5660_2500:
362 case ID_AD5660_1250:
363 st->vref_mv = st->chip_info->int_vref_mv; 325 st->vref_mv = st->chip_info->int_vref_mv;
364 break; 326 else if (voltage_uv)
365 default: 327 st->vref_mv = voltage_uv / 1000;
366 if (voltage_uv) 328 else
367 st->vref_mv = voltage_uv / 1000; 329 dev_warn(&spi->dev, "reference voltage unspecified\n");
368 else
369 dev_warn(&spi->dev,
370 "reference voltage unspecified\n");
371 }
372 330
373 ret = iio_device_register(indio_dev); 331 ret = iio_device_register(indio_dev);
374 if (ret) 332 if (ret)
@@ -377,7 +335,7 @@ static int __devinit ad5446_probe(struct spi_device *spi)
377 return 0; 335 return 0;
378 336
379error_free_device: 337error_free_device:
380 iio_free_device(indio_dev); 338 iio_device_free(indio_dev);
381error_disable_reg: 339error_disable_reg:
382 if (!IS_ERR(reg)) 340 if (!IS_ERR(reg))
383 regulator_disable(reg); 341 regulator_disable(reg);
@@ -398,7 +356,7 @@ static int ad5446_remove(struct spi_device *spi)
398 regulator_disable(st->reg); 356 regulator_disable(st->reg);
399 regulator_put(st->reg); 357 regulator_put(st->reg);
400 } 358 }
401 iio_free_device(indio_dev); 359 iio_device_free(indio_dev);
402 360
403 return 0; 361 return 0;
404} 362}
@@ -408,8 +366,8 @@ static const struct spi_device_id ad5446_id[] = {
408 {"ad5446", ID_AD5446}, 366 {"ad5446", ID_AD5446},
409 {"ad5512a", ID_AD5512A}, 367 {"ad5512a", ID_AD5512A},
410 {"ad5541a", ID_AD5541A}, 368 {"ad5541a", ID_AD5541A},
411 {"ad5542a", ID_AD5542A}, 369 {"ad5542a", ID_AD5541A}, /* ad5541a and ad5542a are compatible */
412 {"ad5543", ID_AD5543}, 370 {"ad5543", ID_AD5541A}, /* ad5541a and ad5543 are compatible */
413 {"ad5553", ID_AD5553}, 371 {"ad5553", ID_AD5553},
414 {"ad5601", ID_AD5601}, 372 {"ad5601", ID_AD5601},
415 {"ad5611", ID_AD5611}, 373 {"ad5611", ID_AD5611},
@@ -420,6 +378,7 @@ static const struct spi_device_id ad5446_id[] = {
420 {"ad5640-1250", ID_AD5640_1250}, 378 {"ad5640-1250", ID_AD5640_1250},
421 {"ad5660-2500", ID_AD5660_2500}, 379 {"ad5660-2500", ID_AD5660_2500},
422 {"ad5660-1250", ID_AD5660_1250}, 380 {"ad5660-1250", ID_AD5660_1250},
381 {"ad5662", ID_AD5662},
423 {} 382 {}
424}; 383};
425MODULE_DEVICE_TABLE(spi, ad5446_id); 384MODULE_DEVICE_TABLE(spi, ad5446_id);
diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
index 4ea3476fb065..dfd68ce7427e 100644
--- a/drivers/staging/iio/dac/ad5446.h
+++ b/drivers/staging/iio/dac/ad5446.h
@@ -34,43 +34,30 @@
34 * @spi: spi_device 34 * @spi: spi_device
35 * @chip_info: chip model specific constants, available modes etc 35 * @chip_info: chip model specific constants, available modes etc
36 * @reg: supply regulator 36 * @reg: supply regulator
37 * @poll_work: bottom half of polling interrupt handler
38 * @vref_mv: actual reference voltage used 37 * @vref_mv: actual reference voltage used
39 * @xfer: default spi transfer
40 * @msg: default spi message
41 * @data: spi transmit buffer
42 */ 38 */
43 39
44struct ad5446_state { 40struct ad5446_state {
45 struct spi_device *spi; 41 struct spi_device *spi;
46 const struct ad5446_chip_info *chip_info; 42 const struct ad5446_chip_info *chip_info;
47 struct regulator *reg; 43 struct regulator *reg;
48 struct work_struct poll_work;
49 unsigned short vref_mv; 44 unsigned short vref_mv;
50 unsigned cached_val; 45 unsigned cached_val;
51 unsigned pwr_down_mode; 46 unsigned pwr_down_mode;
52 unsigned pwr_down; 47 unsigned pwr_down;
53 struct spi_transfer xfer;
54 struct spi_message msg;
55 union {
56 unsigned short d16;
57 unsigned char d24[3];
58 } data;
59}; 48};
60 49
61/** 50/**
62 * struct ad5446_chip_info - chip specific information 51 * struct ad5446_chip_info - chip specific information
63 * @channel: channel spec for the DAC 52 * @channel: channel spec for the DAC
64 * @int_vref_mv: AD5620/40/60: the internal reference voltage 53 * @int_vref_mv: AD5620/40/60: the internal reference voltage
65 * @store_sample: chip specific helper function to store the datum 54 * @write: chip specific helper function to write to the register
66 * @store_sample: chip specific helper function to store the powerpown cmd
67 */ 55 */
68 56
69struct ad5446_chip_info { 57struct ad5446_chip_info {
70 struct iio_chan_spec channel; 58 struct iio_chan_spec channel;
71 u16 int_vref_mv; 59 u16 int_vref_mv;
72 void (*store_sample) (struct ad5446_state *st, unsigned val); 60 int (*write)(struct ad5446_state *st, unsigned val);
73 void (*store_pwr_down) (struct ad5446_state *st, unsigned mode);
74}; 61};
75 62
76/** 63/**
@@ -85,8 +72,6 @@ enum ad5446_supported_device_ids {
85 ID_AD5444, 72 ID_AD5444,
86 ID_AD5446, 73 ID_AD5446,
87 ID_AD5541A, 74 ID_AD5541A,
88 ID_AD5542A,
89 ID_AD5543,
90 ID_AD5512A, 75 ID_AD5512A,
91 ID_AD5553, 76 ID_AD5553,
92 ID_AD5601, 77 ID_AD5601,
@@ -98,6 +83,7 @@ enum ad5446_supported_device_ids {
98 ID_AD5640_1250, 83 ID_AD5640_1250,
99 ID_AD5660_2500, 84 ID_AD5660_2500,
100 ID_AD5660_1250, 85 ID_AD5660_1250,
86 ID_AD5662,
101}; 87};
102 88
103#endif /* IIO_DAC_AD5446_H_ */ 89#endif /* IIO_DAC_AD5446_H_ */
diff --git a/drivers/staging/iio/dac/ad5504.c b/drivers/staging/iio/dac/ad5504.c
index bc17205fe722..019cf15cd24a 100644
--- a/drivers/staging/iio/dac/ad5504.c
+++ b/drivers/staging/iio/dac/ad5504.c
@@ -16,9 +16,9 @@
16#include <linux/regulator/consumer.h> 16#include <linux/regulator/consumer.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "../events.h" 21#include <linux/iio/events.h>
22#include "dac.h" 22#include "dac.h"
23#include "ad5504.h" 23#include "ad5504.h"
24 24
@@ -27,7 +27,8 @@
27 .indexed = 1, \ 27 .indexed = 1, \
28 .output = 1, \ 28 .output = 1, \
29 .channel = (_chan), \ 29 .channel = (_chan), \
30 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 30 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
31 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
31 .address = AD5504_ADDR_DAC(_chan), \ 32 .address = AD5504_ADDR_DAC(_chan), \
32 .scan_type = IIO_ST('u', 12, 16, 0), \ 33 .scan_type = IIO_ST('u', 12, 16, 0), \
33} 34}
@@ -81,7 +82,7 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,
81 int ret; 82 int ret;
82 83
83 switch (m) { 84 switch (m) {
84 case 0: 85 case IIO_CHAN_INFO_RAW:
85 ret = ad5504_spi_read(st->spi, chan->address); 86 ret = ad5504_spi_read(st->spi, chan->address);
86 if (ret < 0) 87 if (ret < 0)
87 return ret; 88 return ret;
@@ -109,7 +110,7 @@ static int ad5504_write_raw(struct iio_dev *indio_dev,
109 int ret; 110 int ret;
110 111
111 switch (mask) { 112 switch (mask) {
112 case 0: 113 case IIO_CHAN_INFO_RAW:
113 if (val >= (1 << chan->scan_type.realbits) || val < 0) 114 if (val >= (1 << chan->scan_type.realbits) || val < 0)
114 return -EINVAL; 115 return -EINVAL;
115 116
@@ -124,7 +125,7 @@ static int ad5504_write_raw(struct iio_dev *indio_dev,
124static ssize_t ad5504_read_powerdown_mode(struct device *dev, 125static ssize_t ad5504_read_powerdown_mode(struct device *dev,
125 struct device_attribute *attr, char *buf) 126 struct device_attribute *attr, char *buf)
126{ 127{
127 struct iio_dev *indio_dev = dev_get_drvdata(dev); 128 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
128 struct ad5504_state *st = iio_priv(indio_dev); 129 struct ad5504_state *st = iio_priv(indio_dev);
129 130
130 const char mode[][14] = {"20kohm_to_gnd", "three_state"}; 131 const char mode[][14] = {"20kohm_to_gnd", "three_state"};
@@ -136,7 +137,7 @@ static ssize_t ad5504_write_powerdown_mode(struct device *dev,
136 struct device_attribute *attr, 137 struct device_attribute *attr,
137 const char *buf, size_t len) 138 const char *buf, size_t len)
138{ 139{
139 struct iio_dev *indio_dev = dev_get_drvdata(dev); 140 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
140 struct ad5504_state *st = iio_priv(indio_dev); 141 struct ad5504_state *st = iio_priv(indio_dev);
141 int ret; 142 int ret;
142 143
@@ -154,7 +155,7 @@ static ssize_t ad5504_read_dac_powerdown(struct device *dev,
154 struct device_attribute *attr, 155 struct device_attribute *attr,
155 char *buf) 156 char *buf)
156{ 157{
157 struct iio_dev *indio_dev = dev_get_drvdata(dev); 158 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
158 struct ad5504_state *st = iio_priv(indio_dev); 159 struct ad5504_state *st = iio_priv(indio_dev);
159 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 160 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
160 161
@@ -168,7 +169,7 @@ static ssize_t ad5504_write_dac_powerdown(struct device *dev,
168{ 169{
169 long readin; 170 long readin;
170 int ret; 171 int ret;
171 struct iio_dev *indio_dev = dev_get_drvdata(dev); 172 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
172 struct ad5504_state *st = iio_priv(indio_dev); 173 struct ad5504_state *st = iio_priv(indio_dev);
173 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 174 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
174 175
@@ -287,7 +288,7 @@ static int __devinit ad5504_probe(struct spi_device *spi)
287 struct regulator *reg; 288 struct regulator *reg;
288 int ret, voltage_uv = 0; 289 int ret, voltage_uv = 0;
289 290
290 indio_dev = iio_allocate_device(sizeof(*st)); 291 indio_dev = iio_device_alloc(sizeof(*st));
291 if (indio_dev == NULL) { 292 if (indio_dev == NULL) {
292 ret = -ENOMEM; 293 ret = -ENOMEM;
293 goto error_ret; 294 goto error_ret;
@@ -350,7 +351,7 @@ error_put_reg:
350 if (!IS_ERR(reg)) 351 if (!IS_ERR(reg))
351 regulator_put(reg); 352 regulator_put(reg);
352 353
353 iio_free_device(indio_dev); 354 iio_device_free(indio_dev);
354error_ret: 355error_ret:
355 return ret; 356 return ret;
356} 357}
@@ -368,7 +369,7 @@ static int __devexit ad5504_remove(struct spi_device *spi)
368 regulator_disable(st->reg); 369 regulator_disable(st->reg);
369 regulator_put(st->reg); 370 regulator_put(st->reg);
370 } 371 }
371 iio_free_device(indio_dev); 372 iio_device_free(indio_dev);
372 373
373 return 0; 374 return 0;
374} 375}
diff --git a/drivers/staging/iio/dac/ad5624r_spi.c b/drivers/staging/iio/dac/ad5624r_spi.c
index 10c7484366ef..42ff644ac43e 100644
--- a/drivers/staging/iio/dac/ad5624r_spi.c
+++ b/drivers/staging/iio/dac/ad5624r_spi.c
@@ -16,8 +16,8 @@
16#include <linux/regulator/consumer.h> 16#include <linux/regulator/consumer.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dac.h" 21#include "dac.h"
22#include "ad5624r.h" 22#include "ad5624r.h"
23 23
@@ -26,7 +26,8 @@
26 .indexed = 1, \ 26 .indexed = 1, \
27 .output = 1, \ 27 .output = 1, \
28 .channel = (_chan), \ 28 .channel = (_chan), \
29 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 29 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
30 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
30 .address = (_chan), \ 31 .address = (_chan), \
31 .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \ 32 .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \
32} 33}
@@ -122,7 +123,7 @@ static int ad5624r_write_raw(struct iio_dev *indio_dev,
122 int ret; 123 int ret;
123 124
124 switch (mask) { 125 switch (mask) {
125 case 0: 126 case IIO_CHAN_INFO_RAW:
126 if (val >= (1 << chan->scan_type.realbits) || val < 0) 127 if (val >= (1 << chan->scan_type.realbits) || val < 0)
127 return -EINVAL; 128 return -EINVAL;
128 129
@@ -140,7 +141,7 @@ static int ad5624r_write_raw(struct iio_dev *indio_dev,
140static ssize_t ad5624r_read_powerdown_mode(struct device *dev, 141static ssize_t ad5624r_read_powerdown_mode(struct device *dev,
141 struct device_attribute *attr, char *buf) 142 struct device_attribute *attr, char *buf)
142{ 143{
143 struct iio_dev *indio_dev = dev_get_drvdata(dev); 144 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
144 struct ad5624r_state *st = iio_priv(indio_dev); 145 struct ad5624r_state *st = iio_priv(indio_dev);
145 146
146 char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"}; 147 char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"};
@@ -152,7 +153,7 @@ static ssize_t ad5624r_write_powerdown_mode(struct device *dev,
152 struct device_attribute *attr, 153 struct device_attribute *attr,
153 const char *buf, size_t len) 154 const char *buf, size_t len)
154{ 155{
155 struct iio_dev *indio_dev = dev_get_drvdata(dev); 156 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
156 struct ad5624r_state *st = iio_priv(indio_dev); 157 struct ad5624r_state *st = iio_priv(indio_dev);
157 int ret; 158 int ret;
158 159
@@ -172,7 +173,7 @@ static ssize_t ad5624r_read_dac_powerdown(struct device *dev,
172 struct device_attribute *attr, 173 struct device_attribute *attr,
173 char *buf) 174 char *buf)
174{ 175{
175 struct iio_dev *indio_dev = dev_get_drvdata(dev); 176 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
176 struct ad5624r_state *st = iio_priv(indio_dev); 177 struct ad5624r_state *st = iio_priv(indio_dev);
177 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 178 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
178 179
@@ -186,7 +187,7 @@ static ssize_t ad5624r_write_dac_powerdown(struct device *dev,
186{ 187{
187 long readin; 188 long readin;
188 int ret; 189 int ret;
189 struct iio_dev *indio_dev = dev_get_drvdata(dev); 190 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
190 struct ad5624r_state *st = iio_priv(indio_dev); 191 struct ad5624r_state *st = iio_priv(indio_dev);
191 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 192 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
192 193
@@ -255,7 +256,7 @@ static int __devinit ad5624r_probe(struct spi_device *spi)
255 struct iio_dev *indio_dev; 256 struct iio_dev *indio_dev;
256 int ret, voltage_uv = 0; 257 int ret, voltage_uv = 0;
257 258
258 indio_dev = iio_allocate_device(sizeof(*st)); 259 indio_dev = iio_device_alloc(sizeof(*st));
259 if (indio_dev == NULL) { 260 if (indio_dev == NULL) {
260 ret = -ENOMEM; 261 ret = -ENOMEM;
261 goto error_ret; 262 goto error_ret;
@@ -305,7 +306,7 @@ error_disable_reg:
305error_put_reg: 306error_put_reg:
306 if (!IS_ERR(st->reg)) 307 if (!IS_ERR(st->reg))
307 regulator_put(st->reg); 308 regulator_put(st->reg);
308 iio_free_device(indio_dev); 309 iio_device_free(indio_dev);
309error_ret: 310error_ret:
310 311
311 return ret; 312 return ret;
@@ -321,7 +322,7 @@ static int __devexit ad5624r_remove(struct spi_device *spi)
321 regulator_disable(st->reg); 322 regulator_disable(st->reg);
322 regulator_put(st->reg); 323 regulator_put(st->reg);
323 } 324 }
324 iio_free_device(indio_dev); 325 iio_device_free(indio_dev);
325 326
326 return 0; 327 return 0;
327} 328}
diff --git a/drivers/staging/iio/dac/ad5686.c b/drivers/staging/iio/dac/ad5686.c
index 2415a6e60c77..c1e903ebc7b9 100644
--- a/drivers/staging/iio/dac/ad5686.c
+++ b/drivers/staging/iio/dac/ad5686.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dac.h" 21#include "dac.h"
22 22
23#define AD5686_DAC_CHANNELS 4 23#define AD5686_DAC_CHANNELS 4
@@ -98,7 +98,8 @@ enum ad5686_supported_device_ids {
98 .indexed = 1, \ 98 .indexed = 1, \
99 .output = 1, \ 99 .output = 1, \
100 .channel = chan, \ 100 .channel = chan, \
101 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 101 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
102 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
102 .address = AD5686_ADDR_DAC(chan), \ 103 .address = AD5686_ADDR_DAC(chan), \
103 .scan_type = IIO_ST('u', bits, 16, shift) \ 104 .scan_type = IIO_ST('u', bits, 16, shift) \
104} 105}
@@ -172,7 +173,7 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
172static ssize_t ad5686_read_powerdown_mode(struct device *dev, 173static ssize_t ad5686_read_powerdown_mode(struct device *dev,
173 struct device_attribute *attr, char *buf) 174 struct device_attribute *attr, char *buf)
174{ 175{
175 struct iio_dev *indio_dev = dev_get_drvdata(dev); 176 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
176 struct ad5686_state *st = iio_priv(indio_dev); 177 struct ad5686_state *st = iio_priv(indio_dev);
177 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 178 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
178 179
@@ -186,7 +187,7 @@ static ssize_t ad5686_write_powerdown_mode(struct device *dev,
186 struct device_attribute *attr, 187 struct device_attribute *attr,
187 const char *buf, size_t len) 188 const char *buf, size_t len)
188{ 189{
189 struct iio_dev *indio_dev = dev_get_drvdata(dev); 190 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
190 struct ad5686_state *st = iio_priv(indio_dev); 191 struct ad5686_state *st = iio_priv(indio_dev);
191 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 192 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
192 unsigned mode; 193 unsigned mode;
@@ -210,7 +211,7 @@ static ssize_t ad5686_read_dac_powerdown(struct device *dev,
210 struct device_attribute *attr, 211 struct device_attribute *attr,
211 char *buf) 212 char *buf)
212{ 213{
213 struct iio_dev *indio_dev = dev_get_drvdata(dev); 214 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
214 struct ad5686_state *st = iio_priv(indio_dev); 215 struct ad5686_state *st = iio_priv(indio_dev);
215 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 216 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
216 217
@@ -224,7 +225,7 @@ static ssize_t ad5686_write_dac_powerdown(struct device *dev,
224{ 225{
225 bool readin; 226 bool readin;
226 int ret; 227 int ret;
227 struct iio_dev *indio_dev = dev_get_drvdata(dev); 228 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
228 struct ad5686_state *st = iio_priv(indio_dev); 229 struct ad5686_state *st = iio_priv(indio_dev);
229 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 230 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
230 231
@@ -296,7 +297,7 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
296 int ret; 297 int ret;
297 298
298 switch (m) { 299 switch (m) {
299 case 0: 300 case IIO_CHAN_INFO_RAW:
300 mutex_lock(&indio_dev->mlock); 301 mutex_lock(&indio_dev->mlock);
301 ret = ad5686_spi_read(st, chan->address); 302 ret = ad5686_spi_read(st, chan->address);
302 mutex_unlock(&indio_dev->mlock); 303 mutex_unlock(&indio_dev->mlock);
@@ -326,7 +327,7 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
326 int ret; 327 int ret;
327 328
328 switch (mask) { 329 switch (mask) {
329 case 0: 330 case IIO_CHAN_INFO_RAW:
330 if (val > (1 << chan->scan_type.realbits) || val < 0) 331 if (val > (1 << chan->scan_type.realbits) || val < 0)
331 return -EINVAL; 332 return -EINVAL;
332 333
@@ -358,7 +359,7 @@ static int __devinit ad5686_probe(struct spi_device *spi)
358 struct iio_dev *indio_dev; 359 struct iio_dev *indio_dev;
359 int ret, regdone = 0, voltage_uv = 0; 360 int ret, regdone = 0, voltage_uv = 0;
360 361
361 indio_dev = iio_allocate_device(sizeof(*st)); 362 indio_dev = iio_device_alloc(sizeof(*st));
362 if (indio_dev == NULL) 363 if (indio_dev == NULL)
363 return -ENOMEM; 364 return -ENOMEM;
364 365
@@ -410,7 +411,7 @@ error_put_reg:
410 if (!IS_ERR(st->reg)) 411 if (!IS_ERR(st->reg))
411 regulator_put(st->reg); 412 regulator_put(st->reg);
412 413
413 iio_free_device(indio_dev); 414 iio_device_free(indio_dev);
414 415
415 return ret; 416 return ret;
416} 417}
@@ -425,7 +426,7 @@ static int __devexit ad5686_remove(struct spi_device *spi)
425 regulator_disable(st->reg); 426 regulator_disable(st->reg);
426 regulator_put(st->reg); 427 regulator_put(st->reg);
427 } 428 }
428 iio_free_device(indio_dev); 429 iio_device_free(indio_dev);
429 430
430 return 0; 431 return 0;
431} 432}
diff --git a/drivers/staging/iio/dac/ad5764.c b/drivers/staging/iio/dac/ad5764.c
index f73a73079490..03dbd937b081 100644
--- a/drivers/staging/iio/dac/ad5764.c
+++ b/drivers/staging/iio/dac/ad5764.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dac.h" 21#include "dac.h"
22 22
23#define AD5764_REG_SF_NOP 0x0 23#define AD5764_REG_SF_NOP 0x0
@@ -79,7 +79,8 @@ enum ad5764_type {
79 .output = 1, \ 79 .output = 1, \
80 .channel = (_chan), \ 80 .channel = (_chan), \
81 .address = (_chan), \ 81 .address = (_chan), \
82 .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT | \ 82 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
83 IIO_CHAN_INFO_OFFSET_SHARED_BIT | \
83 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ 84 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
84 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ 85 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
85 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ 86 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \
@@ -188,7 +189,7 @@ static int ad5764_write_raw(struct iio_dev *indio_dev,
188 unsigned int reg; 189 unsigned int reg;
189 190
190 switch (info) { 191 switch (info) {
191 case 0: 192 case IIO_CHAN_INFO_RAW:
192 if (val >= max_val || val < 0) 193 if (val >= max_val || val < 0)
193 return -EINVAL; 194 return -EINVAL;
194 val <<= chan->scan_type.shift; 195 val <<= chan->scan_type.shift;
@@ -228,7 +229,7 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
228 int ret; 229 int ret;
229 230
230 switch (info) { 231 switch (info) {
231 case 0: 232 case IIO_CHAN_INFO_RAW:
232 reg = AD5764_REG_DATA(chan->address); 233 reg = AD5764_REG_DATA(chan->address);
233 ret = ad5764_read(indio_dev, reg, val); 234 ret = ad5764_read(indio_dev, reg, val);
234 if (ret < 0) 235 if (ret < 0)
@@ -280,7 +281,7 @@ static int __devinit ad5764_probe(struct spi_device *spi)
280 struct ad5764_state *st; 281 struct ad5764_state *st;
281 int ret; 282 int ret;
282 283
283 indio_dev = iio_allocate_device(sizeof(*st)); 284 indio_dev = iio_device_alloc(sizeof(*st));
284 if (indio_dev == NULL) { 285 if (indio_dev == NULL) {
285 dev_err(&spi->dev, "Failed to allocate iio device\n"); 286 dev_err(&spi->dev, "Failed to allocate iio device\n");
286 return -ENOMEM; 287 return -ENOMEM;
@@ -335,7 +336,7 @@ error_free_reg:
335 if (st->chip_info->int_vref == 0) 336 if (st->chip_info->int_vref == 0)
336 regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); 337 regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg);
337error_free: 338error_free:
338 iio_free_device(indio_dev); 339 iio_device_free(indio_dev);
339 340
340 return ret; 341 return ret;
341} 342}
@@ -352,7 +353,7 @@ static int __devexit ad5764_remove(struct spi_device *spi)
352 regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); 353 regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg);
353 } 354 }
354 355
355 iio_free_device(indio_dev); 356 iio_device_free(indio_dev);
356 357
357 return 0; 358 return 0;
358} 359}
diff --git a/drivers/staging/iio/dac/ad5791.c b/drivers/staging/iio/dac/ad5791.c
index ac45636a8d72..13d8b5bb1cea 100644
--- a/drivers/staging/iio/dac/ad5791.c
+++ b/drivers/staging/iio/dac/ad5791.c
@@ -17,8 +17,8 @@
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/module.h> 18#include <linux/module.h>
19 19
20#include "../iio.h" 20#include <linux/iio/iio.h>
21#include "../sysfs.h" 21#include <linux/iio/sysfs.h>
22#include "dac.h" 22#include "dac.h"
23#include "ad5791.h" 23#include "ad5791.h"
24 24
@@ -78,7 +78,8 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
78 .indexed = 1, \ 78 .indexed = 1, \
79 .address = AD5791_ADDR_DAC0, \ 79 .address = AD5791_ADDR_DAC0, \
80 .channel = 0, \ 80 .channel = 0, \
81 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | \ 81 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
82 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
82 IIO_CHAN_INFO_OFFSET_SHARED_BIT, \ 83 IIO_CHAN_INFO_OFFSET_SHARED_BIT, \
83 .scan_type = IIO_ST('u', bits, 24, shift) \ 84 .scan_type = IIO_ST('u', bits, 24, shift) \
84} 85}
@@ -93,7 +94,7 @@ static const struct iio_chan_spec ad5791_channels[] = {
93static ssize_t ad5791_read_powerdown_mode(struct device *dev, 94static ssize_t ad5791_read_powerdown_mode(struct device *dev,
94 struct device_attribute *attr, char *buf) 95 struct device_attribute *attr, char *buf)
95{ 96{
96 struct iio_dev *indio_dev = dev_get_drvdata(dev); 97 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
97 struct ad5791_state *st = iio_priv(indio_dev); 98 struct ad5791_state *st = iio_priv(indio_dev);
98 99
99 const char mode[][14] = {"6kohm_to_gnd", "three_state"}; 100 const char mode[][14] = {"6kohm_to_gnd", "three_state"};
@@ -105,7 +106,7 @@ static ssize_t ad5791_write_powerdown_mode(struct device *dev,
105 struct device_attribute *attr, 106 struct device_attribute *attr,
106 const char *buf, size_t len) 107 const char *buf, size_t len)
107{ 108{
108 struct iio_dev *indio_dev = dev_get_drvdata(dev); 109 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
109 struct ad5791_state *st = iio_priv(indio_dev); 110 struct ad5791_state *st = iio_priv(indio_dev);
110 int ret; 111 int ret;
111 112
@@ -123,7 +124,7 @@ static ssize_t ad5791_read_dac_powerdown(struct device *dev,
123 struct device_attribute *attr, 124 struct device_attribute *attr,
124 char *buf) 125 char *buf)
125{ 126{
126 struct iio_dev *indio_dev = dev_get_drvdata(dev); 127 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
127 struct ad5791_state *st = iio_priv(indio_dev); 128 struct ad5791_state *st = iio_priv(indio_dev);
128 129
129 return sprintf(buf, "%d\n", st->pwr_down); 130 return sprintf(buf, "%d\n", st->pwr_down);
@@ -135,7 +136,7 @@ static ssize_t ad5791_write_dac_powerdown(struct device *dev,
135{ 136{
136 long readin; 137 long readin;
137 int ret; 138 int ret;
138 struct iio_dev *indio_dev = dev_get_drvdata(dev); 139 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
139 struct ad5791_state *st = iio_priv(indio_dev); 140 struct ad5791_state *st = iio_priv(indio_dev);
140 141
141 ret = strict_strtol(buf, 10, &readin); 142 ret = strict_strtol(buf, 10, &readin);
@@ -231,7 +232,7 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
231 int ret; 232 int ret;
232 233
233 switch (m) { 234 switch (m) {
234 case 0: 235 case IIO_CHAN_INFO_RAW:
235 ret = ad5791_spi_read(st->spi, chan->address, val); 236 ret = ad5791_spi_read(st->spi, chan->address, val);
236 if (ret) 237 if (ret)
237 return ret; 238 return ret;
@@ -263,7 +264,7 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,
263 struct ad5791_state *st = iio_priv(indio_dev); 264 struct ad5791_state *st = iio_priv(indio_dev);
264 265
265 switch (mask) { 266 switch (mask) {
266 case 0: 267 case IIO_CHAN_INFO_RAW:
267 val &= AD5791_RES_MASK(chan->scan_type.realbits); 268 val &= AD5791_RES_MASK(chan->scan_type.realbits);
268 val <<= chan->scan_type.shift; 269 val <<= chan->scan_type.shift;
269 270
@@ -288,7 +289,7 @@ static int __devinit ad5791_probe(struct spi_device *spi)
288 struct ad5791_state *st; 289 struct ad5791_state *st;
289 int ret, pos_voltage_uv = 0, neg_voltage_uv = 0; 290 int ret, pos_voltage_uv = 0, neg_voltage_uv = 0;
290 291
291 indio_dev = iio_allocate_device(sizeof(*st)); 292 indio_dev = iio_device_alloc(sizeof(*st));
292 if (indio_dev == NULL) { 293 if (indio_dev == NULL) {
293 ret = -ENOMEM; 294 ret = -ENOMEM;
294 goto error_ret; 295 goto error_ret;
@@ -368,7 +369,7 @@ error_put_reg_neg:
368error_put_reg_pos: 369error_put_reg_pos:
369 if (!IS_ERR(st->reg_vdd)) 370 if (!IS_ERR(st->reg_vdd))
370 regulator_put(st->reg_vdd); 371 regulator_put(st->reg_vdd);
371 iio_free_device(indio_dev); 372 iio_device_free(indio_dev);
372error_ret: 373error_ret:
373 374
374 return ret; 375 return ret;
@@ -389,7 +390,7 @@ static int __devexit ad5791_remove(struct spi_device *spi)
389 regulator_disable(st->reg_vss); 390 regulator_disable(st->reg_vss);
390 regulator_put(st->reg_vss); 391 regulator_put(st->reg_vss);
391 } 392 }
392 iio_free_device(indio_dev); 393 iio_device_free(indio_dev);
393 394
394 return 0; 395 return 0;
395} 396}
diff --git a/drivers/staging/iio/dac/max517.c b/drivers/staging/iio/dac/max517.c
index 41483c72cec1..5287cad1f3a4 100644
--- a/drivers/staging/iio/dac/max517.c
+++ b/drivers/staging/iio/dac/max517.c
@@ -25,8 +25,8 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/err.h> 26#include <linux/err.h>
27 27
28#include "../iio.h" 28#include <linux/iio/iio.h>
29#include "../sysfs.h" 29#include <linux/iio/sysfs.h>
30#include "dac.h" 30#include "dac.h"
31 31
32#include "max517.h" 32#include "max517.h"
@@ -59,7 +59,7 @@ static ssize_t max517_set_value(struct device *dev,
59 struct device_attribute *attr, 59 struct device_attribute *attr,
60 const char *buf, size_t count, int channel) 60 const char *buf, size_t count, int channel)
61{ 61{
62 struct iio_dev *indio_dev = dev_get_drvdata(dev); 62 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
63 struct max517_data *data = iio_priv(indio_dev); 63 struct max517_data *data = iio_priv(indio_dev);
64 struct i2c_client *client = data->client; 64 struct i2c_client *client = data->client;
65 u8 outbuf[4]; /* 1x or 2x command + value */ 65 u8 outbuf[4]; /* 1x or 2x command + value */
@@ -128,7 +128,7 @@ static ssize_t max517_show_scale(struct device *dev,
128 struct device_attribute *attr, 128 struct device_attribute *attr,
129 char *buf, int channel) 129 char *buf, int channel)
130{ 130{
131 struct iio_dev *indio_dev = dev_get_drvdata(dev); 131 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
132 struct max517_data *data = iio_priv(indio_dev); 132 struct max517_data *data = iio_priv(indio_dev);
133 /* Corresponds to Vref / 2^(bits) */ 133 /* Corresponds to Vref / 2^(bits) */
134 unsigned int scale_uv = (data->vref_mv[channel - 1] * 1000) >> 8; 134 unsigned int scale_uv = (data->vref_mv[channel - 1] * 1000) >> 8;
@@ -218,7 +218,7 @@ static int max517_probe(struct i2c_client *client,
218 struct max517_platform_data *platform_data = client->dev.platform_data; 218 struct max517_platform_data *platform_data = client->dev.platform_data;
219 int err; 219 int err;
220 220
221 indio_dev = iio_allocate_device(sizeof(*data)); 221 indio_dev = iio_device_alloc(sizeof(*data));
222 if (indio_dev == NULL) { 222 if (indio_dev == NULL) {
223 err = -ENOMEM; 223 err = -ENOMEM;
224 goto exit; 224 goto exit;
@@ -257,14 +257,15 @@ static int max517_probe(struct i2c_client *client,
257 return 0; 257 return 0;
258 258
259exit_free_device: 259exit_free_device:
260 iio_free_device(indio_dev); 260 iio_device_free(indio_dev);
261exit: 261exit:
262 return err; 262 return err;
263} 263}
264 264
265static int max517_remove(struct i2c_client *client) 265static int max517_remove(struct i2c_client *client)
266{ 266{
267 iio_free_device(i2c_get_clientdata(client)); 267 iio_device_unregister(i2c_get_clientdata(client));
268 iio_device_free(i2c_get_clientdata(client));
268 269
269 return 0; 270 return 0;
270} 271}
diff --git a/drivers/staging/iio/dds/dds.h b/drivers/staging/iio/dds/dds.h
deleted file mode 100644
index d8ac3a93baf6..000000000000
--- a/drivers/staging/iio/dds/dds.h
+++ /dev/null
@@ -1,110 +0,0 @@
1/*
2 * dds.h - sysfs attributes associated with DDS devices
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9/**
10 * /sys/bus/iio/devices/.../ddsX_freqY
11 */
12
13#define IIO_DEV_ATTR_FREQ(_channel, _num, _mode, _show, _store, _addr) \
14 IIO_DEVICE_ATTR(dds##_channel##_freq##_num, \
15 _mode, _show, _store, _addr)
16
17/**
18 * /sys/bus/iio/devices/.../ddsX_freqY_scale
19 */
20
21#define IIO_CONST_ATTR_FREQ_SCALE(_channel, _string) \
22 IIO_CONST_ATTR(dds##_channel##_freq_scale, _string)
23
24/**
25 * /sys/bus/iio/devices/.../ddsX_freqsymbol
26 */
27
28#define IIO_DEV_ATTR_FREQSYMBOL(_channel, _mode, _show, _store, _addr) \
29 IIO_DEVICE_ATTR(dds##_channel##_freqsymbol, \
30 _mode, _show, _store, _addr);
31
32/**
33 * /sys/bus/iio/devices/.../ddsX_phaseY
34 */
35
36#define IIO_DEV_ATTR_PHASE(_channel, _num, _mode, _show, _store, _addr) \
37 IIO_DEVICE_ATTR(dds##_channel##_phase##_num, \
38 _mode, _show, _store, _addr)
39
40/**
41 * /sys/bus/iio/devices/.../ddsX_phaseY_scale
42 */
43
44#define IIO_CONST_ATTR_PHASE_SCALE(_channel, _string) \
45 IIO_CONST_ATTR(dds##_channel##_phase_scale, _string)
46
47/**
48 * /sys/bus/iio/devices/.../ddsX_phasesymbol
49 */
50
51#define IIO_DEV_ATTR_PHASESYMBOL(_channel, _mode, _show, _store, _addr) \
52 IIO_DEVICE_ATTR(dds##_channel##_phasesymbol, \
53 _mode, _show, _store, _addr);
54
55/**
56 * /sys/bus/iio/devices/.../ddsX_pincontrol_en
57 */
58
59#define IIO_DEV_ATTR_PINCONTROL_EN(_channel, _mode, _show, _store, _addr)\
60 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_en, \
61 _mode, _show, _store, _addr);
62
63/**
64 * /sys/bus/iio/devices/.../ddsX_pincontrol_freq_en
65 */
66
67#define IIO_DEV_ATTR_PINCONTROL_FREQ_EN(_channel, _mode, _show, _store, _addr)\
68 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_freq_en, \
69 _mode, _show, _store, _addr);
70
71/**
72 * /sys/bus/iio/devices/.../ddsX_pincontrol_phase_en
73 */
74
75#define IIO_DEV_ATTR_PINCONTROL_PHASE_EN(_channel, _mode, _show, _store, _addr)\
76 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_phase_en, \
77 _mode, _show, _store, _addr);
78
79/**
80 * /sys/bus/iio/devices/.../ddsX_out_enable
81 */
82
83#define IIO_DEV_ATTR_OUT_ENABLE(_channel, _mode, _show, _store, _addr) \
84 IIO_DEVICE_ATTR(dds##_channel##_out_enable, \
85 _mode, _show, _store, _addr);
86
87/**
88 * /sys/bus/iio/devices/.../ddsX_outY_enable
89 */
90
91#define IIO_DEV_ATTR_OUTY_ENABLE(_channel, _output, \
92 _mode, _show, _store, _addr) \
93 IIO_DEVICE_ATTR(dds##_channel##_out##_output##_enable, \
94 _mode, _show, _store, _addr);
95
96/**
97 * /sys/bus/iio/devices/.../ddsX_outY_wavetype
98 */
99
100#define IIO_DEV_ATTR_OUT_WAVETYPE(_channel, _output, _store, _addr) \
101 IIO_DEVICE_ATTR(dds##_channel##_out##_output##_wavetype, \
102 S_IWUSR, NULL, _store, _addr);
103
104/**
105 * /sys/bus/iio/devices/.../ddsX_outY_wavetype_available
106 */
107
108#define IIO_CONST_ATTR_OUT_WAVETYPES_AVAILABLE(_channel, _output, _modes)\
109 IIO_CONST_ATTR(dds##_channel##_out##_output##_wavetype_available,\
110 _modes);
diff --git a/drivers/staging/iio/dds/Kconfig b/drivers/staging/iio/frequency/Kconfig
index 93b7141b2c1f..93b7141b2c1f 100644
--- a/drivers/staging/iio/dds/Kconfig
+++ b/drivers/staging/iio/frequency/Kconfig
diff --git a/drivers/staging/iio/dds/Makefile b/drivers/staging/iio/frequency/Makefile
index 147746176b9b..147746176b9b 100644
--- a/drivers/staging/iio/dds/Makefile
+++ b/drivers/staging/iio/frequency/Makefile
diff --git a/drivers/staging/iio/dds/ad5930.c b/drivers/staging/iio/frequency/ad5930.c
index 9c32d1beae25..2d541d0eebef 100644
--- a/drivers/staging/iio/dds/ad5930.c
+++ b/drivers/staging/iio/frequency/ad5930.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define DRV_NAME "ad5930" 22#define DRV_NAME "ad5930"
23 23
@@ -48,7 +48,7 @@ static ssize_t ad5930_set_parameter(struct device *dev,
48 struct spi_transfer xfer; 48 struct spi_transfer xfer;
49 int ret; 49 int ret;
50 struct ad5903_config *config = (struct ad5903_config *)buf; 50 struct ad5903_config *config = (struct ad5903_config *)buf;
51 struct iio_dev *idev = dev_get_drvdata(dev); 51 struct iio_dev *idev = dev_to_iio_dev(dev);
52 struct ad5930_state *st = iio_priv(idev); 52 struct ad5930_state *st = iio_priv(idev);
53 53
54 config->control = (config->control & ~value_mask); 54 config->control = (config->control & ~value_mask);
@@ -97,7 +97,7 @@ static int __devinit ad5930_probe(struct spi_device *spi)
97 struct iio_dev *idev; 97 struct iio_dev *idev;
98 int ret = 0; 98 int ret = 0;
99 99
100 idev = iio_allocate_device(sizeof(*st)); 100 idev = iio_device_alloc(sizeof(*st));
101 if (idev == NULL) { 101 if (idev == NULL) {
102 ret = -ENOMEM; 102 ret = -ENOMEM;
103 goto error_ret; 103 goto error_ret;
@@ -122,7 +122,7 @@ static int __devinit ad5930_probe(struct spi_device *spi)
122 return 0; 122 return 0;
123 123
124error_free_dev: 124error_free_dev:
125 iio_free_device(idev); 125 iio_device_free(idev);
126error_ret: 126error_ret:
127 return ret; 127 return ret;
128} 128}
@@ -130,7 +130,7 @@ error_ret:
130static int __devexit ad5930_remove(struct spi_device *spi) 130static int __devexit ad5930_remove(struct spi_device *spi)
131{ 131{
132 iio_device_unregister(spi_get_drvdata(spi)); 132 iio_device_unregister(spi_get_drvdata(spi));
133 iio_free_device(spi_get_drvdata(spi)); 133 iio_device_free(spi_get_drvdata(spi));
134 134
135 return 0; 135 return 0;
136} 136}
diff --git a/drivers/staging/iio/dds/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 2ccf25dd9289..fed39404e34a 100644
--- a/drivers/staging/iio/dds/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <asm/div64.h> 17#include <asm/div64.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21#include "dds.h" 21#include "dds.h"
22 22
23#include "ad9832.h" 23#include "ad9832.h"
@@ -77,7 +77,7 @@ static ssize_t ad9832_write(struct device *dev,
77 const char *buf, 77 const char *buf,
78 size_t len) 78 size_t len)
79{ 79{
80 struct iio_dev *indio_dev = dev_get_drvdata(dev); 80 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
81 struct ad9832_state *st = iio_priv(indio_dev); 81 struct ad9832_state *st = iio_priv(indio_dev);
82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
83 int ret; 83 int ret;
@@ -177,18 +177,18 @@ static IIO_DEV_ATTR_OUT_ENABLE(0, S_IWUSR, NULL,
177 ad9832_write, AD9832_OUTPUT_EN); 177 ad9832_write, AD9832_OUTPUT_EN);
178 178
179static struct attribute *ad9832_attributes[] = { 179static struct attribute *ad9832_attributes[] = {
180 &iio_dev_attr_dds0_freq0.dev_attr.attr, 180 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
181 &iio_dev_attr_dds0_freq1.dev_attr.attr, 181 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
182 &iio_const_attr_dds0_freq_scale.dev_attr.attr, 182 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
183 &iio_dev_attr_dds0_phase0.dev_attr.attr, 183 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
184 &iio_dev_attr_dds0_phase1.dev_attr.attr, 184 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
185 &iio_dev_attr_dds0_phase2.dev_attr.attr, 185 &iio_dev_attr_out_altvoltage0_phase2.dev_attr.attr,
186 &iio_dev_attr_dds0_phase3.dev_attr.attr, 186 &iio_dev_attr_out_altvoltage0_phase3.dev_attr.attr,
187 &iio_const_attr_dds0_phase_scale.dev_attr.attr, 187 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
188 &iio_dev_attr_dds0_pincontrol_en.dev_attr.attr, 188 &iio_dev_attr_out_altvoltage0_pincontrol_en.dev_attr.attr,
189 &iio_dev_attr_dds0_freqsymbol.dev_attr.attr, 189 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
190 &iio_dev_attr_dds0_phasesymbol.dev_attr.attr, 190 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
191 &iio_dev_attr_dds0_out_enable.dev_attr.attr, 191 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
192 NULL, 192 NULL,
193}; 193};
194 194
@@ -221,7 +221,7 @@ static int __devinit ad9832_probe(struct spi_device *spi)
221 goto error_put_reg; 221 goto error_put_reg;
222 } 222 }
223 223
224 indio_dev = iio_allocate_device(sizeof(*st)); 224 indio_dev = iio_device_alloc(sizeof(*st));
225 if (indio_dev == NULL) { 225 if (indio_dev == NULL) {
226 ret = -ENOMEM; 226 ret = -ENOMEM;
227 goto error_disable_reg; 227 goto error_disable_reg;
@@ -313,7 +313,7 @@ static int __devinit ad9832_probe(struct spi_device *spi)
313 return 0; 313 return 0;
314 314
315error_free_device: 315error_free_device:
316 iio_free_device(indio_dev); 316 iio_device_free(indio_dev);
317error_disable_reg: 317error_disable_reg:
318 if (!IS_ERR(reg)) 318 if (!IS_ERR(reg))
319 regulator_disable(reg); 319 regulator_disable(reg);
@@ -334,7 +334,7 @@ static int __devexit ad9832_remove(struct spi_device *spi)
334 regulator_disable(st->reg); 334 regulator_disable(st->reg);
335 regulator_put(st->reg); 335 regulator_put(st->reg);
336 } 336 }
337 iio_free_device(indio_dev); 337 iio_device_free(indio_dev);
338 338
339 return 0; 339 return 0;
340} 340}
diff --git a/drivers/staging/iio/dds/ad9832.h b/drivers/staging/iio/frequency/ad9832.h
index c5b701f8aabb..c5b701f8aabb 100644
--- a/drivers/staging/iio/dds/ad9832.h
+++ b/drivers/staging/iio/frequency/ad9832.h
diff --git a/drivers/staging/iio/dds/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 38a2de08626f..1b2dc741d2ce 100644
--- a/drivers/staging/iio/dds/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -19,8 +19,8 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <asm/div64.h> 20#include <asm/div64.h>
21 21
22#include "../iio.h" 22#include <linux/iio/iio.h>
23#include "../sysfs.h" 23#include <linux/iio/sysfs.h>
24#include "dds.h" 24#include "dds.h"
25 25
26#include "ad9834.h" 26#include "ad9834.h"
@@ -66,7 +66,7 @@ static ssize_t ad9834_write(struct device *dev,
66 const char *buf, 66 const char *buf,
67 size_t len) 67 size_t len)
68{ 68{
69 struct iio_dev *indio_dev = dev_get_drvdata(dev); 69 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
70 struct ad9834_state *st = iio_priv(indio_dev); 70 struct ad9834_state *st = iio_priv(indio_dev);
71 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 71 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
72 int ret; 72 int ret;
@@ -145,7 +145,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
145 const char *buf, 145 const char *buf,
146 size_t len) 146 size_t len)
147{ 147{
148 struct iio_dev *indio_dev = dev_get_drvdata(dev); 148 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
149 struct ad9834_state *st = iio_priv(indio_dev); 149 struct ad9834_state *st = iio_priv(indio_dev);
150 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 150 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
151 int ret = 0; 151 int ret = 0;
@@ -203,7 +203,7 @@ static ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
203 struct device_attribute *attr, 203 struct device_attribute *attr,
204 char *buf) 204 char *buf)
205{ 205{
206 struct iio_dev *indio_dev = dev_get_drvdata(dev); 206 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
207 struct ad9834_state *st = iio_priv(indio_dev); 207 struct ad9834_state *st = iio_priv(indio_dev);
208 char *str; 208 char *str;
209 209
@@ -218,14 +218,14 @@ static ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
218} 218}
219 219
220 220
221static IIO_DEVICE_ATTR(dds0_out0_wavetype_available, S_IRUGO, 221static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, S_IRUGO,
222 ad9834_show_out0_wavetype_available, NULL, 0); 222 ad9834_show_out0_wavetype_available, NULL, 0);
223 223
224static ssize_t ad9834_show_out1_wavetype_available(struct device *dev, 224static ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
225 struct device_attribute *attr, 225 struct device_attribute *attr,
226 char *buf) 226 char *buf)
227{ 227{
228 struct iio_dev *indio_dev = dev_get_drvdata(dev); 228 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
229 struct ad9834_state *st = iio_priv(indio_dev); 229 struct ad9834_state *st = iio_priv(indio_dev);
230 char *str; 230 char *str;
231 231
@@ -237,7 +237,7 @@ static ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
237 return sprintf(buf, "%s\n", str); 237 return sprintf(buf, "%s\n", str);
238} 238}
239 239
240static IIO_DEVICE_ATTR(dds0_out1_wavetype_available, S_IRUGO, 240static IIO_DEVICE_ATTR(out_altvoltage0_out1_wavetype_available, S_IRUGO,
241 ad9834_show_out1_wavetype_available, NULL, 0); 241 ad9834_show_out1_wavetype_available, NULL, 0);
242 242
243/** 243/**
@@ -263,36 +263,36 @@ static IIO_DEV_ATTR_OUT_WAVETYPE(0, 0, ad9834_store_wavetype, 0);
263static IIO_DEV_ATTR_OUT_WAVETYPE(0, 1, ad9834_store_wavetype, 1); 263static IIO_DEV_ATTR_OUT_WAVETYPE(0, 1, ad9834_store_wavetype, 1);
264 264
265static struct attribute *ad9834_attributes[] = { 265static struct attribute *ad9834_attributes[] = {
266 &iio_dev_attr_dds0_freq0.dev_attr.attr, 266 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
267 &iio_dev_attr_dds0_freq1.dev_attr.attr, 267 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
268 &iio_const_attr_dds0_freq_scale.dev_attr.attr, 268 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
269 &iio_dev_attr_dds0_phase0.dev_attr.attr, 269 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
270 &iio_dev_attr_dds0_phase1.dev_attr.attr, 270 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
271 &iio_const_attr_dds0_phase_scale.dev_attr.attr, 271 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
272 &iio_dev_attr_dds0_pincontrol_en.dev_attr.attr, 272 &iio_dev_attr_out_altvoltage0_pincontrol_en.dev_attr.attr,
273 &iio_dev_attr_dds0_freqsymbol.dev_attr.attr, 273 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
274 &iio_dev_attr_dds0_phasesymbol.dev_attr.attr, 274 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
275 &iio_dev_attr_dds0_out_enable.dev_attr.attr, 275 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
276 &iio_dev_attr_dds0_out1_enable.dev_attr.attr, 276 &iio_dev_attr_out_altvoltage0_out1_enable.dev_attr.attr,
277 &iio_dev_attr_dds0_out0_wavetype.dev_attr.attr, 277 &iio_dev_attr_out_altvoltage0_out0_wavetype.dev_attr.attr,
278 &iio_dev_attr_dds0_out1_wavetype.dev_attr.attr, 278 &iio_dev_attr_out_altvoltage0_out1_wavetype.dev_attr.attr,
279 &iio_dev_attr_dds0_out0_wavetype_available.dev_attr.attr, 279 &iio_dev_attr_out_altvoltage0_out0_wavetype_available.dev_attr.attr,
280 &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr, 280 &iio_dev_attr_out_altvoltage0_out1_wavetype_available.dev_attr.attr,
281 NULL, 281 NULL,
282}; 282};
283 283
284static struct attribute *ad9833_attributes[] = { 284static struct attribute *ad9833_attributes[] = {
285 &iio_dev_attr_dds0_freq0.dev_attr.attr, 285 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
286 &iio_dev_attr_dds0_freq1.dev_attr.attr, 286 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
287 &iio_const_attr_dds0_freq_scale.dev_attr.attr, 287 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
288 &iio_dev_attr_dds0_phase0.dev_attr.attr, 288 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
289 &iio_dev_attr_dds0_phase1.dev_attr.attr, 289 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
290 &iio_const_attr_dds0_phase_scale.dev_attr.attr, 290 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
291 &iio_dev_attr_dds0_freqsymbol.dev_attr.attr, 291 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
292 &iio_dev_attr_dds0_phasesymbol.dev_attr.attr, 292 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
293 &iio_dev_attr_dds0_out_enable.dev_attr.attr, 293 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
294 &iio_dev_attr_dds0_out0_wavetype.dev_attr.attr, 294 &iio_dev_attr_out_altvoltage0_out0_wavetype.dev_attr.attr,
295 &iio_dev_attr_dds0_out0_wavetype_available.dev_attr.attr, 295 &iio_dev_attr_out_altvoltage0_out0_wavetype_available.dev_attr.attr,
296 NULL, 296 NULL,
297}; 297};
298 298
@@ -334,7 +334,7 @@ static int __devinit ad9834_probe(struct spi_device *spi)
334 goto error_put_reg; 334 goto error_put_reg;
335 } 335 }
336 336
337 indio_dev = iio_allocate_device(sizeof(*st)); 337 indio_dev = iio_device_alloc(sizeof(*st));
338 if (indio_dev == NULL) { 338 if (indio_dev == NULL) {
339 ret = -ENOMEM; 339 ret = -ENOMEM;
340 goto error_disable_reg; 340 goto error_disable_reg;
@@ -414,7 +414,7 @@ static int __devinit ad9834_probe(struct spi_device *spi)
414 return 0; 414 return 0;
415 415
416error_free_device: 416error_free_device:
417 iio_free_device(indio_dev); 417 iio_device_free(indio_dev);
418error_disable_reg: 418error_disable_reg:
419 if (!IS_ERR(reg)) 419 if (!IS_ERR(reg))
420 regulator_disable(reg); 420 regulator_disable(reg);
@@ -434,7 +434,7 @@ static int __devexit ad9834_remove(struct spi_device *spi)
434 regulator_disable(st->reg); 434 regulator_disable(st->reg);
435 regulator_put(st->reg); 435 regulator_put(st->reg);
436 } 436 }
437 iio_free_device(indio_dev); 437 iio_device_free(indio_dev);
438 438
439 return 0; 439 return 0;
440} 440}
diff --git a/drivers/staging/iio/dds/ad9834.h b/drivers/staging/iio/frequency/ad9834.h
index ed5ed8d0007f..ed5ed8d0007f 100644
--- a/drivers/staging/iio/dds/ad9834.h
+++ b/drivers/staging/iio/frequency/ad9834.h
diff --git a/drivers/staging/iio/dds/ad9850.c b/drivers/staging/iio/frequency/ad9850.c
index f4f731bb2191..74abee054ac0 100644
--- a/drivers/staging/iio/dds/ad9850.c
+++ b/drivers/staging/iio/frequency/ad9850.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define DRV_NAME "ad9850" 22#define DRV_NAME "ad9850"
23 23
@@ -43,7 +43,7 @@ static ssize_t ad9850_set_parameter(struct device *dev,
43 struct spi_transfer xfer; 43 struct spi_transfer xfer;
44 int ret; 44 int ret;
45 struct ad9850_config *config = (struct ad9850_config *)buf; 45 struct ad9850_config *config = (struct ad9850_config *)buf;
46 struct iio_dev *idev = dev_get_drvdata(dev); 46 struct iio_dev *idev = dev_to_iio_dev(dev);
47 struct ad9850_state *st = iio_priv(idev); 47 struct ad9850_state *st = iio_priv(idev);
48 48
49 xfer.len = len; 49 xfer.len = len;
@@ -83,7 +83,7 @@ static int __devinit ad9850_probe(struct spi_device *spi)
83 struct iio_dev *idev; 83 struct iio_dev *idev;
84 int ret = 0; 84 int ret = 0;
85 85
86 idev = iio_allocate_device(sizeof(*st)); 86 idev = iio_device_alloc(sizeof(*st));
87 if (idev == NULL) { 87 if (idev == NULL) {
88 ret = -ENOMEM; 88 ret = -ENOMEM;
89 goto error_ret; 89 goto error_ret;
@@ -108,7 +108,7 @@ static int __devinit ad9850_probe(struct spi_device *spi)
108 return 0; 108 return 0;
109 109
110error_free_dev: 110error_free_dev:
111 iio_free_device(idev); 111 iio_device_free(idev);
112error_ret: 112error_ret:
113 return ret; 113 return ret;
114} 114}
@@ -116,7 +116,7 @@ error_ret:
116static int __devexit ad9850_remove(struct spi_device *spi) 116static int __devexit ad9850_remove(struct spi_device *spi)
117{ 117{
118 iio_device_unregister(spi_get_drvdata(spi)); 118 iio_device_unregister(spi_get_drvdata(spi));
119 iio_free_device(spi_get_drvdata(spi)); 119 iio_device_free(spi_get_drvdata(spi));
120 120
121 return 0; 121 return 0;
122} 122}
diff --git a/drivers/staging/iio/dds/ad9852.c b/drivers/staging/iio/frequency/ad9852.c
index 554266c615a8..fd9d14a413a5 100644
--- a/drivers/staging/iio/dds/ad9852.c
+++ b/drivers/staging/iio/frequency/ad9852.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define DRV_NAME "ad9852" 22#define DRV_NAME "ad9852"
23 23
@@ -71,7 +71,7 @@ static ssize_t ad9852_set_parameter(struct device *dev,
71 struct spi_transfer xfer; 71 struct spi_transfer xfer;
72 int ret; 72 int ret;
73 struct ad9852_config *config = (struct ad9852_config *)buf; 73 struct ad9852_config *config = (struct ad9852_config *)buf;
74 struct iio_dev *idev = dev_get_drvdata(dev); 74 struct iio_dev *idev = dev_to_iio_dev(dev);
75 struct ad9852_state *st = iio_priv(idev); 75 struct ad9852_state *st = iio_priv(idev);
76 76
77 xfer.len = 3; 77 xfer.len = 3;
@@ -232,7 +232,7 @@ static int __devinit ad9852_probe(struct spi_device *spi)
232 struct iio_dev *idev; 232 struct iio_dev *idev;
233 int ret = 0; 233 int ret = 0;
234 234
235 idev = iio_allocate_device(sizeof(*st)); 235 idev = iio_device_alloc(sizeof(*st));
236 if (idev == NULL) { 236 if (idev == NULL) {
237 ret = -ENOMEM; 237 ret = -ENOMEM;
238 goto error_ret; 238 goto error_ret;
@@ -258,7 +258,7 @@ static int __devinit ad9852_probe(struct spi_device *spi)
258 return 0; 258 return 0;
259 259
260error_free_dev: 260error_free_dev:
261 iio_free_device(idev); 261 iio_device_free(idev);
262 262
263error_ret: 263error_ret:
264 return ret; 264 return ret;
@@ -267,7 +267,7 @@ error_ret:
267static int __devexit ad9852_remove(struct spi_device *spi) 267static int __devexit ad9852_remove(struct spi_device *spi)
268{ 268{
269 iio_device_unregister(spi_get_drvdata(spi)); 269 iio_device_unregister(spi_get_drvdata(spi));
270 iio_free_device(spi_get_drvdata(spi)); 270 iio_device_free(spi_get_drvdata(spi));
271 271
272 return 0; 272 return 0;
273} 273}
diff --git a/drivers/staging/iio/dds/ad9910.c b/drivers/staging/iio/frequency/ad9910.c
index 3985766d6f87..5a7ba305b75a 100644
--- a/drivers/staging/iio/dds/ad9910.c
+++ b/drivers/staging/iio/frequency/ad9910.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define DRV_NAME "ad9910" 22#define DRV_NAME "ad9910"
23 23
@@ -123,7 +123,7 @@ static ssize_t ad9910_set_parameter(struct device *dev,
123 struct spi_transfer xfer; 123 struct spi_transfer xfer;
124 int ret; 124 int ret;
125 struct ad9910_config *config = (struct ad9910_config *)buf; 125 struct ad9910_config *config = (struct ad9910_config *)buf;
126 struct iio_dev *idev = dev_get_drvdata(dev); 126 struct iio_dev *idev = dev_to_iio_dev(dev);
127 struct ad9910_state *st = iio_priv(idev); 127 struct ad9910_state *st = iio_priv(idev);
128 128
129 xfer.len = 5; 129 xfer.len = 5;
@@ -367,7 +367,7 @@ static int __devinit ad9910_probe(struct spi_device *spi)
367 struct iio_dev *idev; 367 struct iio_dev *idev;
368 int ret = 0; 368 int ret = 0;
369 369
370 idev = iio_allocate_device(sizeof(*st)); 370 idev = iio_device_alloc(sizeof(*st));
371 if (idev == NULL) { 371 if (idev == NULL) {
372 ret = -ENOMEM; 372 ret = -ENOMEM;
373 goto error_ret; 373 goto error_ret;
@@ -392,7 +392,7 @@ static int __devinit ad9910_probe(struct spi_device *spi)
392 return 0; 392 return 0;
393 393
394error_free_dev: 394error_free_dev:
395 iio_free_device(idev); 395 iio_device_free(idev);
396error_ret: 396error_ret:
397 return ret; 397 return ret;
398} 398}
@@ -400,7 +400,7 @@ error_ret:
400static int __devexit ad9910_remove(struct spi_device *spi) 400static int __devexit ad9910_remove(struct spi_device *spi)
401{ 401{
402 iio_device_unregister(spi_get_drvdata(spi)); 402 iio_device_unregister(spi_get_drvdata(spi));
403 iio_free_device(spi_get_drvdata(spi)); 403 iio_device_free(spi_get_drvdata(spi));
404 404
405 return 0; 405 return 0;
406} 406}
diff --git a/drivers/staging/iio/dds/ad9951.c b/drivers/staging/iio/frequency/ad9951.c
index 4d150048002a..ba6f49ff09ae 100644
--- a/drivers/staging/iio/dds/ad9951.c
+++ b/drivers/staging/iio/frequency/ad9951.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define DRV_NAME "ad9951" 22#define DRV_NAME "ad9951"
23 23
@@ -64,7 +64,7 @@ static ssize_t ad9951_set_parameter(struct device *dev,
64 struct spi_transfer xfer; 64 struct spi_transfer xfer;
65 int ret; 65 int ret;
66 struct ad9951_config *config = (struct ad9951_config *)buf; 66 struct ad9951_config *config = (struct ad9951_config *)buf;
67 struct iio_dev *idev = dev_get_drvdata(dev); 67 struct iio_dev *idev = dev_to_iio_dev(dev);
68 struct ad9951_state *st = iio_priv(idev); 68 struct ad9951_state *st = iio_priv(idev);
69 69
70 xfer.len = 3; 70 xfer.len = 3;
@@ -176,7 +176,7 @@ static int __devinit ad9951_probe(struct spi_device *spi)
176 struct iio_dev *idev; 176 struct iio_dev *idev;
177 int ret = 0; 177 int ret = 0;
178 178
179 idev = iio_allocate_device(sizeof(*st)); 179 idev = iio_device_alloc(sizeof(*st));
180 if (idev == NULL) { 180 if (idev == NULL) {
181 ret = -ENOMEM; 181 ret = -ENOMEM;
182 goto error_ret; 182 goto error_ret;
@@ -202,7 +202,7 @@ static int __devinit ad9951_probe(struct spi_device *spi)
202 return 0; 202 return 0;
203 203
204error_free_dev: 204error_free_dev:
205 iio_free_device(idev); 205 iio_device_free(idev);
206 206
207error_ret: 207error_ret:
208 return ret; 208 return ret;
@@ -211,7 +211,7 @@ error_ret:
211static int __devexit ad9951_remove(struct spi_device *spi) 211static int __devexit ad9951_remove(struct spi_device *spi)
212{ 212{
213 iio_device_unregister(spi_get_drvdata(spi)); 213 iio_device_unregister(spi_get_drvdata(spi));
214 iio_free_device(spi_get_drvdata(spi)); 214 iio_device_free(spi_get_drvdata(spi));
215 215
216 return 0; 216 return 0;
217} 217}
diff --git a/drivers/staging/iio/frequency/dds.h b/drivers/staging/iio/frequency/dds.h
new file mode 100644
index 000000000000..c3342f6e052b
--- /dev/null
+++ b/drivers/staging/iio/frequency/dds.h
@@ -0,0 +1,110 @@
1/*
2 * dds.h - sysfs attributes associated with DDS devices
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9/**
10 * /sys/bus/iio/devices/.../out_altvoltageX_frequencyY
11 */
12
13#define IIO_DEV_ATTR_FREQ(_channel, _num, _mode, _show, _store, _addr) \
14 IIO_DEVICE_ATTR(out_altvoltage##_channel##_frequency##_num, \
15 _mode, _show, _store, _addr)
16
17/**
18 * /sys/bus/iio/devices/.../out_altvoltageX_frequencyY_scale
19 */
20
21#define IIO_CONST_ATTR_FREQ_SCALE(_channel, _string) \
22 IIO_CONST_ATTR(out_altvoltage##_channel##_frequency_scale, _string)
23
24/**
25 * /sys/bus/iio/devices/.../out_altvoltageX_frequencysymbol
26 */
27
28#define IIO_DEV_ATTR_FREQSYMBOL(_channel, _mode, _show, _store, _addr) \
29 IIO_DEVICE_ATTR(out_altvoltage##_channel##_frequencysymbol, \
30 _mode, _show, _store, _addr);
31
32/**
33 * /sys/bus/iio/devices/.../out_altvoltageX_phaseY
34 */
35
36#define IIO_DEV_ATTR_PHASE(_channel, _num, _mode, _show, _store, _addr) \
37 IIO_DEVICE_ATTR(out_altvoltage##_channel##_phase##_num, \
38 _mode, _show, _store, _addr)
39
40/**
41 * /sys/bus/iio/devices/.../out_altvoltageX_phaseY_scale
42 */
43
44#define IIO_CONST_ATTR_PHASE_SCALE(_channel, _string) \
45 IIO_CONST_ATTR(out_altvoltage##_channel##_phase_scale, _string)
46
47/**
48 * /sys/bus/iio/devices/.../out_altvoltageX_phasesymbol
49 */
50
51#define IIO_DEV_ATTR_PHASESYMBOL(_channel, _mode, _show, _store, _addr) \
52 IIO_DEVICE_ATTR(out_altvoltage##_channel##_phasesymbol, \
53 _mode, _show, _store, _addr);
54
55/**
56 * /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_en
57 */
58
59#define IIO_DEV_ATTR_PINCONTROL_EN(_channel, _mode, _show, _store, _addr)\
60 IIO_DEVICE_ATTR(out_altvoltage##_channel##_pincontrol_en, \
61 _mode, _show, _store, _addr);
62
63/**
64 * /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_frequency_en
65 */
66
67#define IIO_DEV_ATTR_PINCONTROL_FREQ_EN(_channel, _mode, _show, _store, _addr)\
68 IIO_DEVICE_ATTR(out_altvoltage##_channel##_pincontrol_frequency_en,\
69 _mode, _show, _store, _addr);
70
71/**
72 * /sys/bus/iio/devices/.../out_altvoltageX_pincontrol_phase_en
73 */
74
75#define IIO_DEV_ATTR_PINCONTROL_PHASE_EN(_channel, _mode, _show, _store, _addr)\
76 IIO_DEVICE_ATTR(out_altvoltage##_channel##_pincontrol_phase_en, \
77 _mode, _show, _store, _addr);
78
79/**
80 * /sys/bus/iio/devices/.../out_altvoltageX_out_enable
81 */
82
83#define IIO_DEV_ATTR_OUT_ENABLE(_channel, _mode, _show, _store, _addr) \
84 IIO_DEVICE_ATTR(out_altvoltage##_channel##_out_enable, \
85 _mode, _show, _store, _addr);
86
87/**
88 * /sys/bus/iio/devices/.../out_altvoltageX_outY_enable
89 */
90
91#define IIO_DEV_ATTR_OUTY_ENABLE(_channel, _output, \
92 _mode, _show, _store, _addr) \
93 IIO_DEVICE_ATTR(out_altvoltage##_channel##_out##_output##_enable,\
94 _mode, _show, _store, _addr);
95
96/**
97 * /sys/bus/iio/devices/.../out_altvoltageX_outY_wavetype
98 */
99
100#define IIO_DEV_ATTR_OUT_WAVETYPE(_channel, _output, _store, _addr) \
101 IIO_DEVICE_ATTR(out_altvoltage##_channel##_out##_output##_wavetype,\
102 S_IWUSR, NULL, _store, _addr);
103
104/**
105 * /sys/bus/iio/devices/.../out_altvoltageX_outY_wavetype_available
106 */
107
108#define IIO_CONST_ATTR_OUT_WAVETYPES_AVAILABLE(_channel, _output, _modes)\
109 IIO_CONST_ATTR( \
110 out_altvoltage##_channel##_out##_output##_wavetype_available, _modes);
diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c
index 02cc23420b90..9931e2060e1f 100644
--- a/drivers/staging/iio/gyro/adis16060_core.c
+++ b/drivers/staging/iio/gyro/adis16060_core.c
@@ -15,8 +15,8 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../sysfs.h" 19#include <linux/iio/sysfs.h>
20 20
21#define ADIS16060_GYRO 0x20 /* Measure Angular Rate (Gyro) */ 21#define ADIS16060_GYRO 0x20 /* Measure Angular Rate (Gyro) */
22#define ADIS16060_TEMP_OUT 0x10 /* Measure Temperature */ 22#define ADIS16060_TEMP_OUT 0x10 /* Measure Temperature */
@@ -85,7 +85,7 @@ static int adis16060_read_raw(struct iio_dev *indio_dev,
85 int ret; 85 int ret;
86 86
87 switch (mask) { 87 switch (mask) {
88 case 0: 88 case IIO_CHAN_INFO_RAW:
89 /* Take the iio_dev status lock */ 89 /* Take the iio_dev status lock */
90 mutex_lock(&indio_dev->mlock); 90 mutex_lock(&indio_dev->mlock);
91 ret = adis16060_spi_write(indio_dev, chan->address); 91 ret = adis16060_spi_write(indio_dev, chan->address);
@@ -120,22 +120,26 @@ static const struct iio_chan_spec adis16060_channels[] = {
120 .type = IIO_ANGL_VEL, 120 .type = IIO_ANGL_VEL,
121 .modified = 1, 121 .modified = 1,
122 .channel2 = IIO_MOD_Z, 122 .channel2 = IIO_MOD_Z,
123 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
123 .address = ADIS16060_GYRO, 124 .address = ADIS16060_GYRO,
124 }, { 125 }, {
125 .type = IIO_VOLTAGE, 126 .type = IIO_VOLTAGE,
126 .indexed = 1, 127 .indexed = 1,
127 .channel = 0, 128 .channel = 0,
129 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
128 .address = ADIS16060_AIN1, 130 .address = ADIS16060_AIN1,
129 }, { 131 }, {
130 .type = IIO_VOLTAGE, 132 .type = IIO_VOLTAGE,
131 .indexed = 1, 133 .indexed = 1,
132 .channel = 1, 134 .channel = 1,
135 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
133 .address = ADIS16060_AIN2, 136 .address = ADIS16060_AIN2,
134 }, { 137 }, {
135 .type = IIO_TEMP, 138 .type = IIO_TEMP,
136 .indexed = 1, 139 .indexed = 1,
137 .channel = 0, 140 .channel = 0,
138 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 141 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
142 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
139 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 143 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
140 .address = ADIS16060_TEMP_OUT, 144 .address = ADIS16060_TEMP_OUT,
141 } 145 }
@@ -148,7 +152,7 @@ static int __devinit adis16060_r_probe(struct spi_device *spi)
148 struct iio_dev *indio_dev; 152 struct iio_dev *indio_dev;
149 153
150 /* setup the industrialio driver allocated elements */ 154 /* setup the industrialio driver allocated elements */
151 indio_dev = iio_allocate_device(sizeof(*st)); 155 indio_dev = iio_device_alloc(sizeof(*st));
152 if (indio_dev == NULL) { 156 if (indio_dev == NULL) {
153 ret = -ENOMEM; 157 ret = -ENOMEM;
154 goto error_ret; 158 goto error_ret;
@@ -174,7 +178,7 @@ static int __devinit adis16060_r_probe(struct spi_device *spi)
174 return 0; 178 return 0;
175 179
176error_free_dev: 180error_free_dev:
177 iio_free_device(indio_dev); 181 iio_device_free(indio_dev);
178error_ret: 182error_ret:
179 return ret; 183 return ret;
180} 184}
@@ -183,7 +187,7 @@ error_ret:
183static int adis16060_r_remove(struct spi_device *spi) 187static int adis16060_r_remove(struct spi_device *spi)
184{ 188{
185 iio_device_unregister(spi_get_drvdata(spi)); 189 iio_device_unregister(spi_get_drvdata(spi));
186 iio_free_device(spi_get_drvdata(spi)); 190 iio_device_free(spi_get_drvdata(spi));
187 191
188 return 0; 192 return 0;
189} 193}
diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c
index 1815490db8b4..11f1dccd7a0d 100644
--- a/drivers/staging/iio/gyro/adis16080_core.c
+++ b/drivers/staging/iio/gyro/adis16080_core.c
@@ -14,8 +14,8 @@
14#include <linux/sysfs.h> 14#include <linux/sysfs.h>
15#include <linux/module.h> 15#include <linux/module.h>
16 16
17#include "../iio.h" 17#include <linux/iio/iio.h>
18#include "../sysfs.h" 18#include <linux/iio/sysfs.h>
19 19
20#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */ 20#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */
21#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */ 21#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */
@@ -87,7 +87,7 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
87 87
88 mutex_lock(&indio_dev->mlock); 88 mutex_lock(&indio_dev->mlock);
89 switch (mask) { 89 switch (mask) {
90 case 0: 90 case IIO_CHAN_INFO_RAW:
91 ret = adis16080_spi_write(indio_dev, 91 ret = adis16080_spi_write(indio_dev,
92 chan->address | 92 chan->address |
93 ADIS16080_DIN_WRITE); 93 ADIS16080_DIN_WRITE);
@@ -110,21 +110,25 @@ static const struct iio_chan_spec adis16080_channels[] = {
110 .type = IIO_ANGL_VEL, 110 .type = IIO_ANGL_VEL,
111 .modified = 1, 111 .modified = 1,
112 .channel2 = IIO_MOD_Z, 112 .channel2 = IIO_MOD_Z,
113 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
113 .address = ADIS16080_DIN_GYRO, 114 .address = ADIS16080_DIN_GYRO,
114 }, { 115 }, {
115 .type = IIO_VOLTAGE, 116 .type = IIO_VOLTAGE,
116 .indexed = 1, 117 .indexed = 1,
117 .channel = 0, 118 .channel = 0,
119 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
118 .address = ADIS16080_DIN_AIN1, 120 .address = ADIS16080_DIN_AIN1,
119 }, { 121 }, {
120 .type = IIO_VOLTAGE, 122 .type = IIO_VOLTAGE,
121 .indexed = 1, 123 .indexed = 1,
122 .channel = 1, 124 .channel = 1,
125 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
123 .address = ADIS16080_DIN_AIN2, 126 .address = ADIS16080_DIN_AIN2,
124 }, { 127 }, {
125 .type = IIO_TEMP, 128 .type = IIO_TEMP,
126 .indexed = 1, 129 .indexed = 1,
127 .channel = 0, 130 .channel = 0,
131 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
128 .address = ADIS16080_DIN_TEMP, 132 .address = ADIS16080_DIN_TEMP,
129 } 133 }
130}; 134};
@@ -141,7 +145,7 @@ static int __devinit adis16080_probe(struct spi_device *spi)
141 struct iio_dev *indio_dev; 145 struct iio_dev *indio_dev;
142 146
143 /* setup the industrialio driver allocated elements */ 147 /* setup the industrialio driver allocated elements */
144 indio_dev = iio_allocate_device(sizeof(*st)); 148 indio_dev = iio_device_alloc(sizeof(*st));
145 if (indio_dev == NULL) { 149 if (indio_dev == NULL) {
146 ret = -ENOMEM; 150 ret = -ENOMEM;
147 goto error_ret; 151 goto error_ret;
@@ -167,7 +171,7 @@ static int __devinit adis16080_probe(struct spi_device *spi)
167 return 0; 171 return 0;
168 172
169error_free_dev: 173error_free_dev:
170 iio_free_device(indio_dev); 174 iio_device_free(indio_dev);
171error_ret: 175error_ret:
172 return ret; 176 return ret;
173} 177}
@@ -176,7 +180,7 @@ error_ret:
176static int adis16080_remove(struct spi_device *spi) 180static int adis16080_remove(struct spi_device *spi)
177{ 181{
178 iio_device_unregister(spi_get_drvdata(spi)); 182 iio_device_unregister(spi_get_drvdata(spi));
179 iio_free_device(spi_get_drvdata(spi)); 183 iio_device_free(spi_get_drvdata(spi));
180 184
181 return 0; 185 return 0;
182} 186}
diff --git a/drivers/staging/iio/gyro/adis16130_core.c b/drivers/staging/iio/gyro/adis16130_core.c
index 947eb86f05d8..bf61cd0b5bbc 100644
--- a/drivers/staging/iio/gyro/adis16130_core.c
+++ b/drivers/staging/iio/gyro/adis16130_core.c
@@ -16,8 +16,8 @@
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22#define ADIS16130_CON 0x0 22#define ADIS16130_CON 0x0
23#define ADIS16130_CON_RD (1 << 6) 23#define ADIS16130_CON_RD (1 << 6)
@@ -100,11 +100,13 @@ static const struct iio_chan_spec adis16130_channels[] = {
100 .type = IIO_ANGL_VEL, 100 .type = IIO_ANGL_VEL,
101 .modified = 1, 101 .modified = 1,
102 .channel2 = IIO_MOD_Z, 102 .channel2 = IIO_MOD_Z,
103 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
103 .address = ADIS16130_RATEDATA, 104 .address = ADIS16130_RATEDATA,
104 }, { 105 }, {
105 .type = IIO_TEMP, 106 .type = IIO_TEMP,
106 .indexed = 1, 107 .indexed = 1,
107 .channel = 0, 108 .channel = 0,
109 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
108 .address = ADIS16130_TEMPDATA, 110 .address = ADIS16130_TEMPDATA,
109 } 111 }
110}; 112};
@@ -121,7 +123,7 @@ static int __devinit adis16130_probe(struct spi_device *spi)
121 struct iio_dev *indio_dev; 123 struct iio_dev *indio_dev;
122 124
123 /* setup the industrialio driver allocated elements */ 125 /* setup the industrialio driver allocated elements */
124 indio_dev = iio_allocate_device(sizeof(*st)); 126 indio_dev = iio_device_alloc(sizeof(*st));
125 if (indio_dev == NULL) { 127 if (indio_dev == NULL) {
126 ret = -ENOMEM; 128 ret = -ENOMEM;
127 goto error_ret; 129 goto error_ret;
@@ -145,7 +147,7 @@ static int __devinit adis16130_probe(struct spi_device *spi)
145 return 0; 147 return 0;
146 148
147error_free_dev: 149error_free_dev:
148 iio_free_device(indio_dev); 150 iio_device_free(indio_dev);
149 151
150error_ret: 152error_ret:
151 return ret; 153 return ret;
@@ -155,7 +157,7 @@ error_ret:
155static int adis16130_remove(struct spi_device *spi) 157static int adis16130_remove(struct spi_device *spi)
156{ 158{
157 iio_device_unregister(spi_get_drvdata(spi)); 159 iio_device_unregister(spi_get_drvdata(spi));
158 iio_free_device(spi_get_drvdata(spi)); 160 iio_device_free(spi_get_drvdata(spi));
159 161
160 return 0; 162 return 0;
161} 163}
diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 8f6af47e9559..ec765f955f8d 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -18,9 +18,9 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24 24
25#include "adis16260.h" 25#include "adis16260.h"
26 26
@@ -149,7 +149,7 @@ static ssize_t adis16260_read_frequency_available(struct device *dev,
149 struct device_attribute *attr, 149 struct device_attribute *attr,
150 char *buf) 150 char *buf)
151{ 151{
152 struct iio_dev *indio_dev = dev_get_drvdata(dev); 152 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
153 struct adis16260_state *st = iio_priv(indio_dev); 153 struct adis16260_state *st = iio_priv(indio_dev);
154 if (spi_get_device_id(st->us)->driver_data) 154 if (spi_get_device_id(st->us)->driver_data)
155 return sprintf(buf, "%s\n", "0.129 ~ 256"); 155 return sprintf(buf, "%s\n", "0.129 ~ 256");
@@ -161,7 +161,7 @@ static ssize_t adis16260_read_frequency(struct device *dev,
161 struct device_attribute *attr, 161 struct device_attribute *attr,
162 char *buf) 162 char *buf)
163{ 163{
164 struct iio_dev *indio_dev = dev_get_drvdata(dev); 164 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
165 struct adis16260_state *st = iio_priv(indio_dev); 165 struct adis16260_state *st = iio_priv(indio_dev);
166 int ret, len = 0; 166 int ret, len = 0;
167 u16 t; 167 u16 t;
@@ -186,7 +186,7 @@ static ssize_t adis16260_write_frequency(struct device *dev,
186 const char *buf, 186 const char *buf,
187 size_t len) 187 size_t len)
188{ 188{
189 struct iio_dev *indio_dev = dev_get_drvdata(dev); 189 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
190 struct adis16260_state *st = iio_priv(indio_dev); 190 struct adis16260_state *st = iio_priv(indio_dev);
191 long val; 191 long val;
192 int ret; 192 int ret;
@@ -237,7 +237,7 @@ static ssize_t adis16260_write_reset(struct device *dev,
237 struct device_attribute *attr, 237 struct device_attribute *attr,
238 const char *buf, size_t len) 238 const char *buf, size_t len)
239{ 239{
240 struct iio_dev *indio_dev = dev_get_drvdata(dev); 240 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
241 if (len < 1) 241 if (len < 1)
242 return -EINVAL; 242 return -EINVAL;
243 switch (buf[0]) { 243 switch (buf[0]) {
@@ -389,30 +389,76 @@ enum adis16260_channel {
389}; 389};
390#define ADIS16260_GYRO_CHANNEL_SET(axis, mod) \ 390#define ADIS16260_GYRO_CHANNEL_SET(axis, mod) \
391 struct iio_chan_spec adis16260_channels_##axis[] = { \ 391 struct iio_chan_spec adis16260_channels_##axis[] = { \
392 IIO_CHAN(IIO_ANGL_VEL, 1, 0, 0, NULL, 0, mod, \ 392 { \
393 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ 393 .type = IIO_ANGL_VEL, \
394 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ 394 .modified = 1, \
395 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 395 .channel2 = mod, \
396 gyro, ADIS16260_SCAN_GYRO, \ 396 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
397 IIO_ST('s', 14, 16, 0), 0), \ 397 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
398 IIO_CHAN(IIO_ANGL, 1, 0, 0, NULL, 0, mod, \ 398 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
399 0, \ 399 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
400 angle, ADIS16260_SCAN_ANGL, \ 400 .address = gyro, \
401 IIO_ST('u', 14, 16, 0), 0), \ 401 .scan_index = ADIS16260_SCAN_GYRO, \
402 IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, \ 402 .scan_type = { \
403 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ 403 .sign = 's', \
404 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 404 .realbits = 14, \
405 temp, ADIS16260_SCAN_TEMP, \ 405 .storagebits = 16, \
406 IIO_ST('u', 12, 16, 0), 0), \ 406 }, \
407 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "supply", 0, 0, \ 407 }, { \
408 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 408 .type = IIO_ANGL, \
409 in_supply, ADIS16260_SCAN_SUPPLY, \ 409 .modified = 1, \
410 IIO_ST('u', 12, 16, 0), 0), \ 410 .channel2 = mod, \
411 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 1, 0, \ 411 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
412 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 412 .address = angle, \
413 in_aux, ADIS16260_SCAN_AUX_ADC, \ 413 .scan_index = ADIS16260_SCAN_ANGL, \
414 IIO_ST('u', 12, 16, 0), 0), \ 414 .scan_type = { \
415 IIO_CHAN_SOFT_TIMESTAMP(5) \ 415 .sign = 'u', \
416 .realbits = 14, \
417 .storagebits = 16, \
418 }, \
419 }, { \
420 .type = IIO_TEMP, \
421 .indexed = 1, \
422 .channel = 0, \
423 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
424 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
425 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
426 .address = temp, \
427 .scan_index = ADIS16260_SCAN_TEMP, \
428 .scan_type = { \
429 .sign = 'u', \
430 .realbits = 12, \
431 .storagebits = 16, \
432 }, \
433 }, { \
434 .type = IIO_VOLTAGE, \
435 .indexed = 1, \
436 .channel = 0, \
437 .extend_name = "supply", \
438 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
439 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
440 .address = in_supply, \
441 .scan_index = ADIS16260_SCAN_SUPPLY, \
442 .scan_type = { \
443 .sign = 'u', \
444 .realbits = 12, \
445 .storagebits = 16, \
446 }, \
447 }, { \
448 .type = IIO_VOLTAGE, \
449 .indexed = 1, \
450 .channel = 1, \
451 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
452 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
453 .address = in_aux, \
454 .scan_index = ADIS16260_SCAN_AUX_ADC, \
455 .scan_type = { \
456 .sign = 'u', \
457 .realbits = 12, \
458 .storagebits = 16, \
459 }, \
460 }, \
461 IIO_CHAN_SOFT_TIMESTAMP(5), \
416 } 462 }
417 463
418static const ADIS16260_GYRO_CHANNEL_SET(x, IIO_MOD_X); 464static const ADIS16260_GYRO_CHANNEL_SET(x, IIO_MOD_X);
@@ -440,7 +486,7 @@ static int adis16260_read_raw(struct iio_dev *indio_dev,
440 s16 val16; 486 s16 val16;
441 487
442 switch (mask) { 488 switch (mask) {
443 case 0: 489 case IIO_CHAN_INFO_RAW:
444 mutex_lock(&indio_dev->mlock); 490 mutex_lock(&indio_dev->mlock);
445 addr = adis16260_addresses[chan->address][0]; 491 addr = adis16260_addresses[chan->address][0];
446 ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16); 492 ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16);
@@ -581,7 +627,7 @@ static int __devinit adis16260_probe(struct spi_device *spi)
581 struct iio_dev *indio_dev; 627 struct iio_dev *indio_dev;
582 628
583 /* setup the industrialio driver allocated elements */ 629 /* setup the industrialio driver allocated elements */
584 indio_dev = iio_allocate_device(sizeof(*st)); 630 indio_dev = iio_device_alloc(sizeof(*st));
585 if (indio_dev == NULL) { 631 if (indio_dev == NULL) {
586 ret = -ENOMEM; 632 ret = -ENOMEM;
587 goto error_ret; 633 goto error_ret;
@@ -666,7 +712,7 @@ error_uninitialize_ring:
666error_unreg_ring_funcs: 712error_unreg_ring_funcs:
667 adis16260_unconfigure_ring(indio_dev); 713 adis16260_unconfigure_ring(indio_dev);
668error_free_dev: 714error_free_dev:
669 iio_free_device(indio_dev); 715 iio_device_free(indio_dev);
670error_ret: 716error_ret:
671 return ret; 717 return ret;
672} 718}
@@ -687,7 +733,7 @@ static int adis16260_remove(struct spi_device *spi)
687 adis16260_remove_trigger(indio_dev); 733 adis16260_remove_trigger(indio_dev);
688 iio_buffer_unregister(indio_dev); 734 iio_buffer_unregister(indio_dev);
689 adis16260_unconfigure_ring(indio_dev); 735 adis16260_unconfigure_ring(indio_dev);
690 iio_free_device(indio_dev); 736 iio_device_free(indio_dev);
691 737
692err_ret: 738err_ret:
693 return ret; 739 return ret;
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 711f15122a08..0fe2d9dfb6cd 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -5,20 +5,19 @@
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7 7
8#include "../iio.h" 8#include <linux/iio/iio.h>
9#include "../ring_sw.h" 9#include "../ring_sw.h"
10#include "../trigger_consumer.h" 10#include <linux/iio/trigger_consumer.h>
11#include "adis16260.h" 11#include "adis16260.h"
12 12
13/** 13/**
14 * adis16260_read_ring_data() read data registers which will be placed into ring 14 * adis16260_read_ring_data() read data registers which will be placed into ring
15 * @dev: device associated with child of actual device (iio_dev or iio_trig) 15 * @indio_dev: the IIO device
16 * @rx: somewhere to pass back the value read 16 * @rx: somewhere to pass back the value read
17 **/ 17 **/
18static int adis16260_read_ring_data(struct device *dev, u8 *rx) 18static int adis16260_read_ring_data(struct iio_dev *indio_dev, u8 *rx)
19{ 19{
20 struct spi_message msg; 20 struct spi_message msg;
21 struct iio_dev *indio_dev = dev_get_drvdata(dev);
22 struct adis16260_state *st = iio_priv(indio_dev); 21 struct adis16260_state *st = iio_priv(indio_dev);
23 struct spi_transfer xfers[ADIS16260_OUTPUTS + 1]; 22 struct spi_transfer xfers[ADIS16260_OUTPUTS + 1];
24 int ret; 23 int ret;
@@ -66,22 +65,21 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
66 struct iio_buffer *ring = indio_dev->buffer; 65 struct iio_buffer *ring = indio_dev->buffer;
67 int i = 0; 66 int i = 0;
68 s16 *data; 67 s16 *data;
69 size_t datasize = ring->access->get_bytes_per_datum(ring);
70 68
71 data = kmalloc(datasize , GFP_KERNEL); 69 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
72 if (data == NULL) { 70 if (data == NULL) {
73 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 71 dev_err(&st->us->dev, "memory alloc failed in ring bh");
74 return -ENOMEM; 72 return -ENOMEM;
75 } 73 }
76 74
77 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && 75 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) &&
78 adis16260_read_ring_data(&indio_dev->dev, st->rx) >= 0) 76 adis16260_read_ring_data(indio_dev, st->rx) >= 0)
79 for (; i < bitmap_weight(indio_dev->active_scan_mask, 77 for (; i < bitmap_weight(indio_dev->active_scan_mask,
80 indio_dev->masklength); i++) 78 indio_dev->masklength); i++)
81 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); 79 data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
82 80
83 /* Guaranteed to be aligned with 8 byte boundary */ 81 /* Guaranteed to be aligned with 8 byte boundary */
84 if (ring->scan_timestamp) 82 if (indio_dev->scan_timestamp)
85 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; 83 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
86 84
87 ring->access->store_to(ring, (u8 *)data, pf->timestamp); 85 ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/gyro/adis16260_trigger.c b/drivers/staging/iio/gyro/adis16260_trigger.c
index 8299cd18d705..034559e4d5b9 100644
--- a/drivers/staging/iio/gyro/adis16260_trigger.c
+++ b/drivers/staging/iio/gyro/adis16260_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16260.h" 8#include "adis16260.h"
9 9
10/** 10/**
@@ -29,7 +29,7 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev)
29 int ret; 29 int ret;
30 struct adis16260_state *st = iio_priv(indio_dev); 30 struct adis16260_state *st = iio_priv(indio_dev);
31 31
32 st->trig = iio_allocate_trigger("%s-dev%d", 32 st->trig = iio_trigger_alloc("%s-dev%d",
33 spi_get_device_id(st->us)->name, 33 spi_get_device_id(st->us)->name,
34 indio_dev->id); 34 indio_dev->id);
35 if (st->trig == NULL) { 35 if (st->trig == NULL) {
@@ -60,7 +60,7 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev)
60error_free_irq: 60error_free_irq:
61 free_irq(st->us->irq, st->trig); 61 free_irq(st->us->irq, st->trig);
62error_free_trig: 62error_free_trig:
63 iio_free_trigger(st->trig); 63 iio_trigger_free(st->trig);
64error_ret: 64error_ret:
65 return ret; 65 return ret;
66} 66}
@@ -71,5 +71,5 @@ void adis16260_remove_trigger(struct iio_dev *indio_dev)
71 71
72 iio_trigger_unregister(st->trig); 72 iio_trigger_unregister(st->trig);
73 free_irq(st->us->irq, st->trig); 73 free_irq(st->us->irq, st->trig);
74 iio_free_trigger(st->trig); 74 iio_trigger_free(st->trig);
75} 75}
diff --git a/drivers/staging/iio/gyro/adxrs450.h b/drivers/staging/iio/gyro/adxrs450.h
index af0c870100b6..f8cf21f02943 100644
--- a/drivers/staging/iio/gyro/adxrs450.h
+++ b/drivers/staging/iio/gyro/adxrs450.h
@@ -49,7 +49,7 @@ enum {
49 * @us: actual spi_device 49 * @us: actual spi_device
50 * @buf_lock: mutex to protect tx and rx 50 * @buf_lock: mutex to protect tx and rx
51 * @tx: transmit buffer 51 * @tx: transmit buffer
52 * @rx: recieve buffer 52 * @rx: receive buffer
53 **/ 53 **/
54struct adxrs450_state { 54struct adxrs450_state {
55 struct spi_device *us; 55 struct spi_device *us;
diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c
index 15e2496f70c8..6513119b1e90 100644
--- a/drivers/staging/iio/gyro/adxrs450_core.c
+++ b/drivers/staging/iio/gyro/adxrs450_core.c
@@ -18,8 +18,8 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23 23
24#include "adxrs450.h" 24#include "adxrs450.h"
25 25
@@ -265,7 +265,7 @@ static int adxrs450_read_raw(struct iio_dev *indio_dev,
265 s16 t; 265 s16 t;
266 266
267 switch (mask) { 267 switch (mask) {
268 case 0: 268 case IIO_CHAN_INFO_RAW:
269 switch (chan->type) { 269 switch (chan->type) {
270 case IIO_ANGL_VEL: 270 case IIO_ANGL_VEL:
271 ret = adxrs450_spi_sensor_data(indio_dev, &t); 271 ret = adxrs450_spi_sensor_data(indio_dev, &t);
@@ -329,14 +329,16 @@ static const struct iio_chan_spec adxrs450_channels[2][2] = {
329 .type = IIO_ANGL_VEL, 329 .type = IIO_ANGL_VEL,
330 .modified = 1, 330 .modified = 1,
331 .channel2 = IIO_MOD_Z, 331 .channel2 = IIO_MOD_Z,
332 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 332 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
333 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
333 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT | 334 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT |
334 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 335 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
335 }, { 336 }, {
336 .type = IIO_TEMP, 337 .type = IIO_TEMP,
337 .indexed = 1, 338 .indexed = 1,
338 .channel = 0, 339 .channel = 0,
339 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 340 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
341 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
340 } 342 }
341 }, 343 },
342 [ID_ADXRS453] = { 344 [ID_ADXRS453] = {
@@ -344,13 +346,15 @@ static const struct iio_chan_spec adxrs450_channels[2][2] = {
344 .type = IIO_ANGL_VEL, 346 .type = IIO_ANGL_VEL,
345 .modified = 1, 347 .modified = 1,
346 .channel2 = IIO_MOD_Z, 348 .channel2 = IIO_MOD_Z,
347 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 349 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
350 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
348 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT, 351 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT,
349 }, { 352 }, {
350 .type = IIO_TEMP, 353 .type = IIO_TEMP,
351 .indexed = 1, 354 .indexed = 1,
352 .channel = 0, 355 .channel = 0,
353 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 356 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
357 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
354 } 358 }
355 }, 359 },
356}; 360};
@@ -368,7 +372,7 @@ static int __devinit adxrs450_probe(struct spi_device *spi)
368 struct iio_dev *indio_dev; 372 struct iio_dev *indio_dev;
369 373
370 /* setup the industrialio driver allocated elements */ 374 /* setup the industrialio driver allocated elements */
371 indio_dev = iio_allocate_device(sizeof(*st)); 375 indio_dev = iio_device_alloc(sizeof(*st));
372 if (indio_dev == NULL) { 376 if (indio_dev == NULL) {
373 ret = -ENOMEM; 377 ret = -ENOMEM;
374 goto error_ret; 378 goto error_ret;
@@ -399,7 +403,7 @@ static int __devinit adxrs450_probe(struct spi_device *spi)
399error_initial: 403error_initial:
400 iio_device_unregister(indio_dev); 404 iio_device_unregister(indio_dev);
401error_free_dev: 405error_free_dev:
402 iio_free_device(indio_dev); 406 iio_device_free(indio_dev);
403 407
404error_ret: 408error_ret:
405 return ret; 409 return ret;
@@ -408,7 +412,7 @@ error_ret:
408static int adxrs450_remove(struct spi_device *spi) 412static int adxrs450_remove(struct spi_device *spi)
409{ 413{
410 iio_device_unregister(spi_get_drvdata(spi)); 414 iio_device_unregister(spi_get_drvdata(spi));
411 iio_free_device(spi_get_drvdata(spi)); 415 iio_device_free(spi_get_drvdata(spi));
412 416
413 return 0; 417 return 0;
414} 418}
diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
index f39f346bf04f..0cd4fe916bf9 100644
--- a/drivers/staging/iio/iio_dummy_evgen.c
+++ b/drivers/staging/iio/iio_dummy_evgen.c
@@ -22,8 +22,8 @@
22#include <linux/sysfs.h> 22#include <linux/sysfs.h>
23 23
24#include "iio_dummy_evgen.h" 24#include "iio_dummy_evgen.h"
25#include "iio.h" 25#include <linux/iio/iio.h>
26#include "sysfs.h" 26#include <linux/iio/sysfs.h>
27 27
28/* Fiddly bit of faking and irq without hardware */ 28/* Fiddly bit of faking and irq without hardware */
29#define IIO_EVENTGEN_NO 10 29#define IIO_EVENTGEN_NO 10
diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
index a603a5f51f93..b03554fee443 100644
--- a/drivers/staging/iio/iio_hwmon.c
+++ b/drivers/staging/iio/iio_hwmon.c
@@ -14,8 +14,8 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/hwmon.h> 15#include <linux/hwmon.h>
16#include <linux/hwmon-sysfs.h> 16#include <linux/hwmon-sysfs.h>
17#include "consumer.h" 17#include <linux/iio/consumer.h>
18#include "types.h" 18#include <linux/iio/types.h>
19 19
20/** 20/**
21 * struct iio_hwmon_state - device instance state 21 * struct iio_hwmon_state - device instance state
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index e3a94572bb40..310411911ed7 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -19,10 +19,10 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
21 21
22#include "iio.h" 22#include <linux/iio/iio.h>
23#include "sysfs.h" 23#include <linux/iio/sysfs.h>
24#include "events.h" 24#include <linux/iio/events.h>
25#include "buffer.h" 25#include <linux/iio/buffer.h>
26#include "iio_simple_dummy.h" 26#include "iio_simple_dummy.h"
27 27
28/* 28/*
@@ -73,6 +73,12 @@ static struct iio_chan_spec iio_dummy_channels[] = {
73 /* What other information is available? */ 73 /* What other information is available? */
74 .info_mask = 74 .info_mask =
75 /* 75 /*
76 * in_voltage0_raw
77 * Raw (unscaled no bias removal etc) measurement
78 * from the device.
79 */
80 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
81 /*
76 * in_voltage0_offset 82 * in_voltage0_offset
77 * Offset for userspace to apply prior to scale 83 * Offset for userspace to apply prior to scale
78 * when converting to standard units (microvolts) 84 * when converting to standard units (microvolts)
@@ -114,6 +120,12 @@ static struct iio_chan_spec iio_dummy_channels[] = {
114 .channel2 = 2, 120 .channel2 = 2,
115 .info_mask = 121 .info_mask =
116 /* 122 /*
123 * in_voltage1-voltage2_raw
124 * Raw (unscaled no bias removal etc) measurement
125 * from the device.
126 */
127 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
128 /*
117 * in_voltage-voltage_scale 129 * in_voltage-voltage_scale
118 * Shared version of scale - shared by differential 130 * Shared version of scale - shared by differential
119 * input channels of type IIO_VOLTAGE. 131 * input channels of type IIO_VOLTAGE.
@@ -135,6 +147,7 @@ static struct iio_chan_spec iio_dummy_channels[] = {
135 .channel = 3, 147 .channel = 3,
136 .channel2 = 4, 148 .channel2 = 4,
137 .info_mask = 149 .info_mask =
150 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
138 IIO_CHAN_INFO_SCALE_SHARED_BIT, 151 IIO_CHAN_INFO_SCALE_SHARED_BIT,
139 .scan_index = diffvoltage3m4, 152 .scan_index = diffvoltage3m4,
140 .scan_type = { 153 .scan_type = {
@@ -154,6 +167,7 @@ static struct iio_chan_spec iio_dummy_channels[] = {
154 /* Channel 2 is use for modifiers */ 167 /* Channel 2 is use for modifiers */
155 .channel2 = IIO_MOD_X, 168 .channel2 = IIO_MOD_X,
156 .info_mask = 169 .info_mask =
170 IIO_CHAN_INFO_RAW_SEPARATE_BIT |
157 /* 171 /*
158 * Internal bias correction value. Applied 172 * Internal bias correction value. Applied
159 * by the hardware or driver prior to userspace 173 * by the hardware or driver prior to userspace
@@ -177,6 +191,7 @@ static struct iio_chan_spec iio_dummy_channels[] = {
177 /* DAC channel out_voltage0_raw */ 191 /* DAC channel out_voltage0_raw */
178 { 192 {
179 .type = IIO_VOLTAGE, 193 .type = IIO_VOLTAGE,
194 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
180 .output = 1, 195 .output = 1,
181 .indexed = 1, 196 .indexed = 1,
182 .channel = 0, 197 .channel = 0,
@@ -203,7 +218,7 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
203 218
204 mutex_lock(&st->lock); 219 mutex_lock(&st->lock);
205 switch (mask) { 220 switch (mask) {
206 case 0: /* magic value - channel value read */ 221 case IIO_CHAN_INFO_RAW: /* magic value - channel value read */
207 switch (chan->type) { 222 switch (chan->type) {
208 case IIO_VOLTAGE: 223 case IIO_VOLTAGE:
209 if (chan->output) { 224 if (chan->output) {
@@ -290,7 +305,7 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
290 struct iio_dummy_state *st = iio_priv(indio_dev); 305 struct iio_dummy_state *st = iio_priv(indio_dev);
291 306
292 switch (mask) { 307 switch (mask) {
293 case 0: 308 case IIO_CHAN_INFO_RAW:
294 if (chan->output == 0) 309 if (chan->output == 0)
295 return -EINVAL; 310 return -EINVAL;
296 311
@@ -377,7 +392,7 @@ static int __devinit iio_dummy_probe(int index)
377 * It also has a region (accessed by iio_priv() 392 * It also has a region (accessed by iio_priv()
378 * for chip specific state information. 393 * for chip specific state information.
379 */ 394 */
380 indio_dev = iio_allocate_device(sizeof(*st)); 395 indio_dev = iio_device_alloc(sizeof(*st));
381 if (indio_dev == NULL) { 396 if (indio_dev == NULL) {
382 ret = -ENOMEM; 397 ret = -ENOMEM;
383 goto error_ret; 398 goto error_ret;
@@ -455,9 +470,7 @@ error_unconfigure_buffer:
455error_unregister_events: 470error_unregister_events:
456 iio_simple_dummy_events_unregister(indio_dev); 471 iio_simple_dummy_events_unregister(indio_dev);
457error_free_device: 472error_free_device:
458 /* Note free device should only be called, before registration 473 iio_device_free(indio_dev);
459 * has succeeded. */
460 iio_free_device(indio_dev);
461error_ret: 474error_ret:
462 return ret; 475 return ret;
463} 476}
@@ -494,7 +507,7 @@ static int iio_dummy_remove(int index)
494 goto error_ret; 507 goto error_ret;
495 508
496 /* Free all structures */ 509 /* Free all structures */
497 iio_free_device(indio_dev); 510 iio_device_free(indio_dev);
498 511
499error_ret: 512error_ret:
500 return ret; 513 return ret;
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index bb4daf744362..fdfc8739095a 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -18,9 +18,9 @@
18#include <linux/irq.h> 18#include <linux/irq.h>
19#include <linux/bitmap.h> 19#include <linux/bitmap.h>
20 20
21#include "iio.h" 21#include <linux/iio/iio.h>
22#include "trigger_consumer.h" 22#include <linux/iio/trigger_consumer.h>
23#include "kfifo_buf.h" 23#include <linux/iio/kfifo_buf.h>
24 24
25#include "iio_simple_dummy.h" 25#include "iio_simple_dummy.h"
26 26
@@ -37,7 +37,7 @@ static const s16 fakedata[] = {
37 * @irq: the interrupt number 37 * @irq: the interrupt number
38 * @p: private data - always a pointer to the poll func. 38 * @p: private data - always a pointer to the poll func.
39 * 39 *
40 * This is the guts of buffered capture. On a trigger event occuring, 40 * This is the guts of buffered capture. On a trigger event occurring,
41 * if the pollfunc is attached then this handler is called as a threaded 41 * if the pollfunc is attached then this handler is called as a threaded
42 * interrupt (and hence may sleep). It is responsible for grabbing data 42 * interrupt (and hence may sleep). It is responsible for grabbing data
43 * from the device and pushing it into the associated buffer. 43 * from the device and pushing it into the associated buffer.
@@ -48,12 +48,9 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
48 struct iio_dev *indio_dev = pf->indio_dev; 48 struct iio_dev *indio_dev = pf->indio_dev;
49 struct iio_buffer *buffer = indio_dev->buffer; 49 struct iio_buffer *buffer = indio_dev->buffer;
50 int len = 0; 50 int len = 0;
51 /* 51 u16 *data;
52 * The datasize is obtained from the buffer. It was stored when 52
53 * the preenable setup function was called. 53 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
54 */
55 size_t datasize = buffer->access->get_bytes_per_datum(buffer);
56 u16 *data = kmalloc(datasize, GFP_KERNEL);
57 if (data == NULL) 54 if (data == NULL)
58 return -ENOMEM; 55 return -ENOMEM;
59 56
@@ -64,7 +61,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
64 * up a fast read. The capture will consist of all of them. 61 * up a fast read. The capture will consist of all of them.
65 * Hence we just call the grab data function and fill the 62 * Hence we just call the grab data function and fill the
66 * buffer without processing. 63 * buffer without processing.
67 * sofware scans: can be considered to be random access 64 * software scans: can be considered to be random access
68 * so efficient reading is just a case of minimal bus 65 * so efficient reading is just a case of minimal bus
69 * transactions. 66 * transactions.
70 * software culled hardware scans: 67 * software culled hardware scans:
@@ -87,7 +84,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
87 } 84 }
88 } 85 }
89 /* Store a timestampe at an 8 byte boundary */ 86 /* Store a timestampe at an 8 byte boundary */
90 if (buffer->scan_timestamp) 87 if (indio_dev->scan_timestamp)
91 *(s64 *)(((phys_addr_t)data + len 88 *(s64 *)(((phys_addr_t)data + len
92 + sizeof(s64) - 1) & ~(sizeof(s64) - 1)) 89 + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
93 = iio_get_time_ns(); 90 = iio_get_time_ns();
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index 449c7a5ece80..317b77465db4 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -12,9 +12,9 @@
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/irq.h> 13#include <linux/irq.h>
14 14
15#include "iio.h" 15#include <linux/iio/iio.h>
16#include "sysfs.h" 16#include <linux/iio/sysfs.h>
17#include "events.h" 17#include <linux/iio/events.h>
18#include "iio_simple_dummy.h" 18#include "iio_simple_dummy.h"
19 19
20/* Evgen 'fakes' interrupt events for this example */ 20/* Evgen 'fakes' interrupt events for this example */
@@ -122,7 +122,7 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
122 * @private: pointer to device instance state. 122 * @private: pointer to device instance state.
123 * 123 *
124 * This handler is responsible for querying the device to find out what 124 * This handler is responsible for querying the device to find out what
125 * event occured and for then pushing that event towards userspace. 125 * event occurred and for then pushing that event towards userspace.
126 * Here only one event occurs so we push that directly on with locally 126 * Here only one event occurs so we push that directly on with locally
127 * grabbed timestamp. 127 * grabbed timestamp.
128 */ 128 */
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index cd82b56d58af..a8e51bc04439 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -19,9 +19,9 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <asm/div64.h> 20#include <asm/div64.h>
21 21
22#include "../iio.h" 22#include <linux/iio/iio.h>
23#include "../sysfs.h" 23#include <linux/iio/sysfs.h>
24#include "../buffer.h" 24#include <linux/iio/buffer.h>
25#include "../ring_sw.h" 25#include "../ring_sw.h"
26 26
27#include "ad5933.h" 27#include "ad5933.h"
@@ -109,15 +109,46 @@ static struct ad5933_platform_data ad5933_default_pdata = {
109}; 109};
110 110
111static struct iio_chan_spec ad5933_channels[] = { 111static struct iio_chan_spec ad5933_channels[] = {
112 IIO_CHAN(IIO_TEMP, 0, 1, 1, NULL, 0, 0, 0, 112 {
113 0, AD5933_REG_TEMP_DATA, IIO_ST('s', 14, 16, 0), 0), 113 .type = IIO_TEMP,
114 /* Ring Channels */ 114 .indexed = 1,
115 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "real_raw", 0, 0, 115 .channel = 0,
116 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 116 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
117 AD5933_REG_REAL_DATA, 0, IIO_ST('s', 16, 16, 0), 0), 117 .address = AD5933_REG_TEMP_DATA,
118 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "imag_raw", 0, 0, 118 .scan_type = {
119 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 119 .sign = 's',
120 AD5933_REG_IMAG_DATA, 1, IIO_ST('s', 16, 16, 0), 0), 120 .realbits = 14,
121 .storagebits = 16,
122 },
123 }, { /* Ring Channels */
124 .type = IIO_VOLTAGE,
125 .indexed = 1,
126 .channel = 0,
127 .extend_name = "real_raw",
128 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
129 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
130 .address = AD5933_REG_REAL_DATA,
131 .scan_index = 0,
132 .scan_type = {
133 .sign = 's',
134 .realbits = 16,
135 .storagebits = 16,
136 },
137 }, {
138 .type = IIO_VOLTAGE,
139 .indexed = 1,
140 .channel = 0,
141 .extend_name = "imag_raw",
142 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
143 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
144 .address = AD5933_REG_IMAG_DATA,
145 .scan_index = 1,
146 .scan_type = {
147 .sign = 's',
148 .realbits = 16,
149 .storagebits = 16,
150 },
151 },
121}; 152};
122 153
123static int ad5933_i2c_write(struct i2c_client *client, 154static int ad5933_i2c_write(struct i2c_client *client,
@@ -260,7 +291,7 @@ static ssize_t ad5933_show_frequency(struct device *dev,
260 struct device_attribute *attr, 291 struct device_attribute *attr,
261 char *buf) 292 char *buf)
262{ 293{
263 struct iio_dev *indio_dev = dev_get_drvdata(dev); 294 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
264 struct ad5933_state *st = iio_priv(indio_dev); 295 struct ad5933_state *st = iio_priv(indio_dev);
265 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 296 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
266 int ret; 297 int ret;
@@ -289,7 +320,7 @@ static ssize_t ad5933_store_frequency(struct device *dev,
289 const char *buf, 320 const char *buf,
290 size_t len) 321 size_t len)
291{ 322{
292 struct iio_dev *indio_dev = dev_get_drvdata(dev); 323 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
293 struct ad5933_state *st = iio_priv(indio_dev); 324 struct ad5933_state *st = iio_priv(indio_dev);
294 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 325 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
295 long val; 326 long val;
@@ -323,7 +354,7 @@ static ssize_t ad5933_show(struct device *dev,
323 struct device_attribute *attr, 354 struct device_attribute *attr,
324 char *buf) 355 char *buf)
325{ 356{
326 struct iio_dev *indio_dev = dev_get_drvdata(dev); 357 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
327 struct ad5933_state *st = iio_priv(indio_dev); 358 struct ad5933_state *st = iio_priv(indio_dev);
328 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 359 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
329 int ret = 0, len = 0; 360 int ret = 0, len = 0;
@@ -366,7 +397,7 @@ static ssize_t ad5933_store(struct device *dev,
366 const char *buf, 397 const char *buf,
367 size_t len) 398 size_t len)
368{ 399{
369 struct iio_dev *indio_dev = dev_get_drvdata(dev); 400 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
370 struct ad5933_state *st = iio_priv(indio_dev); 401 struct ad5933_state *st = iio_priv(indio_dev);
371 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 402 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
372 long val; 403 long val;
@@ -495,7 +526,8 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
495 526
496 mutex_lock(&indio_dev->mlock); 527 mutex_lock(&indio_dev->mlock);
497 switch (m) { 528 switch (m) {
498 case 0: 529 case IIO_CHAN_INFO_RAW:
530 case IIO_CHAN_INFO_PROCESSED:
499 if (iio_buffer_enabled(indio_dev)) { 531 if (iio_buffer_enabled(indio_dev)) {
500 ret = -EBUSY; 532 ret = -EBUSY;
501 goto out; 533 goto out;
@@ -537,19 +569,14 @@ static const struct iio_info ad5933_info = {
537static int ad5933_ring_preenable(struct iio_dev *indio_dev) 569static int ad5933_ring_preenable(struct iio_dev *indio_dev)
538{ 570{
539 struct ad5933_state *st = iio_priv(indio_dev); 571 struct ad5933_state *st = iio_priv(indio_dev);
540 size_t d_size;
541 int ret; 572 int ret;
542 573
543 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 574 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
544 return -EINVAL; 575 return -EINVAL;
545 576
546 d_size = bitmap_weight(indio_dev->active_scan_mask, 577 ret = iio_sw_buffer_preenable(indio_dev);
547 indio_dev->masklength) * 578 if (ret < 0)
548 ad5933_channels[1].scan_type.storagebits / 8; 579 return ret;
549
550 if (indio_dev->buffer->access->set_bytes_per_datum)
551 indio_dev->buffer->access->
552 set_bytes_per_datum(indio_dev->buffer, d_size);
553 580
554 ret = ad5933_reset(st); 581 ret = ad5933_reset(st);
555 if (ret < 0) 582 if (ret < 0)
@@ -678,7 +705,7 @@ static int __devinit ad5933_probe(struct i2c_client *client,
678 int ret, voltage_uv = 0; 705 int ret, voltage_uv = 0;
679 struct ad5933_platform_data *pdata = client->dev.platform_data; 706 struct ad5933_platform_data *pdata = client->dev.platform_data;
680 struct ad5933_state *st; 707 struct ad5933_state *st;
681 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 708 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
682 if (indio_dev == NULL) 709 if (indio_dev == NULL)
683 return -ENOMEM; 710 return -ENOMEM;
684 711
@@ -757,7 +784,7 @@ error_put_reg:
757 if (!IS_ERR(st->reg)) 784 if (!IS_ERR(st->reg))
758 regulator_put(st->reg); 785 regulator_put(st->reg);
759 786
760 iio_free_device(indio_dev); 787 iio_device_free(indio_dev);
761 788
762 return ret; 789 return ret;
763} 790}
@@ -774,7 +801,7 @@ static __devexit int ad5933_remove(struct i2c_client *client)
774 regulator_disable(st->reg); 801 regulator_disable(st->reg);
775 regulator_put(st->reg); 802 regulator_put(st->reg);
776 } 803 }
777 iio_free_device(indio_dev); 804 iio_device_free(indio_dev);
778 805
779 return 0; 806 return 0;
780} 807}
diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index e73ad7818d85..1f6bd854e950 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -26,9 +26,9 @@
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/module.h> 27#include <linux/module.h>
28 28
29#include "../iio.h" 29#include <linux/iio/iio.h>
30#include "../sysfs.h" 30#include <linux/iio/sysfs.h>
31#include "../buffer.h" 31#include <linux/iio/buffer.h>
32#include "adis16400.h" 32#include "adis16400.h"
33 33
34enum adis16400_chip_variant { 34enum adis16400_chip_variant {
@@ -179,7 +179,7 @@ static ssize_t adis16400_read_frequency(struct device *dev,
179 struct device_attribute *attr, 179 struct device_attribute *attr,
180 char *buf) 180 char *buf)
181{ 181{
182 struct iio_dev *indio_dev = dev_get_drvdata(dev); 182 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
183 int ret, len = 0; 183 int ret, len = 0;
184 ret = adis16400_get_freq(indio_dev); 184 ret = adis16400_get_freq(indio_dev);
185 if (ret < 0) 185 if (ret < 0)
@@ -225,7 +225,7 @@ static ssize_t adis16400_write_frequency(struct device *dev,
225 const char *buf, 225 const char *buf,
226 size_t len) 226 size_t len)
227{ 227{
228 struct iio_dev *indio_dev = dev_get_drvdata(dev); 228 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
229 struct adis16400_state *st = iio_priv(indio_dev); 229 struct adis16400_state *st = iio_priv(indio_dev);
230 long val; 230 long val;
231 int ret; 231 int ret;
@@ -279,7 +279,7 @@ static ssize_t adis16400_write_reset(struct device *dev,
279 if (ret < 0) 279 if (ret < 0)
280 return ret; 280 return ret;
281 if (val) { 281 if (val) {
282 ret = adis16400_reset(dev_get_drvdata(dev)); 282 ret = adis16400_reset(dev_to_iio_dev(dev));
283 if (ret < 0) 283 if (ret < 0)
284 return ret; 284 return ret;
285 } 285 }
@@ -545,7 +545,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
545 s16 val16; 545 s16 val16;
546 546
547 switch (mask) { 547 switch (mask) {
548 case 0: 548 case IIO_CHAN_INFO_RAW:
549 mutex_lock(&indio_dev->mlock); 549 mutex_lock(&indio_dev->mlock);
550 ret = adis16400_spi_read_reg_16(indio_dev, 550 ret = adis16400_spi_read_reg_16(indio_dev,
551 adis16400_addresses[chan->address][0], 551 adis16400_addresses[chan->address][0],
@@ -635,7 +635,8 @@ static struct iio_chan_spec adis16400_channels[] = {
635 .indexed = 1, 635 .indexed = 1,
636 .channel = 0, 636 .channel = 0,
637 .extend_name = "supply", 637 .extend_name = "supply",
638 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 638 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
639 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
639 .address = in_supply, 640 .address = in_supply,
640 .scan_index = ADIS16400_SCAN_SUPPLY, 641 .scan_index = ADIS16400_SCAN_SUPPLY,
641 .scan_type = IIO_ST('u', 14, 16, 0) 642 .scan_type = IIO_ST('u', 14, 16, 0)
@@ -643,7 +644,8 @@ static struct iio_chan_spec adis16400_channels[] = {
643 .type = IIO_ANGL_VEL, 644 .type = IIO_ANGL_VEL,
644 .modified = 1, 645 .modified = 1,
645 .channel2 = IIO_MOD_X, 646 .channel2 = IIO_MOD_X,
646 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 647 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
648 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
647 IIO_CHAN_INFO_SCALE_SHARED_BIT | 649 IIO_CHAN_INFO_SCALE_SHARED_BIT |
648 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 650 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
649 .address = gyro_x, 651 .address = gyro_x,
@@ -653,7 +655,8 @@ static struct iio_chan_spec adis16400_channels[] = {
653 .type = IIO_ANGL_VEL, 655 .type = IIO_ANGL_VEL,
654 .modified = 1, 656 .modified = 1,
655 .channel2 = IIO_MOD_Y, 657 .channel2 = IIO_MOD_Y,
656 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 658 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
659 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
657 IIO_CHAN_INFO_SCALE_SHARED_BIT | 660 IIO_CHAN_INFO_SCALE_SHARED_BIT |
658 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 661 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
659 .address = gyro_y, 662 .address = gyro_y,
@@ -663,7 +666,8 @@ static struct iio_chan_spec adis16400_channels[] = {
663 .type = IIO_ANGL_VEL, 666 .type = IIO_ANGL_VEL,
664 .modified = 1, 667 .modified = 1,
665 .channel2 = IIO_MOD_Z, 668 .channel2 = IIO_MOD_Z,
666 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 669 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
670 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
667 IIO_CHAN_INFO_SCALE_SHARED_BIT | 671 IIO_CHAN_INFO_SCALE_SHARED_BIT |
668 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 672 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
669 .address = gyro_z, 673 .address = gyro_z,
@@ -673,7 +677,8 @@ static struct iio_chan_spec adis16400_channels[] = {
673 .type = IIO_ACCEL, 677 .type = IIO_ACCEL,
674 .modified = 1, 678 .modified = 1,
675 .channel2 = IIO_MOD_X, 679 .channel2 = IIO_MOD_X,
676 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 680 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
681 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
677 IIO_CHAN_INFO_SCALE_SHARED_BIT | 682 IIO_CHAN_INFO_SCALE_SHARED_BIT |
678 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 683 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
679 .address = accel_x, 684 .address = accel_x,
@@ -683,7 +688,8 @@ static struct iio_chan_spec adis16400_channels[] = {
683 .type = IIO_ACCEL, 688 .type = IIO_ACCEL,
684 .modified = 1, 689 .modified = 1,
685 .channel2 = IIO_MOD_Y, 690 .channel2 = IIO_MOD_Y,
686 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 691 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
692 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
687 IIO_CHAN_INFO_SCALE_SHARED_BIT | 693 IIO_CHAN_INFO_SCALE_SHARED_BIT |
688 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 694 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
689 .address = accel_y, 695 .address = accel_y,
@@ -693,7 +699,8 @@ static struct iio_chan_spec adis16400_channels[] = {
693 .type = IIO_ACCEL, 699 .type = IIO_ACCEL,
694 .modified = 1, 700 .modified = 1,
695 .channel2 = IIO_MOD_Z, 701 .channel2 = IIO_MOD_Z,
696 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 702 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
703 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
697 IIO_CHAN_INFO_SCALE_SHARED_BIT | 704 IIO_CHAN_INFO_SCALE_SHARED_BIT |
698 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 705 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
699 .address = accel_z, 706 .address = accel_z,
@@ -703,7 +710,8 @@ static struct iio_chan_spec adis16400_channels[] = {
703 .type = IIO_MAGN, 710 .type = IIO_MAGN,
704 .modified = 1, 711 .modified = 1,
705 .channel2 = IIO_MOD_X, 712 .channel2 = IIO_MOD_X,
706 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | 713 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
714 IIO_CHAN_INFO_SCALE_SHARED_BIT |
707 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 715 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
708 .address = magn_x, 716 .address = magn_x,
709 .scan_index = ADIS16400_SCAN_MAGN_X, 717 .scan_index = ADIS16400_SCAN_MAGN_X,
@@ -712,7 +720,8 @@ static struct iio_chan_spec adis16400_channels[] = {
712 .type = IIO_MAGN, 720 .type = IIO_MAGN,
713 .modified = 1, 721 .modified = 1,
714 .channel2 = IIO_MOD_Y, 722 .channel2 = IIO_MOD_Y,
715 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | 723 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
724 IIO_CHAN_INFO_SCALE_SHARED_BIT |
716 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 725 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
717 .address = magn_y, 726 .address = magn_y,
718 .scan_index = ADIS16400_SCAN_MAGN_Y, 727 .scan_index = ADIS16400_SCAN_MAGN_Y,
@@ -721,7 +730,8 @@ static struct iio_chan_spec adis16400_channels[] = {
721 .type = IIO_MAGN, 730 .type = IIO_MAGN,
722 .modified = 1, 731 .modified = 1,
723 .channel2 = IIO_MOD_Z, 732 .channel2 = IIO_MOD_Z,
724 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT | 733 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
734 IIO_CHAN_INFO_SCALE_SHARED_BIT |
725 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 735 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
726 .address = magn_z, 736 .address = magn_z,
727 .scan_index = ADIS16400_SCAN_MAGN_Z, 737 .scan_index = ADIS16400_SCAN_MAGN_Z,
@@ -730,7 +740,8 @@ static struct iio_chan_spec adis16400_channels[] = {
730 .type = IIO_TEMP, 740 .type = IIO_TEMP,
731 .indexed = 1, 741 .indexed = 1,
732 .channel = 0, 742 .channel = 0,
733 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 743 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
744 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
734 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 745 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
735 .address = temp, 746 .address = temp,
736 .scan_index = ADIS16400_SCAN_TEMP, 747 .scan_index = ADIS16400_SCAN_TEMP,
@@ -739,7 +750,8 @@ static struct iio_chan_spec adis16400_channels[] = {
739 .type = IIO_VOLTAGE, 750 .type = IIO_VOLTAGE,
740 .indexed = 1, 751 .indexed = 1,
741 .channel = 1, 752 .channel = 1,
742 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 753 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
754 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
743 .address = in1, 755 .address = in1,
744 .scan_index = ADIS16400_SCAN_ADC_0, 756 .scan_index = ADIS16400_SCAN_ADC_0,
745 .scan_type = IIO_ST('s', 12, 16, 0), 757 .scan_type = IIO_ST('s', 12, 16, 0),
@@ -753,7 +765,8 @@ static struct iio_chan_spec adis16350_channels[] = {
753 .indexed = 1, 765 .indexed = 1,
754 .channel = 0, 766 .channel = 0,
755 .extend_name = "supply", 767 .extend_name = "supply",
756 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 768 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
769 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
757 .address = in_supply, 770 .address = in_supply,
758 .scan_index = ADIS16400_SCAN_SUPPLY, 771 .scan_index = ADIS16400_SCAN_SUPPLY,
759 .scan_type = IIO_ST('u', 12, 16, 0) 772 .scan_type = IIO_ST('u', 12, 16, 0)
@@ -761,7 +774,8 @@ static struct iio_chan_spec adis16350_channels[] = {
761 .type = IIO_ANGL_VEL, 774 .type = IIO_ANGL_VEL,
762 .modified = 1, 775 .modified = 1,
763 .channel2 = IIO_MOD_X, 776 .channel2 = IIO_MOD_X,
764 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 777 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
778 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
765 IIO_CHAN_INFO_SCALE_SHARED_BIT | 779 IIO_CHAN_INFO_SCALE_SHARED_BIT |
766 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 780 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
767 .address = gyro_x, 781 .address = gyro_x,
@@ -771,7 +785,8 @@ static struct iio_chan_spec adis16350_channels[] = {
771 .type = IIO_ANGL_VEL, 785 .type = IIO_ANGL_VEL,
772 .modified = 1, 786 .modified = 1,
773 .channel2 = IIO_MOD_Y, 787 .channel2 = IIO_MOD_Y,
774 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 788 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
789 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
775 IIO_CHAN_INFO_SCALE_SHARED_BIT | 790 IIO_CHAN_INFO_SCALE_SHARED_BIT |
776 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 791 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
777 .address = gyro_y, 792 .address = gyro_y,
@@ -781,17 +796,19 @@ static struct iio_chan_spec adis16350_channels[] = {
781 .type = IIO_ANGL_VEL, 796 .type = IIO_ANGL_VEL,
782 .modified = 1, 797 .modified = 1,
783 .channel2 = IIO_MOD_Z, 798 .channel2 = IIO_MOD_Z,
784 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 799 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
800 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
785 IIO_CHAN_INFO_SCALE_SHARED_BIT | 801 IIO_CHAN_INFO_SCALE_SHARED_BIT |
786 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 802 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
787 .address = gyro_z, 803 .address = gyro_z,
788 .scan_index = ADIS16400_SCAN_GYRO_Z, 804 .scan_index = ADIS16400_SCAN_GYRO_Z,
789 .scan_type = IIO_ST('s', 14, 16, 0), 805 .scan_type = IIO_ST('s', 14, 16, 0),
790 }, { 806 }, {
791 .type = IIO_ACCEL, 807 .type = IIO_ACCEL,
792 .modified = 1, 808 .modified = 1,
793 .channel2 = IIO_MOD_X, 809 .channel2 = IIO_MOD_X,
794 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 810 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
811 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
795 IIO_CHAN_INFO_SCALE_SHARED_BIT | 812 IIO_CHAN_INFO_SCALE_SHARED_BIT |
796 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 813 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
797 .address = accel_x, 814 .address = accel_x,
@@ -801,7 +818,8 @@ static struct iio_chan_spec adis16350_channels[] = {
801 .type = IIO_ACCEL, 818 .type = IIO_ACCEL,
802 .modified = 1, 819 .modified = 1,
803 .channel2 = IIO_MOD_Y, 820 .channel2 = IIO_MOD_Y,
804 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 821 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
822 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
805 IIO_CHAN_INFO_SCALE_SHARED_BIT | 823 IIO_CHAN_INFO_SCALE_SHARED_BIT |
806 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 824 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
807 .address = accel_y, 825 .address = accel_y,
@@ -811,7 +829,8 @@ static struct iio_chan_spec adis16350_channels[] = {
811 .type = IIO_ACCEL, 829 .type = IIO_ACCEL,
812 .modified = 1, 830 .modified = 1,
813 .channel2 = IIO_MOD_Z, 831 .channel2 = IIO_MOD_Z,
814 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 832 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
833 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
815 IIO_CHAN_INFO_SCALE_SHARED_BIT | 834 IIO_CHAN_INFO_SCALE_SHARED_BIT |
816 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 835 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
817 .address = accel_z, 836 .address = accel_z,
@@ -822,7 +841,8 @@ static struct iio_chan_spec adis16350_channels[] = {
822 .indexed = 1, 841 .indexed = 1,
823 .channel = 0, 842 .channel = 0,
824 .extend_name = "x", 843 .extend_name = "x",
825 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 844 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
845 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
826 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 846 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
827 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 847 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
828 .address = temp0, 848 .address = temp0,
@@ -833,7 +853,8 @@ static struct iio_chan_spec adis16350_channels[] = {
833 .indexed = 1, 853 .indexed = 1,
834 .channel = 1, 854 .channel = 1,
835 .extend_name = "y", 855 .extend_name = "y",
836 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 856 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
857 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
837 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | 858 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
838 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 859 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
839 .address = temp1, 860 .address = temp1,
@@ -844,7 +865,8 @@ static struct iio_chan_spec adis16350_channels[] = {
844 .indexed = 1, 865 .indexed = 1,
845 .channel = 2, 866 .channel = 2,
846 .extend_name = "z", 867 .extend_name = "z",
847 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 868 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
869 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
848 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 870 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
849 .address = temp2, 871 .address = temp2,
850 .scan_index = ADIS16350_SCAN_TEMP_Z, 872 .scan_index = ADIS16350_SCAN_TEMP_Z,
@@ -853,7 +875,8 @@ static struct iio_chan_spec adis16350_channels[] = {
853 .type = IIO_VOLTAGE, 875 .type = IIO_VOLTAGE,
854 .indexed = 1, 876 .indexed = 1,
855 .channel = 1, 877 .channel = 1,
856 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 878 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
879 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
857 .address = in1, 880 .address = in1,
858 .scan_index = ADIS16350_SCAN_ADC_0, 881 .scan_index = ADIS16350_SCAN_ADC_0,
859 .scan_type = IIO_ST('s', 12, 16, 0), 882 .scan_type = IIO_ST('s', 12, 16, 0),
@@ -867,7 +890,8 @@ static struct iio_chan_spec adis16300_channels[] = {
867 .indexed = 1, 890 .indexed = 1,
868 .channel = 0, 891 .channel = 0,
869 .extend_name = "supply", 892 .extend_name = "supply",
870 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 893 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
894 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
871 .address = in_supply, 895 .address = in_supply,
872 .scan_index = ADIS16400_SCAN_SUPPLY, 896 .scan_index = ADIS16400_SCAN_SUPPLY,
873 .scan_type = IIO_ST('u', 12, 16, 0) 897 .scan_type = IIO_ST('u', 12, 16, 0)
@@ -875,7 +899,8 @@ static struct iio_chan_spec adis16300_channels[] = {
875 .type = IIO_ANGL_VEL, 899 .type = IIO_ANGL_VEL,
876 .modified = 1, 900 .modified = 1,
877 .channel2 = IIO_MOD_X, 901 .channel2 = IIO_MOD_X,
878 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 902 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
903 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
879 IIO_CHAN_INFO_SCALE_SHARED_BIT | 904 IIO_CHAN_INFO_SCALE_SHARED_BIT |
880 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 905 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
881 .address = gyro_x, 906 .address = gyro_x,
@@ -885,7 +910,8 @@ static struct iio_chan_spec adis16300_channels[] = {
885 .type = IIO_ACCEL, 910 .type = IIO_ACCEL,
886 .modified = 1, 911 .modified = 1,
887 .channel2 = IIO_MOD_X, 912 .channel2 = IIO_MOD_X,
888 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 913 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
914 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
889 IIO_CHAN_INFO_SCALE_SHARED_BIT | 915 IIO_CHAN_INFO_SCALE_SHARED_BIT |
890 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 916 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
891 .address = accel_x, 917 .address = accel_x,
@@ -895,7 +921,8 @@ static struct iio_chan_spec adis16300_channels[] = {
895 .type = IIO_ACCEL, 921 .type = IIO_ACCEL,
896 .modified = 1, 922 .modified = 1,
897 .channel2 = IIO_MOD_Y, 923 .channel2 = IIO_MOD_Y,
898 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 924 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
925 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
899 IIO_CHAN_INFO_SCALE_SHARED_BIT | 926 IIO_CHAN_INFO_SCALE_SHARED_BIT |
900 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 927 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
901 .address = accel_y, 928 .address = accel_y,
@@ -905,7 +932,8 @@ static struct iio_chan_spec adis16300_channels[] = {
905 .type = IIO_ACCEL, 932 .type = IIO_ACCEL,
906 .modified = 1, 933 .modified = 1,
907 .channel2 = IIO_MOD_Z, 934 .channel2 = IIO_MOD_Z,
908 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 935 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
936 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
909 IIO_CHAN_INFO_SCALE_SHARED_BIT | 937 IIO_CHAN_INFO_SCALE_SHARED_BIT |
910 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 938 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
911 .address = accel_z, 939 .address = accel_z,
@@ -915,7 +943,8 @@ static struct iio_chan_spec adis16300_channels[] = {
915 .type = IIO_TEMP, 943 .type = IIO_TEMP,
916 .indexed = 1, 944 .indexed = 1,
917 .channel = 0, 945 .channel = 0,
918 .info_mask = IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | 946 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
947 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
919 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 948 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
920 .address = temp, 949 .address = temp,
921 .scan_index = ADIS16400_SCAN_TEMP, 950 .scan_index = ADIS16400_SCAN_TEMP,
@@ -924,7 +953,8 @@ static struct iio_chan_spec adis16300_channels[] = {
924 .type = IIO_VOLTAGE, 953 .type = IIO_VOLTAGE,
925 .indexed = 1, 954 .indexed = 1,
926 .channel = 1, 955 .channel = 1,
927 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 956 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
957 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
928 .address = in1, 958 .address = in1,
929 .scan_index = ADIS16350_SCAN_ADC_0, 959 .scan_index = ADIS16350_SCAN_ADC_0,
930 .scan_type = IIO_ST('s', 12, 16, 0), 960 .scan_type = IIO_ST('s', 12, 16, 0),
@@ -932,7 +962,8 @@ static struct iio_chan_spec adis16300_channels[] = {
932 .type = IIO_INCLI, 962 .type = IIO_INCLI,
933 .modified = 1, 963 .modified = 1,
934 .channel2 = IIO_MOD_X, 964 .channel2 = IIO_MOD_X,
935 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 965 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
966 IIO_CHAN_INFO_SCALE_SHARED_BIT,
936 .address = incli_x, 967 .address = incli_x,
937 .scan_index = ADIS16300_SCAN_INCLI_X, 968 .scan_index = ADIS16300_SCAN_INCLI_X,
938 .scan_type = IIO_ST('s', 13, 16, 0), 969 .scan_type = IIO_ST('s', 13, 16, 0),
@@ -940,7 +971,8 @@ static struct iio_chan_spec adis16300_channels[] = {
940 .type = IIO_INCLI, 971 .type = IIO_INCLI,
941 .modified = 1, 972 .modified = 1,
942 .channel2 = IIO_MOD_Y, 973 .channel2 = IIO_MOD_Y,
943 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, 974 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
975 IIO_CHAN_INFO_SCALE_SHARED_BIT,
944 .address = incli_y, 976 .address = incli_y,
945 .scan_index = ADIS16300_SCAN_INCLI_Y, 977 .scan_index = ADIS16300_SCAN_INCLI_Y,
946 .scan_type = IIO_ST('s', 13, 16, 0), 978 .scan_type = IIO_ST('s', 13, 16, 0),
@@ -953,7 +985,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
953 .type = IIO_ANGL_VEL, 985 .type = IIO_ANGL_VEL,
954 .modified = 1, 986 .modified = 1,
955 .channel2 = IIO_MOD_X, 987 .channel2 = IIO_MOD_X,
956 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 988 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
989 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
957 IIO_CHAN_INFO_SCALE_SHARED_BIT | 990 IIO_CHAN_INFO_SCALE_SHARED_BIT |
958 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 991 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
959 .address = gyro_x, 992 .address = gyro_x,
@@ -963,7 +996,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
963 .type = IIO_ANGL_VEL, 996 .type = IIO_ANGL_VEL,
964 .modified = 1, 997 .modified = 1,
965 .channel2 = IIO_MOD_Y, 998 .channel2 = IIO_MOD_Y,
966 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 999 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1000 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
967 IIO_CHAN_INFO_SCALE_SHARED_BIT | 1001 IIO_CHAN_INFO_SCALE_SHARED_BIT |
968 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 1002 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
969 .address = gyro_y, 1003 .address = gyro_y,
@@ -973,7 +1007,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
973 .type = IIO_ANGL_VEL, 1007 .type = IIO_ANGL_VEL,
974 .modified = 1, 1008 .modified = 1,
975 .channel2 = IIO_MOD_Z, 1009 .channel2 = IIO_MOD_Z,
976 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 1010 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1011 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
977 IIO_CHAN_INFO_SCALE_SHARED_BIT | 1012 IIO_CHAN_INFO_SCALE_SHARED_BIT |
978 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 1013 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
979 .address = gyro_z, 1014 .address = gyro_z,
@@ -983,7 +1018,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
983 .type = IIO_ACCEL, 1018 .type = IIO_ACCEL,
984 .modified = 1, 1019 .modified = 1,
985 .channel2 = IIO_MOD_X, 1020 .channel2 = IIO_MOD_X,
986 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 1021 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1022 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
987 IIO_CHAN_INFO_SCALE_SHARED_BIT | 1023 IIO_CHAN_INFO_SCALE_SHARED_BIT |
988 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 1024 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
989 .address = accel_x, 1025 .address = accel_x,
@@ -993,7 +1029,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
993 .type = IIO_ACCEL, 1029 .type = IIO_ACCEL,
994 .modified = 1, 1030 .modified = 1,
995 .channel2 = IIO_MOD_Y, 1031 .channel2 = IIO_MOD_Y,
996 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 1032 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1033 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
997 IIO_CHAN_INFO_SCALE_SHARED_BIT | 1034 IIO_CHAN_INFO_SCALE_SHARED_BIT |
998 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 1035 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
999 .address = accel_y, 1036 .address = accel_y,
@@ -1003,7 +1040,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
1003 .type = IIO_ACCEL, 1040 .type = IIO_ACCEL,
1004 .modified = 1, 1041 .modified = 1,
1005 .channel2 = IIO_MOD_Z, 1042 .channel2 = IIO_MOD_Z,
1006 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 1043 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1044 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1007 IIO_CHAN_INFO_SCALE_SHARED_BIT | 1045 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1008 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, 1046 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1009 .address = accel_z, 1047 .address = accel_z,
@@ -1013,7 +1051,8 @@ static const struct iio_chan_spec adis16334_channels[] = {
1013 .type = IIO_TEMP, 1051 .type = IIO_TEMP,
1014 .indexed = 1, 1052 .indexed = 1,
1015 .channel = 0, 1053 .channel = 0,
1016 .info_mask = IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | 1054 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1055 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1017 IIO_CHAN_INFO_SCALE_SHARED_BIT, 1056 IIO_CHAN_INFO_SCALE_SHARED_BIT,
1018 .address = accel_z, 1057 .address = accel_z,
1019 .scan_index = ADIS16400_SCAN_ACC_Z, 1058 .scan_index = ADIS16400_SCAN_ACC_Z,
@@ -1122,7 +1161,7 @@ static int __devinit adis16400_probe(struct spi_device *spi)
1122{ 1161{
1123 int ret; 1162 int ret;
1124 struct adis16400_state *st; 1163 struct adis16400_state *st;
1125 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 1164 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
1126 if (indio_dev == NULL) { 1165 if (indio_dev == NULL) {
1127 ret = -ENOMEM; 1166 ret = -ENOMEM;
1128 goto error_ret; 1167 goto error_ret;
@@ -1172,14 +1211,14 @@ static int __devinit adis16400_probe(struct spi_device *spi)
1172 return 0; 1211 return 0;
1173 1212
1174error_remove_trigger: 1213error_remove_trigger:
1175 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) 1214 if (spi->irq)
1176 adis16400_remove_trigger(indio_dev); 1215 adis16400_remove_trigger(indio_dev);
1177error_uninitialize_ring: 1216error_uninitialize_ring:
1178 iio_buffer_unregister(indio_dev); 1217 iio_buffer_unregister(indio_dev);
1179error_unreg_ring_funcs: 1218error_unreg_ring_funcs:
1180 adis16400_unconfigure_ring(indio_dev); 1219 adis16400_unconfigure_ring(indio_dev);
1181error_free_dev: 1220error_free_dev:
1182 iio_free_device(indio_dev); 1221 iio_device_free(indio_dev);
1183error_ret: 1222error_ret:
1184 return ret; 1223 return ret;
1185} 1224}
@@ -1198,7 +1237,7 @@ static int adis16400_remove(struct spi_device *spi)
1198 adis16400_remove_trigger(indio_dev); 1237 adis16400_remove_trigger(indio_dev);
1199 iio_buffer_unregister(indio_dev); 1238 iio_buffer_unregister(indio_dev);
1200 adis16400_unconfigure_ring(indio_dev); 1239 adis16400_unconfigure_ring(indio_dev);
1201 iio_free_device(indio_dev); 1240 iio_device_free(indio_dev);
1202 1241
1203 return 0; 1242 return 0;
1204 1243
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index 8daa038b23e6..809e2c4270d1 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -6,20 +6,19 @@
6#include <linux/bitops.h> 6#include <linux/bitops.h>
7#include <linux/export.h> 7#include <linux/export.h>
8 8
9#include "../iio.h" 9#include <linux/iio/iio.h>
10#include "../ring_sw.h" 10#include "../ring_sw.h"
11#include "../trigger_consumer.h" 11#include <linux/iio/trigger_consumer.h>
12#include "adis16400.h" 12#include "adis16400.h"
13 13
14/** 14/**
15 * adis16400_spi_read_burst() - read all data registers 15 * adis16400_spi_read_burst() - read all data registers
16 * @dev: device associated with child of actual device (iio_dev or iio_trig) 16 * @indio_dev: the IIO device
17 * @rx: somewhere to pass back the value read (min size is 24 bytes) 17 * @rx: somewhere to pass back the value read (min size is 24 bytes)
18 **/ 18 **/
19static int adis16400_spi_read_burst(struct device *dev, u8 *rx) 19static int adis16400_spi_read_burst(struct iio_dev *indio_dev, u8 *rx)
20{ 20{
21 struct spi_message msg; 21 struct spi_message msg;
22 struct iio_dev *indio_dev = dev_get_drvdata(dev);
23 struct adis16400_state *st = iio_priv(indio_dev); 22 struct adis16400_state *st = iio_priv(indio_dev);
24 u32 old_speed_hz = st->us->max_speed_hz; 23 u32 old_speed_hz = st->us->max_speed_hz;
25 int ret; 24 int ret;
@@ -71,9 +70,8 @@ static const u16 read_all_tx_array[] = {
71 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_AUX_ADC)), 70 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_AUX_ADC)),
72}; 71};
73 72
74static int adis16350_spi_read_all(struct device *dev, u8 *rx) 73static int adis16350_spi_read_all(struct iio_dev *indio_dev, u8 *rx)
75{ 74{
76 struct iio_dev *indio_dev = dev_get_drvdata(dev);
77 struct adis16400_state *st = iio_priv(indio_dev); 75 struct adis16400_state *st = iio_priv(indio_dev);
78 76
79 struct spi_message msg; 77 struct spi_message msg;
@@ -119,12 +117,12 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
119 struct iio_buffer *ring = indio_dev->buffer; 117 struct iio_buffer *ring = indio_dev->buffer;
120 int i = 0, j, ret = 0; 118 int i = 0, j, ret = 0;
121 s16 *data; 119 s16 *data;
122 size_t datasize = ring->access->get_bytes_per_datum(ring); 120
123 /* Asumption that long is enough for maximum channels */ 121 /* Asumption that long is enough for maximum channels */
124 unsigned long mask = *indio_dev->active_scan_mask; 122 unsigned long mask = *indio_dev->active_scan_mask;
125 int scan_count = bitmap_weight(indio_dev->active_scan_mask, 123 int scan_count = bitmap_weight(indio_dev->active_scan_mask,
126 indio_dev->masklength); 124 indio_dev->masklength);
127 data = kmalloc(datasize , GFP_KERNEL); 125 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
128 if (data == NULL) { 126 if (data == NULL) {
129 dev_err(&st->us->dev, "memory alloc failed in ring bh"); 127 dev_err(&st->us->dev, "memory alloc failed in ring bh");
130 return -ENOMEM; 128 return -ENOMEM;
@@ -132,13 +130,13 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
132 130
133 if (scan_count) { 131 if (scan_count) {
134 if (st->variant->flags & ADIS16400_NO_BURST) { 132 if (st->variant->flags & ADIS16400_NO_BURST) {
135 ret = adis16350_spi_read_all(&indio_dev->dev, st->rx); 133 ret = adis16350_spi_read_all(indio_dev, st->rx);
136 if (ret < 0) 134 if (ret < 0)
137 goto err; 135 goto err;
138 for (; i < scan_count; i++) 136 for (; i < scan_count; i++)
139 data[i] = *(s16 *)(st->rx + i*2); 137 data[i] = *(s16 *)(st->rx + i*2);
140 } else { 138 } else {
141 ret = adis16400_spi_read_burst(&indio_dev->dev, st->rx); 139 ret = adis16400_spi_read_burst(indio_dev, st->rx);
142 if (ret < 0) 140 if (ret < 0)
143 goto err; 141 goto err;
144 for (; i < scan_count; i++) { 142 for (; i < scan_count; i++) {
diff --git a/drivers/staging/iio/imu/adis16400_trigger.c b/drivers/staging/iio/imu/adis16400_trigger.c
index 5bf000757522..42a678e92fc6 100644
--- a/drivers/staging/iio/imu/adis16400_trigger.c
+++ b/drivers/staging/iio/imu/adis16400_trigger.c
@@ -3,8 +3,8 @@
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h> 4#include <linux/export.h>
5 5
6#include "../iio.h" 6#include <linux/iio/iio.h>
7#include "../trigger.h" 7#include <linux/iio/trigger.h>
8#include "adis16400.h" 8#include "adis16400.h"
9 9
10/** 10/**
@@ -29,7 +29,7 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
29 int ret; 29 int ret;
30 struct adis16400_state *st = iio_priv(indio_dev); 30 struct adis16400_state *st = iio_priv(indio_dev);
31 31
32 st->trig = iio_allocate_trigger("%s-dev%d", 32 st->trig = iio_trigger_alloc("%s-dev%d",
33 indio_dev->name, 33 indio_dev->name,
34 indio_dev->id); 34 indio_dev->id);
35 if (st->trig == NULL) { 35 if (st->trig == NULL) {
@@ -59,7 +59,7 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
59error_free_irq: 59error_free_irq:
60 free_irq(st->us->irq, st->trig); 60 free_irq(st->us->irq, st->trig);
61error_free_trig: 61error_free_trig:
62 iio_free_trigger(st->trig); 62 iio_trigger_free(st->trig);
63error_ret: 63error_ret:
64 return ret; 64 return ret;
65} 65}
@@ -70,5 +70,5 @@ void adis16400_remove_trigger(struct iio_dev *indio_dev)
70 70
71 iio_trigger_unregister(st->trig); 71 iio_trigger_unregister(st->trig);
72 free_irq(st->us->irq, st->trig); 72 free_irq(st->us->irq, st->trig);
73 iio_free_trigger(st->trig); 73 iio_trigger_free(st->trig);
74} 74}
diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index e7e9159d9895..4bed30eac3ed 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -4,15 +4,26 @@
4menu "Light sensors" 4menu "Light sensors"
5 5
6config SENSORS_ISL29018 6config SENSORS_ISL29018
7 tristate "ISL 29018 light and proximity sensor" 7 tristate "ISL 29018 light and proximity sensor"
8 depends on I2C 8 depends on I2C
9 default n 9 select REGMAP_I2C
10 help 10 default n
11 If you say yes here you get support for ambient light sensing and 11 help
12 proximity infrared sensing from Intersil ISL29018. 12 If you say yes here you get support for ambient light sensing and
13 This driver will provide the measurements of ambient light intensity 13 proximity infrared sensing from Intersil ISL29018.
14 in lux, proximity infrared sensing and normal infrared sensing. 14 This driver will provide the measurements of ambient light intensity
15 Data from sensor is accessible via sysfs. 15 in lux, proximity infrared sensing and normal infrared sensing.
16 Data from sensor is accessible via sysfs.
17
18config SENSORS_ISL29028
19 tristate "Intersil ISL29028 Concurrent Light and Proximity Sensor"
20 depends on I2C
21 select REGMAP_I2C
22 help
23 Provides driver for the Intersil's ISL29028 device.
24 This driver supports the sysfs interface to get the ALS, IR intensity,
25 Proximity value via iio. The ISL29028 provides the concurrent sensing
26 of ambient light and proximity.
16 27
17config SENSORS_TSL2563 28config SENSORS_TSL2563
18 tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors" 29 tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors"
@@ -31,4 +42,12 @@ config TSL2583
31 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices. 42 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
32 Access ALS data via iio, sysfs. 43 Access ALS data via iio, sysfs.
33 44
45config TSL2x7x
46 tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
47 depends on I2C
48 help
49 Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672,
50 tmd2672, tsl2772, tmd2772 devices.
51 Provides iio_events and direct access via sysfs.
52
34endmenu 53endmenu
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index 3011fbfa8dc2..141af1eb164c 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -4,4 +4,6 @@
4 4
5obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o 5obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o
6obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o 6obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o
7obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o
7obj-$(CONFIG_TSL2583) += tsl2583.o 8obj-$(CONFIG_TSL2583) += tsl2583.o
9obj-$(CONFIG_TSL2x7x) += tsl2x7x_core.o
diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
index 38ec52b65dfa..0abbf18d6103 100644
--- a/drivers/staging/iio/light/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -26,9 +26,11 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/regmap.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
30#include "../iio.h" 31#include <linux/iio/iio.h>
31#include "../sysfs.h" 32#include <linux/iio/sysfs.h>
33
32#define CONVERSION_TIME_MS 100 34#define CONVERSION_TIME_MS 100
33 35
34#define ISL29018_REG_ADD_COMMAND1 0x00 36#define ISL29018_REG_ADD_COMMAND1 0x00
@@ -51,49 +53,22 @@
51 53
52#define ISL29018_REG_ADD_DATA_LSB 0x02 54#define ISL29018_REG_ADD_DATA_LSB 0x02
53#define ISL29018_REG_ADD_DATA_MSB 0x03 55#define ISL29018_REG_ADD_DATA_MSB 0x03
54#define ISL29018_MAX_REGS (ISL29018_REG_ADD_DATA_MSB+1)
55 56
56#define ISL29018_REG_TEST 0x08 57#define ISL29018_REG_TEST 0x08
57#define ISL29018_TEST_SHIFT 0 58#define ISL29018_TEST_SHIFT 0
58#define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT) 59#define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT)
59 60
60struct isl29018_chip { 61struct isl29018_chip {
61 struct i2c_client *client; 62 struct device *dev;
63 struct regmap *regmap;
62 struct mutex lock; 64 struct mutex lock;
63 unsigned int lux_scale; 65 unsigned int lux_scale;
64 unsigned int range; 66 unsigned int range;
65 unsigned int adc_bit; 67 unsigned int adc_bit;
66 int prox_scheme; 68 int prox_scheme;
67 u8 reg_cache[ISL29018_MAX_REGS];
68}; 69};
69 70
70static int isl29018_write_data(struct i2c_client *client, u8 reg, 71static int isl29018_set_range(struct isl29018_chip *chip, unsigned long range,
71 u8 val, u8 mask, u8 shift)
72{
73 u8 regval = val;
74 int ret;
75 struct isl29018_chip *chip = iio_priv(i2c_get_clientdata(client));
76
77 /* don't cache or mask REG_TEST */
78 if (reg < ISL29018_MAX_REGS) {
79 regval = chip->reg_cache[reg];
80 regval &= ~mask;
81 regval |= val << shift;
82 }
83
84 ret = i2c_smbus_write_byte_data(client, reg, regval);
85 if (ret) {
86 dev_err(&client->dev, "Write to device fails status %x\n", ret);
87 } else {
88 /* don't update cache on err */
89 if (reg < ISL29018_MAX_REGS)
90 chip->reg_cache[reg] = regval;
91 }
92
93 return ret;
94}
95
96static int isl29018_set_range(struct i2c_client *client, unsigned long range,
97 unsigned int *new_range) 72 unsigned int *new_range)
98{ 73{
99 static const unsigned long supp_ranges[] = {1000, 4000, 16000, 64000}; 74 static const unsigned long supp_ranges[] = {1000, 4000, 16000, 64000};
@@ -109,11 +84,11 @@ static int isl29018_set_range(struct i2c_client *client, unsigned long range,
109 if (i >= ARRAY_SIZE(supp_ranges)) 84 if (i >= ARRAY_SIZE(supp_ranges))
110 return -EINVAL; 85 return -EINVAL;
111 86
112 return isl29018_write_data(client, ISL29018_REG_ADD_COMMANDII, 87 return regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII,
113 i, COMMANDII_RANGE_MASK, COMMANDII_RANGE_SHIFT); 88 COMMANDII_RANGE_MASK, i << COMMANDII_RANGE_SHIFT);
114} 89}
115 90
116static int isl29018_set_resolution(struct i2c_client *client, 91static int isl29018_set_resolution(struct isl29018_chip *chip,
117 unsigned long adcbit, unsigned int *conf_adc_bit) 92 unsigned long adcbit, unsigned int *conf_adc_bit)
118{ 93{
119 static const unsigned long supp_adcbit[] = {16, 12, 8, 4}; 94 static const unsigned long supp_adcbit[] = {16, 12, 8, 4};
@@ -129,48 +104,49 @@ static int isl29018_set_resolution(struct i2c_client *client,
129 if (i >= ARRAY_SIZE(supp_adcbit)) 104 if (i >= ARRAY_SIZE(supp_adcbit))
130 return -EINVAL; 105 return -EINVAL;
131 106
132 return isl29018_write_data(client, ISL29018_REG_ADD_COMMANDII, 107 return regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII,
133 i, COMMANDII_RESOLUTION_MASK, 108 COMMANDII_RESOLUTION_MASK,
134 COMMANDII_RESOLUTION_SHIFT); 109 i << COMMANDII_RESOLUTION_SHIFT);
135} 110}
136 111
137static int isl29018_read_sensor_input(struct i2c_client *client, int mode) 112static int isl29018_read_sensor_input(struct isl29018_chip *chip, int mode)
138{ 113{
139 int status; 114 int status;
140 int lsb; 115 unsigned int lsb;
141 int msb; 116 unsigned int msb;
142 117
143 /* Set mode */ 118 /* Set mode */
144 status = isl29018_write_data(client, ISL29018_REG_ADD_COMMAND1, 119 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1,
145 mode, COMMMAND1_OPMODE_MASK, COMMMAND1_OPMODE_SHIFT); 120 mode << COMMMAND1_OPMODE_SHIFT);
146 if (status) { 121 if (status) {
147 dev_err(&client->dev, "Error in setting operating mode\n"); 122 dev_err(chip->dev,
123 "Error in setting operating mode err %d\n", status);
148 return status; 124 return status;
149 } 125 }
150 msleep(CONVERSION_TIME_MS); 126 msleep(CONVERSION_TIME_MS);
151 lsb = i2c_smbus_read_byte_data(client, ISL29018_REG_ADD_DATA_LSB); 127 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_LSB, &lsb);
152 if (lsb < 0) { 128 if (status < 0) {
153 dev_err(&client->dev, "Error in reading LSB DATA\n"); 129 dev_err(chip->dev,
154 return lsb; 130 "Error in reading LSB DATA with err %d\n", status);
131 return status;
155 } 132 }
156 133
157 msb = i2c_smbus_read_byte_data(client, ISL29018_REG_ADD_DATA_MSB); 134 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_MSB, &msb);
158 if (msb < 0) { 135 if (status < 0) {
159 dev_err(&client->dev, "Error in reading MSB DATA\n"); 136 dev_err(chip->dev,
160 return msb; 137 "Error in reading MSB DATA with error %d\n", status);
138 return status;
161 } 139 }
162 dev_vdbg(&client->dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb); 140 dev_vdbg(chip->dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb);
163 141
164 return (msb << 8) | lsb; 142 return (msb << 8) | lsb;
165} 143}
166 144
167static int isl29018_read_lux(struct i2c_client *client, int *lux) 145static int isl29018_read_lux(struct isl29018_chip *chip, int *lux)
168{ 146{
169 int lux_data; 147 int lux_data;
170 struct isl29018_chip *chip = iio_priv(i2c_get_clientdata(client));
171 148
172 lux_data = isl29018_read_sensor_input(client, 149 lux_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_ALS_ONCE);
173 COMMMAND1_OPMODE_ALS_ONCE);
174 150
175 if (lux_data < 0) 151 if (lux_data < 0)
176 return lux_data; 152 return lux_data;
@@ -180,11 +156,11 @@ static int isl29018_read_lux(struct i2c_client *client, int *lux)
180 return 0; 156 return 0;
181} 157}
182 158
183static int isl29018_read_ir(struct i2c_client *client, int *ir) 159static int isl29018_read_ir(struct isl29018_chip *chip, int *ir)
184{ 160{
185 int ir_data; 161 int ir_data;
186 162
187 ir_data = isl29018_read_sensor_input(client, COMMMAND1_OPMODE_IR_ONCE); 163 ir_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_IR_ONCE);
188 164
189 if (ir_data < 0) 165 if (ir_data < 0)
190 return ir_data; 166 return ir_data;
@@ -194,7 +170,7 @@ static int isl29018_read_ir(struct i2c_client *client, int *ir)
194 return 0; 170 return 0;
195} 171}
196 172
197static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme, 173static int isl29018_read_proximity_ir(struct isl29018_chip *chip, int scheme,
198 int *near_ir) 174 int *near_ir)
199{ 175{
200 int status; 176 int status;
@@ -202,14 +178,15 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
202 int ir_data = -1; 178 int ir_data = -1;
203 179
204 /* Do proximity sensing with required scheme */ 180 /* Do proximity sensing with required scheme */
205 status = isl29018_write_data(client, ISL29018_REG_ADD_COMMANDII, 181 status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII,
206 scheme, COMMANDII_SCHEME_MASK, COMMANDII_SCHEME_SHIFT); 182 COMMANDII_SCHEME_MASK,
183 scheme << COMMANDII_SCHEME_SHIFT);
207 if (status) { 184 if (status) {
208 dev_err(&client->dev, "Error in setting operating mode\n"); 185 dev_err(chip->dev, "Error in setting operating mode\n");
209 return status; 186 return status;
210 } 187 }
211 188
212 prox_data = isl29018_read_sensor_input(client, 189 prox_data = isl29018_read_sensor_input(chip,
213 COMMMAND1_OPMODE_PROX_ONCE); 190 COMMMAND1_OPMODE_PROX_ONCE);
214 if (prox_data < 0) 191 if (prox_data < 0)
215 return prox_data; 192 return prox_data;
@@ -219,8 +196,7 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
219 return 0; 196 return 0;
220 } 197 }
221 198
222 ir_data = isl29018_read_sensor_input(client, 199 ir_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_IR_ONCE);
223 COMMMAND1_OPMODE_IR_ONCE);
224 200
225 if (ir_data < 0) 201 if (ir_data < 0)
226 return ir_data; 202 return ir_data;
@@ -238,7 +214,7 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
238static ssize_t show_range(struct device *dev, 214static ssize_t show_range(struct device *dev,
239 struct device_attribute *attr, char *buf) 215 struct device_attribute *attr, char *buf)
240{ 216{
241 struct iio_dev *indio_dev = dev_get_drvdata(dev); 217 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
242 struct isl29018_chip *chip = iio_priv(indio_dev); 218 struct isl29018_chip *chip = iio_priv(indio_dev);
243 219
244 return sprintf(buf, "%u\n", chip->range); 220 return sprintf(buf, "%u\n", chip->range);
@@ -247,9 +223,8 @@ static ssize_t show_range(struct device *dev,
247static ssize_t store_range(struct device *dev, 223static ssize_t store_range(struct device *dev,
248 struct device_attribute *attr, const char *buf, size_t count) 224 struct device_attribute *attr, const char *buf, size_t count)
249{ 225{
250 struct iio_dev *indio_dev = dev_get_drvdata(dev); 226 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
251 struct isl29018_chip *chip = iio_priv(indio_dev); 227 struct isl29018_chip *chip = iio_priv(indio_dev);
252 struct i2c_client *client = chip->client;
253 int status; 228 int status;
254 unsigned long lval; 229 unsigned long lval;
255 unsigned int new_range; 230 unsigned int new_range;
@@ -264,10 +239,11 @@ static ssize_t store_range(struct device *dev,
264 } 239 }
265 240
266 mutex_lock(&chip->lock); 241 mutex_lock(&chip->lock);
267 status = isl29018_set_range(client, lval, &new_range); 242 status = isl29018_set_range(chip, lval, &new_range);
268 if (status < 0) { 243 if (status < 0) {
269 mutex_unlock(&chip->lock); 244 mutex_unlock(&chip->lock);
270 dev_err(dev, "Error in setting max range\n"); 245 dev_err(dev,
246 "Error in setting max range with err %d\n", status);
271 return status; 247 return status;
272 } 248 }
273 chip->range = new_range; 249 chip->range = new_range;
@@ -280,7 +256,7 @@ static ssize_t store_range(struct device *dev,
280static ssize_t show_resolution(struct device *dev, 256static ssize_t show_resolution(struct device *dev,
281 struct device_attribute *attr, char *buf) 257 struct device_attribute *attr, char *buf)
282{ 258{
283 struct iio_dev *indio_dev = dev_get_drvdata(dev); 259 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
284 struct isl29018_chip *chip = iio_priv(indio_dev); 260 struct isl29018_chip *chip = iio_priv(indio_dev);
285 261
286 return sprintf(buf, "%u\n", chip->adc_bit); 262 return sprintf(buf, "%u\n", chip->adc_bit);
@@ -289,9 +265,8 @@ static ssize_t show_resolution(struct device *dev,
289static ssize_t store_resolution(struct device *dev, 265static ssize_t store_resolution(struct device *dev,
290 struct device_attribute *attr, const char *buf, size_t count) 266 struct device_attribute *attr, const char *buf, size_t count)
291{ 267{
292 struct iio_dev *indio_dev = dev_get_drvdata(dev); 268 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
293 struct isl29018_chip *chip = iio_priv(indio_dev); 269 struct isl29018_chip *chip = iio_priv(indio_dev);
294 struct i2c_client *client = chip->client;
295 int status; 270 int status;
296 unsigned long lval; 271 unsigned long lval;
297 unsigned int new_adc_bit; 272 unsigned int new_adc_bit;
@@ -304,7 +279,7 @@ static ssize_t store_resolution(struct device *dev,
304 } 279 }
305 280
306 mutex_lock(&chip->lock); 281 mutex_lock(&chip->lock);
307 status = isl29018_set_resolution(client, lval, &new_adc_bit); 282 status = isl29018_set_resolution(chip, lval, &new_adc_bit);
308 if (status < 0) { 283 if (status < 0) {
309 mutex_unlock(&chip->lock); 284 mutex_unlock(&chip->lock);
310 dev_err(dev, "Error in setting resolution\n"); 285 dev_err(dev, "Error in setting resolution\n");
@@ -320,7 +295,7 @@ static ssize_t store_resolution(struct device *dev,
320static ssize_t show_prox_infrared_supression(struct device *dev, 295static ssize_t show_prox_infrared_supression(struct device *dev,
321 struct device_attribute *attr, char *buf) 296 struct device_attribute *attr, char *buf)
322{ 297{
323 struct iio_dev *indio_dev = dev_get_drvdata(dev); 298 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
324 struct isl29018_chip *chip = iio_priv(indio_dev); 299 struct isl29018_chip *chip = iio_priv(indio_dev);
325 300
326 /* return the "proximity scheme" i.e. if the chip does on chip 301 /* return the "proximity scheme" i.e. if the chip does on chip
@@ -331,7 +306,7 @@ static ssize_t show_prox_infrared_supression(struct device *dev,
331static ssize_t store_prox_infrared_supression(struct device *dev, 306static ssize_t store_prox_infrared_supression(struct device *dev,
332 struct device_attribute *attr, const char *buf, size_t count) 307 struct device_attribute *attr, const char *buf, size_t count)
333{ 308{
334 struct iio_dev *indio_dev = dev_get_drvdata(dev); 309 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
335 struct isl29018_chip *chip = iio_priv(indio_dev); 310 struct isl29018_chip *chip = iio_priv(indio_dev);
336 unsigned long lval; 311 unsigned long lval;
337 312
@@ -379,20 +354,20 @@ static int isl29018_read_raw(struct iio_dev *indio_dev,
379{ 354{
380 int ret = -EINVAL; 355 int ret = -EINVAL;
381 struct isl29018_chip *chip = iio_priv(indio_dev); 356 struct isl29018_chip *chip = iio_priv(indio_dev);
382 struct i2c_client *client = chip->client;
383 357
384 mutex_lock(&chip->lock); 358 mutex_lock(&chip->lock);
385 switch (mask) { 359 switch (mask) {
386 case 0: 360 case IIO_CHAN_INFO_RAW:
361 case IIO_CHAN_INFO_PROCESSED:
387 switch (chan->type) { 362 switch (chan->type) {
388 case IIO_LIGHT: 363 case IIO_LIGHT:
389 ret = isl29018_read_lux(client, val); 364 ret = isl29018_read_lux(chip, val);
390 break; 365 break;
391 case IIO_INTENSITY: 366 case IIO_INTENSITY:
392 ret = isl29018_read_ir(client, val); 367 ret = isl29018_read_ir(chip, val);
393 break; 368 break;
394 case IIO_PROXIMITY: 369 case IIO_PROXIMITY:
395 ret = isl29018_read_proximity_ir(client, 370 ret = isl29018_read_proximity_ir(chip,
396 chip->prox_scheme, val); 371 chip->prox_scheme, val);
397 break; 372 break;
398 default: 373 default:
@@ -419,15 +394,17 @@ static const struct iio_chan_spec isl29018_channels[] = {
419 .type = IIO_LIGHT, 394 .type = IIO_LIGHT,
420 .indexed = 1, 395 .indexed = 1,
421 .channel = 0, 396 .channel = 0,
422 .processed_val = IIO_PROCESSED, 397 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT |
423 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, 398 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
424 }, { 399 }, {
425 .type = IIO_INTENSITY, 400 .type = IIO_INTENSITY,
426 .modified = 1, 401 .modified = 1,
402 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
427 .channel2 = IIO_MOD_LIGHT_IR, 403 .channel2 = IIO_MOD_LIGHT_IR,
428 }, { 404 }, {
429 /* Unindexed in current ABI. But perhaps it should be. */ 405 /* Unindexed in current ABI. But perhaps it should be. */
430 .type = IIO_PROXIMITY, 406 .type = IIO_PROXIMITY,
407 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
431 } 408 }
432}; 409};
433 410
@@ -456,15 +433,12 @@ static const struct attribute_group isl29108_group = {
456 .attrs = isl29018_attributes, 433 .attrs = isl29018_attributes,
457}; 434};
458 435
459static int isl29018_chip_init(struct i2c_client *client) 436static int isl29018_chip_init(struct isl29018_chip *chip)
460{ 437{
461 struct isl29018_chip *chip = iio_priv(i2c_get_clientdata(client));
462 int status; 438 int status;
463 int new_adc_bit; 439 int new_adc_bit;
464 unsigned int new_range; 440 unsigned int new_range;
465 441
466 memset(chip->reg_cache, 0, sizeof(chip->reg_cache));
467
468 /* Code added per Intersil Application Note 1534: 442 /* Code added per Intersil Application Note 1534:
469 * When VDD sinks to approximately 1.8V or below, some of 443 * When VDD sinks to approximately 1.8V or below, some of
470 * the part's registers may change their state. When VDD 444 * the part's registers may change their state. When VDD
@@ -485,10 +459,9 @@ static int isl29018_chip_init(struct i2c_client *client)
485 * the same thing EXCEPT the data sheet asks for a 1ms delay after 459 * the same thing EXCEPT the data sheet asks for a 1ms delay after
486 * writing the CMD1 register. 460 * writing the CMD1 register.
487 */ 461 */
488 status = isl29018_write_data(client, ISL29018_REG_TEST, 0, 462 status = regmap_write(chip->regmap, ISL29018_REG_TEST, 0x0);
489 ISL29018_TEST_MASK, ISL29018_TEST_SHIFT);
490 if (status < 0) { 463 if (status < 0) {
491 dev_err(&client->dev, "Failed to clear isl29018 TEST reg." 464 dev_err(chip->dev, "Failed to clear isl29018 TEST reg."
492 "(%d)\n", status); 465 "(%d)\n", status);
493 return status; 466 return status;
494 } 467 }
@@ -497,10 +470,9 @@ static int isl29018_chip_init(struct i2c_client *client)
497 * "Operating Mode" (COMMAND1) register is reprogrammed when 470 * "Operating Mode" (COMMAND1) register is reprogrammed when
498 * data is read from the device. 471 * data is read from the device.
499 */ 472 */
500 status = isl29018_write_data(client, ISL29018_REG_ADD_COMMAND1, 0, 473 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 0);
501 0xff, 0);
502 if (status < 0) { 474 if (status < 0) {
503 dev_err(&client->dev, "Failed to clear isl29018 CMD1 reg." 475 dev_err(chip->dev, "Failed to clear isl29018 CMD1 reg."
504 "(%d)\n", status); 476 "(%d)\n", status);
505 return status; 477 return status;
506 } 478 }
@@ -508,13 +480,13 @@ static int isl29018_chip_init(struct i2c_client *client)
508 msleep(1); /* per data sheet, page 10 */ 480 msleep(1); /* per data sheet, page 10 */
509 481
510 /* set defaults */ 482 /* set defaults */
511 status = isl29018_set_range(client, chip->range, &new_range); 483 status = isl29018_set_range(chip, chip->range, &new_range);
512 if (status < 0) { 484 if (status < 0) {
513 dev_err(&client->dev, "Init of isl29018 fails\n"); 485 dev_err(chip->dev, "Init of isl29018 fails\n");
514 return status; 486 return status;
515 } 487 }
516 488
517 status = isl29018_set_resolution(client, chip->adc_bit, 489 status = isl29018_set_resolution(chip, chip->adc_bit,
518 &new_adc_bit); 490 &new_adc_bit);
519 491
520 return 0; 492 return 0;
@@ -527,6 +499,32 @@ static const struct iio_info isl29108_info = {
527 .write_raw = &isl29018_write_raw, 499 .write_raw = &isl29018_write_raw,
528}; 500};
529 501
502static bool is_volatile_reg(struct device *dev, unsigned int reg)
503{
504 switch (reg) {
505 case ISL29018_REG_ADD_DATA_LSB:
506 case ISL29018_REG_ADD_DATA_MSB:
507 case ISL29018_REG_ADD_COMMAND1:
508 case ISL29018_REG_TEST:
509 return true;
510 default:
511 return false;
512 }
513}
514
515/*
516 * isl29018_regmap_config: regmap configuration.
517 * Use RBTREE mechanism for caching.
518 */
519static const struct regmap_config isl29018_regmap_config = {
520 .reg_bits = 8,
521 .val_bits = 8,
522 .volatile_reg = is_volatile_reg,
523 .max_register = ISL29018_REG_TEST,
524 .num_reg_defaults_raw = ISL29018_REG_TEST + 1,
525 .cache_type = REGCACHE_RBTREE,
526};
527
530static int __devinit isl29018_probe(struct i2c_client *client, 528static int __devinit isl29018_probe(struct i2c_client *client,
531 const struct i2c_device_id *id) 529 const struct i2c_device_id *id)
532{ 530{
@@ -534,7 +532,7 @@ static int __devinit isl29018_probe(struct i2c_client *client,
534 struct iio_dev *indio_dev; 532 struct iio_dev *indio_dev;
535 int err; 533 int err;
536 534
537 indio_dev = iio_allocate_device(sizeof(*chip)); 535 indio_dev = iio_device_alloc(sizeof(*chip));
538 if (indio_dev == NULL) { 536 if (indio_dev == NULL) {
539 dev_err(&client->dev, "iio allocation fails\n"); 537 dev_err(&client->dev, "iio allocation fails\n");
540 err = -ENOMEM; 538 err = -ENOMEM;
@@ -543,7 +541,7 @@ static int __devinit isl29018_probe(struct i2c_client *client,
543 chip = iio_priv(indio_dev); 541 chip = iio_priv(indio_dev);
544 542
545 i2c_set_clientdata(client, indio_dev); 543 i2c_set_clientdata(client, indio_dev);
546 chip->client = client; 544 chip->dev = &client->dev;
547 545
548 mutex_init(&chip->lock); 546 mutex_init(&chip->lock);
549 547
@@ -551,7 +549,14 @@ static int __devinit isl29018_probe(struct i2c_client *client,
551 chip->range = 1000; 549 chip->range = 1000;
552 chip->adc_bit = 16; 550 chip->adc_bit = 16;
553 551
554 err = isl29018_chip_init(client); 552 chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config);
553 if (IS_ERR(chip->regmap)) {
554 err = PTR_ERR(chip->regmap);
555 dev_err(chip->dev, "regmap initialization failed: %d\n", err);
556 goto exit;
557 }
558
559 err = isl29018_chip_init(chip);
555 if (err) 560 if (err)
556 goto exit_iio_free; 561 goto exit_iio_free;
557 562
@@ -569,7 +574,7 @@ static int __devinit isl29018_probe(struct i2c_client *client,
569 574
570 return 0; 575 return 0;
571exit_iio_free: 576exit_iio_free:
572 iio_free_device(indio_dev); 577 iio_device_free(indio_dev);
573exit: 578exit:
574 return err; 579 return err;
575} 580}
@@ -580,7 +585,7 @@ static int __devexit isl29018_remove(struct i2c_client *client)
580 585
581 dev_dbg(&client->dev, "%s()\n", __func__); 586 dev_dbg(&client->dev, "%s()\n", __func__);
582 iio_device_unregister(indio_dev); 587 iio_device_unregister(indio_dev);
583 iio_free_device(indio_dev); 588 iio_device_free(indio_dev);
584 589
585 return 0; 590 return 0;
586} 591}
@@ -593,7 +598,7 @@ static const struct i2c_device_id isl29018_id[] = {
593MODULE_DEVICE_TABLE(i2c, isl29018_id); 598MODULE_DEVICE_TABLE(i2c, isl29018_id);
594 599
595static const struct of_device_id isl29018_of_match[] = { 600static const struct of_device_id isl29018_of_match[] = {
596 { .compatible = "invn,isl29018", }, 601 { .compatible = "isil,isl29018", },
597 { }, 602 { },
598}; 603};
599MODULE_DEVICE_TABLE(of, isl29018_of_match); 604MODULE_DEVICE_TABLE(of, isl29018_of_match);
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
new file mode 100644
index 000000000000..33a4c3f94a14
--- /dev/null
+++ b/drivers/staging/iio/light/isl29028.c
@@ -0,0 +1,566 @@
1/*
2 * IIO driver for the light sensor ISL29028.
3 * ISL29028 is Concurrent Ambient Light and Proximity Sensor
4 *
5 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope 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
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/module.h>
21#include <linux/i2c.h>
22#include <linux/err.h>
23#include <linux/mutex.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/regmap.h>
27#include <linux/iio/iio.h>
28#include <linux/iio/sysfs.h>
29
30#define CONVERSION_TIME_MS 100
31
32#define ISL29028_REG_CONFIGURE 0x01
33
34#define CONFIGURE_ALS_IR_MODE_ALS 0
35#define CONFIGURE_ALS_IR_MODE_IR BIT(0)
36#define CONFIGURE_ALS_IR_MODE_MASK BIT(0)
37
38#define CONFIGURE_ALS_RANGE_LOW_LUX 0
39#define CONFIGURE_ALS_RANGE_HIGH_LUX BIT(1)
40#define CONFIGURE_ALS_RANGE_MASK BIT(1)
41
42#define CONFIGURE_ALS_DIS 0
43#define CONFIGURE_ALS_EN BIT(2)
44#define CONFIGURE_ALS_EN_MASK BIT(2)
45
46#define CONFIGURE_PROX_DRIVE BIT(3)
47
48#define CONFIGURE_PROX_SLP_SH 4
49#define CONFIGURE_PROX_SLP_MASK (7 << CONFIGURE_PROX_SLP_SH)
50
51#define CONFIGURE_PROX_EN BIT(7)
52#define CONFIGURE_PROX_EN_MASK BIT(7)
53
54#define ISL29028_REG_INTERRUPT 0x02
55
56#define ISL29028_REG_PROX_DATA 0x08
57#define ISL29028_REG_ALSIR_L 0x09
58#define ISL29028_REG_ALSIR_U 0x0A
59
60#define ISL29028_REG_TEST1_MODE 0x0E
61#define ISL29028_REG_TEST2_MODE 0x0F
62
63#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1)
64
65enum als_ir_mode {
66 MODE_NONE = 0,
67 MODE_ALS,
68 MODE_IR
69};
70
71struct isl29028_chip {
72 struct device *dev;
73 struct mutex lock;
74 struct regmap *regmap;
75
76 unsigned int prox_sampling;
77 bool enable_prox;
78
79 int lux_scale;
80 int als_ir_mode;
81};
82
83static int isl29028_set_proxim_sampling(struct isl29028_chip *chip,
84 unsigned int sampling)
85{
86 static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0};
87 int sel;
88 unsigned int period = DIV_ROUND_UP(1000, sampling);
89
90 for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) {
91 if (period >= prox_period[sel])
92 break;
93 }
94 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
95 CONFIGURE_PROX_SLP_MASK, sel << CONFIGURE_PROX_SLP_SH);
96}
97
98static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable)
99{
100 int ret;
101 int val = 0;
102
103 if (enable)
104 val = CONFIGURE_PROX_EN;
105 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
106 CONFIGURE_PROX_EN_MASK, val);
107 if (ret < 0)
108 return ret;
109
110 /* Wait for conversion to be complete for first sample */
111 mdelay(DIV_ROUND_UP(1000, chip->prox_sampling));
112 return 0;
113}
114
115static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale)
116{
117 int val = (lux_scale == 2000) ? CONFIGURE_ALS_RANGE_HIGH_LUX :
118 CONFIGURE_ALS_RANGE_LOW_LUX;
119
120 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
121 CONFIGURE_ALS_RANGE_MASK, val);
122}
123
124static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
125 enum als_ir_mode mode)
126{
127 int ret = 0;
128
129 switch (mode) {
130 case MODE_ALS:
131 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
132 CONFIGURE_ALS_IR_MODE_MASK, CONFIGURE_ALS_IR_MODE_ALS);
133 if (ret < 0)
134 return ret;
135
136 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
137 CONFIGURE_ALS_RANGE_MASK, CONFIGURE_ALS_RANGE_HIGH_LUX);
138 break;
139
140 case MODE_IR:
141 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
142 CONFIGURE_ALS_IR_MODE_MASK, CONFIGURE_ALS_IR_MODE_IR);
143 break;
144
145 case MODE_NONE:
146 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
147 CONFIGURE_ALS_EN_MASK, CONFIGURE_ALS_DIS);
148 }
149
150 if (ret < 0)
151 return ret;
152
153 /* Enable the ALS/IR */
154 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
155 CONFIGURE_ALS_EN_MASK, CONFIGURE_ALS_EN);
156 if (ret < 0)
157 return ret;
158
159 /* Need to wait for conversion time if ALS/IR mode enabled */
160 mdelay(CONVERSION_TIME_MS);
161 return 0;
162}
163
164static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir)
165{
166 unsigned int lsb;
167 unsigned int msb;
168 int ret;
169
170 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb);
171 if (ret < 0) {
172 dev_err(chip->dev,
173 "Error in reading register ALSIR_L err %d\n", ret);
174 return ret;
175 }
176
177 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb);
178 if (ret < 0) {
179 dev_err(chip->dev,
180 "Error in reading register ALSIR_U err %d\n", ret);
181 return ret;
182 }
183
184 *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF);
185 return 0;
186}
187
188static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox)
189{
190 unsigned int data;
191 int ret;
192
193 ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data);
194 if (ret < 0) {
195 dev_err(chip->dev, "Error in reading register %d, error %d\n",
196 ISL29028_REG_PROX_DATA, ret);
197 return ret;
198 }
199 *prox = data;
200 return 0;
201}
202
203static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data)
204{
205 int ret;
206
207 if (!chip->enable_prox) {
208 ret = isl29028_enable_proximity(chip, true);
209 if (ret < 0)
210 return ret;
211 chip->enable_prox = true;
212 }
213 return isl29028_read_proxim(chip, prox_data);
214}
215
216static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
217{
218 int ret;
219 int als_ir_data;
220
221 if (chip->als_ir_mode != MODE_ALS) {
222 ret = isl29028_set_als_ir_mode(chip, MODE_ALS);
223 if (ret < 0) {
224 dev_err(chip->dev,
225 "Error in enabling ALS mode err %d\n", ret);
226 return ret;
227 }
228 chip->als_ir_mode = MODE_ALS;
229 }
230
231 ret = isl29028_read_als_ir(chip, &als_ir_data);
232 if (ret < 0)
233 return ret;
234
235 /*
236 * convert als data count to lux.
237 * if lux_scale = 125, lux = count * 0.031
238 * if lux_scale = 2000, lux = count * 0.49
239 */
240 if (chip->lux_scale == 125)
241 als_ir_data = (als_ir_data * 31) / 1000;
242 else
243 als_ir_data = (als_ir_data * 49) / 100;
244
245 *als_data = als_ir_data;
246 return 0;
247}
248
249static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
250{
251 int ret;
252
253 if (chip->als_ir_mode != MODE_IR) {
254 ret = isl29028_set_als_ir_mode(chip, MODE_IR);
255 if (ret < 0) {
256 dev_err(chip->dev,
257 "Error in enabling IR mode err %d\n", ret);
258 return ret;
259 }
260 chip->als_ir_mode = MODE_IR;
261 }
262 return isl29028_read_als_ir(chip, ir_data);
263}
264
265/* Channel IO */
266static int isl29028_write_raw(struct iio_dev *indio_dev,
267 struct iio_chan_spec const *chan, int val, int val2, long mask)
268{
269 struct isl29028_chip *chip = iio_priv(indio_dev);
270 int ret = -EINVAL;
271
272 mutex_lock(&chip->lock);
273 switch (chan->type) {
274 case IIO_PROXIMITY:
275 if (mask != IIO_CHAN_INFO_SAMP_FREQ) {
276 dev_err(chip->dev,
277 "proximity: mask value 0x%08lx not supported\n",
278 mask);
279 break;
280 }
281 if (val < 1 || val > 100) {
282 dev_err(chip->dev,
283 "Samp_freq %d is not in range[1:100]\n", val);
284 break;
285 }
286 ret = isl29028_set_proxim_sampling(chip, val);
287 if (ret < 0) {
288 dev_err(chip->dev,
289 "Setting proximity samp_freq fail, err %d\n",
290 ret);
291 break;
292 }
293 chip->prox_sampling = val;
294 break;
295
296 case IIO_LIGHT:
297 if (mask != IIO_CHAN_INFO_SCALE) {
298 dev_err(chip->dev,
299 "light: mask value 0x%08lx not supported\n",
300 mask);
301 break;
302 }
303 if ((val != 125) && (val != 2000)) {
304 dev_err(chip->dev,
305 "lux scale %d is invalid [125, 2000]\n", val);
306 break;
307 }
308 ret = isl29028_set_als_scale(chip, val);
309 if (ret < 0) {
310 dev_err(chip->dev,
311 "Setting lux scale fail with error %d\n", ret);
312 break;
313 }
314 chip->lux_scale = val;
315 break;
316
317 default:
318 dev_err(chip->dev, "Unsupported channel type\n");
319 break;
320 }
321 mutex_unlock(&chip->lock);
322 return ret;
323}
324
325static int isl29028_read_raw(struct iio_dev *indio_dev,
326 struct iio_chan_spec const *chan, int *val, int *val2, long mask)
327{
328 struct isl29028_chip *chip = iio_priv(indio_dev);
329 int ret = -EINVAL;
330
331 mutex_lock(&chip->lock);
332 switch (mask) {
333 case IIO_CHAN_INFO_RAW:
334 case IIO_CHAN_INFO_PROCESSED:
335 switch (chan->type) {
336 case IIO_LIGHT:
337 ret = isl29028_als_get(chip, val);
338 break;
339 case IIO_INTENSITY:
340 ret = isl29028_ir_get(chip, val);
341 break;
342 case IIO_PROXIMITY:
343 ret = isl29028_proxim_get(chip, val);
344 break;
345 default:
346 break;
347 }
348 if (ret < 0)
349 break;
350 ret = IIO_VAL_INT;
351 break;
352
353 case IIO_CHAN_INFO_SAMP_FREQ:
354 if (chan->type != IIO_PROXIMITY)
355 break;
356 *val = chip->prox_sampling;
357 ret = IIO_VAL_INT;
358 break;
359
360 case IIO_CHAN_INFO_SCALE:
361 if (chan->type != IIO_LIGHT)
362 break;
363 *val = chip->lux_scale;
364 ret = IIO_VAL_INT;
365 break;
366
367 default:
368 dev_err(chip->dev, "mask value 0x%08lx not supported\n", mask);
369 break;
370 }
371 mutex_unlock(&chip->lock);
372 return ret;
373}
374
375static IIO_CONST_ATTR(in_proximity_sampling_frequency_available,
376 "1, 3, 5, 10, 13, 20, 83, 100");
377static IIO_CONST_ATTR(in_illuminance_scale_available, "125, 2000");
378
379#define ISL29028_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
380#define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr)
381static struct attribute *isl29028_attributes[] = {
382 ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available),
383 ISL29028_CONST_ATTR(in_illuminance_scale_available),
384 NULL,
385};
386
387static const struct attribute_group isl29108_group = {
388 .attrs = isl29028_attributes,
389};
390
391static const struct iio_chan_spec isl29028_channels[] = {
392 {
393 .type = IIO_LIGHT,
394 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT |
395 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
396 }, {
397 .type = IIO_INTENSITY,
398 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
399 }, {
400 .type = IIO_PROXIMITY,
401 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
402 IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT,
403 }
404};
405
406static const struct iio_info isl29028_info = {
407 .attrs = &isl29108_group,
408 .driver_module = THIS_MODULE,
409 .read_raw = &isl29028_read_raw,
410 .write_raw = &isl29028_write_raw,
411};
412
413static int isl29028_chip_init(struct isl29028_chip *chip)
414{
415 int ret;
416
417 chip->enable_prox = false;
418 chip->prox_sampling = 20;
419 chip->lux_scale = 2000;
420 chip->als_ir_mode = MODE_NONE;
421
422 ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0);
423 if (ret < 0) {
424 dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n",
425 __func__, ISL29028_REG_TEST1_MODE, ret);
426 return ret;
427 }
428 ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0);
429 if (ret < 0) {
430 dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n",
431 __func__, ISL29028_REG_TEST2_MODE, ret);
432 return ret;
433 }
434
435 ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0);
436 if (ret < 0) {
437 dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n",
438 __func__, ISL29028_REG_CONFIGURE, ret);
439 return ret;
440 }
441
442 ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling);
443 if (ret < 0) {
444 dev_err(chip->dev, "%s(): setting the proximity, err = %d\n",
445 __func__, ret);
446 return ret;
447 }
448
449 ret = isl29028_set_als_scale(chip, chip->lux_scale);
450 if (ret < 0)
451 dev_err(chip->dev, "%s(): setting als scale failed, err = %d\n",
452 __func__, ret);
453 return ret;
454}
455
456static bool is_volatile_reg(struct device *dev, unsigned int reg)
457{
458 switch (reg) {
459 case ISL29028_REG_INTERRUPT:
460 case ISL29028_REG_PROX_DATA:
461 case ISL29028_REG_ALSIR_L:
462 case ISL29028_REG_ALSIR_U:
463 return true;
464 default:
465 return false;
466 }
467}
468
469static const struct regmap_config isl29028_regmap_config = {
470 .reg_bits = 8,
471 .val_bits = 8,
472 .volatile_reg = is_volatile_reg,
473 .max_register = ISL29028_NUM_REGS - 1,
474 .num_reg_defaults_raw = ISL29028_NUM_REGS,
475 .cache_type = REGCACHE_RBTREE,
476};
477
478static int __devinit isl29028_probe(struct i2c_client *client,
479 const struct i2c_device_id *id)
480{
481 struct isl29028_chip *chip;
482 struct iio_dev *indio_dev;
483 int ret;
484
485 indio_dev = iio_device_alloc(sizeof(*chip));
486 if (!indio_dev) {
487 dev_err(&client->dev, "iio allocation fails\n");
488 return -ENOMEM;
489 }
490
491 chip = iio_priv(indio_dev);
492
493 i2c_set_clientdata(client, indio_dev);
494 chip->dev = &client->dev;
495 mutex_init(&chip->lock);
496
497 chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config);
498 if (IS_ERR(chip->regmap)) {
499 ret = PTR_ERR(chip->regmap);
500 dev_err(chip->dev, "regmap initialization failed: %d\n", ret);
501 goto exit_iio_free;
502 }
503
504 ret = isl29028_chip_init(chip);
505 if (ret < 0) {
506 dev_err(chip->dev, "chip initialization failed: %d\n", ret);
507 goto exit_iio_free;
508 }
509
510 indio_dev->info = &isl29028_info;
511 indio_dev->channels = isl29028_channels;
512 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels);
513 indio_dev->name = id->name;
514 indio_dev->dev.parent = &client->dev;
515 indio_dev->modes = INDIO_DIRECT_MODE;
516 ret = iio_device_register(indio_dev);
517 if (ret < 0) {
518 dev_err(chip->dev, "iio registration fails with error %d\n",
519 ret);
520 goto exit_iio_free;
521 }
522 return 0;
523
524exit_iio_free:
525 iio_device_free(indio_dev);
526 return ret;
527}
528
529static int __devexit isl29028_remove(struct i2c_client *client)
530{
531 struct iio_dev *indio_dev = i2c_get_clientdata(client);
532
533 iio_device_unregister(indio_dev);
534 iio_device_free(indio_dev);
535 return 0;
536}
537
538static const struct i2c_device_id isl29028_id[] = {
539 {"isl29028", 0},
540 {}
541};
542MODULE_DEVICE_TABLE(i2c, isl29028_id);
543
544static const struct of_device_id isl29028_of_match[] = {
545 { .compatible = "isil,isl29028", },
546 { },
547};
548MODULE_DEVICE_TABLE(of, isl29028_of_match);
549
550static struct i2c_driver isl29028_driver = {
551 .class = I2C_CLASS_HWMON,
552 .driver = {
553 .name = "isl29028",
554 .owner = THIS_MODULE,
555 .of_match_table = isl29028_of_match,
556 },
557 .probe = isl29028_probe,
558 .remove = __devexit_p(isl29028_remove),
559 .id_table = isl29028_id,
560};
561
562module_i2c_driver(isl29028_driver);
563
564MODULE_DESCRIPTION("ISL29028 Ambient Light and Proximity Sensor driver");
565MODULE_LICENSE("GPL v2");
566MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index 546c95a4ea9e..9d740be43a82 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -35,9 +35,9 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
38#include "../iio.h" 38#include <linux/iio/iio.h>
39#include "../sysfs.h" 39#include <linux/iio/sysfs.h>
40#include "../events.h" 40#include <linux/iio/events.h>
41#include "tsl2563.h" 41#include "tsl2563.h"
42 42
43/* Use this many bits for fraction part. */ 43/* Use this many bits for fraction part. */
@@ -465,7 +465,7 @@ static int tsl2563_write_raw(struct iio_dev *indio_dev,
465{ 465{
466 struct tsl2563_chip *chip = iio_priv(indio_dev); 466 struct tsl2563_chip *chip = iio_priv(indio_dev);
467 467
468 if (chan->channel == 0) 468 if (chan->channel == IIO_MOD_LIGHT_BOTH)
469 chip->calib0 = calib_from_sysfs(val); 469 chip->calib0 = calib_from_sysfs(val);
470 else 470 else
471 chip->calib1 = calib_from_sysfs(val); 471 chip->calib1 = calib_from_sysfs(val);
@@ -485,7 +485,8 @@ static int tsl2563_read_raw(struct iio_dev *indio_dev,
485 485
486 mutex_lock(&chip->lock); 486 mutex_lock(&chip->lock);
487 switch (m) { 487 switch (m) {
488 case 0: 488 case IIO_CHAN_INFO_RAW:
489 case IIO_CHAN_INFO_PROCESSED:
489 switch (chan->type) { 490 switch (chan->type) {
490 case IIO_LIGHT: 491 case IIO_LIGHT:
491 ret = tsl2563_get_adc(chip); 492 ret = tsl2563_get_adc(chip);
@@ -534,12 +535,14 @@ static const struct iio_chan_spec tsl2563_channels[] = {
534 { 535 {
535 .type = IIO_LIGHT, 536 .type = IIO_LIGHT,
536 .indexed = 1, 537 .indexed = 1,
538 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
537 .channel = 0, 539 .channel = 0,
538 }, { 540 }, {
539 .type = IIO_INTENSITY, 541 .type = IIO_INTENSITY,
540 .modified = 1, 542 .modified = 1,
541 .channel2 = IIO_MOD_LIGHT_BOTH, 543 .channel2 = IIO_MOD_LIGHT_BOTH,
542 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, 544 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
545 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
543 .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH, 546 .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH,
544 IIO_EV_DIR_RISING) | 547 IIO_EV_DIR_RISING) |
545 IIO_EV_BIT(IIO_EV_TYPE_THRESH, 548 IIO_EV_BIT(IIO_EV_TYPE_THRESH,
@@ -548,7 +551,8 @@ static const struct iio_chan_spec tsl2563_channels[] = {
548 .type = IIO_INTENSITY, 551 .type = IIO_INTENSITY,
549 .modified = 1, 552 .modified = 1,
550 .channel2 = IIO_MOD_LIGHT_IR, 553 .channel2 = IIO_MOD_LIGHT_IR,
551 .info_mask = IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, 554 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
555 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
552 } 556 }
553}; 557};
554 558
@@ -710,7 +714,7 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
710 int err = 0; 714 int err = 0;
711 u8 id = 0; 715 u8 id = 0;
712 716
713 indio_dev = iio_allocate_device(sizeof(*chip)); 717 indio_dev = iio_device_alloc(sizeof(*chip));
714 if (!indio_dev) 718 if (!indio_dev)
715 return -ENOMEM; 719 return -ENOMEM;
716 720
@@ -797,7 +801,7 @@ fail2:
797 if (client->irq) 801 if (client->irq)
798 free_irq(client->irq, indio_dev); 802 free_irq(client->irq, indio_dev);
799fail1: 803fail1:
800 iio_free_device(indio_dev); 804 iio_device_free(indio_dev);
801 return err; 805 return err;
802} 806}
803 807
@@ -818,7 +822,7 @@ static int tsl2563_remove(struct i2c_client *client)
818 if (client->irq) 822 if (client->irq)
819 free_irq(client->irq, indio_dev); 823 free_irq(client->irq, indio_dev);
820 824
821 iio_free_device(indio_dev); 825 iio_device_free(indio_dev);
822 826
823 return 0; 827 return 0;
824} 828}
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 8671d98e0448..5e23ad5a30d5 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -28,7 +28,7 @@
28#include <linux/unistd.h> 28#include <linux/unistd.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include "../iio.h" 31#include <linux/iio/iio.h>
32 32
33#define TSL258X_MAX_DEVICE_REGS 32 33#define TSL258X_MAX_DEVICE_REGS 32
34 34
@@ -483,7 +483,7 @@ static int taos_chip_off(struct iio_dev *indio_dev)
483static ssize_t taos_power_state_show(struct device *dev, 483static ssize_t taos_power_state_show(struct device *dev,
484 struct device_attribute *attr, char *buf) 484 struct device_attribute *attr, char *buf)
485{ 485{
486 struct iio_dev *indio_dev = dev_get_drvdata(dev); 486 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
487 struct tsl2583_chip *chip = iio_priv(indio_dev); 487 struct tsl2583_chip *chip = iio_priv(indio_dev);
488 488
489 return sprintf(buf, "%d\n", chip->taos_chip_status); 489 return sprintf(buf, "%d\n", chip->taos_chip_status);
@@ -492,7 +492,7 @@ static ssize_t taos_power_state_show(struct device *dev,
492static ssize_t taos_power_state_store(struct device *dev, 492static ssize_t taos_power_state_store(struct device *dev,
493 struct device_attribute *attr, const char *buf, size_t len) 493 struct device_attribute *attr, const char *buf, size_t len)
494{ 494{
495 struct iio_dev *indio_dev = dev_get_drvdata(dev); 495 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
496 unsigned long value; 496 unsigned long value;
497 497
498 if (strict_strtoul(buf, 0, &value)) 498 if (strict_strtoul(buf, 0, &value))
@@ -509,7 +509,7 @@ static ssize_t taos_power_state_store(struct device *dev,
509static ssize_t taos_gain_show(struct device *dev, 509static ssize_t taos_gain_show(struct device *dev,
510 struct device_attribute *attr, char *buf) 510 struct device_attribute *attr, char *buf)
511{ 511{
512 struct iio_dev *indio_dev = dev_get_drvdata(dev); 512 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
513 struct tsl2583_chip *chip = iio_priv(indio_dev); 513 struct tsl2583_chip *chip = iio_priv(indio_dev);
514 char gain[4] = {0}; 514 char gain[4] = {0};
515 515
@@ -534,7 +534,7 @@ static ssize_t taos_gain_show(struct device *dev,
534static ssize_t taos_gain_store(struct device *dev, 534static ssize_t taos_gain_store(struct device *dev,
535 struct device_attribute *attr, const char *buf, size_t len) 535 struct device_attribute *attr, const char *buf, size_t len)
536{ 536{
537 struct iio_dev *indio_dev = dev_get_drvdata(dev); 537 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
538 struct tsl2583_chip *chip = iio_priv(indio_dev); 538 struct tsl2583_chip *chip = iio_priv(indio_dev);
539 unsigned long value; 539 unsigned long value;
540 540
@@ -571,7 +571,7 @@ static ssize_t taos_gain_available_show(struct device *dev,
571static ssize_t taos_als_time_show(struct device *dev, 571static ssize_t taos_als_time_show(struct device *dev,
572 struct device_attribute *attr, char *buf) 572 struct device_attribute *attr, char *buf)
573{ 573{
574 struct iio_dev *indio_dev = dev_get_drvdata(dev); 574 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
575 struct tsl2583_chip *chip = iio_priv(indio_dev); 575 struct tsl2583_chip *chip = iio_priv(indio_dev);
576 576
577 return sprintf(buf, "%d\n", chip->taos_settings.als_time); 577 return sprintf(buf, "%d\n", chip->taos_settings.als_time);
@@ -580,7 +580,7 @@ static ssize_t taos_als_time_show(struct device *dev,
580static ssize_t taos_als_time_store(struct device *dev, 580static ssize_t taos_als_time_store(struct device *dev,
581 struct device_attribute *attr, const char *buf, size_t len) 581 struct device_attribute *attr, const char *buf, size_t len)
582{ 582{
583 struct iio_dev *indio_dev = dev_get_drvdata(dev); 583 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
584 struct tsl2583_chip *chip = iio_priv(indio_dev); 584 struct tsl2583_chip *chip = iio_priv(indio_dev);
585 unsigned long value; 585 unsigned long value;
586 586
@@ -608,7 +608,7 @@ static ssize_t taos_als_time_available_show(struct device *dev,
608static ssize_t taos_als_trim_show(struct device *dev, 608static ssize_t taos_als_trim_show(struct device *dev,
609 struct device_attribute *attr, char *buf) 609 struct device_attribute *attr, char *buf)
610{ 610{
611 struct iio_dev *indio_dev = dev_get_drvdata(dev); 611 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
612 struct tsl2583_chip *chip = iio_priv(indio_dev); 612 struct tsl2583_chip *chip = iio_priv(indio_dev);
613 613
614 return sprintf(buf, "%d\n", chip->taos_settings.als_gain_trim); 614 return sprintf(buf, "%d\n", chip->taos_settings.als_gain_trim);
@@ -617,7 +617,7 @@ static ssize_t taos_als_trim_show(struct device *dev,
617static ssize_t taos_als_trim_store(struct device *dev, 617static ssize_t taos_als_trim_store(struct device *dev,
618 struct device_attribute *attr, const char *buf, size_t len) 618 struct device_attribute *attr, const char *buf, size_t len)
619{ 619{
620 struct iio_dev *indio_dev = dev_get_drvdata(dev); 620 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
621 struct tsl2583_chip *chip = iio_priv(indio_dev); 621 struct tsl2583_chip *chip = iio_priv(indio_dev);
622 unsigned long value; 622 unsigned long value;
623 623
@@ -633,7 +633,7 @@ static ssize_t taos_als_trim_store(struct device *dev,
633static ssize_t taos_als_cal_target_show(struct device *dev, 633static ssize_t taos_als_cal_target_show(struct device *dev,
634 struct device_attribute *attr, char *buf) 634 struct device_attribute *attr, char *buf)
635{ 635{
636 struct iio_dev *indio_dev = dev_get_drvdata(dev); 636 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
637 struct tsl2583_chip *chip = iio_priv(indio_dev); 637 struct tsl2583_chip *chip = iio_priv(indio_dev);
638 638
639 return sprintf(buf, "%d\n", chip->taos_settings.als_cal_target); 639 return sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
@@ -642,7 +642,7 @@ static ssize_t taos_als_cal_target_show(struct device *dev,
642static ssize_t taos_als_cal_target_store(struct device *dev, 642static ssize_t taos_als_cal_target_store(struct device *dev,
643 struct device_attribute *attr, const char *buf, size_t len) 643 struct device_attribute *attr, const char *buf, size_t len)
644{ 644{
645 struct iio_dev *indio_dev = dev_get_drvdata(dev); 645 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
646 struct tsl2583_chip *chip = iio_priv(indio_dev); 646 struct tsl2583_chip *chip = iio_priv(indio_dev);
647 unsigned long value; 647 unsigned long value;
648 648
@@ -660,7 +660,7 @@ static ssize_t taos_lux_show(struct device *dev, struct device_attribute *attr,
660{ 660{
661 int ret; 661 int ret;
662 662
663 ret = taos_get_lux(dev_get_drvdata(dev)); 663 ret = taos_get_lux(dev_to_iio_dev(dev));
664 if (ret < 0) 664 if (ret < 0)
665 return ret; 665 return ret;
666 666
@@ -670,7 +670,7 @@ static ssize_t taos_lux_show(struct device *dev, struct device_attribute *attr,
670static ssize_t taos_do_calibrate(struct device *dev, 670static ssize_t taos_do_calibrate(struct device *dev,
671 struct device_attribute *attr, const char *buf, size_t len) 671 struct device_attribute *attr, const char *buf, size_t len)
672{ 672{
673 struct iio_dev *indio_dev = dev_get_drvdata(dev); 673 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
674 unsigned long value; 674 unsigned long value;
675 675
676 if (strict_strtoul(buf, 0, &value)) 676 if (strict_strtoul(buf, 0, &value))
@@ -708,7 +708,7 @@ static ssize_t taos_luxtable_show(struct device *dev,
708static ssize_t taos_luxtable_store(struct device *dev, 708static ssize_t taos_luxtable_store(struct device *dev,
709 struct device_attribute *attr, const char *buf, size_t len) 709 struct device_attribute *attr, const char *buf, size_t len)
710{ 710{
711 struct iio_dev *indio_dev = dev_get_drvdata(dev); 711 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
712 struct tsl2583_chip *chip = iio_priv(indio_dev); 712 struct tsl2583_chip *chip = iio_priv(indio_dev);
713 int value[ARRAY_SIZE(taos_device_lux)*3 + 1]; 713 int value[ARRAY_SIZE(taos_device_lux)*3 + 1];
714 int n; 714 int n;
@@ -815,7 +815,7 @@ static int __devinit taos_probe(struct i2c_client *clientp,
815 return -EOPNOTSUPP; 815 return -EOPNOTSUPP;
816 } 816 }
817 817
818 indio_dev = iio_allocate_device(sizeof(*chip)); 818 indio_dev = iio_device_alloc(sizeof(*chip));
819 if (indio_dev == NULL) { 819 if (indio_dev == NULL) {
820 ret = -ENOMEM; 820 ret = -ENOMEM;
821 dev_err(&clientp->dev, "iio allocation failed\n"); 821 dev_err(&clientp->dev, "iio allocation failed\n");
@@ -879,7 +879,7 @@ static int __devinit taos_probe(struct i2c_client *clientp,
879 dev_info(&clientp->dev, "Light sensor found.\n"); 879 dev_info(&clientp->dev, "Light sensor found.\n");
880 return 0; 880 return 0;
881fail1: 881fail1:
882 iio_free_device(indio_dev); 882 iio_device_free(indio_dev);
883fail2: 883fail2:
884 return ret; 884 return ret;
885} 885}
@@ -926,7 +926,7 @@ static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
926static int __devexit taos_remove(struct i2c_client *client) 926static int __devexit taos_remove(struct i2c_client *client)
927{ 927{
928 iio_device_unregister(i2c_get_clientdata(client)); 928 iio_device_unregister(i2c_get_clientdata(client));
929 iio_free_device(i2c_get_clientdata(client)); 929 iio_device_free(i2c_get_clientdata(client));
930 930
931 return 0; 931 return 0;
932} 932}
diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
new file mode 100755
index 000000000000..c4acf5ff1794
--- /dev/null
+++ b/drivers/staging/iio/light/tsl2x7x.h
@@ -0,0 +1,100 @@
1/*
2 * Device driver for monitoring ambient light intensity (lux)
3 * and proximity (prox) within the TAOS TSL2X7X family of devices.
4 *
5 * Copyright (c) 2012, TAOS Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#ifndef __TSL2X7X_H
23#define __TSL2X7X_H
24#include <linux/pm.h>
25
26/* Max number of segments allowable in LUX table */
27#define TSL2X7X_MAX_LUX_TABLE_SIZE 9
28#define MAX_DEFAULT_TABLE_BYTES (sizeof(int) * TSL2X7X_MAX_LUX_TABLE_SIZE)
29
30struct iio_dev;
31
32struct tsl2x7x_lux {
33 unsigned int ratio;
34 unsigned int ch0;
35 unsigned int ch1;
36};
37
38/**
39 * struct tsl2x7x_default_settings - power on defaults unless
40 * overridden by platform data.
41 * @als_time: ALS Integration time - multiple of 50mS
42 * @als_gain: Index into the ALS gain table.
43 * @als_gain_trim: default gain trim to account for
44 * aperture effects.
45 * @wait_time: Time between PRX and ALS cycles
46 * in 2.7 periods
47 * @prx_time: 5.2ms prox integration time -
48 * decrease in 2.7ms periods
49 * @prx_gain: Proximity gain index
50 * @prox_config: Prox configuration filters.
51 * @als_cal_target: Known external ALS reading for
52 * calibration.
53 * @interrupts_en: Enable/Disable - 0x00 = none, 0x10 = als,
54 * 0x20 = prx, 0x30 = bth
55 * @persistence: H/W Filters, Number of 'out of limits'
56 * ADC readings PRX/ALS.
57 * @als_thresh_low: CH0 'low' count to trigger interrupt.
58 * @als_thresh_high: CH0 'high' count to trigger interrupt.
59 * @prox_thres_low: Low threshold proximity detection.
60 * @prox_thres_high: High threshold proximity detection
61 * @prox_pulse_count: Number if proximity emitter pulses
62 * @prox_max_samples_cal: Used for prox cal.
63 */
64struct tsl2x7x_settings {
65 int als_time;
66 int als_gain;
67 int als_gain_trim;
68 int wait_time;
69 int prx_time;
70 int prox_gain;
71 int prox_config;
72 int als_cal_target;
73 u8 interrupts_en;
74 u8 persistence;
75 int als_thresh_low;
76 int als_thresh_high;
77 int prox_thres_low;
78 int prox_thres_high;
79 int prox_pulse_count;
80 int prox_max_samples_cal;
81};
82
83/**
84 * struct tsl2X7X_platform_data - Platform callback, glass and defaults
85 * @platform_power: Suspend/resume platform callback
86 * @power_on: Power on callback
87 * @power_off: Power off callback
88 * @platform_lux_table: Device specific glass coefficents
89 * @platform_default_settings: Device specific power on defaults
90 *
91 */
92struct tsl2X7X_platform_data {
93 int (*platform_power)(struct device *dev, pm_message_t);
94 int (*power_on) (struct iio_dev *indio_dev);
95 int (*power_off) (struct i2c_client *dev);
96 struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE];
97 struct tsl2x7x_settings *platform_default_settings;
98};
99
100#endif /* __TSL2X7X_H */
diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
new file mode 100755
index 000000000000..c3b05a1b3ea8
--- /dev/null
+++ b/drivers/staging/iio/light/tsl2x7x_core.c
@@ -0,0 +1,2082 @@
1/*
2 * Device driver for monitoring ambient light intensity in (lux)
3 * and proximity detection (prox) within the TAOS TSL2X7X family of devices.
4 *
5 * Copyright (c) 2012, TAOS Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <linux/kernel.h>
23#include <linux/i2c.h>
24#include <linux/errno.h>
25#include <linux/delay.h>
26#include <linux/mutex.h>
27#include <linux/interrupt.h>
28#include <linux/slab.h>
29#include <linux/module.h>
30#include <linux/version.h>
31#include <linux/iio/events.h>
32#include <linux/iio/iio.h>
33#include <linux/iio/sysfs.h>
34#include "tsl2x7x.h"
35
36/* Cal defs*/
37#define PROX_STAT_CAL 0
38#define PROX_STAT_SAMP 1
39#define MAX_SAMPLES_CAL 200
40
41/* TSL2X7X Device ID */
42#define TRITON_ID 0x00
43#define SWORDFISH_ID 0x30
44#define HALIBUT_ID 0x20
45
46/* Lux calculation constants */
47#define TSL2X7X_LUX_CALC_OVER_FLOW 65535
48
49/* TAOS Register definitions - note:
50 * depending on device, some of these register are not used and the
51 * register address is benign.
52 */
53/* 2X7X register offsets */
54#define TSL2X7X_MAX_CONFIG_REG 16
55
56/* Device Registers and Masks */
57#define TSL2X7X_CNTRL 0x00
58#define TSL2X7X_ALS_TIME 0X01
59#define TSL2X7X_PRX_TIME 0x02
60#define TSL2X7X_WAIT_TIME 0x03
61#define TSL2X7X_ALS_MINTHRESHLO 0X04
62#define TSL2X7X_ALS_MINTHRESHHI 0X05
63#define TSL2X7X_ALS_MAXTHRESHLO 0X06
64#define TSL2X7X_ALS_MAXTHRESHHI 0X07
65#define TSL2X7X_PRX_MINTHRESHLO 0X08
66#define TSL2X7X_PRX_MINTHRESHHI 0X09
67#define TSL2X7X_PRX_MAXTHRESHLO 0X0A
68#define TSL2X7X_PRX_MAXTHRESHHI 0X0B
69#define TSL2X7X_PERSISTENCE 0x0C
70#define TSL2X7X_PRX_CONFIG 0x0D
71#define TSL2X7X_PRX_COUNT 0x0E
72#define TSL2X7X_GAIN 0x0F
73#define TSL2X7X_NOTUSED 0x10
74#define TSL2X7X_REVID 0x11
75#define TSL2X7X_CHIPID 0x12
76#define TSL2X7X_STATUS 0x13
77#define TSL2X7X_ALS_CHAN0LO 0x14
78#define TSL2X7X_ALS_CHAN0HI 0x15
79#define TSL2X7X_ALS_CHAN1LO 0x16
80#define TSL2X7X_ALS_CHAN1HI 0x17
81#define TSL2X7X_PRX_LO 0x18
82#define TSL2X7X_PRX_HI 0x19
83
84/* tsl2X7X cmd reg masks */
85#define TSL2X7X_CMD_REG 0x80
86#define TSL2X7X_CMD_SPL_FN 0x60
87
88#define TSL2X7X_CMD_PROX_INT_CLR 0X05
89#define TSL2X7X_CMD_ALS_INT_CLR 0x06
90#define TSL2X7X_CMD_PROXALS_INT_CLR 0X07
91
92/* tsl2X7X cntrl reg masks */
93#define TSL2X7X_CNTL_ADC_ENBL 0x02
94#define TSL2X7X_CNTL_PWR_ON 0x01
95
96/* tsl2X7X status reg masks */
97#define TSL2X7X_STA_ADC_VALID 0x01
98#define TSL2X7X_STA_PRX_VALID 0x02
99#define TSL2X7X_STA_ADC_PRX_VALID (TSL2X7X_STA_ADC_VALID |\
100 TSL2X7X_STA_PRX_VALID)
101#define TSL2X7X_STA_ALS_INTR 0x10
102#define TSL2X7X_STA_PRX_INTR 0x20
103
104/* tsl2X7X cntrl reg masks */
105#define TSL2X7X_CNTL_REG_CLEAR 0x00
106#define TSL2X7X_CNTL_PROX_INT_ENBL 0X20
107#define TSL2X7X_CNTL_ALS_INT_ENBL 0X10
108#define TSL2X7X_CNTL_WAIT_TMR_ENBL 0X08
109#define TSL2X7X_CNTL_PROX_DET_ENBL 0X04
110#define TSL2X7X_CNTL_PWRON 0x01
111#define TSL2X7X_CNTL_ALSPON_ENBL 0x03
112#define TSL2X7X_CNTL_INTALSPON_ENBL 0x13
113#define TSL2X7X_CNTL_PROXPON_ENBL 0x0F
114#define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F
115
116/*Prox diode to use */
117#define TSL2X7X_DIODE0 0x10
118#define TSL2X7X_DIODE1 0x20
119#define TSL2X7X_DIODE_BOTH 0x30
120
121/* LED Power */
122#define TSL2X7X_mA100 0x00
123#define TSL2X7X_mA50 0x40
124#define TSL2X7X_mA25 0x80
125#define TSL2X7X_mA13 0xD0
126#define TSL2X7X_MAX_TIMER_CNT (0xFF)
127
128/*Common device IIO EventMask */
129#define TSL2X7X_EVENT_MASK \
130 (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
131 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)),
132
133#define TSL2X7X_MIN_ITIME 3
134
135/* TAOS txx2x7x Device family members */
136enum {
137 tsl2571,
138 tsl2671,
139 tmd2671,
140 tsl2771,
141 tmd2771,
142 tsl2572,
143 tsl2672,
144 tmd2672,
145 tsl2772,
146 tmd2772
147};
148
149enum {
150 TSL2X7X_CHIP_UNKNOWN = 0,
151 TSL2X7X_CHIP_WORKING = 1,
152 TSL2X7X_CHIP_SUSPENDED = 2
153};
154
155struct tsl2x7x_parse_result {
156 int integer;
157 int fract;
158};
159
160/* Per-device data */
161struct tsl2x7x_als_info {
162 u16 als_ch0;
163 u16 als_ch1;
164 u16 lux;
165};
166
167struct tsl2x7x_prox_stat {
168 int min;
169 int max;
170 int mean;
171 unsigned long stddev;
172};
173
174struct tsl2x7x_chip_info {
175 int chan_table_elements;
176 struct iio_chan_spec channel[4];
177 const struct iio_info *info;
178};
179
180struct tsl2X7X_chip {
181 kernel_ulong_t id;
182 struct mutex prox_mutex;
183 struct mutex als_mutex;
184 struct i2c_client *client;
185 u16 prox_data;
186 struct tsl2x7x_als_info als_cur_info;
187 struct tsl2x7x_settings tsl2x7x_settings;
188 struct tsl2X7X_platform_data *pdata;
189 int als_time_scale;
190 int als_saturation;
191 int tsl2x7x_chip_status;
192 u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG];
193 const struct tsl2x7x_chip_info *chip_info;
194 const struct iio_info *info;
195 s64 event_timestamp;
196 /* This structure is intentionally large to accommodate
197 * updates via sysfs. */
198 /* Sized to 9 = max 8 segments + 1 termination segment */
199 struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
200};
201
202/* Different devices require different coefficents */
203static const struct tsl2x7x_lux tsl2x71_lux_table[] = {
204 { 14461, 611, 1211 },
205 { 18540, 352, 623 },
206 { 0, 0, 0 },
207};
208
209static const struct tsl2x7x_lux tmd2x71_lux_table[] = {
210 { 11635, 115, 256 },
211 { 15536, 87, 179 },
212 { 0, 0, 0 },
213};
214
215static const struct tsl2x7x_lux tsl2x72_lux_table[] = {
216 { 14013, 466, 917 },
217 { 18222, 310, 552 },
218 { 0, 0, 0 },
219};
220
221static const struct tsl2x7x_lux tmd2x72_lux_table[] = {
222 { 13218, 130, 262 },
223 { 17592, 92, 169 },
224 { 0, 0, 0 },
225};
226
227static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
228 [tsl2571] = tsl2x71_lux_table,
229 [tsl2671] = tsl2x71_lux_table,
230 [tmd2671] = tmd2x71_lux_table,
231 [tsl2771] = tsl2x71_lux_table,
232 [tmd2771] = tmd2x71_lux_table,
233 [tsl2572] = tsl2x72_lux_table,
234 [tsl2672] = tsl2x72_lux_table,
235 [tmd2672] = tmd2x72_lux_table,
236 [tsl2772] = tsl2x72_lux_table,
237 [tmd2772] = tmd2x72_lux_table,
238};
239
240static const struct tsl2x7x_settings tsl2x7x_default_settings = {
241 .als_time = 219, /* 101 ms */
242 .als_gain = 0,
243 .prx_time = 254, /* 5.4 ms */
244 .prox_gain = 1,
245 .wait_time = 245,
246 .prox_config = 0,
247 .als_gain_trim = 1000,
248 .als_cal_target = 150,
249 .als_thresh_low = 200,
250 .als_thresh_high = 256,
251 .persistence = 255,
252 .interrupts_en = 0,
253 .prox_thres_low = 0,
254 .prox_thres_high = 512,
255 .prox_max_samples_cal = 30,
256 .prox_pulse_count = 8
257};
258
259static const s16 tsl2X7X_als_gainadj[] = {
260 1,
261 8,
262 16,
263 120
264};
265
266static const s16 tsl2X7X_prx_gainadj[] = {
267 1,
268 2,
269 4,
270 8
271};
272
273/* Channel variations */
274enum {
275 ALS,
276 PRX,
277 ALSPRX,
278 PRX2,
279 ALSPRX2,
280};
281
282static const u8 device_channel_config[] = {
283 ALS,
284 PRX,
285 PRX,
286 ALSPRX,
287 ALSPRX,
288 ALS,
289 PRX2,
290 PRX2,
291 ALSPRX2,
292 ALSPRX2
293};
294
295/**
296 * tsl2x7x_parse_buffer() - parse a decimal result from a buffer.
297 * @*buf: pointer to char buffer to parse
298 * @*result: pointer to buffer to contain
299 * resulting interger / decimal as ints.
300 *
301 */
302static int
303tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result *result)
304{
305 int integer = 0, fract = 0, fract_mult = 100000;
306 bool integer_part = true, negative = false;
307
308 if (buf[0] == '-') {
309 negative = true;
310 buf++;
311 }
312
313 while (*buf) {
314 if ('0' <= *buf && *buf <= '9') {
315 if (integer_part)
316 integer = integer*10 + *buf - '0';
317 else {
318 fract += fract_mult*(*buf - '0');
319 if (fract_mult == 1)
320 break;
321 fract_mult /= 10;
322 }
323 } else if (*buf == '\n') {
324 if (*(buf + 1) == '\0')
325 break;
326 else
327 return -EINVAL;
328 } else if (*buf == '.') {
329 integer_part = false;
330 } else {
331 return -EINVAL;
332 }
333 buf++;
334 }
335 if (negative) {
336 if (integer)
337 integer = -integer;
338 else
339 fract = -fract;
340 }
341
342 result->integer = integer;
343 result->fract = fract;
344
345 return 0;
346}
347
348/**
349 * tsl2x7x_i2c_read() - Read a byte from a register.
350 * @client: i2c client
351 * @reg: device register to read from
352 * @*val: pointer to location to store register contents.
353 *
354 */
355static int
356tsl2x7x_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
357{
358 int ret = 0;
359
360 /* select register to write */
361 ret = i2c_smbus_write_byte(client, (TSL2X7X_CMD_REG | reg));
362 if (ret < 0) {
363 dev_err(&client->dev, "%s: failed to write register %x\n"
364 , __func__, reg);
365 return ret;
366 }
367
368 /* read the data */
369 ret = i2c_smbus_read_byte(client);
370 if (ret >= 0)
371 *val = (u8)ret;
372 else
373 dev_err(&client->dev, "%s: failed to read register %x\n"
374 , __func__, reg);
375
376 return ret;
377}
378
379/**
380 * tsl2x7x_get_lux() - Reads and calculates current lux value.
381 * @indio_dev: pointer to IIO device
382 *
383 * The raw ch0 and ch1 values of the ambient light sensed in the last
384 * integration cycle are read from the device.
385 * Time scale factor array values are adjusted based on the integration time.
386 * The raw values are multiplied by a scale factor, and device gain is obtained
387 * using gain index. Limit checks are done next, then the ratio of a multiple
388 * of ch1 value, to the ch0 value, is calculated. Array tsl2x7x_device_lux[]
389 * is then scanned to find the first ratio value that is just above the ratio
390 * we just calculated. The ch0 and ch1 multiplier constants in the array are
391 * then used along with the time scale factor array values, to calculate the
392 * lux.
393 */
394static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
395{
396 u16 ch0, ch1; /* separated ch0/ch1 data from device */
397 u32 lux; /* raw lux calculated from device data */
398 u64 lux64;
399 u32 ratio;
400 u8 buf[4];
401 struct tsl2x7x_lux *p;
402 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
403 int i, ret;
404 u32 ch0lux = 0;
405 u32 ch1lux = 0;
406
407 if (mutex_trylock(&chip->als_mutex) == 0)
408 return chip->als_cur_info.lux; /* busy, so return LAST VALUE */
409
410 if (chip->tsl2x7x_chip_status != TSL2X7X_CHIP_WORKING) {
411 /* device is not enabled */
412 dev_err(&chip->client->dev, "%s: device is not enabled\n",
413 __func__);
414 ret = -EBUSY ;
415 goto out_unlock;
416 }
417
418 ret = tsl2x7x_i2c_read(chip->client,
419 (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &buf[0]);
420 if (ret < 0) {
421 dev_err(&chip->client->dev,
422 "%s: Failed to read STATUS Reg\n", __func__);
423 goto out_unlock;
424 }
425 /* is data new & valid */
426 if (!(buf[0] & TSL2X7X_STA_ADC_VALID)) {
427 dev_err(&chip->client->dev,
428 "%s: data not valid yet\n", __func__);
429 ret = chip->als_cur_info.lux; /* return LAST VALUE */
430 goto out_unlock;
431 }
432
433 for (i = 0; i < 4; i++) {
434 ret = tsl2x7x_i2c_read(chip->client,
435 (TSL2X7X_CMD_REG | (TSL2X7X_ALS_CHAN0LO + i)),
436 &buf[i]);
437 if (ret < 0) {
438 dev_err(&chip->client->dev,
439 "%s: failed to read. err=%x\n", __func__, ret);
440 goto out_unlock;
441 }
442 }
443
444 /* clear any existing interrupt status */
445 ret = i2c_smbus_write_byte(chip->client,
446 (TSL2X7X_CMD_REG |
447 TSL2X7X_CMD_SPL_FN |
448 TSL2X7X_CMD_ALS_INT_CLR));
449 if (ret < 0) {
450 dev_err(&chip->client->dev,
451 "%s: i2c_write_command failed - err = %d\n",
452 __func__, ret);
453 goto out_unlock; /* have no data, so return failure */
454 }
455
456 /* extract ALS/lux data */
457 ch0 = le16_to_cpup((const __le16 *)&buf[0]);
458 ch1 = le16_to_cpup((const __le16 *)&buf[2]);
459
460 chip->als_cur_info.als_ch0 = ch0;
461 chip->als_cur_info.als_ch1 = ch1;
462
463 if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation)) {
464 lux = TSL2X7X_LUX_CALC_OVER_FLOW;
465 goto return_max;
466 }
467
468 if (ch0 == 0) {
469 /* have no data, so return LAST VALUE */
470 ret = chip->als_cur_info.lux;
471 goto out_unlock;
472 }
473 /* calculate ratio */
474 ratio = (ch1 << 15) / ch0;
475 /* convert to unscaled lux using the pointer to the table */
476 p = (struct tsl2x7x_lux *) chip->tsl2x7x_device_lux;
477 while (p->ratio != 0 && p->ratio < ratio)
478 p++;
479
480 if (p->ratio == 0) {
481 lux = 0;
482 } else {
483 ch0lux = DIV_ROUND_UP((ch0 * p->ch0),
484 tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
485 ch1lux = DIV_ROUND_UP((ch1 * p->ch1),
486 tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
487 lux = ch0lux - ch1lux;
488 }
489
490 /* note: lux is 31 bit max at this point */
491 if (ch1lux > ch0lux) {
492 dev_dbg(&chip->client->dev, "ch1lux > ch0lux-return last value\n");
493 ret = chip->als_cur_info.lux;
494 goto out_unlock;
495 }
496
497 /* adjust for active time scale */
498 if (chip->als_time_scale == 0)
499 lux = 0;
500 else
501 lux = (lux + (chip->als_time_scale >> 1)) /
502 chip->als_time_scale;
503
504 /* adjust for active gain scale
505 * The tsl2x7x_device_lux tables have a factor of 256 built-in.
506 * User-specified gain provides a multiplier.
507 * Apply user-specified gain before shifting right to retain precision.
508 * Use 64 bits to avoid overflow on multiplication.
509 * Then go back to 32 bits before division to avoid using div_u64().
510 */
511
512 lux64 = lux;
513 lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim;
514 lux64 >>= 8;
515 lux = lux64;
516 lux = (lux + 500) / 1000;
517
518 if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */
519 lux = TSL2X7X_LUX_CALC_OVER_FLOW;
520
521 /* Update the structure with the latest lux. */
522return_max:
523 chip->als_cur_info.lux = lux;
524 ret = lux;
525
526out_unlock:
527 mutex_unlock(&chip->als_mutex);
528
529 return ret;
530}
531
532/**
533 * tsl2x7x_get_prox() - Reads proximity data registers and updates
534 * chip->prox_data.
535 *
536 * @indio_dev: pointer to IIO device
537 */
538static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
539{
540 int i;
541 int ret;
542 u8 status;
543 u8 chdata[2];
544 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
545
546 if (mutex_trylock(&chip->prox_mutex) == 0) {
547 dev_err(&chip->client->dev,
548 "%s: Can't get prox mutex\n", __func__);
549 return -EBUSY;
550 }
551
552 ret = tsl2x7x_i2c_read(chip->client,
553 (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &status);
554 if (ret < 0) {
555 dev_err(&chip->client->dev,
556 "%s: i2c err=%d\n", __func__, ret);
557 goto prox_poll_err;
558 }
559
560 switch (chip->id) {
561 case tsl2571:
562 case tsl2671:
563 case tmd2671:
564 case tsl2771:
565 case tmd2771:
566 if (!(status & TSL2X7X_STA_ADC_VALID))
567 goto prox_poll_err;
568 break;
569 case tsl2572:
570 case tsl2672:
571 case tmd2672:
572 case tsl2772:
573 case tmd2772:
574 if (!(status & TSL2X7X_STA_PRX_VALID))
575 goto prox_poll_err;
576 break;
577 }
578
579 for (i = 0; i < 2; i++) {
580 ret = tsl2x7x_i2c_read(chip->client,
581 (TSL2X7X_CMD_REG |
582 (TSL2X7X_PRX_LO + i)), &chdata[i]);
583 if (ret < 0)
584 goto prox_poll_err;
585 }
586
587 chip->prox_data =
588 le16_to_cpup((const __le16 *)&chdata[0]);
589
590prox_poll_err:
591
592 mutex_unlock(&chip->prox_mutex);
593
594 return chip->prox_data;
595}
596
597/**
598 * tsl2x7x_defaults() - Populates the device nominal operating parameters
599 * with those provided by a 'platform' data struct or
600 * with prefined defaults.
601 *
602 * @chip: pointer to device structure.
603 */
604static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
605{
606 /* If Operational settings defined elsewhere.. */
607 if (chip->pdata && chip->pdata->platform_default_settings != 0)
608 memcpy(&(chip->tsl2x7x_settings),
609 chip->pdata->platform_default_settings,
610 sizeof(tsl2x7x_default_settings));
611 else
612 memcpy(&(chip->tsl2x7x_settings),
613 &tsl2x7x_default_settings,
614 sizeof(tsl2x7x_default_settings));
615
616 /* Load up the proper lux table. */
617 if (chip->pdata && chip->pdata->platform_lux_table[0].ratio != 0)
618 memcpy(chip->tsl2x7x_device_lux,
619 chip->pdata->platform_lux_table,
620 sizeof(chip->pdata->platform_lux_table));
621 else
622 memcpy(chip->tsl2x7x_device_lux,
623 (struct tsl2x7x_lux *)tsl2x7x_default_lux_table_group[chip->id],
624 MAX_DEFAULT_TABLE_BYTES);
625}
626
627/**
628 * tsl2x7x_als_calibrate() - Obtain single reading and calculate
629 * the als_gain_trim.
630 *
631 * @indio_dev: pointer to IIO device
632 */
633static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
634{
635 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
636 u8 reg_val;
637 int gain_trim_val;
638 int ret;
639 int lux_val;
640
641 ret = i2c_smbus_write_byte(chip->client,
642 (TSL2X7X_CMD_REG | TSL2X7X_CNTRL));
643 if (ret < 0) {
644 dev_err(&chip->client->dev,
645 "%s: failed to write CNTRL register, ret=%d\n",
646 __func__, ret);
647 return ret;
648 }
649
650 reg_val = i2c_smbus_read_byte(chip->client);
651 if ((reg_val & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON))
652 != (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) {
653 dev_err(&chip->client->dev,
654 "%s: failed: ADC not enabled\n", __func__);
655 return -1;
656 }
657
658 ret = i2c_smbus_write_byte(chip->client,
659 (TSL2X7X_CMD_REG | TSL2X7X_CNTRL));
660 if (ret < 0) {
661 dev_err(&chip->client->dev,
662 "%s: failed to write ctrl reg: ret=%d\n",
663 __func__, ret);
664 return ret;
665 }
666
667 reg_val = i2c_smbus_read_byte(chip->client);
668 if ((reg_val & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) {
669 dev_err(&chip->client->dev,
670 "%s: failed: STATUS - ADC not valid.\n", __func__);
671 return -ENODATA;
672 }
673
674 lux_val = tsl2x7x_get_lux(indio_dev);
675 if (lux_val < 0) {
676 dev_err(&chip->client->dev,
677 "%s: failed to get lux\n", __func__);
678 return lux_val;
679 }
680
681 gain_trim_val = (((chip->tsl2x7x_settings.als_cal_target)
682 * chip->tsl2x7x_settings.als_gain_trim) / lux_val);
683 if ((gain_trim_val < 250) || (gain_trim_val > 4000))
684 return -ERANGE;
685
686 chip->tsl2x7x_settings.als_gain_trim = gain_trim_val;
687 dev_info(&chip->client->dev,
688 "%s als_calibrate completed\n", chip->client->name);
689
690 return (int) gain_trim_val;
691}
692
693static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
694{
695 int i;
696 int ret = 0;
697 u8 *dev_reg;
698 u8 utmp;
699 int als_count;
700 int als_time;
701 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
702 u8 reg_val = 0;
703
704 if (chip->pdata && chip->pdata->power_on)
705 chip->pdata->power_on(indio_dev);
706
707 /* Non calculated parameters */
708 chip->tsl2x7x_config[TSL2X7X_PRX_TIME] =
709 chip->tsl2x7x_settings.prx_time;
710 chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] =
711 chip->tsl2x7x_settings.wait_time;
712 chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] =
713 chip->tsl2x7x_settings.prox_config;
714
715 chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] =
716 (chip->tsl2x7x_settings.als_thresh_low) & 0xFF;
717 chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] =
718 (chip->tsl2x7x_settings.als_thresh_low >> 8) & 0xFF;
719 chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] =
720 (chip->tsl2x7x_settings.als_thresh_high) & 0xFF;
721 chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
722 (chip->tsl2x7x_settings.als_thresh_high >> 8) & 0xFF;
723 chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
724 chip->tsl2x7x_settings.persistence;
725
726 chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
727 chip->tsl2x7x_settings.prox_pulse_count;
728 chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] =
729 chip->tsl2x7x_settings.prox_thres_low;
730 chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] =
731 chip->tsl2x7x_settings.prox_thres_high;
732
733 /* and make sure we're not already on */
734 if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
735 /* if forcing a register update - turn off, then on */
736 dev_info(&chip->client->dev, "device is already enabled\n");
737 return -EINVAL;
738 }
739
740 /* determine als integration regster */
741 als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
742 if (als_count == 0)
743 als_count = 1; /* ensure at least one cycle */
744
745 /* convert back to time (encompasses overrides) */
746 als_time = (als_count * 27 + 5) / 10;
747 chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = 256 - als_count;
748
749 /* Set the gain based on tsl2x7x_settings struct */
750 chip->tsl2x7x_config[TSL2X7X_GAIN] =
751 (chip->tsl2x7x_settings.als_gain |
752 (TSL2X7X_mA100 | TSL2X7X_DIODE1)
753 | ((chip->tsl2x7x_settings.prox_gain) << 2));
754
755 /* set chip struct re scaling and saturation */
756 chip->als_saturation = als_count * 922; /* 90% of full scale */
757 chip->als_time_scale = (als_time + 25) / 50;
758
759 /* TSL2X7X Specific power-on / adc enable sequence
760 * Power on the device 1st. */
761 utmp = TSL2X7X_CNTL_PWR_ON;
762 ret = i2c_smbus_write_byte_data(chip->client,
763 TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp);
764 if (ret < 0) {
765 dev_err(&chip->client->dev,
766 "%s: failed on CNTRL reg.\n", __func__);
767 return ret;
768 }
769
770 /* Use the following shadow copy for our delay before enabling ADC.
771 * Write all the registers. */
772 for (i = 0, dev_reg = chip->tsl2x7x_config;
773 i < TSL2X7X_MAX_CONFIG_REG; i++) {
774 ret = i2c_smbus_write_byte_data(chip->client,
775 TSL2X7X_CMD_REG + i, *dev_reg++);
776 if (ret < 0) {
777 dev_err(&chip->client->dev,
778 "%s: failed on write to reg %d.\n", __func__, i);
779 return ret;
780 }
781 }
782
783 mdelay(3); /* Power-on settling time */
784
785 /* NOW enable the ADC
786 * initialize the desired mode of operation */
787 utmp = TSL2X7X_CNTL_PWR_ON |
788 TSL2X7X_CNTL_ADC_ENBL |
789 TSL2X7X_CNTL_PROX_DET_ENBL;
790 ret = i2c_smbus_write_byte_data(chip->client,
791 TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp);
792 if (ret < 0) {
793 dev_err(&chip->client->dev,
794 "%s: failed on 2nd CTRL reg.\n", __func__);
795 return ret;
796 }
797
798 chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING;
799
800 if (chip->tsl2x7x_settings.interrupts_en != 0) {
801 dev_info(&chip->client->dev, "Setting Up Interrupt(s)\n");
802
803 reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL;
804 if ((chip->tsl2x7x_settings.interrupts_en == 0x20) ||
805 (chip->tsl2x7x_settings.interrupts_en == 0x30))
806 reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL;
807
808 reg_val |= chip->tsl2x7x_settings.interrupts_en;
809 ret = i2c_smbus_write_byte_data(chip->client,
810 (TSL2X7X_CMD_REG | TSL2X7X_CNTRL), reg_val);
811 if (ret < 0)
812 dev_err(&chip->client->dev,
813 "%s: failed in tsl2x7x_IOCTL_INT_SET.\n",
814 __func__);
815
816 /* Clear out any initial interrupts */
817 ret = i2c_smbus_write_byte(chip->client,
818 TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
819 TSL2X7X_CMD_PROXALS_INT_CLR);
820 if (ret < 0) {
821 dev_err(&chip->client->dev,
822 "%s: Failed to clear Int status\n",
823 __func__);
824 return ret;
825 }
826 }
827
828 return ret;
829}
830
831static int tsl2x7x_chip_off(struct iio_dev *indio_dev)
832{
833 int ret;
834 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
835
836 /* turn device off */
837 chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED;
838
839 ret = i2c_smbus_write_byte_data(chip->client,
840 TSL2X7X_CMD_REG | TSL2X7X_CNTRL, 0x00);
841
842 if (chip->pdata && chip->pdata->power_off)
843 chip->pdata->power_off(chip->client);
844
845 return ret;
846}
847
848/**
849 * tsl2x7x_invoke_change
850 * @indio_dev: pointer to IIO device
851 *
852 * Obtain and lock both ALS and PROX resources,
853 * determine and save device state (On/Off),
854 * cycle device to implement updated parameter,
855 * put device back into proper state, and unlock
856 * resource.
857 */
858static
859int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
860{
861 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
862 int device_status = chip->tsl2x7x_chip_status;
863
864 mutex_lock(&chip->als_mutex);
865 mutex_lock(&chip->prox_mutex);
866
867 if (device_status == TSL2X7X_CHIP_WORKING)
868 tsl2x7x_chip_off(indio_dev);
869
870 tsl2x7x_chip_on(indio_dev);
871
872 if (device_status != TSL2X7X_CHIP_WORKING)
873 tsl2x7x_chip_off(indio_dev);
874
875 mutex_unlock(&chip->prox_mutex);
876 mutex_unlock(&chip->als_mutex);
877
878 return 0;
879}
880
881static
882void tsl2x7x_prox_calculate(int *data, int length,
883 struct tsl2x7x_prox_stat *statP)
884{
885 int i;
886 int sample_sum;
887 int tmp;
888
889 if (length == 0)
890 length = 1;
891
892 sample_sum = 0;
893 statP->min = INT_MAX;
894 statP->max = INT_MIN;
895 for (i = 0; i < length; i++) {
896 sample_sum += data[i];
897 statP->min = min(statP->min, data[i]);
898 statP->max = max(statP->max, data[i]);
899 }
900
901 statP->mean = sample_sum / length;
902 sample_sum = 0;
903 for (i = 0; i < length; i++) {
904 tmp = data[i] - statP->mean;
905 sample_sum += tmp * tmp;
906 }
907 statP->stddev = int_sqrt((long)sample_sum)/length;
908}
909
910/**
911 * tsl2x7x_prox_cal() - Calculates std. and sets thresholds.
912 * @indio_dev: pointer to IIO device
913 *
914 * Calculates a standard deviation based on the samples,
915 * and sets the threshold accordingly.
916 */
917static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
918{
919 int prox_history[MAX_SAMPLES_CAL + 1];
920 int i;
921 struct tsl2x7x_prox_stat prox_stat_data[2];
922 struct tsl2x7x_prox_stat *calP;
923 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
924 u8 tmp_irq_settings;
925 u8 current_state = chip->tsl2x7x_chip_status;
926
927 if (chip->tsl2x7x_settings.prox_max_samples_cal > MAX_SAMPLES_CAL) {
928 dev_err(&chip->client->dev,
929 "%s: max prox samples cal is too big: %d\n",
930 __func__, chip->tsl2x7x_settings.prox_max_samples_cal);
931 chip->tsl2x7x_settings.prox_max_samples_cal = MAX_SAMPLES_CAL;
932 }
933
934 /* have to stop to change settings */
935 tsl2x7x_chip_off(indio_dev);
936
937 /* Enable proximity detection save just in case prox not wanted yet*/
938 tmp_irq_settings = chip->tsl2x7x_settings.interrupts_en;
939 chip->tsl2x7x_settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
940
941 /*turn on device if not already on*/
942 tsl2x7x_chip_on(indio_dev);
943
944 /*gather the samples*/
945 for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) {
946 mdelay(15);
947 tsl2x7x_get_prox(indio_dev);
948 prox_history[i] = chip->prox_data;
949 dev_info(&chip->client->dev, "2 i=%d prox data= %d\n",
950 i, chip->prox_data);
951 }
952
953 tsl2x7x_chip_off(indio_dev);
954 calP = &prox_stat_data[PROX_STAT_CAL];
955 tsl2x7x_prox_calculate(prox_history,
956 chip->tsl2x7x_settings.prox_max_samples_cal, calP);
957 chip->tsl2x7x_settings.prox_thres_high = (calP->max << 1) - calP->mean;
958
959 dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n",
960 calP->min, calP->mean, calP->max);
961 dev_info(&chip->client->dev,
962 "%s proximity threshold set to %d\n",
963 chip->client->name, chip->tsl2x7x_settings.prox_thres_high);
964
965 /* back to the way they were */
966 chip->tsl2x7x_settings.interrupts_en = tmp_irq_settings;
967 if (current_state == TSL2X7X_CHIP_WORKING)
968 tsl2x7x_chip_on(indio_dev);
969}
970
971static ssize_t tsl2x7x_power_state_show(struct device *dev,
972 struct device_attribute *attr, char *buf)
973{
974 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
975
976 return snprintf(buf, PAGE_SIZE, "%d\n", chip->tsl2x7x_chip_status);
977}
978
979static ssize_t tsl2x7x_power_state_store(struct device *dev,
980 struct device_attribute *attr, const char *buf, size_t len)
981{
982 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
983 bool value;
984
985 if (strtobool(buf, &value))
986 return -EINVAL;
987
988 if (value)
989 tsl2x7x_chip_on(indio_dev);
990 else
991 tsl2x7x_chip_off(indio_dev);
992
993 return len;
994}
995
996static ssize_t tsl2x7x_gain_available_show(struct device *dev,
997 struct device_attribute *attr, char *buf)
998{
999 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1000
1001 switch (chip->id) {
1002 case tsl2571:
1003 case tsl2671:
1004 case tmd2671:
1005 case tsl2771:
1006 case tmd2771:
1007 return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128");
1008 break;
1009 }
1010
1011 return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120");
1012}
1013
1014static ssize_t tsl2x7x_prox_gain_available_show(struct device *dev,
1015 struct device_attribute *attr, char *buf)
1016{
1017 return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8");
1018}
1019
1020static ssize_t tsl2x7x_als_time_show(struct device *dev,
1021 struct device_attribute *attr, char *buf)
1022{
1023 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1024 int y, z;
1025
1026 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
1027 z = y * TSL2X7X_MIN_ITIME;
1028 y /= 1000;
1029 z %= 1000;
1030
1031 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
1032}
1033
1034static ssize_t tsl2x7x_als_time_store(struct device *dev,
1035 struct device_attribute *attr, const char *buf, size_t len)
1036{
1037 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1038 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1039 struct tsl2x7x_parse_result result;
1040
1041 result.integer = 0;
1042 result.fract = 0;
1043
1044 tsl2x7x_parse_buffer(buf, &result);
1045
1046 result.fract /= 1000;
1047 result.fract /= 3;
1048 chip->tsl2x7x_settings.als_time =
1049 (TSL2X7X_MAX_TIMER_CNT - (u8)result.fract);
1050
1051 dev_info(&chip->client->dev, "%s: als time = %d",
1052 __func__, chip->tsl2x7x_settings.als_time);
1053
1054 tsl2x7x_invoke_change(indio_dev);
1055
1056 return IIO_VAL_INT_PLUS_MICRO;
1057}
1058
1059static IIO_CONST_ATTR(in_illuminance0_integration_time_available,
1060 ".00272 - .696");
1061
1062static ssize_t tsl2x7x_als_cal_target_show(struct device *dev,
1063 struct device_attribute *attr, char *buf)
1064{
1065 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1066
1067 return snprintf(buf, PAGE_SIZE, "%d\n",
1068 chip->tsl2x7x_settings.als_cal_target);
1069}
1070
1071static ssize_t tsl2x7x_als_cal_target_store(struct device *dev,
1072 struct device_attribute *attr, const char *buf, size_t len)
1073{
1074 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1075 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1076 unsigned long value;
1077
1078 if (kstrtoul(buf, 0, &value))
1079 return -EINVAL;
1080
1081 if (value)
1082 chip->tsl2x7x_settings.als_cal_target = value;
1083
1084 tsl2x7x_invoke_change(indio_dev);
1085
1086 return len;
1087}
1088
1089/* persistence settings */
1090static ssize_t tsl2x7x_als_persistence_show(struct device *dev,
1091 struct device_attribute *attr, char *buf)
1092{
1093 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1094 int y, z, filter_delay;
1095
1096 /* Determine integration time */
1097 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
1098 z = y * TSL2X7X_MIN_ITIME;
1099 filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F);
1100 y = (filter_delay / 1000);
1101 z = (filter_delay % 1000);
1102
1103 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
1104}
1105
1106static ssize_t tsl2x7x_als_persistence_store(struct device *dev,
1107 struct device_attribute *attr, const char *buf, size_t len)
1108{
1109 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1110 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1111 struct tsl2x7x_parse_result result;
1112 int y, z, filter_delay;
1113
1114 result.integer = 0;
1115 result.fract = 0;
1116 tsl2x7x_parse_buffer(buf, &result);
1117
1118 result.fract /= 1000;
1119 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
1120 z = y * TSL2X7X_MIN_ITIME;
1121
1122 filter_delay =
1123 DIV_ROUND_UP(((result.integer * 1000) + result.fract), z);
1124
1125 chip->tsl2x7x_settings.persistence &= 0xF0;
1126 chip->tsl2x7x_settings.persistence |= (filter_delay & 0x0F);
1127
1128 dev_info(&chip->client->dev, "%s: als persistence = %d",
1129 __func__, filter_delay);
1130
1131 tsl2x7x_invoke_change(indio_dev);
1132
1133 return IIO_VAL_INT_PLUS_MICRO;
1134}
1135
1136static ssize_t tsl2x7x_prox_persistence_show(struct device *dev,
1137 struct device_attribute *attr, char *buf)
1138{
1139 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1140 int y, z, filter_delay;
1141
1142 /* Determine integration time */
1143 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
1144 z = y * TSL2X7X_MIN_ITIME;
1145 filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4);
1146 y = (filter_delay / 1000);
1147 z = (filter_delay % 1000);
1148
1149 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
1150}
1151
1152static ssize_t tsl2x7x_prox_persistence_store(struct device *dev,
1153 struct device_attribute *attr, const char *buf, size_t len)
1154{
1155 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1156 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1157 struct tsl2x7x_parse_result result;
1158 int y, z, filter_delay;
1159
1160 result.integer = 0;
1161 result.fract = 0;
1162 tsl2x7x_parse_buffer(buf, &result);
1163
1164 result.fract /= 1000;
1165 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
1166 z = y * TSL2X7X_MIN_ITIME;
1167
1168 filter_delay =
1169 DIV_ROUND_UP(((result.integer * 1000) + result.fract), z);
1170
1171 chip->tsl2x7x_settings.persistence &= 0x0F;
1172 chip->tsl2x7x_settings.persistence |= ((filter_delay << 4) & 0xF0);
1173
1174 dev_info(&chip->client->dev, "%s: prox persistence = %d",
1175 __func__, filter_delay);
1176
1177 tsl2x7x_invoke_change(indio_dev);
1178
1179 return IIO_VAL_INT_PLUS_MICRO;
1180}
1181
1182static ssize_t tsl2x7x_do_calibrate(struct device *dev,
1183 struct device_attribute *attr, const char *buf, size_t len)
1184{
1185 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1186 bool value;
1187
1188 if (strtobool(buf, &value))
1189 return -EINVAL;
1190
1191 if (value)
1192 tsl2x7x_als_calibrate(indio_dev);
1193
1194 tsl2x7x_invoke_change(indio_dev);
1195
1196 return len;
1197}
1198
1199static ssize_t tsl2x7x_luxtable_show(struct device *dev,
1200 struct device_attribute *attr, char *buf)
1201{
1202 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
1203 int i = 0;
1204 int offset = 0;
1205
1206 while (i < (TSL2X7X_MAX_LUX_TABLE_SIZE * 3)) {
1207 offset += snprintf(buf + offset, PAGE_SIZE, "%d,%d,%d,",
1208 chip->tsl2x7x_device_lux[i].ratio,
1209 chip->tsl2x7x_device_lux[i].ch0,
1210 chip->tsl2x7x_device_lux[i].ch1);
1211 if (chip->tsl2x7x_device_lux[i].ratio == 0) {
1212 /* We just printed the first "0" entry.
1213 * Now get rid of the extra "," and break. */
1214 offset--;
1215 break;
1216 }
1217 i++;
1218 }
1219
1220 offset += snprintf(buf + offset, PAGE_SIZE, "\n");
1221 return offset;
1222}
1223
1224static ssize_t tsl2x7x_luxtable_store(struct device *dev,
1225 struct device_attribute *attr, const char *buf, size_t len)
1226{
1227 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1228 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1229 int value[ARRAY_SIZE(chip->tsl2x7x_device_lux)*3 + 1];
1230 int n;
1231
1232 get_options(buf, ARRAY_SIZE(value), value);
1233
1234 /* We now have an array of ints starting at value[1], and
1235 * enumerated by value[0].
1236 * We expect each group of three ints is one table entry,
1237 * and the last table entry is all 0.
1238 */
1239 n = value[0];
1240 if ((n % 3) || n < 6 ||
1241 n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 3)) {
1242 dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
1243 return -EINVAL;
1244 }
1245
1246 if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
1247 dev_info(dev, "LUX TABLE INPUT ERROR 2 Value[0]=%d\n", n);
1248 return -EINVAL;
1249 }
1250
1251 if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING)
1252 tsl2x7x_chip_off(indio_dev);
1253
1254 /* Zero out the table */
1255 memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux));
1256 memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4));
1257
1258 tsl2x7x_invoke_change(indio_dev);
1259
1260 return len;
1261}
1262
1263static ssize_t tsl2x7x_do_prox_calibrate(struct device *dev,
1264 struct device_attribute *attr, const char *buf, size_t len)
1265{
1266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1267 bool value;
1268
1269 if (strtobool(buf, &value))
1270 return -EINVAL;
1271
1272 if (value)
1273 tsl2x7x_prox_cal(indio_dev);
1274
1275 tsl2x7x_invoke_change(indio_dev);
1276
1277 return len;
1278}
1279
1280static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
1281 u64 event_code)
1282{
1283 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1284 int ret;
1285
1286 if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY)
1287 ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x10);
1288 else
1289 ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x20);
1290
1291 return ret;
1292}
1293
1294static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
1295 u64 event_code,
1296 int val)
1297{
1298 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1299
1300 if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
1301 if (val)
1302 chip->tsl2x7x_settings.interrupts_en |= 0x10;
1303 else
1304 chip->tsl2x7x_settings.interrupts_en &= 0x20;
1305 } else {
1306 if (val)
1307 chip->tsl2x7x_settings.interrupts_en |= 0x20;
1308 else
1309 chip->tsl2x7x_settings.interrupts_en &= 0x10;
1310 }
1311
1312 tsl2x7x_invoke_change(indio_dev);
1313
1314 return 0;
1315}
1316
1317static int tsl2x7x_write_thresh(struct iio_dev *indio_dev,
1318 u64 event_code,
1319 int val)
1320{
1321 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1322
1323 if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
1324 switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
1325 case IIO_EV_DIR_RISING:
1326 chip->tsl2x7x_settings.als_thresh_high = val;
1327 break;
1328 case IIO_EV_DIR_FALLING:
1329 chip->tsl2x7x_settings.als_thresh_low = val;
1330 break;
1331 default:
1332 return -EINVAL;
1333 }
1334 } else {
1335 switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
1336 case IIO_EV_DIR_RISING:
1337 chip->tsl2x7x_settings.prox_thres_high = val;
1338 break;
1339 case IIO_EV_DIR_FALLING:
1340 chip->tsl2x7x_settings.prox_thres_low = val;
1341 break;
1342 default:
1343 return -EINVAL;
1344 }
1345 }
1346
1347 tsl2x7x_invoke_change(indio_dev);
1348
1349 return 0;
1350}
1351
1352static int tsl2x7x_read_thresh(struct iio_dev *indio_dev,
1353 u64 event_code,
1354 int *val)
1355{
1356 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1357
1358 if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
1359 switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
1360 case IIO_EV_DIR_RISING:
1361 *val = chip->tsl2x7x_settings.als_thresh_high;
1362 break;
1363 case IIO_EV_DIR_FALLING:
1364 *val = chip->tsl2x7x_settings.als_thresh_low;
1365 break;
1366 default:
1367 return -EINVAL;
1368 }
1369 } else {
1370 switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
1371 case IIO_EV_DIR_RISING:
1372 *val = chip->tsl2x7x_settings.prox_thres_high;
1373 break;
1374 case IIO_EV_DIR_FALLING:
1375 *val = chip->tsl2x7x_settings.prox_thres_low;
1376 break;
1377 default:
1378 return -EINVAL;
1379 }
1380 }
1381
1382 return 0;
1383}
1384
1385static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
1386 struct iio_chan_spec const *chan,
1387 int *val,
1388 int *val2,
1389 long mask)
1390{
1391 int ret = -EINVAL;
1392 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1393
1394 switch (mask) {
1395 case IIO_CHAN_INFO_PROCESSED:
1396 switch (chan->type) {
1397 case IIO_LIGHT:
1398 tsl2x7x_get_lux(indio_dev);
1399 *val = chip->als_cur_info.lux;
1400 ret = IIO_VAL_INT;
1401 break;
1402 default:
1403 return -EINVAL;
1404 break;
1405 }
1406 break;
1407 case IIO_CHAN_INFO_RAW:
1408 switch (chan->type) {
1409 case IIO_INTENSITY:
1410 tsl2x7x_get_lux(indio_dev);
1411 if (chan->channel == 0)
1412 *val = chip->als_cur_info.als_ch0;
1413 else
1414 *val = chip->als_cur_info.als_ch1;
1415 ret = IIO_VAL_INT;
1416 break;
1417 case IIO_PROXIMITY:
1418 tsl2x7x_get_prox(indio_dev);
1419 *val = chip->prox_data;
1420 ret = IIO_VAL_INT;
1421 break;
1422 default:
1423 return -EINVAL;
1424 break;
1425 }
1426 break;
1427 case IIO_CHAN_INFO_CALIBSCALE:
1428 if (chan->type == IIO_LIGHT)
1429 *val =
1430 tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain];
1431 else
1432 *val =
1433 tsl2X7X_prx_gainadj[chip->tsl2x7x_settings.prox_gain];
1434 ret = IIO_VAL_INT;
1435 break;
1436 case IIO_CHAN_INFO_CALIBBIAS:
1437 *val = chip->tsl2x7x_settings.als_gain_trim;
1438 ret = IIO_VAL_INT;
1439 break;
1440
1441 default:
1442 ret = -EINVAL;
1443 }
1444
1445 return ret;
1446}
1447
1448static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
1449 struct iio_chan_spec const *chan,
1450 int val,
1451 int val2,
1452 long mask)
1453{
1454 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1455
1456 switch (mask) {
1457 case IIO_CHAN_INFO_CALIBSCALE:
1458 if (chan->type == IIO_INTENSITY) {
1459 switch (val) {
1460 case 1:
1461 chip->tsl2x7x_settings.als_gain = 0;
1462 break;
1463 case 8:
1464 chip->tsl2x7x_settings.als_gain = 1;
1465 break;
1466 case 16:
1467 chip->tsl2x7x_settings.als_gain = 2;
1468 break;
1469 case 120:
1470 switch (chip->id) {
1471 case tsl2572:
1472 case tsl2672:
1473 case tmd2672:
1474 case tsl2772:
1475 case tmd2772:
1476 return -EINVAL;
1477 break;
1478 }
1479 chip->tsl2x7x_settings.als_gain = 3;
1480 break;
1481 case 128:
1482 switch (chip->id) {
1483 case tsl2571:
1484 case tsl2671:
1485 case tmd2671:
1486 case tsl2771:
1487 case tmd2771:
1488 return -EINVAL;
1489 break;
1490 }
1491 chip->tsl2x7x_settings.als_gain = 3;
1492 break;
1493 default:
1494 return -EINVAL;
1495 }
1496 } else {
1497 switch (val) {
1498 case 1:
1499 chip->tsl2x7x_settings.prox_gain = 0;
1500 break;
1501 case 2:
1502 chip->tsl2x7x_settings.prox_gain = 1;
1503 break;
1504 case 4:
1505 chip->tsl2x7x_settings.prox_gain = 2;
1506 break;
1507 case 8:
1508 chip->tsl2x7x_settings.prox_gain = 3;
1509 break;
1510 default:
1511 return -EINVAL;
1512 }
1513 }
1514 break;
1515 case IIO_CHAN_INFO_CALIBBIAS:
1516 chip->tsl2x7x_settings.als_gain_trim = val;
1517 break;
1518
1519 default:
1520 return -EINVAL;
1521 }
1522
1523 tsl2x7x_invoke_change(indio_dev);
1524
1525 return 0;
1526}
1527
1528static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR,
1529 tsl2x7x_power_state_show, tsl2x7x_power_state_store);
1530
1531static DEVICE_ATTR(in_proximity0_calibscale_available, S_IRUGO,
1532 tsl2x7x_prox_gain_available_show, NULL);
1533
1534static DEVICE_ATTR(in_illuminance0_calibscale_available, S_IRUGO,
1535 tsl2x7x_gain_available_show, NULL);
1536
1537static DEVICE_ATTR(in_illuminance0_integration_time, S_IRUGO | S_IWUSR,
1538 tsl2x7x_als_time_show, tsl2x7x_als_time_store);
1539
1540static DEVICE_ATTR(in_illuminance0_target_input, S_IRUGO | S_IWUSR,
1541 tsl2x7x_als_cal_target_show, tsl2x7x_als_cal_target_store);
1542
1543static DEVICE_ATTR(in_illuminance0_calibrate, S_IWUSR, NULL,
1544 tsl2x7x_do_calibrate);
1545
1546static DEVICE_ATTR(in_proximity0_calibrate, S_IWUSR, NULL,
1547 tsl2x7x_do_prox_calibrate);
1548
1549static DEVICE_ATTR(in_illuminance0_lux_table, S_IRUGO | S_IWUSR,
1550 tsl2x7x_luxtable_show, tsl2x7x_luxtable_store);
1551
1552static DEVICE_ATTR(in_intensity0_thresh_period, S_IRUGO | S_IWUSR,
1553 tsl2x7x_als_persistence_show, tsl2x7x_als_persistence_store);
1554
1555static DEVICE_ATTR(in_proximity0_thresh_period, S_IRUGO | S_IWUSR,
1556 tsl2x7x_prox_persistence_show, tsl2x7x_prox_persistence_store);
1557
1558/* Use the default register values to identify the Taos device */
1559static int tsl2x7x_device_id(unsigned char *id, int target)
1560{
1561 switch (target) {
1562 case tsl2571:
1563 case tsl2671:
1564 case tsl2771:
1565 return ((*id & 0xf0) == TRITON_ID);
1566 break;
1567 case tmd2671:
1568 case tmd2771:
1569 return ((*id & 0xf0) == HALIBUT_ID);
1570 break;
1571 case tsl2572:
1572 case tsl2672:
1573 case tmd2672:
1574 case tsl2772:
1575 case tmd2772:
1576 return ((*id & 0xf0) == SWORDFISH_ID);
1577 break;
1578 }
1579
1580 return -EINVAL;
1581}
1582
1583static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
1584{
1585 struct iio_dev *indio_dev = private;
1586 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1587 s64 timestamp = iio_get_time_ns();
1588 int ret;
1589 u8 value;
1590
1591 value = i2c_smbus_read_byte_data(chip->client,
1592 TSL2X7X_CMD_REG | TSL2X7X_STATUS);
1593
1594 /* What type of interrupt do we need to process */
1595 if (value & TSL2X7X_STA_PRX_INTR) {
1596 tsl2x7x_get_prox(indio_dev); /* freshen data for ABI */
1597 iio_push_event(indio_dev,
1598 IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
1599 0,
1600 IIO_EV_TYPE_THRESH,
1601 IIO_EV_DIR_EITHER),
1602 timestamp);
1603 }
1604
1605 if (value & TSL2X7X_STA_ALS_INTR) {
1606 tsl2x7x_get_lux(indio_dev); /* freshen data for ABI */
1607 iio_push_event(indio_dev,
1608 IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
1609 0,
1610 IIO_EV_TYPE_THRESH,
1611 IIO_EV_DIR_EITHER),
1612 timestamp);
1613 }
1614 /* Clear interrupt now that we have handled it. */
1615 ret = i2c_smbus_write_byte(chip->client,
1616 TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
1617 TSL2X7X_CMD_PROXALS_INT_CLR);
1618 if (ret < 0)
1619 dev_err(&chip->client->dev,
1620 "%s: Failed to clear irq from event handler. err = %d\n",
1621 __func__, ret);
1622
1623 return IRQ_HANDLED;
1624}
1625
1626static struct attribute *tsl2x7x_ALS_device_attrs[] = {
1627 &dev_attr_power_state.attr,
1628 &dev_attr_in_illuminance0_calibscale_available.attr,
1629 &dev_attr_in_illuminance0_integration_time.attr,
1630 &iio_const_attr_in_illuminance0_integration_time_available\
1631 .dev_attr.attr,
1632 &dev_attr_in_illuminance0_target_input.attr,
1633 &dev_attr_in_illuminance0_calibrate.attr,
1634 &dev_attr_in_illuminance0_lux_table.attr,
1635 NULL
1636};
1637
1638static struct attribute *tsl2x7x_PRX_device_attrs[] = {
1639 &dev_attr_power_state.attr,
1640 &dev_attr_in_proximity0_calibrate.attr,
1641 NULL
1642};
1643
1644static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
1645 &dev_attr_power_state.attr,
1646 &dev_attr_in_illuminance0_calibscale_available.attr,
1647 &dev_attr_in_illuminance0_integration_time.attr,
1648 &iio_const_attr_in_illuminance0_integration_time_available\
1649 .dev_attr.attr,
1650 &dev_attr_in_illuminance0_target_input.attr,
1651 &dev_attr_in_illuminance0_calibrate.attr,
1652 &dev_attr_in_illuminance0_lux_table.attr,
1653 &dev_attr_in_proximity0_calibrate.attr,
1654 NULL
1655};
1656
1657static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
1658 &dev_attr_power_state.attr,
1659 &dev_attr_in_proximity0_calibrate.attr,
1660 &dev_attr_in_proximity0_calibscale_available.attr,
1661 NULL
1662};
1663
1664static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
1665 &dev_attr_power_state.attr,
1666 &dev_attr_in_illuminance0_calibscale_available.attr,
1667 &dev_attr_in_illuminance0_integration_time.attr,
1668 &iio_const_attr_in_illuminance0_integration_time_available\
1669 .dev_attr.attr,
1670 &dev_attr_in_illuminance0_target_input.attr,
1671 &dev_attr_in_illuminance0_calibrate.attr,
1672 &dev_attr_in_illuminance0_lux_table.attr,
1673 &dev_attr_in_proximity0_calibrate.attr,
1674 &dev_attr_in_proximity0_calibscale_available.attr,
1675 NULL
1676};
1677
1678static struct attribute *tsl2X7X_ALS_event_attrs[] = {
1679 &dev_attr_in_intensity0_thresh_period.attr,
1680 NULL,
1681};
1682static struct attribute *tsl2X7X_PRX_event_attrs[] = {
1683 &dev_attr_in_proximity0_thresh_period.attr,
1684 NULL,
1685};
1686
1687static struct attribute *tsl2X7X_ALSPRX_event_attrs[] = {
1688 &dev_attr_in_intensity0_thresh_period.attr,
1689 &dev_attr_in_proximity0_thresh_period.attr,
1690 NULL,
1691};
1692
1693static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
1694 [ALS] = {
1695 .attrs = tsl2x7x_ALS_device_attrs,
1696 },
1697 [PRX] = {
1698 .attrs = tsl2x7x_PRX_device_attrs,
1699 },
1700 [ALSPRX] = {
1701 .attrs = tsl2x7x_ALSPRX_device_attrs,
1702 },
1703 [PRX2] = {
1704 .attrs = tsl2x7x_PRX2_device_attrs,
1705 },
1706 [ALSPRX2] = {
1707 .attrs = tsl2x7x_ALSPRX2_device_attrs,
1708 },
1709};
1710
1711static struct attribute_group tsl2X7X_event_attr_group_tbl[] = {
1712 [ALS] = {
1713 .attrs = tsl2X7X_ALS_event_attrs,
1714 .name = "events",
1715 },
1716 [PRX] = {
1717 .attrs = tsl2X7X_PRX_event_attrs,
1718 .name = "events",
1719 },
1720 [ALSPRX] = {
1721 .attrs = tsl2X7X_ALSPRX_event_attrs,
1722 .name = "events",
1723 },
1724};
1725
1726static const struct iio_info tsl2X7X_device_info[] = {
1727 [ALS] = {
1728 .attrs = &tsl2X7X_device_attr_group_tbl[ALS],
1729 .event_attrs = &tsl2X7X_event_attr_group_tbl[ALS],
1730 .driver_module = THIS_MODULE,
1731 .read_raw = &tsl2x7x_read_raw,
1732 .write_raw = &tsl2x7x_write_raw,
1733 .read_event_value = &tsl2x7x_read_thresh,
1734 .write_event_value = &tsl2x7x_write_thresh,
1735 .read_event_config = &tsl2x7x_read_interrupt_config,
1736 .write_event_config = &tsl2x7x_write_interrupt_config,
1737 },
1738 [PRX] = {
1739 .attrs = &tsl2X7X_device_attr_group_tbl[PRX],
1740 .event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
1741 .driver_module = THIS_MODULE,
1742 .read_raw = &tsl2x7x_read_raw,
1743 .write_raw = &tsl2x7x_write_raw,
1744 .read_event_value = &tsl2x7x_read_thresh,
1745 .write_event_value = &tsl2x7x_write_thresh,
1746 .read_event_config = &tsl2x7x_read_interrupt_config,
1747 .write_event_config = &tsl2x7x_write_interrupt_config,
1748 },
1749 [ALSPRX] = {
1750 .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
1751 .event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
1752 .driver_module = THIS_MODULE,
1753 .read_raw = &tsl2x7x_read_raw,
1754 .write_raw = &tsl2x7x_write_raw,
1755 .read_event_value = &tsl2x7x_read_thresh,
1756 .write_event_value = &tsl2x7x_write_thresh,
1757 .read_event_config = &tsl2x7x_read_interrupt_config,
1758 .write_event_config = &tsl2x7x_write_interrupt_config,
1759 },
1760 [PRX2] = {
1761 .attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
1762 .event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
1763 .driver_module = THIS_MODULE,
1764 .read_raw = &tsl2x7x_read_raw,
1765 .write_raw = &tsl2x7x_write_raw,
1766 .read_event_value = &tsl2x7x_read_thresh,
1767 .write_event_value = &tsl2x7x_write_thresh,
1768 .read_event_config = &tsl2x7x_read_interrupt_config,
1769 .write_event_config = &tsl2x7x_write_interrupt_config,
1770 },
1771 [ALSPRX2] = {
1772 .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
1773 .event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
1774 .driver_module = THIS_MODULE,
1775 .read_raw = &tsl2x7x_read_raw,
1776 .write_raw = &tsl2x7x_write_raw,
1777 .read_event_value = &tsl2x7x_read_thresh,
1778 .write_event_value = &tsl2x7x_write_thresh,
1779 .read_event_config = &tsl2x7x_read_interrupt_config,
1780 .write_event_config = &tsl2x7x_write_interrupt_config,
1781 },
1782};
1783
1784static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
1785 [ALS] = {
1786 .channel = {
1787 {
1788 .type = IIO_LIGHT,
1789 .indexed = 1,
1790 .channel = 0,
1791 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
1792 }, {
1793 .type = IIO_INTENSITY,
1794 .indexed = 1,
1795 .channel = 0,
1796 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1797 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
1798 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
1799 .event_mask = TSL2X7X_EVENT_MASK
1800 }, {
1801 .type = IIO_INTENSITY,
1802 .indexed = 1,
1803 .channel = 1,
1804 },
1805 },
1806 .chan_table_elements = 3,
1807 .info = &tsl2X7X_device_info[ALS],
1808 },
1809 [PRX] = {
1810 .channel = {
1811 {
1812 .type = IIO_PROXIMITY,
1813 .indexed = 1,
1814 .channel = 0,
1815 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
1816 .event_mask = TSL2X7X_EVENT_MASK
1817 },
1818 },
1819 .chan_table_elements = 1,
1820 .info = &tsl2X7X_device_info[PRX],
1821 },
1822 [ALSPRX] = {
1823 .channel = {
1824 {
1825 .type = IIO_LIGHT,
1826 .indexed = 1,
1827 .channel = 0,
1828 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT
1829 }, {
1830 .type = IIO_INTENSITY,
1831 .indexed = 1,
1832 .channel = 0,
1833 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1834 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
1835 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
1836 .event_mask = TSL2X7X_EVENT_MASK
1837 }, {
1838 .type = IIO_INTENSITY,
1839 .indexed = 1,
1840 .channel = 1,
1841 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
1842 }, {
1843 .type = IIO_PROXIMITY,
1844 .indexed = 1,
1845 .channel = 0,
1846 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
1847 .event_mask = TSL2X7X_EVENT_MASK
1848 },
1849 },
1850 .chan_table_elements = 4,
1851 .info = &tsl2X7X_device_info[ALSPRX],
1852 },
1853 [PRX2] = {
1854 .channel = {
1855 {
1856 .type = IIO_PROXIMITY,
1857 .indexed = 1,
1858 .channel = 0,
1859 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1860 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
1861 .event_mask = TSL2X7X_EVENT_MASK
1862 },
1863 },
1864 .chan_table_elements = 1,
1865 .info = &tsl2X7X_device_info[PRX2],
1866 },
1867 [ALSPRX2] = {
1868 .channel = {
1869 {
1870 .type = IIO_LIGHT,
1871 .indexed = 1,
1872 .channel = 0,
1873 .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
1874 }, {
1875 .type = IIO_INTENSITY,
1876 .indexed = 1,
1877 .channel = 0,
1878 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1879 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
1880 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
1881 .event_mask = TSL2X7X_EVENT_MASK
1882 }, {
1883 .type = IIO_INTENSITY,
1884 .indexed = 1,
1885 .channel = 1,
1886 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
1887 }, {
1888 .type = IIO_PROXIMITY,
1889 .indexed = 1,
1890 .channel = 0,
1891 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1892 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
1893 .event_mask = TSL2X7X_EVENT_MASK
1894 },
1895 },
1896 .chan_table_elements = 4,
1897 .info = &tsl2X7X_device_info[ALSPRX2],
1898 },
1899};
1900
1901static int __devinit tsl2x7x_probe(struct i2c_client *clientp,
1902 const struct i2c_device_id *id)
1903{
1904 int ret;
1905 unsigned char device_id;
1906 struct iio_dev *indio_dev;
1907 struct tsl2X7X_chip *chip;
1908
1909 indio_dev = iio_device_alloc(sizeof(*chip));
1910 if (!indio_dev)
1911 return -ENOMEM;
1912
1913 chip = iio_priv(indio_dev);
1914 chip->client = clientp;
1915 i2c_set_clientdata(clientp, indio_dev);
1916
1917 ret = tsl2x7x_i2c_read(chip->client,
1918 TSL2X7X_CHIPID, &device_id);
1919 if (ret < 0)
1920 goto fail1;
1921
1922 if ((!tsl2x7x_device_id(&device_id, id->driver_data)) ||
1923 (tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) {
1924 dev_info(&chip->client->dev,
1925 "%s: i2c device found does not match expected id\n",
1926 __func__);
1927 goto fail1;
1928 }
1929
1930 ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL));
1931 if (ret < 0) {
1932 dev_err(&clientp->dev, "%s: write to cmd reg failed. err = %d\n",
1933 __func__, ret);
1934 goto fail1;
1935 }
1936
1937 /* ALS and PROX functions can be invoked via user space poll
1938 * or H/W interrupt. If busy return last sample. */
1939 mutex_init(&chip->als_mutex);
1940 mutex_init(&chip->prox_mutex);
1941
1942 chip->tsl2x7x_chip_status = TSL2X7X_CHIP_UNKNOWN;
1943 chip->pdata = clientp->dev.platform_data;
1944 chip->id = id->driver_data;
1945 chip->chip_info =
1946 &tsl2x7x_chip_info_tbl[device_channel_config[id->driver_data]];
1947
1948 indio_dev->info = chip->chip_info->info;
1949 indio_dev->dev.parent = &clientp->dev;
1950 indio_dev->modes = INDIO_DIRECT_MODE;
1951 indio_dev->name = chip->client->name;
1952 indio_dev->channels = chip->chip_info->channel;
1953 indio_dev->num_channels = chip->chip_info->chan_table_elements;
1954
1955 if (clientp->irq) {
1956 ret = request_threaded_irq(clientp->irq,
1957 NULL,
1958 &tsl2x7x_event_handler,
1959 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
1960 "TSL2X7X_event",
1961 indio_dev);
1962 if (ret) {
1963 dev_err(&clientp->dev,
1964 "%s: irq request failed", __func__);
1965 goto fail2;
1966 }
1967 }
1968
1969 /* Load up the defaults */
1970 tsl2x7x_defaults(chip);
1971 /* Make sure the chip is on */
1972 tsl2x7x_chip_on(indio_dev);
1973
1974 ret = iio_device_register(indio_dev);
1975 if (ret) {
1976 dev_err(&clientp->dev,
1977 "%s: iio registration failed\n", __func__);
1978 goto fail1;
1979 }
1980
1981 dev_info(&clientp->dev, "%s Light sensor found.\n", id->name);
1982
1983 return 0;
1984
1985fail1:
1986 if (clientp->irq)
1987 free_irq(clientp->irq, indio_dev);
1988fail2:
1989 iio_device_free(indio_dev);
1990
1991 return ret;
1992}
1993
1994static int tsl2x7x_suspend(struct device *dev)
1995{
1996 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1997 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1998 int ret = 0;
1999
2000 if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
2001 ret = tsl2x7x_chip_off(indio_dev);
2002 chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED;
2003 }
2004
2005 if (chip->pdata && chip->pdata->platform_power) {
2006 pm_message_t pmm = {PM_EVENT_SUSPEND};
2007 chip->pdata->platform_power(dev, pmm);
2008 }
2009
2010 return ret;
2011}
2012
2013static int tsl2x7x_resume(struct device *dev)
2014{
2015 struct iio_dev *indio_dev = dev_get_drvdata(dev);
2016 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
2017 int ret = 0;
2018
2019 if (chip->pdata && chip->pdata->platform_power) {
2020 pm_message_t pmm = {PM_EVENT_RESUME};
2021 chip->pdata->platform_power(dev, pmm);
2022 }
2023
2024 if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_SUSPENDED)
2025 ret = tsl2x7x_chip_on(indio_dev);
2026
2027 return ret;
2028}
2029
2030static int __devexit tsl2x7x_remove(struct i2c_client *client)
2031{
2032 struct tsl2X7X_chip *chip = i2c_get_clientdata(client);
2033 struct iio_dev *indio_dev = iio_priv_to_dev(chip);
2034
2035 tsl2x7x_chip_off(indio_dev);
2036
2037 iio_device_unregister(indio_dev);
2038 if (client->irq)
2039 free_irq(client->irq, chip->client->name);
2040
2041 iio_device_free(indio_dev);
2042
2043 return 0;
2044}
2045
2046static struct i2c_device_id tsl2x7x_idtable[] = {
2047 { "tsl2571", tsl2571 },
2048 { "tsl2671", tsl2671 },
2049 { "tmd2671", tmd2671 },
2050 { "tsl2771", tsl2771 },
2051 { "tmd2771", tmd2771 },
2052 { "tsl2572", tsl2572 },
2053 { "tsl2672", tsl2672 },
2054 { "tmd2672", tmd2672 },
2055 { "tsl2772", tsl2772 },
2056 { "tmd2772", tmd2772 },
2057 {}
2058};
2059
2060MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable);
2061
2062static const struct dev_pm_ops tsl2x7x_pm_ops = {
2063 .suspend = tsl2x7x_suspend,
2064 .resume = tsl2x7x_resume,
2065};
2066
2067/* Driver definition */
2068static struct i2c_driver tsl2x7x_driver = {
2069 .driver = {
2070 .name = "tsl2x7x",
2071 .pm = &tsl2x7x_pm_ops,
2072 },
2073 .id_table = tsl2x7x_idtable,
2074 .probe = tsl2x7x_probe,
2075 .remove = __devexit_p(tsl2x7x_remove),
2076};
2077
2078module_i2c_driver(tsl2x7x_driver);
2079
2080MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>");
2081MODULE_DESCRIPTION("TAOS tsl2x7x ambient and proximity light sensor driver");
2082MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/magnetometer/Kconfig b/drivers/staging/iio/magnetometer/Kconfig
index 722c4e13f713..b9d932595ba9 100644
--- a/drivers/staging/iio/magnetometer/Kconfig
+++ b/drivers/staging/iio/magnetometer/Kconfig
@@ -15,13 +15,13 @@ config SENSORS_AK8975
15 will be called ak8975. 15 will be called ak8975.
16 16
17config SENSORS_HMC5843 17config SENSORS_HMC5843
18 tristate "Honeywell HMC5843 3-Axis Magnetometer" 18 tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer"
19 depends on I2C 19 depends on I2C
20 help 20 help
21 Say Y here to add support for the Honeywell HMC 5843 3-Axis 21 Say Y here to add support for the Honeywell HMC5843, HMC5883 and
22 Magnetometer (digital compass). 22 HMC5883L 3-Axis Magnetometer (digital compass).
23 23
24 To compile this driver as a module, choose M here: the module 24 To compile this driver as a module, choose M here: the module
25 will be called hmc5843 25 will be called hmc5843.
26 26
27endmenu 27endmenu
diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
index ebc2d0840caf..5834e4a70f8c 100644
--- a/drivers/staging/iio/magnetometer/ak8975.c
+++ b/drivers/staging/iio/magnetometer/ak8975.c
@@ -30,8 +30,8 @@
30 30
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32 32
33#include "../iio.h" 33#include <linux/iio/iio.h>
34#include "../sysfs.h" 34#include <linux/iio/sysfs.h>
35/* 35/*
36 * Register definitions, as well as various shifts and masks to get at the 36 * Register definitions, as well as various shifts and masks to get at the
37 * individual fields of the registers. 37 * individual fields of the registers.
@@ -242,7 +242,7 @@ static int ak8975_setup(struct i2c_client *client)
242static ssize_t show_mode(struct device *dev, struct device_attribute *devattr, 242static ssize_t show_mode(struct device *dev, struct device_attribute *devattr,
243 char *buf) 243 char *buf)
244{ 244{
245 struct iio_dev *indio_dev = dev_get_drvdata(dev); 245 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
246 struct ak8975_data *data = iio_priv(indio_dev); 246 struct ak8975_data *data = iio_priv(indio_dev);
247 247
248 return sprintf(buf, "%u\n", data->mode); 248 return sprintf(buf, "%u\n", data->mode);
@@ -255,7 +255,7 @@ static ssize_t show_mode(struct device *dev, struct device_attribute *devattr,
255static ssize_t store_mode(struct device *dev, struct device_attribute *devattr, 255static ssize_t store_mode(struct device *dev, struct device_attribute *devattr,
256 const char *buf, size_t count) 256 const char *buf, size_t count)
257{ 257{
258 struct iio_dev *indio_dev = dev_get_drvdata(dev); 258 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
259 struct ak8975_data *data = iio_priv(indio_dev); 259 struct ak8975_data *data = iio_priv(indio_dev);
260 struct i2c_client *client = data->client; 260 struct i2c_client *client = data->client;
261 bool value; 261 bool value;
@@ -431,7 +431,7 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
431 struct ak8975_data *data = iio_priv(indio_dev); 431 struct ak8975_data *data = iio_priv(indio_dev);
432 432
433 switch (mask) { 433 switch (mask) {
434 case 0: 434 case IIO_CHAN_INFO_RAW:
435 return ak8975_read_axis(indio_dev, chan->address, val); 435 return ak8975_read_axis(indio_dev, chan->address, val);
436 case IIO_CHAN_INFO_SCALE: 436 case IIO_CHAN_INFO_SCALE:
437 *val = data->raw_to_gauss[chan->address]; 437 *val = data->raw_to_gauss[chan->address];
@@ -445,7 +445,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
445 .type = IIO_MAGN, \ 445 .type = IIO_MAGN, \
446 .modified = 1, \ 446 .modified = 1, \
447 .channel2 = IIO_MOD_##axis, \ 447 .channel2 = IIO_MOD_##axis, \
448 .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 448 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
449 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
449 .address = index, \ 450 .address = index, \
450 } 451 }
451 452
@@ -505,7 +506,7 @@ static int ak8975_probe(struct i2c_client *client,
505 } 506 }
506 507
507 /* Register with IIO */ 508 /* Register with IIO */
508 indio_dev = iio_allocate_device(sizeof(*data)); 509 indio_dev = iio_device_alloc(sizeof(*data));
509 if (indio_dev == NULL) { 510 if (indio_dev == NULL) {
510 err = -ENOMEM; 511 err = -ENOMEM;
511 goto exit_gpio; 512 goto exit_gpio;
@@ -536,7 +537,7 @@ static int ak8975_probe(struct i2c_client *client,
536 return 0; 537 return 0;
537 538
538exit_free_iio: 539exit_free_iio:
539 iio_free_device(indio_dev); 540 iio_device_free(indio_dev);
540exit_gpio: 541exit_gpio:
541 if (gpio_is_valid(eoc_gpio)) 542 if (gpio_is_valid(eoc_gpio))
542 gpio_free(eoc_gpio); 543 gpio_free(eoc_gpio);
@@ -554,7 +555,7 @@ static int ak8975_remove(struct i2c_client *client)
554 if (gpio_is_valid(data->eoc_gpio)) 555 if (gpio_is_valid(data->eoc_gpio))
555 gpio_free(data->eoc_gpio); 556 gpio_free(data->eoc_gpio);
556 557
557 iio_free_device(indio_dev); 558 iio_device_free(indio_dev);
558 559
559 return 0; 560 return 0;
560} 561}
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c
index e00b416c4d33..c1fa09f07625 100644
--- a/drivers/staging/iio/magnetometer/hmc5843.c
+++ b/drivers/staging/iio/magnetometer/hmc5843.c
@@ -2,6 +2,8 @@
2 Author: Shubhrajyoti Datta <shubhrajyoti@ti.com> 2 Author: Shubhrajyoti Datta <shubhrajyoti@ti.com>
3 Acknowledgement: Jonathan Cameron <jic23@cam.ac.uk> for valuable inputs. 3 Acknowledgement: Jonathan Cameron <jic23@cam.ac.uk> for valuable inputs.
4 4
5 Support for HMC5883 and HMC5883L by Peter Meerwald <pmeerw@pmeerw.net>.
6
5 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
@@ -22,10 +24,8 @@
22#include <linux/i2c.h> 24#include <linux/i2c.h>
23#include <linux/slab.h> 25#include <linux/slab.h>
24#include <linux/types.h> 26#include <linux/types.h>
25#include "../iio.h" 27#include <linux/iio/iio.h>
26#include "../sysfs.h" 28#include <linux/iio/sysfs.h>
27
28#define HMC5843_I2C_ADDRESS 0x1E
29 29
30#define HMC5843_CONFIG_REG_A 0x00 30#define HMC5843_CONFIG_REG_A 0x00
31#define HMC5843_CONFIG_REG_B 0x01 31#define HMC5843_CONFIG_REG_B 0x01
@@ -36,110 +36,185 @@
36#define HMC5843_DATA_OUT_Y_LSB_REG 0x06 36#define HMC5843_DATA_OUT_Y_LSB_REG 0x06
37#define HMC5843_DATA_OUT_Z_MSB_REG 0x07 37#define HMC5843_DATA_OUT_Z_MSB_REG 0x07
38#define HMC5843_DATA_OUT_Z_LSB_REG 0x08 38#define HMC5843_DATA_OUT_Z_LSB_REG 0x08
39/* Beware: Y and Z are exchanged on HMC5883 */
40#define HMC5883_DATA_OUT_Z_MSB_REG 0x05
41#define HMC5883_DATA_OUT_Z_LSB_REG 0x06
42#define HMC5883_DATA_OUT_Y_MSB_REG 0x07
43#define HMC5883_DATA_OUT_Y_LSB_REG 0x08
39#define HMC5843_STATUS_REG 0x09 44#define HMC5843_STATUS_REG 0x09
40#define HMC5843_ID_REG_A 0x0A 45#define HMC5843_ID_REG_A 0x0A
41#define HMC5843_ID_REG_B 0x0B 46#define HMC5843_ID_REG_B 0x0B
42#define HMC5843_ID_REG_C 0x0C 47#define HMC5843_ID_REG_C 0x0C
43 48
49enum hmc5843_ids {
50 HMC5843_ID,
51 HMC5883_ID,
52 HMC5883L_ID,
53};
54
55/*
56 * Beware: identification of the HMC5883 is still "H43";
57 * I2C address is also unchanged
58 */
44#define HMC5843_ID_REG_LENGTH 0x03 59#define HMC5843_ID_REG_LENGTH 0x03
45#define HMC5843_ID_STRING "H43" 60#define HMC5843_ID_STRING "H43"
61#define HMC5843_I2C_ADDRESS 0x1E
46 62
47/* 63/*
48 * Range settings in (+-)Ga 64 * Range gain settings in (+-)Ga
49 * */ 65 * Beware: HMC5843 and HMC5883 have different recommended sensor field
50#define RANGE_GAIN_OFFSET 0x05 66 * ranges; default corresponds to +-1.0 Ga and +-1.3 Ga, respectively
51 67 */
52#define RANGE_0_7 0x00 68#define HMC5843_RANGE_GAIN_OFFSET 0x05
53#define RANGE_1_0 0x01 /* default */ 69#define HMC5843_RANGE_GAIN_DEFAULT 0x01
54#define RANGE_1_5 0x02 70#define HMC5843_RANGE_GAIN_MAX 0x07
55#define RANGE_2_0 0x03
56#define RANGE_3_2 0x04
57#define RANGE_3_8 0x05
58#define RANGE_4_5 0x06
59#define RANGE_6_5 0x07 /* Not recommended */
60 71
61/* 72/*
62 * Device status 73 * Device status
63 */ 74 */
64#define DATA_READY 0x01 75#define HMC5843_DATA_READY 0x01
65#define DATA_OUTPUT_LOCK 0x02 76#define HMC5843_DATA_OUTPUT_LOCK 0x02
66#define VOLTAGE_REGULATOR_ENABLED 0x04 77/* Does not exist on HMC5883, not used */
78#define HMC5843_VOLTAGE_REGULATOR_ENABLED 0x04
67 79
68/* 80/*
69 * Mode register configuration 81 * Mode register configuration
70 */ 82 */
71#define MODE_CONVERSION_CONTINUOUS 0x00 83#define HMC5843_MODE_CONVERSION_CONTINUOUS 0x00
72#define MODE_CONVERSION_SINGLE 0x01 84#define HMC5843_MODE_CONVERSION_SINGLE 0x01
73#define MODE_IDLE 0x02 85#define HMC5843_MODE_IDLE 0x02
74#define MODE_SLEEP 0x03 86#define HMC5843_MODE_SLEEP 0x03
75 87#define HMC5843_MODE_MASK 0x03
76/* Minimum Data Output Rate in 1/10 Hz */ 88
77#define RATE_OFFSET 0x02 89/*
78#define RATE_BITMASK 0x1C 90 * HMC5843: Minimum data output rate
79#define RATE_5 0x00 91 * HMC5883: Typical data output rate
80#define RATE_10 0x01 92 */
81#define RATE_20 0x02 93#define HMC5843_RATE_OFFSET 0x02
82#define RATE_50 0x03 94#define HMC5843_RATE_BITMASK 0x1C
83#define RATE_100 0x04 95#define HMC5843_RATE_NOT_USED 0x07
84#define RATE_200 0x05
85#define RATE_500 0x06
86#define RATE_NOT_USED 0x07
87 96
88/* 97/*
89 * Device Configuration 98 * Device measurement configuration
90 */ 99 */
91#define CONF_NORMAL 0x00 100#define HMC5843_MEAS_CONF_NORMAL 0x00
92#define CONF_POSITIVE_BIAS 0x01 101#define HMC5843_MEAS_CONF_POSITIVE_BIAS 0x01
93#define CONF_NEGATIVE_BIAS 0x02 102#define HMC5843_MEAS_CONF_NEGATIVE_BIAS 0x02
94#define CONF_NOT_USED 0x03 103#define HMC5843_MEAS_CONF_NOT_USED 0x03
95#define MEAS_CONF_MASK 0x03 104#define HMC5843_MEAS_CONF_MASK 0x03
96 105
97static int hmc5843_regval_to_nanoscale[] = { 106/*
107 * Scaling factors: 10000000/Gain
108 */
109static const int hmc5843_regval_to_nanoscale[] = {
98 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714 110 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714
99}; 111};
100 112
101static const int regval_to_input_field_mg[] = { 113static const int hmc5883_regval_to_nanoscale[] = {
102 700, 114 7812, 9766, 13021, 16287, 24096, 27701, 32573, 45662
103 1000,
104 1500,
105 2000,
106 3200,
107 3800,
108 4500,
109 6500
110}; 115};
111static const char * const regval_to_samp_freq[] = { 116
112 "0.5", 117static const int hmc5883l_regval_to_nanoscale[] = {
113 "1", 118 7299, 9174, 12195, 15152, 22727, 25641, 30303, 43478
114 "2", 119};
115 "5", 120
116 "10", 121/*
117 "20", 122 * From the HMC5843 datasheet:
118 "50", 123 * Value | Sensor input field range (Ga) | Gain (counts/milli-Gauss)
124 * 0 | (+-)0.7 | 1620
125 * 1 | (+-)1.0 | 1300
126 * 2 | (+-)1.5 | 970
127 * 3 | (+-)2.0 | 780
128 * 4 | (+-)3.2 | 530
129 * 5 | (+-)3.8 | 460
130 * 6 | (+-)4.5 | 390
131 * 7 | (+-)6.5 | 280
132 *
133 * From the HMC5883 datasheet:
134 * Value | Recommended sensor field range (Ga) | Gain (counts/Gauss)
135 * 0 | (+-)0.9 | 1280
136 * 1 | (+-)1.2 | 1024
137 * 2 | (+-)1.9 | 768
138 * 3 | (+-)2.5 | 614
139 * 4 | (+-)4.0 | 415
140 * 5 | (+-)4.6 | 361
141 * 6 | (+-)5.5 | 307
142 * 7 | (+-)7.9 | 219
143 *
144 * From the HMC5883L datasheet:
145 * Value | Recommended sensor field range (Ga) | Gain (LSB/Gauss)
146 * 0 | (+-)0.88 | 1370
147 * 1 | (+-)1.3 | 1090
148 * 2 | (+-)1.9 | 820
149 * 3 | (+-)2.5 | 660
150 * 4 | (+-)4.0 | 440
151 * 5 | (+-)4.7 | 390
152 * 6 | (+-)5.6 | 330
153 * 7 | (+-)8.1 | 230
154 */
155static const int hmc5843_regval_to_input_field_mga[] = {
156 700, 1000, 1500, 2000, 3200, 3800, 4500, 6500
157};
158
159static const int hmc5883_regval_to_input_field_mga[] = {
160 900, 1200, 1900, 2500, 4000, 4600, 5500, 7900
161};
162
163static const int hmc5883l_regval_to_input_field_mga[] = {
164 880, 1300, 1900, 2500, 4000, 4700, 5600, 8100
165};
166
167/*
168 * From the datasheet:
169 * Value | HMC5843 | HMC5883/HMC5883L
170 * | Data output rate (Hz) | Data output rate (Hz)
171 * 0 | 0.5 | 0.75
172 * 1 | 1 | 1.5
173 * 2 | 2 | 3
174 * 3 | 5 | 7.5
175 * 4 | 10 (default) | 15
176 * 5 | 20 | 30
177 * 6 | 50 | 75
178 * 7 | Not used | Not used
179 */
180static const char * const hmc5843_regval_to_sample_freq[] = {
181 "0.5", "1", "2", "5", "10", "20", "50",
182};
183
184static const char * const hmc5883_regval_to_sample_freq[] = {
185 "0.75", "1.5", "3", "7.5", "15", "30", "75",
119}; 186};
120 187
121/* Addresses to scan: 0x1E */ 188/* Addresses to scan: 0x1E */
122static const unsigned short normal_i2c[] = { HMC5843_I2C_ADDRESS, 189static const unsigned short normal_i2c[] = { HMC5843_I2C_ADDRESS,
123 I2C_CLIENT_END }; 190 I2C_CLIENT_END };
191
192/* Describe chip variants */
193struct hmc5843_chip_info {
194 const struct iio_chan_spec *channels;
195 int num_channels;
196 const char * const *regval_to_sample_freq;
197 const int *regval_to_input_field_mga;
198 const int *regval_to_nanoscale;
199};
124 200
125/* Each client has this additional data */ 201/* Each client has this additional data */
126struct hmc5843_data { 202struct hmc5843_data {
127 struct mutex lock; 203 struct mutex lock;
128 u8 rate; 204 u8 rate;
129 u8 meas_conf; 205 u8 meas_conf;
130 u8 operating_mode; 206 u8 operating_mode;
131 u8 range; 207 u8 range;
208 const struct hmc5843_chip_info *variant;
132}; 209};
133 210
134static void hmc5843_init_client(struct i2c_client *client); 211/* The lower two bits contain the current conversion mode */
135
136static s32 hmc5843_configure(struct i2c_client *client, 212static s32 hmc5843_configure(struct i2c_client *client,
137 u8 operating_mode) 213 u8 operating_mode)
138{ 214{
139 /* The lower two bits contain the current conversion mode */
140 return i2c_smbus_write_byte_data(client, 215 return i2c_smbus_write_byte_data(client,
141 HMC5843_MODE_REG, 216 HMC5843_MODE_REG,
142 (operating_mode & 0x03)); 217 operating_mode & HMC5843_MODE_MASK);
143} 218}
144 219
145/* Return the measurement value from the specified channel */ 220/* Return the measurement value from the specified channel */
@@ -153,7 +228,7 @@ static int hmc5843_read_measurement(struct iio_dev *indio_dev,
153 228
154 mutex_lock(&data->lock); 229 mutex_lock(&data->lock);
155 result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); 230 result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG);
156 while (!(result & DATA_READY)) 231 while (!(result & HMC5843_DATA_READY))
157 result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); 232 result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG);
158 233
159 result = i2c_smbus_read_word_data(client, address); 234 result = i2c_smbus_read_word_data(client, address);
@@ -161,30 +236,29 @@ static int hmc5843_read_measurement(struct iio_dev *indio_dev,
161 if (result < 0) 236 if (result < 0)
162 return -EINVAL; 237 return -EINVAL;
163 238
164 *val = (s16)swab16((u16)result); 239 *val = (s16)swab16((u16)result);
165 return IIO_VAL_INT; 240 return IIO_VAL_INT;
166} 241}
167 242
168
169/* 243/*
170 * From the datasheet 244 * From the datasheet:
171 * 0 - Continuous-Conversion Mode: In continuous-conversion mode, the 245 * 0 - Continuous-Conversion Mode: In continuous-conversion mode, the
172 * device continuously performs conversions and places the result in the 246 * device continuously performs conversions and places the result in
173 * data register. 247 * the data register.
174 * 248 *
175 * 1 - Single-Conversion Mode : device performs a single measurement, 249 * 1 - Single-Conversion Mode : Device performs a single measurement,
176 * sets RDY high and returned to sleep mode 250 * sets RDY high and returns to sleep mode.
177 * 251 *
178 * 2 - Idle Mode : Device is placed in idle mode. 252 * 2 - Idle Mode : Device is placed in idle mode.
179 * 253 *
180 * 3 - Sleep Mode. Device is placed in sleep mode. 254 * 3 - Sleep Mode : Device is placed in sleep mode.
181 * 255 *
182 */ 256 */
183static ssize_t hmc5843_show_operating_mode(struct device *dev, 257static ssize_t hmc5843_show_operating_mode(struct device *dev,
184 struct device_attribute *attr, 258 struct device_attribute *attr,
185 char *buf) 259 char *buf)
186{ 260{
187 struct iio_dev *indio_dev = dev_get_drvdata(dev); 261 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
188 struct hmc5843_data *data = iio_priv(indio_dev); 262 struct hmc5843_data *data = iio_priv(indio_dev);
189 return sprintf(buf, "%d\n", data->operating_mode); 263 return sprintf(buf, "%d\n", data->operating_mode);
190} 264}
@@ -194,21 +268,22 @@ static ssize_t hmc5843_set_operating_mode(struct device *dev,
194 const char *buf, 268 const char *buf,
195 size_t count) 269 size_t count)
196{ 270{
197 struct iio_dev *indio_dev = dev_get_drvdata(dev); 271 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
198 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); 272 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
199 struct hmc5843_data *data = iio_priv(indio_dev); 273 struct hmc5843_data *data = iio_priv(indio_dev);
200 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 274 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
201 unsigned long operating_mode = 0; 275 unsigned long operating_mode = 0;
202 s32 status; 276 s32 status;
203 int error; 277 int error;
278
204 mutex_lock(&data->lock); 279 mutex_lock(&data->lock);
205 error = strict_strtoul(buf, 10, &operating_mode); 280 error = kstrtoul(buf, 10, &operating_mode);
206 if (error) { 281 if (error) {
207 count = error; 282 count = error;
208 goto exit; 283 goto exit;
209 } 284 }
210 dev_dbg(dev, "set Conversion mode to %lu\n", operating_mode); 285 dev_dbg(dev, "set conversion mode to %lu\n", operating_mode);
211 if (operating_mode > MODE_SLEEP) { 286 if (operating_mode > HMC5843_MODE_SLEEP) {
212 count = -EINVAL; 287 count = -EINVAL;
213 goto exit; 288 goto exit;
214 } 289 }
@@ -225,6 +300,7 @@ exit:
225 mutex_unlock(&data->lock); 300 mutex_unlock(&data->lock);
226 return count; 301 return count;
227} 302}
303
228static IIO_DEVICE_ATTR(operating_mode, 304static IIO_DEVICE_ATTR(operating_mode,
229 S_IWUSR | S_IRUGO, 305 S_IWUSR | S_IRUGO,
230 hmc5843_show_operating_mode, 306 hmc5843_show_operating_mode,
@@ -234,25 +310,29 @@ static IIO_DEVICE_ATTR(operating_mode,
234/* 310/*
235 * API for setting the measurement configuration to 311 * API for setting the measurement configuration to
236 * Normal, Positive bias and Negative bias 312 * Normal, Positive bias and Negative bias
237 * From the datasheet
238 * 313 *
239 * Normal measurement configuration (default): In normal measurement 314 * From the datasheet:
240 * configuration the device follows normal measurement flow. Pins BP and BN 315 * 0 - Normal measurement configuration (default): In normal measurement
241 * are left floating and high impedance. 316 * configuration the device follows normal measurement flow. Pins BP
317 * and BN are left floating and high impedance.
242 * 318 *
243 * Positive bias configuration: In positive bias configuration, a positive 319 * 1 - Positive bias configuration: In positive bias configuration, a
244 * current is forced across the resistive load on pins BP and BN. 320 * positive current is forced across the resistive load on pins BP
321 * and BN.
245 * 322 *
246 * Negative bias configuration. In negative bias configuration, a negative 323 * 2 - Negative bias configuration. In negative bias configuration, a
247 * current is forced across the resistive load on pins BP and BN. 324 * negative current is forced across the resistive load on pins BP
325 * and BN.
248 * 326 *
249 */ 327 */
250static s32 hmc5843_set_meas_conf(struct i2c_client *client, 328static s32 hmc5843_set_meas_conf(struct i2c_client *client,
251 u8 meas_conf) 329 u8 meas_conf)
252{ 330{
253 struct hmc5843_data *data = i2c_get_clientdata(client); 331 struct iio_dev *indio_dev = i2c_get_clientdata(client);
332 struct hmc5843_data *data = iio_priv(indio_dev);
254 u8 reg_val; 333 u8 reg_val;
255 reg_val = (meas_conf & MEAS_CONF_MASK) | (data->rate << RATE_OFFSET); 334 reg_val = (meas_conf & HMC5843_MEAS_CONF_MASK) |
335 (data->rate << HMC5843_RATE_OFFSET);
256 return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val); 336 return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val);
257} 337}
258 338
@@ -260,7 +340,7 @@ static ssize_t hmc5843_show_measurement_configuration(struct device *dev,
260 struct device_attribute *attr, 340 struct device_attribute *attr,
261 char *buf) 341 char *buf)
262{ 342{
263 struct iio_dev *indio_dev = dev_get_drvdata(dev); 343 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
264 struct hmc5843_data *data = iio_priv(indio_dev); 344 struct hmc5843_data *data = iio_priv(indio_dev);
265 return sprintf(buf, "%d\n", data->meas_conf); 345 return sprintf(buf, "%d\n", data->meas_conf);
266} 346}
@@ -270,16 +350,20 @@ static ssize_t hmc5843_set_measurement_configuration(struct device *dev,
270 const char *buf, 350 const char *buf,
271 size_t count) 351 size_t count)
272{ 352{
273 struct iio_dev *indio_dev = dev_get_drvdata(dev); 353 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
274 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); 354 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
275 struct hmc5843_data *data = i2c_get_clientdata(client); 355 struct hmc5843_data *data = iio_priv(indio_dev);
276 unsigned long meas_conf = 0; 356 unsigned long meas_conf = 0;
277 int error = strict_strtoul(buf, 10, &meas_conf); 357 int error;
358
359 error = kstrtoul(buf, 10, &meas_conf);
278 if (error) 360 if (error)
279 return error; 361 return error;
280 mutex_lock(&data->lock); 362 if (meas_conf >= HMC5843_MEAS_CONF_NOT_USED)
363 return -EINVAL;
281 364
282 dev_dbg(dev, "set mode to %lu\n", meas_conf); 365 mutex_lock(&data->lock);
366 dev_dbg(dev, "set measurement configuration to %lu\n", meas_conf);
283 if (hmc5843_set_meas_conf(client, meas_conf)) { 367 if (hmc5843_set_meas_conf(client, meas_conf)) {
284 count = -EINVAL; 368 count = -EINVAL;
285 goto exit; 369 goto exit;
@@ -290,71 +374,85 @@ exit:
290 mutex_unlock(&data->lock); 374 mutex_unlock(&data->lock);
291 return count; 375 return count;
292} 376}
377
293static IIO_DEVICE_ATTR(meas_conf, 378static IIO_DEVICE_ATTR(meas_conf,
294 S_IWUSR | S_IRUGO, 379 S_IWUSR | S_IRUGO,
295 hmc5843_show_measurement_configuration, 380 hmc5843_show_measurement_configuration,
296 hmc5843_set_measurement_configuration, 381 hmc5843_set_measurement_configuration,
297 0); 382 0);
298 383
299/* 384static ssize_t hmc5843_show_sampling_frequencies_available(struct device *dev,
300 * From Datasheet 385 struct device_attribute *attr,
301 * The table shows the minimum data output 386 char *buf)
302 * Value | Minimum data output rate(Hz) 387{
303 * 0 | 0.5 388 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
304 * 1 | 1 389 struct hmc5843_data *data = iio_priv(indio_dev);
305 * 2 | 2 390 ssize_t total_n = 0;
306 * 3 | 5 391 int i;
307 * 4 | 10 (default) 392
308 * 5 | 20 393 for (i = 0; i < HMC5843_RATE_NOT_USED; i++) {
309 * 6 | 50 394 ssize_t n = sprintf(buf, "%s ", data->variant->regval_to_sample_freq[i]);
310 * 7 | Not used 395 buf += n;
311 */ 396 total_n += n;
312static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.5 1 2 5 10 20 50"); 397 }
398 /* replace trailing space by newline */
399 buf[-1] = '\n';
400
401 return total_n;
402}
403
404static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(hmc5843_show_sampling_frequencies_available);
313 405
314static s32 hmc5843_set_rate(struct i2c_client *client, 406static s32 hmc5843_set_rate(struct i2c_client *client,
315 u8 rate) 407 u8 rate)
316{ 408{
317 struct hmc5843_data *data = i2c_get_clientdata(client); 409 struct iio_dev *indio_dev = i2c_get_clientdata(client);
410 struct hmc5843_data *data = iio_priv(indio_dev);
318 u8 reg_val; 411 u8 reg_val;
319 412
320 reg_val = (data->meas_conf) | (rate << RATE_OFFSET); 413 if (rate >= HMC5843_RATE_NOT_USED) {
321 if (rate >= RATE_NOT_USED) {
322 dev_err(&client->dev, 414 dev_err(&client->dev,
323 "This data output rate is not supported\n"); 415 "data output rate is not supported\n");
324 return -EINVAL; 416 return -EINVAL;
325 } 417 }
418
419 reg_val = data->meas_conf | (rate << HMC5843_RATE_OFFSET);
326 return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val); 420 return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val);
327} 421}
328 422
329static ssize_t set_sampling_frequency(struct device *dev, 423static int hmc5843_check_sampling_frequency(struct hmc5843_data *data,
424 const char *buf)
425{
426 const char * const *samp_freq = data->variant->regval_to_sample_freq;
427 int i;
428
429 for (i = 0; i < HMC5843_RATE_NOT_USED; i++) {
430 if (sysfs_streq(buf, samp_freq[i]))
431 return i;
432 }
433
434 return -EINVAL;
435}
436
437static ssize_t hmc5843_set_sampling_frequency(struct device *dev,
330 struct device_attribute *attr, 438 struct device_attribute *attr,
331 const char *buf, size_t count) 439 const char *buf, size_t count)
332{ 440{
333 441
334 struct iio_dev *indio_dev = dev_get_drvdata(dev); 442 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
335 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); 443 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
336 struct hmc5843_data *data = iio_priv(indio_dev); 444 struct hmc5843_data *data = iio_priv(indio_dev);
337 unsigned long rate = 0; 445 int rate;
338 446
339 if (strncmp(buf, "0.5" , 3) == 0) 447 rate = hmc5843_check_sampling_frequency(data, buf);
340 rate = RATE_5; 448 if (rate < 0) {
341 else if (strncmp(buf, "1" , 1) == 0) 449 dev_err(&client->dev,
342 rate = RATE_10; 450 "sampling frequency is not supported\n");
343 else if (strncmp(buf, "2", 1) == 0) 451 return rate;
344 rate = RATE_20; 452 }
345 else if (strncmp(buf, "5", 1) == 0)
346 rate = RATE_50;
347 else if (strncmp(buf, "10", 2) == 0)
348 rate = RATE_100;
349 else if (strncmp(buf, "20" , 2) == 0)
350 rate = RATE_200;
351 else if (strncmp(buf, "50" , 2) == 0)
352 rate = RATE_500;
353 else
354 return -EINVAL;
355 453
356 mutex_lock(&data->lock); 454 mutex_lock(&data->lock);
357 dev_dbg(dev, "set rate to %lu\n", rate); 455 dev_dbg(dev, "set rate to %d\n", rate);
358 if (hmc5843_set_rate(client, rate)) { 456 if (hmc5843_set_rate(client, rate)) {
359 count = -EINVAL; 457 count = -EINVAL;
360 goto exit; 458 goto exit;
@@ -366,89 +464,79 @@ exit:
366 return count; 464 return count;
367} 465}
368 466
369static ssize_t show_sampling_frequency(struct device *dev, 467static ssize_t hmc5843_show_sampling_frequency(struct device *dev,
370 struct device_attribute *attr, char *buf) 468 struct device_attribute *attr, char *buf)
371{ 469{
372 struct iio_dev *indio_dev = dev_get_drvdata(dev); 470 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
373 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); 471 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
374 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 472 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
473 struct hmc5843_data *data = iio_priv(indio_dev);
375 s32 rate; 474 s32 rate;
376 475
377 rate = i2c_smbus_read_byte_data(client, this_attr->address); 476 rate = i2c_smbus_read_byte_data(client, this_attr->address);
378 if (rate < 0) 477 if (rate < 0)
379 return rate; 478 return rate;
380 rate = (rate & RATE_BITMASK) >> RATE_OFFSET; 479 rate = (rate & HMC5843_RATE_BITMASK) >> HMC5843_RATE_OFFSET;
381 return sprintf(buf, "%s\n", regval_to_samp_freq[rate]); 480 return sprintf(buf, "%s\n", data->variant->regval_to_sample_freq[rate]);
382} 481}
482
383static IIO_DEVICE_ATTR(sampling_frequency, 483static IIO_DEVICE_ATTR(sampling_frequency,
384 S_IWUSR | S_IRUGO, 484 S_IWUSR | S_IRUGO,
385 show_sampling_frequency, 485 hmc5843_show_sampling_frequency,
386 set_sampling_frequency, 486 hmc5843_set_sampling_frequency,
387 HMC5843_CONFIG_REG_A); 487 HMC5843_CONFIG_REG_A);
388 488
389/* 489static ssize_t hmc5843_show_range_gain(struct device *dev,
390 * From Datasheet
391 * Nominal gain settings
392 * Value | Sensor Input Field Range(Ga) | Gain(counts/ milli-gauss)
393 *0 |(+-)0.7 |1620
394 *1 |(+-)1.0 |1300
395 *2 |(+-)1.5 |970
396 *3 |(+-)2.0 |780
397 *4 |(+-)3.2 |530
398 *5 |(+-)3.8 |460
399 *6 |(+-)4.5 |390
400 *7 |(+-)6.5 |280
401 */
402static ssize_t show_range(struct device *dev,
403 struct device_attribute *attr, 490 struct device_attribute *attr,
404 char *buf) 491 char *buf)
405{ 492{
406 u8 range; 493 u8 range;
407 struct iio_dev *indio_dev = dev_get_drvdata(dev); 494 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
408 struct hmc5843_data *data = iio_priv(indio_dev); 495 struct hmc5843_data *data = iio_priv(indio_dev);
409 496
410 range = data->range; 497 range = data->range;
411 return sprintf(buf, "%d\n", regval_to_input_field_mg[range]); 498 return sprintf(buf, "%d\n", data->variant->regval_to_input_field_mga[range]);
412} 499}
413 500
414static ssize_t set_range(struct device *dev, 501static ssize_t hmc5843_set_range_gain(struct device *dev,
415 struct device_attribute *attr, 502 struct device_attribute *attr,
416 const char *buf, 503 const char *buf,
417 size_t count) 504 size_t count)
418{ 505{
419 struct iio_dev *indio_dev = dev_get_drvdata(dev); 506 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
420 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); 507 struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
421 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 508 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
422 struct hmc5843_data *data = iio_priv(indio_dev); 509 struct hmc5843_data *data = iio_priv(indio_dev);
423 unsigned long range = 0; 510 unsigned long range = 0;
424 int error; 511 int error;
512
425 mutex_lock(&data->lock); 513 mutex_lock(&data->lock);
426 error = strict_strtoul(buf, 10, &range); 514 error = kstrtoul(buf, 10, &range);
427 if (error) { 515 if (error) {
428 count = error; 516 count = error;
429 goto exit; 517 goto exit;
430 } 518 }
431 dev_dbg(dev, "set range to %lu\n", range); 519 dev_dbg(dev, "set range to %lu\n", range);
432 520
433 if (range > RANGE_6_5) { 521 if (range > HMC5843_RANGE_GAIN_MAX) {
434 count = -EINVAL; 522 count = -EINVAL;
435 goto exit; 523 goto exit;
436 } 524 }
437 525
438 data->range = range; 526 data->range = range;
439 range = range << RANGE_GAIN_OFFSET; 527 range = range << HMC5843_RANGE_GAIN_OFFSET;
440 if (i2c_smbus_write_byte_data(client, this_attr->address, range)) 528 if (i2c_smbus_write_byte_data(client, this_attr->address, range))
441 count = -EINVAL; 529 count = -EINVAL;
442 530
443exit: 531exit:
444 mutex_unlock(&data->lock); 532 mutex_unlock(&data->lock);
445 return count; 533 return count;
446
447} 534}
535
448static IIO_DEVICE_ATTR(in_magn_range, 536static IIO_DEVICE_ATTR(in_magn_range,
449 S_IWUSR | S_IRUGO, 537 S_IWUSR | S_IRUGO,
450 show_range, 538 hmc5843_show_range_gain,
451 set_range, 539 hmc5843_set_range_gain,
452 HMC5843_CONFIG_REG_B); 540 HMC5843_CONFIG_REG_B);
453 541
454static int hmc5843_read_raw(struct iio_dev *indio_dev, 542static int hmc5843_read_raw(struct iio_dev *indio_dev,
@@ -459,13 +547,13 @@ static int hmc5843_read_raw(struct iio_dev *indio_dev,
459 struct hmc5843_data *data = iio_priv(indio_dev); 547 struct hmc5843_data *data = iio_priv(indio_dev);
460 548
461 switch (mask) { 549 switch (mask) {
462 case 0: 550 case IIO_CHAN_INFO_RAW:
463 return hmc5843_read_measurement(indio_dev, 551 return hmc5843_read_measurement(indio_dev,
464 chan->address, 552 chan->address,
465 val); 553 val);
466 case IIO_CHAN_INFO_SCALE: 554 case IIO_CHAN_INFO_SCALE:
467 *val = 0; 555 *val = 0;
468 *val2 = hmc5843_regval_to_nanoscale[data->range]; 556 *val2 = data->variant->regval_to_nanoscale[data->range];
469 return IIO_VAL_INT_PLUS_NANO; 557 return IIO_VAL_INT_PLUS_NANO;
470 }; 558 };
471 return -EINVAL; 559 return -EINVAL;
@@ -476,7 +564,8 @@ static int hmc5843_read_raw(struct iio_dev *indio_dev,
476 .type = IIO_MAGN, \ 564 .type = IIO_MAGN, \
477 .modified = 1, \ 565 .modified = 1, \
478 .channel2 = IIO_MOD_##axis, \ 566 .channel2 = IIO_MOD_##axis, \
479 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ 567 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
568 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
480 .address = add \ 569 .address = add \
481 } 570 }
482 571
@@ -486,12 +575,18 @@ static const struct iio_chan_spec hmc5843_channels[] = {
486 HMC5843_CHANNEL(Z, HMC5843_DATA_OUT_Z_MSB_REG), 575 HMC5843_CHANNEL(Z, HMC5843_DATA_OUT_Z_MSB_REG),
487}; 576};
488 577
578static const struct iio_chan_spec hmc5883_channels[] = {
579 HMC5843_CHANNEL(X, HMC5843_DATA_OUT_X_MSB_REG),
580 HMC5843_CHANNEL(Y, HMC5883_DATA_OUT_Y_MSB_REG),
581 HMC5843_CHANNEL(Z, HMC5883_DATA_OUT_Z_MSB_REG),
582};
583
489static struct attribute *hmc5843_attributes[] = { 584static struct attribute *hmc5843_attributes[] = {
490 &iio_dev_attr_meas_conf.dev_attr.attr, 585 &iio_dev_attr_meas_conf.dev_attr.attr,
491 &iio_dev_attr_operating_mode.dev_attr.attr, 586 &iio_dev_attr_operating_mode.dev_attr.attr,
492 &iio_dev_attr_sampling_frequency.dev_attr.attr, 587 &iio_dev_attr_sampling_frequency.dev_attr.attr,
493 &iio_dev_attr_in_magn_range.dev_attr.attr, 588 &iio_dev_attr_in_magn_range.dev_attr.attr,
494 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 589 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
495 NULL 590 NULL
496}; 591};
497 592
@@ -499,6 +594,33 @@ static const struct attribute_group hmc5843_group = {
499 .attrs = hmc5843_attributes, 594 .attrs = hmc5843_attributes,
500}; 595};
501 596
597static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = {
598 [HMC5843_ID] = {
599 .channels = hmc5843_channels,
600 .num_channels = ARRAY_SIZE(hmc5843_channels),
601 .regval_to_sample_freq = hmc5843_regval_to_sample_freq,
602 .regval_to_input_field_mga =
603 hmc5843_regval_to_input_field_mga,
604 .regval_to_nanoscale = hmc5843_regval_to_nanoscale,
605 },
606 [HMC5883_ID] = {
607 .channels = hmc5883_channels,
608 .num_channels = ARRAY_SIZE(hmc5883_channels),
609 .regval_to_sample_freq = hmc5883_regval_to_sample_freq,
610 .regval_to_input_field_mga =
611 hmc5883_regval_to_input_field_mga,
612 .regval_to_nanoscale = hmc5883_regval_to_nanoscale,
613 },
614 [HMC5883L_ID] = {
615 .channels = hmc5883_channels,
616 .num_channels = ARRAY_SIZE(hmc5883_channels),
617 .regval_to_sample_freq = hmc5883_regval_to_sample_freq,
618 .regval_to_input_field_mga =
619 hmc5883l_regval_to_input_field_mga,
620 .regval_to_nanoscale = hmc5883l_regval_to_nanoscale,
621 },
622};
623
502static int hmc5843_detect(struct i2c_client *client, 624static int hmc5843_detect(struct i2c_client *client,
503 struct i2c_board_info *info) 625 struct i2c_board_info *info)
504{ 626{
@@ -518,18 +640,23 @@ static int hmc5843_detect(struct i2c_client *client,
518 return 0; 640 return 0;
519} 641}
520 642
521/* Called when we have found a new HMC5843. */ 643/* Called when we have found a new HMC58X3 */
522static void hmc5843_init_client(struct i2c_client *client) 644static void hmc5843_init_client(struct i2c_client *client,
645 const struct i2c_device_id *id)
523{ 646{
524 struct iio_dev *indio_dev = i2c_get_clientdata(client); 647 struct iio_dev *indio_dev = i2c_get_clientdata(client);
525 struct hmc5843_data *data = iio_priv(indio_dev); 648 struct hmc5843_data *data = iio_priv(indio_dev);
526 649
650 data->variant = &hmc5843_chip_info_tbl[id->driver_data];
651 indio_dev->channels = data->variant->channels;
652 indio_dev->num_channels = data->variant->num_channels;
527 hmc5843_set_meas_conf(client, data->meas_conf); 653 hmc5843_set_meas_conf(client, data->meas_conf);
528 hmc5843_set_rate(client, data->rate); 654 hmc5843_set_rate(client, data->rate);
529 hmc5843_configure(client, data->operating_mode); 655 hmc5843_configure(client, data->operating_mode);
530 i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range); 656 i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range);
531 mutex_init(&data->lock); 657 mutex_init(&data->lock);
532 pr_info("HMC5843 initialized\n"); 658
659 pr_info("%s initialized\n", id->name);
533} 660}
534 661
535static const struct iio_info hmc5843_info = { 662static const struct iio_info hmc5843_info = {
@@ -545,35 +672,34 @@ static int hmc5843_probe(struct i2c_client *client,
545 struct iio_dev *indio_dev; 672 struct iio_dev *indio_dev;
546 int err = 0; 673 int err = 0;
547 674
548 indio_dev = iio_allocate_device(sizeof(*data)); 675 indio_dev = iio_device_alloc(sizeof(*data));
549 if (indio_dev == NULL) { 676 if (indio_dev == NULL) {
550 err = -ENOMEM; 677 err = -ENOMEM;
551 goto exit; 678 goto exit;
552 } 679 }
553 data = iio_priv(indio_dev);
554 /* default settings at probe */
555 680
556 data->meas_conf = CONF_NORMAL; 681 /* default settings at probe */
557 data->range = RANGE_1_0; 682 data = iio_priv(indio_dev);
558 data->operating_mode = MODE_CONVERSION_CONTINUOUS; 683 data->meas_conf = HMC5843_MEAS_CONF_NORMAL;
684 data->range = HMC5843_RANGE_GAIN_DEFAULT;
685 data->operating_mode = HMC5843_MODE_CONVERSION_CONTINUOUS;
559 686
560 i2c_set_clientdata(client, indio_dev); 687 i2c_set_clientdata(client, indio_dev);
561 688 hmc5843_init_client(client, id);
562 /* Initialize the HMC5843 chip */
563 hmc5843_init_client(client);
564 689
565 indio_dev->info = &hmc5843_info; 690 indio_dev->info = &hmc5843_info;
566 indio_dev->name = id->name; 691 indio_dev->name = id->name;
567 indio_dev->channels = hmc5843_channels;
568 indio_dev->num_channels = ARRAY_SIZE(hmc5843_channels);
569 indio_dev->dev.parent = &client->dev; 692 indio_dev->dev.parent = &client->dev;
570 indio_dev->modes = INDIO_DIRECT_MODE; 693 indio_dev->modes = INDIO_DIRECT_MODE;
694
571 err = iio_device_register(indio_dev); 695 err = iio_device_register(indio_dev);
572 if (err) 696 if (err)
573 goto exit_free2; 697 goto exit_free2;
698
574 return 0; 699 return 0;
700
575exit_free2: 701exit_free2:
576 iio_free_device(indio_dev); 702 iio_device_free(indio_dev);
577exit: 703exit:
578 return err; 704 return err;
579} 705}
@@ -584,8 +710,8 @@ static int hmc5843_remove(struct i2c_client *client)
584 710
585 iio_device_unregister(indio_dev); 711 iio_device_unregister(indio_dev);
586 /* sleep mode to save power */ 712 /* sleep mode to save power */
587 hmc5843_configure(client, MODE_SLEEP); 713 hmc5843_configure(client, HMC5843_MODE_SLEEP);
588 iio_free_device(indio_dev); 714 iio_device_free(indio_dev);
589 715
590 return 0; 716 return 0;
591} 717}
@@ -593,14 +719,18 @@ static int hmc5843_remove(struct i2c_client *client)
593#ifdef CONFIG_PM_SLEEP 719#ifdef CONFIG_PM_SLEEP
594static int hmc5843_suspend(struct device *dev) 720static int hmc5843_suspend(struct device *dev)
595{ 721{
596 hmc5843_configure(to_i2c_client(dev), MODE_SLEEP); 722 hmc5843_configure(to_i2c_client(dev), HMC5843_MODE_SLEEP);
597 return 0; 723 return 0;
598} 724}
599 725
600static int hmc5843_resume(struct device *dev) 726static int hmc5843_resume(struct device *dev)
601{ 727{
602 struct hmc5843_data *data = i2c_get_clientdata(to_i2c_client(dev)); 728 struct i2c_client *client = to_i2c_client(dev);
603 hmc5843_configure(to_i2c_client(dev), data->operating_mode); 729 struct iio_dev *indio_dev = i2c_get_clientdata(client);
730 struct hmc5843_data *data = iio_priv(indio_dev);
731
732 hmc5843_configure(client, data->operating_mode);
733
604 return 0; 734 return 0;
605} 735}
606 736
@@ -611,7 +741,9 @@ static SIMPLE_DEV_PM_OPS(hmc5843_pm_ops, hmc5843_suspend, hmc5843_resume);
611#endif 741#endif
612 742
613static const struct i2c_device_id hmc5843_id[] = { 743static const struct i2c_device_id hmc5843_id[] = {
614 { "hmc5843", 0 }, 744 { "hmc5843", HMC5843_ID },
745 { "hmc5883", HMC5883_ID },
746 { "hmc5883l", HMC5883L_ID },
615 { } 747 { }
616}; 748};
617MODULE_DEVICE_TABLE(i2c, hmc5843_id); 749MODULE_DEVICE_TABLE(i2c, hmc5843_id);
@@ -630,5 +762,5 @@ static struct i2c_driver hmc5843_driver = {
630module_i2c_driver(hmc5843_driver); 762module_i2c_driver(hmc5843_driver);
631 763
632MODULE_AUTHOR("Shubhrajyoti Datta <shubhrajyoti@ti.com"); 764MODULE_AUTHOR("Shubhrajyoti Datta <shubhrajyoti@ti.com");
633MODULE_DESCRIPTION("HMC5843 driver"); 765MODULE_DESCRIPTION("HMC5843/5883/5883L driver");
634MODULE_LICENSE("GPL"); 766MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
index 57baac6c0d40..f04ece7fbc2f 100644
--- a/drivers/staging/iio/meter/ade7753.c
+++ b/drivers/staging/iio/meter/ade7753.c
@@ -18,8 +18,8 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "meter.h" 23#include "meter.h"
24#include "ade7753.h" 24#include "ade7753.h"
25 25
@@ -28,7 +28,7 @@ static int ade7753_spi_write_reg_8(struct device *dev,
28 u8 val) 28 u8 val)
29{ 29{
30 int ret; 30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev); 31 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
32 struct ade7753_state *st = iio_priv(indio_dev); 32 struct ade7753_state *st = iio_priv(indio_dev);
33 33
34 mutex_lock(&st->buf_lock); 34 mutex_lock(&st->buf_lock);
@@ -46,7 +46,7 @@ static int ade7753_spi_write_reg_16(struct device *dev,
46 u16 value) 46 u16 value)
47{ 47{
48 int ret; 48 int ret;
49 struct iio_dev *indio_dev = dev_get_drvdata(dev); 49 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
50 struct ade7753_state *st = iio_priv(indio_dev); 50 struct ade7753_state *st = iio_priv(indio_dev);
51 51
52 mutex_lock(&st->buf_lock); 52 mutex_lock(&st->buf_lock);
@@ -63,7 +63,7 @@ static int ade7753_spi_read_reg_8(struct device *dev,
63 u8 reg_address, 63 u8 reg_address,
64 u8 *val) 64 u8 *val)
65{ 65{
66 struct iio_dev *indio_dev = dev_get_drvdata(dev); 66 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
67 struct ade7753_state *st = iio_priv(indio_dev); 67 struct ade7753_state *st = iio_priv(indio_dev);
68 ssize_t ret; 68 ssize_t ret;
69 69
@@ -82,7 +82,7 @@ static int ade7753_spi_read_reg_16(struct device *dev,
82 u8 reg_address, 82 u8 reg_address,
83 u16 *val) 83 u16 *val)
84{ 84{
85 struct iio_dev *indio_dev = dev_get_drvdata(dev); 85 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
86 struct ade7753_state *st = iio_priv(indio_dev); 86 struct ade7753_state *st = iio_priv(indio_dev);
87 ssize_t ret; 87 ssize_t ret;
88 88
@@ -104,7 +104,7 @@ static int ade7753_spi_read_reg_24(struct device *dev,
104 u32 *val) 104 u32 *val)
105{ 105{
106 struct spi_message msg; 106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_get_drvdata(dev); 107 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7753_state *st = iio_priv(indio_dev); 108 struct ade7753_state *st = iio_priv(indio_dev);
109 int ret; 109 int ret;
110 struct spi_transfer xfers[] = { 110 struct spi_transfer xfers[] = {
@@ -416,7 +416,7 @@ static ssize_t ade7753_write_frequency(struct device *dev,
416 const char *buf, 416 const char *buf,
417 size_t len) 417 size_t len)
418{ 418{
419 struct iio_dev *indio_dev = dev_get_drvdata(dev); 419 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
420 struct ade7753_state *st = iio_priv(indio_dev); 420 struct ade7753_state *st = iio_priv(indio_dev);
421 unsigned long val; 421 unsigned long val;
422 int ret; 422 int ret;
@@ -517,7 +517,7 @@ static int __devinit ade7753_probe(struct spi_device *spi)
517 struct iio_dev *indio_dev; 517 struct iio_dev *indio_dev;
518 518
519 /* setup the industrialio driver allocated elements */ 519 /* setup the industrialio driver allocated elements */
520 indio_dev = iio_allocate_device(sizeof(*st)); 520 indio_dev = iio_device_alloc(sizeof(*st));
521 if (indio_dev == NULL) { 521 if (indio_dev == NULL) {
522 ret = -ENOMEM; 522 ret = -ENOMEM;
523 goto error_ret; 523 goto error_ret;
@@ -546,7 +546,7 @@ static int __devinit ade7753_probe(struct spi_device *spi)
546 return 0; 546 return 0;
547 547
548error_free_dev: 548error_free_dev:
549 iio_free_device(indio_dev); 549 iio_device_free(indio_dev);
550 550
551error_ret: 551error_ret:
552 return ret; 552 return ret;
@@ -564,7 +564,7 @@ static int ade7753_remove(struct spi_device *spi)
564 if (ret) 564 if (ret)
565 goto err_ret; 565 goto err_ret;
566 566
567 iio_free_device(indio_dev); 567 iio_device_free(indio_dev);
568err_ret: 568err_ret:
569 return ret; 569 return ret;
570} 570}
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
index 8d81c92007e9..6cee28a5e877 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -18,8 +18,8 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "meter.h" 23#include "meter.h"
24#include "ade7754.h" 24#include "ade7754.h"
25 25
@@ -28,7 +28,7 @@ static int ade7754_spi_write_reg_8(struct device *dev,
28 u8 val) 28 u8 val)
29{ 29{
30 int ret; 30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev); 31 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
32 struct ade7754_state *st = iio_priv(indio_dev); 32 struct ade7754_state *st = iio_priv(indio_dev);
33 33
34 mutex_lock(&st->buf_lock); 34 mutex_lock(&st->buf_lock);
@@ -46,7 +46,7 @@ static int ade7754_spi_write_reg_16(struct device *dev,
46 u16 value) 46 u16 value)
47{ 47{
48 int ret; 48 int ret;
49 struct iio_dev *indio_dev = dev_get_drvdata(dev); 49 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
50 struct ade7754_state *st = iio_priv(indio_dev); 50 struct ade7754_state *st = iio_priv(indio_dev);
51 51
52 mutex_lock(&st->buf_lock); 52 mutex_lock(&st->buf_lock);
@@ -63,7 +63,7 @@ static int ade7754_spi_read_reg_8(struct device *dev,
63 u8 reg_address, 63 u8 reg_address,
64 u8 *val) 64 u8 *val)
65{ 65{
66 struct iio_dev *indio_dev = dev_get_drvdata(dev); 66 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
67 struct ade7754_state *st = iio_priv(indio_dev); 67 struct ade7754_state *st = iio_priv(indio_dev);
68 int ret; 68 int ret;
69 69
@@ -82,7 +82,7 @@ static int ade7754_spi_read_reg_16(struct device *dev,
82 u8 reg_address, 82 u8 reg_address,
83 u16 *val) 83 u16 *val)
84{ 84{
85 struct iio_dev *indio_dev = dev_get_drvdata(dev); 85 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
86 struct ade7754_state *st = iio_priv(indio_dev); 86 struct ade7754_state *st = iio_priv(indio_dev);
87 int ret; 87 int ret;
88 88
@@ -104,7 +104,7 @@ static int ade7754_spi_read_reg_24(struct device *dev,
104 u32 *val) 104 u32 *val)
105{ 105{
106 struct spi_message msg; 106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_get_drvdata(dev); 107 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7754_state *st = iio_priv(indio_dev); 108 struct ade7754_state *st = iio_priv(indio_dev);
109 int ret; 109 int ret;
110 struct spi_transfer xfers[] = { 110 struct spi_transfer xfers[] = {
@@ -436,7 +436,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
436 const char *buf, 436 const char *buf,
437 size_t len) 437 size_t len)
438{ 438{
439 struct iio_dev *indio_dev = dev_get_drvdata(dev); 439 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
440 struct ade7754_state *st = iio_priv(indio_dev); 440 struct ade7754_state *st = iio_priv(indio_dev);
441 unsigned long val; 441 unsigned long val;
442 int ret; 442 int ret;
@@ -540,7 +540,7 @@ static int __devinit ade7754_probe(struct spi_device *spi)
540 struct iio_dev *indio_dev; 540 struct iio_dev *indio_dev;
541 541
542 /* setup the industrialio driver allocated elements */ 542 /* setup the industrialio driver allocated elements */
543 indio_dev = iio_allocate_device(sizeof(*st)); 543 indio_dev = iio_device_alloc(sizeof(*st));
544 if (indio_dev == NULL) { 544 if (indio_dev == NULL) {
545 ret = -ENOMEM; 545 ret = -ENOMEM;
546 goto error_ret; 546 goto error_ret;
@@ -568,7 +568,7 @@ static int __devinit ade7754_probe(struct spi_device *spi)
568 return 0; 568 return 0;
569 569
570error_free_dev: 570error_free_dev:
571 iio_free_device(indio_dev); 571 iio_device_free(indio_dev);
572 572
573error_ret: 573error_ret:
574 return ret; 574 return ret;
@@ -585,7 +585,7 @@ static int ade7754_remove(struct spi_device *spi)
585 if (ret) 585 if (ret)
586 goto err_ret; 586 goto err_ret;
587 587
588 iio_free_device(indio_dev); 588 iio_device_free(indio_dev);
589 589
590err_ret: 590err_ret:
591 return ret; 591 return ret;
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index dcb20294dfe8..96d6114a31aa 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -18,9 +18,9 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "../buffer.h" 23#include <linux/iio/buffer.h>
24#include "meter.h" 24#include "meter.h"
25#include "ade7758.h" 25#include "ade7758.h"
26 26
@@ -29,7 +29,7 @@ int ade7758_spi_write_reg_8(struct device *dev,
29 u8 val) 29 u8 val)
30{ 30{
31 int ret; 31 int ret;
32 struct iio_dev *indio_dev = dev_get_drvdata(dev); 32 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
33 struct ade7758_state *st = iio_priv(indio_dev); 33 struct ade7758_state *st = iio_priv(indio_dev);
34 34
35 mutex_lock(&st->buf_lock); 35 mutex_lock(&st->buf_lock);
@@ -48,7 +48,7 @@ static int ade7758_spi_write_reg_16(struct device *dev,
48{ 48{
49 int ret; 49 int ret;
50 struct spi_message msg; 50 struct spi_message msg;
51 struct iio_dev *indio_dev = dev_get_drvdata(dev); 51 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
52 struct ade7758_state *st = iio_priv(indio_dev); 52 struct ade7758_state *st = iio_priv(indio_dev);
53 struct spi_transfer xfers[] = { 53 struct spi_transfer xfers[] = {
54 { 54 {
@@ -77,7 +77,7 @@ static int ade7758_spi_write_reg_24(struct device *dev,
77{ 77{
78 int ret; 78 int ret;
79 struct spi_message msg; 79 struct spi_message msg;
80 struct iio_dev *indio_dev = dev_get_drvdata(dev); 80 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
81 struct ade7758_state *st = iio_priv(indio_dev); 81 struct ade7758_state *st = iio_priv(indio_dev);
82 struct spi_transfer xfers[] = { 82 struct spi_transfer xfers[] = {
83 { 83 {
@@ -106,7 +106,7 @@ int ade7758_spi_read_reg_8(struct device *dev,
106 u8 *val) 106 u8 *val)
107{ 107{
108 struct spi_message msg; 108 struct spi_message msg;
109 struct iio_dev *indio_dev = dev_get_drvdata(dev); 109 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
110 struct ade7758_state *st = iio_priv(indio_dev); 110 struct ade7758_state *st = iio_priv(indio_dev);
111 int ret; 111 int ret;
112 struct spi_transfer xfers[] = { 112 struct spi_transfer xfers[] = {
@@ -149,7 +149,7 @@ static int ade7758_spi_read_reg_16(struct device *dev,
149 u16 *val) 149 u16 *val)
150{ 150{
151 struct spi_message msg; 151 struct spi_message msg;
152 struct iio_dev *indio_dev = dev_get_drvdata(dev); 152 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
153 struct ade7758_state *st = iio_priv(indio_dev); 153 struct ade7758_state *st = iio_priv(indio_dev);
154 int ret; 154 int ret;
155 struct spi_transfer xfers[] = { 155 struct spi_transfer xfers[] = {
@@ -195,7 +195,7 @@ static int ade7758_spi_read_reg_24(struct device *dev,
195 u32 *val) 195 u32 *val)
196{ 196{
197 struct spi_message msg; 197 struct spi_message msg;
198 struct iio_dev *indio_dev = dev_get_drvdata(dev); 198 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
199 struct ade7758_state *st = iio_priv(indio_dev); 199 struct ade7758_state *st = iio_priv(indio_dev);
200 int ret; 200 int ret;
201 struct spi_transfer xfers[] = { 201 struct spi_transfer xfers[] = {
@@ -534,7 +534,7 @@ static ssize_t ade7758_write_frequency(struct device *dev,
534 const char *buf, 534 const char *buf,
535 size_t len) 535 size_t len)
536{ 536{
537 struct iio_dev *indio_dev = dev_get_drvdata(dev); 537 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
538 unsigned long val; 538 unsigned long val;
539 int ret; 539 int ret;
540 u8 reg, t; 540 u8 reg, t;
@@ -662,66 +662,217 @@ static const struct attribute_group ade7758_attribute_group = {
662}; 662};
663 663
664static struct iio_chan_spec ade7758_channels[] = { 664static struct iio_chan_spec ade7758_channels[] = {
665 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "raw", 0, 0, 665 {
666 IIO_CHAN_INFO_SCALE_SHARED_BIT, 666 .type = IIO_VOLTAGE,
667 AD7758_WT(AD7758_PHASE_A, AD7758_VOLTAGE), 667 .indexed = 1,
668 0, IIO_ST('s', 24, 32, 0), 0), 668 .channel = 0,
669 IIO_CHAN(IIO_CURRENT, 0, 1, 0, "raw", 0, 0, 669 .extend_name = "raw",
670 IIO_CHAN_INFO_SCALE_SHARED_BIT, 670 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
671 AD7758_WT(AD7758_PHASE_A, AD7758_CURRENT), 671 IIO_CHAN_INFO_SCALE_SHARED_BIT,
672 1, IIO_ST('s', 24, 32, 0), 0), 672 .address = AD7758_WT(AD7758_PHASE_A, AD7758_VOLTAGE),
673 IIO_CHAN(IIO_POWER, 0, 1, 0, "apparent_raw", 0, 0, 673 .scan_index = 0,
674 IIO_CHAN_INFO_SCALE_SHARED_BIT, 674 .scan_type = {
675 AD7758_WT(AD7758_PHASE_A, AD7758_APP_PWR), 675 .sign = 's',
676 2, IIO_ST('s', 24, 32, 0), 0), 676 .realbits = 24,
677 IIO_CHAN(IIO_POWER, 0, 1, 0, "active_raw", 0, 0, 677 .storagebits = 32,
678 IIO_CHAN_INFO_SCALE_SHARED_BIT, 678 },
679 AD7758_WT(AD7758_PHASE_A, AD7758_ACT_PWR), 679 }, {
680 3, IIO_ST('s', 24, 32, 0), 0), 680 .type = IIO_CURRENT,
681 IIO_CHAN(IIO_POWER, 0, 1, 0, "reactive_raw", 0, 0, 681 .indexed = 1,
682 IIO_CHAN_INFO_SCALE_SHARED_BIT, 682 .channel = 0,
683 AD7758_WT(AD7758_PHASE_A, AD7758_REACT_PWR), 683 .extend_name = "raw",
684 4, IIO_ST('s', 24, 32, 0), 0), 684 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
685 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "raw", 1, 0, 685 IIO_CHAN_INFO_SCALE_SHARED_BIT,
686 IIO_CHAN_INFO_SCALE_SHARED_BIT, 686 .address = AD7758_WT(AD7758_PHASE_A, AD7758_CURRENT),
687 AD7758_WT(AD7758_PHASE_B, AD7758_VOLTAGE), 687 .scan_index = 1,
688 5, IIO_ST('s', 24, 32, 0), 0), 688 .scan_type = {
689 IIO_CHAN(IIO_CURRENT, 0, 1, 0, "raw", 1, 0, 689 .sign = 's',
690 IIO_CHAN_INFO_SCALE_SHARED_BIT, 690 .realbits = 24,
691 AD7758_WT(AD7758_PHASE_B, AD7758_CURRENT), 691 .storagebits = 32,
692 6, IIO_ST('s', 24, 32, 0), 0), 692 },
693 IIO_CHAN(IIO_POWER, 0, 1, 0, "apparent_raw", 1, 0, 693 }, {
694 IIO_CHAN_INFO_SCALE_SHARED_BIT, 694 .type = IIO_POWER,
695 AD7758_WT(AD7758_PHASE_B, AD7758_APP_PWR), 695 .indexed = 1,
696 7, IIO_ST('s', 24, 32, 0), 0), 696 .channel = 0,
697 IIO_CHAN(IIO_POWER, 0, 1, 0, "active_raw", 1, 0, 697 .extend_name = "apparent_raw",
698 IIO_CHAN_INFO_SCALE_SHARED_BIT, 698 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
699 AD7758_WT(AD7758_PHASE_B, AD7758_ACT_PWR), 699 IIO_CHAN_INFO_SCALE_SHARED_BIT,
700 8, IIO_ST('s', 24, 32, 0), 0), 700 .address = AD7758_WT(AD7758_PHASE_A, AD7758_APP_PWR),
701 IIO_CHAN(IIO_POWER, 0, 1, 0, "reactive_raw", 1, 0, 701 .scan_index = 2,
702 IIO_CHAN_INFO_SCALE_SHARED_BIT, 702 .scan_type = {
703 AD7758_WT(AD7758_PHASE_B, AD7758_REACT_PWR), 703 .sign = 's',
704 9, IIO_ST('s', 24, 32, 0), 0), 704 .realbits = 24,
705 IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, "raw", 2, 0, 705 .storagebits = 32,
706 IIO_CHAN_INFO_SCALE_SHARED_BIT, 706 },
707 AD7758_WT(AD7758_PHASE_C, AD7758_VOLTAGE), 707 }, {
708 10, IIO_ST('s', 24, 32, 0), 0), 708 .type = IIO_POWER,
709 IIO_CHAN(IIO_CURRENT, 0, 1, 0, "raw", 2, 0, 709 .indexed = 1,
710 IIO_CHAN_INFO_SCALE_SHARED_BIT, 710 .channel = 0,
711 AD7758_WT(AD7758_PHASE_C, AD7758_CURRENT), 711 .extend_name = "active_raw",
712 11, IIO_ST('s', 24, 32, 0), 0), 712 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
713 IIO_CHAN(IIO_POWER, 0, 1, 0, "apparent_raw", 2, 0, 713 IIO_CHAN_INFO_SCALE_SHARED_BIT,
714 IIO_CHAN_INFO_SCALE_SHARED_BIT, 714 .address = AD7758_WT(AD7758_PHASE_A, AD7758_ACT_PWR),
715 AD7758_WT(AD7758_PHASE_C, AD7758_APP_PWR), 715 .scan_index = 3,
716 12, IIO_ST('s', 24, 32, 0), 0), 716 .scan_type = {
717 IIO_CHAN(IIO_POWER, 0, 1, 0, "active_raw", 2, 0, 717 .sign = 's',
718 IIO_CHAN_INFO_SCALE_SHARED_BIT, 718 .realbits = 24,
719 AD7758_WT(AD7758_PHASE_C, AD7758_ACT_PWR), 719 .storagebits = 32,
720 13, IIO_ST('s', 24, 32, 0), 0), 720 },
721 IIO_CHAN(IIO_POWER, 0, 1, 0, "reactive_raw", 2, 0, 721 }, {
722 IIO_CHAN_INFO_SCALE_SHARED_BIT, 722 .type = IIO_POWER,
723 AD7758_WT(AD7758_PHASE_C, AD7758_REACT_PWR), 723 .indexed = 1,
724 14, IIO_ST('s', 24, 32, 0), 0), 724 .channel = 0,
725 .extend_name = "reactive_raw",
726 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
727 IIO_CHAN_INFO_SCALE_SHARED_BIT,
728 .address = AD7758_WT(AD7758_PHASE_A, AD7758_REACT_PWR),
729 .scan_index = 4,
730 .scan_type = {
731 .sign = 's',
732 .realbits = 24,
733 .storagebits = 32,
734 },
735 }, {
736 .type = IIO_VOLTAGE,
737 .indexed = 1,
738 .channel = 1,
739 .extend_name = "raw",
740 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
741 IIO_CHAN_INFO_SCALE_SHARED_BIT,
742 .address = AD7758_WT(AD7758_PHASE_B, AD7758_VOLTAGE),
743 .scan_index = 5,
744 .scan_type = {
745 .sign = 's',
746 .realbits = 24,
747 .storagebits = 32,
748 },
749 }, {
750 .type = IIO_CURRENT,
751 .indexed = 1,
752 .channel = 1,
753 .extend_name = "raw",
754 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
755 IIO_CHAN_INFO_SCALE_SHARED_BIT,
756 .address = AD7758_WT(AD7758_PHASE_B, AD7758_CURRENT),
757 .scan_index = 6,
758 .scan_type = {
759 .sign = 's',
760 .realbits = 24,
761 .storagebits = 32,
762 },
763 }, {
764 .type = IIO_POWER,
765 .indexed = 1,
766 .channel = 1,
767 .extend_name = "apparent_raw",
768 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
769 IIO_CHAN_INFO_SCALE_SHARED_BIT,
770 .address = AD7758_WT(AD7758_PHASE_B, AD7758_APP_PWR),
771 .scan_index = 7,
772 .scan_type = {
773 .sign = 's',
774 .realbits = 24,
775 .storagebits = 32,
776 },
777 }, {
778 .type = IIO_POWER,
779 .indexed = 1,
780 .channel = 1,
781 .extend_name = "active_raw",
782 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
783 IIO_CHAN_INFO_SCALE_SHARED_BIT,
784 .address = AD7758_WT(AD7758_PHASE_B, AD7758_ACT_PWR),
785 .scan_index = 8,
786 .scan_type = {
787 .sign = 's',
788 .realbits = 24,
789 .storagebits = 32,
790 },
791 }, {
792 .type = IIO_POWER,
793 .indexed = 1,
794 .channel = 1,
795 .extend_name = "reactive_raw",
796 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
797 IIO_CHAN_INFO_SCALE_SHARED_BIT,
798 .address = AD7758_WT(AD7758_PHASE_B, AD7758_REACT_PWR),
799 .scan_index = 9,
800 .scan_type = {
801 .sign = 's',
802 .realbits = 24,
803 .storagebits = 32,
804 },
805 }, {
806 .type = IIO_VOLTAGE,
807 .indexed = 1,
808 .channel = 2,
809 .extend_name = "raw",
810 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
811 IIO_CHAN_INFO_SCALE_SHARED_BIT,
812 .address = AD7758_WT(AD7758_PHASE_C, AD7758_VOLTAGE),
813 .scan_index = 10,
814 .scan_type = {
815 .sign = 's',
816 .realbits = 24,
817 .storagebits = 32,
818 },
819 }, {
820 .type = IIO_CURRENT,
821 .indexed = 1,
822 .channel = 2,
823 .extend_name = "raw",
824 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
825 IIO_CHAN_INFO_SCALE_SHARED_BIT,
826 .address = AD7758_WT(AD7758_PHASE_C, AD7758_CURRENT),
827 .scan_index = 11,
828 .scan_type = {
829 .sign = 's',
830 .realbits = 24,
831 .storagebits = 32,
832 },
833 }, {
834 .type = IIO_POWER,
835 .indexed = 1,
836 .channel = 2,
837 .extend_name = "apparent_raw",
838 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
839 IIO_CHAN_INFO_SCALE_SHARED_BIT,
840 .address = AD7758_WT(AD7758_PHASE_C, AD7758_APP_PWR),
841 .scan_index = 12,
842 .scan_type = {
843 .sign = 's',
844 .realbits = 24,
845 .storagebits = 32,
846 },
847 }, {
848 .type = IIO_POWER,
849 .indexed = 1,
850 .channel = 2,
851 .extend_name = "active_raw",
852 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
853 IIO_CHAN_INFO_SCALE_SHARED_BIT,
854 .address = AD7758_WT(AD7758_PHASE_C, AD7758_ACT_PWR),
855 .scan_index = 13,
856 .scan_type = {
857 .sign = 's',
858 .realbits = 24,
859 .storagebits = 32,
860 },
861 }, {
862 .type = IIO_POWER,
863 .indexed = 1,
864 .channel = 2,
865 .extend_name = "reactive_raw",
866 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
867 IIO_CHAN_INFO_SCALE_SHARED_BIT,
868 .address = AD7758_WT(AD7758_PHASE_C, AD7758_REACT_PWR),
869 .scan_index = 14,
870 .scan_type = {
871 .sign = 's',
872 .realbits = 24,
873 .storagebits = 32,
874 },
875 },
725 IIO_CHAN_SOFT_TIMESTAMP(15), 876 IIO_CHAN_SOFT_TIMESTAMP(15),
726}; 877};
727 878
@@ -734,7 +885,7 @@ static int __devinit ade7758_probe(struct spi_device *spi)
734{ 885{
735 int i, ret; 886 int i, ret;
736 struct ade7758_state *st; 887 struct ade7758_state *st;
737 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); 888 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
738 889
739 if (indio_dev == NULL) { 890 if (indio_dev == NULL) {
740 ret = -ENOMEM; 891 ret = -ENOMEM;
@@ -800,7 +951,7 @@ static int __devinit ade7758_probe(struct spi_device *spi)
800 return 0; 951 return 0;
801 952
802error_remove_trigger: 953error_remove_trigger:
803 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) 954 if (spi->irq)
804 ade7758_remove_trigger(indio_dev); 955 ade7758_remove_trigger(indio_dev);
805error_uninitialize_ring: 956error_uninitialize_ring:
806 ade7758_uninitialize_ring(indio_dev); 957 ade7758_uninitialize_ring(indio_dev);
@@ -811,7 +962,7 @@ error_free_tx:
811error_free_rx: 962error_free_rx:
812 kfree(st->rx); 963 kfree(st->rx);
813error_free_dev: 964error_free_dev:
814 iio_free_device(indio_dev); 965 iio_device_free(indio_dev);
815error_ret: 966error_ret:
816 return ret; 967 return ret;
817} 968}
@@ -833,7 +984,7 @@ static int ade7758_remove(struct spi_device *spi)
833 kfree(st->tx); 984 kfree(st->tx);
834 kfree(st->rx); 985 kfree(st->rx);
835 986
836 iio_free_device(indio_dev); 987 iio_device_free(indio_dev);
837 988
838err_ret: 989err_ret:
839 return ret; 990 return ret;
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index c45b23bb1229..92159f208d14 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -12,18 +12,17 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <asm/unaligned.h> 13#include <asm/unaligned.h>
14 14
15#include "../iio.h" 15#include <linux/iio/iio.h>
16#include "../ring_sw.h" 16#include "../ring_sw.h"
17#include "../trigger_consumer.h" 17#include <linux/iio/trigger_consumer.h>
18#include "ade7758.h" 18#include "ade7758.h"
19 19
20/** 20/**
21 * ade7758_spi_read_burst() - read data registers 21 * ade7758_spi_read_burst() - read data registers
22 * @dev: device associated with child of actual device (iio_dev or iio_trig) 22 * @indio_dev: the IIO device
23 **/ 23 **/
24static int ade7758_spi_read_burst(struct device *dev) 24static int ade7758_spi_read_burst(struct iio_dev *indio_dev)
25{ 25{
26 struct iio_dev *indio_dev = dev_get_drvdata(dev);
27 struct ade7758_state *st = iio_priv(indio_dev); 26 struct ade7758_state *st = iio_priv(indio_dev);
28 int ret; 27 int ret;
29 28
@@ -68,11 +67,11 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
68 u32 *dat32 = (u32 *)dat64; 67 u32 *dat32 = (u32 *)dat64;
69 68
70 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 69 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
71 if (ade7758_spi_read_burst(&indio_dev->dev) >= 0) 70 if (ade7758_spi_read_burst(indio_dev) >= 0)
72 *dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF; 71 *dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
73 72
74 /* Guaranteed to be aligned with 8 byte boundary */ 73 /* Guaranteed to be aligned with 8 byte boundary */
75 if (ring->scan_timestamp) 74 if (indio_dev->scan_timestamp)
76 dat64[1] = pf->timestamp; 75 dat64[1] = pf->timestamp;
77 76
78 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp); 77 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
@@ -92,29 +91,19 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
92static int ade7758_ring_preenable(struct iio_dev *indio_dev) 91static int ade7758_ring_preenable(struct iio_dev *indio_dev)
93{ 92{
94 struct ade7758_state *st = iio_priv(indio_dev); 93 struct ade7758_state *st = iio_priv(indio_dev);
95 struct iio_buffer *ring = indio_dev->buffer;
96 size_t d_size;
97 unsigned channel; 94 unsigned channel;
95 int ret;
98 96
99 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 97 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
100 return -EINVAL; 98 return -EINVAL;
101 99
100 ret = iio_sw_buffer_preenable(indio_dev);
101 if (ret < 0)
102 return ret;
103
102 channel = find_first_bit(indio_dev->active_scan_mask, 104 channel = find_first_bit(indio_dev->active_scan_mask,
103 indio_dev->masklength); 105 indio_dev->masklength);
104 106
105 d_size = st->ade7758_ring_channels[channel].scan_type.storagebits / 8;
106
107 if (ring->scan_timestamp) {
108 d_size += sizeof(s64);
109
110 if (d_size % sizeof(s64))
111 d_size += sizeof(s64) - (d_size % sizeof(s64));
112 }
113
114 if (indio_dev->buffer->access->set_bytes_per_datum)
115 indio_dev->buffer->access->
116 set_bytes_per_datum(indio_dev->buffer, d_size);
117
118 ade7758_write_waveform_type(&indio_dev->dev, 107 ade7758_write_waveform_type(&indio_dev->dev,
119 st->ade7758_ring_channels[channel].address); 108 st->ade7758_ring_channels[channel].address);
120 109
diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c
index b6569c706651..f9c6a340092b 100644
--- a/drivers/staging/iio/meter/ade7758_trigger.c
+++ b/drivers/staging/iio/meter/ade7758_trigger.c
@@ -11,8 +11,8 @@
11#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
12#include <linux/export.h> 12#include <linux/export.h>
13 13
14#include "../iio.h" 14#include <linux/iio/iio.h>
15#include "../trigger.h" 15#include <linux/iio/trigger.h>
16#include "ade7758.h" 16#include "ade7758.h"
17 17
18/** 18/**
@@ -63,7 +63,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
63 struct ade7758_state *st = iio_priv(indio_dev); 63 struct ade7758_state *st = iio_priv(indio_dev);
64 int ret; 64 int ret;
65 65
66 st->trig = iio_allocate_trigger("%s-dev%d", 66 st->trig = iio_trigger_alloc("%s-dev%d",
67 spi_get_device_id(st->us)->name, 67 spi_get_device_id(st->us)->name,
68 indio_dev->id); 68 indio_dev->id);
69 if (st->trig == NULL) { 69 if (st->trig == NULL) {
@@ -94,7 +94,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
94error_free_irq: 94error_free_irq:
95 free_irq(st->us->irq, st->trig); 95 free_irq(st->us->irq, st->trig);
96error_free_trig: 96error_free_trig:
97 iio_free_trigger(st->trig); 97 iio_trigger_free(st->trig);
98error_ret: 98error_ret:
99 return ret; 99 return ret;
100} 100}
@@ -105,5 +105,5 @@ void ade7758_remove_trigger(struct iio_dev *indio_dev)
105 105
106 iio_trigger_unregister(st->trig); 106 iio_trigger_unregister(st->trig);
107 free_irq(st->us->irq, st->trig); 107 free_irq(st->us->irq, st->trig);
108 iio_free_trigger(st->trig); 108 iio_trigger_free(st->trig);
109} 109}
diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
index 0beab478dcd9..b3f7e0fa9612 100644
--- a/drivers/staging/iio/meter/ade7759.c
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -18,8 +18,8 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "meter.h" 23#include "meter.h"
24#include "ade7759.h" 24#include "ade7759.h"
25 25
@@ -28,7 +28,7 @@ static int ade7759_spi_write_reg_8(struct device *dev,
28 u8 val) 28 u8 val)
29{ 29{
30 int ret; 30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev); 31 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
32 struct ade7759_state *st = iio_priv(indio_dev); 32 struct ade7759_state *st = iio_priv(indio_dev);
33 33
34 mutex_lock(&st->buf_lock); 34 mutex_lock(&st->buf_lock);
@@ -46,7 +46,7 @@ static int ade7759_spi_write_reg_16(struct device *dev,
46 u16 value) 46 u16 value)
47{ 47{
48 int ret; 48 int ret;
49 struct iio_dev *indio_dev = dev_get_drvdata(dev); 49 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
50 struct ade7759_state *st = iio_priv(indio_dev); 50 struct ade7759_state *st = iio_priv(indio_dev);
51 51
52 mutex_lock(&st->buf_lock); 52 mutex_lock(&st->buf_lock);
@@ -63,7 +63,7 @@ static int ade7759_spi_read_reg_8(struct device *dev,
63 u8 reg_address, 63 u8 reg_address,
64 u8 *val) 64 u8 *val)
65{ 65{
66 struct iio_dev *indio_dev = dev_get_drvdata(dev); 66 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
67 struct ade7759_state *st = iio_priv(indio_dev); 67 struct ade7759_state *st = iio_priv(indio_dev);
68 int ret; 68 int ret;
69 69
@@ -82,7 +82,7 @@ static int ade7759_spi_read_reg_16(struct device *dev,
82 u8 reg_address, 82 u8 reg_address,
83 u16 *val) 83 u16 *val)
84{ 84{
85 struct iio_dev *indio_dev = dev_get_drvdata(dev); 85 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
86 struct ade7759_state *st = iio_priv(indio_dev); 86 struct ade7759_state *st = iio_priv(indio_dev);
87 int ret; 87 int ret;
88 88
@@ -104,7 +104,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
104 u64 *val) 104 u64 *val)
105{ 105{
106 struct spi_message msg; 106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_get_drvdata(dev); 107 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7759_state *st = iio_priv(indio_dev); 108 struct ade7759_state *st = iio_priv(indio_dev);
109 int ret; 109 int ret;
110 struct spi_transfer xfers[] = { 110 struct spi_transfer xfers[] = {
@@ -376,7 +376,7 @@ static ssize_t ade7759_write_frequency(struct device *dev,
376 const char *buf, 376 const char *buf,
377 size_t len) 377 size_t len)
378{ 378{
379 struct iio_dev *indio_dev = dev_get_drvdata(dev); 379 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
380 struct ade7759_state *st = iio_priv(indio_dev); 380 struct ade7759_state *st = iio_priv(indio_dev);
381 unsigned long val; 381 unsigned long val;
382 int ret; 382 int ret;
@@ -463,7 +463,7 @@ static int __devinit ade7759_probe(struct spi_device *spi)
463 struct iio_dev *indio_dev; 463 struct iio_dev *indio_dev;
464 464
465 /* setup the industrialio driver allocated elements */ 465 /* setup the industrialio driver allocated elements */
466 indio_dev = iio_allocate_device(sizeof(*st)); 466 indio_dev = iio_device_alloc(sizeof(*st));
467 if (indio_dev == NULL) { 467 if (indio_dev == NULL) {
468 ret = -ENOMEM; 468 ret = -ENOMEM;
469 goto error_ret; 469 goto error_ret;
@@ -491,7 +491,7 @@ static int __devinit ade7759_probe(struct spi_device *spi)
491 return 0; 491 return 0;
492 492
493error_free_dev: 493error_free_dev:
494 iio_free_device(indio_dev); 494 iio_device_free(indio_dev);
495error_ret: 495error_ret:
496 return ret; 496 return ret;
497} 497}
@@ -507,7 +507,7 @@ static int ade7759_remove(struct spi_device *spi)
507 if (ret) 507 if (ret)
508 goto err_ret; 508 goto err_ret;
509 509
510 iio_free_device(indio_dev); 510 iio_device_free(indio_dev);
511 511
512err_ret: 512err_ret:
513 return ret; 513 return ret;
diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c
index 1e1faa0479d3..06090465fa5f 100644
--- a/drivers/staging/iio/meter/ade7854-i2c.c
+++ b/drivers/staging/iio/meter/ade7854-i2c.c
@@ -12,7 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/module.h> 13#include <linux/module.h>
14 14
15#include "../iio.h" 15#include <linux/iio/iio.h>
16#include "ade7854.h" 16#include "ade7854.h"
17 17
18static int ade7854_i2c_write_reg_8(struct device *dev, 18static int ade7854_i2c_write_reg_8(struct device *dev,
@@ -20,7 +20,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev,
20 u8 value) 20 u8 value)
21{ 21{
22 int ret; 22 int ret;
23 struct iio_dev *indio_dev = dev_get_drvdata(dev); 23 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
24 struct ade7854_state *st = iio_priv(indio_dev); 24 struct ade7854_state *st = iio_priv(indio_dev);
25 25
26 mutex_lock(&st->buf_lock); 26 mutex_lock(&st->buf_lock);
@@ -39,7 +39,7 @@ static int ade7854_i2c_write_reg_16(struct device *dev,
39 u16 value) 39 u16 value)
40{ 40{
41 int ret; 41 int ret;
42 struct iio_dev *indio_dev = dev_get_drvdata(dev); 42 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
43 struct ade7854_state *st = iio_priv(indio_dev); 43 struct ade7854_state *st = iio_priv(indio_dev);
44 44
45 mutex_lock(&st->buf_lock); 45 mutex_lock(&st->buf_lock);
@@ -59,7 +59,7 @@ static int ade7854_i2c_write_reg_24(struct device *dev,
59 u32 value) 59 u32 value)
60{ 60{
61 int ret; 61 int ret;
62 struct iio_dev *indio_dev = dev_get_drvdata(dev); 62 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
63 struct ade7854_state *st = iio_priv(indio_dev); 63 struct ade7854_state *st = iio_priv(indio_dev);
64 64
65 mutex_lock(&st->buf_lock); 65 mutex_lock(&st->buf_lock);
@@ -80,7 +80,7 @@ static int ade7854_i2c_write_reg_32(struct device *dev,
80 u32 value) 80 u32 value)
81{ 81{
82 int ret; 82 int ret;
83 struct iio_dev *indio_dev = dev_get_drvdata(dev); 83 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
84 struct ade7854_state *st = iio_priv(indio_dev); 84 struct ade7854_state *st = iio_priv(indio_dev);
85 85
86 mutex_lock(&st->buf_lock); 86 mutex_lock(&st->buf_lock);
@@ -101,7 +101,7 @@ static int ade7854_i2c_read_reg_8(struct device *dev,
101 u16 reg_address, 101 u16 reg_address,
102 u8 *val) 102 u8 *val)
103{ 103{
104 struct iio_dev *indio_dev = dev_get_drvdata(dev); 104 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
105 struct ade7854_state *st = iio_priv(indio_dev); 105 struct ade7854_state *st = iio_priv(indio_dev);
106 int ret; 106 int ret;
107 107
@@ -127,7 +127,7 @@ static int ade7854_i2c_read_reg_16(struct device *dev,
127 u16 reg_address, 127 u16 reg_address,
128 u16 *val) 128 u16 *val)
129{ 129{
130 struct iio_dev *indio_dev = dev_get_drvdata(dev); 130 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
131 struct ade7854_state *st = iio_priv(indio_dev); 131 struct ade7854_state *st = iio_priv(indio_dev);
132 int ret; 132 int ret;
133 133
@@ -153,7 +153,7 @@ static int ade7854_i2c_read_reg_24(struct device *dev,
153 u16 reg_address, 153 u16 reg_address,
154 u32 *val) 154 u32 *val)
155{ 155{
156 struct iio_dev *indio_dev = dev_get_drvdata(dev); 156 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
157 struct ade7854_state *st = iio_priv(indio_dev); 157 struct ade7854_state *st = iio_priv(indio_dev);
158 int ret; 158 int ret;
159 159
@@ -179,7 +179,7 @@ static int ade7854_i2c_read_reg_32(struct device *dev,
179 u16 reg_address, 179 u16 reg_address,
180 u32 *val) 180 u32 *val)
181{ 181{
182 struct iio_dev *indio_dev = dev_get_drvdata(dev); 182 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
183 struct ade7854_state *st = iio_priv(indio_dev); 183 struct ade7854_state *st = iio_priv(indio_dev);
184 int ret; 184 int ret;
185 185
@@ -208,7 +208,7 @@ static int __devinit ade7854_i2c_probe(struct i2c_client *client,
208 struct ade7854_state *st; 208 struct ade7854_state *st;
209 struct iio_dev *indio_dev; 209 struct iio_dev *indio_dev;
210 210
211 indio_dev = iio_allocate_device(sizeof(*st)); 211 indio_dev = iio_device_alloc(sizeof(*st));
212 if (indio_dev == NULL) 212 if (indio_dev == NULL)
213 return -ENOMEM; 213 return -ENOMEM;
214 st = iio_priv(indio_dev); 214 st = iio_priv(indio_dev);
@@ -226,7 +226,7 @@ static int __devinit ade7854_i2c_probe(struct i2c_client *client,
226 226
227 ret = ade7854_probe(indio_dev, &client->dev); 227 ret = ade7854_probe(indio_dev, &client->dev);
228 if (ret) 228 if (ret)
229 iio_free_device(indio_dev); 229 iio_device_free(indio_dev);
230 230
231 return ret; 231 return ret;
232} 232}
diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c
index 81121862c1bd..9fb2f8bfca81 100644
--- a/drivers/staging/iio/meter/ade7854-spi.c
+++ b/drivers/staging/iio/meter/ade7854-spi.c
@@ -12,7 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/module.h> 13#include <linux/module.h>
14 14
15#include "../iio.h" 15#include <linux/iio/iio.h>
16#include "ade7854.h" 16#include "ade7854.h"
17 17
18static int ade7854_spi_write_reg_8(struct device *dev, 18static int ade7854_spi_write_reg_8(struct device *dev,
@@ -21,7 +21,7 @@ static int ade7854_spi_write_reg_8(struct device *dev,
21{ 21{
22 int ret; 22 int ret;
23 struct spi_message msg; 23 struct spi_message msg;
24 struct iio_dev *indio_dev = dev_get_drvdata(dev); 24 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
25 struct ade7854_state *st = iio_priv(indio_dev); 25 struct ade7854_state *st = iio_priv(indio_dev);
26 struct spi_transfer xfer = { 26 struct spi_transfer xfer = {
27 .tx_buf = st->tx, 27 .tx_buf = st->tx,
@@ -49,7 +49,7 @@ static int ade7854_spi_write_reg_16(struct device *dev,
49{ 49{
50 int ret; 50 int ret;
51 struct spi_message msg; 51 struct spi_message msg;
52 struct iio_dev *indio_dev = dev_get_drvdata(dev); 52 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
53 struct ade7854_state *st = iio_priv(indio_dev); 53 struct ade7854_state *st = iio_priv(indio_dev);
54 struct spi_transfer xfer = { 54 struct spi_transfer xfer = {
55 .tx_buf = st->tx, 55 .tx_buf = st->tx,
@@ -78,7 +78,7 @@ static int ade7854_spi_write_reg_24(struct device *dev,
78{ 78{
79 int ret; 79 int ret;
80 struct spi_message msg; 80 struct spi_message msg;
81 struct iio_dev *indio_dev = dev_get_drvdata(dev); 81 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
82 struct ade7854_state *st = iio_priv(indio_dev); 82 struct ade7854_state *st = iio_priv(indio_dev);
83 struct spi_transfer xfer = { 83 struct spi_transfer xfer = {
84 .tx_buf = st->tx, 84 .tx_buf = st->tx,
@@ -108,7 +108,7 @@ static int ade7854_spi_write_reg_32(struct device *dev,
108{ 108{
109 int ret; 109 int ret;
110 struct spi_message msg; 110 struct spi_message msg;
111 struct iio_dev *indio_dev = dev_get_drvdata(dev); 111 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
112 struct ade7854_state *st = iio_priv(indio_dev); 112 struct ade7854_state *st = iio_priv(indio_dev);
113 struct spi_transfer xfer = { 113 struct spi_transfer xfer = {
114 .tx_buf = st->tx, 114 .tx_buf = st->tx,
@@ -138,7 +138,7 @@ static int ade7854_spi_read_reg_8(struct device *dev,
138 u8 *val) 138 u8 *val)
139{ 139{
140 struct spi_message msg; 140 struct spi_message msg;
141 struct iio_dev *indio_dev = dev_get_drvdata(dev); 141 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
142 struct ade7854_state *st = iio_priv(indio_dev); 142 struct ade7854_state *st = iio_priv(indio_dev);
143 int ret; 143 int ret;
144 struct spi_transfer xfers[] = { 144 struct spi_transfer xfers[] = {
@@ -180,7 +180,7 @@ static int ade7854_spi_read_reg_16(struct device *dev,
180 u16 *val) 180 u16 *val)
181{ 181{
182 struct spi_message msg; 182 struct spi_message msg;
183 struct iio_dev *indio_dev = dev_get_drvdata(dev); 183 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
184 struct ade7854_state *st = iio_priv(indio_dev); 184 struct ade7854_state *st = iio_priv(indio_dev);
185 int ret; 185 int ret;
186 struct spi_transfer xfers[] = { 186 struct spi_transfer xfers[] = {
@@ -221,7 +221,7 @@ static int ade7854_spi_read_reg_24(struct device *dev,
221 u32 *val) 221 u32 *val)
222{ 222{
223 struct spi_message msg; 223 struct spi_message msg;
224 struct iio_dev *indio_dev = dev_get_drvdata(dev); 224 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
225 struct ade7854_state *st = iio_priv(indio_dev); 225 struct ade7854_state *st = iio_priv(indio_dev);
226 int ret; 226 int ret;
227 struct spi_transfer xfers[] = { 227 struct spi_transfer xfers[] = {
@@ -263,7 +263,7 @@ static int ade7854_spi_read_reg_32(struct device *dev,
263 u32 *val) 263 u32 *val)
264{ 264{
265 struct spi_message msg; 265 struct spi_message msg;
266 struct iio_dev *indio_dev = dev_get_drvdata(dev); 266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267 struct ade7854_state *st = iio_priv(indio_dev); 267 struct ade7854_state *st = iio_priv(indio_dev);
268 int ret; 268 int ret;
269 struct spi_transfer xfers[] = { 269 struct spi_transfer xfers[] = {
@@ -306,7 +306,7 @@ static int __devinit ade7854_spi_probe(struct spi_device *spi)
306 struct ade7854_state *st; 306 struct ade7854_state *st;
307 struct iio_dev *indio_dev; 307 struct iio_dev *indio_dev;
308 308
309 indio_dev = iio_allocate_device(sizeof(*st)); 309 indio_dev = iio_device_alloc(sizeof(*st));
310 if (indio_dev == NULL) 310 if (indio_dev == NULL)
311 return -ENOMEM; 311 return -ENOMEM;
312 st = iio_priv(indio_dev); 312 st = iio_priv(indio_dev);
@@ -325,7 +325,7 @@ static int __devinit ade7854_spi_probe(struct spi_device *spi)
325 325
326 ret = ade7854_probe(indio_dev, &spi->dev); 326 ret = ade7854_probe(indio_dev, &spi->dev);
327 if (ret) 327 if (ret)
328 iio_free_device(indio_dev); 328 iio_device_free(indio_dev);
329 329
330 return 0; 330 return 0;
331} 331}
diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c
index 49c01c5c1b59..c642da84842a 100644
--- a/drivers/staging/iio/meter/ade7854.c
+++ b/drivers/staging/iio/meter/ade7854.c
@@ -17,8 +17,8 @@
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/module.h> 18#include <linux/module.h>
19 19
20#include "../iio.h" 20#include <linux/iio/iio.h>
21#include "../sysfs.h" 21#include <linux/iio/sysfs.h>
22#include "meter.h" 22#include "meter.h"
23#include "ade7854.h" 23#include "ade7854.h"
24 24
@@ -28,7 +28,7 @@ static ssize_t ade7854_read_8bit(struct device *dev,
28{ 28{
29 int ret; 29 int ret;
30 u8 val = 0; 30 u8 val = 0;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev); 31 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
32 struct ade7854_state *st = iio_priv(indio_dev); 32 struct ade7854_state *st = iio_priv(indio_dev);
33 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 33 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
34 34
@@ -45,7 +45,7 @@ static ssize_t ade7854_read_16bit(struct device *dev,
45{ 45{
46 int ret; 46 int ret;
47 u16 val = 0; 47 u16 val = 0;
48 struct iio_dev *indio_dev = dev_get_drvdata(dev); 48 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
49 struct ade7854_state *st = iio_priv(indio_dev); 49 struct ade7854_state *st = iio_priv(indio_dev);
50 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 50 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
51 51
@@ -62,7 +62,7 @@ static ssize_t ade7854_read_24bit(struct device *dev,
62{ 62{
63 int ret; 63 int ret;
64 u32 val; 64 u32 val;
65 struct iio_dev *indio_dev = dev_get_drvdata(dev); 65 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
66 struct ade7854_state *st = iio_priv(indio_dev); 66 struct ade7854_state *st = iio_priv(indio_dev);
67 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 67 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
68 68
@@ -80,7 +80,7 @@ static ssize_t ade7854_read_32bit(struct device *dev,
80 int ret; 80 int ret;
81 u32 val = 0; 81 u32 val = 0;
82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
83 struct iio_dev *indio_dev = dev_get_drvdata(dev); 83 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
84 struct ade7854_state *st = iio_priv(indio_dev); 84 struct ade7854_state *st = iio_priv(indio_dev);
85 85
86 ret = st->read_reg_32(dev, this_attr->address, &val); 86 ret = st->read_reg_32(dev, this_attr->address, &val);
@@ -96,7 +96,7 @@ static ssize_t ade7854_write_8bit(struct device *dev,
96 size_t len) 96 size_t len)
97{ 97{
98 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 98 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
99 struct iio_dev *indio_dev = dev_get_drvdata(dev); 99 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
100 struct ade7854_state *st = iio_priv(indio_dev); 100 struct ade7854_state *st = iio_priv(indio_dev);
101 101
102 int ret; 102 int ret;
@@ -117,7 +117,7 @@ static ssize_t ade7854_write_16bit(struct device *dev,
117 size_t len) 117 size_t len)
118{ 118{
119 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 119 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
120 struct iio_dev *indio_dev = dev_get_drvdata(dev); 120 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
121 struct ade7854_state *st = iio_priv(indio_dev); 121 struct ade7854_state *st = iio_priv(indio_dev);
122 122
123 int ret; 123 int ret;
@@ -138,7 +138,7 @@ static ssize_t ade7854_write_24bit(struct device *dev,
138 size_t len) 138 size_t len)
139{ 139{
140 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 140 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
141 struct iio_dev *indio_dev = dev_get_drvdata(dev); 141 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
142 struct ade7854_state *st = iio_priv(indio_dev); 142 struct ade7854_state *st = iio_priv(indio_dev);
143 143
144 int ret; 144 int ret;
@@ -159,7 +159,7 @@ static ssize_t ade7854_write_32bit(struct device *dev,
159 size_t len) 159 size_t len)
160{ 160{
161 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 161 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
162 struct iio_dev *indio_dev = dev_get_drvdata(dev); 162 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
163 struct ade7854_state *st = iio_priv(indio_dev); 163 struct ade7854_state *st = iio_priv(indio_dev);
164 164
165 int ret; 165 int ret;
@@ -176,7 +176,7 @@ error_ret:
176 176
177static int ade7854_reset(struct device *dev) 177static int ade7854_reset(struct device *dev)
178{ 178{
179 struct iio_dev *indio_dev = dev_get_drvdata(dev); 179 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
180 struct ade7854_state *st = iio_priv(indio_dev); 180 struct ade7854_state *st = iio_priv(indio_dev);
181 u16 val; 181 u16 val;
182 182
@@ -425,7 +425,7 @@ static IIO_DEV_ATTR_CVAHR(ade7854_read_32bit,
425 425
426static int ade7854_set_irq(struct device *dev, bool enable) 426static int ade7854_set_irq(struct device *dev, bool enable)
427{ 427{
428 struct iio_dev *indio_dev = dev_get_drvdata(dev); 428 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
429 struct ade7854_state *st = iio_priv(indio_dev); 429 struct ade7854_state *st = iio_priv(indio_dev);
430 430
431 int ret; 431 int ret;
@@ -581,7 +581,7 @@ int ade7854_probe(struct iio_dev *indio_dev, struct device *dev)
581error_unreg_dev: 581error_unreg_dev:
582 iio_device_unregister(indio_dev); 582 iio_device_unregister(indio_dev);
583error_free_dev: 583error_free_dev:
584 iio_free_device(indio_dev); 584 iio_device_free(indio_dev);
585 585
586 return ret; 586 return ret;
587} 587}
@@ -590,7 +590,7 @@ EXPORT_SYMBOL(ade7854_probe);
590int ade7854_remove(struct iio_dev *indio_dev) 590int ade7854_remove(struct iio_dev *indio_dev)
591{ 591{
592 iio_device_unregister(indio_dev); 592 iio_device_unregister(indio_dev);
593 iio_free_device(indio_dev); 593 iio_device_free(indio_dev);
594 594
595 return 0; 595 return 0;
596} 596}
diff --git a/drivers/staging/iio/meter/meter.h b/drivers/staging/iio/meter/meter.h
index 6a3db1423631..23e1b5f480a9 100644
--- a/drivers/staging/iio/meter/meter.h
+++ b/drivers/staging/iio/meter/meter.h
@@ -1,4 +1,4 @@
1#include "../sysfs.h" 1#include <linux/iio/sysfs.h>
2 2
3/* metering ic types of attribute */ 3/* metering ic types of attribute */
4 4
diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c
index d8ce854c1897..8b71eb0e16f5 100644
--- a/drivers/staging/iio/resolver/ad2s1200.c
+++ b/drivers/staging/iio/resolver/ad2s1200.c
@@ -19,8 +19,8 @@
19#include <linux/gpio.h> 19#include <linux/gpio.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22#include "../iio.h" 22#include <linux/iio/iio.h>
23#include "../sysfs.h" 23#include <linux/iio/sysfs.h>
24 24
25#define DRV_NAME "ad2s1200" 25#define DRV_NAME "ad2s1200"
26 26
@@ -85,10 +85,12 @@ static const struct iio_chan_spec ad2s1200_channels[] = {
85 .type = IIO_ANGL, 85 .type = IIO_ANGL,
86 .indexed = 1, 86 .indexed = 1,
87 .channel = 0, 87 .channel = 0,
88 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
88 }, { 89 }, {
89 .type = IIO_ANGL_VEL, 90 .type = IIO_ANGL_VEL,
90 .indexed = 1, 91 .indexed = 1,
91 .channel = 0, 92 .channel = 0,
93 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
92 } 94 }
93}; 95};
94 96
@@ -110,7 +112,7 @@ static int __devinit ad2s1200_probe(struct spi_device *spi)
110 DRV_NAME, pins[pn]); 112 DRV_NAME, pins[pn]);
111 goto error_ret; 113 goto error_ret;
112 } 114 }
113 indio_dev = iio_allocate_device(sizeof(*st)); 115 indio_dev = iio_device_alloc(sizeof(*st));
114 if (indio_dev == NULL) { 116 if (indio_dev == NULL) {
115 ret = -ENOMEM; 117 ret = -ENOMEM;
116 goto error_ret; 118 goto error_ret;
@@ -140,7 +142,7 @@ static int __devinit ad2s1200_probe(struct spi_device *spi)
140 return 0; 142 return 0;
141 143
142error_free_dev: 144error_free_dev:
143 iio_free_device(indio_dev); 145 iio_device_free(indio_dev);
144error_ret: 146error_ret:
145 for (--pn; pn >= 0; pn--) 147 for (--pn; pn >= 0; pn--)
146 gpio_free(pins[pn]); 148 gpio_free(pins[pn]);
@@ -150,7 +152,7 @@ error_ret:
150static int __devexit ad2s1200_remove(struct spi_device *spi) 152static int __devexit ad2s1200_remove(struct spi_device *spi)
151{ 153{
152 iio_device_unregister(spi_get_drvdata(spi)); 154 iio_device_unregister(spi_get_drvdata(spi));
153 iio_free_device(spi_get_drvdata(spi)); 155 iio_device_free(spi_get_drvdata(spi));
154 156
155 return 0; 157 return 0;
156} 158}
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index c439fcf72be7..f313859476c1 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -18,8 +18,8 @@
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include "../iio.h" 21#include <linux/iio/iio.h>
22#include "../sysfs.h" 22#include <linux/iio/sysfs.h>
23#include "ad2s1210.h" 23#include "ad2s1210.h"
24 24
25#define DRV_NAME "ad2s1210" 25#define DRV_NAME "ad2s1210"
@@ -200,7 +200,7 @@ static ssize_t ad2s1210_store_softreset(struct device *dev,
200 const char *buf, 200 const char *buf,
201 size_t len) 201 size_t len)
202{ 202{
203 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 203 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
204 int ret; 204 int ret;
205 205
206 mutex_lock(&st->lock); 206 mutex_lock(&st->lock);
@@ -214,7 +214,7 @@ static ssize_t ad2s1210_show_fclkin(struct device *dev,
214 struct device_attribute *attr, 214 struct device_attribute *attr,
215 char *buf) 215 char *buf)
216{ 216{
217 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 217 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
218 return sprintf(buf, "%d\n", st->fclkin); 218 return sprintf(buf, "%d\n", st->fclkin);
219} 219}
220 220
@@ -223,7 +223,7 @@ static ssize_t ad2s1210_store_fclkin(struct device *dev,
223 const char *buf, 223 const char *buf,
224 size_t len) 224 size_t len)
225{ 225{
226 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 226 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
227 unsigned long fclkin; 227 unsigned long fclkin;
228 int ret; 228 int ret;
229 229
@@ -252,7 +252,7 @@ static ssize_t ad2s1210_show_fexcit(struct device *dev,
252 struct device_attribute *attr, 252 struct device_attribute *attr,
253 char *buf) 253 char *buf)
254{ 254{
255 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 255 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
256 return sprintf(buf, "%d\n", st->fexcit); 256 return sprintf(buf, "%d\n", st->fexcit);
257} 257}
258 258
@@ -260,7 +260,7 @@ static ssize_t ad2s1210_store_fexcit(struct device *dev,
260 struct device_attribute *attr, 260 struct device_attribute *attr,
261 const char *buf, size_t len) 261 const char *buf, size_t len)
262{ 262{
263 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 263 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
264 unsigned long fexcit; 264 unsigned long fexcit;
265 int ret; 265 int ret;
266 266
@@ -287,7 +287,7 @@ static ssize_t ad2s1210_show_control(struct device *dev,
287 struct device_attribute *attr, 287 struct device_attribute *attr,
288 char *buf) 288 char *buf)
289{ 289{
290 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 290 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
291 int ret; 291 int ret;
292 mutex_lock(&st->lock); 292 mutex_lock(&st->lock);
293 ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL); 293 ret = ad2s1210_config_read(st, AD2S1210_REG_CONTROL);
@@ -299,7 +299,7 @@ static ssize_t ad2s1210_store_control(struct device *dev,
299 struct device_attribute *attr, 299 struct device_attribute *attr,
300 const char *buf, size_t len) 300 const char *buf, size_t len)
301{ 301{
302 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 302 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
303 unsigned long udata; 303 unsigned long udata;
304 unsigned char data; 304 unsigned char data;
305 int ret; 305 int ret;
@@ -345,7 +345,7 @@ error_ret:
345static ssize_t ad2s1210_show_resolution(struct device *dev, 345static ssize_t ad2s1210_show_resolution(struct device *dev,
346 struct device_attribute *attr, char *buf) 346 struct device_attribute *attr, char *buf)
347{ 347{
348 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 348 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
349 return sprintf(buf, "%d\n", st->resolution); 349 return sprintf(buf, "%d\n", st->resolution);
350} 350}
351 351
@@ -353,7 +353,7 @@ static ssize_t ad2s1210_store_resolution(struct device *dev,
353 struct device_attribute *attr, 353 struct device_attribute *attr,
354 const char *buf, size_t len) 354 const char *buf, size_t len)
355{ 355{
356 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 356 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
357 unsigned char data; 357 unsigned char data;
358 unsigned long udata; 358 unsigned long udata;
359 int ret; 359 int ret;
@@ -403,7 +403,7 @@ error_ret:
403static ssize_t ad2s1210_show_fault(struct device *dev, 403static ssize_t ad2s1210_show_fault(struct device *dev,
404 struct device_attribute *attr, char *buf) 404 struct device_attribute *attr, char *buf)
405{ 405{
406 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 406 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
407 int ret; 407 int ret;
408 408
409 mutex_lock(&st->lock); 409 mutex_lock(&st->lock);
@@ -418,7 +418,7 @@ static ssize_t ad2s1210_clear_fault(struct device *dev,
418 const char *buf, 418 const char *buf,
419 size_t len) 419 size_t len)
420{ 420{
421 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 421 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
422 int ret; 422 int ret;
423 423
424 mutex_lock(&st->lock); 424 mutex_lock(&st->lock);
@@ -441,7 +441,7 @@ static ssize_t ad2s1210_show_reg(struct device *dev,
441 struct device_attribute *attr, 441 struct device_attribute *attr,
442 char *buf) 442 char *buf)
443{ 443{
444 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 444 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
445 struct iio_dev_attr *iattr = to_iio_dev_attr(attr); 445 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
446 int ret; 446 int ret;
447 447
@@ -455,7 +455,7 @@ static ssize_t ad2s1210_show_reg(struct device *dev,
455static ssize_t ad2s1210_store_reg(struct device *dev, 455static ssize_t ad2s1210_store_reg(struct device *dev,
456 struct device_attribute *attr, const char *buf, size_t len) 456 struct device_attribute *attr, const char *buf, size_t len)
457{ 457{
458 struct ad2s1210_state *st = iio_priv(dev_get_drvdata(dev)); 458 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
459 unsigned long data; 459 unsigned long data;
460 int ret; 460 int ret;
461 struct iio_dev_attr *iattr = to_iio_dev_attr(attr); 461 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
@@ -580,10 +580,12 @@ static struct iio_chan_spec ad2s1210_channels[] = {
580 .type = IIO_ANGL, 580 .type = IIO_ANGL,
581 .indexed = 1, 581 .indexed = 1,
582 .channel = 0, 582 .channel = 0,
583 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
583 }, { 584 }, {
584 .type = IIO_ANGL_VEL, 585 .type = IIO_ANGL_VEL,
585 .indexed = 1, 586 .indexed = 1,
586 .channel = 0, 587 .channel = 0,
588 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
587 } 589 }
588}; 590};
589 591
@@ -688,7 +690,7 @@ static int __devinit ad2s1210_probe(struct spi_device *spi)
688 if (spi->dev.platform_data == NULL) 690 if (spi->dev.platform_data == NULL)
689 return -EINVAL; 691 return -EINVAL;
690 692
691 indio_dev = iio_allocate_device(sizeof(*st)); 693 indio_dev = iio_device_alloc(sizeof(*st));
692 if (indio_dev == NULL) { 694 if (indio_dev == NULL) {
693 ret = -ENOMEM; 695 ret = -ENOMEM;
694 goto error_ret; 696 goto error_ret;
@@ -729,7 +731,7 @@ static int __devinit ad2s1210_probe(struct spi_device *spi)
729error_free_gpios: 731error_free_gpios:
730 ad2s1210_free_gpios(st); 732 ad2s1210_free_gpios(st);
731error_free_dev: 733error_free_dev:
732 iio_free_device(indio_dev); 734 iio_device_free(indio_dev);
733error_ret: 735error_ret:
734 return ret; 736 return ret;
735} 737}
@@ -740,7 +742,7 @@ static int __devexit ad2s1210_remove(struct spi_device *spi)
740 742
741 iio_device_unregister(indio_dev); 743 iio_device_unregister(indio_dev);
742 ad2s1210_free_gpios(iio_priv(indio_dev)); 744 ad2s1210_free_gpios(iio_priv(indio_dev));
743 iio_free_device(indio_dev); 745 iio_device_free(indio_dev);
744 746
745 return 0; 747 return 0;
746} 748}
diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index 2a86f582ddf1..a8057228dca1 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -16,8 +16,8 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../sysfs.h" 20#include <linux/iio/sysfs.h>
21 21
22struct ad2s90_state { 22struct ad2s90_state {
23 struct mutex lock; 23 struct mutex lock;
@@ -55,6 +55,7 @@ static const struct iio_chan_spec ad2s90_chan = {
55 .type = IIO_ANGL, 55 .type = IIO_ANGL,
56 .indexed = 1, 56 .indexed = 1,
57 .channel = 0, 57 .channel = 0,
58 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
58}; 59};
59 60
60static int __devinit ad2s90_probe(struct spi_device *spi) 61static int __devinit ad2s90_probe(struct spi_device *spi)
@@ -63,7 +64,7 @@ static int __devinit ad2s90_probe(struct spi_device *spi)
63 struct ad2s90_state *st; 64 struct ad2s90_state *st;
64 int ret = 0; 65 int ret = 0;
65 66
66 indio_dev = iio_allocate_device(sizeof(*st)); 67 indio_dev = iio_device_alloc(sizeof(*st));
67 if (indio_dev == NULL) { 68 if (indio_dev == NULL) {
68 ret = -ENOMEM; 69 ret = -ENOMEM;
69 goto error_ret; 70 goto error_ret;
@@ -92,7 +93,7 @@ static int __devinit ad2s90_probe(struct spi_device *spi)
92 return 0; 93 return 0;
93 94
94error_free_dev: 95error_free_dev:
95 iio_free_device(indio_dev); 96 iio_device_free(indio_dev);
96error_ret: 97error_ret:
97 return ret; 98 return ret;
98} 99}
@@ -100,7 +101,7 @@ error_ret:
100static int __devexit ad2s90_remove(struct spi_device *spi) 101static int __devexit ad2s90_remove(struct spi_device *spi)
101{ 102{
102 iio_device_unregister(spi_get_drvdata(spi)); 103 iio_device_unregister(spi_get_drvdata(spi));
103 iio_free_device(spi_get_drvdata(spi)); 104 iio_device_free(spi_get_drvdata(spi));
104 105
105 return 0; 106 return 0;
106} 107}
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index b9945ec44faa..9358c6cb1c72 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -15,7 +15,7 @@
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/poll.h> 16#include <linux/poll.h>
17#include "ring_sw.h" 17#include "ring_sw.h"
18#include "trigger.h" 18#include <linux/iio/trigger.h>
19 19
20/** 20/**
21 * struct iio_sw_ring_buffer - software ring buffer 21 * struct iio_sw_ring_buffer - software ring buffer
diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h
index 7556e2122367..a5857aa7aefa 100644
--- a/drivers/staging/iio/ring_sw.h
+++ b/drivers/staging/iio/ring_sw.h
@@ -23,7 +23,7 @@
23 23
24#ifndef _IIO_RING_SW_H_ 24#ifndef _IIO_RING_SW_H_
25#define _IIO_RING_SW_H_ 25#define _IIO_RING_SW_H_
26#include "buffer.h" 26#include <linux/iio/buffer.h>
27 27
28struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev); 28struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
29void iio_sw_rb_free(struct iio_buffer *ring); 29void iio_sw_rb_free(struct iio_buffer *ring);
diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
index 665653d79f02..f85734d212bb 100644
--- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
+++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
@@ -15,8 +15,8 @@
15 15
16#include <asm/gptimers.h> 16#include <asm/gptimers.h>
17 17
18#include "../iio.h" 18#include <linux/iio/iio.h>
19#include "../trigger.h" 19#include <linux/iio/trigger.h>
20 20
21struct bfin_timer { 21struct bfin_timer {
22 unsigned short id, bit; 22 unsigned short id, bit;
@@ -172,7 +172,7 @@ static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
172 st->timer_num = ret; 172 st->timer_num = ret;
173 st->t = &iio_bfin_timer_code[st->timer_num]; 173 st->t = &iio_bfin_timer_code[st->timer_num];
174 174
175 st->trig = iio_allocate_trigger("bfintmr%d", st->timer_num); 175 st->trig = iio_trigger_alloc("bfintmr%d", st->timer_num);
176 if (!st->trig) { 176 if (!st->trig) {
177 ret = -ENOMEM; 177 ret = -ENOMEM;
178 goto out1; 178 goto out1;
@@ -203,7 +203,7 @@ static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
203out4: 203out4:
204 iio_trigger_unregister(st->trig); 204 iio_trigger_unregister(st->trig);
205out2: 205out2:
206 iio_put_trigger(st->trig); 206 iio_trigger_put(st->trig);
207out1: 207out1:
208 kfree(st); 208 kfree(st);
209out: 209out:
@@ -217,7 +217,7 @@ static int __devexit iio_bfin_tmr_trigger_remove(struct platform_device *pdev)
217 disable_gptimers(st->t->bit); 217 disable_gptimers(st->t->bit);
218 free_irq(st->irq, st); 218 free_irq(st->irq, st);
219 iio_trigger_unregister(st->trig); 219 iio_trigger_unregister(st->trig);
220 iio_put_trigger(st->trig); 220 iio_trigger_put(st->trig);
221 kfree(st); 221 kfree(st);
222 222
223 return 0; 223 return 0;
diff --git a/drivers/staging/iio/trigger/iio-trig-gpio.c b/drivers/staging/iio/trigger/iio-trig-gpio.c
index a3465947235e..90b26846fc6b 100644
--- a/drivers/staging/iio/trigger/iio-trig-gpio.c
+++ b/drivers/staging/iio/trigger/iio-trig-gpio.c
@@ -22,8 +22,8 @@
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24 24
25#include "../iio.h" 25#include <linux/iio/iio.h>
26#include "../trigger.h" 26#include <linux/iio/trigger.h>
27 27
28static LIST_HEAD(iio_gpio_trigger_list); 28static LIST_HEAD(iio_gpio_trigger_list);
29static DEFINE_MUTEX(iio_gpio_trigger_list_lock); 29static DEFINE_MUTEX(iio_gpio_trigger_list_lock);
@@ -72,7 +72,7 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev)
72 72
73 for (irq = irq_res->start; irq <= irq_res->end; irq++) { 73 for (irq = irq_res->start; irq <= irq_res->end; irq++) {
74 74
75 trig = iio_allocate_trigger("irqtrig%d", irq); 75 trig = iio_trigger_alloc("irqtrig%d", irq);
76 if (!trig) { 76 if (!trig) {
77 ret = -ENOMEM; 77 ret = -ENOMEM;
78 goto error_free_completed_registrations; 78 goto error_free_completed_registrations;
@@ -114,7 +114,7 @@ error_release_irq:
114error_free_trig_info: 114error_free_trig_info:
115 kfree(trig_info); 115 kfree(trig_info);
116error_put_trigger: 116error_put_trigger:
117 iio_put_trigger(trig); 117 iio_trigger_put(trig);
118error_free_completed_registrations: 118error_free_completed_registrations:
119 /* The rest should have been added to the iio_gpio_trigger_list */ 119 /* The rest should have been added to the iio_gpio_trigger_list */
120 list_for_each_entry_safe(trig, 120 list_for_each_entry_safe(trig,
@@ -144,7 +144,7 @@ static int iio_gpio_trigger_remove(struct platform_device *pdev)
144 iio_trigger_unregister(trig); 144 iio_trigger_unregister(trig);
145 free_irq(trig_info->irq, trig); 145 free_irq(trig_info->irq, trig);
146 kfree(trig_info); 146 kfree(trig_info);
147 iio_put_trigger(trig); 147 iio_trigger_put(trig);
148 } 148 }
149 mutex_unlock(&iio_gpio_trigger_list_lock); 149 mutex_unlock(&iio_gpio_trigger_list_lock);
150 150
diff --git a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
index a80cf67bf84d..9f2d055524a3 100644
--- a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
+++ b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/rtc.h> 18#include <linux/rtc.h>
19#include "../iio.h" 19#include <linux/iio/iio.h>
20#include "../trigger.h" 20#include <linux/iio/trigger.h>
21 21
22static LIST_HEAD(iio_prtc_trigger_list); 22static LIST_HEAD(iio_prtc_trigger_list);
23static DEFINE_MUTEX(iio_prtc_trigger_list_lock); 23static DEFINE_MUTEX(iio_prtc_trigger_list_lock);
@@ -112,7 +112,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
112 for (i = 0;; i++) { 112 for (i = 0;; i++) {
113 if (pdata[i] == NULL) 113 if (pdata[i] == NULL)
114 break; 114 break;
115 trig = iio_allocate_trigger("periodic%s", pdata[i]); 115 trig = iio_trigger_alloc("periodic%s", pdata[i]);
116 if (!trig) { 116 if (!trig) {
117 ret = -ENOMEM; 117 ret = -ENOMEM;
118 goto error_free_completed_registrations; 118 goto error_free_completed_registrations;
@@ -152,7 +152,7 @@ error_free_trig_info:
152 kfree(trig_info); 152 kfree(trig_info);
153error_put_trigger_and_remove_from_list: 153error_put_trigger_and_remove_from_list:
154 list_del(&trig->alloc_list); 154 list_del(&trig->alloc_list);
155 iio_put_trigger(trig); 155 iio_trigger_put(trig);
156error_free_completed_registrations: 156error_free_completed_registrations:
157 list_for_each_entry_safe(trig, 157 list_for_each_entry_safe(trig,
158 trig2, 158 trig2,
diff --git a/drivers/staging/iio/trigger/iio-trig-sysfs.c b/drivers/staging/iio/trigger/iio-trig-sysfs.c
index 174dc65709d5..552763bb3d4c 100644
--- a/drivers/staging/iio/trigger/iio-trig-sysfs.c
+++ b/drivers/staging/iio/trigger/iio-trig-sysfs.c
@@ -11,8 +11,8 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/list.h> 12#include <linux/list.h>
13 13
14#include "../iio.h" 14#include <linux/iio/iio.h>
15#include "../trigger.h" 15#include <linux/iio/trigger.h>
16 16
17struct iio_sysfs_trig { 17struct iio_sysfs_trig {
18 struct iio_trigger *trig; 18 struct iio_trigger *trig;
@@ -139,7 +139,7 @@ static int iio_sysfs_trigger_probe(int id)
139 goto out1; 139 goto out1;
140 } 140 }
141 t->id = id; 141 t->id = id;
142 t->trig = iio_allocate_trigger("sysfstrig%d", id); 142 t->trig = iio_trigger_alloc("sysfstrig%d", id);
143 if (!t->trig) { 143 if (!t->trig) {
144 ret = -ENOMEM; 144 ret = -ENOMEM;
145 goto free_t; 145 goto free_t;
@@ -158,7 +158,7 @@ static int iio_sysfs_trigger_probe(int id)
158 return 0; 158 return 0;
159 159
160out2: 160out2:
161 iio_put_trigger(t->trig); 161 iio_trigger_put(t->trig);
162free_t: 162free_t:
163 kfree(t); 163 kfree(t);
164out1: 164out1:
@@ -182,7 +182,7 @@ static int iio_sysfs_trigger_remove(int id)
182 } 182 }
183 183
184 iio_trigger_unregister(t->trig); 184 iio_trigger_unregister(t->trig);
185 iio_free_trigger(t->trig); 185 iio_trigger_free(t->trig);
186 186
187 list_del(&t->l); 187 list_del(&t->l);
188 kfree(t); 188 kfree(t);
diff --git a/drivers/staging/ipack/Kconfig b/drivers/staging/ipack/Kconfig
new file mode 100644
index 000000000000..af321789dddb
--- /dev/null
+++ b/drivers/staging/ipack/Kconfig
@@ -0,0 +1,20 @@
1#
2# IPACK configuration.
3#
4
5menuconfig IPACK_BUS
6 tristate "IndustryPack bus support"
7 ---help---
8 If you say Y here you get support for the IndustryPack Framework
9 for drivers for many types of boards that support this industrial
10 bus. The IndustryPack Framework is a virtual bus allowing to
11 communicate between carrier and mezzanine cards connected through
12 this bus.
13
14if IPACK_BUS
15
16source "drivers/staging/ipack/bridges/Kconfig"
17
18source "drivers/staging/ipack/devices/Kconfig"
19
20endif # IPACK
diff --git a/drivers/staging/ipack/Makefile b/drivers/staging/ipack/Makefile
new file mode 100644
index 000000000000..85ff223616fd
--- /dev/null
+++ b/drivers/staging/ipack/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for the IPACK bridge device drivers.
3#
4obj-$(CONFIG_IPACK_BUS) += ipack.o
5obj-y += devices/
6obj-y += bridges/
diff --git a/drivers/staging/ipack/TODO b/drivers/staging/ipack/TODO
new file mode 100644
index 000000000000..3a45a53afd88
--- /dev/null
+++ b/drivers/staging/ipack/TODO
@@ -0,0 +1,46 @@
1 TODO
2 ====
3Introduction
4============
5
6These drivers add support for IndustryPack devices: carrier and mezzanine
7boards.
8
9The ipack driver is just an abstraction of the bus providing the common
10operations between the two kind of boards.
11
12TODO
13====
14
15TPCI-200
16--------
17
18* It receives the name of the mezzanine plugged in each slot by SYSFS.
19 No autodetection supported yet, because the mezzanine driver could not be
20 loaded at the time that the tpci200 driver loads.
21
22* It has a linked list with the tpci200 devices it is managing. Get rid of it
23 and use driver_for_each_device() instead.
24
25IP-OCTAL
26--------
27
28* It has a linked list which saves the devices it is currently
29 managing. It should use the driver_for_each_device() function. It is not there
30 due to the impossibility of using container_of macro to recover the
31 corresponding "struct ipoctal" because the attribute "struct ipack_device" is
32 a pointer. This code should be refactored.
33
34Ipack
35-----
36
37* The structures and API exported can be improved a lot. For example, the
38 way to unregistering mezzanine devices, doing the mezzanine driver a call to
39 remove_device() to notify the carrier driver, or the opposite with the call to
40 the ipack_driver_ops' remove() function could be improved.
41
42
43Contact
44=======
45
46Contact: Samuel Iglesias Gonsalvez <siglesias@igalia.com> \ No newline at end of file
diff --git a/drivers/staging/ipack/bridges/Kconfig b/drivers/staging/ipack/bridges/Kconfig
new file mode 100644
index 000000000000..97c837ea7a03
--- /dev/null
+++ b/drivers/staging/ipack/bridges/Kconfig
@@ -0,0 +1,8 @@
1config BOARD_TPCI200
2 tristate "TEWS TPCI-200 support for IndustryPack bus"
3 depends on IPACK_BUS
4 depends on PCI
5 help
6 This driver supports the TEWS TPCI200 device for the IndustryPack bus.
7 default n
8
diff --git a/drivers/staging/ipack/bridges/Makefile b/drivers/staging/ipack/bridges/Makefile
new file mode 100644
index 000000000000..d8b76459300f
--- /dev/null
+++ b/drivers/staging/ipack/bridges/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_BOARD_TPCI200) += tpci200.o
diff --git a/drivers/staging/ipack/bridges/tpci200.c b/drivers/staging/ipack/bridges/tpci200.c
new file mode 100644
index 000000000000..ad2870750235
--- /dev/null
+++ b/drivers/staging/ipack/bridges/tpci200.c
@@ -0,0 +1,1141 @@
1/**
2 * tpci200.c
3 *
4 * driver for the TEWS TPCI-200 device
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include "tpci200.h"
18
19static struct ipack_bus_ops tpci200_bus_ops;
20
21/* TPCI200 controls registers */
22static int control_reg[] = {
23 TPCI200_CONTROL_A_REG,
24 TPCI200_CONTROL_B_REG,
25 TPCI200_CONTROL_C_REG,
26 TPCI200_CONTROL_D_REG
27};
28
29/* Linked list to save the registered devices */
30static LIST_HEAD(tpci200_list);
31
32static int tpci200_slot_unregister(struct ipack_device *dev);
33
34static struct tpci200_board *check_slot(struct ipack_device *dev)
35{
36 struct tpci200_board *tpci200;
37 int found = 0;
38
39 if (dev == NULL) {
40 pr_info("Slot doesn't exist.\n");
41 return NULL;
42 }
43
44 list_for_each_entry(tpci200, &tpci200_list, list) {
45 if (tpci200->number == dev->bus_nr) {
46 found = 1;
47 break;
48 }
49 }
50
51 if (!found) {
52 pr_err("Carrier not found\n");
53 return NULL;
54 }
55
56 if (dev->slot >= TPCI200_NB_SLOT) {
57 pr_info("Slot [%d:%d] doesn't exist! Last tpci200 slot is %d.\n",
58 dev->bus_nr, dev->slot, TPCI200_NB_SLOT-1);
59 return NULL;
60 }
61
62 BUG_ON(tpci200->slots == NULL);
63 if (tpci200->slots[dev->slot].dev == NULL) {
64 pr_info("Slot [%d:%d] is not registered !\n", dev->bus_nr,
65 dev->slot);
66 return NULL;
67 }
68
69 return tpci200;
70}
71
72static inline unsigned char __tpci200_read8(void __iomem *address,
73 unsigned long offset)
74{
75 return ioread8(address + (offset^1));
76}
77
78static inline unsigned short __tpci200_read16(void __iomem *address,
79 unsigned long offset)
80{
81 return ioread16(address + offset);
82}
83
84static inline unsigned int __tpci200_read32(void __iomem *address,
85 unsigned long offset)
86{
87 return swahw32(ioread32(address + offset));
88}
89
90static inline void __tpci200_write8(unsigned char value,
91 void __iomem *address, unsigned long offset)
92{
93 iowrite8(value, address+(offset^1));
94}
95
96static inline void __tpci200_write16(unsigned short value,
97 void __iomem *address,
98 unsigned long offset)
99{
100 iowrite16(value, address+offset);
101}
102
103static inline void __tpci200_write32(unsigned int value,
104 void __iomem *address,
105 unsigned long offset)
106{
107 iowrite32(swahw32(value), address+offset);
108}
109
110static struct ipack_addr_space *get_slot_address_space(struct ipack_device *dev,
111 int space)
112{
113 struct ipack_addr_space *addr;
114
115 switch (space) {
116 case IPACK_IO_SPACE:
117 addr = &dev->io_space;
118 break;
119 case IPACK_ID_SPACE:
120 addr = &dev->id_space;
121 break;
122 case IPACK_MEM_SPACE:
123 addr = &dev->mem_space;
124 break;
125 default:
126 pr_err("Slot [%d:%d] space number %d doesn't exist !\n",
127 dev->bus_nr, dev->slot, space);
128 return NULL;
129 break;
130 }
131
132 if ((addr->size == 0) || (addr->address == NULL)) {
133 pr_err("Error, slot space not mapped !\n");
134 return NULL;
135 }
136
137 return addr;
138}
139
140static int tpci200_read8(struct ipack_device *dev, int space,
141 unsigned long offset, unsigned char *value)
142{
143 struct ipack_addr_space *addr;
144 struct tpci200_board *tpci200;
145
146 tpci200 = check_slot(dev);
147 if (tpci200 == NULL)
148 return -EINVAL;
149
150 addr = get_slot_address_space(dev, space);
151 if (addr == NULL)
152 return -EINVAL;
153
154 if (offset >= addr->size) {
155 pr_err("Error, slot space offset error !\n");
156 return -EFAULT;
157 }
158
159 *value = __tpci200_read8(addr->address, offset);
160
161 return 0;
162}
163
164static int tpci200_read16(struct ipack_device *dev, int space,
165 unsigned long offset, unsigned short *value)
166{
167 struct ipack_addr_space *addr;
168 struct tpci200_board *tpci200;
169
170 tpci200 = check_slot(dev);
171 if (tpci200 == NULL)
172 return -EINVAL;
173
174 addr = get_slot_address_space(dev, space);
175 if (addr == NULL)
176 return -EINVAL;
177
178 if ((offset+2) >= addr->size) {
179 pr_err("Error, slot space offset error !\n");
180 return -EFAULT;
181 }
182 *value = __tpci200_read16(addr->address, offset);
183
184 return 0;
185}
186
187static int tpci200_read32(struct ipack_device *dev, int space,
188 unsigned long offset, unsigned int *value)
189{
190 struct ipack_addr_space *addr;
191 struct tpci200_board *tpci200;
192
193 tpci200 = check_slot(dev);
194 if (tpci200 == NULL)
195 return -EINVAL;
196
197 addr = get_slot_address_space(dev, space);
198 if (addr == NULL)
199 return -EINVAL;
200
201 if ((offset+4) >= addr->size) {
202 pr_err("Error, slot space offset error !\n");
203 return -EFAULT;
204 }
205
206 *value = __tpci200_read32(addr->address, offset);
207
208 return 0;
209}
210
211static int tpci200_write8(struct ipack_device *dev, int space,
212 unsigned long offset, unsigned char value)
213{
214 struct ipack_addr_space *addr;
215 struct tpci200_board *tpci200;
216
217 tpci200 = check_slot(dev);
218 if (tpci200 == NULL)
219 return -EINVAL;
220
221 addr = get_slot_address_space(dev, space);
222 if (addr == NULL)
223 return -EINVAL;
224
225 if (offset >= addr->size) {
226 pr_err("Error, slot space offset error !\n");
227 return -EFAULT;
228 }
229
230 __tpci200_write8(value, addr->address, offset);
231
232 return 0;
233}
234
235static int tpci200_write16(struct ipack_device *dev, int space,
236 unsigned long offset, unsigned short value)
237{
238 struct ipack_addr_space *addr;
239 struct tpci200_board *tpci200;
240
241 tpci200 = check_slot(dev);
242 if (tpci200 == NULL)
243 return -EINVAL;
244
245 addr = get_slot_address_space(dev, space);
246 if (addr == NULL)
247 return -EINVAL;
248
249 if ((offset+2) >= addr->size) {
250 pr_err("Error, slot space offset error !\n");
251 return -EFAULT;
252 }
253
254 __tpci200_write16(value, addr->address, offset);
255
256 return 0;
257}
258
259static int tpci200_write32(struct ipack_device *dev, int space,
260 unsigned long offset, unsigned int value)
261{
262 struct ipack_addr_space *addr;
263 struct tpci200_board *tpci200;
264
265 tpci200 = check_slot(dev);
266 if (tpci200 == NULL)
267 return -EINVAL;
268
269 addr = get_slot_address_space(dev, space);
270 if (addr == NULL)
271 return -EINVAL;
272
273 if ((offset+4) >= addr->size) {
274 pr_err("Error, slot space offset error !\n");
275 return -EFAULT;
276 }
277
278 __tpci200_write32(value, addr->address, offset);
279
280 return 0;
281}
282
283static void tpci200_unregister(struct tpci200_board *tpci200)
284{
285 int i;
286
287 free_irq(tpci200->info->pdev->irq, (void *) tpci200);
288
289 pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs);
290 pci_iounmap(tpci200->info->pdev, tpci200->info->ioidint_space);
291 pci_iounmap(tpci200->info->pdev, tpci200->info->mem8_space);
292
293 pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
294 pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
295 pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR);
296
297 pci_disable_device(tpci200->info->pdev);
298 pci_dev_put(tpci200->info->pdev);
299
300 kfree(tpci200->info);
301
302 for (i = 0; i < TPCI200_NB_SLOT; i++) {
303 tpci200->slots[i].io_phys.address = NULL;
304 tpci200->slots[i].io_phys.size = 0;
305 tpci200->slots[i].id_phys.address = NULL;
306 tpci200->slots[i].id_phys.size = 0;
307 tpci200->slots[i].mem_phys.address = NULL;
308 tpci200->slots[i].mem_phys.size = 0;
309 }
310}
311
312static irqreturn_t tpci200_interrupt(int irq, void *dev_id)
313{
314 struct tpci200_board *tpci200 = (struct tpci200_board *) dev_id;
315 int i;
316 unsigned long flags;
317 unsigned short status_reg, reg_value;
318 unsigned short unhandled_ints = 0;
319 irqreturn_t ret = IRQ_NONE;
320
321 spin_lock_irqsave(&tpci200->info->access_lock, flags);
322
323 /* Read status register */
324 status_reg = readw(tpci200->info->interface_regs +
325 TPCI200_STATUS_REG);
326
327 if (status_reg & TPCI200_SLOT_INT_MASK) {
328 unhandled_ints = status_reg & TPCI200_SLOT_INT_MASK;
329 /* callback to the IRQ handler for the corresponding slot */
330 for (i = 0; i < TPCI200_NB_SLOT; i++) {
331 if ((tpci200->slots[i].irq != NULL) &&
332 (status_reg & ((TPCI200_A_INT0 | TPCI200_A_INT1) << (2*i)))) {
333
334 ret = tpci200->slots[i].irq->handler(tpci200->slots[i].irq->arg);
335
336 /* Dummy reads */
337 readw(tpci200->slots[i].dev->io_space.address +
338 0xC0);
339 readw(tpci200->slots[i].dev->io_space.address +
340 0xC2);
341
342 unhandled_ints &= ~(((TPCI200_A_INT0 | TPCI200_A_INT1) << (2*i)));
343 }
344 }
345 }
346 /* Interrupt not handled are disabled */
347 if (unhandled_ints) {
348 for (i = 0; i < TPCI200_NB_SLOT; i++) {
349 if (unhandled_ints & ((TPCI200_INT0_EN | TPCI200_INT1_EN) << (2*i))) {
350 pr_info("No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n",
351 tpci200->number, i);
352 reg_value = readw(
353 tpci200->info->interface_regs +
354 control_reg[i]);
355 reg_value &=
356 ~(TPCI200_INT0_EN | TPCI200_INT1_EN);
357 writew(reg_value,
358 (tpci200->info->interface_regs +
359 control_reg[i]));
360 }
361 }
362 }
363
364 spin_unlock_irqrestore(&tpci200->info->access_lock, flags);
365 return ret;
366}
367
368#ifdef CONFIG_SYSFS
369
370static struct ipack_device *tpci200_slot_register(unsigned int tpci200_number,
371 unsigned int slot_position)
372{
373 int found = 0;
374 struct ipack_device *dev;
375 struct tpci200_board *tpci200;
376
377 list_for_each_entry(tpci200, &tpci200_list, list) {
378 if (tpci200->number == tpci200_number) {
379 found = 1;
380 break;
381 }
382 }
383
384 if (!found) {
385 pr_err("carrier board not found for the device\n");
386 return NULL;
387 }
388
389 if (slot_position >= TPCI200_NB_SLOT) {
390 pr_info("Slot [%d:%d] doesn't exist!\n", tpci200_number,
391 slot_position);
392 return NULL;
393 }
394
395 if (mutex_lock_interruptible(&tpci200->mutex))
396 return NULL;
397
398 if (tpci200->slots[slot_position].dev != NULL) {
399 pr_err("Slot [%d:%d] already installed !\n", tpci200_number,
400 slot_position);
401 goto err_unlock;
402 }
403
404 /*
405 * Give the same IRQ number as the slot number.
406 * The TPCI200 has assigned his own two IRQ by PCI bus driver
407 */
408 dev = ipack_device_register(tpci200->info->ipack_bus,
409 slot_position, slot_position);
410 if (dev == NULL) {
411 pr_info("Slot [%d:%d] Unable to register an ipack device\n",
412 tpci200_number, slot_position);
413 goto err_unlock;
414 }
415
416 tpci200->slots[slot_position].dev = dev;
417 mutex_unlock(&tpci200->mutex);
418 return dev;
419
420err_unlock:
421 mutex_unlock(&tpci200->mutex);
422 return NULL;
423}
424
425static ssize_t tpci200_store_board(struct device *pdev, const char *buf,
426 size_t count, int slot)
427{
428 struct tpci200_board *card = dev_get_drvdata(pdev);
429 struct ipack_device *dev = card->slots[slot].dev;
430
431 if (dev != NULL)
432 return -EBUSY;
433
434 dev = tpci200_slot_register(card->number, slot);
435 if (dev == NULL)
436 return -ENODEV;
437
438 return count;
439}
440
441static ssize_t tpci200_show_board(struct device *pdev, char *buf, int slot)
442{
443 struct tpci200_board *card = dev_get_drvdata(pdev);
444 struct ipack_device *dev = card->slots[slot].dev;
445
446 if (dev != NULL)
447 return snprintf(buf, PAGE_SIZE, "%s\n", dev_name(&dev->dev));
448 else
449 return snprintf(buf, PAGE_SIZE, "none\n");
450}
451
452static ssize_t tpci200_show_description(struct device *pdev,
453 struct device_attribute *attr,
454 char *buf)
455{
456 return snprintf(buf, PAGE_SIZE,
457 "TEWS tpci200 carrier PCI for Industry-pack mezzanines.\n");
458}
459
460static ssize_t tpci200_show_board_slot0(struct device *pdev,
461 struct device_attribute *attr,
462 char *buf)
463{
464 return tpci200_show_board(pdev, buf, 0);
465}
466
467static ssize_t tpci200_store_board_slot0(struct device *pdev,
468 struct device_attribute *attr,
469 const char *buf, size_t count)
470{
471 return tpci200_store_board(pdev, buf, count, 0);
472}
473
474static ssize_t tpci200_show_board_slot1(struct device *pdev,
475 struct device_attribute *attr,
476 char *buf)
477{
478 return tpci200_show_board(pdev, buf, 1);
479}
480
481static ssize_t tpci200_store_board_slot1(struct device *pdev,
482 struct device_attribute *attr,
483 const char *buf, size_t count)
484{
485 return tpci200_store_board(pdev, buf, count, 1);
486}
487
488static ssize_t tpci200_show_board_slot2(struct device *pdev,
489 struct device_attribute *attr,
490 char *buf)
491{
492 return tpci200_show_board(pdev, buf, 2);
493}
494
495static ssize_t tpci200_store_board_slot2(struct device *pdev,
496 struct device_attribute *attr,
497 const char *buf, size_t count)
498{
499 return tpci200_store_board(pdev, buf, count, 2);
500}
501
502
503static ssize_t tpci200_show_board_slot3(struct device *pdev,
504 struct device_attribute *attr,
505 char *buf)
506{
507 return tpci200_show_board(pdev, buf, 3);
508}
509
510static ssize_t tpci200_store_board_slot3(struct device *pdev,
511 struct device_attribute *attr,
512 const char *buf, size_t count)
513{
514 return tpci200_store_board(pdev, buf, count, 3);
515}
516
517/* Declaration of the device attributes for the TPCI200 */
518static DEVICE_ATTR(description, S_IRUGO,
519 tpci200_show_description, NULL);
520static DEVICE_ATTR(board_slot0, S_IRUGO | S_IWUSR,
521 tpci200_show_board_slot0, tpci200_store_board_slot0);
522static DEVICE_ATTR(board_slot1, S_IRUGO | S_IWUSR,
523 tpci200_show_board_slot1, tpci200_store_board_slot1);
524static DEVICE_ATTR(board_slot2, S_IRUGO | S_IWUSR,
525 tpci200_show_board_slot2, tpci200_store_board_slot2);
526static DEVICE_ATTR(board_slot3, S_IRUGO | S_IWUSR,
527 tpci200_show_board_slot3, tpci200_store_board_slot3);
528
529static struct attribute *tpci200_attrs[] = {
530 &dev_attr_description.attr,
531 &dev_attr_board_slot0.attr,
532 &dev_attr_board_slot1.attr,
533 &dev_attr_board_slot2.attr,
534 &dev_attr_board_slot3.attr,
535 NULL,
536};
537
538static struct attribute_group tpci200_attr_group = {
539 .attrs = tpci200_attrs,
540};
541
542static int tpci200_create_sysfs_files(struct tpci200_board *card)
543{
544 return sysfs_create_group(&card->info->pdev->dev.kobj,
545 &tpci200_attr_group);
546}
547
548static void tpci200_remove_sysfs_files(struct tpci200_board *card)
549{
550 sysfs_remove_group(&card->info->pdev->dev.kobj, &tpci200_attr_group);
551}
552
553#else
554
555static int tpci200_create_sysfs_files(struct tpci200_board *card)
556{
557 return 0;
558}
559
560static void tpci200_remove_sysfs_files(struct tpci200_board *card)
561{
562}
563
564#endif /* CONFIG_SYSFS */
565
566static int tpci200_register(struct tpci200_board *tpci200)
567{
568 int i;
569 int res;
570 unsigned long ioidint_base;
571 unsigned long mem_base;
572 unsigned short slot_ctrl;
573
574 if (pci_enable_device(tpci200->info->pdev) < 0)
575 return -ENODEV;
576
577 if (tpci200_create_sysfs_files(tpci200) < 0) {
578 pr_err("failed creating sysfs files\n");
579 res = -EFAULT;
580 goto out_disable_pci;
581 }
582
583 /* Request IP interface register (Bar 2) */
584 res = pci_request_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR,
585 "Carrier IP interface registers");
586 if (res) {
587 pr_err("(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !",
588 tpci200->info->pdev->bus->number,
589 tpci200->info->pdev->devfn);
590 goto out_remove_sysfs;
591 }
592
593 /* Request IO ID INT space (Bar 3) */
594 res = pci_request_region(tpci200->info->pdev,
595 TPCI200_IO_ID_INT_SPACES_BAR,
596 "Carrier IO ID INT space");
597 if (res) {
598 pr_err("(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !",
599 tpci200->info->pdev->bus->number,
600 tpci200->info->pdev->devfn);
601 goto out_release_ip_space;
602 }
603
604 /* Request MEM space (Bar 4) */
605 res = pci_request_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR,
606 "Carrier MEM space");
607 if (res) {
608 pr_err("(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!",
609 tpci200->info->pdev->bus->number,
610 tpci200->info->pdev->devfn);
611 goto out_release_ioid_int_space;
612 }
613
614 /* Map internal tpci200 driver user space */
615 tpci200->info->interface_regs =
616 ioremap(pci_resource_start(tpci200->info->pdev,
617 TPCI200_IP_INTERFACE_BAR),
618 TPCI200_IFACE_SIZE);
619 tpci200->info->ioidint_space =
620 ioremap(pci_resource_start(tpci200->info->pdev,
621 TPCI200_IO_ID_INT_SPACES_BAR),
622 TPCI200_IOIDINT_SIZE);
623 tpci200->info->mem8_space =
624 ioremap(pci_resource_start(tpci200->info->pdev,
625 TPCI200_MEM8_SPACE_BAR),
626 TPCI200_MEM8_SIZE);
627
628 spin_lock_init(&tpci200->info->access_lock);
629 ioidint_base = pci_resource_start(tpci200->info->pdev,
630 TPCI200_IO_ID_INT_SPACES_BAR);
631 mem_base = pci_resource_start(tpci200->info->pdev,
632 TPCI200_MEM8_SPACE_BAR);
633
634 /* Set the default parameters of the slot
635 * INT0 disabled, level sensitive
636 * INT1 disabled, level sensitive
637 * error interrupt disabled
638 * timeout interrupt disabled
639 * recover time disabled
640 * clock rate 8 MHz
641 */
642 slot_ctrl = 0;
643
644 /* Set all slot physical address space */
645 for (i = 0; i < TPCI200_NB_SLOT; i++) {
646 tpci200->slots[i].io_phys.address =
647 (void __iomem *)ioidint_base +
648 TPCI200_IO_SPACE_OFF + TPCI200_IO_SPACE_GAP*i;
649 tpci200->slots[i].io_phys.size = TPCI200_IO_SPACE_SIZE;
650
651 tpci200->slots[i].id_phys.address =
652 (void __iomem *)ioidint_base +
653 TPCI200_ID_SPACE_OFF + TPCI200_ID_SPACE_GAP*i;
654 tpci200->slots[i].id_phys.size = TPCI200_ID_SPACE_SIZE;
655
656 tpci200->slots[i].mem_phys.address =
657 (void __iomem *)mem_base + TPCI200_MEM8_GAP*i;
658 tpci200->slots[i].mem_phys.size = TPCI200_MEM8_SIZE;
659
660 writew(slot_ctrl, (tpci200->info->interface_regs +
661 control_reg[i]));
662 }
663
664 res = request_irq(tpci200->info->pdev->irq,
665 tpci200_interrupt, IRQF_SHARED,
666 KBUILD_MODNAME, (void *) tpci200);
667 if (res) {
668 pr_err("(bn 0x%X, sn 0x%X) unable to register IRQ !",
669 tpci200->info->pdev->bus->number,
670 tpci200->info->pdev->devfn);
671 tpci200_unregister(tpci200);
672 goto out_err;
673 }
674
675 return 0;
676
677out_release_ioid_int_space:
678 pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
679out_release_ip_space:
680 pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
681out_remove_sysfs:
682 tpci200_remove_sysfs_files(tpci200);
683out_disable_pci:
684 pci_disable_device(tpci200->info->pdev);
685out_err:
686 return res;
687}
688
689static int __tpci200_request_irq(struct tpci200_board *tpci200,
690 struct ipack_device *dev)
691{
692 unsigned short slot_ctrl;
693
694 /* Set the default parameters of the slot
695 * INT0 enabled, level sensitive
696 * INT1 enabled, level sensitive
697 * error interrupt disabled
698 * timeout interrupt disabled
699 * recover time disabled
700 * clock rate 8 MHz
701 */
702 slot_ctrl = TPCI200_INT0_EN | TPCI200_INT1_EN;
703 writew(slot_ctrl, (tpci200->info->interface_regs +
704 control_reg[dev->slot]));
705
706 return 0;
707}
708
709static void __tpci200_free_irq(struct tpci200_board *tpci200,
710 struct ipack_device *dev)
711{
712 unsigned short slot_ctrl;
713
714 /* Set the default parameters of the slot
715 * INT0 disabled, level sensitive
716 * INT1 disabled, level sensitive
717 * error interrupt disabled
718 * timeout interrupt disabled
719 * recover time disabled
720 * clock rate 8 MHz
721 */
722 slot_ctrl = 0;
723 writew(slot_ctrl, (tpci200->info->interface_regs +
724 control_reg[dev->slot]));
725}
726
727static int tpci200_free_irq(struct ipack_device *dev)
728{
729 int res;
730 struct slot_irq *slot_irq;
731 struct tpci200_board *tpci200;
732
733 tpci200 = check_slot(dev);
734 if (tpci200 == NULL) {
735 res = -EINVAL;
736 goto out;
737 }
738
739 if (mutex_lock_interruptible(&tpci200->mutex)) {
740 res = -ERESTARTSYS;
741 goto out;
742 }
743
744 if (tpci200->slots[dev->slot].irq == NULL) {
745 res = -EINVAL;
746 goto out_unlock;
747 }
748
749 __tpci200_free_irq(tpci200, dev);
750 slot_irq = tpci200->slots[dev->slot].irq;
751 tpci200->slots[dev->slot].irq = NULL;
752 kfree(slot_irq);
753
754out_unlock:
755 mutex_unlock(&tpci200->mutex);
756out:
757 return res;
758}
759
760static int tpci200_slot_unmap_space(struct ipack_device *dev, int space)
761{
762 int res;
763 struct ipack_addr_space *virt_addr_space;
764 struct tpci200_board *tpci200;
765
766 tpci200 = check_slot(dev);
767 if (tpci200 == NULL) {
768 res = -EINVAL;
769 goto out;
770 }
771
772 if (mutex_lock_interruptible(&tpci200->mutex)) {
773 res = -ERESTARTSYS;
774 goto out;
775 }
776
777 switch (space) {
778 case IPACK_IO_SPACE:
779 if (dev->io_space.address == NULL) {
780 pr_info("Slot [%d:%d] IO space not mapped !\n",
781 dev->bus_nr, dev->slot);
782 goto out_unlock;
783 }
784 virt_addr_space = &dev->io_space;
785 break;
786 case IPACK_ID_SPACE:
787 if (dev->id_space.address == NULL) {
788 pr_info("Slot [%d:%d] ID space not mapped !\n",
789 dev->bus_nr, dev->slot);
790 goto out_unlock;
791 }
792 virt_addr_space = &dev->id_space;
793 break;
794 case IPACK_MEM_SPACE:
795 if (dev->mem_space.address == NULL) {
796 pr_info("Slot [%d:%d] MEM space not mapped !\n",
797 dev->bus_nr, dev->slot);
798 goto out_unlock;
799 }
800 virt_addr_space = &dev->mem_space;
801 break;
802 default:
803 pr_err("Slot [%d:%d] space number %d doesn't exist !\n",
804 dev->bus_nr, dev->slot, space);
805 res = -EINVAL;
806 goto out_unlock;
807 break;
808 }
809
810 iounmap(virt_addr_space->address);
811
812 virt_addr_space->address = NULL;
813 virt_addr_space->size = 0;
814out_unlock:
815 mutex_unlock(&tpci200->mutex);
816out:
817 return res;
818}
819
820static int tpci200_slot_unregister(struct ipack_device *dev)
821{
822 struct tpci200_board *tpci200;
823
824 if (dev == NULL)
825 return -ENODEV;
826
827 tpci200 = check_slot(dev);
828 if (tpci200 == NULL)
829 return -EINVAL;
830
831 tpci200_free_irq(dev);
832
833 if (mutex_lock_interruptible(&tpci200->mutex))
834 return -ERESTARTSYS;
835
836 ipack_device_unregister(dev);
837 tpci200->slots[dev->slot].dev = NULL;
838 mutex_unlock(&tpci200->mutex);
839
840 return 0;
841}
842
843static int tpci200_slot_map_space(struct ipack_device *dev,
844 unsigned int memory_size, int space)
845{
846 int res;
847 unsigned int size_to_map;
848 void __iomem *phys_address;
849 struct ipack_addr_space *virt_addr_space;
850 struct tpci200_board *tpci200;
851
852 tpci200 = check_slot(dev);
853 if (tpci200 == NULL) {
854 res = -EINVAL;
855 goto out;
856 }
857
858 if (mutex_lock_interruptible(&tpci200->mutex)) {
859 res = -ERESTARTSYS;
860 goto out;
861 }
862
863 switch (space) {
864 case IPACK_IO_SPACE:
865 if (dev->io_space.address != NULL) {
866 pr_err("Slot [%d:%d] IO space already mapped !\n",
867 tpci200->number, dev->slot);
868 res = -EINVAL;
869 goto out_unlock;
870 }
871 virt_addr_space = &dev->io_space;
872
873 phys_address = tpci200->slots[dev->slot].io_phys.address;
874 size_to_map = tpci200->slots[dev->slot].io_phys.size;
875 break;
876 case IPACK_ID_SPACE:
877 if (dev->id_space.address != NULL) {
878 pr_err("Slot [%d:%d] ID space already mapped !\n",
879 tpci200->number, dev->slot);
880 res = -EINVAL;
881 goto out_unlock;
882 }
883 virt_addr_space = &dev->id_space;
884
885 phys_address = tpci200->slots[dev->slot].id_phys.address;
886 size_to_map = tpci200->slots[dev->slot].id_phys.size;
887 break;
888 case IPACK_MEM_SPACE:
889 if (dev->mem_space.address != NULL) {
890 pr_err("Slot [%d:%d] MEM space already mapped !\n",
891 tpci200->number, dev->slot);
892 res = -EINVAL;
893 goto out_unlock;
894 }
895 virt_addr_space = &dev->mem_space;
896
897 if (memory_size > tpci200->slots[dev->slot].mem_phys.size) {
898 pr_err("Slot [%d:%d] request is 0x%X memory, only 0x%X available !\n",
899 dev->bus_nr, dev->slot, memory_size,
900 tpci200->slots[dev->slot].mem_phys.size);
901 res = -EINVAL;
902 goto out_unlock;
903 }
904
905 phys_address = tpci200->slots[dev->slot].mem_phys.address;
906 size_to_map = memory_size;
907 break;
908 default:
909 pr_err("Slot [%d:%d] space %d doesn't exist !\n",
910 tpci200->number, dev->slot, space);
911 res = -EINVAL;
912 goto out_unlock;
913 break;
914 }
915
916 virt_addr_space->size = size_to_map;
917 virt_addr_space->address =
918 ioremap((unsigned long)phys_address, size_to_map);
919
920out_unlock:
921 mutex_unlock(&tpci200->mutex);
922out:
923 return res;
924}
925
926static int tpci200_request_irq(struct ipack_device *dev, int vector,
927 int (*handler)(void *), void *arg)
928{
929 int res;
930 struct slot_irq *slot_irq;
931 struct tpci200_board *tpci200;
932
933 tpci200 = check_slot(dev);
934 if (tpci200 == NULL) {
935 res = -EINVAL;
936 goto out;
937 }
938
939 if (mutex_lock_interruptible(&tpci200->mutex)) {
940 res = -ERESTARTSYS;
941 goto out;
942 }
943
944 if (tpci200->slots[dev->slot].irq != NULL) {
945 pr_err("Slot [%d:%d] IRQ already registered !\n", dev->bus_nr,
946 dev->slot);
947 res = -EINVAL;
948 goto out_unlock;
949 }
950
951 slot_irq = kzalloc(sizeof(struct slot_irq), GFP_KERNEL);
952 if (slot_irq == NULL) {
953 pr_err("Slot [%d:%d] unable to allocate memory for IRQ !\n",
954 dev->bus_nr, dev->slot);
955 res = -ENOMEM;
956 goto out_unlock;
957 }
958
959 /*
960 * WARNING: Setup Interrupt Vector in the IndustryPack device
961 * before an IRQ request.
962 * Read the User Manual of your IndustryPack device to know
963 * where to write the vector in memory.
964 */
965 slot_irq->vector = vector;
966 slot_irq->handler = handler;
967 slot_irq->arg = arg;
968 slot_irq->name = dev_name(&dev->dev);
969
970 tpci200->slots[dev->slot].irq = slot_irq;
971 res = __tpci200_request_irq(tpci200, dev);
972
973out_unlock:
974 mutex_unlock(&tpci200->mutex);
975out:
976 return res;
977}
978
979static void tpci200_slot_remove(struct tpci200_slot *slot)
980{
981 if ((slot->dev == NULL) ||
982 (slot->dev->driver->ops->remove == NULL))
983 return;
984
985 slot->dev->driver->ops->remove(slot->dev);
986}
987
988static void tpci200_uninstall(struct tpci200_board *tpci200)
989{
990 int i;
991
992 for (i = 0; i < TPCI200_NB_SLOT; i++)
993 tpci200_slot_remove(&tpci200->slots[i]);
994
995 tpci200_unregister(tpci200);
996 kfree(tpci200->slots);
997}
998
999static struct ipack_bus_ops tpci200_bus_ops = {
1000 .map_space = tpci200_slot_map_space,
1001 .unmap_space = tpci200_slot_unmap_space,
1002 .request_irq = tpci200_request_irq,
1003 .free_irq = tpci200_free_irq,
1004 .read8 = tpci200_read8,
1005 .read16 = tpci200_read16,
1006 .read32 = tpci200_read32,
1007 .write8 = tpci200_write8,
1008 .write16 = tpci200_write16,
1009 .write32 = tpci200_write32,
1010 .remove_device = tpci200_slot_unregister,
1011};
1012
1013static int tpci200_install(struct tpci200_board *tpci200)
1014{
1015 int res;
1016
1017 tpci200->slots = kzalloc(
1018 TPCI200_NB_SLOT * sizeof(struct tpci200_slot), GFP_KERNEL);
1019 if (tpci200->slots == NULL) {
1020 res = -ENOMEM;
1021 goto out_err;
1022 }
1023
1024 res = tpci200_register(tpci200);
1025 if (res)
1026 goto out_free;
1027
1028 mutex_init(&tpci200->mutex);
1029 return 0;
1030
1031out_free:
1032 kfree(tpci200->slots);
1033 tpci200->slots = NULL;
1034out_err:
1035 return res;
1036}
1037
1038static int tpci200_pciprobe(struct pci_dev *pdev,
1039 const struct pci_device_id *id)
1040{
1041 int ret;
1042 struct tpci200_board *tpci200;
1043
1044 tpci200 = kzalloc(sizeof(struct tpci200_board), GFP_KERNEL);
1045 if (!tpci200)
1046 return -ENOMEM;
1047
1048 tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL);
1049 if (!tpci200->info) {
1050 kfree(tpci200);
1051 return -ENOMEM;
1052 }
1053
1054 /* Save struct pci_dev pointer */
1055 tpci200->info->pdev = pdev;
1056 tpci200->info->id_table = (struct pci_device_id *)id;
1057
1058 /* register the device and initialize it */
1059 ret = tpci200_install(tpci200);
1060 if (ret) {
1061 pr_err("Error during tpci200 install !\n");
1062 kfree(tpci200->info);
1063 kfree(tpci200);
1064 return -ENODEV;
1065 }
1066
1067 /* Register the carrier in the industry pack bus driver */
1068 tpci200->info->ipack_bus = ipack_bus_register(&pdev->dev,
1069 TPCI200_NB_SLOT,
1070 &tpci200_bus_ops);
1071 if (!tpci200->info->ipack_bus) {
1072 pr_err("error registering the carrier on ipack driver\n");
1073 tpci200_uninstall(tpci200);
1074 kfree(tpci200->info);
1075 kfree(tpci200);
1076 return -EFAULT;
1077 }
1078
1079 /* save the bus number given by ipack to logging purpose */
1080 tpci200->number = tpci200->info->ipack_bus->bus_nr;
1081 dev_set_drvdata(&pdev->dev, tpci200);
1082 /* add the registered device in an internal linked list */
1083 list_add_tail(&tpci200->list, &tpci200_list);
1084 return ret;
1085}
1086
1087static void __tpci200_pci_remove(struct tpci200_board *tpci200)
1088{
1089 tpci200_uninstall(tpci200);
1090 tpci200_remove_sysfs_files(tpci200);
1091 list_del(&tpci200->list);
1092 ipack_bus_unregister(tpci200->info->ipack_bus);
1093 kfree(tpci200->info);
1094 kfree(tpci200);
1095}
1096
1097static void __devexit tpci200_pci_remove(struct pci_dev *dev)
1098{
1099 struct tpci200_board *tpci200, *next;
1100
1101 /* Search the registered device to uninstall it */
1102 list_for_each_entry_safe(tpci200, next, &tpci200_list, list) {
1103 if (tpci200->info->pdev == dev) {
1104 __tpci200_pci_remove(tpci200);
1105 break;
1106 }
1107 }
1108}
1109
1110static struct pci_device_id tpci200_idtable[2] = {
1111 { TPCI200_VENDOR_ID, TPCI200_DEVICE_ID, TPCI200_SUBVENDOR_ID,
1112 TPCI200_SUBDEVICE_ID },
1113 { 0, },
1114};
1115
1116static struct pci_driver tpci200_pci_drv = {
1117 .name = "tpci200",
1118 .id_table = tpci200_idtable,
1119 .probe = tpci200_pciprobe,
1120 .remove = __devexit_p(tpci200_pci_remove),
1121};
1122
1123static int __init tpci200_drvr_init_module(void)
1124{
1125 return pci_register_driver(&tpci200_pci_drv);
1126}
1127
1128static void __exit tpci200_drvr_exit_module(void)
1129{
1130 struct tpci200_board *tpci200, *next;
1131
1132 list_for_each_entry_safe(tpci200, next, &tpci200_list, list)
1133 __tpci200_pci_remove(tpci200);
1134
1135 pci_unregister_driver(&tpci200_pci_drv);
1136}
1137
1138MODULE_DESCRIPTION("TEWS TPCI-200 device driver");
1139MODULE_LICENSE("GPL");
1140module_init(tpci200_drvr_init_module);
1141module_exit(tpci200_drvr_exit_module);
diff --git a/drivers/staging/ipack/bridges/tpci200.h b/drivers/staging/ipack/bridges/tpci200.h
new file mode 100644
index 000000000000..0b547eedddc2
--- /dev/null
+++ b/drivers/staging/ipack/bridges/tpci200.h
@@ -0,0 +1,162 @@
1/**
2 * tpci200.h
3 *
4 * driver for the carrier TEWS TPCI-200
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
12 */
13
14#ifndef _TPCI200_H_
15#define _TPCI200_H_
16
17#include <linux/version.h>
18#include <linux/limits.h>
19#include <linux/pci.h>
20#include <linux/spinlock.h>
21#include <linux/interrupt.h>
22#include <linux/swab.h>
23#include <linux/io.h>
24
25#include "../ipack.h"
26
27#define TPCI200_NB_SLOT 0x4
28#define TPCI200_NB_BAR 0x6
29
30#define TPCI200_VENDOR_ID 0x1498
31#define TPCI200_DEVICE_ID 0x30C8
32#define TPCI200_SUBVENDOR_ID 0x1498
33#define TPCI200_SUBDEVICE_ID 0x300A
34
35#define TPCI200_IP_INTERFACE_BAR 2
36#define TPCI200_IO_ID_INT_SPACES_BAR 3
37#define TPCI200_MEM16_SPACE_BAR 4
38#define TPCI200_MEM8_SPACE_BAR 5
39
40#define TPCI200_REVISION_REG 0x00
41#define TPCI200_CONTROL_A_REG 0x02
42#define TPCI200_CONTROL_B_REG 0x04
43#define TPCI200_CONTROL_C_REG 0x06
44#define TPCI200_CONTROL_D_REG 0x08
45#define TPCI200_RESET_REG 0x0A
46#define TPCI200_STATUS_REG 0x0C
47
48#define TPCI200_IFACE_SIZE 0x100
49
50#define TPCI200_IO_SPACE_OFF 0x0000
51#define TPCI200_IO_SPACE_GAP 0x0100
52#define TPCI200_IO_SPACE_SIZE 0x0080
53#define TPCI200_ID_SPACE_OFF 0x0080
54#define TPCI200_ID_SPACE_GAP 0x0100
55#define TPCI200_ID_SPACE_SIZE 0x0040
56#define TPCI200_INT_SPACE_OFF 0x00C0
57#define TPCI200_INT_SPACE_GAP 0x0100
58#define TPCI200_INT_SPACE_SIZE 0x0040
59#define TPCI200_IOIDINT_SIZE 0x0400
60
61#define TPCI200_MEM8_GAP 0x00400000
62#define TPCI200_MEM8_SIZE 0x00400000
63#define TPCI200_MEM16_GAP 0x00800000
64#define TPCI200_MEM16_SIZE 0x00800000
65
66#define TPCI200_INT0_EN 0x0040
67#define TPCI200_INT1_EN 0x0080
68#define TPCI200_INT0_EDGE 0x0010
69#define TPCI200_INT1_EDGE 0x0020
70#define TPCI200_ERR_INT_EN 0x0008
71#define TPCI200_TIME_INT_EN 0x0004
72#define TPCI200_RECOVER_EN 0x0002
73#define TPCI200_CLK32 0x0001
74
75#define TPCI200_A_RESET 0x0001
76#define TPCI200_B_RESET 0x0002
77#define TPCI200_C_RESET 0x0004
78#define TPCI200_D_RESET 0x0008
79
80#define TPCI200_A_TIMEOUT 0x1000
81#define TPCI200_B_TIMEOUT 0x2000
82#define TPCI200_C_TIMEOUT 0x4000
83#define TPCI200_D_TIMEOUT 0x8000
84
85#define TPCI200_A_ERROR 0x0100
86#define TPCI200_B_ERROR 0x0200
87#define TPCI200_C_ERROR 0x0400
88#define TPCI200_D_ERROR 0x0800
89
90#define TPCI200_A_INT0 0x0001
91#define TPCI200_A_INT1 0x0002
92#define TPCI200_B_INT0 0x0004
93#define TPCI200_B_INT1 0x0008
94#define TPCI200_C_INT0 0x0010
95#define TPCI200_C_INT1 0x0020
96#define TPCI200_D_INT0 0x0040
97#define TPCI200_D_INT1 0x0080
98
99#define TPCI200_SLOT_INT_MASK 0x00FF
100
101#define VME_IOID_SPACE "IOID"
102#define VME_MEM_SPACE "MEM"
103
104/**
105 * struct slot_irq - slot IRQ definition.
106 * @vector Vector number
107 * @handler Handler called when IRQ arrives
108 * @arg Handler argument
109 * @name IRQ name
110 *
111 */
112struct slot_irq {
113 int vector;
114 int (*handler)(void *);
115 void *arg;
116 const char *name;
117};
118
119/**
120 * struct tpci200_slot - data specific to the tpci200 slot.
121 * @slot_id Slot identification gived to external interface
122 * @irq Slot IRQ infos
123 * @io_phys IO physical base address register of the slot
124 * @id_phys ID physical base address register of the slot
125 * @mem_phys MEM physical base address register of the slot
126 *
127 */
128struct tpci200_slot {
129 struct ipack_device *dev;
130 struct slot_irq *irq;
131 struct ipack_addr_space io_phys;
132 struct ipack_addr_space id_phys;
133 struct ipack_addr_space mem_phys;
134};
135
136/**
137 * struct tpci200_infos - informations specific of the TPCI200 tpci200.
138 * @pci_dev PCI device
139 * @interface_regs Pointer to IP interface space (Bar 2)
140 * @ioidint_space Pointer to IP ID, IO and INT space (Bar 3)
141 * @mem8_space Pointer to MEM space (Bar 4)
142 * @access_lock Mutex lock for simultaneous access
143 *
144 */
145struct tpci200_infos {
146 struct pci_dev *pdev;
147 struct pci_device_id *id_table;
148 void __iomem *interface_regs;
149 void __iomem *ioidint_space;
150 void __iomem *mem8_space;
151 spinlock_t access_lock;
152 struct ipack_bus_device *ipack_bus;
153};
154struct tpci200_board {
155 struct list_head list;
156 unsigned int number;
157 struct mutex mutex;
158 struct tpci200_slot *slots;
159 struct tpci200_infos *info;
160};
161
162#endif /* _TPCI200_H_ */
diff --git a/drivers/staging/ipack/devices/Kconfig b/drivers/staging/ipack/devices/Kconfig
new file mode 100644
index 000000000000..39f71888a584
--- /dev/null
+++ b/drivers/staging/ipack/devices/Kconfig
@@ -0,0 +1,7 @@
1config SERIAL_IPOCTAL
2 tristate "IndustryPack IP-OCTAL uart support"
3 depends on IPACK_BUS
4 help
5 This driver supports the IPOCTAL serial port device for the IndustryPack bus.
6 default n
7
diff --git a/drivers/staging/ipack/devices/Makefile b/drivers/staging/ipack/devices/Makefile
new file mode 100644
index 000000000000..6de18bda4a9a
--- /dev/null
+++ b/drivers/staging/ipack/devices/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_SERIAL_IPOCTAL) += ipoctal.o
diff --git a/drivers/staging/ipack/devices/ipoctal.c b/drivers/staging/ipack/devices/ipoctal.c
new file mode 100644
index 000000000000..29f6fa841d23
--- /dev/null
+++ b/drivers/staging/ipack/devices/ipoctal.c
@@ -0,0 +1,901 @@
1/**
2 * ipoctal.c
3 *
4 * driver for the GE IP-OCTAL boards
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/device.h>
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/interrupt.h>
20#include <linux/fs.h>
21#include <linux/delay.h>
22#include <linux/sched.h>
23#include <linux/tty.h>
24#include <linux/serial.h>
25#include <linux/tty_flip.h>
26#include <linux/slab.h>
27#include <linux/uaccess.h>
28#include <linux/atomic.h>
29#include "../ipack.h"
30#include "ipoctal.h"
31#include "scc2698.h"
32
33#define IP_OCTAL_MANUFACTURER_ID 0xF0
34#define IP_OCTAL_232_ID 0x22
35#define IP_OCTAL_422_ID 0x2A
36#define IP_OCTAL_485_ID 0x48
37
38#define IP_OCTAL_ID_SPACE_VECTOR 0x41
39#define IP_OCTAL_NB_BLOCKS 4
40
41static struct ipack_driver driver;
42static const struct tty_operations ipoctal_fops;
43
44struct ipoctal {
45 struct list_head list;
46 struct ipack_device *dev;
47 unsigned int board_id;
48 struct scc2698_channel *chan_regs;
49 struct scc2698_block *block_regs;
50 struct ipoctal_stats chan_stats[NR_CHANNELS];
51 char *buffer[NR_CHANNELS];
52 unsigned int nb_bytes[NR_CHANNELS];
53 unsigned int count_wr[NR_CHANNELS];
54 struct ipoctal_config chan_config[NR_CHANNELS];
55 wait_queue_head_t queue[NR_CHANNELS];
56 unsigned short error_flag[NR_CHANNELS];
57 spinlock_t lock[NR_CHANNELS];
58 unsigned int pointer_read[NR_CHANNELS];
59 unsigned int pointer_write[NR_CHANNELS];
60 atomic_t open[NR_CHANNELS];
61 unsigned char write;
62 struct tty_port tty_port[NR_CHANNELS];
63 struct tty_driver *tty_drv;
64};
65
66/* Linked list to save the registered devices */
67static LIST_HEAD(ipoctal_list);
68
69static inline void ipoctal_write_io_reg(struct ipoctal *ipoctal,
70 unsigned char *dest,
71 unsigned char value)
72{
73 unsigned long offset;
74
75 offset = ((void __iomem *) dest) - ipoctal->dev->io_space.address;
76 ipoctal->dev->bus->ops->write8(ipoctal->dev, IPACK_IO_SPACE, offset,
77 value);
78}
79
80static inline void ipoctal_write_cr_cmd(struct ipoctal *ipoctal,
81 unsigned char *dest,
82 unsigned char value)
83{
84 ipoctal_write_io_reg(ipoctal, dest, value);
85}
86
87static inline unsigned char ipoctal_read_io_reg(struct ipoctal *ipoctal,
88 unsigned char *src)
89{
90 unsigned long offset;
91 unsigned char value;
92
93 offset = ((void __iomem *) src) - ipoctal->dev->io_space.address;
94 ipoctal->dev->bus->ops->read8(ipoctal->dev, IPACK_IO_SPACE, offset,
95 &value);
96 return value;
97}
98
99static struct ipoctal *ipoctal_find_board(struct tty_struct *tty)
100{
101 struct ipoctal *p;
102
103 list_for_each_entry(p, &ipoctal_list, list) {
104 if (tty->driver->major == p->tty_drv->major)
105 return p;
106 }
107
108 return NULL;
109}
110
111static int ipoctal_port_activate(struct tty_port *port, struct tty_struct *tty)
112{
113 struct ipoctal *ipoctal;
114 int channel = tty->index;
115
116 ipoctal = ipoctal_find_board(tty);
117
118 if (ipoctal == NULL) {
119 pr_err("Device not found. Major %d\n", tty->driver->major);
120 return -ENODEV;
121 }
122
123 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
124 CR_ENABLE_RX);
125 tty->driver_data = ipoctal;
126
127 return 0;
128}
129
130static int ipoctal_open(struct tty_struct *tty, struct file *file)
131{
132 int channel = tty->index;
133 int res;
134 struct ipoctal *ipoctal;
135
136 ipoctal = ipoctal_find_board(tty);
137
138 if (ipoctal == NULL) {
139 pr_err("Device not found. Major %d\n", tty->driver->major);
140 return -ENODEV;
141 }
142
143 if (atomic_read(&ipoctal->open[channel]))
144 return -EBUSY;
145
146 res = tty_port_open(&ipoctal->tty_port[channel], tty, file);
147 if (res)
148 return res;
149
150 atomic_inc(&ipoctal->open[channel]);
151 return 0;
152}
153
154static void ipoctal_reset_stats(struct ipoctal_stats *stats)
155{
156 stats->tx = 0;
157 stats->rx = 0;
158 stats->rcv_break = 0;
159 stats->framing_err = 0;
160 stats->overrun_err = 0;
161 stats->parity_err = 0;
162}
163
164static void ipoctal_free_channel(struct tty_struct *tty)
165{
166 int channel = tty->index;
167 struct ipoctal *ipoctal = tty->driver_data;
168
169 if (ipoctal == NULL)
170 return;
171
172 ipoctal_reset_stats(&ipoctal->chan_stats[channel]);
173 ipoctal->pointer_read[channel] = 0;
174 ipoctal->pointer_write[channel] = 0;
175 ipoctal->nb_bytes[channel] = 0;
176}
177
178static void ipoctal_close(struct tty_struct *tty, struct file *filp)
179{
180 int channel = tty->index;
181 struct ipoctal *ipoctal = tty->driver_data;
182
183 tty_port_close(&ipoctal->tty_port[channel], tty, filp);
184
185 if (atomic_dec_and_test(&ipoctal->open[channel]))
186 ipoctal_free_channel(tty);
187}
188
189static int ipoctal_get_icount(struct tty_struct *tty,
190 struct serial_icounter_struct *icount)
191{
192 struct ipoctal *ipoctal = tty->driver_data;
193 int channel = tty->index;
194
195 icount->cts = 0;
196 icount->dsr = 0;
197 icount->rng = 0;
198 icount->dcd = 0;
199 icount->rx = ipoctal->chan_stats[channel].rx;
200 icount->tx = ipoctal->chan_stats[channel].tx;
201 icount->frame = ipoctal->chan_stats[channel].framing_err;
202 icount->parity = ipoctal->chan_stats[channel].parity_err;
203 icount->brk = ipoctal->chan_stats[channel].rcv_break;
204 return 0;
205}
206
207static int ipoctal_irq_handler(void *arg)
208{
209 unsigned int channel;
210 unsigned int block;
211 unsigned char isr;
212 unsigned char sr;
213 unsigned char isr_tx_rdy, isr_rx_rdy;
214 unsigned char value;
215 unsigned char flag;
216 struct tty_struct *tty;
217 struct ipoctal *ipoctal = (struct ipoctal *) arg;
218
219 /* Check all channels */
220 for (channel = 0; channel < NR_CHANNELS; channel++) {
221 /* If there is no client, skip the check */
222 if (!atomic_read(&ipoctal->open[channel]))
223 continue;
224
225 tty = tty_port_tty_get(&ipoctal->tty_port[channel]);
226 if (!tty)
227 continue;
228
229 /*
230 * The HW is organized in pair of channels.
231 * See which register we need to read from
232 */
233 block = channel / 2;
234 isr = ipoctal_read_io_reg(ipoctal,
235 &ipoctal->block_regs[block].u.r.isr);
236 sr = ipoctal_read_io_reg(ipoctal,
237 &ipoctal->chan_regs[channel].u.r.sr);
238
239 if ((channel % 2) == 1) {
240 isr_tx_rdy = isr & ISR_TxRDY_B;
241 isr_rx_rdy = isr & ISR_RxRDY_FFULL_B;
242 } else {
243 isr_tx_rdy = isr & ISR_TxRDY_A;
244 isr_rx_rdy = isr & ISR_RxRDY_FFULL_A;
245 }
246
247 /* In case of RS-485, change from TX to RX when finishing TX.
248 * Half-duplex.
249 */
250 if ((ipoctal->board_id == IP_OCTAL_485_ID) &&
251 (sr & SR_TX_EMPTY) &&
252 (ipoctal->nb_bytes[channel] == 0)) {
253 ipoctal_write_io_reg(ipoctal,
254 &ipoctal->chan_regs[channel].u.w.cr,
255 CR_DISABLE_TX);
256 ipoctal_write_cr_cmd(ipoctal,
257 &ipoctal->chan_regs[channel].u.w.cr,
258 CR_CMD_NEGATE_RTSN);
259 ipoctal_write_io_reg(ipoctal,
260 &ipoctal->chan_regs[channel].u.w.cr,
261 CR_ENABLE_RX);
262 ipoctal->write = 1;
263 wake_up_interruptible(&ipoctal->queue[channel]);
264 }
265
266 /* RX data */
267 if (isr_rx_rdy && (sr & SR_RX_READY)) {
268 value = ipoctal_read_io_reg(ipoctal,
269 &ipoctal->chan_regs[channel].u.r.rhr);
270 flag = TTY_NORMAL;
271
272 /* Error: count statistics */
273 if (sr & SR_ERROR) {
274 ipoctal_write_cr_cmd(ipoctal,
275 &ipoctal->chan_regs[channel].u.w.cr,
276 CR_CMD_RESET_ERR_STATUS);
277
278 if (sr & SR_OVERRUN_ERROR) {
279 ipoctal->error_flag[channel] |= UART_OVERRUN;
280 ipoctal->chan_stats[channel].overrun_err++;
281 /* Overrun doesn't affect the current character*/
282 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
283 }
284 if (sr & SR_PARITY_ERROR) {
285 ipoctal->error_flag[channel] |= UART_PARITY;
286 ipoctal->chan_stats[channel].parity_err++;
287 flag = TTY_PARITY;
288 }
289 if (sr & SR_FRAMING_ERROR) {
290 ipoctal->error_flag[channel] |= UART_FRAMING;
291 ipoctal->chan_stats[channel].framing_err++;
292 flag = TTY_FRAME;
293 }
294 if (sr & SR_RECEIVED_BREAK) {
295 ipoctal->error_flag[channel] |= UART_BREAK;
296 ipoctal->chan_stats[channel].rcv_break++;
297 flag = TTY_BREAK;
298 }
299 }
300
301 tty_insert_flip_char(tty, value, flag);
302 }
303
304 /* TX of each character */
305 if (isr_tx_rdy && (sr & SR_TX_READY)) {
306 unsigned int *pointer_write =
307 &ipoctal->pointer_write[channel];
308
309 if (ipoctal->nb_bytes[channel] <= 0) {
310 ipoctal->nb_bytes[channel] = 0;
311 continue;
312 }
313 spin_lock(&ipoctal->lock[channel]);
314 value = ipoctal->buffer[channel][*pointer_write];
315 ipoctal_write_io_reg(ipoctal,
316 &ipoctal->chan_regs[channel].u.w.thr,
317 value);
318 ipoctal->chan_stats[channel].tx++;
319 ipoctal->count_wr[channel]++;
320 (*pointer_write)++;
321 *pointer_write = *pointer_write % PAGE_SIZE;
322 ipoctal->nb_bytes[channel]--;
323 spin_unlock(&ipoctal->lock[channel]);
324
325 if ((ipoctal->nb_bytes[channel] == 0) &&
326 (waitqueue_active(&ipoctal->queue[channel]))) {
327
328 if (ipoctal->board_id != IP_OCTAL_485_ID) {
329 ipoctal->write = 1;
330 wake_up_interruptible(&ipoctal->queue[channel]);
331 }
332 }
333 }
334
335 tty_flip_buffer_push(tty);
336 tty_kref_put(tty);
337 }
338 return IRQ_HANDLED;
339}
340
341static int ipoctal_check_model(struct ipack_device *dev, unsigned char *id)
342{
343 unsigned char manufacturerID;
344 unsigned char board_id;
345
346 dev->bus->ops->read8(dev, IPACK_ID_SPACE,
347 IPACK_IDPROM_OFFSET_MANUFACTURER_ID, &manufacturerID);
348 if (manufacturerID != IP_OCTAL_MANUFACTURER_ID)
349 return -ENODEV;
350
351 dev->bus->ops->read8(dev, IPACK_ID_SPACE,
352 IPACK_IDPROM_OFFSET_MODEL, (unsigned char *)&board_id);
353
354 switch (board_id) {
355 case IP_OCTAL_232_ID:
356 case IP_OCTAL_422_ID:
357 case IP_OCTAL_485_ID:
358 *id = board_id;
359 break;
360 default:
361 return -ENODEV;
362 }
363
364 return 0;
365}
366
367static const struct tty_port_operations ipoctal_tty_port_ops = {
368 .dtr_rts = NULL,
369 .activate = ipoctal_port_activate,
370};
371
372static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
373 unsigned int slot, unsigned int vector)
374{
375 int res = 0;
376 int i;
377 struct tty_driver *tty;
378 char name[20];
379 unsigned char board_id;
380
381 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
382 IPACK_ID_SPACE);
383 if (res) {
384 pr_err("Unable to map slot [%d:%d] ID space!\n", bus_nr, slot);
385 return res;
386 }
387
388 res = ipoctal_check_model(ipoctal->dev, &board_id);
389 if (res) {
390 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev,
391 IPACK_ID_SPACE);
392 goto out_unregister_id_space;
393 }
394 ipoctal->board_id = board_id;
395
396 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
397 IPACK_IO_SPACE);
398 if (res) {
399 pr_err("Unable to map slot [%d:%d] IO space!\n", bus_nr, slot);
400 goto out_unregister_id_space;
401 }
402
403 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev,
404 0x8000, IPACK_MEM_SPACE);
405 if (res) {
406 pr_err("Unable to map slot [%d:%d] MEM space!\n", bus_nr, slot);
407 goto out_unregister_io_space;
408 }
409
410 /* Save the virtual address to access the registers easily */
411 ipoctal->chan_regs =
412 (struct scc2698_channel *) ipoctal->dev->io_space.address;
413 ipoctal->block_regs =
414 (struct scc2698_block *) ipoctal->dev->io_space.address;
415
416 /* Disable RX and TX before touching anything */
417 for (i = 0; i < NR_CHANNELS ; i++) {
418 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[i].u.w.cr,
419 CR_DISABLE_RX | CR_DISABLE_TX);
420 }
421
422 for (i = 0; i < IP_OCTAL_NB_BLOCKS; i++) {
423 ipoctal_write_io_reg(ipoctal,
424 &ipoctal->block_regs[i].u.w.acr,
425 ACR_BRG_SET2);
426 ipoctal_write_io_reg(ipoctal,
427 &ipoctal->block_regs[i].u.w.opcr,
428 OPCR_MPP_OUTPUT | OPCR_MPOa_RTSN |
429 OPCR_MPOb_RTSN);
430 ipoctal_write_io_reg(ipoctal,
431 &ipoctal->block_regs[i].u.w.imr,
432 IMR_TxRDY_A | IMR_RxRDY_FFULL_A |
433 IMR_DELTA_BREAK_A | IMR_TxRDY_B |
434 IMR_RxRDY_FFULL_B | IMR_DELTA_BREAK_B);
435 }
436
437 /*
438 * IP-OCTAL has different addresses to copy its IRQ vector.
439 * Depending of the carrier these addresses are accesible or not.
440 * More info in the datasheet.
441 */
442 ipoctal->dev->bus->ops->request_irq(ipoctal->dev, vector,
443 ipoctal_irq_handler, ipoctal);
444 ipoctal->dev->bus->ops->write8(ipoctal->dev, IPACK_ID_SPACE, 0, vector);
445
446 /* Register the TTY device */
447
448 /* Each IP-OCTAL channel is a TTY port */
449 tty = alloc_tty_driver(NR_CHANNELS);
450
451 if (!tty) {
452 res = -ENOMEM;
453 goto out_unregister_slot_unmap;
454 }
455
456 /* Fill struct tty_driver with ipoctal data */
457 tty->owner = THIS_MODULE;
458 tty->driver_name = "ipoctal";
459 sprintf(name, "ipoctal.%d.%d.", bus_nr, slot);
460 tty->name = name;
461 tty->major = 0;
462
463 tty->minor_start = 0;
464 tty->type = TTY_DRIVER_TYPE_SERIAL;
465 tty->subtype = SERIAL_TYPE_NORMAL;
466 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
467 tty->init_termios = tty_std_termios;
468 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
469 tty->init_termios.c_ispeed = 9600;
470 tty->init_termios.c_ospeed = 9600;
471
472 tty_set_operations(tty, &ipoctal_fops);
473 res = tty_register_driver(tty);
474 if (res) {
475 pr_err("Can't register tty driver.\n");
476 put_tty_driver(tty);
477 goto out_unregister_slot_unmap;
478 }
479
480 /* Save struct tty_driver for use it when uninstalling the device */
481 ipoctal->tty_drv = tty;
482
483 for (i = 0; i < NR_CHANNELS; i++) {
484 tty_port_init(&ipoctal->tty_port[i]);
485 tty_port_alloc_xmit_buf(&ipoctal->tty_port[i]);
486 ipoctal->tty_port[i].ops = &ipoctal_tty_port_ops;
487
488 ipoctal_reset_stats(&ipoctal->chan_stats[i]);
489 ipoctal->nb_bytes[i] = 0;
490 init_waitqueue_head(&ipoctal->queue[i]);
491 ipoctal->error_flag[i] = UART_NOERROR;
492
493 spin_lock_init(&ipoctal->lock[i]);
494 ipoctal->pointer_read[i] = 0;
495 ipoctal->pointer_write[i] = 0;
496 ipoctal->nb_bytes[i] = 0;
497 tty_register_device(tty, i, NULL);
498
499 /*
500 * Enable again the RX. TX will be enabled when
501 * there is something to send
502 */
503 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[i].u.w.cr,
504 CR_ENABLE_RX);
505 }
506
507 return 0;
508
509out_unregister_slot_unmap:
510 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_ID_SPACE);
511out_unregister_io_space:
512 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_IO_SPACE);
513out_unregister_id_space:
514 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_MEM_SPACE);
515 return res;
516}
517
518static inline int ipoctal_copy_write_buffer(struct ipoctal *ipoctal,
519 unsigned int channel,
520 const unsigned char *buf,
521 int count)
522{
523 unsigned long flags;
524 int i;
525 unsigned int *pointer_read = &ipoctal->pointer_read[channel];
526
527 /* Copy the bytes from the user buffer to the internal one */
528 for (i = 0; i < count; i++) {
529 if (i <= (PAGE_SIZE - ipoctal->nb_bytes[channel])) {
530 spin_lock_irqsave(&ipoctal->lock[channel], flags);
531 ipoctal->tty_port[channel].xmit_buf[*pointer_read] = buf[i];
532 *pointer_read = (*pointer_read + 1) % PAGE_SIZE;
533 ipoctal->nb_bytes[channel]++;
534 spin_unlock_irqrestore(&ipoctal->lock[channel], flags);
535 } else {
536 break;
537 }
538 }
539 return i;
540}
541
542static int ipoctal_write(struct ipoctal *ipoctal, unsigned int channel,
543 const unsigned char *buf, int count)
544{
545 ipoctal->nb_bytes[channel] = 0;
546 ipoctal->count_wr[channel] = 0;
547
548 ipoctal_copy_write_buffer(ipoctal, channel, buf, count);
549
550 ipoctal->error_flag[channel] = UART_NOERROR;
551
552 /* As the IP-OCTAL 485 only supports half duplex, do it manually */
553 if (ipoctal->board_id == IP_OCTAL_485_ID) {
554 ipoctal_write_io_reg(ipoctal,
555 &ipoctal->chan_regs[channel].u.w.cr,
556 CR_DISABLE_RX);
557 ipoctal_write_cr_cmd(ipoctal,
558 &ipoctal->chan_regs[channel].u.w.cr,
559 CR_CMD_ASSERT_RTSN);
560 }
561
562 /*
563 * Send a packet and then disable TX to avoid failure after several send
564 * operations
565 */
566 ipoctal_write_io_reg(ipoctal,
567 &ipoctal->chan_regs[channel].u.w.cr,
568 CR_ENABLE_TX);
569 wait_event_interruptible(ipoctal->queue[channel], ipoctal->write);
570 ipoctal_write_io_reg(ipoctal,
571 &ipoctal->chan_regs[channel].u.w.cr,
572 CR_DISABLE_TX);
573
574 ipoctal->write = 0;
575 return ipoctal->count_wr[channel];
576}
577
578static int ipoctal_write_tty(struct tty_struct *tty,
579 const unsigned char *buf, int count)
580{
581 unsigned int channel = tty->index;
582 struct ipoctal *ipoctal = tty->driver_data;
583
584 return ipoctal_write(ipoctal, channel, buf, count);
585}
586
587static int ipoctal_write_room(struct tty_struct *tty)
588{
589 int channel = tty->index;
590 struct ipoctal *ipoctal = tty->driver_data;
591
592 return PAGE_SIZE - ipoctal->nb_bytes[channel];
593}
594
595static int ipoctal_chars_in_buffer(struct tty_struct *tty)
596{
597 int channel = tty->index;
598 struct ipoctal *ipoctal = tty->driver_data;
599
600 return ipoctal->nb_bytes[channel];
601}
602
603static void ipoctal_set_termios(struct tty_struct *tty,
604 struct ktermios *old_termios)
605{
606 unsigned int cflag;
607 unsigned char mr1 = 0;
608 unsigned char mr2 = 0;
609 unsigned char csr = 0;
610 unsigned int channel = tty->index;
611 struct ipoctal *ipoctal = tty->driver_data;
612 speed_t baud;
613
614 cflag = tty->termios->c_cflag;
615
616 /* Disable and reset everything before change the setup */
617 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
618 CR_DISABLE_RX | CR_DISABLE_TX);
619 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
620 CR_CMD_RESET_RX);
621 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
622 CR_CMD_RESET_TX);
623 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
624 CR_CMD_RESET_ERR_STATUS);
625 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
626 CR_CMD_RESET_MR);
627
628 /* Set Bits per chars */
629 switch (cflag & CSIZE) {
630 case CS6:
631 mr1 |= MR1_CHRL_6_BITS;
632 break;
633 case CS7:
634 mr1 |= MR1_CHRL_7_BITS;
635 break;
636 case CS8:
637 default:
638 mr1 |= MR1_CHRL_8_BITS;
639 /* By default, select CS8 */
640 tty->termios->c_cflag = (cflag & ~CSIZE) | CS8;
641 break;
642 }
643
644 /* Set Parity */
645 if (cflag & PARENB)
646 if (cflag & PARODD)
647 mr1 |= MR1_PARITY_ON | MR1_PARITY_ODD;
648 else
649 mr1 |= MR1_PARITY_ON | MR1_PARITY_EVEN;
650 else
651 mr1 |= MR1_PARITY_OFF;
652
653 /* Mark or space parity is not supported */
654 tty->termios->c_cflag &= ~CMSPAR;
655
656 /* Set stop bits */
657 if (cflag & CSTOPB)
658 mr2 |= MR2_STOP_BITS_LENGTH_2;
659 else
660 mr2 |= MR2_STOP_BITS_LENGTH_1;
661
662 /* Set the flow control */
663 switch (ipoctal->board_id) {
664 case IP_OCTAL_232_ID:
665 if (cflag & CRTSCTS) {
666 mr1 |= MR1_RxRTS_CONTROL_ON;
667 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_ON;
668 ipoctal->chan_config[channel].flow_control = 1;
669 } else {
670 mr1 |= MR1_RxRTS_CONTROL_OFF;
671 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_OFF;
672 ipoctal->chan_config[channel].flow_control = 0;
673 }
674 break;
675 case IP_OCTAL_422_ID:
676 mr1 |= MR1_RxRTS_CONTROL_OFF;
677 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_OFF;
678 ipoctal->chan_config[channel].flow_control = 0;
679 break;
680 case IP_OCTAL_485_ID:
681 mr1 |= MR1_RxRTS_CONTROL_OFF;
682 mr2 |= MR2_TxRTS_CONTROL_ON | MR2_CTS_ENABLE_TX_OFF;
683 ipoctal->chan_config[channel].flow_control = 0;
684 break;
685 default:
686 return;
687 break;
688 }
689
690 baud = tty_get_baud_rate(tty);
691 tty_termios_encode_baud_rate(tty->termios, baud, baud);
692
693 /* Set baud rate */
694 switch (tty->termios->c_ospeed) {
695 case 75:
696 csr |= TX_CLK_75 | RX_CLK_75;
697 break;
698 case 110:
699 csr |= TX_CLK_110 | RX_CLK_110;
700 break;
701 case 150:
702 csr |= TX_CLK_150 | RX_CLK_150;
703 break;
704 case 300:
705 csr |= TX_CLK_300 | RX_CLK_300;
706 break;
707 case 600:
708 csr |= TX_CLK_600 | RX_CLK_600;
709 break;
710 case 1200:
711 csr |= TX_CLK_1200 | RX_CLK_1200;
712 break;
713 case 1800:
714 csr |= TX_CLK_1800 | RX_CLK_1800;
715 break;
716 case 2000:
717 csr |= TX_CLK_2000 | RX_CLK_2000;
718 break;
719 case 2400:
720 csr |= TX_CLK_2400 | RX_CLK_2400;
721 break;
722 case 4800:
723 csr |= TX_CLK_4800 | RX_CLK_4800;
724 break;
725 case 9600:
726 csr |= TX_CLK_9600 | RX_CLK_9600;
727 break;
728 case 19200:
729 csr |= TX_CLK_19200 | RX_CLK_19200;
730 break;
731 case 38400:
732 default:
733 csr |= TX_CLK_38400 | RX_CLK_38400;
734 /* In case of default, we establish 38400 bps */
735 tty_termios_encode_baud_rate(tty->termios, 38400, 38400);
736 break;
737 }
738
739 mr1 |= MR1_ERROR_CHAR;
740 mr1 |= MR1_RxINT_RxRDY;
741
742 /* Write the control registers */
743 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.mr, mr1);
744 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.mr, mr2);
745 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.csr, csr);
746
747 /* save the setup in the structure */
748 ipoctal->chan_config[channel].baud = tty_get_baud_rate(tty);
749 ipoctal->chan_config[channel].bits_per_char = cflag & CSIZE;
750 ipoctal->chan_config[channel].parity = cflag & PARENB;
751 ipoctal->chan_config[channel].stop_bits = cflag & CSTOPB;
752
753 /* Enable again the RX */
754 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
755 CR_ENABLE_RX);
756}
757
758static void ipoctal_hangup(struct tty_struct *tty)
759{
760 unsigned long flags;
761 int channel = tty->index;
762 struct ipoctal *ipoctal = tty->driver_data;
763
764 if (ipoctal == NULL)
765 return;
766
767 spin_lock_irqsave(&ipoctal->lock[channel], flags);
768 ipoctal->nb_bytes[channel] = 0;
769 ipoctal->pointer_read[channel] = 0;
770 ipoctal->pointer_write[channel] = 0;
771 spin_unlock_irqrestore(&ipoctal->lock[channel], flags);
772
773 tty_port_hangup(&ipoctal->tty_port[channel]);
774
775 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
776 CR_DISABLE_RX | CR_DISABLE_TX);
777 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
778 CR_CMD_RESET_RX);
779 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
780 CR_CMD_RESET_TX);
781 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
782 CR_CMD_RESET_ERR_STATUS);
783 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].u.w.cr,
784 CR_CMD_RESET_MR);
785
786 clear_bit(ASYNCB_INITIALIZED, &ipoctal->tty_port[channel].flags);
787 wake_up_interruptible(&ipoctal->tty_port[channel].open_wait);
788}
789
790static const struct tty_operations ipoctal_fops = {
791 .ioctl = NULL,
792 .open = ipoctal_open,
793 .close = ipoctal_close,
794 .write = ipoctal_write_tty,
795 .set_termios = ipoctal_set_termios,
796 .write_room = ipoctal_write_room,
797 .chars_in_buffer = ipoctal_chars_in_buffer,
798 .get_icount = ipoctal_get_icount,
799 .hangup = ipoctal_hangup,
800};
801
802static int ipoctal_match(struct ipack_device *dev)
803{
804 int res;
805 unsigned char board_id;
806
807 if ((!dev->bus->ops) || (!dev->bus->ops->map_space) ||
808 (!dev->bus->ops->unmap_space))
809 return 0;
810
811 res = dev->bus->ops->map_space(dev, 0, IPACK_ID_SPACE);
812 if (res)
813 return 0;
814
815 res = ipoctal_check_model(dev, &board_id);
816 dev->bus->ops->unmap_space(dev, IPACK_ID_SPACE);
817 if (!res)
818 return 1;
819
820 return 0;
821}
822
823static int ipoctal_probe(struct ipack_device *dev)
824{
825 int res;
826 struct ipoctal *ipoctal;
827
828 ipoctal = kzalloc(sizeof(struct ipoctal), GFP_KERNEL);
829 if (ipoctal == NULL)
830 return -ENOMEM;
831
832 ipoctal->dev = dev;
833 res = ipoctal_inst_slot(ipoctal, dev->bus_nr, dev->slot, dev->irq);
834 if (res)
835 goto out_uninst;
836
837 list_add_tail(&ipoctal->list, &ipoctal_list);
838 return 0;
839
840out_uninst:
841 kfree(ipoctal);
842 return res;
843}
844
845static void __ipoctal_remove(struct ipoctal *ipoctal)
846{
847 int i;
848
849 for (i = 0; i < NR_CHANNELS; i++) {
850 tty_unregister_device(ipoctal->tty_drv, i);
851 tty_port_free_xmit_buf(&ipoctal->tty_port[i]);
852 }
853
854 tty_unregister_driver(ipoctal->tty_drv);
855 put_tty_driver(ipoctal->tty_drv);
856
857 /* Tell the carrier board to free all the resources for this device */
858 if (ipoctal->dev->bus->ops->remove_device != NULL)
859 ipoctal->dev->bus->ops->remove_device(ipoctal->dev);
860
861 list_del(&ipoctal->list);
862 kfree(ipoctal);
863}
864
865static void ipoctal_remove(struct ipack_device *device)
866{
867 struct ipoctal *ipoctal, *next;
868
869 list_for_each_entry_safe(ipoctal, next, &ipoctal_list, list) {
870 if (ipoctal->dev == device)
871 __ipoctal_remove(ipoctal);
872 }
873}
874
875static struct ipack_driver_ops ipoctal_drv_ops = {
876 .match = ipoctal_match,
877 .probe = ipoctal_probe,
878 .remove = ipoctal_remove,
879};
880
881static int __init ipoctal_init(void)
882{
883 driver.ops = &ipoctal_drv_ops;
884 return ipack_driver_register(&driver, THIS_MODULE, KBUILD_MODNAME);
885}
886
887static void __exit ipoctal_exit(void)
888{
889 struct ipoctal *p, *next;
890
891 list_for_each_entry_safe(p, next, &ipoctal_list, list)
892 __ipoctal_remove(p);
893
894 ipack_driver_unregister(&driver);
895}
896
897MODULE_DESCRIPTION("IP-Octal 232, 422 and 485 device driver");
898MODULE_LICENSE("GPL");
899
900module_init(ipoctal_init);
901module_exit(ipoctal_exit);
diff --git a/drivers/staging/ipack/devices/ipoctal.h b/drivers/staging/ipack/devices/ipoctal.h
new file mode 100644
index 000000000000..266f3617069d
--- /dev/null
+++ b/drivers/staging/ipack/devices/ipoctal.h
@@ -0,0 +1,80 @@
1/**
2 * ipoctal.h
3 *
4 * driver for the IPOCTAL boards
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
12 */
13
14#ifndef _IPOCTAL_H
15#define _IPOCTAL_H_
16
17#define NR_CHANNELS 8
18#define IPOCTAL_MAX_BOARDS 16
19#define MAX_DEVICES (NR_CHANNELS * IPOCTAL_MAX_BOARDS)
20#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
21
22/**
23 * enum uart_parity_e - UART supported parity.
24 */
25enum uart_parity_e {
26 UART_NONE = 0,
27 UART_ODD = 1,
28 UART_EVEN = 2,
29};
30
31/**
32 * enum uart_error - UART error type
33 *
34 */
35enum uart_error {
36 UART_NOERROR = 0, /* No error during transmission */
37 UART_TIMEOUT = 1 << 0, /* Timeout error */
38 UART_OVERRUN = 1 << 1, /* Overrun error */
39 UART_PARITY = 1 << 2, /* Parity error */
40 UART_FRAMING = 1 << 3, /* Framing error */
41 UART_BREAK = 1 << 4, /* Received break */
42};
43
44/**
45 * struct ipoctal_config - Serial configuration
46 *
47 * @baud: Baud rate
48 * @stop_bits: Stop bits (1 or 2)
49 * @bits_per_char: data size in bits
50 * @parity
51 * @flow_control: Flow control management (RTS/CTS) (0 disabled, 1 enabled)
52 */
53struct ipoctal_config {
54 unsigned int baud;
55 unsigned int stop_bits;
56 unsigned int bits_per_char;
57 unsigned short parity;
58 unsigned int flow_control;
59};
60
61/**
62 * struct ipoctal_stats -- Stats since last reset
63 *
64 * @tx: Number of transmitted bytes
65 * @rx: Number of received bytes
66 * @overrun: Number of overrun errors
67 * @parity_err: Number of parity errors
68 * @framing_err: Number of framing errors
69 * @rcv_break: Number of break received
70 */
71struct ipoctal_stats {
72 unsigned long tx;
73 unsigned long rx;
74 unsigned long overrun_err;
75 unsigned long parity_err;
76 unsigned long framing_err;
77 unsigned long rcv_break;
78};
79
80#endif /* _IPOCTAL_H_ */
diff --git a/drivers/staging/ipack/devices/scc2698.h b/drivers/staging/ipack/devices/scc2698.h
new file mode 100644
index 000000000000..47f6269985fd
--- /dev/null
+++ b/drivers/staging/ipack/devices/scc2698.h
@@ -0,0 +1,228 @@
1/*
2 * scc2698.h
3 *
4 * driver for the IPOCTAL boards
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
12 */
13
14#ifndef SCC2698_H_
15#define SCC2698_H_
16
17/*
18 * struct scc2698_channel - Channel access to scc2698 IO
19 *
20 * dn value are only spacer.
21 *
22 */
23struct scc2698_channel {
24 union {
25 struct {
26 unsigned char d0, mr; /* Mode register 1/2*/
27 unsigned char d1, sr; /* Status register */
28 unsigned char d2, r1; /* reserved */
29 unsigned char d3, rhr; /* Receive holding register (R) */
30 unsigned char junk[8]; /* other crap for block control */
31 } r; /* Read access */
32 struct {
33 unsigned char d0, mr; /* Mode register 1/2 */
34 unsigned char d1, csr; /* Clock select register */
35 unsigned char d2, cr; /* Command register */
36 unsigned char d3, thr; /* Transmit holding register */
37 unsigned char junk[8]; /* other crap for block control */
38 } w; /* Write access */
39 } u;
40};
41
42/*
43 * struct scc2698_block - Block access to scc2698 IO
44 *
45 * The scc2698 contain 4 block.
46 * Each block containt two channel a and b.
47 * dn value are only spacer.
48 *
49 */
50struct scc2698_block {
51 union {
52 struct {
53 unsigned char d0, mra; /* Mode register 1/2 (a) */
54 unsigned char d1, sra; /* Status register (a) */
55 unsigned char d2, r1; /* reserved */
56 unsigned char d3, rhra; /* Receive holding register (a) */
57 unsigned char d4, ipcr; /* Input port change register of block */
58 unsigned char d5, isr; /* Interrupt status register of block */
59 unsigned char d6, ctur; /* Counter timer upper register of block */
60 unsigned char d7, ctlr; /* Counter timer lower register of block */
61 unsigned char d8, mrb; /* Mode register 1/2 (b) */
62 unsigned char d9, srb; /* Status register (b) */
63 unsigned char da, r2; /* reserved */
64 unsigned char db, rhrb; /* Receive holding register (b) */
65 unsigned char dc, r3; /* reserved */
66 unsigned char dd, ip; /* Input port register of block */
67 unsigned char de, ctg; /* Start counter timer of block */
68 unsigned char df, cts; /* Stop counter timer of block */
69 } r; /* Read access */
70 struct {
71 unsigned char d0, mra; /* Mode register 1/2 (a) */
72 unsigned char d1, csra; /* Clock select register (a) */
73 unsigned char d2, cra; /* Command register (a) */
74 unsigned char d3, thra; /* Transmit holding register (a) */
75 unsigned char d4, acr; /* Auxiliary control register of block */
76 unsigned char d5, imr; /* Interrupt mask register of block */
77 unsigned char d6, ctu; /* Counter timer upper register of block */
78 unsigned char d7, ctl; /* Counter timer lower register of block */
79 unsigned char d8, mrb; /* Mode register 1/2 (b) */
80 unsigned char d9, csrb; /* Clock select register (a) */
81 unsigned char da, crb; /* Command register (b) */
82 unsigned char db, thrb; /* Transmit holding register (b) */
83 unsigned char dc, r1; /* reserved */
84 unsigned char dd, opcr; /* Output port configuration register of block */
85 unsigned char de, r2; /* reserved */
86 unsigned char df, r3; /* reserved */
87 } w; /* Write access */
88 } u;
89} ;
90
91#define MR1_CHRL_5_BITS (0x0 << 0)
92#define MR1_CHRL_6_BITS (0x1 << 0)
93#define MR1_CHRL_7_BITS (0x2 << 0)
94#define MR1_CHRL_8_BITS (0x3 << 0)
95#define MR1_PARITY_EVEN (0x1 << 2)
96#define MR1_PARITY_ODD (0x0 << 2)
97#define MR1_PARITY_ON (0x0 << 3)
98#define MR1_PARITY_FORCE (0x1 << 3)
99#define MR1_PARITY_OFF (0x2 << 3)
100#define MR1_PARITY_SPECIAL (0x3 << 3)
101#define MR1_ERROR_CHAR (0x0 << 5)
102#define MR1_ERROR_BLOCK (0x1 << 5)
103#define MR1_RxINT_RxRDY (0x0 << 6)
104#define MR1_RxINT_FFULL (0x1 << 6)
105#define MR1_RxRTS_CONTROL_ON (0x1 << 7)
106#define MR1_RxRTS_CONTROL_OFF (0x0 << 7)
107
108#define MR2_STOP_BITS_LENGTH_1 (0x7 << 0)
109#define MR2_STOP_BITS_LENGTH_2 (0xF << 0)
110#define MR2_CTS_ENABLE_TX_ON (0x1 << 4)
111#define MR2_CTS_ENABLE_TX_OFF (0x0 << 4)
112#define MR2_TxRTS_CONTROL_ON (0x1 << 5)
113#define MR2_TxRTS_CONTROL_OFF (0x0 << 5)
114#define MR2_CH_MODE_NORMAL (0x0 << 6)
115#define MR2_CH_MODE_ECHO (0x1 << 6)
116#define MR2_CH_MODE_LOCAL (0x2 << 6)
117#define MR2_CH_MODE_REMOTE (0x3 << 6)
118
119#define CR_ENABLE_RX (0x1 << 0)
120#define CR_DISABLE_RX (0x1 << 1)
121#define CR_ENABLE_TX (0x1 << 2)
122#define CR_DISABLE_TX (0x1 << 3)
123#define CR_CMD_RESET_MR (0x1 << 4)
124#define CR_CMD_RESET_RX (0x2 << 4)
125#define CR_CMD_RESET_TX (0x3 << 4)
126#define CR_CMD_RESET_ERR_STATUS (0x4 << 4)
127#define CR_CMD_RESET_BREAK_CHANGE (0x5 << 4)
128#define CR_CMD_START_BREAK (0x6 << 4)
129#define CR_CMD_STOP_BREAK (0x7 << 4)
130#define CR_CMD_ASSERT_RTSN (0x8 << 4)
131#define CR_CMD_NEGATE_RTSN (0x9 << 4)
132#define CR_CMD_SET_TIMEOUT_MODE (0xA << 4)
133#define CR_CMD_DISABLE_TIMEOUT_MODE (0xC << 4)
134
135#define SR_RX_READY (0x1 << 0)
136#define SR_FIFO_FULL (0x1 << 1)
137#define SR_TX_READY (0x1 << 2)
138#define SR_TX_EMPTY (0x1 << 3)
139#define SR_OVERRUN_ERROR (0x1 << 4)
140#define SR_PARITY_ERROR (0x1 << 5)
141#define SR_FRAMING_ERROR (0x1 << 6)
142#define SR_RECEIVED_BREAK (0x1 << 7)
143
144#define SR_ERROR (0xF0)
145
146#define ACR_DELTA_IP0_IRQ_EN (0x1 << 0)
147#define ACR_DELTA_IP1_IRQ_EN (0x1 << 1)
148#define ACR_DELTA_IP2_IRQ_EN (0x1 << 2)
149#define ACR_DELTA_IP3_IRQ_EN (0x1 << 3)
150#define ACR_CT_Mask (0x7 << 4)
151#define ACR_CExt (0x0 << 4)
152#define ACR_CTxCA (0x1 << 4)
153#define ACR_CTxCB (0x2 << 4)
154#define ACR_CClk16 (0x3 << 4)
155#define ACR_TExt (0x4 << 4)
156#define ACR_TExt16 (0x5 << 4)
157#define ACR_TClk (0x6 << 4)
158#define ACR_TClk16 (0x7 << 4)
159#define ACR_BRG_SET1 (0x0 << 7)
160#define ACR_BRG_SET2 (0x1 << 7)
161
162#define TX_CLK_75 (0x0 << 0)
163#define TX_CLK_110 (0x1 << 0)
164#define TX_CLK_38400 (0x2 << 0)
165#define TX_CLK_150 (0x3 << 0)
166#define TX_CLK_300 (0x4 << 0)
167#define TX_CLK_600 (0x5 << 0)
168#define TX_CLK_1200 (0x6 << 0)
169#define TX_CLK_2000 (0x7 << 0)
170#define TX_CLK_2400 (0x8 << 0)
171#define TX_CLK_4800 (0x9 << 0)
172#define TX_CLK_1800 (0xA << 0)
173#define TX_CLK_9600 (0xB << 0)
174#define TX_CLK_19200 (0xC << 0)
175#define RX_CLK_75 (0x0 << 4)
176#define RX_CLK_110 (0x1 << 4)
177#define RX_CLK_38400 (0x2 << 4)
178#define RX_CLK_150 (0x3 << 4)
179#define RX_CLK_300 (0x4 << 4)
180#define RX_CLK_600 (0x5 << 4)
181#define RX_CLK_1200 (0x6 << 4)
182#define RX_CLK_2000 (0x7 << 4)
183#define RX_CLK_2400 (0x8 << 4)
184#define RX_CLK_4800 (0x9 << 4)
185#define RX_CLK_1800 (0xA << 4)
186#define RX_CLK_9600 (0xB << 4)
187#define RX_CLK_19200 (0xC << 4)
188
189#define OPCR_MPOa_RTSN (0x0 << 0)
190#define OPCR_MPOa_C_TO (0x1 << 0)
191#define OPCR_MPOa_TxC1X (0x2 << 0)
192#define OPCR_MPOa_TxC16X (0x3 << 0)
193#define OPCR_MPOa_RxC1X (0x4 << 0)
194#define OPCR_MPOa_RxC16X (0x5 << 0)
195#define OPCR_MPOa_TxRDY (0x6 << 0)
196#define OPCR_MPOa_RxRDY_FF (0x7 << 0)
197
198#define OPCR_MPOb_RTSN (0x0 << 4)
199#define OPCR_MPOb_C_TO (0x1 << 4)
200#define OPCR_MPOb_TxC1X (0x2 << 4)
201#define OPCR_MPOb_TxC16X (0x3 << 4)
202#define OPCR_MPOb_RxC1X (0x4 << 4)
203#define OPCR_MPOb_RxC16X (0x5 << 4)
204#define OPCR_MPOb_TxRDY (0x6 << 4)
205#define OPCR_MPOb_RxRDY_FF (0x7 << 4)
206
207#define OPCR_MPP_INPUT (0x0 << 7)
208#define OPCR_MPP_OUTPUT (0x1 << 7)
209
210#define IMR_TxRDY_A (0x1 << 0)
211#define IMR_RxRDY_FFULL_A (0x1 << 1)
212#define IMR_DELTA_BREAK_A (0x1 << 2)
213#define IMR_COUNTER_READY (0x1 << 3)
214#define IMR_TxRDY_B (0x1 << 4)
215#define IMR_RxRDY_FFULL_B (0x1 << 5)
216#define IMR_DELTA_BREAK_B (0x1 << 6)
217#define IMR_INPUT_PORT_CHANGE (0x1 << 7)
218
219#define ISR_TxRDY_A (0x1 << 0)
220#define ISR_RxRDY_FFULL_A (0x1 << 1)
221#define ISR_DELTA_BREAK_A (0x1 << 2)
222#define ISR_COUNTER_READY (0x1 << 3)
223#define ISR_TxRDY_B (0x1 << 4)
224#define ISR_RxRDY_FFULL_B (0x1 << 5)
225#define ISR_DELTA_BREAK_B (0x1 << 6)
226#define ISR_INPUT_PORT_CHANGE (0x1 << 7)
227
228#endif /* SCC2698_H_ */
diff --git a/drivers/staging/ipack/ipack.c b/drivers/staging/ipack/ipack.c
new file mode 100644
index 000000000000..2b4fa51bf167
--- /dev/null
+++ b/drivers/staging/ipack/ipack.c
@@ -0,0 +1,205 @@
1/*
2 * Industry-pack bus support functions.
3 *
4 * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
5 * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/module.h>
15#include <linux/mutex.h>
16#include <linux/slab.h>
17#include "ipack.h"
18
19#define to_ipack_dev(device) container_of(device, struct ipack_device, dev)
20#define to_ipack_driver(drv) container_of(drv, struct ipack_driver, driver)
21
22/* used when allocating bus numbers */
23#define IPACK_MAXBUS 64
24
25static DEFINE_MUTEX(ipack_mutex);
26
27struct ipack_busmap {
28 unsigned long busmap[IPACK_MAXBUS / (8*sizeof(unsigned long))];
29};
30static struct ipack_busmap busmap;
31
32static void ipack_device_release(struct device *dev)
33{
34 struct ipack_device *device = to_ipack_dev(dev);
35 kfree(device);
36}
37
38static int ipack_bus_match(struct device *device, struct device_driver *driver)
39{
40 int ret;
41 struct ipack_device *dev = to_ipack_dev(device);
42 struct ipack_driver *drv = to_ipack_driver(driver);
43
44 if ((!drv->ops) || (!drv->ops->match))
45 return -EINVAL;
46
47 ret = drv->ops->match(dev);
48 if (ret)
49 dev->driver = drv;
50
51 return 0;
52}
53
54static int ipack_bus_probe(struct device *device)
55{
56 struct ipack_device *dev = to_ipack_dev(device);
57
58 if (!dev->driver->ops->probe)
59 return -EINVAL;
60
61 return dev->driver->ops->probe(dev);
62}
63
64static int ipack_bus_remove(struct device *device)
65{
66 struct ipack_device *dev = to_ipack_dev(device);
67
68 if (!dev->driver->ops->remove)
69 return -EINVAL;
70
71 dev->driver->ops->remove(dev);
72 return 0;
73}
74
75static struct bus_type ipack_bus_type = {
76 .name = "ipack",
77 .probe = ipack_bus_probe,
78 .match = ipack_bus_match,
79 .remove = ipack_bus_remove,
80};
81
82static int ipack_assign_bus_number(void)
83{
84 int busnum;
85
86 mutex_lock(&ipack_mutex);
87 busnum = find_next_zero_bit(busmap.busmap, IPACK_MAXBUS, 1);
88
89 if (busnum >= IPACK_MAXBUS) {
90 pr_err("too many buses\n");
91 busnum = -1;
92 goto error_find_busnum;
93 }
94
95 set_bit(busnum, busmap.busmap);
96
97error_find_busnum:
98 mutex_unlock(&ipack_mutex);
99 return busnum;
100}
101
102struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
103 struct ipack_bus_ops *ops)
104{
105 int bus_nr;
106 struct ipack_bus_device *bus;
107
108 bus = kzalloc(sizeof(struct ipack_bus_device), GFP_KERNEL);
109 if (!bus)
110 return NULL;
111
112 bus_nr = ipack_assign_bus_number();
113 if (bus_nr < 0) {
114 kfree(bus);
115 return NULL;
116 }
117
118 bus->bus_nr = bus_nr;
119 bus->parent = parent;
120 bus->slots = slots;
121 bus->ops = ops;
122 return bus;
123}
124EXPORT_SYMBOL_GPL(ipack_bus_register);
125
126int ipack_bus_unregister(struct ipack_bus_device *bus)
127{
128 mutex_lock(&ipack_mutex);
129 clear_bit(bus->bus_nr, busmap.busmap);
130 mutex_unlock(&ipack_mutex);
131 kfree(bus);
132 return 0;
133}
134EXPORT_SYMBOL_GPL(ipack_bus_unregister);
135
136int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
137 char *name)
138{
139 edrv->driver.owner = owner;
140 edrv->driver.name = name;
141 edrv->driver.bus = &ipack_bus_type;
142 return driver_register(&edrv->driver);
143}
144EXPORT_SYMBOL_GPL(ipack_driver_register);
145
146void ipack_driver_unregister(struct ipack_driver *edrv)
147{
148 driver_unregister(&edrv->driver);
149}
150EXPORT_SYMBOL_GPL(ipack_driver_unregister);
151
152struct ipack_device *ipack_device_register(struct ipack_bus_device *bus,
153 int slot, int irqv)
154{
155 int ret;
156 struct ipack_device *dev;
157
158 dev = kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
159 if (!dev)
160 return NULL;
161
162 dev->dev.bus = &ipack_bus_type;
163 dev->dev.release = ipack_device_release;
164 dev->dev.parent = bus->parent;
165 dev->slot = slot;
166 dev->bus_nr = bus->bus_nr;
167 dev->irq = irqv;
168 dev->bus = bus;
169 dev_set_name(&dev->dev,
170 "ipack-dev.%u.%u", dev->bus_nr, dev->slot);
171
172 ret = device_register(&dev->dev);
173 if (ret < 0) {
174 pr_err("error registering the device.\n");
175 dev->driver->ops->remove(dev);
176 kfree(dev);
177 return NULL;
178 }
179
180 return dev;
181}
182EXPORT_SYMBOL_GPL(ipack_device_register);
183
184void ipack_device_unregister(struct ipack_device *dev)
185{
186 device_unregister(&dev->dev);
187}
188EXPORT_SYMBOL_GPL(ipack_device_unregister);
189
190static int __init ipack_init(void)
191{
192 return bus_register(&ipack_bus_type);
193}
194
195static void __exit ipack_exit(void)
196{
197 bus_unregister(&ipack_bus_type);
198}
199
200module_init(ipack_init);
201module_exit(ipack_exit);
202
203MODULE_AUTHOR("Samuel Iglesias Gonsalvez <siglesias@igalia.com>");
204MODULE_LICENSE("GPL");
205MODULE_DESCRIPTION("Industry-pack bus core");
diff --git a/drivers/staging/ipack/ipack.h b/drivers/staging/ipack/ipack.h
new file mode 100644
index 000000000000..8bc001e3ca4e
--- /dev/null
+++ b/drivers/staging/ipack/ipack.h
@@ -0,0 +1,183 @@
1/*
2 * Industry-pack bus.
3 *
4 * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
5 * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
10 */
11
12#include <linux/device.h>
13
14#define IPACK_IDPROM_OFFSET_I 0x01
15#define IPACK_IDPROM_OFFSET_P 0x03
16#define IPACK_IDPROM_OFFSET_A 0x05
17#define IPACK_IDPROM_OFFSET_C 0x07
18#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
19#define IPACK_IDPROM_OFFSET_MODEL 0x0B
20#define IPACK_IDPROM_OFFSET_REVISION 0x0D
21#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
22#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
23#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
24#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
25#define IPACK_IDPROM_OFFSET_CRC 0x17
26
27struct ipack_bus_ops;
28struct ipack_driver;
29
30enum ipack_space {
31 IPACK_IO_SPACE = 0,
32 IPACK_ID_SPACE = 1,
33 IPACK_MEM_SPACE = 2,
34};
35
36/**
37 * struct ipack_addr_space - Virtual address space mapped for a specified type.
38 *
39 * @address: virtual address
40 * @size: size of the mapped space
41 */
42struct ipack_addr_space {
43 void __iomem *address;
44 unsigned int size;
45};
46
47/**
48 * struct ipack_device
49 *
50 * @bus_nr: IP bus number where the device is plugged
51 * @slot: Slot where the device is plugged in the carrier board
52 * @irq: IRQ vector
53 * @driver: Pointer to the ipack_driver that manages the device
54 * @bus: ipack_bus_device where the device is plugged to.
55 * @id_space: Virtual address to ID space.
56 * @io_space: Virtual address to IO space.
57 * @mem_space: Virtual address to MEM space.
58 * @dev: device in kernel representation.
59 *
60 * Warning: Direct access to mapped memory is possible but the endianness
61 * is not the same with PCI carrier or VME carrier. The endianness is managed
62 * by the carrier board throught bus->ops.
63 */
64struct ipack_device {
65 unsigned int bus_nr;
66 unsigned int slot;
67 unsigned int irq;
68 struct ipack_driver *driver;
69 struct ipack_bus_device *bus;
70 struct ipack_addr_space id_space;
71 struct ipack_addr_space io_space;
72 struct ipack_addr_space mem_space;
73 struct device dev;
74};
75
76/**
77 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
78 *
79 * @match: Match function
80 * @probe: Probe function
81 * @remove: tell the driver that the carrier board wants to remove one device
82 */
83
84struct ipack_driver_ops {
85 int (*match) (struct ipack_device *dev);
86 int (*probe) (struct ipack_device *dev);
87 void (*remove) (struct ipack_device *dev);
88};
89
90/**
91 * struct ipack_driver -- Specific data to each ipack board driver
92 *
93 * @driver: Device driver kernel representation
94 * @ops: Mezzanine driver operations specific for the ipack bus.
95 */
96struct ipack_driver {
97 struct device_driver driver;
98 struct ipack_driver_ops *ops;
99};
100
101/**
102 * struct ipack_bus_ops - available operations on a bridge module
103 *
104 * @map_space: map IP address space
105 * @unmap_space: unmap IP address space
106 * @request_irq: request IRQ
107 * @free_irq: free IRQ
108 * @read8: read unsigned char
109 * @read16: read unsigned short
110 * @read32: read unsigned int
111 * @write8: read unsigned char
112 * @write16: read unsigned short
113 * @write32: read unsigned int
114 * @remove_device: tell the bridge module that the device has been removed
115 */
116struct ipack_bus_ops {
117 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
118 int (*unmap_space) (struct ipack_device *dev, int space);
119 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
120 int (*free_irq) (struct ipack_device *dev);
121 int (*read8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char *value);
122 int (*read16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short *value);
123 int (*read32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int *value);
124 int (*write8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char value);
125 int (*write16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short value);
126 int (*write32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int value);
127 int (*remove_device) (struct ipack_device *dev);
128};
129
130/**
131 * struct ipack_bus_device
132 *
133 * @dev: pointer to carrier device
134 * @slots: number of slots available
135 * @bus_nr: ipack bus number
136 * @ops: bus operations for the mezzanine drivers
137 */
138struct ipack_bus_device {
139 struct device *parent;
140 int slots;
141 int bus_nr;
142 struct ipack_bus_ops *ops;
143};
144
145/**
146 * ipack_bus_register -- register a new ipack bus
147 *
148 * @parent: pointer to the parent device, if any.
149 * @slots: number of slots available in the bus device.
150 * @ops: bus operations for the mezzanine drivers.
151 *
152 * The carrier board device should call this function to register itself as
153 * available bus device in ipack.
154 */
155struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
156 struct ipack_bus_ops *ops);
157
158/**
159 * ipack_bus_unregister -- unregister an ipack bus
160 */
161int ipack_bus_unregister(struct ipack_bus_device *bus);
162
163/**
164 * ipack_driver_register -- Register a new driver
165 *
166 * Called by a ipack driver to register itself as a driver
167 * that can manage ipack devices.
168 */
169int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name);
170void ipack_driver_unregister(struct ipack_driver *edrv);
171
172/**
173 * ipack_device_register -- register a new mezzanine device
174 *
175 * @bus: ipack bus device it is plugged to.
176 * @slot: slot position in the bus device.
177 * @irqv: IRQ vector for the mezzanine.
178 *
179 * Register a new ipack device (mezzanine device). The call is done by
180 * the carrier device driver.
181 */
182struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv);
183void ipack_device_unregister(struct ipack_device *dev);
diff --git a/drivers/staging/line6/config.h b/drivers/staging/line6/config.h
deleted file mode 100644
index f8a5149e3dad..000000000000
--- a/drivers/staging/line6/config.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Line6 Linux USB driver - 0.8.0
3 *
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#ifndef CONFIG_H
13#define CONFIG_H
14
15
16#ifdef CONFIG_USB_DEBUG
17#define DEBUG 1
18#endif
19
20
21/*
22 * Development tools.
23 */
24#define DO_DEBUG_MESSAGES 0
25#define DO_DUMP_URB_SEND DO_DEBUG_MESSAGES
26#define DO_DUMP_URB_RECEIVE DO_DEBUG_MESSAGES
27#define DO_DUMP_PCM_SEND 0
28#define DO_DUMP_PCM_RECEIVE 0
29#define DO_DUMP_MIDI_SEND DO_DEBUG_MESSAGES
30#define DO_DUMP_MIDI_RECEIVE DO_DEBUG_MESSAGES
31#define DO_DUMP_ANY (DO_DUMP_URB_SEND || DO_DUMP_URB_RECEIVE || \
32 DO_DUMP_PCM_SEND || DO_DUMP_PCM_RECEIVE || \
33 DO_DUMP_MIDI_SEND || DO_DUMP_MIDI_RECEIVE)
34#define CREATE_RAW_FILE 0
35
36#if DO_DEBUG_MESSAGES
37#define CHECKPOINT printk(KERN_INFO "line6usb: %s (%s:%d)\n", \
38 __func__, __FILE__, __LINE__)
39#endif
40
41#if DO_DEBUG_MESSAGES
42#define DEBUG_MESSAGES(x) (x)
43#else
44#define DEBUG_MESSAGES(x)
45#endif
46
47
48#endif
diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
index 2e602e192b07..4513f78f1127 100644
--- a/drivers/staging/line6/driver.c
+++ b/drivers/staging/line6/driver.c
@@ -92,15 +92,10 @@ const unsigned char line6_midi_id[] = {
92 Code to request version of POD, Variax interface 92 Code to request version of POD, Variax interface
93 (and maybe other devices). 93 (and maybe other devices).
94*/ 94*/
95static const char line6_request_version0[] = { 95static const char line6_request_version[] = {
96 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7 96 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
97}; 97};
98 98
99/*
100 Copy of version request code with GFP_KERNEL flag for use in URB.
101*/
102static const char *line6_request_version;
103
104struct usb_line6 *line6_devices[LINE6_MAX_DEVICES]; 99struct usb_line6 *line6_devices[LINE6_MAX_DEVICES];
105 100
106/** 101/**
@@ -336,8 +331,21 @@ int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
336*/ 331*/
337int line6_version_request_async(struct usb_line6 *line6) 332int line6_version_request_async(struct usb_line6 *line6)
338{ 333{
339 return line6_send_raw_message_async(line6, line6_request_version, 334 char *buffer;
340 sizeof(line6_request_version0)); 335 int retval;
336
337 buffer = kmalloc(sizeof(line6_request_version), GFP_ATOMIC);
338 if (buffer == NULL) {
339 dev_err(line6->ifcdev, "Out of memory");
340 return -ENOMEM;
341 }
342
343 memcpy(buffer, line6_request_version, sizeof(line6_request_version));
344
345 retval = line6_send_raw_message_async(line6, buffer,
346 sizeof(line6_request_version));
347 kfree(buffer);
348 return retval;
341} 349}
342 350
343/* 351/*
@@ -1292,70 +1300,7 @@ static struct usb_driver line6_driver = {
1292 .id_table = line6_id_table, 1300 .id_table = line6_id_table,
1293}; 1301};
1294 1302
1295/* 1303module_usb_driver(line6_driver);
1296 Module initialization.
1297*/
1298static int __init line6_init(void)
1299{
1300 int i, retval;
1301
1302 printk(KERN_INFO "%s driver version %s\n", DRIVER_NAME, DRIVER_VERSION);
1303
1304 for (i = LINE6_MAX_DEVICES; i--;)
1305 line6_devices[i] = NULL;
1306
1307 retval = usb_register(&line6_driver);
1308
1309 if (retval) {
1310 printk(KERN_ERR KBUILD_MODNAME
1311 ": usb_register failed. Error number %d\n", retval);
1312 return retval;
1313 }
1314
1315 line6_request_version = kmalloc(sizeof(line6_request_version0),
1316 GFP_KERNEL);
1317
1318 if (line6_request_version == NULL) {
1319 printk(KERN_ERR KBUILD_MODNAME ":Out of memory\n");
1320 return -ENOMEM;
1321 }
1322
1323 memcpy((char *)line6_request_version, line6_request_version0,
1324 sizeof(line6_request_version0));
1325
1326 return retval;
1327}
1328
1329/*
1330 Module cleanup.
1331*/
1332static void __exit line6_exit(void)
1333{
1334 int i;
1335 struct usb_line6 *line6;
1336 struct snd_line6_pcm *line6pcm;
1337
1338 /* stop all PCM channels */
1339 for (i = LINE6_MAX_DEVICES; i--;) {
1340 line6 = line6_devices[i];
1341
1342 if (line6 == NULL)
1343 continue;
1344
1345 line6pcm = line6->line6pcm;
1346
1347 if (line6pcm == NULL)
1348 continue;
1349
1350 line6_pcm_release(line6pcm, ~0);
1351 }
1352
1353 usb_deregister(&line6_driver);
1354 kfree(line6_request_version);
1355}
1356
1357module_init(line6_init);
1358module_exit(line6_exit);
1359 1304
1360MODULE_AUTHOR(DRIVER_AUTHOR); 1305MODULE_AUTHOR(DRIVER_AUTHOR);
1361MODULE_DESCRIPTION(DRIVER_DESC); 1306MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c
index 13d02939c3cb..50407294fbd4 100644
--- a/drivers/staging/line6/midi.c
+++ b/drivers/staging/line6/midi.c
@@ -406,7 +406,7 @@ int line6_init_midi(struct usb_line6 *line6)
406 406
407 line6midi->line6 = line6; 407 line6midi->line6 = line6;
408 408
409 switch(line6->product) { 409 switch (line6->product) {
410 case LINE6_DEVID_PODHD300: 410 case LINE6_DEVID_PODHD300:
411 case LINE6_DEVID_PODHD500: 411 case LINE6_DEVID_PODHD500:
412 line6midi->midi_mask_transmit = 1; 412 line6midi->midi_mask_transmit = 1;
diff --git a/drivers/staging/line6/midibuf.c b/drivers/staging/line6/midibuf.c
index 7b532e5ce8b4..836e8c847c52 100644
--- a/drivers/staging/line6/midibuf.c
+++ b/drivers/staging/line6/midibuf.c
@@ -64,7 +64,7 @@ int line6_midibuf_init(struct MidiBuffer *this, int size, int split)
64 64
65void line6_midibuf_status(struct MidiBuffer *this) 65void line6_midibuf_status(struct MidiBuffer *this)
66{ 66{
67 printk(KERN_DEBUG "midibuf size=%d split=%d pos_read=%d pos_write=%d " 67 pr_debug("midibuf size=%d split=%d pos_read=%d pos_write=%d "
68 "full=%d command_prev=%02x\n", this->size, this->split, 68 "full=%d command_prev=%02x\n", this->size, this->split,
69 this->pos_read, this->pos_write, this->full, this->command_prev); 69 this->pos_read, this->pos_write, this->full, this->command_prev);
70} 70}
diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c
index 90d2d4475cb4..5e319e3ce685 100644
--- a/drivers/staging/line6/pcm.c
+++ b/drivers/staging/line6/pcm.c
@@ -99,7 +99,7 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
99 unsigned long flags_new = flags_old | channels; 99 unsigned long flags_new = flags_old | channels;
100 unsigned long flags_final = flags_old; 100 unsigned long flags_final = flags_old;
101 int err = 0; 101 int err = 0;
102 102
103 line6pcm->prev_fbuf = NULL; 103 line6pcm->prev_fbuf = NULL;
104 104
105 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) { 105 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
diff --git a/drivers/staging/media/as102/as102_fe.c b/drivers/staging/media/as102/as102_fe.c
index 5917657b9d0f..9ce8c9daa2e7 100644
--- a/drivers/staging/media/as102/as102_fe.c
+++ b/drivers/staging/media/as102/as102_fe.c
@@ -17,8 +17,6 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20#include <linux/version.h>
21
22#include "as102_drv.h" 20#include "as102_drv.h"
23#include "as10x_types.h" 21#include "as10x_types.h"
24#include "as10x_cmd.h" 22#include "as10x_cmd.h"
diff --git a/drivers/staging/media/as102/as102_fw.c b/drivers/staging/media/as102/as102_fw.c
index 1075fb1df0d9..b9670ee41b4e 100644
--- a/drivers/staging/media/as102/as102_fw.c
+++ b/drivers/staging/media/as102/as102_fw.c
@@ -230,11 +230,8 @@ int as102_fw_upload(struct as10x_bus_adapter_t *bus_adap)
230 pr_info("%s: firmware: %s loaded with success\n", 230 pr_info("%s: firmware: %s loaded with success\n",
231 DRIVER_NAME, fw2); 231 DRIVER_NAME, fw2);
232error: 232error:
233 /* free data buffer */
234 kfree(cmd_buf); 233 kfree(cmd_buf);
235 /* release firmware if needed */ 234 release_firmware(firmware);
236 if (firmware != NULL)
237 release_firmware(firmware);
238 235
239 LEAVE(); 236 LEAVE();
240 return errno; 237 return errno;
diff --git a/drivers/staging/media/as102/as102_usb_drv.c b/drivers/staging/media/as102/as102_usb_drv.c
index 6875c88e7bec..aaf1bc2ad1b2 100644
--- a/drivers/staging/media/as102/as102_usb_drv.c
+++ b/drivers/staging/media/as102/as102_usb_drv.c
@@ -367,7 +367,7 @@ static int as102_usb_probe(struct usb_interface *intf,
367 ENTER(); 367 ENTER();
368 368
369 /* This should never actually happen */ 369 /* This should never actually happen */
370 if ((sizeof(as102_usb_id_table) / sizeof(struct usb_device_id)) != 370 if (ARRAY_SIZE(as102_usb_id_table) !=
371 (sizeof(as102_device_names) / sizeof(const char *))) { 371 (sizeof(as102_device_names) / sizeof(const char *))) {
372 pr_err("Device names table invalid size"); 372 pr_err("Device names table invalid size");
373 return -EINVAL; 373 return -EINVAL;
@@ -380,8 +380,7 @@ static int as102_usb_probe(struct usb_interface *intf,
380 } 380 }
381 381
382 /* Assign the user-friendly device name */ 382 /* Assign the user-friendly device name */
383 for (i = 0; i < (sizeof(as102_usb_id_table) / 383 for (i = 0; i < ARRAY_SIZE(as102_usb_id_table); i++) {
384 sizeof(struct usb_device_id)); i++) {
385 if (id == &as102_usb_id_table[i]) { 384 if (id == &as102_usb_id_table[i]) {
386 as102_dev->name = as102_device_names[i]; 385 as102_dev->name = as102_device_names[i];
387 as102_dev->elna_cfg = as102_elna_cfg[i]; 386 as102_dev->elna_cfg = as102_elna_cfg[i];
diff --git a/drivers/staging/media/as102/as102_usb_drv.h b/drivers/staging/media/as102/as102_usb_drv.h
index fc2884ab02a2..1ad1ec52b11e 100644
--- a/drivers/staging/media/as102/as102_usb_drv.h
+++ b/drivers/staging/media/as102/as102_usb_drv.h
@@ -17,8 +17,6 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20#include <linux/version.h>
21
22#ifndef _AS102_USB_DRV_H_ 20#ifndef _AS102_USB_DRV_H_
23#define _AS102_USB_DRV_H_ 21#define _AS102_USB_DRV_H_
24 22
diff --git a/drivers/staging/media/easycap/easycap_ioctl.c b/drivers/staging/media/easycap/easycap_ioctl.c
index 9413b37490c2..3cee3cd986d2 100644
--- a/drivers/staging/media/easycap/easycap_ioctl.c
+++ b/drivers/staging/media/easycap/easycap_ioctl.c
@@ -26,6 +26,7 @@
26/*****************************************************************************/ 26/*****************************************************************************/
27 27
28#include "easycap.h" 28#include "easycap.h"
29#include <linux/version.h>
29 30
30/*--------------------------------------------------------------------------*/ 31/*--------------------------------------------------------------------------*/
31/* 32/*
diff --git a/drivers/staging/media/go7007/README b/drivers/staging/media/go7007/README
index 48f447637817..aeba1324a9c5 100644
--- a/drivers/staging/media/go7007/README
+++ b/drivers/staging/media/go7007/README
@@ -6,6 +6,6 @@ Todo:
6 - testing? 6 - testing?
7 - handle churn in v4l layer. 7 - handle churn in v4l layer.
8 8
9Please send patchs to Greg Kroah-Hartman <greg@kroah.com> and Cc: Ross 9Please send patches to Greg Kroah-Hartman <greg@linuxfoundation.org> and Cc: Ross
10Cohen <rcohen@snurgle.org> as well. 10Cohen <rcohen@snurgle.org> as well.
11 11
diff --git a/drivers/staging/media/go7007/s2250-loader.c b/drivers/staging/media/go7007/s2250-loader.c
index 4e132519e253..7c5af4f289b6 100644
--- a/drivers/staging/media/go7007/s2250-loader.c
+++ b/drivers/staging/media/go7007/s2250-loader.c
@@ -160,31 +160,7 @@ static struct usb_driver s2250loader_driver = {
160 .id_table = s2250loader_ids, 160 .id_table = s2250loader_ids,
161}; 161};
162 162
163static int __init s2250loader_init(void) 163module_usb_driver(s2250loader_driver);
164{
165 int r;
166 unsigned i = 0;
167
168 for (i = 0; i < MAX_DEVICES; i++)
169 s2250_dev_table[i] = NULL;
170
171 r = usb_register(&s2250loader_driver);
172 if (r) {
173 printk(KERN_ERR "usb_register failed. Error number %d\n", r);
174 return -1;
175 }
176
177 printk(KERN_INFO "s2250loader_init: driver registered\n");
178 return 0;
179}
180module_init(s2250loader_init);
181
182static void __exit s2250loader_cleanup(void)
183{
184 printk(KERN_INFO "s2250loader_cleanup\n");
185 usb_deregister(&s2250loader_driver);
186}
187module_exit(s2250loader_cleanup);
188 164
189MODULE_AUTHOR(""); 165MODULE_AUTHOR("");
190MODULE_DESCRIPTION("firmware loader for Sensoray 2250/2251"); 166MODULE_DESCRIPTION("firmware loader for Sensoray 2250/2251");
diff --git a/drivers/staging/mei/TODO b/drivers/staging/mei/TODO
deleted file mode 100644
index fc266018355e..000000000000
--- a/drivers/staging/mei/TODO
+++ /dev/null
@@ -1,10 +0,0 @@
1TODO:
2 - Cleanup and split the timer function
3Upon Unstaging:
4 - move mei.h to include/linux/mei.h
5 - Documentation/ioctl/ioctl-number.txt
6 - move mei.txt under Documentation/mei/
7 - move mei-amt-version.c under Documentation/mei
8 - add hostprogs-y for mei-amt-version.c
9 - drop mei_version.h
10 - Updated MAINTAINERS
diff --git a/drivers/staging/net/Kconfig b/drivers/staging/net/Kconfig
new file mode 100644
index 000000000000..a64e56b1898a
--- /dev/null
+++ b/drivers/staging/net/Kconfig
@@ -0,0 +1,38 @@
1if NETDEVICES
2
3if WAN
4
5config PC300
6 tristate "Cyclades-PC300 support (RS-232/V.35, X.21, T1/E1 boards)"
7 depends on HDLC && PCI && BROKEN
8 ---help---
9 This driver is broken because of struct tty_driver change.
10
11 Driver for the Cyclades-PC300 synchronous communication boards.
12
13 These boards provide synchronous serial interfaces to your
14 Linux box (interfaces currently available are RS-232/V.35, X.21 and
15 T1/E1). If you wish to support Multilink PPP, please select the
16 option later and read the file README.mlppp provided by PC300
17 package.
18
19 To compile this as a module, choose M here: the module
20 will be called pc300.
21
22 If unsure, say N.
23
24config PC300_MLPPP
25 bool "Cyclades-PC300 MLPPP support"
26 depends on PC300 && PPP_MULTILINK && PPP_SYNC_TTY && HDLC_PPP
27 help
28 Multilink PPP over the PC300 synchronous communication boards.
29
30comment "Cyclades-PC300 MLPPP support is disabled."
31 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
32
33comment "Refer to the file README.mlppp, provided by PC300 package."
34 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
35
36endif # WAN
37
38endif # NETDEVICES
diff --git a/drivers/staging/net/Makefile b/drivers/staging/net/Makefile
new file mode 100644
index 000000000000..0799c43d5114
--- /dev/null
+++ b/drivers/staging/net/Makefile
@@ -0,0 +1,5 @@
1pc300-y := pc300_drv.o
2pc300-$(CONFIG_PC300_MLPPP) += pc300_tty.o
3pc300-objs := $(pc300-y)
4
5obj-$(CONFIG_PC300) += pc300.o
diff --git a/drivers/staging/net/TODO b/drivers/staging/net/TODO
new file mode 100644
index 000000000000..e3446f2ad7c7
--- /dev/null
+++ b/drivers/staging/net/TODO
@@ -0,0 +1,5 @@
1PC300
2The driver is very broken and cannot work with the current TTY layer. It is
3inevitable to convert it to the new TTY API.
4
5If no one steps in to adopt the driver, it will be removed in the 3.7 release.
diff --git a/drivers/net/wan/pc300-falc-lh.h b/drivers/staging/net/pc300-falc-lh.h
index 01ed23ca76c7..01ed23ca76c7 100644
--- a/drivers/net/wan/pc300-falc-lh.h
+++ b/drivers/staging/net/pc300-falc-lh.h
diff --git a/drivers/net/wan/pc300.h b/drivers/staging/net/pc300.h
index 2e4f84f6cad4..2e4f84f6cad4 100644
--- a/drivers/net/wan/pc300.h
+++ b/drivers/staging/net/pc300.h
diff --git a/drivers/net/wan/pc300_drv.c b/drivers/staging/net/pc300_drv.c
index cb0f8d932b0c..cb0f8d932b0c 100644
--- a/drivers/net/wan/pc300_drv.c
+++ b/drivers/staging/net/pc300_drv.c
diff --git a/drivers/net/wan/pc300_tty.c b/drivers/staging/net/pc300_tty.c
index 4709f4228561..4709f4228561 100644
--- a/drivers/net/wan/pc300_tty.c
+++ b/drivers/staging/net/pc300_tty.c
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index a4c17b0e10cf..ba6ed8f4e8a3 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -42,7 +42,7 @@
42 * enum nvec_event_size - The size of an event message 42 * enum nvec_event_size - The size of an event message
43 * @NVEC_2BYTES: The message has one command byte and one data byte 43 * @NVEC_2BYTES: The message has one command byte and one data byte
44 * @NVEC_3BYTES: The message has one command byte and two data bytes 44 * @NVEC_3BYTES: The message has one command byte and two data bytes
45 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and as 45 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and has
46 * up to as many bytes as the number in the count byte. The 46 * up to as many bytes as the number in the count byte. The
47 * maximum is 32 47 * maximum is 32
48 * 48 *
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index d91751f9ffe8..34afc16bc493 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -163,7 +163,7 @@ static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
163 /* 163 /*
164 * We received a packet with either an alignment error 164 * We received a packet with either an alignment error
165 * or a FCS error. This may be signalling that we are 165 * or a FCS error. This may be signalling that we are
166 * running 10Mbps with GMXX_RXX_FRM_CTL[PRE_CHK} 166 * running 10Mbps with GMXX_RXX_FRM_CTL[PRE_CHK]
167 * off. If this is the case we need to parse the 167 * off. If this is the case we need to parse the
168 * packet to determine if we can remove a non spec 168 * packet to determine if we can remove a non spec
169 * preamble and generate a correct packet. 169 * preamble and generate a correct packet.
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 5877b2c64e2a..5631dd9f8201 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -62,7 +62,7 @@
62 * You can define GET_SKBUFF_QOS() to override how the skbuff output 62 * You can define GET_SKBUFF_QOS() to override how the skbuff output
63 * function determines which output queue is used. The default 63 * function determines which output queue is used. The default
64 * implementation always uses the base queue for the port. If, for 64 * implementation always uses the base queue for the port. If, for
65 * example, you wanted to use the skb->priority fieid, define 65 * example, you wanted to use the skb->priority field, define
66 * GET_SKBUFF_QOS as: #define GET_SKBUFF_QOS(skb) ((skb)->priority) 66 * GET_SKBUFF_QOS as: #define GET_SKBUFF_QOS(skb) ((skb)->priority)
67 */ 67 */
68#ifndef GET_SKBUFF_QOS 68#ifndef GET_SKBUFF_QOS
@@ -165,8 +165,8 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
165#endif 165#endif
166 166
167 /* 167 /*
168 * Prefetch the private data structure. It is larger that one 168 * Prefetch the private data structure. It is larger than the
169 * cache line. 169 * one cache line.
170 */ 170 */
171 prefetch(priv); 171 prefetch(priv);
172 172
@@ -291,8 +291,8 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
291 * See if we can put this skb in the FPA pool. Any strange 291 * See if we can put this skb in the FPA pool. Any strange
292 * behavior from the Linux networking stack will most likely 292 * behavior from the Linux networking stack will most likely
293 * be caused by a bug in the following code. If some field is 293 * be caused by a bug in the following code. If some field is
294 * in use by the network stack and get carried over when a 294 * in use by the network stack and gets carried over when a
295 * buffer is reused, bad thing may happen. If in doubt and 295 * buffer is reused, bad things may happen. If in doubt and
296 * you dont need the absolute best performance, disable the 296 * you dont need the absolute best performance, disable the
297 * define REUSE_SKBUFFS_WITHOUT_FREE. The reuse of buffers has 297 * define REUSE_SKBUFFS_WITHOUT_FREE. The reuse of buffers has
298 * shown a 25% increase in performance under some loads. 298 * shown a 25% increase in performance under some loads.
diff --git a/drivers/staging/octeon/ethernet-util.h b/drivers/staging/octeon/ethernet-util.h
index 144fb99bf50c..2da5ce17ead0 100644
--- a/drivers/staging/octeon/ethernet-util.h
+++ b/drivers/staging/octeon/ethernet-util.h
@@ -38,7 +38,7 @@ static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr)
38} 38}
39 39
40/** 40/**
41 * INTERFACE - convert IPD port to locgical interface 41 * INTERFACE - convert IPD port to logical interface
42 * @ipd_port: Port to check 42 * @ipd_port: Port to check
43 * 43 *
44 * Returns Logical interface 44 * Returns Logical interface
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 60cba8194de3..18f7a790f73d 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -357,7 +357,7 @@ static void cvm_oct_common_set_multicast_list(struct net_device *dev)
357 /* Force accept multicast packets */ 357 /* Force accept multicast packets */
358 control.s.mcst = 2; 358 control.s.mcst = 2;
359 else 359 else
360 /* Force reject multicat packets */ 360 /* Force reject multicast packets */
361 control.s.mcst = 1; 361 control.s.mcst = 1;
362 362
363 if (dev->flags & IFF_PROMISC) 363 if (dev->flags & IFF_PROMISC)
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index 3d9199320d86..992275c0d87c 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -71,8 +71,8 @@ static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
71 71
72 ver = dcon_read(dcon, DCON_REG_ID); 72 ver = dcon_read(dcon, DCON_REG_ID);
73 if ((ver >> 8) != 0xDC) { 73 if ((ver >> 8) != 0xDC) {
74 printk(KERN_ERR "olpc-dcon: DCON ID not 0xDCxx: 0x%04x " 74 printk(KERN_ERR "olpc-dcon: DCON ID not 0xDCxx: 0x%04x instead.\n",
75 "instead.\n", ver); 75 ver);
76 rc = -ENXIO; 76 rc = -ENXIO;
77 goto err; 77 goto err;
78 } 78 }
@@ -134,10 +134,10 @@ static int dcon_bus_stabilize(struct dcon_priv *dcon, int is_powered_down)
134power_up: 134power_up:
135 if (is_powered_down) { 135 if (is_powered_down) {
136 x = 1; 136 x = 1;
137 x = olpc_ec_cmd(0x26, (unsigned char *) &x, 1, NULL, 0); 137 x = olpc_ec_cmd(0x26, (unsigned char *)&x, 1, NULL, 0);
138 if (x) { 138 if (x) {
139 printk(KERN_WARNING "olpc-dcon: unable to force dcon " 139 printk(KERN_WARNING "olpc-dcon: unable to force dcon to power up: %d!\n",
140 "to power up: %d!\n", x); 140 x);
141 return x; 141 return x;
142 } 142 }
143 msleep(10); /* we'll be conservative */ 143 msleep(10); /* we'll be conservative */
@@ -150,11 +150,10 @@ power_up:
150 x = dcon_read(dcon, DCON_REG_ID); 150 x = dcon_read(dcon, DCON_REG_ID);
151 } 151 }
152 if (x < 0) { 152 if (x < 0) {
153 printk(KERN_ERR "olpc-dcon: unable to stabilize dcon's " 153 printk(KERN_ERR "olpc-dcon: unable to stabilize dcon's smbus, reasserting power and praying.\n");
154 "smbus, reasserting power and praying.\n");
155 BUG_ON(olpc_board_at_least(olpc_board(0xc2))); 154 BUG_ON(olpc_board_at_least(olpc_board(0xc2)));
156 x = 0; 155 x = 0;
157 olpc_ec_cmd(0x26, (unsigned char *) &x, 1, NULL, 0); 156 olpc_ec_cmd(0x26, (unsigned char *)&x, 1, NULL, 0);
158 msleep(100); 157 msleep(100);
159 is_powered_down = 1; 158 is_powered_down = 1;
160 goto power_up; /* argh, stupid hardware.. */ 159 goto power_up; /* argh, stupid hardware.. */
@@ -220,10 +219,10 @@ static void dcon_sleep(struct dcon_priv *dcon, bool sleep)
220 219
221 if (sleep) { 220 if (sleep) {
222 x = 0; 221 x = 0;
223 x = olpc_ec_cmd(0x26, (unsigned char *) &x, 1, NULL, 0); 222 x = olpc_ec_cmd(0x26, (unsigned char *)&x, 1, NULL, 0);
224 if (x) 223 if (x)
225 printk(KERN_WARNING "olpc-dcon: unable to force dcon " 224 printk(KERN_WARNING "olpc-dcon: unable to force dcon to power down: %d!\n",
226 "to power down: %d!\n", x); 225 x);
227 else 226 else
228 dcon->asleep = sleep; 227 dcon->asleep = sleep;
229 } else { 228 } else {
@@ -232,8 +231,8 @@ static void dcon_sleep(struct dcon_priv *dcon, bool sleep)
232 dcon->disp_mode |= MODE_BL_ENABLE; 231 dcon->disp_mode |= MODE_BL_ENABLE;
233 x = dcon_bus_stabilize(dcon, 1); 232 x = dcon_bus_stabilize(dcon, 1);
234 if (x) 233 if (x)
235 printk(KERN_WARNING "olpc-dcon: unable to reinit dcon" 234 printk(KERN_WARNING "olpc-dcon: unable to reinit dcon hardware: %d!\n",
236 " hardware: %d!\n", x); 235 x);
237 else 236 else
238 dcon->asleep = sleep; 237 dcon->asleep = sleep;
239 238
@@ -304,7 +303,7 @@ static void dcon_source_switch(struct work_struct *work)
304 303
305 switch (source) { 304 switch (source) {
306 case DCON_SOURCE_CPU: 305 case DCON_SOURCE_CPU:
307 printk("dcon_source_switch to CPU\n"); 306 printk(KERN_INFO "dcon_source_switch to CPU\n");
308 /* Enable the scanline interrupt bit */ 307 /* Enable the scanline interrupt bit */
309 if (dcon_write(dcon, DCON_REG_MODE, 308 if (dcon_write(dcon, DCON_REG_MODE,
310 dcon->disp_mode | MODE_SCAN_INT)) 309 dcon->disp_mode | MODE_SCAN_INT))
@@ -599,7 +598,7 @@ static int dcon_fb_notifier(struct notifier_block *self,
599 struct fb_event *evdata = data; 598 struct fb_event *evdata = data;
600 struct dcon_priv *dcon = container_of(self, struct dcon_priv, 599 struct dcon_priv *dcon = container_of(self, struct dcon_priv,
601 fbevent_nb); 600 fbevent_nb);
602 int *blank = (int *) evdata->data; 601 int *blank = (int *)evdata->data;
603 if (((event != FB_EVENT_BLANK) && (event != FB_EVENT_CONBLANK)) || 602 if (((event != FB_EVENT_BLANK) && (event != FB_EVENT_CONBLANK)) ||
604 dcon->ignore_fb_events) 603 dcon->ignore_fb_events)
605 return 0; 604 return 0;
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
index cb6ce0cf92a0..c87fdfac4855 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
@@ -116,7 +116,7 @@ static int dcon_init_xo_1(struct dcon_priv *dcon)
116 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS); 116 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS);
117 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_STS); 117 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_STS);
118 118
119 /* FIXME: Clear the posiitive status as well, just to be sure */ 119 /* FIXME: Clear the positive status as well, just to be sure */
120 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_POSITIVE_EDGE_STS); 120 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_POSITIVE_EDGE_STS);
121 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_POSITIVE_EDGE_STS); 121 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_POSITIVE_EDGE_STS);
122 122
diff --git a/drivers/staging/omapdrm/Makefile b/drivers/staging/omapdrm/Makefile
index d9cdc120d122..1ca0e0016de4 100644
--- a/drivers/staging/omapdrm/Makefile
+++ b/drivers/staging/omapdrm/Makefile
@@ -13,6 +13,7 @@ omapdrm-y := omap_drv.o \
13 omap_fb.o \ 13 omap_fb.o \
14 omap_fbdev.o \ 14 omap_fbdev.o \
15 omap_gem.o \ 15 omap_gem.o \
16 omap_gem_dmabuf.o \
16 omap_dmm_tiler.o \ 17 omap_dmm_tiler.o \
17 tcm-sita.o 18 tcm-sita.o
18 19
diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c
index 1ecb6a73d790..9d83060e753a 100644
--- a/drivers/staging/omapdrm/omap_dmm_tiler.c
+++ b/drivers/staging/omapdrm/omap_dmm_tiler.c
@@ -347,7 +347,7 @@ struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt, uint16_t w,
347 ret = tcm_reserve_2d(containers[fmt], w, h, align, &block->area); 347 ret = tcm_reserve_2d(containers[fmt], w, h, align, &block->area);
348 if (ret) { 348 if (ret) {
349 kfree(block); 349 kfree(block);
350 return 0; 350 return ERR_PTR(-ENOMEM);
351 } 351 }
352 352
353 /* add to allocation list */ 353 /* add to allocation list */
@@ -371,7 +371,7 @@ struct tiler_block *tiler_reserve_1d(size_t size)
371 if (tcm_reserve_1d(containers[TILFMT_PAGE], num_pages, 371 if (tcm_reserve_1d(containers[TILFMT_PAGE], num_pages,
372 &block->area)) { 372 &block->area)) {
373 kfree(block); 373 kfree(block);
374 return 0; 374 return ERR_PTR(-ENOMEM);
375 } 375 }
376 376
377 spin_lock(&omap_dmm->list_lock); 377 spin_lock(&omap_dmm->list_lock);
diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
index 620b8d54223d..0d2acca376ca 100644
--- a/drivers/staging/omapdrm/omap_drv.c
+++ b/drivers/staging/omapdrm/omap_drv.c
@@ -746,7 +746,7 @@ static const struct file_operations omapdriver_fops = {
746 746
747static struct drm_driver omap_drm_driver = { 747static struct drm_driver omap_drm_driver = {
748 .driver_features = 748 .driver_features =
749 DRIVER_HAVE_IRQ | DRIVER_MODESET | DRIVER_GEM, 749 DRIVER_HAVE_IRQ | DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
750 .load = dev_load, 750 .load = dev_load,
751 .unload = dev_unload, 751 .unload = dev_unload,
752 .open = dev_open, 752 .open = dev_open,
@@ -766,6 +766,10 @@ static struct drm_driver omap_drm_driver = {
766 .debugfs_init = omap_debugfs_init, 766 .debugfs_init = omap_debugfs_init,
767 .debugfs_cleanup = omap_debugfs_cleanup, 767 .debugfs_cleanup = omap_debugfs_cleanup,
768#endif 768#endif
769 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
770 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
771 .gem_prime_export = omap_gem_prime_export,
772 .gem_prime_import = omap_gem_prime_import,
769 .gem_init_object = omap_gem_init_object, 773 .gem_init_object = omap_gem_init_object,
770 .gem_free_object = omap_gem_free_object, 774 .gem_free_object = omap_gem_free_object,
771 .gem_vm_ops = &omap_gem_vm_ops, 775 .gem_vm_ops = &omap_gem_vm_ops,
diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h
index b7e0f0773003..f238d574da0c 100644
--- a/drivers/staging/omapdrm/omap_drv.h
+++ b/drivers/staging/omapdrm/omap_drv.h
@@ -138,6 +138,8 @@ int omap_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
138int omap_gem_dumb_create(struct drm_file *file, struct drm_device *dev, 138int omap_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
139 struct drm_mode_create_dumb *args); 139 struct drm_mode_create_dumb *args);
140int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma); 140int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma);
141int omap_gem_mmap_obj(struct drm_gem_object *obj,
142 struct vm_area_struct *vma);
141int omap_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); 143int omap_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
142int omap_gem_op_start(struct drm_gem_object *obj, enum omap_gem_op op); 144int omap_gem_op_start(struct drm_gem_object *obj, enum omap_gem_op op);
143int omap_gem_op_finish(struct drm_gem_object *obj, enum omap_gem_op op); 145int omap_gem_op_finish(struct drm_gem_object *obj, enum omap_gem_op op);
@@ -145,12 +147,24 @@ int omap_gem_op_sync(struct drm_gem_object *obj, enum omap_gem_op op);
145int omap_gem_op_async(struct drm_gem_object *obj, enum omap_gem_op op, 147int omap_gem_op_async(struct drm_gem_object *obj, enum omap_gem_op op,
146 void (*fxn)(void *arg), void *arg); 148 void (*fxn)(void *arg), void *arg);
147int omap_gem_roll(struct drm_gem_object *obj, uint32_t roll); 149int omap_gem_roll(struct drm_gem_object *obj, uint32_t roll);
150void omap_gem_cpu_sync(struct drm_gem_object *obj, int pgoff);
151void omap_gem_dma_sync(struct drm_gem_object *obj,
152 enum dma_data_direction dir);
148int omap_gem_get_paddr(struct drm_gem_object *obj, 153int omap_gem_get_paddr(struct drm_gem_object *obj,
149 dma_addr_t *paddr, bool remap); 154 dma_addr_t *paddr, bool remap);
150int omap_gem_put_paddr(struct drm_gem_object *obj); 155int omap_gem_put_paddr(struct drm_gem_object *obj);
156int omap_gem_get_pages(struct drm_gem_object *obj, struct page ***pages,
157 bool remap);
158int omap_gem_put_pages(struct drm_gem_object *obj);
159uint32_t omap_gem_flags(struct drm_gem_object *obj);
151uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj); 160uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj);
152size_t omap_gem_mmap_size(struct drm_gem_object *obj); 161size_t omap_gem_mmap_size(struct drm_gem_object *obj);
153 162
163struct dma_buf * omap_gem_prime_export(struct drm_device *dev,
164 struct drm_gem_object *obj, int flags);
165struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev,
166 struct dma_buf *buffer);
167
154static inline int align_pitch(int pitch, int width, int bpp) 168static inline int align_pitch(int pitch, int width, int bpp)
155{ 169{
156 int bytespp = (bpp + 7) / 8; 170 int bytespp = (bpp + 7) / 8;
diff --git a/drivers/staging/omapdrm/omap_fb.c b/drivers/staging/omapdrm/omap_fb.c
index 04b235b6724a..74260f043ab1 100644
--- a/drivers/staging/omapdrm/omap_fb.c
+++ b/drivers/staging/omapdrm/omap_fb.c
@@ -167,7 +167,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, int x, int y,
167} 167}
168 168
169/* Call for unpin 'a' (if not NULL), and pin 'b' (if not NULL). Although 169/* Call for unpin 'a' (if not NULL), and pin 'b' (if not NULL). Although
170 * buffers to unpin are just just pushed to the unpin fifo so that the 170 * buffers to unpin are just pushed to the unpin fifo so that the
171 * caller can defer unpin until vblank. 171 * caller can defer unpin until vblank.
172 * 172 *
173 * Note if this fails (ie. something went very wrong!), all buffers are 173 * Note if this fails (ie. something went very wrong!), all buffers are
@@ -197,8 +197,11 @@ int omap_framebuffer_replace(struct drm_framebuffer *a,
197 pa->paddr = 0; 197 pa->paddr = 0;
198 } 198 }
199 199
200 if (pb && !ret) 200 if (pb && !ret) {
201 ret = omap_gem_get_paddr(pb->bo, &pb->paddr, true); 201 ret = omap_gem_get_paddr(pb->bo, &pb->paddr, true);
202 if (!ret)
203 omap_gem_dma_sync(pb->bo, DMA_TO_DEVICE);
204 }
202 } 205 }
203 206
204 if (ret) { 207 if (ret) {
diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c
index 921f058cc6a4..3a0d035a9e03 100644
--- a/drivers/staging/omapdrm/omap_gem.c
+++ b/drivers/staging/omapdrm/omap_gem.c
@@ -207,13 +207,27 @@ static inline bool is_shmem(struct drm_gem_object *obj)
207 return obj->filp != NULL; 207 return obj->filp != NULL;
208} 208}
209 209
210/**
211 * shmem buffers that are mapped cached can simulate coherency via using
212 * page faulting to keep track of dirty pages
213 */
214static inline bool is_cached_coherent(struct drm_gem_object *obj)
215{
216 struct omap_gem_object *omap_obj = to_omap_bo(obj);
217 return is_shmem(obj) &&
218 ((omap_obj->flags & OMAP_BO_CACHE_MASK) == OMAP_BO_CACHED);
219}
220
210static DEFINE_SPINLOCK(sync_lock); 221static DEFINE_SPINLOCK(sync_lock);
211 222
212/** ensure backing pages are allocated */ 223/** ensure backing pages are allocated */
213static int omap_gem_attach_pages(struct drm_gem_object *obj) 224static int omap_gem_attach_pages(struct drm_gem_object *obj)
214{ 225{
226 struct drm_device *dev = obj->dev;
215 struct omap_gem_object *omap_obj = to_omap_bo(obj); 227 struct omap_gem_object *omap_obj = to_omap_bo(obj);
216 struct page **pages; 228 struct page **pages;
229 int i, npages = obj->size >> PAGE_SHIFT;
230 dma_addr_t *addrs;
217 231
218 WARN_ON(omap_obj->pages); 232 WARN_ON(omap_obj->pages);
219 233
@@ -231,16 +245,18 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
231 * DSS, GPU, etc. are not cache coherent: 245 * DSS, GPU, etc. are not cache coherent:
232 */ 246 */
233 if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) { 247 if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) {
234 int i, npages = obj->size >> PAGE_SHIFT; 248 addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL);
235 dma_addr_t *addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL);
236 for (i = 0; i < npages; i++) { 249 for (i = 0; i < npages; i++) {
237 addrs[i] = dma_map_page(obj->dev->dev, pages[i], 250 addrs[i] = dma_map_page(dev->dev, pages[i],
238 0, PAGE_SIZE, DMA_BIDIRECTIONAL); 251 0, PAGE_SIZE, DMA_BIDIRECTIONAL);
239 } 252 }
240 omap_obj->addrs = addrs; 253 } else {
254 addrs = kzalloc(npages * sizeof(addrs), GFP_KERNEL);
241 } 255 }
242 256
257 omap_obj->addrs = addrs;
243 omap_obj->pages = pages; 258 omap_obj->pages = pages;
259
244 return 0; 260 return 0;
245} 261}
246 262
@@ -258,14 +274,21 @@ static void omap_gem_detach_pages(struct drm_gem_object *obj)
258 dma_unmap_page(obj->dev->dev, omap_obj->addrs[i], 274 dma_unmap_page(obj->dev->dev, omap_obj->addrs[i],
259 PAGE_SIZE, DMA_BIDIRECTIONAL); 275 PAGE_SIZE, DMA_BIDIRECTIONAL);
260 } 276 }
261 kfree(omap_obj->addrs);
262 omap_obj->addrs = NULL;
263 } 277 }
264 278
279 kfree(omap_obj->addrs);
280 omap_obj->addrs = NULL;
281
265 _drm_gem_put_pages(obj, omap_obj->pages, true, false); 282 _drm_gem_put_pages(obj, omap_obj->pages, true, false);
266 omap_obj->pages = NULL; 283 omap_obj->pages = NULL;
267} 284}
268 285
286/* get buffer flags */
287uint32_t omap_gem_flags(struct drm_gem_object *obj)
288{
289 return to_omap_bo(obj)->flags;
290}
291
269/** get mmap offset */ 292/** get mmap offset */
270static uint64_t mmap_offset(struct drm_gem_object *obj) 293static uint64_t mmap_offset(struct drm_gem_object *obj)
271{ 294{
@@ -330,6 +353,7 @@ static int fault_1d(struct drm_gem_object *obj,
330 vma->vm_start) >> PAGE_SHIFT; 353 vma->vm_start) >> PAGE_SHIFT;
331 354
332 if (omap_obj->pages) { 355 if (omap_obj->pages) {
356 omap_gem_cpu_sync(obj, pgoff);
333 pfn = page_to_pfn(omap_obj->pages[pgoff]); 357 pfn = page_to_pfn(omap_obj->pages[pgoff]);
334 } else { 358 } else {
335 BUG_ON(!(omap_obj->flags & OMAP_BO_DMA)); 359 BUG_ON(!(omap_obj->flags & OMAP_BO_DMA));
@@ -504,7 +528,6 @@ fail:
504/** We override mainly to fix up some of the vm mapping flags.. */ 528/** We override mainly to fix up some of the vm mapping flags.. */
505int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma) 529int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma)
506{ 530{
507 struct omap_gem_object *omap_obj;
508 int ret; 531 int ret;
509 532
510 ret = drm_gem_mmap(filp, vma); 533 ret = drm_gem_mmap(filp, vma);
@@ -513,8 +536,13 @@ int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma)
513 return ret; 536 return ret;
514 } 537 }
515 538
516 /* after drm_gem_mmap(), it is safe to access the obj */ 539 return omap_gem_mmap_obj(vma->vm_private_data, vma);
517 omap_obj = to_omap_bo(vma->vm_private_data); 540}
541
542int omap_gem_mmap_obj(struct drm_gem_object *obj,
543 struct vm_area_struct *vma)
544{
545 struct omap_gem_object *omap_obj = to_omap_bo(obj);
518 546
519 vma->vm_flags &= ~VM_PFNMAP; 547 vma->vm_flags &= ~VM_PFNMAP;
520 vma->vm_flags |= VM_MIXEDMAP; 548 vma->vm_flags |= VM_MIXEDMAP;
@@ -524,12 +552,31 @@ int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma)
524 } else if (omap_obj->flags & OMAP_BO_UNCACHED) { 552 } else if (omap_obj->flags & OMAP_BO_UNCACHED) {
525 vma->vm_page_prot = pgprot_noncached(vm_get_page_prot(vma->vm_flags)); 553 vma->vm_page_prot = pgprot_noncached(vm_get_page_prot(vma->vm_flags));
526 } else { 554 } else {
555 /*
556 * We do have some private objects, at least for scanout buffers
557 * on hardware without DMM/TILER. But these are allocated write-
558 * combine
559 */
560 if (WARN_ON(!obj->filp))
561 return -EINVAL;
562
563 /*
564 * Shunt off cached objs to shmem file so they have their own
565 * address_space (so unmap_mapping_range does what we want,
566 * in particular in the case of mmap'd dmabufs)
567 */
568 fput(vma->vm_file);
569 get_file(obj->filp);
570 vma->vm_pgoff = 0;
571 vma->vm_file = obj->filp;
572
527 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); 573 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
528 } 574 }
529 575
530 return ret; 576 return 0;
531} 577}
532 578
579
533/** 580/**
534 * omap_gem_dumb_create - create a dumb buffer 581 * omap_gem_dumb_create - create a dumb buffer
535 * @drm_file: our client file 582 * @drm_file: our client file
@@ -639,6 +686,48 @@ fail:
639 return ret; 686 return ret;
640} 687}
641 688
689/* Sync the buffer for CPU access.. note pages should already be
690 * attached, ie. omap_gem_get_pages()
691 */
692void omap_gem_cpu_sync(struct drm_gem_object *obj, int pgoff)
693{
694 struct drm_device *dev = obj->dev;
695 struct omap_gem_object *omap_obj = to_omap_bo(obj);
696
697 if (is_cached_coherent(obj) && omap_obj->addrs[pgoff]) {
698 dma_unmap_page(dev->dev, omap_obj->addrs[pgoff],
699 PAGE_SIZE, DMA_BIDIRECTIONAL);
700 omap_obj->addrs[pgoff] = 0;
701 }
702}
703
704/* sync the buffer for DMA access */
705void omap_gem_dma_sync(struct drm_gem_object *obj,
706 enum dma_data_direction dir)
707{
708 struct drm_device *dev = obj->dev;
709 struct omap_gem_object *omap_obj = to_omap_bo(obj);
710
711 if (is_cached_coherent(obj)) {
712 int i, npages = obj->size >> PAGE_SHIFT;
713 struct page **pages = omap_obj->pages;
714 bool dirty = false;
715
716 for (i = 0; i < npages; i++) {
717 if (!omap_obj->addrs[i]) {
718 omap_obj->addrs[i] = dma_map_page(dev->dev, pages[i], 0,
719 PAGE_SIZE, DMA_BIDIRECTIONAL);
720 dirty = true;
721 }
722 }
723
724 if (dirty) {
725 unmap_mapping_range(obj->filp->f_mapping, 0,
726 omap_gem_mmap_size(obj), 1);
727 }
728 }
729}
730
642/* Get physical address for DMA.. if 'remap' is true, and the buffer is not 731/* Get physical address for DMA.. if 'remap' is true, and the buffer is not
643 * already contiguous, remap it to pin in physically contiguous memory.. (ie. 732 * already contiguous, remap it to pin in physically contiguous memory.. (ie.
644 * map in TILER) 733 * map in TILER)
@@ -703,6 +792,7 @@ int omap_gem_get_paddr(struct drm_gem_object *obj,
703 *paddr = omap_obj->paddr; 792 *paddr = omap_obj->paddr;
704 } else { 793 } else {
705 ret = -EINVAL; 794 ret = -EINVAL;
795 goto fail;
706 } 796 }
707 797
708fail: 798fail:
@@ -764,9 +854,27 @@ static int get_pages(struct drm_gem_object *obj, struct page ***pages)
764 return 0; 854 return 0;
765} 855}
766 856
767int omap_gem_get_pages(struct drm_gem_object *obj, struct page ***pages) 857/* if !remap, and we don't have pages backing, then fail, rather than
858 * increasing the pin count (which we don't really do yet anyways,
859 * because we don't support swapping pages back out). And 'remap'
860 * might not be quite the right name, but I wanted to keep it working
861 * similarly to omap_gem_get_paddr(). Note though that mutex is not
862 * aquired if !remap (because this can be called in atomic ctxt),
863 * but probably omap_gem_get_paddr() should be changed to work in the
864 * same way. If !remap, a matching omap_gem_put_pages() call is not
865 * required (and should not be made).
866 */
867int omap_gem_get_pages(struct drm_gem_object *obj, struct page ***pages,
868 bool remap)
768{ 869{
769 int ret; 870 int ret;
871 if (!remap) {
872 struct omap_gem_object *omap_obj = to_omap_bo(obj);
873 if (!omap_obj->pages)
874 return -ENOMEM;
875 *pages = omap_obj->pages;
876 return 0;
877 }
770 mutex_lock(&obj->dev->struct_mutex); 878 mutex_lock(&obj->dev->struct_mutex);
771 ret = get_pages(obj, pages); 879 ret = get_pages(obj, pages);
772 mutex_unlock(&obj->dev->struct_mutex); 880 mutex_unlock(&obj->dev->struct_mutex);
diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c
new file mode 100644
index 000000000000..42728e0cc194
--- /dev/null
+++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c
@@ -0,0 +1,220 @@
1/*
2 * drivers/staging/omapdrm/omap_gem_dmabuf.c
3 *
4 * Copyright (C) 2011 Texas Instruments
5 * Author: Rob Clark <rob.clark@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * 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, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "omap_drv.h"
21
22#include <linux/dma-buf.h>
23
24static struct sg_table *omap_gem_map_dma_buf(
25 struct dma_buf_attachment *attachment,
26 enum dma_data_direction dir)
27{
28 struct drm_gem_object *obj = attachment->dmabuf->priv;
29 struct sg_table *sg;
30 dma_addr_t paddr;
31 int ret;
32
33 sg = kzalloc(sizeof(*sg), GFP_KERNEL);
34 if (!sg)
35 return ERR_PTR(-ENOMEM);
36
37 /* camera, etc, need physically contiguous.. but we need a
38 * better way to know this..
39 */
40 ret = omap_gem_get_paddr(obj, &paddr, true);
41 if (ret)
42 goto out;
43
44 ret = sg_alloc_table(sg, 1, GFP_KERNEL);
45 if (ret)
46 goto out;
47
48 sg_init_table(sg->sgl, 1);
49 sg_dma_len(sg->sgl) = obj->size;
50 sg_set_page(sg->sgl, pfn_to_page(PFN_DOWN(paddr)), obj->size, 0);
51 sg_dma_address(sg->sgl) = paddr;
52
53 /* this should be after _get_paddr() to ensure we have pages attached */
54 omap_gem_dma_sync(obj, dir);
55
56out:
57 if (ret)
58 return ERR_PTR(ret);
59 return sg;
60}
61
62static void omap_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
63 struct sg_table *sg, enum dma_data_direction dir)
64{
65 struct drm_gem_object *obj = attachment->dmabuf->priv;
66 omap_gem_put_paddr(obj);
67 sg_free_table(sg);
68 kfree(sg);
69}
70
71static void omap_gem_dmabuf_release(struct dma_buf *buffer)
72{
73 struct drm_gem_object *obj = buffer->priv;
74 /* release reference that was taken when dmabuf was exported
75 * in omap_gem_prime_set()..
76 */
77 drm_gem_object_unreference_unlocked(obj);
78}
79
80
81static int omap_gem_dmabuf_begin_cpu_access(struct dma_buf *buffer,
82 size_t start, size_t len, enum dma_data_direction dir)
83{
84 struct drm_gem_object *obj = buffer->priv;
85 struct page **pages;
86 if (omap_gem_flags(obj) & OMAP_BO_TILED) {
87 /* TODO we would need to pin at least part of the buffer to
88 * get de-tiled view. For now just reject it.
89 */
90 return -ENOMEM;
91 }
92 /* make sure we have the pages: */
93 return omap_gem_get_pages(obj, &pages, true);
94}
95
96static void omap_gem_dmabuf_end_cpu_access(struct dma_buf *buffer,
97 size_t start, size_t len, enum dma_data_direction dir)
98{
99 struct drm_gem_object *obj = buffer->priv;
100 omap_gem_put_pages(obj);
101}
102
103
104static void *omap_gem_dmabuf_kmap_atomic(struct dma_buf *buffer,
105 unsigned long page_num)
106{
107 struct drm_gem_object *obj = buffer->priv;
108 struct page **pages;
109 omap_gem_get_pages(obj, &pages, false);
110 omap_gem_cpu_sync(obj, page_num);
111 return kmap_atomic(pages[page_num]);
112}
113
114static void omap_gem_dmabuf_kunmap_atomic(struct dma_buf *buffer,
115 unsigned long page_num, void *addr)
116{
117 kunmap_atomic(addr);
118}
119
120static void *omap_gem_dmabuf_kmap(struct dma_buf *buffer,
121 unsigned long page_num)
122{
123 struct drm_gem_object *obj = buffer->priv;
124 struct page **pages;
125 omap_gem_get_pages(obj, &pages, false);
126 omap_gem_cpu_sync(obj, page_num);
127 return kmap(pages[page_num]);
128}
129
130static void omap_gem_dmabuf_kunmap(struct dma_buf *buffer,
131 unsigned long page_num, void *addr)
132{
133 struct drm_gem_object *obj = buffer->priv;
134 struct page **pages;
135 omap_gem_get_pages(obj, &pages, false);
136 kunmap(pages[page_num]);
137}
138
139/*
140 * TODO maybe we can split up drm_gem_mmap to avoid duplicating
141 * some here.. or at least have a drm_dmabuf_mmap helper.
142 */
143static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
144 struct vm_area_struct *vma)
145{
146 struct drm_gem_object *obj = buffer->priv;
147 int ret = 0;
148
149 if (WARN_ON(!obj->filp))
150 return -EINVAL;
151
152 /* Check for valid size. */
153 if (omap_gem_mmap_size(obj) < vma->vm_end - vma->vm_start) {
154 ret = -EINVAL;
155 goto out_unlock;
156 }
157
158 if (!obj->dev->driver->gem_vm_ops) {
159 ret = -EINVAL;
160 goto out_unlock;
161 }
162
163 vma->vm_flags |= VM_RESERVED | VM_IO | VM_PFNMAP | VM_DONTEXPAND;
164 vma->vm_ops = obj->dev->driver->gem_vm_ops;
165 vma->vm_private_data = obj;
166 vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
167
168 /* Take a ref for this mapping of the object, so that the fault
169 * handler can dereference the mmap offset's pointer to the object.
170 * This reference is cleaned up by the corresponding vm_close
171 * (which should happen whether the vma was created by this call, or
172 * by a vm_open due to mremap or partial unmap or whatever).
173 */
174 vma->vm_ops->open(vma);
175
176out_unlock:
177
178 return omap_gem_mmap_obj(obj, vma);
179}
180
181struct dma_buf_ops omap_dmabuf_ops = {
182 .map_dma_buf = omap_gem_map_dma_buf,
183 .unmap_dma_buf = omap_gem_unmap_dma_buf,
184 .release = omap_gem_dmabuf_release,
185 .begin_cpu_access = omap_gem_dmabuf_begin_cpu_access,
186 .end_cpu_access = omap_gem_dmabuf_end_cpu_access,
187 .kmap_atomic = omap_gem_dmabuf_kmap_atomic,
188 .kunmap_atomic = omap_gem_dmabuf_kunmap_atomic,
189 .kmap = omap_gem_dmabuf_kmap,
190 .kunmap = omap_gem_dmabuf_kunmap,
191 .mmap = omap_gem_dmabuf_mmap,
192};
193
194struct dma_buf * omap_gem_prime_export(struct drm_device *dev,
195 struct drm_gem_object *obj, int flags)
196{
197 return dma_buf_export(obj, &omap_dmabuf_ops, obj->size, 0600);
198}
199
200struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev,
201 struct dma_buf *buffer)
202{
203 struct drm_gem_object *obj;
204
205 /* is this one of own objects? */
206 if (buffer->ops == &omap_dmabuf_ops) {
207 obj = buffer->priv;
208 /* is it from our device? */
209 if (obj->dev == dev) {
210 drm_gem_object_reference(obj);
211 return obj;
212 }
213 }
214
215 /*
216 * TODO add support for importing buffers from other devices..
217 * for now we don't need this but would be nice to add eventually
218 */
219 return ERR_PTR(-EINVAL);
220}
diff --git a/drivers/staging/omapdrm/tcm-sita.c b/drivers/staging/omapdrm/tcm-sita.c
index 10d5ac3dae4b..efb609510540 100644
--- a/drivers/staging/omapdrm/tcm-sita.c
+++ b/drivers/staging/omapdrm/tcm-sita.c
@@ -200,7 +200,7 @@ static s32 sita_reserve_1d(struct tcm *tcm, u32 num_slots,
200 * 200 *
201 * @param w width 201 * @param w width
202 * @param h height 202 * @param h height
203 * @param area pointer to the area that will be populated with the reesrved 203 * @param area pointer to the area that will be populated with the reserved
204 * area 204 * area
205 * 205 *
206 * @return 0 on success, non-0 error value on failure. 206 * @return 0 on success, non-0 error value on failure.
diff --git a/drivers/staging/ozwpan/README b/drivers/staging/ozwpan/README
index bb1a69b94541..7c055ec99544 100644
--- a/drivers/staging/ozwpan/README
+++ b/drivers/staging/ozwpan/README
@@ -9,7 +9,7 @@ technology.
9 9
10To operate the driver must be bound to a suitable network interface. This can 10To operate the driver must be bound to a suitable network interface. This can
11be done when the module is loaded (specifying the name of the network interface 11be done when the module is loaded (specifying the name of the network interface
12as a paramter - e.g. 'insmod ozwpan g_net_dev=go0') or can be bound after 12as a parameter - e.g. 'insmod ozwpan g_net_dev=go0') or can be bound after
13loading using an ioctl call. See the ozappif.h file and the ioctls 13loading using an ioctl call. See the ozappif.h file and the ioctls
14OZ_IOCTL_ADD_BINDING and OZ_IOCTL_REMOVE_BINDING. 14OZ_IOCTL_ADD_BINDING and OZ_IOCTL_REMOVE_BINDING.
15 15
diff --git a/drivers/staging/ozwpan/ozappif.h b/drivers/staging/ozwpan/ozappif.h
index af0273293872..1b59b0748c6b 100644
--- a/drivers/staging/ozwpan/ozappif.h
+++ b/drivers/staging/ozwpan/ozappif.h
@@ -11,13 +11,13 @@
11#define OZ_IOCTL_MAGIC 0xf4 11#define OZ_IOCTL_MAGIC 0xf4
12 12
13struct oz_mac_addr { 13struct oz_mac_addr {
14 unsigned char a[6]; 14 __u8 a[6];
15}; 15};
16 16
17#define OZ_MAX_PDS 8 17#define OZ_MAX_PDS 8
18 18
19struct oz_pd_list { 19struct oz_pd_list {
20 int count; 20 __u32 count;
21 struct oz_mac_addr addr[OZ_MAX_PDS]; 21 struct oz_mac_addr addr[OZ_MAX_PDS];
22}; 22};
23 23
@@ -27,18 +27,10 @@ struct oz_binding_info {
27 char name[OZ_MAX_BINDING_LEN]; 27 char name[OZ_MAX_BINDING_LEN];
28}; 28};
29 29
30struct oz_test {
31 int action;
32};
33
34#define OZ_IOCTL_GET_PD_LIST _IOR(OZ_IOCTL_MAGIC, 0, struct oz_pd_list) 30#define OZ_IOCTL_GET_PD_LIST _IOR(OZ_IOCTL_MAGIC, 0, struct oz_pd_list)
35#define OZ_IOCTL_SET_ACTIVE_PD _IOW(OZ_IOCTL_MAGIC, 1, struct oz_mac_addr) 31#define OZ_IOCTL_SET_ACTIVE_PD _IOW(OZ_IOCTL_MAGIC, 1, struct oz_mac_addr)
36#define OZ_IOCTL_GET_ACTIVE_PD _IOR(OZ_IOCTL_MAGIC, 2, struct oz_mac_addr) 32#define OZ_IOCTL_GET_ACTIVE_PD _IOR(OZ_IOCTL_MAGIC, 2, struct oz_mac_addr)
37#define OZ_IOCTL_CLEAR_EVENTS _IO(OZ_IOCTL_MAGIC, 3)
38#define OZ_IOCTL_GET_EVENTS _IOR(OZ_IOCTL_MAGIC, 4, struct oz_evtlist)
39#define OZ_IOCTL_ADD_BINDING _IOW(OZ_IOCTL_MAGIC, 5, struct oz_binding_info) 33#define OZ_IOCTL_ADD_BINDING _IOW(OZ_IOCTL_MAGIC, 5, struct oz_binding_info)
40#define OZ_IOCTL_TEST _IOWR(OZ_IOCTL_MAGIC, 6, struct oz_test)
41#define OZ_IOCTL_SET_EVENT_MASK _IOW(OZ_IOCTL_MAGIC, 7, unsigned long)
42#define OZ_IOCTL_REMOVE_BINDING _IOW(OZ_IOCTL_MAGIC, 8, struct oz_binding_info) 34#define OZ_IOCTL_REMOVE_BINDING _IOW(OZ_IOCTL_MAGIC, 8, struct oz_binding_info)
43#define OZ_IOCTL_MAX 9 35#define OZ_IOCTL_MAX 9
44 36
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
index 1c380d687963..27325f74ecdc 100644
--- a/drivers/staging/ozwpan/ozcdev.c
+++ b/drivers/staging/ozwpan/ozcdev.c
@@ -41,9 +41,6 @@ struct oz_serial_ctx {
41}; 41};
42/*------------------------------------------------------------------------------ 42/*------------------------------------------------------------------------------
43 */ 43 */
44int g_taction;
45/*------------------------------------------------------------------------------
46 */
47static struct oz_cdev g_cdev; 44static struct oz_cdev g_cdev;
48/*------------------------------------------------------------------------------ 45/*------------------------------------------------------------------------------
49 * Context: process and softirq 46 * Context: process and softirq
@@ -276,20 +273,6 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
276 return -EFAULT; 273 return -EFAULT;
277 } 274 }
278 break; 275 break;
279#ifdef WANT_EVENT_TRACE
280 case OZ_IOCTL_CLEAR_EVENTS:
281 oz_events_clear();
282 break;
283 case OZ_IOCTL_GET_EVENTS:
284 rc = oz_events_copy((void __user *)arg);
285 break;
286 case OZ_IOCTL_SET_EVENT_MASK:
287 if (copy_from_user(&g_evt_mask, (void __user *)arg,
288 sizeof(unsigned long))) {
289 return -EFAULT;
290 }
291 break;
292#endif /* WANT_EVENT_TRACE */
293 case OZ_IOCTL_ADD_BINDING: 276 case OZ_IOCTL_ADD_BINDING:
294 case OZ_IOCTL_REMOVE_BINDING: { 277 case OZ_IOCTL_REMOVE_BINDING: {
295 struct oz_binding_info b; 278 struct oz_binding_info b;
diff --git a/drivers/staging/ozwpan/ozevent.c b/drivers/staging/ozwpan/ozevent.c
index 73703d3e96bd..7f66b4f19b01 100644
--- a/drivers/staging/ozwpan/ozevent.c
+++ b/drivers/staging/ozwpan/ozevent.c
@@ -5,29 +5,46 @@
5 */ 5 */
6#include "ozconfig.h" 6#include "ozconfig.h"
7#ifdef WANT_EVENT_TRACE 7#ifdef WANT_EVENT_TRACE
8#include <linux/module.h>
9#include <linux/debugfs.h>
8#include <linux/jiffies.h> 10#include <linux/jiffies.h>
9#include <linux/uaccess.h> 11#include <linux/uaccess.h>
10#include "oztrace.h" 12#include "oztrace.h"
11#include "ozevent.h" 13#include "ozevent.h"
14#include "ozappif.h"
12/*------------------------------------------------------------------------------ 15/*------------------------------------------------------------------------------
16 * Although the event mask is logically part of the oz_evtdev structure, it is
17 * needed outside of this file so define it seperately to avoid the need to
18 * export definition of struct oz_evtdev.
13 */ 19 */
14unsigned long g_evt_mask = 0xffffffff; 20u32 g_evt_mask;
15/*------------------------------------------------------------------------------ 21/*------------------------------------------------------------------------------
16 */ 22 */
17#define OZ_MAX_EVTS 2048 /* Must be power of 2 */ 23#define OZ_MAX_EVTS 2048 /* Must be power of 2 */
18DEFINE_SPINLOCK(g_eventlock); 24struct oz_evtdev {
19static int g_evt_in; 25 struct dentry *root_dir;
20static int g_evt_out; 26 int evt_in;
21static int g_missed_events; 27 int evt_out;
22static struct oz_event g_events[OZ_MAX_EVTS]; 28 int missed_events;
29 int present;
30 atomic_t users;
31 spinlock_t lock;
32 struct oz_event evts[OZ_MAX_EVTS];
33};
34
35static struct oz_evtdev g_evtdev;
36
23/*------------------------------------------------------------------------------ 37/*------------------------------------------------------------------------------
24 * Context: process 38 * Context: process
25 */ 39 */
26void oz_event_init(void) 40void oz_event_init(void)
27{ 41{
42 /* Because g_evtdev is static external all fields initally zero so no
43 * need to reinitialised those.
44 */
28 oz_trace("Event tracing initialized\n"); 45 oz_trace("Event tracing initialized\n");
29 g_evt_in = g_evt_out = 0; 46 spin_lock_init(&g_evtdev.lock);
30 g_missed_events = 0; 47 atomic_set(&g_evtdev.users, 0);
31} 48}
32/*------------------------------------------------------------------------------ 49/*------------------------------------------------------------------------------
33 * Context: process 50 * Context: process
@@ -43,74 +60,136 @@ void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4)
43{ 60{
44 unsigned long irqstate; 61 unsigned long irqstate;
45 int ix; 62 int ix;
46 spin_lock_irqsave(&g_eventlock, irqstate); 63 spin_lock_irqsave(&g_evtdev.lock, irqstate);
47 ix = (g_evt_in + 1) & (OZ_MAX_EVTS - 1); 64 ix = (g_evtdev.evt_in + 1) & (OZ_MAX_EVTS - 1);
48 if (ix != g_evt_out) { 65 if (ix != g_evtdev.evt_out) {
49 struct oz_event *e = &g_events[g_evt_in]; 66 struct oz_event *e = &g_evtdev.evts[g_evtdev.evt_in];
50 e->jiffies = jiffies; 67 e->jiffies = jiffies;
51 e->evt = evt; 68 e->evt = evt;
52 e->ctx1 = ctx1; 69 e->ctx1 = ctx1;
53 e->ctx2 = ctx2; 70 e->ctx2 = ctx2;
54 e->ctx3 = ctx3; 71 e->ctx3 = (__u32)(unsigned long)ctx3;
55 e->ctx4 = ctx4; 72 e->ctx4 = ctx4;
56 g_evt_in = ix; 73 g_evtdev.evt_in = ix;
57 } else { 74 } else {
58 g_missed_events++; 75 g_evtdev.missed_events++;
59 } 76 }
60 spin_unlock_irqrestore(&g_eventlock, irqstate); 77 spin_unlock_irqrestore(&g_evtdev.lock, irqstate);
61} 78}
62/*------------------------------------------------------------------------------ 79/*------------------------------------------------------------------------------
63 * Context: process 80 * Context: process
64 */ 81 */
65int oz_events_copy(struct oz_evtlist __user *lst) 82static void oz_events_clear(struct oz_evtdev *dev)
66{ 83{
67 int first; 84 unsigned long irqstate;
68 int ix; 85 oz_trace("Clearing events\n");
69 struct hdr { 86 spin_lock_irqsave(&dev->lock, irqstate);
70 int count; 87 dev->evt_in = dev->evt_out = 0;
71 int missed; 88 dev->missed_events = 0;
72 } hdr; 89 spin_unlock_irqrestore(&dev->lock, irqstate);
73 ix = g_evt_out; 90}
74 hdr.count = g_evt_in - ix; 91#ifdef CONFIG_DEBUG_FS
75 if (hdr.count < 0) 92/*------------------------------------------------------------------------------
76 hdr.count += OZ_MAX_EVTS; 93 * Context: process
77 if (hdr.count > OZ_EVT_LIST_SZ) 94 */
78 hdr.count = OZ_EVT_LIST_SZ; 95int oz_events_open(struct inode *inode, struct file *filp)
79 hdr.missed = g_missed_events; 96{
80 g_missed_events = 0; 97 oz_trace("oz_evt_open()\n");
81 if (copy_to_user((void __user *)lst, &hdr, sizeof(hdr))) 98 oz_trace("Open flags: 0x%x\n", filp->f_flags);
82 return -EFAULT; 99 if (atomic_add_return(1, &g_evtdev.users) == 1) {
83 first = OZ_MAX_EVTS - ix; 100 oz_events_clear(&g_evtdev);
84 if (first > hdr.count) 101 return nonseekable_open(inode, filp);
85 first = hdr.count; 102 } else {
86 if (first) { 103 atomic_dec(&g_evtdev.users);
87 int sz = first*sizeof(struct oz_event); 104 return -EBUSY;
88 void __user *p = (void __user *)lst->evts;
89 if (copy_to_user(p, &g_events[ix], sz))
90 return -EFAULT;
91 if (hdr.count > first) {
92 p = (void __user *)&lst->evts[first];
93 sz = (hdr.count-first)*sizeof(struct oz_event);
94 if (copy_to_user(p, g_events, sz))
95 return -EFAULT;
96 }
97 } 105 }
98 ix += hdr.count; 106}
99 if (ix >= OZ_MAX_EVTS) 107/*------------------------------------------------------------------------------
100 ix -= OZ_MAX_EVTS; 108 * Context: process
101 g_evt_out = ix; 109 */
110int oz_events_release(struct inode *inode, struct file *filp)
111{
112 oz_events_clear(&g_evtdev);
113 atomic_dec(&g_evtdev.users);
114 g_evt_mask = 0;
115 oz_trace("oz_evt_release()\n");
102 return 0; 116 return 0;
103} 117}
104/*------------------------------------------------------------------------------ 118/*------------------------------------------------------------------------------
105 * Context: process 119 * Context: process
106 */ 120 */
107void oz_events_clear(void) 121ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count,
122 loff_t *fpos)
108{ 123{
109 unsigned long irqstate; 124 struct oz_evtdev *dev = &g_evtdev;
110 spin_lock_irqsave(&g_eventlock, irqstate); 125 int rc = 0;
111 g_evt_in = g_evt_out = 0; 126 int nb_evts = count / sizeof(struct oz_event);
112 g_missed_events = 0; 127 int n;
113 spin_unlock_irqrestore(&g_eventlock, irqstate); 128 int sz;
129
130 n = dev->evt_in - dev->evt_out;
131 if (n < 0)
132 n += OZ_MAX_EVTS;
133 if (nb_evts > n)
134 nb_evts = n;
135 if (nb_evts == 0)
136 goto out;
137 n = OZ_MAX_EVTS - dev->evt_out;
138 if (n > nb_evts)
139 n = nb_evts;
140 sz = n * sizeof(struct oz_event);
141 if (copy_to_user(buf, &dev->evts[dev->evt_out], sz)) {
142 rc = -EFAULT;
143 goto out;
144 }
145 if (n == nb_evts)
146 goto out2;
147 n = nb_evts - n;
148 if (copy_to_user(buf + sz, dev->evts, n * sizeof(struct oz_event))) {
149 rc = -EFAULT;
150 goto out;
151 }
152out2:
153 dev->evt_out = (dev->evt_out + nb_evts) & (OZ_MAX_EVTS - 1);
154 rc = nb_evts * sizeof(struct oz_event);
155out:
156 return rc;
114} 157}
115#endif /* WANT_EVENT_TRACE */ 158/*------------------------------------------------------------------------------
159 */
160const struct file_operations oz_events_fops = {
161 .owner = THIS_MODULE,
162 .open = oz_events_open,
163 .release = oz_events_release,
164 .read = oz_events_read,
165};
166/*------------------------------------------------------------------------------
167 * Context: process
168 */
169void oz_debugfs_init(void)
170{
171 struct dentry *parent;
116 172
173 parent = debugfs_create_dir("ozwpan", NULL);
174 if (parent == NULL) {
175 oz_trace("Failed to create debugfs directory ozmo\n");
176 return;
177 } else {
178 g_evtdev.root_dir = parent;
179 if (debugfs_create_file("events", S_IRUSR, parent, NULL,
180 &oz_events_fops) == NULL)
181 oz_trace("Failed to create file ozmo/events\n");
182 if (debugfs_create_x32("event_mask", S_IRUSR | S_IWUSR, parent,
183 &g_evt_mask) == NULL)
184 oz_trace("Failed to create file ozmo/event_mask\n");
185 }
186}
187/*------------------------------------------------------------------------------
188 * Context: process
189 */
190void oz_debugfs_remove(void)
191{
192 debugfs_remove_recursive(g_evtdev.root_dir);
193}
194#endif /* CONFIG_DEBUG_FS */
195#endif /* WANT_EVENT_TRACE */
diff --git a/drivers/staging/ozwpan/ozevent.h b/drivers/staging/ozwpan/ozevent.h
index f033d014c6f3..32f6f9859c41 100644
--- a/drivers/staging/ozwpan/ozevent.h
+++ b/drivers/staging/ozwpan/ozevent.h
@@ -9,23 +9,24 @@
9#include "ozeventdef.h" 9#include "ozeventdef.h"
10 10
11#ifdef WANT_EVENT_TRACE 11#ifdef WANT_EVENT_TRACE
12extern unsigned long g_evt_mask; 12extern u32 g_evt_mask;
13void oz_event_init(void); 13void oz_event_init(void);
14void oz_event_term(void); 14void oz_event_term(void);
15void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4); 15void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4);
16void oz_debugfs_init(void);
17void oz_debugfs_remove(void);
16#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4) \ 18#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4) \
17 do { \ 19 do { \
18 if ((1<<(__evt)) & g_evt_mask) \ 20 if ((1<<(__evt)) & g_evt_mask) \
19 oz_event_log2(__evt, __ctx1, __ctx2, __ctx3, __ctx4); \ 21 oz_event_log2(__evt, __ctx1, __ctx2, __ctx3, __ctx4); \
20 } while (0) 22 } while (0)
21int oz_events_copy(struct oz_evtlist __user *lst); 23
22void oz_events_clear(void);
23#else 24#else
24#define oz_event_init() 25#define oz_event_init()
25#define oz_event_term() 26#define oz_event_term()
26#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4) 27#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4)
27#define oz_events_copy(__lst) 28#define oz_debugfs_init()
28#define oz_events_clear() 29#define oz_debugfs_remove()
29#endif /* WANT_EVENT_TRACE */ 30#endif /* WANT_EVENT_TRACE */
30 31
31#endif /* _OZEVENT_H */ 32#endif /* _OZEVENT_H */
diff --git a/drivers/staging/ozwpan/ozeventdef.h b/drivers/staging/ozwpan/ozeventdef.h
index a880288bab11..4b938981671a 100644
--- a/drivers/staging/ozwpan/ozeventdef.h
+++ b/drivers/staging/ozwpan/ozeventdef.h
@@ -29,19 +29,12 @@
29#define OZ_EVT_DEBUG 20 29#define OZ_EVT_DEBUG 20
30 30
31struct oz_event { 31struct oz_event {
32 unsigned long jiffies; 32 __u32 jiffies;
33 unsigned char evt; 33 __u8 evt;
34 unsigned char ctx1; 34 __u8 ctx1;
35 unsigned short ctx2; 35 __u16 ctx2;
36 void *ctx3; 36 __u32 ctx3;
37 unsigned ctx4; 37 __u32 ctx4;
38};
39
40#define OZ_EVT_LIST_SZ 64
41struct oz_evtlist {
42 int count;
43 int missed;
44 struct oz_event evts[OZ_EVT_LIST_SZ];
45}; 38};
46 39
47#endif /* _OZEVENTDEF_H */ 40#endif /* _OZEVENTDEF_H */
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
index 750b14eb505e..251f07c39a6b 100644
--- a/drivers/staging/ozwpan/ozhcd.c
+++ b/drivers/staging/ozwpan/ozhcd.c
@@ -1416,7 +1416,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1416 oz_trace("USB_REQ_SET_CONFIGURATION - req\n"); 1416 oz_trace("USB_REQ_SET_CONFIGURATION - req\n");
1417 break; 1417 break;
1418 case USB_REQ_GET_CONFIGURATION: 1418 case USB_REQ_GET_CONFIGURATION:
1419 /* We short curcuit this case and reply directly since 1419 /* We short circuit this case and reply directly since
1420 * we have the selected configuration number cached. 1420 * we have the selected configuration number cached.
1421 */ 1421 */
1422 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, 1422 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0,
@@ -1432,7 +1432,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1432 } 1432 }
1433 break; 1433 break;
1434 case USB_REQ_GET_INTERFACE: 1434 case USB_REQ_GET_INTERFACE:
1435 /* We short curcuit this case and reply directly since 1435 /* We short circuit this case and reply directly since
1436 * we have the selected interface alternative cached. 1436 * we have the selected interface alternative cached.
1437 */ 1437 */
1438 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, 1438 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0,
@@ -1463,7 +1463,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1463 rc = -ENOMEM; 1463 rc = -ENOMEM;
1464 } else { 1464 } else {
1465 /* Note: we are queuing the request after we have 1465 /* Note: we are queuing the request after we have
1466 * submitted it to be tranmitted. If the request were 1466 * submitted it to be transmitted. If the request were
1467 * to complete before we queued it then it would not 1467 * to complete before we queued it then it would not
1468 * be found in the queue. It seems impossible for 1468 * be found in the queue. It seems impossible for
1469 * this to happen but if it did the request would 1469 * this to happen but if it did the request would
diff --git a/drivers/staging/ozwpan/ozmain.c b/drivers/staging/ozwpan/ozmain.c
index aaf2ccc0bcfb..7579645d642a 100644
--- a/drivers/staging/ozwpan/ozmain.c
+++ b/drivers/staging/ozwpan/ozmain.c
@@ -33,6 +33,9 @@ static int __init ozwpan_init(void)
33 oz_protocol_init(g_net_dev); 33 oz_protocol_init(g_net_dev);
34 oz_app_enable(OZ_APPID_USB, 1); 34 oz_app_enable(OZ_APPID_USB, 1);
35 oz_apps_init(); 35 oz_apps_init();
36#ifdef CONFIG_DEBUG_FS
37 oz_debugfs_init();
38#endif
36 return 0; 39 return 0;
37} 40}
38/*------------------------------------------------------------------------------ 41/*------------------------------------------------------------------------------
@@ -44,6 +47,9 @@ static void __exit ozwpan_exit(void)
44 oz_apps_term(); 47 oz_apps_term();
45 oz_cdev_deregister(); 48 oz_cdev_deregister();
46 oz_event_term(); 49 oz_event_term();
50#ifdef CONFIG_DEBUG_FS
51 oz_debugfs_remove();
52#endif
47} 53}
48/*------------------------------------------------------------------------------ 54/*------------------------------------------------------------------------------
49 */ 55 */
@@ -53,6 +59,6 @@ module_exit(ozwpan_exit);
53 59
54MODULE_AUTHOR("Chris Kelly"); 60MODULE_AUTHOR("Chris Kelly");
55MODULE_DESCRIPTION("Ozmo Devices USB over WiFi hcd driver"); 61MODULE_DESCRIPTION("Ozmo Devices USB over WiFi hcd driver");
56MODULE_VERSION("1.0.8"); 62MODULE_VERSION("1.0.9");
57MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
58 64
diff --git a/drivers/staging/ozwpan/ozusbsvc.c b/drivers/staging/ozwpan/ozusbsvc.c
index 9e74f9602384..8fa7f256ad8c 100644
--- a/drivers/staging/ozwpan/ozusbsvc.c
+++ b/drivers/staging/ozwpan/ozusbsvc.c
@@ -7,7 +7,7 @@
7 * The implementation of this service is split into two parts the first of which 7 * The implementation of this service is split into two parts the first of which
8 * is protocol independent and the second contains protocol specific details. 8 * is protocol independent and the second contains protocol specific details.
9 * This split is to allow alternative protocols to be defined. 9 * This split is to allow alternative protocols to be defined.
10 * The implemenation of this service uses ozhcd.c to implement a USB HCD. 10 * The implementation of this service uses ozhcd.c to implement a USB HCD.
11 * ----------------------------------------------------------------------------- 11 * -----------------------------------------------------------------------------
12 */ 12 */
13#include <linux/init.h> 13#include <linux/init.h>
diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
index 6183573f112f..7365089a33e8 100644
--- a/drivers/staging/panel/panel.c
+++ b/drivers/staging/panel/panel.c
@@ -754,7 +754,7 @@ static void lcd_backlight(int on)
754 if (lcd_bl_pin == PIN_NONE) 754 if (lcd_bl_pin == PIN_NONE)
755 return; 755 return;
756 756
757 /* The backlight is activated by seting the AUTOFEED line to +5V */ 757 /* The backlight is activated by setting the AUTOFEED line to +5V */
758 spin_lock(&pprt_lock); 758 spin_lock(&pprt_lock);
759 bits.bl = on; 759 bits.bl = on;
760 panel_set_bits(); 760 panel_set_bits();
diff --git a/drivers/staging/ramster/Kconfig b/drivers/staging/ramster/Kconfig
index 4af1f8d4b953..8349887827dc 100644
--- a/drivers/staging/ramster/Kconfig
+++ b/drivers/staging/ramster/Kconfig
@@ -1,6 +1,6 @@
1config RAMSTER 1config RAMSTER
2 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem" 2 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem"
3 depends on (CLEANCACHE || FRONTSWAP) && CONFIGFS_FS=y && !ZCACHE && !XVMALLOC && !HIGHMEM 3 depends on (CLEANCACHE || FRONTSWAP) && CONFIGFS_FS=y && !ZCACHE && !XVMALLOC && !HIGHMEM && NET
4 select LZO_COMPRESS 4 select LZO_COMPRESS
5 select LZO_DECOMPRESS 5 select LZO_DECOMPRESS
6 default n 6 default n
diff --git a/drivers/staging/ramster/cluster/tcp.c b/drivers/staging/ramster/cluster/tcp.c
index b9721c1055b1..d0a07d722b61 100644
--- a/drivers/staging/ramster/cluster/tcp.c
+++ b/drivers/staging/ramster/cluster/tcp.c
@@ -111,7 +111,7 @@ static struct socket *r2net_listen_sock;
111 * r2net_wq. teardown detaches the callbacks before destroying the workqueue. 111 * r2net_wq. teardown detaches the callbacks before destroying the workqueue.
112 * quorum work is queued as sock containers are shutdown.. stop_listening 112 * quorum work is queued as sock containers are shutdown.. stop_listening
113 * tears down all the node's sock containers, preventing future shutdowns 113 * tears down all the node's sock containers, preventing future shutdowns
114 * and queued quroum work, before canceling delayed quorum work and 114 * and queued quorum work, before canceling delayed quorum work and
115 * destroying the work queue. 115 * destroying the work queue.
116 */ 116 */
117static struct workqueue_struct *r2net_wq; 117static struct workqueue_struct *r2net_wq;
@@ -660,7 +660,7 @@ out:
660 660
661/* 661/*
662 * we register callbacks so we can queue work on events before calling 662 * we register callbacks so we can queue work on events before calling
663 * the original callbacks. our callbacks our careful to test user_data 663 * the original callbacks. our callbacks are careful to test user_data
664 * to discover when they've reaced with r2net_unregister_callbacks(). 664 * to discover when they've reaced with r2net_unregister_callbacks().
665 */ 665 */
666static void r2net_register_callbacks(struct sock *sk, 666static void r2net_register_callbacks(struct sock *sk,
diff --git a/drivers/staging/ramster/xvmalloc.c b/drivers/staging/ramster/xvmalloc.c
index 93ba8e9407aa..44ceb0b823a9 100644
--- a/drivers/staging/ramster/xvmalloc.c
+++ b/drivers/staging/ramster/xvmalloc.c
@@ -132,7 +132,7 @@ static u32 find_block(struct xv_pool *pool, u32 size,
132 if (!pool->flbitmap) 132 if (!pool->flbitmap)
133 return 0; 133 return 0;
134 134
135 /* Get freelist index correspoding to this size */ 135 /* Get freelist index corresponding to this size */
136 slindex = get_index(size); 136 slindex = get_index(size);
137 slbitmap = pool->slbitmap[slindex / BITS_PER_LONG]; 137 slbitmap = pool->slbitmap[slindex / BITS_PER_LONG];
138 slbitstart = slindex % BITS_PER_LONG; 138 slbitstart = slindex % BITS_PER_LONG;
diff --git a/drivers/staging/ramster/zcache-main.c b/drivers/staging/ramster/zcache-main.c
index 68b2e053a0e6..4e7ef0e6b79c 100644
--- a/drivers/staging/ramster/zcache-main.c
+++ b/drivers/staging/ramster/zcache-main.c
@@ -1331,7 +1331,7 @@ static ssize_t zv_max_mean_zsize_store(struct kobject *kobj,
1331 * when that limit is reached, further puts will be rejected (until 1331 * when that limit is reached, further puts will be rejected (until
1332 * some pages have been flushed). Note that, due to compression, 1332 * some pages have been flushed). Note that, due to compression,
1333 * this number may exceed 100; it defaults to 75 and we set an 1333 * this number may exceed 100; it defaults to 75 and we set an
1334 * arbitary limit of 150. A poor choice will almost certainly result 1334 * arbitrary limit of 150. A poor choice will almost certainly result
1335 * in OOM's, so this value should only be changed prudently. 1335 * in OOM's, so this value should only be changed prudently.
1336 */ 1336 */
1337static ssize_t zv_page_count_policy_percent_show(struct kobject *kobj, 1337static ssize_t zv_page_count_policy_percent_show(struct kobject *kobj,
@@ -2004,7 +2004,7 @@ int zcache_pampd_replace_in_obj(void *new_pampd, struct tmem_obj *obj)
2004 * Called by the message handler after a (still compressed) page has been 2004 * Called by the message handler after a (still compressed) page has been
2005 * fetched from the remote machine in response to an "is_remote" tmem_get 2005 * fetched from the remote machine in response to an "is_remote" tmem_get
2006 * or persistent tmem_localify. For a tmem_get, "extra" is the address of 2006 * or persistent tmem_localify. For a tmem_get, "extra" is the address of
2007 * the page that is to be filled to succesfully resolve the tmem_get; for 2007 * the page that is to be filled to successfully resolve the tmem_get; for
2008 * a (persistent) tmem_localify, "extra" is NULL (as the data is placed only 2008 * a (persistent) tmem_localify, "extra" is NULL (as the data is placed only
2009 * in the local zcache). "data" points to "size" bytes of (compressed) data 2009 * in the local zcache). "data" points to "size" bytes of (compressed) data
2010 * passed in the message. In the case of a persistent remote get, if 2010 * passed in the message. In the case of a persistent remote get, if
@@ -2095,7 +2095,7 @@ out:
2095/* 2095/*
2096 * Called on a remote persistent tmem_get to attempt to preallocate 2096 * Called on a remote persistent tmem_get to attempt to preallocate
2097 * local storage for the data contained in the remote persistent page. 2097 * local storage for the data contained in the remote persistent page.
2098 * If succesfully preallocated, returns the pampd, marked as remote and 2098 * If successfully preallocated, returns the pampd, marked as remote and
2099 * in_transit. Else returns NULL. Note that the appropriate tmem data 2099 * in_transit. Else returns NULL. Note that the appropriate tmem data
2100 * structure must be locked. 2100 * structure must be locked.
2101 */ 2101 */
diff --git a/drivers/staging/rtl8187se/Makefile b/drivers/staging/rtl8187se/Makefile
index 72db504b23b4..91d1aa2830c9 100644
--- a/drivers/staging/rtl8187se/Makefile
+++ b/drivers/staging/rtl8187se/Makefile
@@ -10,7 +10,7 @@ ccflags-y += -DHIGH_POWER
10ccflags-y += -DSW_DIG 10ccflags-y += -DSW_DIG
11ccflags-y += -DRATE_ADAPT 11ccflags-y += -DRATE_ADAPT
12 12
13#enable it for legacy power save, disable it for leisure power save 13#enable it for legacy power save, disable it for leisure power save
14ccflags-y += -DENABLE_LPS 14ccflags-y += -DENABLE_LPS
15 15
16 16
diff --git a/drivers/staging/rtl8187se/ieee80211/dot11d.c b/drivers/staging/rtl8187se/ieee80211/dot11d.c
index 309bb8bf287e..0e93eb0735a7 100644
--- a/drivers/staging/rtl8187se/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8187se/ieee80211/dot11d.c
@@ -55,7 +55,7 @@ Dot11d_Reset(struct ieee80211_device *ieee)
55 55
56// 56//
57// Description: 57// Description:
58// Update country IE from Beacon or Probe Resopnse 58// Update country IE from Beacon or Probe Response
59// and configure PHY for operation in the regulatory domain. 59// and configure PHY for operation in the regulatory domain.
60// 60//
61// TODO: 61// TODO:
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211.h b/drivers/staging/rtl8187se/ieee80211/ieee80211.h
index 40dd715d9df7..b94c48b29302 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211.h
@@ -834,7 +834,7 @@ enum ieee80211_state {
834 /* the association procedure is sending AUTH request*/ 834 /* the association procedure is sending AUTH request*/
835 IEEE80211_ASSOCIATING_AUTHENTICATING, 835 IEEE80211_ASSOCIATING_AUTHENTICATING,
836 836
837 /* the association procedure has successfully authentcated 837 /* the association procedure has successfully authenticated
838 * and is sending association request 838 * and is sending association request
839 */ 839 */
840 IEEE80211_ASSOCIATING_AUTHENTICATED, 840 IEEE80211_ASSOCIATING_AUTHENTICATED,
@@ -934,7 +934,7 @@ struct ieee80211_device {
934 * with RX of broad/multicast frames */ 934 * with RX of broad/multicast frames */
935 935
936 /* Fragmentation structures */ 936 /* Fragmentation structures */
937 // each streaming contain a entry 937 /* each stream contains an entry */
938 struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN]; 938 struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
939 unsigned int frag_next_idx[17]; 939 unsigned int frag_next_idx[17];
940 u16 fts; /* Fragmentation Threshold */ 940 u16 fts; /* Fragmentation Threshold */
@@ -972,7 +972,7 @@ struct ieee80211_device {
972 972
973 int rate; /* current rate */ 973 int rate; /* current rate */
974 int basic_rate; 974 int basic_rate;
975 //FIXME: pleace callback, see if redundant with softmac_features 975 //FIXME: please callback, see if redundant with softmac_features
976 short active_scan; 976 short active_scan;
977 977
978 /* this contains flags for selectively enable softmac support */ 978 /* this contains flags for selectively enable softmac support */
@@ -1106,7 +1106,7 @@ struct ieee80211_device {
1106 1106
1107 /* used instead of hard_start_xmit (not softmac_hard_start_xmit) 1107 /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1108 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data 1108 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1109 * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set 1109 * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1110 * then also management frames are sent via this callback. 1110 * then also management frames are sent via this callback.
1111 * This function can't sleep. 1111 * This function can't sleep.
1112 */ 1112 */
@@ -1124,7 +1124,7 @@ struct ieee80211_device {
1124 1124
1125 /* ask to the driver to retune the radio . 1125 /* ask to the driver to retune the radio .
1126 * This function can sleep. the driver should ensure 1126 * This function can sleep. the driver should ensure
1127 * the radio has been swithced before return. 1127 * the radio has been switched before return.
1128 */ 1128 */
1129 void (*set_chan)(struct net_device *dev,short ch); 1129 void (*set_chan)(struct net_device *dev,short ch);
1130 1130
@@ -1135,7 +1135,7 @@ struct ieee80211_device {
1135 * The syncro version is similar to the start_scan but 1135 * The syncro version is similar to the start_scan but
1136 * does not return until all channels has been scanned. 1136 * does not return until all channels has been scanned.
1137 * this is called in user context and should sleep, 1137 * this is called in user context and should sleep,
1138 * it is called in a work_queue when swithcing to ad-hoc mode 1138 * it is called in a work_queue when switching to ad-hoc mode
1139 * or in behalf of iwlist scan when the card is associated 1139 * or in behalf of iwlist scan when the card is associated
1140 * and root user ask for a scan. 1140 * and root user ask for a scan.
1141 * the function stop_scan should stop both the syncro and 1141 * the function stop_scan should stop both the syncro and
@@ -1196,7 +1196,7 @@ struct ieee80211_device {
1196/* Generate probe requests */ 1196/* Generate probe requests */
1197#define IEEE_SOFTMAC_PROBERQ (1<<4) 1197#define IEEE_SOFTMAC_PROBERQ (1<<4)
1198 1198
1199/* Generate respones to probe requests */ 1199/* Generate response to probe requests */
1200#define IEEE_SOFTMAC_PROBERS (1<<5) 1200#define IEEE_SOFTMAC_PROBERS (1<<5)
1201 1201
1202/* The ieee802.11 stack will manages the netif queue 1202/* The ieee802.11 stack will manages the netif queue
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
index 26bacb96d247..8173240dcf7a 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
@@ -42,7 +42,7 @@ short ieee80211_is_shortslot(const struct ieee80211_network *net)
42 return net->capability & WLAN_CAPABILITY_SHORT_SLOT; 42 return net->capability & WLAN_CAPABILITY_SHORT_SLOT;
43} 43}
44 44
45/* returns the total length needed for pleacing the RATE MFIE 45/* returns the total length needed for placing the RATE MFIE
46 * tag and the EXTENDED RATE MFIE tag if needed. 46 * tag and the EXTENDED RATE MFIE tag if needed.
47 * It encludes two bytes per tag for the tag itself and its len 47 * It encludes two bytes per tag for the tag itself and its len
48 */ 48 */
@@ -60,7 +60,7 @@ unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee)
60 return rate_len; 60 return rate_len;
61} 61}
62 62
63/* pleace the MFIE rate, tag to the memory (double) poined. 63/* place the MFIE rate, tag to the memory (double) poised.
64 * Then it updates the pointer so that 64 * Then it updates the pointer so that
65 * it points after the new MFIE tag added. 65 * it points after the new MFIE tag added.
66 */ 66 */
@@ -467,7 +467,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
467 * So we switch to IEEE80211_LINKED_SCANNING to remember 467 * So we switch to IEEE80211_LINKED_SCANNING to remember
468 * that we are still logically linked (not interested in 468 * that we are still logically linked (not interested in
469 * new network events, despite for updating the net list, 469 * new network events, despite for updating the net list,
470 * but we are temporarly 'unlinked' as the driver shall 470 * but we are temporarily 'unlinked' as the driver shall
471 * not filter RX frames and the channel is changing. 471 * not filter RX frames and the channel is changing.
472 * So the only situation in witch are interested is to check 472 * So the only situation in witch are interested is to check
473 * if the state become LINKED because of the #1 situation 473 * if the state become LINKED because of the #1 situation
@@ -530,7 +530,7 @@ void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
530 * So we switch to IEEE80211_LINKED_SCANNING to remember 530 * So we switch to IEEE80211_LINKED_SCANNING to remember
531 * that we are still logically linked (not interested in 531 * that we are still logically linked (not interested in
532 * new network events, despite for updating the net list, 532 * new network events, despite for updating the net list,
533 * but we are temporarly 'unlinked' as the driver shall 533 * but we are temporarily 'unlinked' as the driver shall
534 * not filter RX frames and the channel is changing. 534 * not filter RX frames and the channel is changing.
535 * So the only situation in witch are interested is to check 535 * So the only situation in witch are interested is to check
536 * if the state become LINKED because of the #1 situation 536 * if the state become LINKED because of the #1 situation
@@ -1140,7 +1140,7 @@ void ieee80211_associate_abort(struct ieee80211_device *ieee)
1140 1140
1141 ieee->associate_seq++; 1141 ieee->associate_seq++;
1142 1142
1143 /* don't scan, and avoid to have the RX path possibily 1143 /* don't scan, and avoid to have the RX path possibly
1144 * try again to associate. Even do not react to AUTH or 1144 * try again to associate. Even do not react to AUTH or
1145 * ASSOC response. Just wait for the retry wq to be scheduled. 1145 * ASSOC response. Just wait for the retry wq to be scheduled.
1146 * Here we will check if there are good nets to associate 1146 * Here we will check if there are good nets to associate
@@ -1346,14 +1346,14 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee
1346 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch); 1346 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1347 1347
1348 if ( /* if the user set the AP check if match. 1348 if ( /* if the user set the AP check if match.
1349 * if the network does not broadcast essid we check the user supplyed ANY essid 1349 * if the network does not broadcast essid we check the user supplied ANY essid
1350 * if the network does broadcast and the user does not set essid it is OK 1350 * if the network does broadcast and the user does not set essid it is OK
1351 * if the network does broadcast and the user did set essid chech if essid match 1351 * if the network does broadcast and the user did set essid chech if essid match
1352 */ 1352 */
1353 ( apset && apmatch && 1353 ( apset && apmatch &&
1354 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) || 1354 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1355 /* if the ap is not set, check that the user set the bssid 1355 /* if the ap is not set, check that the user set the bssid
1356 * and the network does bradcast and that those two bssid matches 1356 * and the network does broadcast and that those two bssid matches
1357 */ 1357 */
1358 (!apset && ssidset && ssidbroad && ssidmatch) 1358 (!apset && ssidset && ssidbroad && ssidmatch)
1359 ){ 1359 ){
@@ -1821,7 +1821,7 @@ ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1821 1821
1822 while (left >= sizeof(struct ieee80211_info_element_hdr)) { 1822 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
1823 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) { 1823 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
1824 printk(KERN_WARNING "[re]associate reeponse error!"); 1824 printk(KERN_WARNING "[re]associate response error!");
1825 return 1; 1825 return 1;
1826 } 1826 }
1827 switch (info_element->id) { 1827 switch (info_element->id) {
@@ -1905,7 +1905,7 @@ associate_complete:
1905 } 1905 }
1906 }else{ 1906 }else{
1907 ieee->softmac_stats.rx_auth_rs_err++; 1907 ieee->softmac_stats.rx_auth_rs_err++;
1908 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode); 1908 IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode);
1909 ieee80211_associate_abort(ieee); 1909 ieee80211_associate_abort(ieee);
1910 } 1910 }
1911 1911
@@ -2184,15 +2184,15 @@ void ieee80211_start_ibss_wq(struct work_struct *work)
2184 2184
2185 if(ieee->state == IEEE80211_NOLINK) 2185 if(ieee->state == IEEE80211_NOLINK)
2186 ieee->current_network.channel = 10; 2186 ieee->current_network.channel = 10;
2187 /* if not then the state is not linked. Maybe the user swithced to 2187 /* if not then the state is not linked. Maybe the user switched to
2188 * ad-hoc mode just after being in monitor mode, or just after 2188 * ad-hoc mode just after being in monitor mode, or just after
2189 * being very few time in managed mode (so the card have had no 2189 * being very few time in managed mode (so the card have had no
2190 * time to scan all the chans..) or we have just run up the iface 2190 * time to scan all the chans..) or we have just run up the iface
2191 * after setting ad-hoc mode. So we have to give another try.. 2191 * after setting ad-hoc mode. So we have to give another try..
2192 * Here, in ibss mode, should be safe to do this without extra care 2192 * Here, in ibss mode, should be safe to do this without extra care
2193 * (in bss mode we had to make sure no-one tryed to associate when 2193 * (in bss mode we had to make sure no-one tried to associate when
2194 * we had just checked the ieee->state and we was going to start the 2194 * we had just checked the ieee->state and we was going to start the
2195 * scan) beacause in ibss mode the ieee80211_new_net function, when 2195 * scan) because in ibss mode the ieee80211_new_net function, when
2196 * finds a good net, just set the ieee->state to IEEE80211_LINKED, 2196 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2197 * so, at worst, we waste a bit of time to initiate an unneeded syncro 2197 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2198 * scan, that will stop at the first round because it sees the state 2198 * scan, that will stop at the first round because it sees the state
@@ -2342,7 +2342,7 @@ void ieee80211_associate_retry_wq(struct work_struct *work)
2342 goto exit; 2342 goto exit;
2343 /* until we do not set the state to IEEE80211_NOLINK 2343 /* until we do not set the state to IEEE80211_NOLINK
2344 * there are no possibility to have someone else trying 2344 * there are no possibility to have someone else trying
2345 * to start an association procdure (we get here with 2345 * to start an association procedure (we get here with
2346 * ieee->state = IEEE80211_ASSOCIATING). 2346 * ieee->state = IEEE80211_ASSOCIATING).
2347 * When we set the state to IEEE80211_NOLINK it is possible 2347 * When we set the state to IEEE80211_NOLINK it is possible
2348 * that the RX path run an attempt to associate, but 2348 * that the RX path run an attempt to associate, but
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c
index e46ff2ffa09b..5d204906baf7 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c
@@ -362,7 +362,7 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
362 ieee80211_stop_protocol(ieee); 362 ieee80211_stop_protocol(ieee);
363 363
364 /* this is just to be sure that the GET wx callback 364 /* this is just to be sure that the GET wx callback
365 * has consisten infos. not needed otherwise 365 * has consistent infos. not needed otherwise
366 */ 366 */
367 spin_lock_irqsave(&ieee->lock, flags); 367 spin_lock_irqsave(&ieee->lock, flags);
368 368
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
index 552115cd760e..89ed86ef0d15 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
@@ -328,7 +328,7 @@ int ieee80211_rtl_xmit(struct sk_buff *skb,
328 //printk(KERN_WARNING "upper layer packet!\n"); 328 //printk(KERN_WARNING "upper layer packet!\n");
329 spin_lock_irqsave(&ieee->lock, flags); 329 spin_lock_irqsave(&ieee->lock, flags);
330 330
331 /* If there is no driver handler to take the TXB, dont' bother 331 /* If there is no driver handler to take the TXB, don't bother
332 * creating it... */ 332 * creating it... */
333 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))|| 333 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))||
334 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) { 334 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
@@ -413,10 +413,7 @@ int ieee80211_rtl_xmit(struct sk_buff *skb,
413 413
414 /* Determine fragmentation size based on destination (multicast 414 /* Determine fragmentation size based on destination (multicast
415 * and broadcast are not fragmented) */ 415 * and broadcast are not fragmented) */
416// if (is_multicast_ether_addr(dest) || 416 if (is_multicast_ether_addr(header.addr1)) {
417// is_broadcast_ether_addr(dest)) {
418 if (is_multicast_ether_addr(header.addr1) ||
419 is_broadcast_ether_addr(header.addr1)) {
420 frag_size = MAX_FRAG_THRESHOLD; 417 frag_size = MAX_FRAG_THRESHOLD;
421 qos_ctl = QOS_CTL_NOTCONTAIN_ACK; 418 qos_ctl = QOS_CTL_NOTCONTAIN_ACK;
422 } 419 }
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
index ca414a915a4e..c7917b24425c 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
@@ -363,7 +363,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
363 (*crypt)->priv); 363 (*crypt)->priv);
364 sec.flags |= (1 << key); 364 sec.flags |= (1 << key);
365 /* This ensures a key will be activated if no key is 365 /* This ensures a key will be activated if no key is
366 * explicitely set */ 366 * explicitly set */
367 if (key == sec.active_key) 367 if (key == sec.active_key)
368 sec.flags |= SEC_ACTIVE_KEY; 368 sec.flags |= SEC_ACTIVE_KEY;
369 ieee->tx_keyidx = key;//by wb 080312 369 ieee->tx_keyidx = key;//by wb 080312
diff --git a/drivers/staging/rtl8187se/r8180.h b/drivers/staging/rtl8187se/r8180.h
index a2c46ae4a400..2682afbac4ff 100644
--- a/drivers/staging/rtl8187se/r8180.h
+++ b/drivers/staging/rtl8187se/r8180.h
@@ -11,7 +11,7 @@
11 11
12 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 12 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
13 13
14 We want to tanks the Authors of those projects and the Ndiswrapper 14 We want to thanks the Authors of those projects and the Ndiswrapper
15 project Authors. 15 project Authors.
16*/ 16*/
17 17
@@ -514,12 +514,12 @@ typedef struct r8180_priv
514 bool bDefaultAntenna1; 514 bool bDefaultAntenna1;
515 u8 SignalStrength; 515 u8 SignalStrength;
516 long Stats_SignalStrength; 516 long Stats_SignalStrength;
517 long LastSignalStrengthInPercent; // In percentange, used for smoothing, e.g. Moving Average. 517 long LastSignalStrengthInPercent; // In percentage, used for smoothing, e.g. Moving Average.
518 u8 SignalQuality; // in 0-100 index. 518 u8 SignalQuality; // in 0-100 index.
519 long Stats_SignalQuality; 519 long Stats_SignalQuality;
520 long RecvSignalPower; // in dBm. 520 long RecvSignalPower; // in dBm.
521 long Stats_RecvSignalPower; 521 long Stats_RecvSignalPower;
522 u8 LastRxPktAntenna; // +by amy 080312 Antenn which received the lasted packet. 0: Aux, 1:Main. Added by Roger, 2008.01.25. 522 u8 LastRxPktAntenna; // +by amy 080312 Antenna which received the lasted packet. 0: Aux, 1:Main. Added by Roger, 2008.01.25.
523 u32 AdRxOkCnt; 523 u32 AdRxOkCnt;
524 long AdRxSignalStrength; 524 long AdRxSignalStrength;
525 u8 CurrAntennaIndex; // Index to current Antenna (both Tx and Rx). 525 u8 CurrAntennaIndex; // Index to current Antenna (both Tx and Rx).
@@ -530,7 +530,7 @@ typedef struct r8180_priv
530 long AdRxSsThreshold; // Signal strength threshold to switch antenna. 530 long AdRxSsThreshold; // Signal strength threshold to switch antenna.
531 long AdMaxRxSsThreshold; // Max value of AdRxSsThreshold. 531 long AdMaxRxSsThreshold; // Max value of AdRxSsThreshold.
532 bool bAdSwitchedChecking; // TRUE if we shall shall check Rx signal strength for last time switching antenna. 532 bool bAdSwitchedChecking; // TRUE if we shall shall check Rx signal strength for last time switching antenna.
533 long AdRxSsBeforeSwitched; // Rx signal strength before we swithed antenna. 533 long AdRxSsBeforeSwitched; // Rx signal strength before we switched antenna.
534 struct timer_list SwAntennaDiversityTimer; 534 struct timer_list SwAntennaDiversityTimer;
535//by amy for antenna 535//by amy for antenna
536//{by amy 080312 536//{by amy 080312
@@ -553,7 +553,7 @@ typedef struct r8180_priv
553 bool bDigMechanism; // TRUE if DIG is enabled, FALSE ow. 553 bool bDigMechanism; // TRUE if DIG is enabled, FALSE ow.
554 bool bRegHighPowerMechanism; // For High Power Mechanism. 061010, by rcnjko. 554 bool bRegHighPowerMechanism; // For High Power Mechanism. 061010, by rcnjko.
555 u32 FalseAlarmRegValue; 555 u32 FalseAlarmRegValue;
556 u8 RegDigOfdmFaUpTh; // Upper threhold of OFDM false alarm, which is used in DIG. 556 u8 RegDigOfdmFaUpTh; // Upper threshold of OFDM false alarm, which is used in DIG.
557 u8 DIG_NumberFallbackVote; 557 u8 DIG_NumberFallbackVote;
558 u8 DIG_NumberUpgradeVote; 558 u8 DIG_NumberUpgradeVote;
559 // For HW antenna diversity, added by Roger, 2008.01.30. 559 // For HW antenna diversity, added by Roger, 2008.01.30.
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 4fe52f6b0034..fd22b75aea4f 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -1329,7 +1329,7 @@ u16 N_DBPSOfRate(u16 DataRate)
1329} 1329}
1330 1330
1331/* 1331/*
1332 * For Netgear case, they want good-looking singal strength. 1332 * For Netgear case, they want good-looking signal strength.
1333 */ 1333 */
1334long NetgearSignalStrengthTranslate(long LastSS, long CurrSS) 1334long NetgearSignalStrengthTranslate(long LastSS, long CurrSS)
1335{ 1335{
@@ -1380,7 +1380,7 @@ long TranslateToDbm8185(u8 SignalStrengthIndex)
1380 1380
1381/* 1381/*
1382 * Perform signal smoothing for dynamic mechanism. 1382 * Perform signal smoothing for dynamic mechanism.
1383 * This is different with PerformSignalSmoothing8185 in smoothing fomula. 1383 * This is different with PerformSignalSmoothing8185 in smoothing formula.
1384 * No dramatic adjustion is apply because dynamic mechanism need some degree 1384 * No dramatic adjustion is apply because dynamic mechanism need some degree
1385 * of correctness. Ported from 8187B. 1385 * of correctness. Ported from 8187B.
1386 */ 1386 */
@@ -1535,7 +1535,7 @@ void rtl8180_rx(struct net_device *dev)
1535 /* HW is probably passing several buggy frames 1535 /* HW is probably passing several buggy frames
1536 * without FD or LD flag set. 1536 * without FD or LD flag set.
1537 * Throw this garbage away to prevent skb 1537 * Throw this garbage away to prevent skb
1538 * memory exausting 1538 * memory exhausting
1539 */ 1539 */
1540 if (!priv->rx_skb_complete) 1540 if (!priv->rx_skb_complete)
1541 dev_kfree_skb_any(priv->rx_skb); 1541 dev_kfree_skb_any(priv->rx_skb);
@@ -1648,14 +1648,14 @@ void rtl8180_rx(struct net_device *dev)
1648 priv->Stats_SignalQuality = (long)(priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6; 1648 priv->Stats_SignalQuality = (long)(priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
1649 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower - 1) / 6; 1649 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower - 1) / 6;
1650 1650
1651 /* Figure out which antenna that received the lasted packet. */ 1651 /* Figure out which antenna that received the last packet. */
1652 priv->LastRxPktAntenna = Antenna ? 1 : 0; /* 0: aux, 1: main. */ 1652 priv->LastRxPktAntenna = Antenna ? 1 : 0; /* 0: aux, 1: main. */
1653 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength); 1653 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
1654 } 1654 }
1655 1655
1656 if (first) { 1656 if (first) {
1657 if (!priv->rx_skb_complete) { 1657 if (!priv->rx_skb_complete) {
1658 /* seems that HW sometimes fails to reiceve and 1658 /* seems that HW sometimes fails to receive and
1659 doesn't provide the last descriptor */ 1659 doesn't provide the last descriptor */
1660 dev_kfree_skb_any(priv->rx_skb); 1660 dev_kfree_skb_any(priv->rx_skb);
1661 priv->stats.rxnolast++; 1661 priv->stats.rxnolast++;
@@ -1672,7 +1672,7 @@ void rtl8180_rx(struct net_device *dev)
1672 priv->rx_skb_complete = 0; 1672 priv->rx_skb_complete = 0;
1673 priv->rx_skb->dev = dev; 1673 priv->rx_skb->dev = dev;
1674 } else { 1674 } else {
1675 /* if we are here we should have already RXed 1675 /* if we are here we should have already RXed
1676 * the first frame. 1676 * the first frame.
1677 * If we get here and the skb is not allocated then 1677 * If we get here and the skb is not allocated then
1678 * we have just throw out garbage (skb not allocated) 1678 * we have just throw out garbage (skb not allocated)
@@ -1821,15 +1821,15 @@ rate) {
1821/* 1821/*
1822 * This is a rough attempt to TX a frame 1822 * This is a rough attempt to TX a frame
1823 * This is called by the ieee 80211 stack to TX management frames. 1823 * This is called by the ieee 80211 stack to TX management frames.
1824 * If the ring is full packet are dropped (for data frame the queue 1824 * If the ring is full packets are dropped (for data frame the queue
1825 * is stopped before this can happen). For this reason it is better 1825 * is stopped before this can happen). For this reason it is better
1826 * if the descriptors are larger than the largest management frame 1826 * if the descriptors are larger than the largest management frame
1827 * we intend to TX: i'm unsure what the HW does if it will not found 1827 * we intend to TX: i'm unsure what the HW does if it will not find
1828 * the last fragment of a frame because it has been dropped... 1828 * the last fragment of a frame because it has been dropped...
1829 * Since queues for Management and Data frames are different we 1829 * Since queues for Management and Data frames are different we
1830 * might use a different lock than tx_lock (for example mgmt_tx_lock) 1830 * might use a different lock than tx_lock (for example mgmt_tx_lock)
1831 */ 1831 */
1832/* these function may loops if invoked with 0 descriptors or 0 len buffer */ 1832/* these function may loop if invoked with 0 descriptors or 0 len buffer */
1833int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 1833int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1834{ 1834{
1835 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1835 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
@@ -2003,8 +2003,7 @@ short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, int priority,
2003 } 2003 }
2004 2004
2005 memcpy(&dest, frag_hdr->addr1, ETH_ALEN); 2005 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
2006 if (is_multicast_ether_addr(dest) || 2006 if (is_multicast_ether_addr(dest)) {
2007 is_broadcast_ether_addr(dest)) {
2008 Duration = 0; 2007 Duration = 0;
2009 RtsDur = 0; 2008 RtsDur = 0;
2010 bRTSEnable = 0; 2009 bRTSEnable = 0;
@@ -2378,7 +2377,7 @@ void rtl8180_wmm_param_update(struct work_struct *work)
2378 u8 u1bAIFS; 2377 u8 u1bAIFS;
2379 u32 u4bAcParam; 2378 u32 u4bAcParam;
2380 pAcParam = (PAC_PARAM)(&AcParam); 2379 pAcParam = (PAC_PARAM)(&AcParam);
2381 /* Retrive paramters to udpate. */ 2380 /* Retrieve paramters to update. */
2382 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime; 2381 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
2383 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)| 2382 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
2384 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)| 2383 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
@@ -2414,7 +2413,7 @@ void rtl8180_wmm_param_update(struct work_struct *work)
2414 u8 u1bAIFS; 2413 u8 u1bAIFS;
2415 u32 u4bAcParam; 2414 u32 u4bAcParam;
2416 2415
2417 /* Retrive paramters to udpate. */ 2416 /* Retrieve paramters to update. */
2418 eACI = pAcParam->f.AciAifsn.f.ACI; 2417 eACI = pAcParam->f.AciAifsn.f.ACI;
2419 /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */ 2418 /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
2420 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime; 2419 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
@@ -2700,7 +2699,7 @@ short rtl8180_init(struct net_device *dev)
2700 priv->bTxPowerTrack = false; 2699 priv->bTxPowerTrack = false;
2701 priv->ThermalMeter = 0; 2700 priv->ThermalMeter = 0;
2702 priv->FalseAlarmRegValue = 0; 2701 priv->FalseAlarmRegValue = 0;
2703 priv->RegDigOfdmFaUpTh = 0xc; /* Upper threhold of OFDM false alarm, which is used in DIG. */ 2702 priv->RegDigOfdmFaUpTh = 0xc; /* Upper threshold of OFDM false alarm, which is used in DIG. */
2704 priv->DIG_NumberFallbackVote = 0; 2703 priv->DIG_NumberFallbackVote = 0;
2705 priv->DIG_NumberUpgradeVote = 0; 2704 priv->DIG_NumberUpgradeVote = 0;
2706 priv->LastSignalStrengthInPercent = 0; 2705 priv->LastSignalStrengthInPercent = 0;
@@ -2896,7 +2895,7 @@ short rtl8180_init(struct net_device *dev)
2896 priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8; 2895 priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8;
2897 } 2896 }
2898 2897
2899 /* 3Read crystal calibtration and thermal meter indication on 87SE. */ 2898 /* 3Read crystal calibration and thermal meter indication on 87SE. */
2900 eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16); 2899 eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16);
2901 2900
2902 /* Crystal calibration for Xin and Xout resp. */ 2901 /* Crystal calibration for Xin and Xout resp. */
@@ -3140,7 +3139,7 @@ void rtl8180_adapter_start(struct net_device *dev)
3140 3139
3141 /* 3140 /*
3142 * The following is very strange. seems to be that 1 means test mode, 3141 * The following is very strange. seems to be that 1 means test mode,
3143 * but we need to acknolwledges the nic when a packet is ready 3142 * but we need to acknowledges the nic when a packet is ready
3144 * although we set it to 0 3143 * although we set it to 0
3145 */ 3144 */
3146 3145
@@ -3971,7 +3970,7 @@ irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
3971 } 3970 }
3972 3971
3973 if (inta == 0xffff) { 3972 if (inta == 0xffff) {
3974 /* HW disappared */ 3973 /* HW disappeared */
3975 spin_unlock_irqrestore(&priv->irq_th_lock, flags); 3974 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3976 return IRQ_HANDLED; 3975 return IRQ_HANDLED;
3977 } 3976 }
diff --git a/drivers/staging/rtl8187se/r8180_dm.c b/drivers/staging/rtl8187se/r8180_dm.c
index 4d7a5951486e..b8f2ba010a04 100644
--- a/drivers/staging/rtl8187se/r8180_dm.c
+++ b/drivers/staging/rtl8187se/r8180_dm.c
@@ -2,7 +2,7 @@
2#include "r8180_hw.h" 2#include "r8180_hw.h"
3#include "r8180_93cx6.h" 3#include "r8180_93cx6.h"
4 4
5 /* Return TRUE if we shall perform High Power Mecahnism, FALSE otherwise. */ 5 /* Return TRUE if we shall perform High Power Mechanism, FALSE otherwise. */
6#define RATE_ADAPTIVE_TIMER_PERIOD 300 6#define RATE_ADAPTIVE_TIMER_PERIOD 300
7 7
8bool CheckHighPower(struct net_device *dev) 8bool CheckHighPower(struct net_device *dev)
@@ -105,7 +105,7 @@ void rtl8180_tx_pw_wq(struct work_struct *work)
105 105
106 106
107/* 107/*
108 * Return TRUE if we shall perform DIG Mecahnism, FALSE otherwise. 108 * Return TRUE if we shall perform DIG Mechanism, FALSE otherwise.
109 */ 109 */
110bool CheckDig(struct net_device *dev) 110bool CheckDig(struct net_device *dev)
111{ 111{
@@ -507,7 +507,7 @@ void StaRateAdaptive87SE(struct net_device *dev)
507 * and retry rate. 507 * and retry rate.
508 * (3) Remove all Initial Gain Updates over OFDM rate. To avoid the complicated 508 * (3) Remove all Initial Gain Updates over OFDM rate. To avoid the complicated
509 * situation, Initial Gain Update is upon on DIG mechanism except CCK rate. 509 * situation, Initial Gain Update is upon on DIG mechanism except CCK rate.
510 * (4) Add the mehanism of trying to upgrade tx rate. 510 * (4) Add the mechanism of trying to upgrade tx rate.
511 * (5) Record the information of upping tx rate to avoid trying upping tx rate constantly. 511 * (5) Record the information of upping tx rate to avoid trying upping tx rate constantly.
512 * 512 *
513 */ 513 */
@@ -528,7 +528,7 @@ void StaRateAdaptive87SE(struct net_device *dev)
528 if (priv->bTryuping == true) { 528 if (priv->bTryuping == true) {
529 /* 2 For Test Upgrading mechanism 529 /* 2 For Test Upgrading mechanism
530 * Note: 530 * Note:
531 * Sometimes the throughput is upon on the capability bwtween the AP and NIC, 531 * Sometimes the throughput is upon on the capability between the AP and NIC,
532 * thus the low data rate does not improve the performance. 532 * thus the low data rate does not improve the performance.
533 * We randomly upgrade the data rate and check if the retry rate is improved. 533 * We randomly upgrade the data rate and check if the retry rate is improved.
534 */ 534 */
@@ -704,7 +704,7 @@ void StaRateAdaptive87SE(struct net_device *dev)
704 704
705 /* 705 /*
706 * The difference in throughput between 48Mbps and 36Mbps is 8M. 706 * The difference in throughput between 48Mbps and 36Mbps is 8M.
707 * So, we must be carefully in this rate scale. Isaiah 2008-02-15. 707 * So, we must be careful in this rate scale. Isaiah 2008-02-15.
708 */ 708 */
709 if (((priv->CurrentOperaRate == 72) || (priv->CurrentOperaRate == 48) || (priv->CurrentOperaRate == 36)) && 709 if (((priv->CurrentOperaRate == 72) || (priv->CurrentOperaRate == 48) || (priv->CurrentOperaRate == 36)) &&
710 (priv->FailTxRateCount > 2)) 710 (priv->FailTxRateCount > 2))
@@ -1009,7 +1009,7 @@ void SwAntennaDiversity(struct net_device *dev)
1009 if (priv->AdCheckPeriod > priv->AdMaxCheckPeriod) 1009 if (priv->AdCheckPeriod > priv->AdMaxCheckPeriod)
1010 priv->AdCheckPeriod = priv->AdMaxCheckPeriod; 1010 priv->AdCheckPeriod = priv->AdMaxCheckPeriod;
1011 1011
1012 /* Wrong deceision => switch back. */ 1012 /* Wrong decision => switch back. */
1013 SwitchAntenna(dev); 1013 SwitchAntenna(dev);
1014 } else { 1014 } else {
1015 /* Rx Signal Strength is improved. */ 1015 /* Rx Signal Strength is improved. */
@@ -1057,7 +1057,7 @@ void SwAntennaDiversity(struct net_device *dev)
1057 } 1057 }
1058 /* 1058 /*
1059 * <Roger_Notes> We evaluate Rx signal strength ONLY when default antenna 1059 * <Roger_Notes> We evaluate Rx signal strength ONLY when default antenna
1060 * didn't changed by HW evaluation. 1060 * didn't change by HW evaluation.
1061 * 2008.02.27. 1061 * 2008.02.27.
1062 * 1062 *
1063 * [TRC Dell Lab] SignalStrength is inaccuracy. Isaiah 2008-03-05 1063 * [TRC Dell Lab] SignalStrength is inaccuracy. Isaiah 2008-03-05
@@ -1098,7 +1098,7 @@ void SwAntennaDiversity(struct net_device *dev)
1098 priv->AdAuxAntennaRxOkCnt = 0; 1098 priv->AdAuxAntennaRxOkCnt = 0;
1099} 1099}
1100 1100
1101 /* Return TRUE if we shall perform Tx Power Tracking Mecahnism, FALSE otherwise. */ 1101 /* Return TRUE if we shall perform Tx Power Tracking Mechanism, FALSE otherwise. */
1102bool CheckTxPwrTracking(struct net_device *dev) 1102bool CheckTxPwrTracking(struct net_device *dev)
1103{ 1103{
1104 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1104 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
diff --git a/drivers/staging/rtl8187se/r8180_rtl8225z2.c b/drivers/staging/rtl8187se/r8180_rtl8225z2.c
index ee5b867fd0d4..d28c1d996084 100644
--- a/drivers/staging/rtl8187se/r8180_rtl8225z2.c
+++ b/drivers/staging/rtl8187se/r8180_rtl8225z2.c
@@ -190,7 +190,7 @@ static void rtl8225_SetTXPowerLevel(struct net_device *dev, short ch)
190 write_phy_cck(dev, 0x44 + i, power); 190 write_phy_cck(dev, 0x44 + i, power);
191 } 191 }
192 192
193 /* FIXME Is this delay really needeed ? */ 193 /* FIXME Is this delay really needed ? */
194 force_pci_posting(dev); 194 force_pci_posting(dev);
195 mdelay(1); 195 mdelay(1);
196 196
@@ -479,7 +479,7 @@ s8 DbmToTxPwrIdx(struct r8180_priv *priv, WIRELESS_MODE WirelessMode,
479 479
480 /* 480 /*
481 * TRUE if we want to use a default implementation. 481 * TRUE if we want to use a default implementation.
482 * We shall set it to FALSE when we have exact translation formular 482 * We shall set it to FALSE when we have exact translation formula
483 * for target IC. 070622, by rcnjko. 483 * for target IC. 070622, by rcnjko.
484 */ 484 */
485 if (bUseDefault) { 485 if (bUseDefault) {
diff --git a/drivers/staging/rtl8187se/r8180_wx.c b/drivers/staging/rtl8187se/r8180_wx.c
index 303ec691262a..46ee6f47f525 100644
--- a/drivers/staging/rtl8187se/r8180_wx.c
+++ b/drivers/staging/rtl8187se/r8180_wx.c
@@ -13,7 +13,7 @@
13 13
14 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 14 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
15 15
16 We want to tanks the Authors of those projects and the Ndiswrapper 16 We want to thanks the Authors of those projects and the Ndiswrapper
17 project Authors. 17 project Authors.
18*/ 18*/
19 19
@@ -1181,7 +1181,7 @@ static iw_handler r8180_wx_handlers[] = {
1181 r8180_wx_set_wap, /* SIOCSIWAP */ 1181 r8180_wx_set_wap, /* SIOCSIWAP */
1182 r8180_wx_get_wap, /* SIOCGIWAP */ 1182 r8180_wx_get_wap, /* SIOCGIWAP */
1183 r8180_wx_set_mlme, /* SIOCSIWMLME*/ 1183 r8180_wx_set_mlme, /* SIOCSIWMLME*/
1184 dummy, /* SIOCGIWAPLIST -- depricated */ 1184 dummy, /* SIOCGIWAPLIST -- deprecated */
1185 r8180_wx_set_scan, /* SIOCSIWSCAN */ 1185 r8180_wx_set_scan, /* SIOCSIWSCAN */
1186 r8180_wx_get_scan, /* SIOCGIWSCAN */ 1186 r8180_wx_get_scan, /* SIOCGIWSCAN */
1187 r8180_wx_set_essid, /* SIOCSIWESSID */ 1187 r8180_wx_set_essid, /* SIOCSIWESSID */
@@ -1369,7 +1369,7 @@ static inline int is_same_network(struct ieee80211_network *src,
1369 (dst->capability & WLAN_CAPABILITY_BSS))); 1369 (dst->capability & WLAN_CAPABILITY_BSS)));
1370} 1370}
1371 1371
1372/* WB modefied to show signal to GUI on 18-01-2008 */ 1372/* WB modified to show signal to GUI on 18-01-2008 */
1373static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev) 1373static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev)
1374{ 1374{
1375 struct r8180_priv *priv = ieee80211_priv(dev); 1375 struct r8180_priv *priv = ieee80211_priv(dev);
diff --git a/drivers/staging/rtl8187se/r8180_wx.h b/drivers/staging/rtl8187se/r8180_wx.h
index 735d03dceed3..408191403112 100644
--- a/drivers/staging/rtl8187se/r8180_wx.h
+++ b/drivers/staging/rtl8187se/r8180_wx.h
@@ -7,7 +7,7 @@
7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon 7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon
8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
9 9
10 We want to tanks the Authors of such projects and the Ndiswrapper project Authors. 10 We want to thanks the Authors of such projects and the Ndiswrapper project Authors.
11*/ 11*/
12 12
13/* this file (will) contains wireless extension handlers*/ 13/* this file (will) contains wireless extension handlers*/
diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c
index 4b0b830f9ab6..914495783c06 100644
--- a/drivers/staging/rtl8187se/r8185b_init.c
+++ b/drivers/staging/rtl8187se/r8185b_init.c
@@ -1,22 +1,22 @@
1/*++ 1/*
2Copyright (c) Realtek Semiconductor Corp. All rights reserved. 2 * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
3 3 *
4Module Name: 4 * Module Name:
5 r8185b_init.c 5 * r8185b_init.c
6 6 *
7Abstract: 7 * Abstract:
8 Hardware Initialization and Hardware IO for RTL8185B 8 * Hardware Initialization and Hardware IO for RTL8185B
9 9 *
10Major Change History: 10 * Major Change History:
11 When Who What 11 * When Who What
12 ---------- --------------- ------------------------------- 12 * ---------- --------------- -------------------------------
13 2006-11-15 Xiong Created 13 * 2006-11-15 Xiong Created
14 14 *
15Notes: 15 * Notes:
16 This file is ported from RTL8185B Windows driver. 16 * This file is ported from RTL8185B Windows driver.
17 17 *
18 18 *
19--*/ 19 */
20 20
21/*--------------------------Include File------------------------------------*/ 21/*--------------------------Include File------------------------------------*/
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
@@ -25,155 +25,134 @@ Notes:
25#include "r8180_rtl8225.h" /* RTL8225 Radio frontend */ 25#include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
26#include "r8180_93cx6.h" /* Card EEPROM */ 26#include "r8180_93cx6.h" /* Card EEPROM */
27#include "r8180_wx.h" 27#include "r8180_wx.h"
28
29#include "ieee80211/dot11d.h" 28#include "ieee80211/dot11d.h"
30
31
32/* #define CONFIG_RTL8180_IO_MAP */ 29/* #define CONFIG_RTL8180_IO_MAP */
33
34#define TC_3W_POLL_MAX_TRY_CNT 5 30#define TC_3W_POLL_MAX_TRY_CNT 5
31
35static u8 MAC_REG_TABLE[][2] = { 32static u8 MAC_REG_TABLE[][2] = {
36 /*PAGA 0: */ 33 /*PAGA 0: */
37 /* 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185() */ 34 /* 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185() */
38 /* 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185(). */ 35 /* 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185(). */
39 /* 0x1F0~0x1F8 set in MacConfig_85BASIC() */ 36 /* 0x1F0~0x1F8 set in MacConfig_85BASIC() */
40 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42}, 37 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
41 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03}, 38 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
42 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03}, 39 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
43 {0x94, 0x0F}, {0x95, 0x32}, 40 {0x94, 0x0F}, {0x95, 0x32},
44 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00}, 41 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
45 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32}, 42 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
46 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4}, 43 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
47 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00}, 44 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
48 {0xff, 0x00}, 45 {0xff, 0x00},
49 46
50 /*PAGE 1: */ 47 /*PAGE 1: */
51 /* For Flextronics system Logo PCIHCT failure: */ 48 /* For Flextronics system Logo PCIHCT failure: */
52 /* 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1 */ 49 /* 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1 */
53 {0x5e, 0x01}, 50 {0x5e, 0x01},
54 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24}, 51 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
55 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF}, 52 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
56 {0x82, 0xFF}, {0x83, 0x03}, 53 {0x82, 0xFF}, {0x83, 0x03},
57 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, /* lzm add 080826 */ 54 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, /* lzm add 080826 */
58 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},/* lzm add 080826 */ 55 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22}, /* lzm add 080826 */
59 {0xe2, 0x00}, 56 {0xe2, 0x00},
60 57
61 58
62 /* PAGE 2: */ 59 /* PAGE 2: */
63 {0x5e, 0x02}, 60 {0x5e, 0x02},
64 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5}, 61 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
65 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff}, 62 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
66 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08}, 63 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
67 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f}, 64 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
68 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f}, 65 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
69 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff}, 66 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
70 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00}, 67 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
71 68
72 /* PAGA 0: */ 69 /* PAGA 0: */
73 {0x5e, 0x00}, {0x9f, 0x03} 70 {0x5e, 0x00}, {0x9f, 0x03}
74 }; 71 };
75 72
76 73
77static u8 ZEBRA_AGC[] = { 74static u8 ZEBRA_AGC[] = {
78 0, 75 0,
79 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 76 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72,
80 0x71, 0x70, 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 77 0x71, 0x70, 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62,
81 0x48, 0x47, 0x46, 0x45, 0x44, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x08, 0x07, 78 0x48, 0x47, 0x46, 0x45, 0x44, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x08, 0x07,
82 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x15, 0x16, 80 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x15, 0x16,
84 0x17, 0x17, 0x18, 0x18, 0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e, 81 0x17, 0x17, 0x18, 0x18, 0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e,
85 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23, 0x24, 82 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23, 0x24,
86 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F 83 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F
87 }; 84 };
88 85
89static u32 ZEBRA_RF_RX_GAIN_TABLE[] = { 86static u32 ZEBRA_RF_RX_GAIN_TABLE[] = {
90 0x0096, 0x0076, 0x0056, 0x0036, 0x0016, 0x01f6, 0x01d6, 0x01b6, 87 0x0096, 0x0076, 0x0056, 0x0036, 0x0016, 0x01f6, 0x01d6, 0x01b6,
91 0x0196, 0x0176, 0x00F7, 0x00D7, 0x00B7, 0x0097, 0x0077, 0x0057, 88 0x0196, 0x0176, 0x00F7, 0x00D7, 0x00B7, 0x0097, 0x0077, 0x0057,
92 0x0037, 0x00FB, 0x00DB, 0x00BB, 0x00FF, 0x00E3, 0x00C3, 0x00A3, 89 0x0037, 0x00FB, 0x00DB, 0x00BB, 0x00FF, 0x00E3, 0x00C3, 0x00A3,
93 0x0083, 0x0063, 0x0043, 0x0023, 0x0003, 0x01E3, 0x01C3, 0x01A3, 90 0x0083, 0x0063, 0x0043, 0x0023, 0x0003, 0x01E3, 0x01C3, 0x01A3,
94 0x0183, 0x0163, 0x0143, 0x0123, 0x0103 91 0x0183, 0x0163, 0x0143, 0x0123, 0x0103
95 }; 92 };
96 93
97static u8 OFDM_CONFIG[] = { 94static u8 OFDM_CONFIG[] = {
98 /* OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX */ 95 /* OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX */
99 /* OFDM reg0x3C[4]=1'b1: Enable RX power saving mode */ 96 /* OFDM reg0x3C[4]=1'b1: Enable RX power saving mode */
100 /* ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test */ 97 /* ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test */
101 98 /* 0x00 */
102 /* 0x00 */ 99 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
103 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50, 100 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
104 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 101 /* 0x10 */
105 /* 0x10 */ 102 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
106 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26, 103 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
107 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB, 104 /* 0x20 */
108 /* 0x20 */ 105 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
109 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00, 106 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
110 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00, 107 /* 0x30 */
111 /* 0x30 */ 108 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
112 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e, 109 0xD8, 0x3C, 0x7B, 0x10, 0x10
113 0xD8, 0x3C, 0x7B, 0x10, 0x10 110 };
114 }; 111
115 112 /*---------------------------------------------------------------
116/* --------------------------------------------------------------- 113 * Hardware IO
117 * Hardware IO 114 * the code is ported from Windows source code
118 * the code is ported from Windows source code 115 *---------------------------------------------------------------
119 ----------------------------------------------------------------*/ 116 */
120 117
121void 118void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data)
122PlatformIOWrite1Byte(
123 struct net_device *dev,
124 u32 offset,
125 u8 data
126 )
127{ 119{
128 write_nic_byte(dev, offset, data); 120 write_nic_byte(dev, offset, data);
129 read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ 121 read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
130
131} 122}
132 123
133void 124void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data)
134PlatformIOWrite2Byte(
135 struct net_device *dev,
136 u32 offset,
137 u16 data
138 )
139{ 125{
140 write_nic_word(dev, offset, data); 126 write_nic_word(dev, offset, data);
141 read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ 127 read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
142
143
144} 128}
129
145u8 PlatformIORead1Byte(struct net_device *dev, u32 offset); 130u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
146 131
147void 132void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data)
148PlatformIOWrite4Byte(
149 struct net_device *dev,
150 u32 offset,
151 u32 data
152 )
153{ 133{
154/* {by amy 080312 */ 134 if (offset == PhyAddr) {
155if (offset == PhyAddr) { 135 /* For Base Band configuration. */
156/* For Base Band configuration. */
157 unsigned char cmdByte; 136 unsigned char cmdByte;
158 unsigned long dataBytes; 137 unsigned long dataBytes;
159 unsigned char idx; 138 unsigned char idx;
160 u8 u1bTmp; 139 u8 u1bTmp;
161 140
162 cmdByte = (u8)(data & 0x000000ff); 141 cmdByte = (u8)(data & 0x000000ff);
163 dataBytes = data>>8; 142 dataBytes = data>>8;
164 143
165 /* 144 /*
166 071010, rcnjko: 145 * 071010, rcnjko:
167 The critical section is only BB read/write race condition. 146 * The critical section is only BB read/write race condition.
168 Assumption: 147 * Assumption:
169 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for 148 * 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
170 acquiring the spinlock in such context. 149 * acquiring the spinlock in such context.
171 2. PlatformIOWrite4Byte() MUST NOT be recursive. 150 * 2. PlatformIOWrite4Byte() MUST NOT be recursive.
172 */ 151 */
173/* NdisAcquireSpinLock( &(pDevice->IoSpinLock) ); */ 152 /* NdisAcquireSpinLock( &(pDevice->IoSpinLock) ); */
174 153
175 for (idx = 0; idx < 30; idx++) { 154 for (idx = 0; idx < 30; idx++) {
176 /* Make sure command bit is clear before access it. */ 155 /* Make sure command bit is clear before access it. */
177 u1bTmp = PlatformIORead1Byte(dev, PhyAddr); 156 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
178 if ((u1bTmp & BIT7) == 0) 157 if ((u1bTmp & BIT7) == 0)
179 break; 158 break;
@@ -186,20 +165,14 @@ if (offset == PhyAddr) {
186 165
187 write_nic_byte(dev, offset, cmdByte); 166 write_nic_byte(dev, offset, cmdByte);
188 167
189/* NdisReleaseSpinLock( &(pDevice->IoSpinLock) ); */ 168 /* NdisReleaseSpinLock( &(pDevice->IoSpinLock) ); */
190 } 169 } else {
191/* by amy 080312} */
192 else {
193 write_nic_dword(dev, offset, data); 170 write_nic_dword(dev, offset, data);
194 read_nic_dword(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ 171 read_nic_dword(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
195 } 172 }
196} 173}
197 174
198u8 175u8 PlatformIORead1Byte(struct net_device *dev, u32 offset)
199PlatformIORead1Byte(
200 struct net_device *dev,
201 u32 offset
202 )
203{ 176{
204 u8 data = 0; 177 u8 data = 0;
205 178
@@ -209,11 +182,7 @@ PlatformIORead1Byte(
209 return data; 182 return data;
210} 183}
211 184
212u16 185u16 PlatformIORead2Byte(struct net_device *dev, u32 offset)
213PlatformIORead2Byte(
214 struct net_device *dev,
215 u32 offset
216 )
217{ 186{
218 u16 data = 0; 187 u16 data = 0;
219 188
@@ -223,11 +192,7 @@ PlatformIORead2Byte(
223 return data; 192 return data;
224} 193}
225 194
226u32 195u32 PlatformIORead4Byte(struct net_device *dev, u32 offset)
227PlatformIORead4Byte(
228 struct net_device *dev,
229 u32 offset
230 )
231{ 196{
232 u32 data = 0; 197 u32 data = 0;
233 198
@@ -242,22 +207,19 @@ void SetOutputEnableOfRfPins(struct net_device *dev)
242 write_nic_word(dev, RFPinsEnable, 0x1bff); 207 write_nic_word(dev, RFPinsEnable, 0x1bff);
243} 208}
244 209
245static int 210static int HwHSSIThreeWire(struct net_device *dev,
246HwHSSIThreeWire( 211 u8 *pDataBuf,
247 struct net_device *dev, 212 u8 nDataBufBitCnt,
248 u8 *pDataBuf, 213 int bSI,
249 u8 nDataBufBitCnt, 214 int bWrite)
250 int bSI,
251 int bWrite
252 )
253{ 215{
254 int bResult = 1; 216 int bResult = 1;
255 u8 TryCnt; 217 u8 TryCnt;
256 u8 u1bTmp; 218 u8 u1bTmp;
257 219
258 do { 220 do {
259 /* Check if WE and RE are cleared. */ 221 /* Check if WE and RE are cleared. */
260 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) { 222 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) {
261 u1bTmp = read_nic_byte(dev, SW_3W_CMD1); 223 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
262 if ((u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0) 224 if ((u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0)
263 break; 225 break;
@@ -275,15 +237,15 @@ HwHSSIThreeWire(
275 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG); 237 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
276 238
277 if (bSI) 239 if (bSI)
278 u1bTmp |= RF_SW_CFG_SI; /* reg08[1]=1 Serial Interface(SI) */ 240 u1bTmp |= RF_SW_CFG_SI; /* reg08[1]=1 Serial Interface(SI) */
279 241
280 else 242 else
281 u1bTmp &= ~RF_SW_CFG_SI; /* reg08[1]=0 Parallel Interface(PI) */ 243 u1bTmp &= ~RF_SW_CFG_SI; /* reg08[1]=0 Parallel Interface(PI) */
282 244
283 245
284 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp); 246 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
285 247
286 if (bSI) { 248 if (bSI) {
287 /* jong: HW SI read must set reg84[3]=0. */ 249 /* jong: HW SI read must set reg84[3]=0. */
288 u1bTmp = read_nic_byte(dev, RFPinsSelect); 250 u1bTmp = read_nic_byte(dev, RFPinsSelect);
289 u1bTmp &= ~BIT3; 251 u1bTmp &= ~BIT3;
@@ -291,14 +253,14 @@ HwHSSIThreeWire(
291 } 253 }
292 /* Fill up data buffer for write operation. */ 254 /* Fill up data buffer for write operation. */
293 255
294 if (bWrite) { 256 if (bWrite) {
295 if (nDataBufBitCnt == 16) { 257 if (nDataBufBitCnt == 16) {
296 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf)); 258 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
297 } else if (nDataBufBitCnt == 64) { 259 } else if (nDataBufBitCnt == 64) {
298 /* RTL8187S shouldn't enter this case */ 260 /* RTL8187S shouldn't enter this case */
299 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf)); 261 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
300 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4))); 262 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
301 } else { 263 } else {
302 int idx; 264 int idx;
303 int ByteCnt = nDataBufBitCnt / 8; 265 int ByteCnt = nDataBufBitCnt / 8;
304 /* printk("%d\n",nDataBufBitCnt); */ 266 /* printk("%d\n",nDataBufBitCnt); */
@@ -324,11 +286,11 @@ HwHSSIThreeWire(
324 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx)); 286 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
325 287
326 } 288 }
327 } else { /* read */ 289 } else { /* read */
328 if (bSI) { 290 if (bSI) {
329 /* SI - reg274[3:0] : RF register's Address */ 291 /* SI - reg274[3:0] : RF register's Address */
330 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf)); 292 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
331 } else { 293 } else {
332 /* PI - reg274[15:12] : RF register's Address */ 294 /* PI - reg274[15:12] : RF register's Address */
333 write_nic_word(dev, SW_3W_DB0, (*((u16 *)pDataBuf)) << 12); 295 write_nic_word(dev, SW_3W_DB0, (*((u16 *)pDataBuf)) << 12);
334 } 296 }
@@ -343,7 +305,7 @@ HwHSSIThreeWire(
343 305
344 306
345 /* Check if DONE is set. */ 307 /* Check if DONE is set. */
346 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) { 308 for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) {
347 u1bTmp = read_nic_byte(dev, SW_3W_CMD1); 309 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
348 if ((u1bTmp & SW_3W_CMD1_DONE) != 0) 310 if ((u1bTmp & SW_3W_CMD1_DONE) != 0)
349 break; 311 break;
@@ -353,12 +315,12 @@ HwHSSIThreeWire(
353 315
354 write_nic_byte(dev, SW_3W_CMD1, 0); 316 write_nic_byte(dev, SW_3W_CMD1, 0);
355 317
356 /* Read back data for read operation. */ 318 /* Read back data for read operation. */
357 if (bWrite == 0) { 319 if (bWrite == 0) {
358 if (bSI) { 320 if (bSI) {
359 /* Serial Interface : reg363_362[11:0] */ 321 /* Serial Interface : reg363_362[11:0] */
360 *((u16 *)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ; 322 *((u16 *)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
361 } else { 323 } else {
362 /* Parallel Interface : reg361_360[11:0] */ 324 /* Parallel Interface : reg361_360[11:0] */
363 *((u16 *)pDataBuf) = read_nic_word(dev, PI_DATA_READ); 325 *((u16 *)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
364 } 326 }
@@ -366,13 +328,12 @@ HwHSSIThreeWire(
366 *((u16 *)pDataBuf) &= 0x0FFF; 328 *((u16 *)pDataBuf) &= 0x0FFF;
367 } 329 }
368 330
369 } while (0); 331 } while (0);
370 332
371 return bResult; 333 return bResult;
372} 334}
373 335
374void 336void RF_WriteReg(struct net_device *dev, u8 offset, u32 data)
375RF_WriteReg(struct net_device *dev, u8 offset, u32 data)
376{ 337{
377 u32 data2Write; 338 u32 data2Write;
378 u8 len; 339 u8 len;
@@ -400,11 +361,7 @@ u32 RF_ReadReg(struct net_device *dev, u8 offset)
400 361
401 362
402/* by Owen on 04/07/14 for writing BB register successfully */ 363/* by Owen on 04/07/14 for writing BB register successfully */
403void 364void WriteBBPortUchar(struct net_device *dev, u32 Data)
404WriteBBPortUchar(
405 struct net_device *dev,
406 u32 Data
407 )
408{ 365{
409 /* u8 TimeoutCounter; */ 366 /* u8 TimeoutCounter; */
410 u8 RegisterContent; 367 u8 RegisterContent;
@@ -421,11 +378,7 @@ WriteBBPortUchar(
421 } 378 }
422} 379}
423 380
424u8 381u8 ReadBBPortUchar(struct net_device *dev, u32 addr)
425ReadBBPortUchar(
426 struct net_device *dev,
427 u32 addr
428 )
429{ 382{
430 /*u8 TimeoutCounter; */ 383 /*u8 TimeoutCounter; */
431 u8 RegisterContent; 384 u8 RegisterContent;
@@ -435,66 +388,62 @@ ReadBBPortUchar(
435 388
436 return RegisterContent; 389 return RegisterContent;
437} 390}
438/* {by amy 080312 */
439/* 391/*
440 Description: 392 * Description:
441 Perform Antenna settings with antenna diversity on 87SE. 393 * Perform Antenna settings with antenna diversity on 87SE.
442 Created by Roger, 2008.01.25. 394 * Created by Roger, 2008.01.25.
443*/ 395 */
444bool 396bool SetAntennaConfig87SE(struct net_device *dev,
445SetAntennaConfig87SE( 397 u8 DefaultAnt, /* 0: Main, 1: Aux. */
446 struct net_device *dev, 398 bool bAntDiversity) /* 1:Enable, 0: Disable. */
447 u8 DefaultAnt, /* 0: Main, 1: Aux. */
448 bool bAntDiversity /* 1:Enable, 0: Disable. */
449)
450{ 399{
451 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 400 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
452 bool bAntennaSwitched = true; 401 bool bAntennaSwitched = true;
453 402
454 /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */ 403 /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */
455 404
456 /* Threshold for antenna diversity. */ 405 /* Threshold for antenna diversity. */
457 write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */ 406 write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */
458 407
459 if (bAntDiversity) { /* Enable Antenna Diversity. */ 408 if (bAntDiversity) { /* Enable Antenna Diversity. */
460 if (DefaultAnt == 1) { /* aux antenna */ 409 if (DefaultAnt == 1) { /* aux antenna */
461 410
462 /* Mac register, aux antenna */ 411 /* Mac register, aux antenna */
463 write_nic_byte(dev, ANTSEL, 0x00); 412 write_nic_byte(dev, ANTSEL, 0x00);
464 413
465 /* Config CCK RX antenna. */ 414 /* Config CCK RX antenna. */
466 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ 415 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
467 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ 416 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */
468 417
469 /* Config OFDM RX antenna. */ 418 /* Config OFDM RX antenna. */
470 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ 419 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
471 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ 420 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */
472 } else { /* use main antenna */ 421 } else { /* use main antenna */
473 /* Mac register, main antenna */ 422 /* Mac register, main antenna */
474 write_nic_byte(dev, ANTSEL, 0x03); 423 write_nic_byte(dev, ANTSEL, 0x03);
475 /* base band */ 424 /* base band */
476 /* Config CCK RX antenna. */ 425 /* Config CCK RX antenna. */
477 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ 426 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
478 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ 427 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */
479 428
480 /* Config OFDM RX antenna. */ 429 /* Config OFDM RX antenna. */
481 write_phy_ofdm(dev, 0x0d, 0x5c); /* Reg0d : 5c */ 430 write_phy_ofdm(dev, 0x0d, 0x5c); /* Reg0d : 5c */
482 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ 431 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */
483 } 432 }
484 } else { 433 } else {
485 /* Disable Antenna Diversity. */ 434 /* Disable Antenna Diversity. */
486 if (DefaultAnt == 1) { /* aux Antenna */ 435 if (DefaultAnt == 1) { /* aux Antenna */
487 /* Mac register, aux antenna */ 436 /* Mac register, aux antenna */
488 write_nic_byte(dev, ANTSEL, 0x00); 437 write_nic_byte(dev, ANTSEL, 0x00);
489 438
490 /* Config CCK RX antenna. */ 439 /* Config CCK RX antenna. */
491 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ 440 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
492 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */ 441 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
493 442
494 /* Config OFDM RX antenna. */ 443 /* Config OFDM RX antenna. */
495 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ 444 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
496 write_phy_ofdm(dev, 0x18, 0x32); /* Reg18 : 32 */ 445 write_phy_ofdm(dev, 0x18, 0x32); /* Reg18 : 32 */
497 } else { /* main Antenna */ 446 } else { /* main Antenna */
498 /* Mac register, main antenna */ 447 /* Mac register, main antenna */
499 write_nic_byte(dev, ANTSEL, 0x03); 448 write_nic_byte(dev, ANTSEL, 0x03);
500 449
@@ -502,25 +451,22 @@ SetAntennaConfig87SE(
502 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ 451 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
503 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */ 452 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
504 453
505 /* Config OFDM RX antenna. */ 454 /* Config OFDM RX antenna. */
506 write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */ 455 write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */
507 write_phy_ofdm(dev, 0x18, 0x32); /*Reg18 : 32 */ 456 write_phy_ofdm(dev, 0x18, 0x32); /*Reg18 : 32 */
508 } 457 }
509 } 458 }
510 priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */ 459 priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */
511 return bAntennaSwitched; 460 return bAntennaSwitched;
512} 461}
513/* by amy 080312 */
514/* 462/*
515--------------------------------------------------------------- 463 *--------------------------------------------------------------
516 * Hardware Initialization. 464 * Hardware Initialization.
517 * the code is ported from Windows source code 465 * the code is ported from Windows source code
518----------------------------------------------------------------*/ 466 *--------------------------------------------------------------
519 467 */
520void 468
521ZEBRA_Config_85BASIC_HardCode( 469void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev)
522 struct net_device *dev
523 )
524{ 470{
525 471
526 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 472 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
@@ -532,163 +478,151 @@ ZEBRA_Config_85BASIC_HardCode(
532 478
533 479
534/* 480/*
535============================================================================= 481 *===========================================================================
536 87S_PCIE :: RADIOCFG.TXT 482 * 87S_PCIE :: RADIOCFG.TXT
537============================================================================= 483 *===========================================================================
538*/ 484 */
539 485
540 486
541 /* Page1 : reg16-reg30 */ 487 /* Page1 : reg16-reg30 */
542 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); /* switch to page1 */ 488 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); /* switch to page1 */
543 u4bRF23 = RF_ReadReg(dev, 0x08); mdelay(1); 489 u4bRF23 = RF_ReadReg(dev, 0x08); mdelay(1);
544 u4bRF24 = RF_ReadReg(dev, 0x09); mdelay(1); 490 u4bRF24 = RF_ReadReg(dev, 0x09); mdelay(1);
545 491
546 if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) { 492 if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) {
547 d_cut = 1; 493 d_cut = 1;
548 printk(KERN_INFO "rtl8187se: card type changed from C- to D-cut\n"); 494 printk(KERN_INFO "rtl8187se: card type changed from C- to D-cut\n");
549 } 495 }
550 496
551 /* Page0 : reg0-reg15 */ 497 /* Page0 : reg0-reg15 */
552 498
553 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);/* 1 */ 499 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);/* 1 */
554 500 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
555 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1); 501 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);/* 2 */
556 502 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);/* 3 */
557 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);/* 2 */ 503 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
558 504 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
559 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);/* 3 */ 505 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
560 506 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
561 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); 507 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
562 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1); 508 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
563 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1); 509 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
564 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1); 510 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
565 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1); 511 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
566 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1); 512 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
567 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1); 513 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
568 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1); 514 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
569 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
570 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
571 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
572 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
573
574 515
575 /* Page1 : reg16-reg30 */ 516 /* Page1 : reg16-reg30 */
576 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); 517 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
577 518 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
578 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1); 519 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
579 520 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
580 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1); 521 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
581 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1); 522 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
582 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
583
584
585 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
586/* Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl. */ 523/* Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl. */
587 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1); 524 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
588 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1); 525 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
589 526
590 if (d_cut) { 527 if (d_cut) {
591 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1); 528 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
592 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); 529 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
593 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); /* RX LO buffer */ 530 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); /* RX LO buffer */
594 } else { 531 } else {
595 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1); 532 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
596 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); 533 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
597 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); /* RX LO buffer */ 534 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); /* RX LO buffer */
598 } 535 }
599 536
600 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); 537 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
601 538 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1); /* 6 */
602 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1); /* 6 */ 539 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
540 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
603 541
604 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1); 542 for (i = 0; i <= 36; i++) {
605 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1); 543 RF_WriteReg(dev, 0x01, i); mdelay(1);
606 for (i = 0; i <= 36; i++) {
607 RF_WriteReg(dev, 0x01, i); mdelay(1);
608 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1); 544 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
609 } 545 }
610 546
611 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /* 203, 343 */ 547 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /* 203, 343 */
612 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); /* 400 */ 548 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); /* 400 */
549 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30, and HSSI disable 137 */
550 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
613 551
614 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30, and HSSI disable 137 */ 552 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); /* Z4 synthesizer loop filter setting, 392 */
615 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 553 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
616 554
617 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); /* Z4 synthesizer loop filter setting, 392 */ 555 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); /* switch to reg0-reg15, and HSSI disable */
618 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 556 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
619 557
620 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); /* switch to reg0-reg15, and HSSI disable */ 558 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); /* CBC on, Tx Rx disable, High gain */
621 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 559 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
622 560
623 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); /* CBC on, Tx Rx disable, High gain */ 561 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); /* Z4 setted channel 1 */
624 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 562 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
625 563
626 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); /* Z4 setted channel 1 */ 564 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); /* LC calibration */
627 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 565 mdelay(200); /* Deay 200 ms. */ /* 0xfd */
566 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
567 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
628 568
629 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); /* LC calibration */ 569 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30 137, and HSSI disable 137 */
630 mdelay(200); /* Deay 200 ms. */ /* 0xfd */ 570 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
631 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
632 mdelay(10); /* Deay 10 ms. */ /* 0xfd */
633 571
634 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); /* switch to reg16-reg30 137, and HSSI disable 137 */ 572 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
635 mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 573 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
636 574 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
637 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1); 575 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
638 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
639 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
640 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
641 576
642 /* DAC calibration off 20070702 */ 577 /* DAC calibration off 20070702 */
643 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1); 578 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
644 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1); 579 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
645/* {by amy 080312 */
646 /* For crystal calibration, added by Roger, 2007.12.11. */ 580 /* For crystal calibration, added by Roger, 2007.12.11. */
647 if (priv->bXtalCalibration) { /* reg 30. */ 581 if (priv->bXtalCalibration) { /* reg 30. */
648 /* enable crystal calibration. 582 /*
649 RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0]. 583 * enable crystal calibration.
650 (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0 584 * RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
651 (3)RF signal on/off when calibration[13], default: on, set BIT13=0. 585 * (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
652 So we should minus 4 BITs offset. */ 586 * (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
653 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9); mdelay(1); 587 * So we should minus 4 BITs offset.
588 */
589 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9); mdelay(1);
654 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n", 590 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
655 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9); 591 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11 | BIT9);
656 } else { 592 } else {
657 /* using default value. Xin=6, Xout=6. */ 593 /* using default value. Xin=6, Xout=6. */
658 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); 594 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
659 } 595 }
660/* by amy 080312 */
661 596
662 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); /* switch to reg0-reg15, and HSSI enable */ 597 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); /* switch to reg0-reg15, and HSSI enable */
663 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); /* Rx BB start calibration, 00c//+edward */ 598 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); /* Rx BB start calibration, 00c//+edward */
664 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); /* temperature meter off */ 599 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); /* temperature meter off */
665 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); /* Rx mode */ 600 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); /* Rx mode */
666 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 601 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
667 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 602 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
668 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 603 mdelay(10); /* Deay 10 ms.*/ /* 0xfe */
669 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); /* Rx mode*/ /*+edward */ 604 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); /* Rx mode*/ /*+edward */
670 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); /* Rx mode*/ /*+edward */ 605 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); /* Rx mode*/ /*+edward */
671 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); /* Rx mode*/ /*+edward */ 606 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); /* Rx mode*/ /*+edward */
672 607 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */
673 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */ 608 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */
674 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); /* Rx mode*/ /*+edward */ 609 /* power save parameters. */
675 /* power save parameters. */
676 u1b24E = read_nic_byte(dev, 0x24E); 610 u1b24E = read_nic_byte(dev, 0x24E);
677 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6)))); 611 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
678 612
679 /*============================================================================= 613 /*=============================================================================
680 614 *
681 ============================================================================= 615 *===========================================================================
682 CCKCONF.TXT 616 * CCKCONF.TXT
683 ============================================================================= 617 *===========================================================================
684 */ 618 *
685 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27 619 * [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
686 CCK reg0x00[7]=1'b1 :power saving for TX (default) 620 * CCK reg0x00[7]=1'b1 :power saving for TX (default)
687 CCK reg0x00[6]=1'b1: power saving for RX (default) 621 * CCK reg0x00[6]=1'b1: power saving for RX (default)
688 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation. 622 * CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
689 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1 623 * CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
690 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0 624 * CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
691 */ 625 */
692 626
693 write_phy_cck(dev, 0x00, 0xc8); 627 write_phy_cck(dev, 0x00, 0xc8);
694 write_phy_cck(dev, 0x06, 0x1c); 628 write_phy_cck(dev, 0x06, 0x1c);
@@ -697,7 +631,7 @@ ZEBRA_Config_85BASIC_HardCode(
697 write_phy_cck(dev, 0x2f, 0x06); 631 write_phy_cck(dev, 0x2f, 0x06);
698 write_phy_cck(dev, 0x01, 0x46); 632 write_phy_cck(dev, 0x01, 0x46);
699 633
700 /* power control */ 634 /* power control */
701 write_nic_byte(dev, CCK_TXAGC, 0x10); 635 write_nic_byte(dev, CCK_TXAGC, 0x10);
702 write_nic_byte(dev, OFDM_TXAGC, 0x1B); 636 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
703 write_nic_byte(dev, ANTSEL, 0x03); 637 write_nic_byte(dev, ANTSEL, 0x03);
@@ -705,14 +639,14 @@ ZEBRA_Config_85BASIC_HardCode(
705 639
706 640
707 /* 641 /*
708 ============================================================================= 642 *===========================================================================
709 AGC.txt 643 * AGC.txt
710 ============================================================================= 644 *===========================================================================
711 */ 645 */
712 646
713 write_phy_ofdm(dev, 0x00, 0x12); 647 write_phy_ofdm(dev, 0x00, 0x12);
714 648
715 for (i = 0; i < 128; i++) { 649 for (i = 0; i < 128; i++) {
716 650
717 data = ZEBRA_AGC[i+1]; 651 data = ZEBRA_AGC[i+1];
718 data = data << 8; 652 data = data << 8;
@@ -730,49 +664,43 @@ ZEBRA_Config_85BASIC_HardCode(
730 PlatformIOWrite4Byte(dev, PhyAddr, 0x00001080); /* Annie, 2006-05-05 */ 664 PlatformIOWrite4Byte(dev, PhyAddr, 0x00001080); /* Annie, 2006-05-05 */
731 665
732 /* 666 /*
733 ============================================================================= 667 *===========================================================================
734 668 *
735 ============================================================================= 669 *===========================================================================
736 OFDMCONF.TXT 670 * OFDMCONF.TXT
737 ============================================================================= 671 *===========================================================================
738 */ 672 */
739 673
740 for (i = 0; i < 60; i++) { 674 for (i = 0; i < 60; i++) {
741 u4bRegOffset = i; 675 u4bRegOffset = i;
742 u4bRegValue = OFDM_CONFIG[i]; 676 u4bRegValue = OFDM_CONFIG[i];
743 677
744 WriteBBPortUchar(dev, 678 WriteBBPortUchar(dev,
745 (0x00000080 | 679 (0x00000080 |
746 (u4bRegOffset & 0x7f) | 680 (u4bRegOffset & 0x7f) |
747 ((u4bRegValue & 0xff) << 8))); 681 ((u4bRegValue & 0xff) << 8)));
748 } 682 }
749 683
750 /* 684 /*
751 ============================================================================= 685 *===========================================================================
752 by amy for antenna 686 * by amy for antenna
753 ============================================================================= 687 *===========================================================================
754 */ 688 */
755/* {by amy 080312 */
756 /* Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26. */ 689 /* Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26. */
757 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity); 690 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
758/* by amy 080312} */
759/* by amy for antenna */
760} 691}
761 692
762 693
763void 694void UpdateInitialGain(struct net_device *dev)
764UpdateInitialGain(
765 struct net_device *dev
766 )
767{ 695{
768 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 696 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
769 697
770 /* lzm add 080826 */ 698 /* lzm add 080826 */
771 if (priv->eRFPowerState != eRfOn) { 699 if (priv->eRFPowerState != eRfOn) {
772 /* Don't access BB/RF under disable PLL situation. 700 /* Don't access BB/RF under disable PLL situation.
773 RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n")); 701 * RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
774 Back to the original state 702 * Back to the original state
775 */ 703 */
776 priv->InitialGain = priv->InitialGainBackUp; 704 priv->InitialGain = priv->InitialGainBackUp;
777 return; 705 return;
778 } 706 }
@@ -826,7 +754,7 @@ UpdateInitialGain(
826 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1); 754 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
827 break; 755 break;
828 756
829 default: /* MP */ 757 default: /* MP */
830 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1); 758 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
831 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 759 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
832 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1); 760 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
@@ -834,14 +762,11 @@ UpdateInitialGain(
834 } 762 }
835} 763}
836/* 764/*
837 Description: 765 * Description:
838 Tx Power tracking mechanism routine on 87SE. 766 * Tx Power tracking mechanism routine on 87SE.
839 Created by Roger, 2007.12.11. 767 * Created by Roger, 2007.12.11.
840*/ 768 */
841void 769void InitTxPwrTracking87SE(struct net_device *dev)
842InitTxPwrTracking87SE(
843 struct net_device *dev
844)
845{ 770{
846 u32 u4bRfReg; 771 u32 u4bRfReg;
847 772
@@ -851,49 +776,41 @@ InitTxPwrTracking87SE(
851 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1); 776 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
852} 777}
853 778
854void 779void PhyConfig8185(struct net_device *dev)
855PhyConfig8185(
856 struct net_device *dev
857 )
858{ 780{
859 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 781 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
860 write_nic_dword(dev, RCR, priv->ReceiveConfig); 782 write_nic_dword(dev, RCR, priv->ReceiveConfig);
861 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03; 783 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
862 /* RF config */ 784 /* RF config */
863 ZEBRA_Config_85BASIC_HardCode(dev); 785 ZEBRA_Config_85BASIC_HardCode(dev);
864/* {by amy 080312 */
865 /* Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06. */ 786 /* Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06. */
866 if (priv->bDigMechanism) { 787 if (priv->bDigMechanism) {
867 if (priv->InitialGain == 0) 788 if (priv->InitialGain == 0)
868 priv->InitialGain = 4; 789 priv->InitialGain = 4;
869 } 790 }
870 791
871 /* 792 /*
872 Enable thermal meter indication to implement TxPower tracking on 87SE. 793 * Enable thermal meter indication to implement TxPower tracking on 87SE.
873 We initialize thermal meter here to avoid unsuccessful configuration. 794 * We initialize thermal meter here to avoid unsuccessful configuration.
874 Added by Roger, 2007.12.11. 795 * Added by Roger, 2007.12.11.
875 */ 796 */
876 if (priv->bTxPowerTrack) 797 if (priv->bTxPowerTrack)
877 InitTxPwrTracking87SE(dev); 798 InitTxPwrTracking87SE(dev);
878 799
879/* by amy 080312} */
880 priv->InitialGainBackUp = priv->InitialGain; 800 priv->InitialGainBackUp = priv->InitialGain;
881 UpdateInitialGain(dev); 801 UpdateInitialGain(dev);
882 802
883 return; 803 return;
884} 804}
885 805
886void 806void HwConfigureRTL8185(struct net_device *dev)
887HwConfigureRTL8185(
888 struct net_device *dev
889 )
890{ 807{
891 /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */ 808 /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */
892 u8 bUNIVERSAL_CONTROL_RL = 0; 809 u8 bUNIVERSAL_CONTROL_RL = 0;
893 u8 bUNIVERSAL_CONTROL_AGC = 1; 810 u8 bUNIVERSAL_CONTROL_AGC = 1;
894 u8 bUNIVERSAL_CONTROL_ANT = 1; 811 u8 bUNIVERSAL_CONTROL_ANT = 1;
895 u8 bAUTO_RATE_FALLBACK_CTL = 1; 812 u8 bAUTO_RATE_FALLBACK_CTL = 1;
896 u8 val8; 813 u8 val8;
897 write_nic_word(dev, BRSR, 0x0fff); 814 write_nic_word(dev, BRSR, 0x0fff);
898 /* Retry limit */ 815 /* Retry limit */
899 val8 = read_nic_byte(dev, CW_CONF); 816 val8 = read_nic_byte(dev, CW_CONF);
@@ -907,24 +824,24 @@ HwConfigureRTL8185(
907 824
908 /* Tx AGC */ 825 /* Tx AGC */
909 val8 = read_nic_byte(dev, TXAGC_CTL); 826 val8 = read_nic_byte(dev, TXAGC_CTL);
910 if (bUNIVERSAL_CONTROL_AGC) { 827 if (bUNIVERSAL_CONTROL_AGC) {
911 write_nic_byte(dev, CCK_TXAGC, 128); 828 write_nic_byte(dev, CCK_TXAGC, 128);
912 write_nic_byte(dev, OFDM_TXAGC, 128); 829 write_nic_byte(dev, OFDM_TXAGC, 128);
913 val8 = val8 & 0xfe; 830 val8 = val8 & 0xfe;
914 } else { 831 } else {
915 val8 = val8 | 0x01 ; 832 val8 = val8 | 0x01 ;
916 } 833 }
917 834
918 835
919 write_nic_byte(dev, TXAGC_CTL, val8); 836 write_nic_byte(dev, TXAGC_CTL, val8);
920 837
921 /* Tx Antenna including Feedback control */ 838 /* Tx Antenna including Feedback control */
922 val8 = read_nic_byte(dev, TXAGC_CTL); 839 val8 = read_nic_byte(dev, TXAGC_CTL);
923 840
924 if (bUNIVERSAL_CONTROL_ANT) { 841 if (bUNIVERSAL_CONTROL_ANT) {
925 write_nic_byte(dev, ANTSEL, 0x00); 842 write_nic_byte(dev, ANTSEL, 0x00);
926 val8 = val8 & 0xfd; 843 val8 = val8 & 0xfd;
927 } else { 844 } else {
928 val8 = val8 & (val8|0x02); /* xiong-2006-11-15 */ 845 val8 = val8 & (val8|0x02); /* xiong-2006-11-15 */
929 } 846 }
930 847
@@ -933,7 +850,7 @@ HwConfigureRTL8185(
933 /* Auto Rate fallback control */ 850 /* Auto Rate fallback control */
934 val8 = read_nic_byte(dev, RATE_FALLBACK); 851 val8 = read_nic_byte(dev, RATE_FALLBACK);
935 val8 &= 0x7c; 852 val8 &= 0x7c;
936 if (bAUTO_RATE_FALLBACK_CTL) { 853 if (bAUTO_RATE_FALLBACK_CTL) {
937 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1; 854 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
938 855
939 /* <RJ_TODO_8185B> We shall set up the ARFR according to user's setting. */ 856 /* <RJ_TODO_8185B> We shall set up the ARFR according to user's setting. */
@@ -942,40 +859,34 @@ HwConfigureRTL8185(
942 write_nic_byte(dev, RATE_FALLBACK, val8); 859 write_nic_byte(dev, RATE_FALLBACK, val8);
943} 860}
944 861
945static void 862static void MacConfig_85BASIC_HardCode(struct net_device *dev)
946MacConfig_85BASIC_HardCode(
947 struct net_device *dev)
948{ 863{
949 /* 864 /*
950 ============================================================================ 865 *==========================================================================
951 MACREG.TXT 866 * MACREG.TXT
952 ============================================================================ 867 *==========================================================================
953 */ 868 */
954 int nLinesRead = 0; 869 int nLinesRead = 0;
955 870 u32 u4bRegOffset, u4bRegValue, u4bPageIndex = 0;
956 u32 u4bRegOffset, u4bRegValue, u4bPageIndex = 0; 871 int i;
957 int i;
958 872
959 nLinesRead = sizeof(MAC_REG_TABLE)/2; 873 nLinesRead = sizeof(MAC_REG_TABLE)/2;
960 874
961 for (i = 0; i < nLinesRead; i++) { /* nLinesRead=101 */ 875 for (i = 0; i < nLinesRead; i++) { /* nLinesRead=101 */
962 u4bRegOffset = MAC_REG_TABLE[i][0]; 876 u4bRegOffset = MAC_REG_TABLE[i][0];
963 u4bRegValue = MAC_REG_TABLE[i][1]; 877 u4bRegValue = MAC_REG_TABLE[i][1];
964 878
965 if (u4bRegOffset == 0x5e) 879 if (u4bRegOffset == 0x5e)
966 u4bPageIndex = u4bRegValue; 880 u4bPageIndex = u4bRegValue;
967
968 else 881 else
969 u4bRegOffset |= (u4bPageIndex << 8); 882 u4bRegOffset |= (u4bPageIndex << 8);
970 883
971 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue); 884 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
972 } 885 }
973 /* ============================================================================ */ 886 /* ============================================================================ */
974} 887}
975 888
976static void 889static void MacConfig_85BASIC(struct net_device *dev)
977MacConfig_85BASIC(
978 struct net_device *dev)
979{ 890{
980 891
981 u8 u1DA; 892 u8 u1DA;
@@ -994,18 +905,18 @@ MacConfig_85BASIC(
994 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000); 905 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
995 PlatformIOWrite1Byte(dev, 0x1F8, 0x00); 906 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
996 907
997 /* Asked for by SD3 CM Lin, 2006.06.27, by rcnjko. */ 908 /* Asked for by SD3 CM Lin, 2006.06.27, by rcnjko. */
998 /* power save parameter based on "87SE power save parameters 20071127.doc", as follow. */ 909 /* power save parameter based on "87SE power save parameters 20071127.doc", as follow. */
999 910
1000 /* Enable DA10 TX power saving */ 911 /* Enable DA10 TX power saving */
1001 u1DA = read_nic_byte(dev, PHYPR); 912 u1DA = read_nic_byte(dev, PHYPR);
1002 write_nic_byte(dev, PHYPR, (u1DA | BIT2)); 913 write_nic_byte(dev, PHYPR, (u1DA | BIT2));
1003 914
1004 /* POWER: */ 915 /* POWER: */
1005 write_nic_word(dev, 0x360, 0x1000); 916 write_nic_word(dev, 0x360, 0x1000);
1006 write_nic_word(dev, 0x362, 0x1000); 917 write_nic_word(dev, 0x362, 0x1000);
1007 918
1008 /* AFE. */ 919 /* AFE. */
1009 write_nic_word(dev, 0x370, 0x0560); 920 write_nic_word(dev, 0x370, 0x0560);
1010 write_nic_word(dev, 0x372, 0x0560); 921 write_nic_word(dev, 0x372, 0x0560);
1011 write_nic_word(dev, 0x374, 0x0DA4); 922 write_nic_word(dev, 0x374, 0x0DA4);
@@ -1013,54 +924,48 @@ MacConfig_85BASIC(
1013 write_nic_word(dev, 0x378, 0x0560); 924 write_nic_word(dev, 0x378, 0x0560);
1014 write_nic_word(dev, 0x37A, 0x0560); 925 write_nic_word(dev, 0x37A, 0x0560);
1015 write_nic_word(dev, 0x37C, 0x00EC); 926 write_nic_word(dev, 0x37C, 0x00EC);
1016 write_nic_word(dev, 0x37E, 0x00EC); /*+edward */ 927 write_nic_word(dev, 0x37E, 0x00EC); /* +edward */
1017 write_nic_byte(dev, 0x24E, 0x01); 928 write_nic_byte(dev, 0x24E, 0x01);
1018} 929}
1019 930
1020u8 931u8 GetSupportedWirelessMode8185(struct net_device *dev)
1021GetSupportedWirelessMode8185(
1022 struct net_device *dev
1023)
1024{ 932{
1025 u8 btSupportedWirelessMode = 0; 933 u8 btSupportedWirelessMode = 0;
1026 934
1027 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G); 935 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1028 return btSupportedWirelessMode; 936 return btSupportedWirelessMode;
1029} 937}
1030 938
1031void 939void ActUpdateChannelAccessSetting(struct net_device *dev,
1032ActUpdateChannelAccessSetting( 940 WIRELESS_MODE WirelessMode,
1033 struct net_device *dev, 941 PCHANNEL_ACCESS_SETTING ChnlAccessSetting)
1034 WIRELESS_MODE WirelessMode,
1035 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1036 )
1037{ 942{
1038 struct r8180_priv *priv = ieee80211_priv(dev); 943 struct r8180_priv *priv = ieee80211_priv(dev);
1039 struct ieee80211_device *ieee = priv->ieee80211; 944 struct ieee80211_device *ieee = priv->ieee80211;
1040 AC_CODING eACI; 945 AC_CODING eACI;
1041 AC_PARAM AcParam; 946 AC_PARAM AcParam;
1042 u8 bFollowLegacySetting = 0; 947 u8 bFollowLegacySetting = 0;
1043 u8 u1bAIFS; 948 u8 u1bAIFS;
1044 949
1045 /* 950 /*
1046 <RJ_TODO_8185B> 951 * <RJ_TODO_8185B>
1047 TODO: We still don't know how to set up these registers, just follow WMAC to 952 * TODO: We still don't know how to set up these registers, just follow WMAC to
1048 verify 8185B FPAG. 953 * verify 8185B FPAG.
1049 954 *
1050 <RJ_TODO_8185B> 955 * <RJ_TODO_8185B>
1051 Jong said CWmin/CWmax register are not functional in 8185B, 956 * Jong said CWmin/CWmax register are not functional in 8185B,
1052 so we shall fill channel access realted register into AC parameter registers, 957 * so we shall fill channel access realted register into AC parameter registers,
1053 even in nQBss. 958 * even in nQBss.
1054 */ 959 */
1055 ChnlAccessSetting->SIFS_Timer = 0x22; /* Suggested by Jong, 2005.12.08. */ 960 ChnlAccessSetting->SIFS_Timer = 0x22; /* Suggested by Jong, 2005.12.08. */
1056 ChnlAccessSetting->DIFS_Timer = 0x1C; /* 2006.06.02, by rcnjko. */ 961 ChnlAccessSetting->DIFS_Timer = 0x1C; /* 2006.06.02, by rcnjko. */
1057 ChnlAccessSetting->SlotTimeTimer = 9; /* 2006.06.02, by rcnjko. */ 962 ChnlAccessSetting->SlotTimeTimer = 9; /* 2006.06.02, by rcnjko. */
1058 ChnlAccessSetting->EIFS_Timer = 0x5B; /* Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */ 963 ChnlAccessSetting->EIFS_Timer = 0x5B; /* Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */
1059 ChnlAccessSetting->CWminIndex = 3; /* 2006.06.02, by rcnjko. */ 964 ChnlAccessSetting->CWminIndex = 3; /* 2006.06.02, by rcnjko. */
1060 ChnlAccessSetting->CWmaxIndex = 7; /* 2006.06.02, by rcnjko. */ 965 ChnlAccessSetting->CWmaxIndex = 7; /* 2006.06.02, by rcnjko. */
1061 966
1062 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer); 967 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1063 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */ 968 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */
1064 969
1065 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer); 970 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer);
1066 971
@@ -1074,17 +979,17 @@ ActUpdateChannelAccessSetting(
1074 } 979 }
1075 980
1076 /* this setting is copied from rtl8187B. xiong-2006-11-13 */ 981 /* this setting is copied from rtl8187B. xiong-2006-11-13 */
1077 if (bFollowLegacySetting) { 982 if (bFollowLegacySetting) {
1078 983
1079 /* 984 /*
1080 Follow 802.11 seeting to AC parameter, all AC shall use the same parameter. 985 * Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
1081 2005.12.01, by rcnjko. 986 * 2005.12.01, by rcnjko.
1082 */ 987 */
1083 AcParam.longData = 0; 988 AcParam.longData = 0;
1084 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */ 989 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
1085 AcParam.f.AciAifsn.f.ACM = 0; 990 AcParam.f.AciAifsn.f.ACM = 0;
1086 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; /* Follow 802.11 CWmin. */ 991 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; /* Follow 802.11 CWmin. */
1087 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; /* Follow 802.11 CWmax. */ 992 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; /* Follow 802.11 CWmax. */
1088 AcParam.f.TXOPLimit = 0; 993 AcParam.f.TXOPLimit = 0;
1089 994
1090 /* lzm reserved 080826 */ 995 /* lzm reserved 080826 */
@@ -1095,7 +1000,7 @@ ActUpdateChannelAccessSetting(
1095 if (ieee->iw_mode == IW_MODE_ADHOC) 1000 if (ieee->iw_mode == IW_MODE_ADHOC)
1096 AcParam.f.TXOPLimit = 0x0020; 1001 AcParam.f.TXOPLimit = 0x0020;
1097 1002
1098 for (eACI = 0; eACI < AC_MAX; eACI++) { 1003 for (eACI = 0; eACI < AC_MAX; eACI++) {
1099 AcParam.f.AciAifsn.f.ACI = (u8)eACI; 1004 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
1100 { 1005 {
1101 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam); 1006 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
@@ -1103,7 +1008,7 @@ ActUpdateChannelAccessSetting(
1103 u8 u1bAIFS; 1008 u8 u1bAIFS;
1104 u32 u4bAcParam; 1009 u32 u4bAcParam;
1105 1010
1106 /* Retrive paramters to udpate. */ 1011 /* Retrieve paramters to update. */
1107 eACI = pAcParam->f.AciAifsn.f.ACI; 1012 eACI = pAcParam->f.AciAifsn.f.ACI;
1108 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime; 1013 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
1109 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) | 1014 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
@@ -1111,7 +1016,7 @@ ActUpdateChannelAccessSetting(
1111 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) | 1016 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
1112 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET)); 1017 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
1113 1018
1114 switch (eACI) { 1019 switch (eACI) {
1115 case AC1_BK: 1020 case AC1_BK:
1116 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */ 1021 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
1117 break; 1022 break;
@@ -1133,47 +1038,46 @@ ActUpdateChannelAccessSetting(
1133 break; 1038 break;
1134 } 1039 }
1135 1040
1136 /* Cehck ACM bit. */ 1041 /* Cehck ACM bit. */
1137 /* If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13. */ 1042 /* If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13. */
1138 { 1043 {
1139 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn); 1044 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
1140 AC_CODING eACI = pAciAifsn->f.ACI; 1045 AC_CODING eACI = pAciAifsn->f.ACI;
1141 1046
1142 /*modified Joseph */ 1047 /*for 8187B AsynIORead issue */
1143 /*for 8187B AsynIORead issue */
1144 u8 AcmCtrl = 0; 1048 u8 AcmCtrl = 0;
1145 if (pAciAifsn->f.ACM) { 1049 if (pAciAifsn->f.ACM) {
1146 /* ACM bit is 1. */ 1050 /* ACM bit is 1. */
1147 switch (eACI) { 1051 switch (eACI) {
1148 case AC0_BE: 1052 case AC0_BE:
1149 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); /* or 0x21 */ 1053 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); /* or 0x21 */
1150 break; 1054 break;
1151 1055
1152 case AC2_VI: 1056 case AC2_VI:
1153 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); /* or 0x42 */ 1057 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); /* or 0x42 */
1154 break; 1058 break;
1155 1059
1156 case AC3_VO: 1060 case AC3_VO:
1157 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); /* or 0x84 */ 1061 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); /* or 0x84 */
1158 break; 1062 break;
1159 1063
1160 default: 1064 default:
1161 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI); 1065 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI);
1162 break; 1066 break;
1163 } 1067 }
1164 } else { 1068 } else {
1165 /* ACM bit is 0. */ 1069 /* ACM bit is 0. */
1166 switch (eACI) { 1070 switch (eACI) {
1167 case AC0_BE: 1071 case AC0_BE:
1168 AcmCtrl &= ((~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xDE */ 1072 AcmCtrl &= ((~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xDE */
1169 break; 1073 break;
1170 1074
1171 case AC2_VI: 1075 case AC2_VI:
1172 AcmCtrl &= ((~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xBD */ 1076 AcmCtrl &= ((~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xBD */
1173 break; 1077 break;
1174 1078
1175 case AC3_VO: 1079 case AC3_VO:
1176 AcmCtrl &= ((~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0x7B */ 1080 AcmCtrl &= ((~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0x7B */
1177 break; 1081 break;
1178 1082
1179 default: 1083 default:
@@ -1187,53 +1091,51 @@ ActUpdateChannelAccessSetting(
1187 } 1091 }
1188} 1092}
1189 1093
1190void 1094void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode)
1191ActSetWirelessMode8185(
1192 struct net_device *dev,
1193 u8 btWirelessMode
1194 )
1195{ 1095{
1196 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1096 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1197 struct ieee80211_device *ieee = priv->ieee80211; 1097 struct ieee80211_device *ieee = priv->ieee80211;
1198 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev); 1098 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1199 1099
1200 if ((btWirelessMode & btSupportedWirelessMode) == 0) { 1100 if ((btWirelessMode & btSupportedWirelessMode) == 0) {
1201 /* Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko. */ 1101 /* Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko. */
1202 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n", 1102 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
1203 btWirelessMode, btSupportedWirelessMode); 1103 btWirelessMode, btSupportedWirelessMode);
1204 return; 1104 return;
1205 } 1105 }
1206 1106
1207 /* 1. Assign wireless mode to swtich if necessary. */ 1107 /* 1. Assign wireless mode to switch if necessary. */
1208 if (btWirelessMode == WIRELESS_MODE_AUTO) { 1108 if (btWirelessMode == WIRELESS_MODE_AUTO) {
1209 if ((btSupportedWirelessMode & WIRELESS_MODE_A)) { 1109 if ((btSupportedWirelessMode & WIRELESS_MODE_A)) {
1210 btWirelessMode = WIRELESS_MODE_A; 1110 btWirelessMode = WIRELESS_MODE_A;
1211 } else if (btSupportedWirelessMode & WIRELESS_MODE_G) { 1111 } else if (btSupportedWirelessMode & WIRELESS_MODE_G) {
1212 btWirelessMode = WIRELESS_MODE_G; 1112 btWirelessMode = WIRELESS_MODE_G;
1213 1113
1214 } else if ((btSupportedWirelessMode & WIRELESS_MODE_B)) { 1114 } else if ((btSupportedWirelessMode & WIRELESS_MODE_B)) {
1215 btWirelessMode = WIRELESS_MODE_B;
1216 } else {
1217 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1218 btSupportedWirelessMode);
1219 btWirelessMode = WIRELESS_MODE_B; 1115 btWirelessMode = WIRELESS_MODE_B;
1116 } else {
1117 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1118 btSupportedWirelessMode);
1119 btWirelessMode = WIRELESS_MODE_B;
1220 } 1120 }
1221 } 1121 }
1222 1122
1223 /* 2. Swtich band: RF or BB specific actions, 1123 /*
1124 * 2. Swtich band: RF or BB specific actions,
1224 * for example, refresh tables in omc8255, or change initial gain if necessary. 1125 * for example, refresh tables in omc8255, or change initial gain if necessary.
1225 * Nothing to do for Zebra to switch band. 1126 * Nothing to do for Zebra to switch band.
1226 * Update current wireless mode if we swtich to specified band successfully. */ 1127 * Update current wireless mode if we switch to specified band successfully.
1128 */
1227 1129
1228 ieee->mode = (WIRELESS_MODE)btWirelessMode; 1130 ieee->mode = (WIRELESS_MODE)btWirelessMode;
1229 1131
1230 /* 3. Change related setting. */ 1132 /* 3. Change related setting. */
1231 if( ieee->mode == WIRELESS_MODE_A ) { 1133 if( ieee->mode == WIRELESS_MODE_A ) {
1232 DMESG("WIRELESS_MODE_A\n"); 1134 DMESG("WIRELESS_MODE_A\n");
1233 } else if( ieee->mode == WIRELESS_MODE_B ) { 1135 } else if( ieee->mode == WIRELESS_MODE_B ) {
1234 DMESG("WIRELESS_MODE_B\n"); 1136 DMESG("WIRELESS_MODE_B\n");
1235 } else if( ieee->mode == WIRELESS_MODE_G ) { 1137 } else if( ieee->mode == WIRELESS_MODE_G ) {
1236 DMESG("WIRELESS_MODE_G\n"); 1138 DMESG("WIRELESS_MODE_G\n");
1237 } 1139 }
1238 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting); 1140 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
1239} 1141}
@@ -1245,22 +1147,16 @@ void rtl8185b_irq_enable(struct net_device *dev)
1245 priv->irq_enabled = 1; 1147 priv->irq_enabled = 1;
1246 write_nic_dword(dev, IMR, priv->IntrMask); 1148 write_nic_dword(dev, IMR, priv->IntrMask);
1247} 1149}
1248/* by amy for power save */ 1150
1249void 1151void DrvIFIndicateDisassociation(struct net_device *dev, u16 reason)
1250DrvIFIndicateDisassociation(
1251 struct net_device *dev,
1252 u16 reason
1253 )
1254{ 1152{
1255 /* nothing is needed after disassociation request. */ 1153 /* nothing is needed after disassociation request. */
1256 } 1154}
1257void 1155
1258MgntDisconnectIBSS( 1156void MgntDisconnectIBSS(struct net_device *dev)
1259 struct net_device *dev
1260)
1261{ 1157{
1262 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1158 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1263 u8 i; 1159 u8 i;
1264 1160
1265 DrvIFIndicateDisassociation(dev, unspec_reason); 1161 DrvIFIndicateDisassociation(dev, unspec_reason);
1266 1162
@@ -1271,166 +1167,143 @@ MgntDisconnectIBSS(
1271 1167
1272 priv->ieee80211->state = IEEE80211_NOLINK; 1168 priv->ieee80211->state = IEEE80211_NOLINK;
1273 /* 1169 /*
1274 Stop Beacon. 1170 * Stop Beacon.
1275 1171 *
1276 Vista add a Adhoc profile, HW radio off until OID_DOT11_RESET_REQUEST 1172 * Vista add a Adhoc profile, HW radio off until OID_DOT11_RESET_REQUEST
1277 Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck. 1173 * Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
1278 Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send. 1174 * Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
1279 1175 *
1280 Disable Beacon Queue Own bit, suggested by jong */ 1176 * Disable Beacon Queue Own bit, suggested by jong
1177 */
1281 ieee80211_stop_send_beacons(priv->ieee80211); 1178 ieee80211_stop_send_beacons(priv->ieee80211);
1282 1179
1283 priv->ieee80211->link_change(dev); 1180 priv->ieee80211->link_change(dev);
1284 notify_wx_assoc_event(priv->ieee80211); 1181 notify_wx_assoc_event(priv->ieee80211);
1285} 1182}
1286void 1183
1287MlmeDisassociateRequest( 1184void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn)
1288 struct net_device *dev,
1289 u8 *asSta,
1290 u8 asRsn
1291 )
1292{ 1185{
1293 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1186 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1294 u8 i; 1187 u8 i;
1295 1188
1296 SendDisassociation(priv->ieee80211, asSta, asRsn); 1189 SendDisassociation(priv->ieee80211, asSta, asRsn);
1297 1190
1298 if (memcmp(priv->ieee80211->current_network.bssid, asSta, 6) == 0) { 1191 if (memcmp(priv->ieee80211->current_network.bssid, asSta, 6) == 0) {
1299 /*ShuChen TODO: change media status. */ 1192 /* ShuChen TODO: change media status. */
1300 /*ShuChen TODO: What to do when disassociate. */ 1193 /* ShuChen TODO: What to do when disassociate. */
1301 DrvIFIndicateDisassociation(dev, unspec_reason); 1194 DrvIFIndicateDisassociation(dev, unspec_reason);
1302 1195
1303
1304
1305 for (i = 0; i < 6; i++) 1196 for (i = 0; i < 6; i++)
1306 priv->ieee80211->current_network.bssid[i] = 0x22; 1197 priv->ieee80211->current_network.bssid[i] = 0x22;
1307 1198
1308 ieee80211_disassociate(priv->ieee80211); 1199 ieee80211_disassociate(priv->ieee80211);
1309 } 1200 }
1310
1311} 1201}
1312 1202
1313void 1203void MgntDisconnectAP(struct net_device *dev, u8 asRsn)
1314MgntDisconnectAP(
1315 struct net_device *dev,
1316 u8 asRsn
1317)
1318{ 1204{
1319 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1205 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1320 1206
1321 /* 1207 /*
1322 Commented out by rcnjko, 2005.01.27: 1208 * Commented out by rcnjko, 2005.01.27:
1323 I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE(). 1209 * I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
1324 1210 *
1325 2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success 1211 * 2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
1326 1212 *
1327 In WPA WPA2 need to Clear all key ... because new key will set after new handshaking. 1213 * In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
1328 2004.10.11, by rcnjko. */ 1214 * 2004.10.11, by rcnjko.
1215 */
1329 MlmeDisassociateRequest(dev, priv->ieee80211->current_network.bssid, asRsn); 1216 MlmeDisassociateRequest(dev, priv->ieee80211->current_network.bssid, asRsn);
1330 1217
1331 priv->ieee80211->state = IEEE80211_NOLINK; 1218 priv->ieee80211->state = IEEE80211_NOLINK;
1332} 1219}
1333bool 1220
1334MgntDisconnect( 1221bool MgntDisconnect(struct net_device *dev, u8 asRsn)
1335 struct net_device *dev,
1336 u8 asRsn
1337)
1338{ 1222{
1339 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1223 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1340 /* 1224 /*
1341 Schedule an workitem to wake up for ps mode, 070109, by rcnjko. 1225 * Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
1342 */ 1226 */
1343 1227
1344 if (IS_DOT11D_ENABLE(priv->ieee80211)) 1228 if (IS_DOT11D_ENABLE(priv->ieee80211))
1345 Dot11d_Reset(priv->ieee80211); 1229 Dot11d_Reset(priv->ieee80211);
1346 /* In adhoc mode, update beacon frame. */ 1230 /* In adhoc mode, update beacon frame. */
1347 if (priv->ieee80211->state == IEEE80211_LINKED) { 1231 if (priv->ieee80211->state == IEEE80211_LINKED) {
1348 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) 1232 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1349 MgntDisconnectIBSS(dev); 1233 MgntDisconnectIBSS(dev);
1350 1234
1351 if (priv->ieee80211->iw_mode == IW_MODE_INFRA) { 1235 if (priv->ieee80211->iw_mode == IW_MODE_INFRA) {
1352 /* We clear key here instead of MgntDisconnectAP() because that 1236 /*
1353 MgntActSet_802_11_DISASSOCIATE() is an interface called by OS, 1237 * We clear key here instead of MgntDisconnectAP() because that
1354 e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is 1238 * MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
1355 used to handle disassociation related things to AP, e.g. send Disassoc 1239 * e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
1356 frame to AP. 2005.01.27, by rcnjko. */ 1240 * used to handle disassociation related things to AP, e.g. send Disassoc
1241 * frame to AP. 2005.01.27, by rcnjko.
1242 */
1357 MgntDisconnectAP(dev, asRsn); 1243 MgntDisconnectAP(dev, asRsn);
1358 } 1244 }
1359 /* Inidicate Disconnect, 2005.02.23, by rcnjko. */ 1245 /* Indicate Disconnect, 2005.02.23, by rcnjko. */
1360 } 1246 }
1361 return true; 1247 return true;
1362} 1248}
1363/* 1249/*
1364 Description: 1250 * Description:
1365 Chang RF Power State. 1251 * Chang RF Power State.
1366 Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE. 1252 * Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
1367 1253 *
1368 Assumption: 1254 * Assumption:
1369 PASSIVE LEVEL. 1255 * PASSIVE LEVEL.
1370*/ 1256 */
1371bool 1257bool SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState)
1372SetRFPowerState(
1373 struct net_device *dev,
1374 RT_RF_POWER_STATE eRFPowerState
1375 )
1376{ 1258{
1377 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1259 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1378 bool bResult = false; 1260 bool bResult = false;
1379 1261
1380 if (eRFPowerState == priv->eRFPowerState) 1262 if (eRFPowerState == priv->eRFPowerState)
1381 return bResult; 1263 return bResult;
1382 1264
1383 bResult = SetZebraRFPowerState8185(dev, eRFPowerState); 1265 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
1384 1266
1385 return bResult; 1267 return bResult;
1386} 1268}
1387void 1269
1388HalEnableRx8185Dummy( 1270void HalEnableRx8185Dummy(struct net_device *dev)
1389 struct net_device *dev
1390 )
1391{ 1271{
1392} 1272}
1393void 1273
1394HalDisableRx8185Dummy( 1274void HalDisableRx8185Dummy(struct net_device *dev)
1395 struct net_device *dev
1396 )
1397{ 1275{
1398} 1276}
1399 1277
1400bool 1278bool MgntActSet_RF_State(struct net_device *dev, RT_RF_POWER_STATE StateToSet, u32 ChangeSource)
1401MgntActSet_RF_State(
1402 struct net_device *dev,
1403 RT_RF_POWER_STATE StateToSet,
1404 u32 ChangeSource
1405 )
1406{ 1279{
1407 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1280 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1408 bool bActionAllowed = false; 1281 bool bActionAllowed = false;
1409 bool bConnectBySSID = false; 1282 bool bConnectBySSID = false;
1410 RT_RF_POWER_STATE rtState; 1283 RT_RF_POWER_STATE rtState;
1411 u16 RFWaitCounter = 0; 1284 u16 RFWaitCounter = 0;
1412 unsigned long flag; 1285 unsigned long flag;
1413 /* 1286 /*
1414 Prevent the race condition of RF state change. By Bruce, 2007-11-28. 1287 * Prevent the race condition of RF state change. By Bruce, 2007-11-28.
1415 Only one thread can change the RF state at one time, and others should wait to be executed. 1288 * Only one thread can change the RF state at one time, and others should wait to be executed.
1416 */ 1289 */
1417 while (true) { 1290 while (true) {
1418 spin_lock_irqsave(&priv->rf_ps_lock, flag); 1291 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1419 if (priv->RFChangeInProgress) { 1292 if (priv->RFChangeInProgress) {
1420 spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1293 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1421 /* Set RF after the previous action is done. */ 1294 /* Set RF after the previous action is done. */
1422 while (priv->RFChangeInProgress) { 1295 while (priv->RFChangeInProgress) {
1423 RFWaitCounter++; 1296 RFWaitCounter++;
1424 udelay(1000); /* 1 ms */ 1297 udelay(1000); /* 1 ms */
1425 1298
1426 /* Wait too long, return FALSE to avoid to be stuck here. */ 1299 /* Wait too long, return FALSE to avoid to be stuck here. */
1427 if (RFWaitCounter > 1000) { /* 1sec */ 1300 if (RFWaitCounter > 1000) { /* 1sec */
1428 printk("MgntActSet_RF_State(): Wait too long to set RF\n"); 1301 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
1429 /* TODO: Reset RF state? */ 1302 /* TODO: Reset RF state? */
1430 return false; 1303 return false;
1431 } 1304 }
1432 } 1305 }
1433 } else { 1306 } else {
1434 priv->RFChangeInProgress = true; 1307 priv->RFChangeInProgress = true;
1435 spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1308 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1436 break; 1309 break;
@@ -1438,12 +1311,12 @@ MgntActSet_RF_State(
1438 } 1311 }
1439 rtState = priv->eRFPowerState; 1312 rtState = priv->eRFPowerState;
1440 1313
1441 switch (StateToSet) { 1314 switch (StateToSet) {
1442 case eRfOn: 1315 case eRfOn:
1443 /* 1316 /*
1444 Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or 1317 * Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
1445 the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02. 1318 * the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
1446 */ 1319 */
1447 priv->RfOffReason &= (~ChangeSource); 1320 priv->RfOffReason &= (~ChangeSource);
1448 1321
1449 if (!priv->RfOffReason) { 1322 if (!priv->RfOffReason) {
@@ -1453,25 +1326,24 @@ MgntActSet_RF_State(
1453 if (rtState == eRfOff && ChangeSource >= RF_CHANGE_BY_HW && !priv->bInHctTest) 1326 if (rtState == eRfOff && ChangeSource >= RF_CHANGE_BY_HW && !priv->bInHctTest)
1454 bConnectBySSID = true; 1327 bConnectBySSID = true;
1455 1328
1456 } else 1329 } else
1457 ; 1330 ;
1458 break; 1331 break;
1459 1332
1460 case eRfOff: 1333 case eRfOff:
1461 /* 070125, rcnjko: we always keep connected in AP mode. */ 1334 /* 070125, rcnjko: we always keep connected in AP mode. */
1462 1335
1463 if (priv->RfOffReason > RF_CHANGE_BY_IPS) { 1336 if (priv->RfOffReason > RF_CHANGE_BY_IPS) {
1464 /* 1337 /*
1465 060808, Annie: 1338 * 060808, Annie:
1466 Disconnect to current BSS when radio off. Asked by QuanTa. 1339 * Disconnect to current BSS when radio off. Asked by QuanTa.
1467 1340 *
1468 Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(), 1341 * Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
1469 because we do NOT need to set ssid to dummy ones. 1342 * because we do NOT need to set ssid to dummy ones.
1470 */ 1343 */
1471 MgntDisconnect(dev, disas_lv_ss); 1344 MgntDisconnect(dev, disas_lv_ss);
1472 1345 /* Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI. */
1473 /* Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI. */ 1346 }
1474 }
1475 1347
1476 priv->RfOffReason |= ChangeSource; 1348 priv->RfOffReason |= ChangeSource;
1477 bActionAllowed = true; 1349 bActionAllowed = true;
@@ -1484,14 +1356,14 @@ MgntActSet_RF_State(
1484 break; 1356 break;
1485 } 1357 }
1486 1358
1487 if (bActionAllowed) { 1359 if (bActionAllowed) {
1488 /* Config HW to the specified mode. */ 1360 /* Config HW to the specified mode. */
1489 SetRFPowerState(dev, StateToSet); 1361 SetRFPowerState(dev, StateToSet);
1490 1362
1491 /* Turn on RF. */ 1363 /* Turn on RF. */
1492 if (StateToSet == eRfOn) { 1364 if (StateToSet == eRfOn) {
1493 HalEnableRx8185Dummy(dev); 1365 HalEnableRx8185Dummy(dev);
1494 if (bConnectBySSID) { 1366 if (bConnectBySSID) {
1495 /* by amy not supported */ 1367 /* by amy not supported */
1496 } 1368 }
1497 } 1369 }
@@ -1507,69 +1379,61 @@ MgntActSet_RF_State(
1507 spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1379 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1508 return bActionAllowed; 1380 return bActionAllowed;
1509} 1381}
1510void 1382
1511InactivePowerSave( 1383void InactivePowerSave(struct net_device *dev)
1512 struct net_device *dev
1513 )
1514{ 1384{
1515 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1385 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1516 /* 1386 /*
1517 This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem 1387 * This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
1518 is really scheduled. 1388 * is really scheduled.
1519 The old code, sets this flag before scheduling the IPS workitem and however, at the same time the 1389 * The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
1520 previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing 1390 * previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
1521 blocks the IPS procedure of switching RF. 1391 * blocks the IPS procedure of switching RF.
1522 */ 1392 */
1523 priv->bSwRfProcessing = true; 1393 priv->bSwRfProcessing = true;
1524 1394
1525 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS); 1395 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
1526 1396
1527 /* 1397 /*
1528 To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20. 1398 * To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
1529 */ 1399 */
1530 1400
1531 priv->bSwRfProcessing = false; 1401 priv->bSwRfProcessing = false;
1532} 1402}
1533 1403
1534/* 1404/*
1535 Description: 1405 * Description:
1536 Enter the inactive power save mode. RF will be off 1406 * Enter the inactive power save mode. RF will be off
1537*/ 1407 */
1538void 1408void IPSEnter(struct net_device *dev)
1539IPSEnter(
1540 struct net_device *dev
1541 )
1542{ 1409{
1543 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1410 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1544 RT_RF_POWER_STATE rtState; 1411 RT_RF_POWER_STATE rtState;
1545 if (priv->bInactivePs) { 1412 if (priv->bInactivePs) {
1546 rtState = priv->eRFPowerState; 1413 rtState = priv->eRFPowerState;
1547 1414
1548 /* 1415 /*
1549 Do not enter IPS in the following conditions: 1416 * Do not enter IPS in the following conditions:
1550 (1) RF is already OFF or Sleep 1417 * (1) RF is already OFF or Sleep
1551 (2) bSwRfProcessing (indicates the IPS is still under going) 1418 * (2) bSwRfProcessing (indicates the IPS is still under going)
1552 (3) Connectted (only disconnected can trigger IPS) 1419 * (3) Connected (only disconnected can trigger IPS)
1553 (4) IBSS (send Beacon) 1420 * (4) IBSS (send Beacon)
1554 (5) AP mode (send Beacon) 1421 * (5) AP mode (send Beacon)
1555 */ 1422 */
1556 if (rtState == eRfOn && !priv->bSwRfProcessing 1423 if (rtState == eRfOn && !priv->bSwRfProcessing
1557 && (priv->ieee80211->state != IEEE80211_LINKED)) { 1424 && (priv->ieee80211->state != IEEE80211_LINKED)) {
1558 priv->eInactivePowerState = eRfOff; 1425 priv->eInactivePowerState = eRfOff;
1559 InactivePowerSave(dev); 1426 InactivePowerSave(dev);
1560 } 1427 }
1561 } 1428 }
1562} 1429}
1563void 1430void IPSLeave(struct net_device *dev)
1564IPSLeave(
1565 struct net_device *dev
1566 )
1567{ 1431{
1568 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1432 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1569 RT_RF_POWER_STATE rtState; 1433 RT_RF_POWER_STATE rtState;
1570 if (priv->bInactivePs) { 1434 if (priv->bInactivePs) {
1571 rtState = priv->eRFPowerState; 1435 rtState = priv->eRFPowerState;
1572 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS) { 1436 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS) {
1573 priv->eInactivePowerState = eRfOn; 1437 priv->eInactivePowerState = eRfOn;
1574 InactivePowerSave(dev); 1438 InactivePowerSave(dev);
1575 } 1439 }
@@ -1582,8 +1446,8 @@ void rtl8185b_adapter_start(struct net_device *dev)
1582 struct ieee80211_device *ieee = priv->ieee80211; 1446 struct ieee80211_device *ieee = priv->ieee80211;
1583 1447
1584 u8 SupportedWirelessMode; 1448 u8 SupportedWirelessMode;
1585 u8 InitWirelessMode; 1449 u8 InitWirelessMode;
1586 u8 bInvalidWirelessMode = 0; 1450 u8 bInvalidWirelessMode = 0;
1587 u8 tmpu8; 1451 u8 tmpu8;
1588 u8 btCR9346; 1452 u8 btCR9346;
1589 u8 TmpU1b; 1453 u8 TmpU1b;
@@ -1598,89 +1462,89 @@ void rtl8185b_adapter_start(struct net_device *dev)
1598 HwConfigureRTL8185(dev); 1462 HwConfigureRTL8185(dev);
1599 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]); 1463 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
1600 write_nic_word(dev, MAC4, ((u32 *)dev->dev_addr)[1] & 0xffff); 1464 write_nic_word(dev, MAC4, ((u32 *)dev->dev_addr)[1] & 0xffff);
1601 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); /* default network type to 'No Link' */ 1465 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); /* default network type to 'No Link' */
1602 write_nic_word(dev, BcnItv, 100); 1466 write_nic_word(dev, BcnItv, 100);
1603 write_nic_word(dev, AtimWnd, 2); 1467 write_nic_word(dev, AtimWnd, 2);
1604 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF); 1468 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
1605 write_nic_byte(dev, WPA_CONFIG, 0); 1469 write_nic_byte(dev, WPA_CONFIG, 0);
1606 MacConfig_85BASIC(dev); 1470 MacConfig_85BASIC(dev);
1607 /* Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko. */ 1471 /* Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko. */
1608 /* BT_DEMO_BOARD type */ 1472 /* BT_DEMO_BOARD type */
1609 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a); 1473 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
1610 1474
1611 /* 1475 /*
1612 ----------------------------------------------------------------------------- 1476 *---------------------------------------------------------------------------
1613 Set up PHY related. 1477 * Set up PHY related.
1614 ----------------------------------------------------------------------------- 1478 *---------------------------------------------------------------------------
1615 */ 1479 */
1616 /* Enable Config3.PARAM_En to revise AnaaParm. */ 1480 /* Enable Config3.PARAM_En to revise AnaaParm. */
1617 write_nic_byte(dev, CR9346, 0xc0); /* enable config register write */ 1481 write_nic_byte(dev, CR9346, 0xc0); /* enable config register write */
1618 tmpu8 = read_nic_byte(dev, CONFIG3); 1482 tmpu8 = read_nic_byte(dev, CONFIG3);
1619 write_nic_byte(dev, CONFIG3, (tmpu8 | CONFIG3_PARM_En)); 1483 write_nic_byte(dev, CONFIG3, (tmpu8 | CONFIG3_PARM_En));
1620 /* Turn on Analog power. */ 1484 /* Turn on Analog power. */
1621 /* Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko. */ 1485 /* Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko. */
1622 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON); 1486 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
1623 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON); 1487 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
1624 write_nic_word(dev, ANAPARAM3, 0x0010); 1488 write_nic_word(dev, ANAPARAM3, 0x0010);
1625 1489
1626 write_nic_byte(dev, CONFIG3, tmpu8); 1490 write_nic_byte(dev, CONFIG3, tmpu8);
1627 write_nic_byte(dev, CR9346, 0x00); 1491 write_nic_byte(dev, CR9346, 0x00);
1628 /* enable EEM0 and EEM1 in 9346CR */ 1492 /* enable EEM0 and EEM1 in 9346CR */
1629 btCR9346 = read_nic_byte(dev, CR9346); 1493 btCR9346 = read_nic_byte(dev, CR9346);
1630 write_nic_byte(dev, CR9346, (btCR9346 | 0xC0)); 1494 write_nic_byte(dev, CR9346, (btCR9346 | 0xC0));
1631 1495
1632 /* B cut use LED1 to control HW RF on/off */ 1496 /* B cut use LED1 to control HW RF on/off */
1633 TmpU1b = read_nic_byte(dev, CONFIG5); 1497 TmpU1b = read_nic_byte(dev, CONFIG5);
1634 TmpU1b = TmpU1b & ~BIT3; 1498 TmpU1b = TmpU1b & ~BIT3;
1635 write_nic_byte(dev, CONFIG5, TmpU1b); 1499 write_nic_byte(dev, CONFIG5, TmpU1b);
1636 1500
1637 /* disable EEM0 and EEM1 in 9346CR */ 1501 /* disable EEM0 and EEM1 in 9346CR */
1638 btCR9346 &= ~(0xC0); 1502 btCR9346 &= ~(0xC0);
1639 write_nic_byte(dev, CR9346, btCR9346); 1503 write_nic_byte(dev, CR9346, btCR9346);
1640 1504
1641 /* Enable Led (suggested by Jong) */ 1505 /* Enable Led (suggested by Jong) */
1642 /* B-cut RF Radio on/off 5e[3]=0 */ 1506 /* B-cut RF Radio on/off 5e[3]=0 */
1643 btPSR = read_nic_byte(dev, PSR); 1507 btPSR = read_nic_byte(dev, PSR);
1644 write_nic_byte(dev, PSR, (btPSR | BIT3)); 1508 write_nic_byte(dev, PSR, (btPSR | BIT3));
1645 /* setup initial timing for RFE. */ 1509 /* setup initial timing for RFE. */
1646 write_nic_word(dev, RFPinsOutput, 0x0480); 1510 write_nic_word(dev, RFPinsOutput, 0x0480);
1647 SetOutputEnableOfRfPins(dev); 1511 SetOutputEnableOfRfPins(dev);
1648 write_nic_word(dev, RFPinsSelect, 0x2488); 1512 write_nic_word(dev, RFPinsSelect, 0x2488);
1649 1513
1650 /* PHY config. */ 1514 /* PHY config. */
1651 PhyConfig8185(dev); 1515 PhyConfig8185(dev);
1652 1516
1653 /* 1517 /*
1654 We assume RegWirelessMode has already been initialized before, 1518 * We assume RegWirelessMode has already been initialized before,
1655 however, we has to validate the wireless mode here and provide a 1519 * however, we has to validate the wireless mode here and provide a
1656 reasonable initialized value if necessary. 2005.01.13, by rcnjko. 1520 * reasonable initialized value if necessary. 2005.01.13, by rcnjko.
1657 */ 1521 */
1658 SupportedWirelessMode = GetSupportedWirelessMode8185(dev); 1522 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1659 if ((ieee->mode != WIRELESS_MODE_B) && 1523 if ((ieee->mode != WIRELESS_MODE_B) &&
1660 (ieee->mode != WIRELESS_MODE_G) && 1524 (ieee->mode != WIRELESS_MODE_G) &&
1661 (ieee->mode != WIRELESS_MODE_A) && 1525 (ieee->mode != WIRELESS_MODE_A) &&
1662 (ieee->mode != WIRELESS_MODE_AUTO)) { 1526 (ieee->mode != WIRELESS_MODE_AUTO)) {
1663 /* It should be one of B, G, A, or AUTO. */ 1527 /* It should be one of B, G, A, or AUTO. */
1664 bInvalidWirelessMode = 1; 1528 bInvalidWirelessMode = 1;
1665 } else { 1529 } else {
1666 /* One of B, G, A, or AUTO. */ 1530 /* One of B, G, A, or AUTO. */
1667 /* Check if the wireless mode is supported by RF. */ 1531 /* Check if the wireless mode is supported by RF. */
1668 if ((ieee->mode != WIRELESS_MODE_AUTO) && 1532 if ((ieee->mode != WIRELESS_MODE_AUTO) &&
1669 (ieee->mode & SupportedWirelessMode) == 0) { 1533 (ieee->mode & SupportedWirelessMode) == 0) {
1670 bInvalidWirelessMode = 1; 1534 bInvalidWirelessMode = 1;
1671 } 1535 }
1672 } 1536 }
1673 1537
1674 if (bInvalidWirelessMode || ieee->mode == WIRELESS_MODE_AUTO) { 1538 if (bInvalidWirelessMode || ieee->mode == WIRELESS_MODE_AUTO) {
1675 /* Auto or other invalid value. */ 1539 /* Auto or other invalid value. */
1676 /* Assigne a wireless mode to initialize. */ 1540 /* Assigne a wireless mode to initialize. */
1677 if ((SupportedWirelessMode & WIRELESS_MODE_A)) { 1541 if ((SupportedWirelessMode & WIRELESS_MODE_A)) {
1678 InitWirelessMode = WIRELESS_MODE_A; 1542 InitWirelessMode = WIRELESS_MODE_A;
1679 } else if ((SupportedWirelessMode & WIRELESS_MODE_G)) { 1543 } else if ((SupportedWirelessMode & WIRELESS_MODE_G)) {
1680 InitWirelessMode = WIRELESS_MODE_G; 1544 InitWirelessMode = WIRELESS_MODE_G;
1681 } else if ((SupportedWirelessMode & WIRELESS_MODE_B)) { 1545 } else if ((SupportedWirelessMode & WIRELESS_MODE_B)) {
1682 InitWirelessMode = WIRELESS_MODE_B; 1546 InitWirelessMode = WIRELESS_MODE_B;
1683 } else { 1547 } else {
1684 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", 1548 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
1685 SupportedWirelessMode); 1549 SupportedWirelessMode);
1686 InitWirelessMode = WIRELESS_MODE_B; 1550 InitWirelessMode = WIRELESS_MODE_B;
@@ -1690,24 +1554,21 @@ void rtl8185b_adapter_start(struct net_device *dev)
1690 if (bInvalidWirelessMode) 1554 if (bInvalidWirelessMode)
1691 ieee->mode = (WIRELESS_MODE)InitWirelessMode; 1555 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
1692 1556
1693 } else { 1557 } else {
1694 /* One of B, G, A. */ 1558 /* One of B, G, A. */
1695 InitWirelessMode = ieee->mode; 1559 InitWirelessMode = ieee->mode;
1696 } 1560 }
1697/* by amy for power save */
1698 priv->eRFPowerState = eRfOff; 1561 priv->eRFPowerState = eRfOff;
1699 priv->RfOffReason = 0; 1562 priv->RfOffReason = 0;
1700 { 1563 {
1701 MgntActSet_RF_State(dev, eRfOn, 0); 1564 MgntActSet_RF_State(dev, eRfOn, 0);
1702 } 1565 }
1703 /* 1566 /*
1704 If inactive power mode is enabled, disable rf while in disconnected state. 1567 * If inactive power mode is enabled, disable rf while in disconnected state.
1705 */ 1568 */
1706 if (priv->bInactivePs) 1569 if (priv->bInactivePs)
1707 MgntActSet_RF_State(dev , eRfOff, RF_CHANGE_BY_IPS); 1570 MgntActSet_RF_State(dev , eRfOff, RF_CHANGE_BY_IPS);
1708 1571
1709/* by amy for power save */
1710
1711 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode)); 1572 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
1712 1573
1713 /* ----------------------------------------------------------------------------- */ 1574 /* ----------------------------------------------------------------------------- */
@@ -1715,7 +1576,7 @@ void rtl8185b_adapter_start(struct net_device *dev)
1715 rtl8185b_irq_enable(dev); 1576 rtl8185b_irq_enable(dev);
1716 1577
1717 netif_start_queue(dev); 1578 netif_start_queue(dev);
1718 } 1579}
1719 1580
1720void rtl8185b_rx_enable(struct net_device *dev) 1581void rtl8185b_rx_enable(struct net_device *dev)
1721{ 1582{
@@ -1728,7 +1589,7 @@ void rtl8185b_rx_enable(struct net_device *dev)
1728 DMESG("NIC in promisc mode"); 1589 DMESG("NIC in promisc mode");
1729 1590
1730 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR || \ 1591 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1731 dev->flags & IFF_PROMISC) { 1592 dev->flags & IFF_PROMISC) {
1732 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM); 1593 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
1733 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP; 1594 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
1734 } 1595 }
diff --git a/drivers/staging/rtl8192e/Kconfig b/drivers/staging/rtl8192e/Kconfig
index f87e21101857..4602a47cdb4a 100644
--- a/drivers/staging/rtl8192e/Kconfig
+++ b/drivers/staging/rtl8192e/Kconfig
@@ -14,6 +14,7 @@ if RTLLIB
14config RTLLIB_CRYPTO_CCMP 14config RTLLIB_CRYPTO_CCMP
15 tristate "Support for rtllib CCMP crypto" 15 tristate "Support for rtllib CCMP crypto"
16 depends on RTLLIB 16 depends on RTLLIB
17 select CRYPTO_AES
17 default y 18 default y
18 ---help--- 19 ---help---
19 CCMP crypto driver for rtllib. 20 CCMP crypto driver for rtllib.
@@ -23,6 +24,8 @@ config RTLLIB_CRYPTO_CCMP
23config RTLLIB_CRYPTO_TKIP 24config RTLLIB_CRYPTO_TKIP
24 tristate "Support for rtllib TKIP crypto" 25 tristate "Support for rtllib TKIP crypto"
25 depends on RTLLIB 26 depends on RTLLIB
27 select CRYPTO_ARC4
28 select CRYPTO_MICHAEL_MIC
26 default y 29 default y
27 ---help--- 30 ---help---
28 TKIP crypto driver for rtllib. 31 TKIP crypto driver for rtllib.
@@ -31,6 +34,7 @@ config RTLLIB_CRYPTO_TKIP
31 34
32config RTLLIB_CRYPTO_WEP 35config RTLLIB_CRYPTO_WEP
33 tristate "Support for rtllib WEP crypto" 36 tristate "Support for rtllib WEP crypto"
37 select CRYPTO_ARC4
34 depends on RTLLIB 38 depends on RTLLIB
35 default y 39 default y
36 ---help--- 40 ---help---
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
index 58d044ea5524..ea91744f7ccf 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
@@ -342,7 +342,6 @@ static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
342u32 cmpk_message_handle_rx(struct net_device *dev, 342u32 cmpk_message_handle_rx(struct net_device *dev,
343 struct rtllib_rx_stats *pstats) 343 struct rtllib_rx_stats *pstats)
344{ 344{
345 struct r8192_priv *priv = rtllib_priv(dev);
346 int total_length; 345 int total_length;
347 u8 cmd_length, exe_cnt = 0; 346 u8 cmd_length, exe_cnt = 0;
348 u8 element_id; 347 u8 element_id;
@@ -409,8 +408,6 @@ u32 cmpk_message_handle_rx(struct net_device *dev,
409 return 1; 408 return 1;
410 } 409 }
411 410
412 priv->stats.rxcmdpkt[element_id]++;
413
414 total_length -= cmd_length; 411 total_length -= cmd_length;
415 pcmd_buff += cmd_length; 412 pcmd_buff += cmd_length;
416 } 413 }
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
index 37719859bdae..b526fa428679 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
@@ -216,7 +216,7 @@ static bool firmware_check_ready(struct net_device *dev,
216 break; 216 break;
217 default: 217 default:
218 rt_status = false; 218 rt_status = false;
219 RT_TRACE(COMP_FIRMWARE, "Unknown firware status"); 219 RT_TRACE(COMP_FIRMWARE, "Unknown firmware status");
220 break; 220 break;
221 } 221 }
222 222
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
index 3e705efaaf22..9676c591c859 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
@@ -689,7 +689,7 @@ void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
689 case RF_8258: 689 case RF_8258:
690 break; 690 break;
691 default: 691 default:
692 RT_TRACE(COMP_ERR, "unknown rf chip in funtion %s()\n", 692 RT_TRACE(COMP_ERR, "unknown rf chip in function %s()\n",
693 __func__); 693 __func__);
694 break; 694 break;
695 } 695 }
diff --git a/drivers/staging/rtl8192e/rtl8192e/r819xE_phyreg.h b/drivers/staging/rtl8192e/rtl8192e/r819xE_phyreg.h
index d5de279f6644..970298b07af7 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r819xE_phyreg.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r819xE_phyreg.h
@@ -306,7 +306,7 @@
306#define bRFStart 0x0000f000 306#define bRFStart 0x0000f000
307#define bBBStart 0x000000f0 307#define bBBStart 0x000000f0
308#define bBBCCKStart 0x0000000f 308#define bBBCCKStart 0x0000000f
309/* Reg)x814 */ 309/* Reg x814 */
310#define bPAEnd 0xf 310#define bPAEnd 0xf
311#define bTREnd 0x0f000000 311#define bTREnd 0x0f000000
312#define bRFEnd 0x000f0000 312#define bRFEnd 0x000f0000
@@ -844,7 +844,7 @@
844#define bRTL8258_RxLPFBW 0xc00 844#define bRTL8258_RxLPFBW 0xc00
845#define bRTL8258_RSSILPFBW 0xc0 845#define bRTL8258_RSSILPFBW 0xc0
846 846
847/* byte endable for sb_write */ 847/* byte enable for sb_write */
848#define bByte0 0x1 848#define bByte0 0x1
849#define bByte1 0x2 849#define bByte1 0x2
850#define bByte2 0x4 850#define bByte2 0x4
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 71adb6b3344d..4f602b227b50 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -1025,7 +1025,7 @@ static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
1025 break; 1025 break;
1026 } 1026 }
1027 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait " 1027 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait "
1028 "until rf chang is done.\n", __func__); 1028 "until rf change is done.\n", __func__);
1029 mdelay(1); 1029 mdelay(1);
1030 RFInProgressTimeOut++; 1030 RFInProgressTimeOut++;
1031 spin_lock_irqsave(&priv->rf_ps_lock, flags); 1031 spin_lock_irqsave(&priv->rf_ps_lock, flags);
@@ -1211,7 +1211,7 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
1211 priv->AcmControl = 0; 1211 priv->AcmControl = 0;
1212 priv->pFirmware = vzalloc(sizeof(struct rt_firmware)); 1212 priv->pFirmware = vzalloc(sizeof(struct rt_firmware));
1213 if (!priv->pFirmware) 1213 if (!priv->pFirmware)
1214 printk(KERN_ERR "rtl8193e: Unable to allocate space " 1214 printk(KERN_ERR "rtl8192e: Unable to allocate space "
1215 "for firmware\n"); 1215 "for firmware\n");
1216 1216
1217 skb_queue_head_init(&priv->rx_queue); 1217 skb_queue_head_init(&priv->rx_queue);
@@ -2024,10 +2024,10 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
2024 stype = WLAN_FC_GET_STYPE(fc); 2024 stype = WLAN_FC_GET_STYPE(fc);
2025 pda_addr = header->addr1; 2025 pda_addr = header->addr1;
2026 2026
2027 if (is_multicast_ether_addr(pda_addr)) 2027 if (is_broadcast_ether_addr(pda_addr))
2028 multi_addr = true;
2029 else if (is_broadcast_ether_addr(pda_addr))
2030 broad_addr = true; 2028 broad_addr = true;
2029 else if (is_multicast_ether_addr(pda_addr))
2030 multi_addr = true;
2031 else 2031 else
2032 uni_addr = true; 2032 uni_addr = true;
2033 2033
@@ -2358,8 +2358,7 @@ static void rtl8192_rx_normal(struct net_device *dev)
2358 stats.RxBufShift); 2358 stats.RxBufShift);
2359 skb_trim(skb, skb->len - 4/*sCrcLng*/); 2359 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2360 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data; 2360 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2361 if (!is_broadcast_ether_addr(rtllib_hdr->addr1) && 2361 if (!is_multicast_ether_addr(rtllib_hdr->addr1)) {
2362 !is_multicast_ether_addr(rtllib_hdr->addr1)) {
2363 /* unicast packet */ 2362 /* unicast packet */
2364 unicast_packet = true; 2363 unicast_packet = true;
2365 } 2364 }
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
index 2a2519cc284d..320d5fc026b4 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
@@ -353,7 +353,6 @@ struct rt_stats {
353 unsigned long rxrdu; 353 unsigned long rxrdu;
354 unsigned long rxok; 354 unsigned long rxok;
355 unsigned long rxframgment; 355 unsigned long rxframgment;
356 unsigned long rxcmdpkt[8];
357 unsigned long rxurberr; 356 unsigned long rxurberr;
358 unsigned long rxstaterr; 357 unsigned long rxstaterr;
359 unsigned long rxdatacrcerr; 358 unsigned long rxdatacrcerr;
@@ -944,7 +943,7 @@ struct r8192_priv {
944 bool bfsync_processing; 943 bool bfsync_processing;
945 u32 rate_record; 944 u32 rate_record;
946 u32 rateCountDiffRecord; 945 u32 rateCountDiffRecord;
947 u32 ContiuneDiffCount; 946 u32 ContinueDiffCount;
948 bool bswitch_fsync; 947 bool bswitch_fsync;
949 u8 framesync; 948 u8 framesync;
950 u32 framesyncC34; 949 u32 framesyncC34;
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
index f026b7171f62..481b1e4d4913 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
@@ -493,7 +493,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
493 493
494 if (priv->bResetInProgress) { 494 if (priv->bResetInProgress) {
495 RT_TRACE(COMP_POWER_TRACKING, 495 RT_TRACE(COMP_POWER_TRACKING,
496 "we are in slient reset progress, so return\n"); 496 "we are in silent reset progress, so return\n");
497 write_nic_byte(dev, Pw_Track_Flag, 0); 497 write_nic_byte(dev, Pw_Track_Flag, 0);
498 write_nic_byte(dev, FW_Busy_Flag, 0); 498 write_nic_byte(dev, FW_Busy_Flag, 0);
499 return; 499 return;
@@ -2615,22 +2615,22 @@ void dm_fsync_timer_callback(unsigned long data)
2615 rate_count_diff; 2615 rate_count_diff;
2616 if (DiffNum >= 2616 if (DiffNum >=
2617 priv->rtllib->fsync_seconddiff_ratethreshold) 2617 priv->rtllib->fsync_seconddiff_ratethreshold)
2618 priv->ContiuneDiffCount++; 2618 priv->ContinueDiffCount++;
2619 else 2619 else
2620 priv->ContiuneDiffCount = 0; 2620 priv->ContinueDiffCount = 0;
2621 2621
2622 if (priv->ContiuneDiffCount >= 2) { 2622 if (priv->ContinueDiffCount >= 2) {
2623 bSwitchFromCountDiff = true; 2623 bSwitchFromCountDiff = true;
2624 priv->ContiuneDiffCount = 0; 2624 priv->ContinueDiffCount = 0;
2625 } 2625 }
2626 } else { 2626 } else {
2627 priv->ContiuneDiffCount = 0; 2627 priv->ContinueDiffCount = 0;
2628 } 2628 }
2629 2629
2630 if (rate_count_diff <= 2630 if (rate_count_diff <=
2631 priv->rtllib->fsync_firstdiff_ratethreshold) { 2631 priv->rtllib->fsync_firstdiff_ratethreshold) {
2632 bSwitchFromCountDiff = true; 2632 bSwitchFromCountDiff = true;
2633 priv->ContiuneDiffCount = 0; 2633 priv->ContinueDiffCount = 0;
2634 } 2634 }
2635 priv->rate_record = rate_count; 2635 priv->rate_record = rate_count;
2636 priv->rateCountDiffRecord = rate_count_diff; 2636 priv->rateCountDiffRecord = rate_count_diff;
@@ -2677,10 +2677,10 @@ void dm_fsync_timer_callback(unsigned long data)
2677 write_nic_byte(dev, 0xC36, 0x5c); 2677 write_nic_byte(dev, 0xC36, 0x5c);
2678 write_nic_byte(dev, 0xC3e, 0x96); 2678 write_nic_byte(dev, 0xC3e, 0x96);
2679 } 2679 }
2680 priv->ContiuneDiffCount = 0; 2680 priv->ContinueDiffCount = 0;
2681 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 2681 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
2682 } 2682 }
2683 RT_TRACE(COMP_HALDM, "ContiuneDiffCount %d\n", priv->ContiuneDiffCount); 2683 RT_TRACE(COMP_HALDM, "ContinueDiffCount %d\n", priv->ContinueDiffCount);
2684 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d " 2684 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d "
2685 "bSwitchFsync %d\n", priv->rate_record, rate_count, 2685 "bSwitchFsync %d\n", priv->rate_record, rate_count,
2686 rate_count_diff, priv->bswitch_fsync); 2686 rate_count_diff, priv->bswitch_fsync);
@@ -2723,7 +2723,7 @@ static void dm_EndSWFsync(struct net_device *dev)
2723 write_nic_byte(dev, 0xC3e, 0x96); 2723 write_nic_byte(dev, 0xC3e, 0x96);
2724 } 2724 }
2725 2725
2726 priv->ContiuneDiffCount = 0; 2726 priv->ContinueDiffCount = 0;
2727 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 2727 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
2728} 2728}
2729 2729
@@ -2735,7 +2735,7 @@ static void dm_StartSWFsync(struct net_device *dev)
2735 2735
2736 RT_TRACE(COMP_HALDM, "%s\n", __func__); 2736 RT_TRACE(COMP_HALDM, "%s\n", __func__);
2737 priv->rate_record = 0; 2737 priv->rate_record = 0;
2738 priv->ContiuneDiffCount = 0; 2738 priv->ContinueDiffCount = 0;
2739 priv->rateCountDiffRecord = 0; 2739 priv->rateCountDiffRecord = 0;
2740 priv->bswitch_fsync = false; 2740 priv->bswitch_fsync = false;
2741 2741
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
index 4e93669210af..778d7baf8e08 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
@@ -1322,9 +1322,9 @@ static struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
1322 1322
1323struct iw_handler_def r8192_wx_handlers_def = { 1323struct iw_handler_def r8192_wx_handlers_def = {
1324 .standard = r8192_wx_handlers, 1324 .standard = r8192_wx_handlers,
1325 .num_standard = sizeof(r8192_wx_handlers) / sizeof(iw_handler), 1325 .num_standard = ARRAY_SIZE(r8192_wx_handlers),
1326 .private = r8192_private_handler, 1326 .private = r8192_private_handler,
1327 .num_private = sizeof(r8192_private_handler) / sizeof(iw_handler), 1327 .num_private = ARRAY_SIZE(r8192_private_handler),
1328 .num_private_args = sizeof(r8192_private_args) / 1328 .num_private_args = sizeof(r8192_private_args) /
1329 sizeof(struct iw_priv_args), 1329 sizeof(struct iw_priv_args),
1330 .get_wireless_stats = r8192_get_wireless_stats, 1330 .get_wireless_stats = r8192_get_wireless_stats,
diff --git a/drivers/staging/rtl8192e/rtl819x_TSProc.c b/drivers/staging/rtl8192e/rtl819x_TSProc.c
index 711a096be7a7..658e875232aa 100644
--- a/drivers/staging/rtl8192e/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_TSProc.c
@@ -310,7 +310,7 @@ bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
310 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs) 310 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
311{ 311{
312 u8 UP = 0; 312 u8 UP = 0;
313 if (is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr)) { 313 if (is_multicast_ether_addr(Addr)) {
314 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or " 314 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or "
315 "Multicast\n"); 315 "Multicast\n");
316 return false; 316 return false;
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index e26aec86a5c8..d7460ae3a765 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -169,7 +169,7 @@ struct cb_desc {
169 169
170 u8 nStuckCount; 170 u8 nStuckCount;
171 171
172 /* Tx Firmware Relaged flags (10-11)*/ 172 /* Tx Firmware Related flags (10-11)*/
173 u8 bCTSEnable:1; 173 u8 bCTSEnable:1;
174 u8 bRTSEnable:1; 174 u8 bRTSEnable:1;
175 u8 bUseShortGI:1; 175 u8 bUseShortGI:1;
@@ -1690,7 +1690,7 @@ enum rtllib_state {
1690 /* the association procedure is sending AUTH request*/ 1690 /* the association procedure is sending AUTH request*/
1691 RTLLIB_ASSOCIATING_AUTHENTICATING, 1691 RTLLIB_ASSOCIATING_AUTHENTICATING,
1692 1692
1693 /* the association procedure has successfully authentcated 1693 /* the association procedure has successfully authenticated
1694 * and is sending association request 1694 * and is sending association request
1695 */ 1695 */
1696 RTLLIB_ASSOCIATING_AUTHENTICATED, 1696 RTLLIB_ASSOCIATING_AUTHENTICATED,
@@ -2409,7 +2409,7 @@ struct rtllib_device {
2409 2409
2410 /* used instead of hard_start_xmit (not softmac_hard_start_xmit) 2410 /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
2411 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data 2411 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
2412 * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set 2412 * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
2413 * then also management frames are sent via this callback. 2413 * then also management frames are sent via this callback.
2414 * This function can't sleep. 2414 * This function can't sleep.
2415 */ 2415 */
@@ -2422,12 +2422,12 @@ struct rtllib_device {
2422 */ 2422 */
2423 void (*data_hard_stop)(struct net_device *dev); 2423 void (*data_hard_stop)(struct net_device *dev);
2424 2424
2425 /* OK this is complementar to data_poll_hard_stop */ 2425 /* OK this is complementing to data_poll_hard_stop */
2426 void (*data_hard_resume)(struct net_device *dev); 2426 void (*data_hard_resume)(struct net_device *dev);
2427 2427
2428 /* ask to the driver to retune the radio . 2428 /* ask to the driver to retune the radio .
2429 * This function can sleep. the driver should ensure 2429 * This function can sleep. the driver should ensure
2430 * the radio has been swithced before return. 2430 * the radio has been switched before return.
2431 */ 2431 */
2432 void (*set_chan)(struct net_device *dev, short ch); 2432 void (*set_chan)(struct net_device *dev, short ch);
2433 2433
@@ -2438,7 +2438,7 @@ struct rtllib_device {
2438 * The syncro version is similar to the start_scan but 2438 * The syncro version is similar to the start_scan but
2439 * does not return until all channels has been scanned. 2439 * does not return until all channels has been scanned.
2440 * this is called in user context and should sleep, 2440 * this is called in user context and should sleep,
2441 * it is called in a work_queue when swithcing to ad-hoc mode 2441 * it is called in a work_queue when switching to ad-hoc mode
2442 * or in behalf of iwlist scan when the card is associated 2442 * or in behalf of iwlist scan when the card is associated
2443 * and root user ask for a scan. 2443 * and root user ask for a scan.
2444 * the fucntion stop_scan should stop both the syncro and 2444 * the fucntion stop_scan should stop both the syncro and
@@ -2481,7 +2481,7 @@ struct rtllib_device {
2481 struct rtllib_network *network); 2481 struct rtllib_network *network);
2482 2482
2483 2483
2484 /* check whether Tx hw resouce available */ 2484 /* check whether Tx hw resource available */
2485 short (*check_nic_enough_desc)(struct net_device *dev, int queue_index); 2485 short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
2486 short (*get_nic_desc_num)(struct net_device *dev, int queue_index); 2486 short (*get_nic_desc_num)(struct net_device *dev, int queue_index);
2487 void (*SetBWModeHandler)(struct net_device *dev, 2487 void (*SetBWModeHandler)(struct net_device *dev,
@@ -2543,10 +2543,10 @@ struct rtllib_device {
2543/* Generate probe requests */ 2543/* Generate probe requests */
2544#define IEEE_SOFTMAC_PROBERQ (1<<4) 2544#define IEEE_SOFTMAC_PROBERQ (1<<4)
2545 2545
2546/* Generate respones to probe requests */ 2546/* Generate response to probe requests */
2547#define IEEE_SOFTMAC_PROBERS (1<<5) 2547#define IEEE_SOFTMAC_PROBERS (1<<5)
2548 2548
2549/* The ieee802.11 stack will manages the netif queue 2549/* The ieee802.11 stack will manage the netif queue
2550 * wake/stop for the driver, taking care of 802.11 2550 * wake/stop for the driver, taking care of 802.11
2551 * fragmentation. See softmac.c for details. */ 2551 * fragmentation. See softmac.c for details. */
2552#define IEEE_SOFTMAC_TX_QUEUE (1<<7) 2552#define IEEE_SOFTMAC_TX_QUEUE (1<<7)
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 13979b5ea32a..8b8a5c661a26 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -496,7 +496,7 @@ void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prx
496 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN); 496 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
497 } 497 }
498 498
499 /* Indicat the packets to upper layer */ 499 /* Indicate the packets to upper layer */
500 if (sub_skb) { 500 if (sub_skb) {
501 stats->rx_packets++; 501 stats->rx_packets++;
502 stats->rx_bytes += sub_skb->len; 502 stats->rx_bytes += sub_skb->len;
@@ -1000,7 +1000,7 @@ static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
1000 return -1; 1000 return -1;
1001 1001
1002 /* {broad,multi}cast packets to our BSS go through */ 1002 /* {broad,multi}cast packets to our BSS go through */
1003 if (is_multicast_ether_addr(dst) || is_broadcast_ether_addr(dst)) { 1003 if (is_multicast_ether_addr(dst)) {
1004 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) 1004 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1005 return -1; 1005 return -1;
1006 } 1006 }
@@ -1233,7 +1233,7 @@ static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
1233 if (is_multicast_ether_addr(dst)) 1233 if (is_multicast_ether_addr(dst))
1234 ieee->stats.multicast++; 1234 ieee->stats.multicast++;
1235 1235
1236 /* Indicat the packets to upper layer */ 1236 /* Indicate the packets to upper layer */
1237 memset(sub_skb->cb, 0, sizeof(sub_skb->cb)); 1237 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1238 sub_skb->protocol = eth_type_trans(sub_skb, dev); 1238 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1239 sub_skb->dev = dev; 1239 sub_skb->dev = dev;
@@ -1269,7 +1269,7 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1269 sc = le16_to_cpu(hdr->seq_ctl); 1269 sc = le16_to_cpu(hdr->seq_ctl);
1270 1270
1271 /*Filter pkt not to me*/ 1271 /*Filter pkt not to me*/
1272 multicast = is_multicast_ether_addr(hdr->addr1)|is_broadcast_ether_addr(hdr->addr1); 1272 multicast = is_multicast_ether_addr(hdr->addr1);
1273 unicast = !multicast; 1273 unicast = !multicast;
1274 if (unicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) { 1274 if (unicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) {
1275 if (ieee->bNetPromiscuousMode) 1275 if (ieee->bNetPromiscuousMode)
@@ -1350,7 +1350,7 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1350 /* Get TS for Rx Reorder */ 1350 /* Get TS for Rx Reorder */
1351 hdr = (struct rtllib_hdr_4addr *) skb->data; 1351 hdr = (struct rtllib_hdr_4addr *) skb->data;
1352 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data) 1352 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1353 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1) 1353 && !is_multicast_ether_addr(hdr->addr1)
1354 && (!bToOtherSTA)) { 1354 && (!bToOtherSTA)) {
1355 TID = Frame_QoSTID(skb->data); 1355 TID = Frame_QoSTID(skb->data);
1356 SeqNum = WLAN_GET_SEQ_SEQ(sc); 1356 SeqNum = WLAN_GET_SEQ_SEQ(sc);
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index c5a15dba1bf5..a21b4d91a596 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -31,7 +31,7 @@ short rtllib_is_shortslot(const struct rtllib_network *net)
31 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME; 31 return net->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME;
32} 32}
33 33
34/* returns the total length needed for pleacing the RATE MFIE 34/* returns the total length needed for placing the RATE MFIE
35 * tag and the EXTENDED RATE MFIE tag if needed. 35 * tag and the EXTENDED RATE MFIE tag if needed.
36 * It encludes two bytes per tag for the tag itself and its len 36 * It encludes two bytes per tag for the tag itself and its len
37 */ 37 */
@@ -49,7 +49,7 @@ static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee)
49 return rate_len; 49 return rate_len;
50} 50}
51 51
52/* pleace the MFIE rate, tag to the memory (double) poined. 52/* place the MFIE rate, tag to the memory (double) pointed.
53 * Then it updates the pointer so that 53 * Then it updates the pointer so that
54 * it points after the new MFIE tag added. 54 * it points after the new MFIE tag added.
55 */ 55 */
@@ -557,7 +557,7 @@ void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
557 * new network events, despite for updating the net list, 557 * new network events, despite for updating the net list,
558 * but we are temporarly 'unlinked' as the driver shall 558 * but we are temporarly 'unlinked' as the driver shall
559 * not filter RX frames and the channel is changing. 559 * not filter RX frames and the channel is changing.
560 * So the only situation in witch are interested is to check 560 * So the only situation in which are interested is to check
561 * if the state become LINKED because of the #1 situation 561 * if the state become LINKED because of the #1 situation
562 */ 562 */
563 563
@@ -1681,7 +1681,7 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1681 1681
1682 /* if the user set the AP check if match. 1682 /* if the user set the AP check if match.
1683 * if the network does not broadcast essid we check the 1683 * if the network does not broadcast essid we check the
1684 * user supplyed ANY essid 1684 * user supplied ANY essid
1685 * if the network does broadcast and the user does not set 1685 * if the network does broadcast and the user does not set
1686 * essid it is OK 1686 * essid it is OK
1687 * if the network does broadcast and the user did set essid 1687 * if the network does broadcast and the user did set essid
@@ -2444,16 +2444,16 @@ inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2444 2444
2445/* following are for a simplier TX queue management. 2445/* following are for a simplier TX queue management.
2446 * Instead of using netif_[stop/wake]_queue the driver 2446 * Instead of using netif_[stop/wake]_queue the driver
2447 * will uses these two function (plus a reset one), that 2447 * will use these two functions (plus a reset one), that
2448 * will internally uses the kernel netif_* and takes 2448 * will internally use the kernel netif_* and takes
2449 * care of the ieee802.11 fragmentation. 2449 * care of the ieee802.11 fragmentation.
2450 * So the driver receives a fragment per time and might 2450 * So the driver receives a fragment per time and might
2451 * call the stop function when it want without take care 2451 * call the stop function when it wants to not
2452 * to have enought room to TX an entire packet. 2452 * have enough room to TX an entire packet.
2453 * This might be useful if each fragment need it's own 2453 * This might be useful if each fragment needs it's own
2454 * descriptor, thus just keep a total free memory > than 2454 * descriptor, thus just keep a total free memory > than
2455 * the max fragmentation treshold is not enought.. If the 2455 * the max fragmentation threshold is not enough.. If the
2456 * ieee802.11 stack passed a TXB struct then you needed 2456 * ieee802.11 stack passed a TXB struct then you need
2457 * to keep N free descriptors where 2457 * to keep N free descriptors where
2458 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD 2458 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2459 * In this way you need just one and the 802.11 stack 2459 * In this way you need just one and the 802.11 stack
@@ -2696,15 +2696,15 @@ static void rtllib_start_ibss_wq(void *data)
2696 rtllib_softmac_check_all_nets(ieee); 2696 rtllib_softmac_check_all_nets(ieee);
2697 2697
2698 2698
2699 /* if not then the state is not linked. Maybe the user swithced to 2699 /* if not then the state is not linked. Maybe the user switched to
2700 * ad-hoc mode just after being in monitor mode, or just after 2700 * ad-hoc mode just after being in monitor mode, or just after
2701 * being very few time in managed mode (so the card have had no 2701 * being very few time in managed mode (so the card have had no
2702 * time to scan all the chans..) or we have just run up the iface 2702 * time to scan all the chans..) or we have just run up the iface
2703 * after setting ad-hoc mode. So we have to give another try.. 2703 * after setting ad-hoc mode. So we have to give another try..
2704 * Here, in ibss mode, should be safe to do this without extra care 2704 * Here, in ibss mode, should be safe to do this without extra care
2705 * (in bss mode we had to make sure no-one tryed to associate when 2705 * (in bss mode we had to make sure no-one tried to associate when
2706 * we had just checked the ieee->state and we was going to start the 2706 * we had just checked the ieee->state and we was going to start the
2707 * scan) beacause in ibss mode the rtllib_new_net function, when 2707 * scan) because in ibss mode the rtllib_new_net function, when
2708 * finds a good net, just set the ieee->state to RTLLIB_LINKED, 2708 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2709 * so, at worst, we waste a bit of time to initiate an unneeded syncro 2709 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2710 * scan, that will stop at the first round because it sees the state 2710 * scan, that will stop at the first round because it sees the state
@@ -2819,7 +2819,7 @@ void rtllib_start_bss(struct rtllib_device *ieee)
2819 2819
2820 /* ensure no-one start an associating process (thus setting 2820 /* ensure no-one start an associating process (thus setting
2821 * the ieee->state to rtllib_ASSOCIATING) while we 2821 * the ieee->state to rtllib_ASSOCIATING) while we
2822 * have just cheked it and we are going to enable scan. 2822 * have just checked it and we are going to enable scan.
2823 * The rtllib_new_net function is always called with 2823 * The rtllib_new_net function is always called with
2824 * lock held (from both rtllib_softmac_check_all_nets and 2824 * lock held (from both rtllib_softmac_check_all_nets and
2825 * the rx path), so we cannot be in the middle of such function 2825 * the rx path), so we cannot be in the middle of such function
@@ -2872,7 +2872,7 @@ static void rtllib_associate_retry_wq(void *data)
2872 2872
2873 /* until we do not set the state to RTLLIB_NOLINK 2873 /* until we do not set the state to RTLLIB_NOLINK
2874 * there are no possibility to have someone else trying 2874 * there are no possibility to have someone else trying
2875 * to start an association procdure (we get here with 2875 * to start an association procedure (we get here with
2876 * ieee->state = RTLLIB_ASSOCIATING). 2876 * ieee->state = RTLLIB_ASSOCIATING).
2877 * When we set the state to RTLLIB_NOLINK it is possible 2877 * When we set the state to RTLLIB_NOLINK it is possible
2878 * that the RX path run an attempt to associate, but 2878 * that the RX path run an attempt to associate, but
@@ -3679,8 +3679,7 @@ void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, u8 *asSta,
3679 3679
3680 RemovePeerTS(rtllib, asSta); 3680 RemovePeerTS(rtllib, asSta);
3681 3681
3682 3682 if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) {
3683 if (memcpy(rtllib->current_network.bssid, asSta, 6) == NULL) {
3684 rtllib->state = RTLLIB_NOLINK; 3683 rtllib->state = RTLLIB_NOLINK;
3685 3684
3686 for (i = 0; i < 6; i++) 3685 for (i = 0; i < 6; i++)
diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
index 1523bc7a2105..1bb6b52e0f24 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
@@ -479,7 +479,7 @@ int rtllib_wx_set_essid(struct rtllib_device *ieee,
479 479
480 480
481 /* this is just to be sure that the GET wx callback 481 /* this is just to be sure that the GET wx callback
482 * has consisten infos. not needed otherwise 482 * has consistent infos. not needed otherwise
483 */ 483 */
484 spin_lock_irqsave(&ieee->lock, flags); 484 spin_lock_irqsave(&ieee->lock, flags);
485 485
@@ -575,7 +575,7 @@ int rtllib_wx_set_power(struct rtllib_device *ieee,
575 if ((!ieee->sta_wake_up) || 575 if ((!ieee->sta_wake_up) ||
576 (!ieee->enter_sleep_state) || 576 (!ieee->enter_sleep_state) ||
577 (!ieee->ps_is_queue_empty)) { 577 (!ieee->ps_is_queue_empty)) {
578 RTLLIB_DEBUG(RTLLIB_DL_ERR, "%s(): PS mode is tryied to be use " 578 RTLLIB_DEBUG(RTLLIB_DL_ERR, "%s(): PS mode is tried to be use "
579 "but driver missed a callback\n\n", __func__); 579 "but driver missed a callback\n\n", __func__);
580 return -1; 580 return -1;
581 } 581 }
diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
index f451bfc27a86..42900ee4825b 100644
--- a/drivers/staging/rtl8192e/rtllib_tx.c
+++ b/drivers/staging/rtl8192e/rtllib_tx.c
@@ -59,7 +59,7 @@
59802.11 Data Frame 59802.11 Data Frame
60 60
61 61
62802.11 frame_contorl for data frames - 2 bytes 62802.11 frame_control for data frames - 2 bytes
63 ,-----------------------------------------------------------------------------------------. 63 ,-----------------------------------------------------------------------------------------.
64bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | 64bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
65 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------| 65 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
@@ -296,8 +296,7 @@ static void rtllib_tx_query_agg_cap(struct rtllib_device *ieee,
296 return; 296 return;
297 if (!IsQoSDataFrame(skb->data)) 297 if (!IsQoSDataFrame(skb->data))
298 return; 298 return;
299 if (is_multicast_ether_addr(hdr->addr1) || 299 if (is_multicast_ether_addr(hdr->addr1))
300 is_broadcast_ether_addr(hdr->addr1))
301 return; 300 return;
302 301
303 if (tcb_desc->bdhcp || ieee->CntAfterLink < 2) 302 if (tcb_desc->bdhcp || ieee->CntAfterLink < 2)
@@ -515,7 +514,7 @@ u16 rtllib_query_seqnum(struct rtllib_device *ieee, struct sk_buff *skb,
515{ 514{
516 u16 seqnum = 0; 515 u16 seqnum = 0;
517 516
518 if (is_multicast_ether_addr(dst) || is_broadcast_ether_addr(dst)) 517 if (is_multicast_ether_addr(dst))
519 return 0; 518 return 0;
520 if (IsQoSDataFrame(skb->data)) { 519 if (IsQoSDataFrame(skb->data)) {
521 struct tx_ts_record *pTS = NULL; 520 struct tx_ts_record *pTS = NULL;
@@ -576,7 +575,7 @@ int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
576 575
577 spin_lock_irqsave(&ieee->lock, flags); 576 spin_lock_irqsave(&ieee->lock, flags);
578 577
579 /* If there is no driver handler to take the TXB, dont' bother 578 /* If there is no driver handler to take the TXB, don't bother
580 * creating it... */ 579 * creating it... */
581 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & 580 if ((!ieee->hard_start_xmit && !(ieee->softmac_features &
582 IEEE_SOFTMAC_TX_QUEUE)) || 581 IEEE_SOFTMAC_TX_QUEUE)) ||
@@ -698,8 +697,7 @@ int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
698 ETH_ALEN); 697 ETH_ALEN);
699 } 698 }
700 699
701 bIsMulticast = is_broadcast_ether_addr(header.addr1) || 700 bIsMulticast = is_multicast_ether_addr(header.addr1);
702 is_multicast_ether_addr(header.addr1);
703 701
704 header.frame_ctl = cpu_to_le16(fc); 702 header.frame_ctl = cpu_to_le16(fc);
705 703
@@ -738,7 +736,7 @@ int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
738 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS)) 736 (CFG_RTLLIB_COMPUTE_FCS | CFG_RTLLIB_RESERVE_FCS))
739 bytes_per_frag -= RTLLIB_FCS_LEN; 737 bytes_per_frag -= RTLLIB_FCS_LEN;
740 738
741 /* Each fragment may need to have room for encryptiong 739 /* Each fragment may need to have room for encrypting
742 * pre/postfix */ 740 * pre/postfix */
743 if (encrypt) { 741 if (encrypt) {
744 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len + 742 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
index c27ff7edbaf2..c7e8d4d8ec2b 100644
--- a/drivers/staging/rtl8192e/rtllib_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_wx.c
@@ -88,7 +88,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
88 } 88 }
89 /* Add the protocol name */ 89 /* Add the protocol name */
90 iwe.cmd = SIOCGIWNAME; 90 iwe.cmd = SIOCGIWNAME;
91 for (i = 0; i < (sizeof(rtllib_modes)/sizeof(rtllib_modes[0])); i++) { 91 for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
92 if (network->mode&(1<<i)) { 92 if (network->mode&(1<<i)) {
93 sprintf(pname, rtllib_modes[i].mode_string, 93 sprintf(pname, rtllib_modes[i].mode_string,
94 rtllib_modes[i].mode_size); 94 rtllib_modes[i].mode_size);
@@ -408,7 +408,7 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
408 (*crypt)->priv); 408 (*crypt)->priv);
409 sec.flags |= (1 << key); 409 sec.flags |= (1 << key);
410 /* This ensures a key will be activated if no key is 410 /* This ensures a key will be activated if no key is
411 * explicitely set */ 411 * explicitly set */
412 if (key == sec.active_key) 412 if (key == sec.active_key)
413 sec.flags |= SEC_ACTIVE_KEY; 413 sec.flags |= SEC_ACTIVE_KEY;
414 ieee->crypt_info.tx_keyidx = key; 414 ieee->crypt_info.tx_keyidx = key;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
index e3d47bcf4cab..82d4bf6a86a5 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
@@ -161,7 +161,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
161 if (ieee->pHTInfo == NULL) 161 if (ieee->pHTInfo == NULL)
162 { 162 {
163 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n"); 163 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n");
164 return NULL; 164 goto failed;
165 } 165 }
166 HTUpdateDefaultSetting(ieee); 166 HTUpdateDefaultSetting(ieee);
167 HTInitializeHTInfo(ieee); //may move to other place. 167 HTInitializeHTInfo(ieee); //may move to other place.
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index be2a28cf8edd..e3cf7a45b900 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -671,7 +671,7 @@ void RxReorderIndicatePacket( struct ieee80211_device *ieee,
671 index = 1; 671 index = 1;
672 } else { 672 } else {
673 /* Current packet is going to be inserted into pending list.*/ 673 /* Current packet is going to be inserted into pending list.*/
674 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__); 674 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__FUNCTION__);
675 if(!list_empty(&ieee->RxReorder_Unused_List)) { 675 if(!list_empty(&ieee->RxReorder_Unused_List)) {
676 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List); 676 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
677 list_del_init(&pReorderEntry->List); 677 list_del_init(&pReorderEntry->List);
@@ -1285,7 +1285,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1285*/ 1285*/
1286//added by amy for reorder 1286//added by amy for reorder
1287 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data) 1287 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1288 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)) 1288 && !is_multicast_ether_addr(hdr->addr1))
1289 { 1289 {
1290 TID = Frame_QoSTID(skb->data); 1290 TID = Frame_QoSTID(skb->data);
1291 SeqNum = WLAN_GET_SEQ_SEQ(sc); 1291 SeqNum = WLAN_GET_SEQ_SEQ(sc);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index c2ab5fa15465..f6ff8cff313a 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -2062,7 +2062,7 @@ ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
2062 } 2062 }
2063 }else{ 2063 }else{
2064 ieee->softmac_stats.rx_auth_rs_err++; 2064 ieee->softmac_stats.rx_auth_rs_err++;
2065 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode); 2065 IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode);
2066 ieee80211_associate_abort(ieee); 2066 ieee80211_associate_abort(ieee);
2067 } 2067 }
2068 2068
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 59c45a510efb..3f5ceeb88b6c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -314,7 +314,7 @@ void ieee80211_tx_query_agg_cap(struct ieee80211_device* ieee, struct sk_buff* s
314 if (!IsQoSDataFrame(skb->data)) 314 if (!IsQoSDataFrame(skb->data))
315 return; 315 return;
316 316
317 if (is_multicast_ether_addr(hdr->addr1) || is_broadcast_ether_addr(hdr->addr1)) 317 if (is_multicast_ether_addr(hdr->addr1))
318 return; 318 return;
319 //check packet and mode later 319 //check packet and mode later
320#ifdef TO_DO_LIST 320#ifdef TO_DO_LIST
@@ -575,7 +575,7 @@ void ieee80211_txrate_selectmode(struct ieee80211_device* ieee, cb_desc* tcb_des
575 575
576void ieee80211_query_seqnum(struct ieee80211_device*ieee, struct sk_buff* skb, u8* dst) 576void ieee80211_query_seqnum(struct ieee80211_device*ieee, struct sk_buff* skb, u8* dst)
577{ 577{
578 if (is_multicast_ether_addr(dst) || is_broadcast_ether_addr(dst)) 578 if (is_multicast_ether_addr(dst))
579 return; 579 return;
580 if (IsQoSDataFrame(skb->data)) //we deal qos data only 580 if (IsQoSDataFrame(skb->data)) //we deal qos data only
581 { 581 {
@@ -693,8 +693,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
693 693
694 /* Determine fragmentation size based on destination (multicast 694 /* Determine fragmentation size based on destination (multicast
695 * and broadcast are not fragmented) */ 695 * and broadcast are not fragmented) */
696 if (is_multicast_ether_addr(header.addr1) || 696 if (is_multicast_ether_addr(header.addr1)) {
697 is_broadcast_ether_addr(header.addr1)) {
698 frag_size = MAX_FRAG_THRESHOLD; 697 frag_size = MAX_FRAG_THRESHOLD;
699 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK; 698 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
700 } 699 }
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 957ce4ef48b5..06a9824bbff1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -350,7 +350,7 @@ bool GetTs(
350 // We do not build any TS for Broadcast or Multicast stream. 350 // We do not build any TS for Broadcast or Multicast stream.
351 // So reject these kinds of search here. 351 // So reject these kinds of search here.
352 // 352 //
353 if(is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr)) 353 if (is_multicast_ether_addr(Addr))
354 { 354 {
355 IEEE80211_DEBUG(IEEE80211_DL_ERR, "get TS for Broadcast or Multicast\n"); 355 IEEE80211_DEBUG(IEEE80211_DL_ERR, "get TS for Broadcast or Multicast\n");
356 return false; 356 return false;
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index 8878cfeb0fbb..3c515b7bc542 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -14,7 +14,7 @@
14 14
15 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 15 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
16 16
17 We want to tanks the Authors of those projects and the Ndiswrapper 17 We want to thank the Authors of those projects and the Ndiswrapper
18 project Authors. 18 project Authors.
19*/ 19*/
20 20
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h b/drivers/staging/rtl8192u/r8180_93cx6.h
index fb3ac9766ea5..5cea51e1142e 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.h
+++ b/drivers/staging/rtl8192u/r8180_93cx6.h
@@ -7,7 +7,7 @@
7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon 7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon
8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
9 9
10 We want to tanks the Authors of such projects and the Ndiswrapper project Authors. 10 We want to thank the Authors of such projects and the Ndiswrapper project Authors.
11*/ 11*/
12 12
13/*This files contains card eeprom (93c46 or 93c56) programming routines*/ 13/*This files contains card eeprom (93c46 or 93c56) programming routines*/
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index 9b81f26d40fe..57e3383cc935 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -11,7 +11,7 @@
11 11
12 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 12 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
13 13
14 We want to tanks the Authors of those projects and the Ndiswrapper 14 We want to thank the Authors of those projects and the Ndiswrapper
15 project Authors. 15 project Authors.
16*/ 16*/
17 17
@@ -98,7 +98,7 @@ do { if(rt_global_debug_component & component) \
98#define COMP_INIT BIT2 // during driver initialization / halt / reset. 98#define COMP_INIT BIT2 // during driver initialization / halt / reset.
99 99
100 100
101#define COMP_RECV BIT3 // Reveive part data path. 101#define COMP_RECV BIT3 // Receive data path.
102#define COMP_SEND BIT4 // Send part path. 102#define COMP_SEND BIT4 // Send part path.
103#define COMP_IO BIT5 // I/O Related. Added by Annie, 2006-03-02. 103#define COMP_IO BIT5 // I/O Related. Added by Annie, 2006-03-02.
104#define COMP_POWER BIT6 // 802.11 Power Save mode or System/Device Power state related. 104#define COMP_POWER BIT6 // 802.11 Power Save mode or System/Device Power state related.
@@ -322,7 +322,7 @@ typedef struct _tx_fwinfo_819x_usb {
322 u8 TxSubCarrier:2; // This is used for legacy OFDM rate only. 322 u8 TxSubCarrier:2; // This is used for legacy OFDM rate only.
323 u8 STBC:2; 323 u8 STBC:2;
324 u8 AllowAggregation:1; 324 u8 AllowAggregation:1;
325 u8 RtsHT:1; //Interpre RtsRate field as high throughput data rate 325 u8 RtsHT:1; //Interpret RtsRate field as high throughput data rate
326 u8 RtsShort:1; //Short PLCP for CCK, or short GI for 11n MCS 326 u8 RtsShort:1; //Short PLCP for CCK, or short GI for 11n MCS
327 u8 RtsBandwidth:1; // This is used for HT MCS rate only. 327 u8 RtsBandwidth:1; // This is used for HT MCS rate only.
328 u8 RtsSubcarrier:2; // This is used for legacy OFDM rate only. 328 u8 RtsSubcarrier:2; // This is used for legacy OFDM rate only.
@@ -610,7 +610,6 @@ typedef struct Stats
610// unsigned long rxnopointer; 610// unsigned long rxnopointer;
611 unsigned long rxok; 611 unsigned long rxok;
612 unsigned long rxframgment; 612 unsigned long rxframgment;
613 unsigned long rxcmdpkt[4]; //08/05/08 amy rx cmd element txfeedback/bcn report/cfg set/query
614 unsigned long rxurberr; 613 unsigned long rxurberr;
615 unsigned long rxstaterr; 614 unsigned long rxstaterr;
616 unsigned long received_rate_histogram[4][32]; //0: Total, 1:OK, 2:CRC, 3:ICV, 2007 07 03 cosa 615 unsigned long received_rate_histogram[4][32]; //0: Total, 1:OK, 2:CRC, 3:ICV, 2007 07 03 cosa
@@ -1117,7 +1116,7 @@ typedef struct r8192_priv
1117 bool bfsync_processing; // 500ms Fsync timer is active or not 1116 bool bfsync_processing; // 500ms Fsync timer is active or not
1118 u32 rate_record; 1117 u32 rate_record;
1119 u32 rateCountDiffRecord; 1118 u32 rateCountDiffRecord;
1120 u32 ContiuneDiffCount; 1119 u32 ContinueDiffCount;
1121 bool bswitch_fsync; 1120 bool bswitch_fsync;
1122 1121
1123 u8 framesync; 1122 u8 framesync;
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 9c00865f302a..5981d6658320 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -203,7 +203,7 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
203 { 203 {
204 Dot11d_Init(ieee); 204 Dot11d_Init(ieee);
205 ieee->bGlobalDomain = false; 205 ieee->bGlobalDomain = false;
206 //acturally 8225 & 8256 rf chip only support B,G,24N mode 206 //actually 8225 & 8256 rf chips only support B,G,24N mode
207 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) 207 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256))
208 { 208 {
209 min_chan = 1; 209 min_chan = 1;
@@ -1103,7 +1103,7 @@ inline u16 rtl8192_rate2rate(short rate)
1103} 1103}
1104 1104
1105 1105
1106/* The protype of rx_isr has changed since one verion of Linux Kernel */ 1106/* The prototype of rx_isr has changed since one version of Linux Kernel */
1107static void rtl8192_rx_isr(struct urb *urb) 1107static void rtl8192_rx_isr(struct urb *urb)
1108{ 1108{
1109 struct sk_buff *skb = (struct sk_buff *) urb->context; 1109 struct sk_buff *skb = (struct sk_buff *) urb->context;
@@ -1476,7 +1476,7 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
1476 if(tcb_desc->queue_index != TXCMD_QUEUE) { 1476 if(tcb_desc->queue_index != TXCMD_QUEUE) {
1477 if(tx_urb->status == 0) { 1477 if(tx_urb->status == 0) {
1478 dev->trans_start = jiffies; 1478 dev->trans_start = jiffies;
1479 // As act as station mode, destion shall be unicast address. 1479 // Act as station mode, destination shall be unicast address.
1480 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom); 1480 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1481 //priv->ieee80211->stats.tx_packets++; 1481 //priv->ieee80211->stats.tx_packets++;
1482 priv->stats.txoktotal++; 1482 priv->stats.txoktotal++;
@@ -1522,13 +1522,13 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
1522 else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index])!= 0)&&\ 1522 else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index])!= 0)&&\
1523 (!(priv->ieee80211->queue_stop))) { 1523 (!(priv->ieee80211->queue_stop))) {
1524 // Tx Driver Aggregation process 1524 // Tx Driver Aggregation process
1525 /* The driver will aggregation the packets according to the following stets 1525 /* The driver will aggregation the packets according to the following stats
1526 * 1. check whether there's tx irq available, for it's a completion return 1526 * 1. check whether there's tx irq available, for it's a completion return
1527 * function, it should contain enough tx irq; 1527 * function, it should contain enough tx irq;
1528 * 2. check pakcet type; 1528 * 2. check packet type;
1529 * 3. initialize sendlist, check whether the to-be send packet no greater than 1 1529 * 3. initialize sendlist, check whether the to-be send packet no greater than 1
1530 * 4. aggregation the packets, and fill firmware info and tx desc to it, etc. 1530 * 4. aggregates the packets, and fill firmware info and tx desc into it, etc.
1531 * 5. check whehter the packet could be sent, otherwise just insert to wait head 1531 * 5. check whether the packet could be sent, otherwise just insert into wait head
1532 * */ 1532 * */
1533 skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]); 1533 skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
1534 if(!check_nic_enough_desc(dev, queue_index)) { 1534 if(!check_nic_enough_desc(dev, queue_index)) {
@@ -2447,7 +2447,7 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
2447 return 0; 2447 return 0;
2448} 2448}
2449 2449
2450/* handle manage frame frame beacon and probe response */ 2450/* handle and manage frame from beacon and probe response */
2451static int rtl8192_handle_beacon(struct net_device * dev, 2451static int rtl8192_handle_beacon(struct net_device * dev,
2452 struct ieee80211_beacon * beacon, 2452 struct ieee80211_beacon * beacon,
2453 struct ieee80211_network * network) 2453 struct ieee80211_network * network)
@@ -2625,7 +2625,7 @@ bool GetHalfNmodeSupportByAPs819xUsb(struct net_device* dev)
2625void rtl8192_refresh_supportrate(struct r8192_priv* priv) 2625void rtl8192_refresh_supportrate(struct r8192_priv* priv)
2626{ 2626{
2627 struct ieee80211_device* ieee = priv->ieee80211; 2627 struct ieee80211_device* ieee = priv->ieee80211;
2628 //we donot consider set support rate for ABG mode, only HT MCS rate is set here. 2628 //we do not consider set support rate for ABG mode, only HT MCS rate is set here.
2629 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G) 2629 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2630 { 2630 {
2631 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16); 2631 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
@@ -2780,10 +2780,10 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
2780 priv->TransmitConfig = 2780 priv->TransmitConfig =
2781 // TCR_DurProcMode | //for RTL8185B, duration setting by HW 2781 // TCR_DurProcMode | //for RTL8185B, duration setting by HW
2782 //? TCR_DISReqQsize | 2782 //? TCR_DISReqQsize |
2783 (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)| // Max DMA Burst Size per Tx DMA Burst, 7: reservied. 2783 (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)| // Max DMA Burst Size per Tx DMA Burst, 7: reserved.
2784 (priv->ShortRetryLimit<<TCR_SRL_OFFSET)| // Short retry limit 2784 (priv->ShortRetryLimit<<TCR_SRL_OFFSET)| // Short retry limit
2785 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit 2785 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
2786 (false ? TCR_SAT: 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them 2786 (false ? TCR_SAT: 0); // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
2787#ifdef TO_DO_LIST 2787#ifdef TO_DO_LIST
2788 if(Adapter->bInHctTest) 2788 if(Adapter->bInHctTest)
2789 pHalData->ReceiveConfig = pHalData->CSMethod | 2789 pHalData->ReceiveConfig = pHalData->CSMethod |
@@ -3437,7 +3437,7 @@ if(Adapter->ResetProgress == RESET_TYPE_NORESET)
3437 { // User disable RF via registry. 3437 { // User disable RF via registry.
3438 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n")); 3438 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
3439 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW); 3439 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
3440 // Those action will be discard in MgntActSet_RF_State because off the same state 3440 // Those actions will be discard in MgntActSet_RF_State because of the same state
3441 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++) 3441 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
3442 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0); 3442 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3443 } 3443 }
@@ -3458,7 +3458,7 @@ if(Adapter->ResetProgress == RESET_TYPE_NORESET)
3458 if(pHalData->eRFPowerState == eRfOff) 3458 if(pHalData->eRFPowerState == eRfOff)
3459 { 3459 {
3460 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason); 3460 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
3461 // Those action will be discard in MgntActSet_RF_State because off the same state 3461 // Those actions will be discard in MgntActSet_RF_State because of the same state
3462 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++) 3462 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
3463 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0); 3463 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3464 } 3464 }
@@ -3586,7 +3586,7 @@ TxCheckStuck(struct net_device *dev)
3586 //unsigned long flags; 3586 //unsigned long flags;
3587 3587
3588 // 3588 //
3589 // Decide Stuch threshold according to current power save mode 3589 // Decide such threshold according to current power save mode
3590 // 3590 //
3591 3591
3592// RT_TRACE(COMP_RESET, " ==> TxCheckStuck()\n"); 3592// RT_TRACE(COMP_RESET, " ==> TxCheckStuck()\n");
@@ -3745,7 +3745,7 @@ rtl819x_ifcheck_resetornot(struct net_device *dev)
3745 3745
3746 // Driver should not check RX stuck in IBSS mode because it is required to 3746 // Driver should not check RX stuck in IBSS mode because it is required to
3747 // set Check BSSID in order to send beacon, however, if check BSSID is 3747 // set Check BSSID in order to send beacon, however, if check BSSID is
3748 // set, STA cannot hear any packet a all. Emily, 2008.04.12 3748 // set, STA cannot hear any packet at all. Emily, 2008.04.12
3749 RxResetType = RxCheckStuck(dev); 3749 RxResetType = RxCheckStuck(dev);
3750 } 3750 }
3751 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL) 3751 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
@@ -3962,7 +3962,7 @@ RESET_START:
3962 up(&priv->wx_sem); 3962 up(&priv->wx_sem);
3963 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__); 3963 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
3964 //rtl8192_irq_disable(dev); 3964 //rtl8192_irq_disable(dev);
3965 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__); 3965 RT_TRACE(COMP_RESET,"%s():===========>start up the driver\n",__FUNCTION__);
3966 reset_status = _rtl8192_up(dev); 3966 reset_status = _rtl8192_up(dev);
3967 3967
3968 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__); 3968 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
@@ -4155,7 +4155,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
4155void watch_dog_timer_callback(unsigned long data) 4155void watch_dog_timer_callback(unsigned long data)
4156{ 4156{
4157 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data); 4157 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
4158 //printk("===============>watch_dog timer\n"); 4158 //printk("===============>watch_dog timer\n");
4159 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq, 0); 4159 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq, 0);
4160 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME)); 4160 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
4161} 4161}
@@ -4170,7 +4170,7 @@ int _rtl8192_up(struct net_device *dev)
4170 init_status = rtl8192_adapter_start(dev); 4170 init_status = rtl8192_adapter_start(dev);
4171 if(!init_status) 4171 if(!init_status)
4172 { 4172 {
4173 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n", __FUNCTION__); 4173 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization failed!\n", __FUNCTION__);
4174 priv->up=priv->ieee80211->ieee_up = 0; 4174 priv->up=priv->ieee80211->ieee_up = 0;
4175 return -EAGAIN; 4175 return -EAGAIN;
4176 } 4176 }
@@ -4256,7 +4256,7 @@ int rtl8192_down(struct net_device *dev)
4256 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ [i]); 4256 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ [i]);
4257 } 4257 }
4258 4258
4259 //as cancel_delayed_work will del work->timer, so if work is not definedas struct delayed_work, it will corrupt 4259 //as cancel_delayed_work will del work->timer, so if work is not defined as struct delayed_work, it will corrupt
4260// flush_scheduled_work(); 4260// flush_scheduled_work();
4261 rtl8192_cancel_deferred_work(priv); 4261 rtl8192_cancel_deferred_work(priv);
4262 deinit_hal_dm(dev); 4262 deinit_hal_dm(dev);
@@ -4516,7 +4516,7 @@ u8 HwRateToMRate90(bool bIsHT, u8 rate)
4516 4516
4517/** 4517/**
4518 * Function: UpdateRxPktTimeStamp 4518 * Function: UpdateRxPktTimeStamp
4519 * Overview: Recored down the TSF time stamp when receiving a packet 4519 * Overview: Record the TSF time stamp when receiving a packet
4520 * 4520 *
4521 * Input: 4521 * Input:
4522 * PADAPTER Adapter 4522 * PADAPTER Adapter
@@ -4556,10 +4556,10 @@ long rtl819x_translate_todbm(u8 signal_strength_index )// 0-100 index.
4556} 4556}
4557 4557
4558 4558
4559/* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to 4559/* 2008/01/22 MH We can not declare RSSI/EVM total value of sliding window to
4560 be a local static. Otherwise, it may increase when we return from S3/S4. The 4560 be a local static. Otherwise, it may increase when we return from S3/S4. The
4561 value will be kept in memory or disk. We must delcare the value in adapter 4561 value will be kept in memory or disk. Declare the value in the adaptor
4562 and it will be reinitialized when return from S3/S4. */ 4562 and it will be reinitialized when returned from S3/S4. */
4563void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats) 4563void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
4564{ 4564{
4565 bool bcheck = false; 4565 bool bcheck = false;
@@ -5091,8 +5091,8 @@ static void rtl8192_query_rxphystatus(
5091 tmp_rxevm = pofdm_buf->rxevm_X[i]; 5091 tmp_rxevm = pofdm_buf->rxevm_X[i];
5092 rx_evmX = (char)(tmp_rxevm); 5092 rx_evmX = (char)(tmp_rxevm);
5093 5093
5094 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment 5094 // Do not use shift operation like "rx_evmX >>= 1" because the compiler of free build environment
5095 // fill most significant bit to "zero" when doing shifting operation which may change a negative 5095 // will set the most significant bit to "zero" when doing shifting operation which may change a negative
5096 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore. 5096 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
5097 rx_evmX /= 2; //dbm 5097 rx_evmX /= 2; //dbm
5098 5098
@@ -5171,7 +5171,7 @@ void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
5171 type = WLAN_FC_GET_TYPE(fc); 5171 type = WLAN_FC_GET_TYPE(fc);
5172 praddr = hdr->addr1; 5172 praddr = hdr->addr1;
5173 5173
5174 /* Check if the received packet is acceptabe. */ 5174 /* Check if the received packet is acceptable. */
5175 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) && 5175 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
5176 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3)) 5176 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
5177 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV)); 5177 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
@@ -5211,7 +5211,7 @@ void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
5211 5211
5212/** 5212/**
5213* Function: UpdateReceivedRateHistogramStatistics 5213* Function: UpdateReceivedRateHistogramStatistics
5214* Overview: Recored down the received data rate 5214* Overview: Record the received data rate
5215* 5215*
5216* Input: 5216* Input:
5217* struct net_device *dev 5217* struct net_device *dev
@@ -5401,7 +5401,7 @@ void query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats,
5401 } 5401 }
5402 5402
5403#ifdef USB_RX_AGGREGATION_SUPPORT 5403#ifdef USB_RX_AGGREGATION_SUPPORT
5404 /* for the rx aggregated sub frame, the redundant space truelly contained in the packet */ 5404 /* for the rx aggregated sub frame, the redundant space truly contained in the packet */
5405 if(bIsRxAggrSubframe) { 5405 if(bIsRxAggrSubframe) {
5406 skb_pull(skb, 8); 5406 skb_pull(skb, 8);
5407 } 5407 }
@@ -5480,7 +5480,7 @@ void rtl8192_rx_nomal(struct sk_buff* skb)
5480 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false); 5480 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false);
5481 } 5481 }
5482#endif 5482#endif
5483 /* Process the MPDU recevied */ 5483 /* Process the MPDU received */
5484 skb_trim(skb, skb->len - 4/*sCrcLng*/); 5484 skb_trim(skb, skb->len - 4/*sCrcLng*/);
5485 5485
5486 rx_pkt_len = skb->len; 5486 rx_pkt_len = skb->len;
@@ -5538,7 +5538,7 @@ void rtl8192_rx_nomal(struct sk_buff* skb)
5538 if(PacketLength > agg_skb->len) { 5538 if(PacketLength > agg_skb->len) {
5539 break; 5539 break;
5540 } 5540 }
5541 /* Process the MPDU recevied */ 5541 /* Process the MPDU received */
5542 skb = dev_alloc_skb(PacketLength); 5542 skb = dev_alloc_skb(PacketLength);
5543 memcpy(skb_put(skb,PacketLength),agg_skb->data, PacketLength); 5543 memcpy(skb_put(skb,PacketLength),agg_skb->data, PacketLength);
5544 skb_trim(skb, skb->len - 4/*sCrcLng*/); 5544 skb_trim(skb, skb->len - 4/*sCrcLng*/);
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 2dde9fa5c21e..cd8dc85e9c0f 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -38,7 +38,7 @@ static u32 edca_setting_UL[HT_IOT_PEER_MAX] =
38/*------------------------Define global variable-----------------------------*/ 38/*------------------------Define global variable-----------------------------*/
39// Debug variable ? 39// Debug variable ?
40dig_t dm_digtable; 40dig_t dm_digtable;
41// Store current shoftware write register content for MAC PHY. 41// Store current software write register content for MAC PHY.
42u8 dm_shadow[16][256] = {{0}}; 42u8 dm_shadow[16][256] = {{0}};
43// For Dynamic Rx Path Selection by Signal Strength 43// For Dynamic Rx Path Selection by Signal Strength
44DRxPathSel DM_RxPathSelTable; 44DRxPathSel DM_RxPathSelTable;
@@ -119,7 +119,7 @@ static void dm_pd_th(struct net_device *dev);
119static void dm_cs_ratio(struct net_device *dev); 119static void dm_cs_ratio(struct net_device *dev);
120 120
121static void dm_init_ctstoself(struct net_device *dev); 121static void dm_init_ctstoself(struct net_device *dev);
122// DM --> EDCA turboe mode control 122// DM --> EDCA turbo mode control
123static void dm_check_edca_turbo(struct net_device *dev); 123static void dm_check_edca_turbo(struct net_device *dev);
124 124
125// DM --> HW RF control 125// DM --> HW RF control
@@ -348,7 +348,7 @@ extern void init_rate_adaptive(struct net_device * dev)
348 * 348 *
349 * Revised History: 349 * Revised History:
350 * When Who Remark 350 * When Who Remark
351 * 05/26/08 amy Create version 0 proting from windows code. 351 * 05/26/08 amy Create version 0 porting from windows code.
352 * 352 *
353 *---------------------------------------------------------------------------*/ 353 *---------------------------------------------------------------------------*/
354static void dm_check_rate_adaptive(struct net_device * dev) 354static void dm_check_rate_adaptive(struct net_device * dev)
@@ -543,7 +543,7 @@ static u32 OFDMSwingTable[OFDM_Table_Length] = {
543 0x5a400169, // 3, +3db 543 0x5a400169, // 3, +3db
544 0x50800142, // 4, +2db 544 0x50800142, // 4, +2db
545 0x47c0011f, // 5, +1db 545 0x47c0011f, // 5, +1db
546 0x40000100, // 6, +0db ===> default, upper for higher temprature, lower for low temprature 546 0x40000100, // 6, +0db ===> default, upper for higher temperature, lower for low temperature
547 0x390000e4, // 7, -1db 547 0x390000e4, // 7, -1db
548 0x32c000cb, // 8, -2db 548 0x32c000cb, // 8, -2db
549 0x2d4000b5, // 9, -3db 549 0x2d4000b5, // 9, -3db
@@ -678,7 +678,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device * dev)
678 { 678 {
679 write_nic_byte(dev, 0x1ba, 0); 679 write_nic_byte(dev, 0x1ba, 0);
680 viviflag = FALSE; 680 viviflag = FALSE;
681 RT_TRACE(COMP_POWER_TRACKING, "we filted this data\n"); 681 RT_TRACE(COMP_POWER_TRACKING, "we filtered the data\n");
682 for(k = 0;k < 5; k++) 682 for(k = 0;k < 5; k++)
683 tmp_report[k] = 0; 683 tmp_report[k] = 0;
684 break; 684 break;
@@ -864,14 +864,14 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device * dev)
864 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d \n", tmpRegA); 864 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d \n", tmpRegA);
865 if(tmpRegA < 3 || tmpRegA > 13) 865 if(tmpRegA < 3 || tmpRegA > 13)
866 return; 866 return;
867 if(tmpRegA >= 12) // if over 12, TP will be bad when high temprature 867 if(tmpRegA >= 12) // if over 12, TP will be bad when high temperature
868 tmpRegA = 12; 868 tmpRegA = 12;
869 RT_TRACE(COMP_POWER_TRACKING, "Valid ThermalMeterA = %d \n", tmpRegA); 869 RT_TRACE(COMP_POWER_TRACKING, "Valid ThermalMeterA = %d \n", tmpRegA);
870 priv->ThermalMeter[0] = ThermalMeterVal; //We use fixed value by Bryant's suggestion 870 priv->ThermalMeter[0] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
871 priv->ThermalMeter[1] = ThermalMeterVal; //We use fixed value by Bryant's suggestion 871 priv->ThermalMeter[1] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
872 872
873 //Get current RF-A temprature index 873 //Get current RF-A temperature index
874 if(priv->ThermalMeter[0] >= (u8)tmpRegA) //lower temprature 874 if(priv->ThermalMeter[0] >= (u8)tmpRegA) //lower temperature
875 { 875 {
876 tmpOFDMindex = tmpCCK20Mindex = 6+(priv->ThermalMeter[0]-(u8)tmpRegA); 876 tmpOFDMindex = tmpCCK20Mindex = 6+(priv->ThermalMeter[0]-(u8)tmpRegA);
877 tmpCCK40Mindex = tmpCCK20Mindex - 6; 877 tmpCCK40Mindex = tmpCCK20Mindex - 6;
@@ -885,7 +885,7 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device * dev)
885 else 885 else
886 { 886 {
887 tmpval = ((u8)tmpRegA - priv->ThermalMeter[0]); 887 tmpval = ((u8)tmpRegA - priv->ThermalMeter[0]);
888 if(tmpval >= 6) // higher temprature 888 if(tmpval >= 6) // higher temperature
889 tmpOFDMindex = tmpCCK20Mindex = 0; // max to +6dB 889 tmpOFDMindex = tmpCCK20Mindex = 0; // max to +6dB
890 else 890 else
891 tmpOFDMindex = tmpCCK20Mindex = 6 - tmpval; 891 tmpOFDMindex = tmpCCK20Mindex = 6 - tmpval;
@@ -1457,9 +1457,9 @@ static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
1457{ 1457{
1458 struct r8192_priv *priv = ieee80211_priv(dev); 1458 struct r8192_priv *priv = ieee80211_priv(dev);
1459 1459
1460 // Tx Power tracking by Theremal Meter require Firmware R/W 3-wire. This mechanism 1460 // Tx Power tracking by Thermal Meter requires Firmware R/W 3-wire. This mechanism
1461 // can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w 1461 // can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
1462 // 3-wire by driver cause RF goes into wrong state. 1462 // 3-wire by driver causes RF to go into a wrong state.
1463 if(priv->ieee80211->FwRWRF) 1463 if(priv->ieee80211->FwRWRF)
1464 priv->btxpower_tracking = TRUE; 1464 priv->btxpower_tracking = TRUE;
1465 else 1465 else
@@ -1520,7 +1520,7 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
1520 1520
1521 if(!TM_Trigger) 1521 if(!TM_Trigger)
1522 { 1522 {
1523 //Attention!! You have to wirte all 12bits data to RF, or it may cause RF to crash 1523 //Attention!! You have to write all 12bits of data to RF, or it may cause RF to crash
1524 //actually write reg0x02 bit1=0, then bit1=1. 1524 //actually write reg0x02 bit1=0, then bit1=1.
1525 //DbgPrint("Trigger ThermalMeter, write RF reg0x2 = 0x4d to 0x4f\n"); 1525 //DbgPrint("Trigger ThermalMeter, write RF reg0x2 = 0x4d to 0x4f\n");
1526 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d); 1526 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
@@ -1744,7 +1744,7 @@ extern void dm_restore_dynamic_mechanism_state(struct net_device *dev)
1744 write_nic_dword(dev, RATR0, ratr_value); 1744 write_nic_dword(dev, RATR0, ratr_value);
1745 write_nic_byte(dev, UFWP, 1); 1745 write_nic_byte(dev, UFWP, 1);
1746 } 1746 }
1747 //Resore TX Power Tracking Index 1747 //Restore TX Power Tracking Index
1748 if(priv->btxpower_trackingInit && priv->btxpower_tracking){ 1748 if(priv->btxpower_trackingInit && priv->btxpower_tracking){
1749 dm_txpower_reset_recovery(dev); 1749 dm_txpower_reset_recovery(dev);
1750 } 1750 }
@@ -2031,7 +2031,7 @@ static void dm_dig_init(struct net_device *dev)
2031 dm_digtable.dbg_mode = DM_DBG_OFF; //off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig 2031 dm_digtable.dbg_mode = DM_DBG_OFF; //off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig
2032 dm_digtable.dig_algorithm_switch = 0; 2032 dm_digtable.dig_algorithm_switch = 0;
2033 2033
2034 /* 2007/10/04 MH Define init gain threshol. */ 2034 /* 2007/10/04 MH Define init gain threshold. */
2035 dm_digtable.dig_state = DM_STA_DIG_MAX; 2035 dm_digtable.dig_state = DM_STA_DIG_MAX;
2036 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX; 2036 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
2037 dm_digtable.initialgain_lowerbound_state = false; 2037 dm_digtable.initialgain_lowerbound_state = false;
@@ -2097,7 +2097,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi(
2097 return; 2097 return;
2098 2098
2099 //DbgPrint("Dig by Sw Rssi \n"); 2099 //DbgPrint("Dig by Sw Rssi \n");
2100 if(dm_digtable.dig_algorithm_switch) // if swithed algorithm, we have to disable FW Dig. 2100 if(dm_digtable.dig_algorithm_switch) // if switched algorithm, we have to disable FW Dig.
2101 fw_dig = 0; 2101 fw_dig = 0;
2102 if(fw_dig <= 3) // execute several times to make sure the FW Dig is disabled 2102 if(fw_dig <= 3) // execute several times to make sure the FW Dig is disabled
2103 {// FW DIG Off 2103 {// FW DIG Off
@@ -2160,8 +2160,8 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
2160 /*DbgPrint("DIG Check\n\r RSSI=%d LOW=%d HIGH=%d STATE=%d", 2160 /*DbgPrint("DIG Check\n\r RSSI=%d LOW=%d HIGH=%d STATE=%d",
2161 pHalData->UndecoratedSmoothedPWDB, DM_DigTable.RssiLowThresh, 2161 pHalData->UndecoratedSmoothedPWDB, DM_DigTable.RssiLowThresh,
2162 DM_DigTable.RssiHighThresh, DM_DigTable.Dig_State);*/ 2162 DM_DigTable.RssiHighThresh, DM_DigTable.Dig_State);*/
2163 /* 1. When RSSI decrease, We have to judge if it is smaller than a treshold 2163 /* 1. When RSSI decrease, We have to judge if it is smaller than a threshold
2164 and then execute below step. */ 2164 and then execute the step below. */
2165 if ((priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh)) 2165 if ((priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh))
2166 { 2166 {
2167 /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters 2167 /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
@@ -2220,8 +2220,8 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
2220 2220
2221 } 2221 }
2222 2222
2223 /* 2. When RSSI increase, We have to judge if it is larger than a treshold 2223 /* 2. When RSSI increase, We have to judge if it is larger than a threshold
2224 and then execute below step. */ 2224 and then execute the step below. */
2225 if ((priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) ) 2225 if ((priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) )
2226 { 2226 {
2227 u8 reset_flag = 0; 2227 u8 reset_flag = 0;
@@ -2329,7 +2329,7 @@ static void dm_ctrl_initgain_byrssi_highpwr(
2329 } 2329 }
2330 2330
2331 /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if 2331 /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
2332 it is larger than a treshold and then execute below step. */ 2332 it is larger than a threshold and then execute the step below. */
2333 // 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue. 2333 // 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
2334 if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_power_highthresh) 2334 if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_power_highthresh)
2335 { 2335 {
@@ -2841,8 +2841,8 @@ static void dm_check_rfctrl_gpio(struct net_device * dev)
2841{ 2841{
2842 //struct r8192_priv *priv = ieee80211_priv(dev); 2842 //struct r8192_priv *priv = ieee80211_priv(dev);
2843 2843
2844 // Walk around for DTM test, we will not enable HW - radio on/off because r/w 2844 // Work around for DTM test, we will not enable HW - radio on/off because r/w
2845 // page 1 register before Lextra bus is enabled cause system fails when resuming 2845 // page 1 register before extra bus is enabled causing system failures when resuming
2846 // from S4. 20080218, Emily 2846 // from S4. 20080218, Emily
2847 2847
2848 // Stop to execute workitem to prevent S3/S4 bug. 2848 // Stop to execute workitem to prevent S3/S4 bug.
@@ -3377,30 +3377,30 @@ extern void dm_fsync_timer_callback(unsigned long data)
3377 { 3377 {
3378 3378
3379 u32 DiffNum = priv->rateCountDiffRecord - rate_count_diff; 3379 u32 DiffNum = priv->rateCountDiffRecord - rate_count_diff;
3380 // Contiune count 3380 // Continue count
3381 if(DiffNum >= priv->ieee80211->fsync_seconddiff_ratethreshold) 3381 if(DiffNum >= priv->ieee80211->fsync_seconddiff_ratethreshold)
3382 priv->ContiuneDiffCount++; 3382 priv->ContinueDiffCount++;
3383 else 3383 else
3384 priv->ContiuneDiffCount = 0; 3384 priv->ContinueDiffCount = 0;
3385 3385
3386 // Contiune count over 3386 // Continue count over
3387 if(priv->ContiuneDiffCount >=2) 3387 if(priv->ContinueDiffCount >=2)
3388 { 3388 {
3389 bSwitchFromCountDiff = true; 3389 bSwitchFromCountDiff = true;
3390 priv->ContiuneDiffCount = 0; 3390 priv->ContinueDiffCount = 0;
3391 } 3391 }
3392 } 3392 }
3393 else 3393 else
3394 { 3394 {
3395 // Stop contiune count 3395 // Stop the continued count
3396 priv->ContiuneDiffCount = 0; 3396 priv->ContinueDiffCount = 0;
3397 } 3397 }
3398 3398
3399 //If Count diff <= FsyncRateCountThreshold 3399 //If Count diff <= FsyncRateCountThreshold
3400 if(rate_count_diff <= priv->ieee80211->fsync_firstdiff_ratethreshold) 3400 if(rate_count_diff <= priv->ieee80211->fsync_firstdiff_ratethreshold)
3401 { 3401 {
3402 bSwitchFromCountDiff = true; 3402 bSwitchFromCountDiff = true;
3403 priv->ContiuneDiffCount = 0; 3403 priv->ContinueDiffCount = 0;
3404 } 3404 }
3405 priv->rate_record = rate_count; 3405 priv->rate_record = rate_count;
3406 priv->rateCountDiffRecord = rate_count_diff; 3406 priv->rateCountDiffRecord = rate_count_diff;
@@ -3468,14 +3468,14 @@ extern void dm_fsync_timer_callback(unsigned long data)
3468 #endif 3468 #endif
3469 write_nic_byte(dev, 0xC3e, 0x96); 3469 write_nic_byte(dev, 0xC3e, 0x96);
3470 } 3470 }
3471 priv->ContiuneDiffCount = 0; 3471 priv->ContinueDiffCount = 0;
3472 #ifdef RTL8190P 3472 #ifdef RTL8190P
3473 write_nic_dword(dev, rOFDM0_RxDetector2, 0x164052cd); 3473 write_nic_dword(dev, rOFDM0_RxDetector2, 0x164052cd);
3474 #else 3474 #else
3475 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 3475 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
3476 #endif 3476 #endif
3477 } 3477 }
3478 RT_TRACE(COMP_HALDM, "ContiuneDiffCount %d\n", priv->ContiuneDiffCount); 3478 RT_TRACE(COMP_HALDM, "ContinueDiffCount %d\n", priv->ContinueDiffCount);
3479 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync); 3479 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync);
3480} 3480}
3481 3481
@@ -3507,7 +3507,7 @@ static void dm_EndSWFsync(struct net_device *dev)
3507 write_nic_byte(dev, 0xC3e, 0x96); 3507 write_nic_byte(dev, 0xC3e, 0x96);
3508 } 3508 }
3509 3509
3510 priv->ContiuneDiffCount = 0; 3510 priv->ContinueDiffCount = 0;
3511#ifndef RTL8190P 3511#ifndef RTL8190P
3512 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 3512 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
3513#endif 3513#endif
@@ -3523,8 +3523,8 @@ static void dm_StartSWFsync(struct net_device *dev)
3523 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__); 3523 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
3524 // Initial rate record to zero, start to record. 3524 // Initial rate record to zero, start to record.
3525 priv->rate_record = 0; 3525 priv->rate_record = 0;
3526 // Initial contiune diff count to zero, start to record. 3526 // Initialize continue diff count to zero, start to record.
3527 priv->ContiuneDiffCount = 0; 3527 priv->ContinueDiffCount = 0;
3528 priv->rateCountDiffRecord = 0; 3528 priv->rateCountDiffRecord = 0;
3529 priv->bswitch_fsync = false; 3529 priv->bswitch_fsync = false;
3530 3530
@@ -3875,7 +3875,7 @@ static void dm_send_rssi_tofw(struct net_device *dev)
3875 3875
3876 // If we test chariot, we should stop the TX command ? 3876 // If we test chariot, we should stop the TX command ?
3877 // Because 92E will always silent reset when we send tx command. We use register 3877 // Because 92E will always silent reset when we send tx command. We use register
3878 // 0x1e0(byte) to botify driver. 3878 // 0x1e0(byte) to notify driver.
3879 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb); 3879 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);
3880 return; 3880 return;
3881 tx_cmd.Op = TXCMD_SET_RX_RSSI; 3881 tx_cmd.Op = TXCMD_SET_RX_RSSI;
diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h
index e89aaf70143b..1bfe871dcfb2 100644
--- a/drivers/staging/rtl8192u/r8192U_hw.h
+++ b/drivers/staging/rtl8192u/r8192U_hw.h
@@ -10,7 +10,7 @@
10 Parts of this driver are based on the Intel Pro Wireless 10 Parts of this driver are based on the Intel Pro Wireless
11 2100 GPL driver. 11 2100 GPL driver.
12 12
13 We want to tanks the Authors of those projects 13 We want to thank the Authors of those projects
14 and the Ndiswrapper project Authors. 14 and the Ndiswrapper project Authors.
15*/ 15*/
16 16
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index f6408f98ede6..71f2d2349c38 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -13,7 +13,7 @@
13 13
14 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 14 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
15 15
16 We want to tanks the Authors of those projects and the Ndiswrapper 16 We want to thank the Authors of those projects and the Ndiswrapper
17 project Authors. 17 project Authors.
18*/ 18*/
19 19
@@ -256,7 +256,7 @@ static int r8192_wx_get_ap_status(struct net_device *dev,
256 //count the length of input ssid 256 //count the length of input ssid
257 for(name_len=0 ; ((char*)wrqu->data.pointer)[name_len]!='\0' ; name_len++); 257 for(name_len=0 ; ((char*)wrqu->data.pointer)[name_len]!='\0' ; name_len++);
258 258
259 //search for the correspoding info which is received 259 //search for the corresponding info which is received
260 list_for_each_entry(target, &ieee->network_list, list) { 260 list_for_each_entry(target, &ieee->network_list, list) {
261 if ( (target->ssid_len == name_len) && 261 if ( (target->ssid_len == name_len) &&
262 (strncmp(target->ssid, (char*)wrqu->data.pointer, name_len)==0)){ 262 (strncmp(target->ssid, (char*)wrqu->data.pointer, name_len)==0)){
@@ -419,7 +419,7 @@ static int rtl8180_wx_get_range(struct net_device *dev,
419 range->max_qual.updated = 7; /* Updated all three */ 419 range->max_qual.updated = 7; /* Updated all three */
420 420
421 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */ 421 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
422 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ 422 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
423 range->avg_qual.level = 20 + -98; 423 range->avg_qual.level = 20 + -98;
424 range->avg_qual.noise = 0; 424 range->avg_qual.noise = 0;
425 range->avg_qual.updated = 7; /* Updated all three */ 425 range->avg_qual.updated = 7; /* Updated all three */
@@ -1047,7 +1047,7 @@ static iw_handler r8192_wx_handlers[] =
1047#else 1047#else
1048 NULL, 1048 NULL,
1049#endif 1049#endif
1050 dummy, /* SIOCGIWAPLIST -- depricated */ 1050 dummy, /* SIOCGIWAPLIST -- deprecated */
1051 r8192_wx_set_scan, /* SIOCSIWSCAN */ 1051 r8192_wx_set_scan, /* SIOCSIWSCAN */
1052 r8192_wx_get_scan, /* SIOCGIWSCAN */ 1052 r8192_wx_get_scan, /* SIOCGIWSCAN */
1053 r8192_wx_set_essid, /* SIOCSIWESSID */ 1053 r8192_wx_set_essid, /* SIOCSIWESSID */
@@ -1211,9 +1211,9 @@ struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
1211 1211
1212struct iw_handler_def r8192_wx_handlers_def={ 1212struct iw_handler_def r8192_wx_handlers_def={
1213 .standard = r8192_wx_handlers, 1213 .standard = r8192_wx_handlers,
1214 .num_standard = sizeof(r8192_wx_handlers) / sizeof(iw_handler), 1214 .num_standard = ARRAY_SIZE(r8192_wx_handlers),
1215 .private = r8192_private_handler, 1215 .private = r8192_private_handler,
1216 .num_private = sizeof(r8192_private_handler) / sizeof(iw_handler), 1216 .num_private = ARRAY_SIZE(r8192_private_handler),
1217 .num_private_args = sizeof(r8192_private_args) / sizeof(struct iw_priv_args), 1217 .num_private_args = sizeof(r8192_private_args) / sizeof(struct iw_priv_args),
1218#if WIRELESS_EXT >= 17 1218#if WIRELESS_EXT >= 17
1219 .get_wireless_stats = r8192_get_wireless_stats, 1219 .get_wireless_stats = r8192_get_wireless_stats,
diff --git a/drivers/staging/rtl8192u/r8192U_wx.h b/drivers/staging/rtl8192u/r8192U_wx.h
index f4cf2801136a..9f6b10505426 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.h
+++ b/drivers/staging/rtl8192u/r8192U_wx.h
@@ -7,7 +7,7 @@
7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon 7 Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon
8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 8 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
9 9
10 We want to tanks the Authors of such projects and the Ndiswrapper project Authors. 10 We want to thank the Authors of such projects and the Ndiswrapper project Authors.
11*/ 11*/
12 12
13/* this file (will) contains wireless extension handlers*/ 13/* this file (will) contains wireless extension handlers*/
diff --git a/drivers/staging/rtl8192u/r819xU_HTType.h b/drivers/staging/rtl8192u/r819xU_HTType.h
index 2ac421626e7c..e07f8b17a0d6 100644
--- a/drivers/staging/rtl8192u/r819xU_HTType.h
+++ b/drivers/staging/rtl8192u/r819xU_HTType.h
@@ -211,7 +211,7 @@ typedef struct _RT_HIGH_THROUGHPUT{
211 u8 bEnableHT; 211 u8 bEnableHT;
212 u8 bCurrentHTSupport; 212 u8 bCurrentHTSupport;
213 213
214 u8 bRegBW40MHz; // Tx 40MHz channel capablity 214 u8 bRegBW40MHz; // Tx 40MHz channel capability
215 u8 bCurBW40MHz; // Tx 40MHz channel capability 215 u8 bCurBW40MHz; // Tx 40MHz channel capability
216 216
217 u8 bRegShortGI40MHz; // Tx Short GI for 40Mhz 217 u8 bRegShortGI40MHz; // Tx Short GI for 40Mhz
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.c b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
index 0cb28c776c49..a8a6dc2c365f 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.c
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
@@ -157,7 +157,7 @@ SendTxCommandPacket(
157 seg_ptr = skb_put(skb, buffer_len); 157 seg_ptr = skb_put(skb, buffer_len);
158 /* 158 /*
159 * Transform from little endian to big endian 159 * Transform from little endian to big endian
160 * and pending zero 160 * and pending zero
161 */ 161 */
162 memcpy(seg_ptr,codevirtualaddress,buffer_len); 162 memcpy(seg_ptr,codevirtualaddress,buffer_len);
163 tcb_desc->txbuf_size= (u16)buffer_len; 163 tcb_desc->txbuf_size= (u16)buffer_len;
@@ -697,7 +697,6 @@ cmpk_message_handle_rx(
697 struct ieee80211_rx_stats *pstats) 697 struct ieee80211_rx_stats *pstats)
698{ 698{
699// u32 debug_level = DBG_LOUD; 699// u32 debug_level = DBG_LOUD;
700 struct r8192_priv *priv = ieee80211_priv(dev);
701 int total_length; 700 int total_length;
702 u8 cmd_length, exe_cnt = 0; 701 u8 cmd_length, exe_cnt = 0;
703 u8 element_id; 702 u8 element_id;
@@ -719,15 +718,15 @@ cmpk_message_handle_rx(
719 /* 2. Read virtual address from RFD. */ 718 /* 2. Read virtual address from RFD. */
720 pcmd_buff = pstats->virtual_address; 719 pcmd_buff = pstats->virtual_address;
721 720
722 /* 3. Read command pakcet element id and length. */ 721 /* 3. Read command packet element id and length. */
723 element_id = pcmd_buff[0]; 722 element_id = pcmd_buff[0];
724 /*RT_TRACE(COMP_SEND, DebugLevel, 723 /*RT_TRACE(COMP_SEND, DebugLevel,
725 ("\n\r[CMPK]-->element ID=%d Len=%d", element_id, total_length));*/ 724 ("\n\r[CMPK]-->element ID=%d Len=%d", element_id, total_length));*/
726 725
727 /* 4. Check every received command packet conent according to different 726 /* 4. Check every received command packet content according to different
728 element type. Because FW may aggregate RX command packet to minimize 727 element type. Because FW may aggregate RX command packet to minimize
729 transmit time between DRV and FW.*/ 728 transmit time between DRV and FW.*/
730 // Add a counter to prevent to locked in the loop too long 729 // Add a counter to prevent the lock in the loop from being held too long
731 while (total_length > 0 || exe_cnt++ >100) 730 while (total_length > 0 || exe_cnt++ >100)
732 { 731 {
733 /* 2007/01/17 MH We support aggregation of different cmd in the same packet. */ 732 /* 2007/01/17 MH We support aggregation of different cmd in the same packet. */
@@ -779,9 +778,6 @@ cmpk_message_handle_rx(
779 // 2007/01/22 MH Add to display tx statistic. 778 // 2007/01/22 MH Add to display tx statistic.
780 //cmpk_DisplayTxStatistic(pAdapter); 779 //cmpk_DisplayTxStatistic(pAdapter);
781 780
782 /* 2007/03/09 MH Collect sidderent cmd element pkt num. */
783 priv->stats.rxcmdpkt[element_id]++;
784
785 total_length -= cmd_length; 781 total_length -= cmd_length;
786 pcmd_buff += cmd_length; 782 pcmd_buff += cmd_length;
787 } /* while (total_length > 0) */ 783 } /* while (total_length > 0) */
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index 4bb5fffca5b9..b12d19079798 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -275,11 +275,11 @@ bool init_firmware(struct net_device *dev)
275 275
276 /* 276 /*
277 * Download boot, main, and data image for System reset. 277 * Download boot, main, and data image for System reset.
278 * Download data image for firmware reseta 278 * Download data image for firmware reset
279 */ 279 */
280 for(init_step = starting_state; init_step <= FW_INIT_STEP2_DATA; init_step++) { 280 for(init_step = starting_state; init_step <= FW_INIT_STEP2_DATA; init_step++) {
281 /* 281 /*
282 * Open Image file, and map file to contineous memory if open file success. 282 * Open image file, and map file to continuous memory if open file success.
283 * or read image file from array. Default load from IMG file 283 * or read image file from array. Default load from IMG file
284 */ 284 */
285 if(rst_opt == OPT_SYSTEM_RESET) { 285 if(rst_opt == OPT_SYSTEM_RESET) {
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index c4586b0817d1..dd1954daea2d 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -40,7 +40,7 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
40 * and do register read/write 40 * and do register read/write
41 * input: u32 dwBitMask //taget bit pos in the addr to be modified 41 * input: u32 dwBitMask //taget bit pos in the addr to be modified
42 * output: none 42 * output: none
43 * return: u32 return the shift bit bit position of the mask 43 * return: u32 return the shift bit position of the mask
44 * ****************************************************************************/ 44 * ****************************************************************************/
45u32 rtl8192_CalculateBitShift(u32 dwBitMask) 45u32 rtl8192_CalculateBitShift(u32 dwBitMask)
46{ 46{
@@ -176,7 +176,7 @@ u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath,
176 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1); 176 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
177 177
178 178
179 // TODO: we should not delay such a long time. Ask help from SD3 179 // TODO: we should not delay such a long time. Ask for help from SD3
180 msleep(1); 180 msleep(1);
181 181
182 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData); 182 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
@@ -252,7 +252,7 @@ void rtl8192_phy_RFSerialWrite(struct net_device* dev, RF90_RADIO_PATH_E eRFPath
252 NewOffset = Offset; 252 NewOffset = Offset;
253 } 253 }
254 254
255 // Put write addr in [5:0] and write data in [31:16] 255 // Put write addr in [5:0] and write data in [31:16]
256 DataAndAddr = (Data<<16) | (NewOffset&0x3f); 256 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
257 257
258 // Write Operation 258 // Write Operation
@@ -525,7 +525,7 @@ void rtl8192_phy_configmac(struct net_device* dev)
525} 525}
526 526
527/****************************************************************************** 527/******************************************************************************
528 *function: This function do dirty work 528 *function: This function does dirty work
529 * input: dev 529 * input: dev
530 * output: none 530 * output: none
531 * return: none 531 * return: none
@@ -578,7 +578,7 @@ void rtl8192_phyConfigBB(struct net_device* dev, u8 ConfigType)
578void rtl8192_InitBBRFRegDef(struct net_device* dev) 578void rtl8192_InitBBRFRegDef(struct net_device* dev)
579{ 579{
580 struct r8192_priv *priv = ieee80211_priv(dev); 580 struct r8192_priv *priv = ieee80211_priv(dev);
581// RF Interface Sowrtware Control 581// RF Interface Software Control
582 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870 582 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
583 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) 583 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
584 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874 584 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
@@ -602,7 +602,7 @@ void rtl8192_InitBBRFRegDef(struct net_device* dev)
602 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A) 602 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
603 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E) 603 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
604 604
605 //Addr of LSSI. Wirte RF register by driver 605 //Addr of LSSI. Write RF register by driver
606 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter 606 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
607 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter; 607 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
608 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter; 608 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
@@ -1384,7 +1384,7 @@ u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u
1384} 1384}
1385 1385
1386/****************************************************************************** 1386/******************************************************************************
1387 *function: This function does acturally set channel work 1387 *function: This function does actually set channel work
1388 * input: struct net_device *dev 1388 * input: struct net_device *dev
1389 * u8 channel 1389 * u8 channel
1390 * output: none 1390 * output: none
@@ -1425,7 +1425,7 @@ void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1425} 1425}
1426 1426
1427/****************************************************************************** 1427/******************************************************************************
1428 *function: This function scheduled actural workitem to set channel 1428 *function: This function scheduled actual work item to set channel
1429 * input: net_device dev 1429 * input: net_device dev
1430 * u8 channel //channel to set 1430 * u8 channel //channel to set
1431 * output: none 1431 * output: none
diff --git a/drivers/staging/rtl8192u/r819xU_phyreg.h b/drivers/staging/rtl8192u/r819xU_phyreg.h
index 06b0b539e1bc..50f24dce8b16 100644
--- a/drivers/staging/rtl8192u/r819xU_phyreg.h
+++ b/drivers/staging/rtl8192u/r819xU_phyreg.h
@@ -443,7 +443,7 @@
443#define bCCKRxIG 0x7f00 443#define bCCKRxIG 0x7f00
444#define bCCKLNAPolarity 0x800000 444#define bCCKLNAPolarity 0x800000
445#define bCCKRx1stGain 0x7f0000 445#define bCCKRx1stGain 0x7f0000
446#define bCCKRFExtend 0x20000000 //CCK Rx Iinital gain polarity 446#define bCCKRFExtend 0x20000000 //CCK Rx inital gain polarity
447#define bCCKRxAGCSatLevel 0x1f000000 447#define bCCKRxAGCSatLevel 0x1f000000
448#define bCCKRxAGCSatCount 0xe0 448#define bCCKRxAGCSatCount 0xe0
449#define bCCKRxRFSettle 0x1f //AGCsamp_dly 449#define bCCKRxRFSettle 0x1f //AGCsamp_dly
diff --git a/drivers/staging/rtl8712/big_endian.h b/drivers/staging/rtl8712/big_endian.h
deleted file mode 100644
index b16f8ecf99c6..000000000000
--- a/drivers/staging/rtl8712/big_endian.h
+++ /dev/null
@@ -1,94 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
24 *
25 ******************************************************************************/
26#ifndef _LINUX_BYTEORDER_BIG_ENDIAN_H
27#define _LINUX_BYTEORDER_BIG_ENDIAN_H
28
29#ifndef __BIG_ENDIAN
30#define __BIG_ENDIAN 4321
31#endif
32#ifndef __BIG_ENDIAN_BITFIELD
33#define __BIG_ENDIAN_BITFIELD
34#endif
35
36#include "swab.h"
37
38#define __constant_htonl(x) ((__u32)(x))
39#define __constant_ntohl(x) ((__u32)(x))
40#define __constant_htons(x) ((__u16)(x))
41#define __constant_ntohs(x) ((__u16)(x))
42#define __constant_cpu_to_le64(x) ___constant_swab64((x))
43#define __constant_le64_to_cpu(x) ___constant_swab64((x))
44#define __constant_cpu_to_le32(x) ___constant_swab32((x))
45#define __constant_le32_to_cpu(x) ___constant_swab32((x))
46#define __constant_cpu_to_le16(x) ___constant_swab16((x))
47#define __constant_le16_to_cpu(x) ___constant_swab16((x))
48#define __constant_cpu_to_be64(x) ((__u64)(x))
49#define __constant_be64_to_cpu(x) ((__u64)(x))
50#define __constant_cpu_to_be32(x) ((__u32)(x))
51#define __constant_be32_to_cpu(x) ((__u32)(x))
52#define __constant_cpu_to_be16(x) ((__u16)(x))
53#define __constant_be16_to_cpu(x) ((__u16)(x))
54#define __cpu_to_le64(x) __swab64((x))
55#define __le64_to_cpu(x) __swab64((x))
56#define __cpu_to_le32(x) __swab32((x))
57#define __le32_to_cpu(x) __swab32((x))
58#define __cpu_to_le16(x) __swab16((x))
59#define __le16_to_cpu(x) __swab16((x))
60#define __cpu_to_be64(x) ((__u64)(x))
61#define __be64_to_cpu(x) ((__u64)(x))
62#define __cpu_to_be32(x) ((__u32)(x))
63#define __be32_to_cpu(x) ((__u32)(x))
64#define __cpu_to_be16(x) ((__u16)(x))
65#define __be16_to_cpu(x) ((__u16)(x))
66#define __cpu_to_le64p(x) __swab64p((x))
67#define __le64_to_cpup(x) __swab64p((x))
68#define __cpu_to_le32p(x) __swab32p((x))
69#define __le32_to_cpup(x) __swab32p((x))
70#define __cpu_to_le16p(x) __swab16p((x))
71#define __le16_to_cpup(x) __swab16p((x))
72#define __cpu_to_be64p(x) (*(__u64 *)(x))
73#define __be64_to_cpup(x) (*(__u64 *)(x))
74#define __cpu_to_be32p(x) (*(__u32 *)(x))
75#define __be32_to_cpup(x) (*(__u32 *)(x))
76#define __cpu_to_be16p(x) (*(__u16 *)(x))
77#define __be16_to_cpup(x) (*(__u16 *)(x))
78#define __cpu_to_le64s(x) __swab64s((x))
79#define __le64_to_cpus(x) __swab64s((x))
80#define __cpu_to_le32s(x) __swab32s((x))
81#define __le32_to_cpus(x) __swab32s((x))
82#define __cpu_to_le16s(x) __swab16s((x))
83#define __le16_to_cpus(x) __swab16s((x))
84#define __cpu_to_be64s(x) do {} while (0)
85#define __be64_to_cpus(x) do {} while (0)
86#define __cpu_to_be32s(x) do {} while (0)
87#define __be32_to_cpus(x) do {} while (0)
88#define __cpu_to_be16s(x) do {} while (0)
89#define __be16_to_cpus(x) do {} while (0)
90
91#include "generic.h"
92
93#endif /* _LINUX_BYTEORDER_BIG_ENDIAN_H */
94
diff --git a/drivers/staging/rtl8712/drv_types.h b/drivers/staging/rtl8712/drv_types.h
index e83665d06020..62b55663c63a 100644
--- a/drivers/staging/rtl8712/drv_types.h
+++ b/drivers/staging/rtl8712/drv_types.h
@@ -146,7 +146,7 @@ struct dvobj_priv {
146/** 146/**
147 * struct _adapter - the main adapter structure for this device. 147 * struct _adapter - the main adapter structure for this device.
148 * 148 *
149 * bup: True indicates that the interface is Up. 149 * bup: True indicates that the interface is up.
150 */ 150 */
151struct _adapter { 151struct _adapter {
152 struct dvobj_priv dvobjpriv; 152 struct dvobj_priv dvobjpriv;
diff --git a/drivers/staging/rtl8712/generic.h b/drivers/staging/rtl8712/generic.h
deleted file mode 100644
index 8868c9f4adf8..000000000000
--- a/drivers/staging/rtl8712/generic.h
+++ /dev/null
@@ -1,178 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
24 *
25 ******************************************************************************/
26#ifndef _LINUX_BYTEORDER_GENERIC_H
27#define _LINUX_BYTEORDER_GENERIC_H
28
29/*
30 * linux/byteorder_generic.h
31 * Generic Byte-reordering support
32 *
33 * Francois-Rene Rideau <fare@tunes.org> 19970707
34 * gathered all the good ideas from all asm-foo/byteorder.h into one file,
35 * cleaned them up.
36 * I hope it is compliant with non-GCC compilers.
37 * I decided to put __BYTEORDER_HAS_U64__ in byteorder.h,
38 * because I wasn't sure it would be ok to put it in types.h
39 * Upgraded it to 2.1.43
40 * Francois-Rene Rideau <fare@tunes.org> 19971012
41 * Upgraded it to 2.1.57
42 * to please Linus T., replaced huge #ifdef's between little/big endian
43 * by nestedly #include'd files.
44 * Francois-Rene Rideau <fare@tunes.org> 19971205
45 * Made it to 2.1.71; now a facelift:
46 * Put files under include/linux/byteorder/
47 * Split swab from generic support.
48 *
49 * TODO:
50 * = Regular kernel maintainers could also replace all these manual
51 * byteswap macros that remain, disseminated among drivers,
52 * after some grep or the sources...
53 * = Linus might want to rename all these macros and files to fit his taste,
54 * to fit his personal naming scheme.
55 * = it seems that a few drivers would also appreciate
56 * nybble swapping support...
57 * = every architecture could add their byteswap macro in asm/byteorder.h
58 * see how some architectures already do (i386, alpha, ppc, etc)
59 * = cpu_to_beXX and beXX_to_cpu might some day need to be well
60 * distinguished throughout the kernel. This is not the case currently,
61 * since little endian, big endian, and pdp endian machines needn't it.
62 * But this might be the case for, say, a port of Linux to 20/21 bit
63 * architectures (and F21 Linux addict around?).
64 */
65
66/*
67 * The following macros are to be defined by <asm/byteorder.h>:
68 *
69 * Conversion of long and short int between network and host format
70 * ntohl(__u32 x)
71 * ntohs(__u16 x)
72 * htonl(__u32 x)
73 * htons(__u16 x)
74 * It seems that some programs (which? where? or perhaps a standard? POSIX?)
75 * might like the above to be functions, not macros (why?).
76 * if that's true, then detect them, and take measures.
77 * Anyway, the measure is: define only ___ntohl as a macro instead,
78 * and in a separate file, have
79 * unsigned long inline ntohl(x){return ___ntohl(x);}
80 *
81 * The same for constant arguments
82 * __constant_ntohl(__u32 x)
83 * __constant_ntohs(__u16 x)
84 * __constant_htonl(__u32 x)
85 * __constant_htons(__u16 x)
86 *
87 * Conversion of XX-bit integers (16- 32- or 64-)
88 * between native CPU format and little/big endian format
89 * 64-bit stuff only defined for proper architectures
90 * cpu_to_[bl]eXX(__uXX x)
91 * [bl]eXX_to_cpu(__uXX x)
92 *
93 * The same, but takes a pointer to the value to convert
94 * cpu_to_[bl]eXXp(__uXX x)
95 * [bl]eXX_to_cpup(__uXX x)
96 *
97 * The same, but change in situ
98 * cpu_to_[bl]eXXs(__uXX x)
99 * [bl]eXX_to_cpus(__uXX x)
100 *
101 * See asm-foo/byteorder.h for examples of how to provide
102 * architecture-optimized versions
103 *
104 */
105
106
107/*
108 * inside the kernel, we can use nicknames;
109 * outside of it, we must avoid POSIX namespace pollution...
110 */
111#define cpu_to_le64 __cpu_to_le64
112#define le64_to_cpu __le64_to_cpu
113#define cpu_to_le32 __cpu_to_le32
114#define le32_to_cpu __le32_to_cpu
115#define cpu_to_le16 __cpu_to_le16
116#define le16_to_cpu __le16_to_cpu
117#define cpu_to_be64 __cpu_to_be64
118#define be64_to_cpu __be64_to_cpu
119#define cpu_to_be32 __cpu_to_be32
120#define be32_to_cpu __be32_to_cpu
121#define cpu_to_be16 __cpu_to_be16
122#define be16_to_cpu __be16_to_cpu
123#define cpu_to_le64p __cpu_to_le64p
124#define le64_to_cpup __le64_to_cpup
125#define cpu_to_le32p __cpu_to_le32p
126#define le32_to_cpup __le32_to_cpup
127#define cpu_to_le16p __cpu_to_le16p
128#define le16_to_cpup __le16_to_cpup
129#define cpu_to_be64p __cpu_to_be64p
130#define be64_to_cpup __be64_to_cpup
131#define cpu_to_be32p __cpu_to_be32p
132#define be32_to_cpup __be32_to_cpup
133#define cpu_to_be16p __cpu_to_be16p
134#define be16_to_cpup __be16_to_cpup
135#define cpu_to_le64s __cpu_to_le64s
136#define le64_to_cpus __le64_to_cpus
137#define cpu_to_le32s __cpu_to_le32s
138#define le32_to_cpus __le32_to_cpus
139#define cpu_to_le16s __cpu_to_le16s
140#define le16_to_cpus __le16_to_cpus
141#define cpu_to_be64s __cpu_to_be64s
142#define be64_to_cpus __be64_to_cpus
143#define cpu_to_be32s __cpu_to_be32s
144#define be32_to_cpus __be32_to_cpus
145#define cpu_to_be16s __cpu_to_be16s
146#define be16_to_cpus __be16_to_cpus
147
148
149/*
150 * Handle ntohl and suches. These have various compatibility
151 * issues - like we want to give the prototype even though we
152 * also have a macro for them in case some strange program
153 * wants to take the address of the thing or something..
154 *
155 * Note that these used to return a "long" in libc5, even though
156 * long is often 64-bit these days.. Thus the casts.
157 *
158 * They have to be macros in order to do the constant folding
159 * correctly - if the argument passed into a inline function
160 * it is no longer constant according to gcc..
161 */
162
163#undef ntohl
164#undef ntohs
165#undef htonl
166#undef htons
167
168/*
169 * Do the prototypes. Somebody might want to take the
170 * address or some such sick thing..
171 */
172extern __u32 ntohl(__u32);
173extern __u32 htonl(__u32);
174extern unsigned short int ntohs(unsigned short int);
175extern unsigned short int htons(unsigned short int);
176
177#endif /* _LINUX_BYTEORDER_GENERIC_H */
178
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index cc893c0f5ad3..cb9d4cfe8fe4 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -36,7 +36,6 @@
36 36
37#include "osdep_service.h" 37#include "osdep_service.h"
38#include "drv_types.h" 38#include "drv_types.h"
39#include "rtl871x_byteorder.h"
40#include "usb_osintf.h" 39#include "usb_osintf.h"
41 40
42#define FWBUFF_ALIGN_SZ 512 41#define FWBUFF_ALIGN_SZ 512
diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h
index 3c0092b7de09..21515c31b373 100644
--- a/drivers/staging/rtl8712/ieee80211.h
+++ b/drivers/staging/rtl8712/ieee80211.h
@@ -705,7 +705,7 @@ enum ieee80211_state {
705 IEEE80211_ASSOCIATING_RETRY, 705 IEEE80211_ASSOCIATING_RETRY,
706 /* the association procedure is sending AUTH request*/ 706 /* the association procedure is sending AUTH request*/
707 IEEE80211_ASSOCIATING_AUTHENTICATING, 707 IEEE80211_ASSOCIATING_AUTHENTICATING,
708 /* the association procedure has successfully authentcated 708 /* the association procedure has successfully authenticated
709 * and is sending association request 709 * and is sending association request
710 */ 710 */
711 IEEE80211_ASSOCIATING_AUTHENTICATED, 711 IEEE80211_ASSOCIATING_AUTHENTICATED,
diff --git a/drivers/staging/rtl8712/if_ether.h b/drivers/staging/rtl8712/if_ether.h
deleted file mode 100644
index 2bbe527bcd5c..000000000000
--- a/drivers/staging/rtl8712/if_ether.h
+++ /dev/null
@@ -1,141 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
24 *
25 ******************************************************************************/
26/*
27 * INET An implementation of the TCP/IP protocol suite for the LINUX
28 * operating system. INET is implemented using the BSD Socket
29 * interface as the means of communication with the user level.
30 *
31 * Global definitions for the Ethernet IEEE 802.3 interface.
32 *
33 * Version: @(#)if_ether.h 1.0.1a 02/08/94
34 *
35 * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
36 * Donald Becker, <becker@super.org>
37 * Alan Cox, <alan@redhat.com>
38 * Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk>
39 *
40 * This program is free software; you can redistribute it and/or
41 * modify it under the terms of the GNU General Public License
42 * as published by the Free Software Foundation; either version
43 * 2 of the License, or (at your option) any later version.
44 */
45
46#ifndef _LINUX_IF_ETHER_H
47#define _LINUX_IF_ETHER_H
48
49/*
50 * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
51 * and FCS/CRC (frame check sequence).
52 */
53
54#define ETH_ALEN 6 /* Octets in one ethernet addr */
55#define ETH_HLEN 14 /* Total octets in header. */
56#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
57#define ETH_DATA_LEN 1500 /* Max. octets in payload */
58#define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
59
60/*
61 * These are the defined Ethernet Protocol ID's.
62 */
63
64#define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */
65#define ETH_P_PUP 0x0200 /* Xerox PUP packet */
66#define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */
67#define ETH_P_IP 0x0800 /* Internet Protocol packet */
68#define ETH_P_X25 0x0805 /* CCITT X.25 */
69#define ETH_P_ARP 0x0806 /* Address Resolution packet */
70#define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet
71 * [ NOT AN OFFICIAL ID ] */
72#define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */
73#define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr
74 * Trans packet */
75#define ETH_P_DEC 0x6000 /* DEC Assigned proto */
76#define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */
77#define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */
78#define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */
79#define ETH_P_LAT 0x6004 /* DEC LAT */
80#define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
81#define ETH_P_CUST 0x6006 /* DEC Customer use */
82#define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
83#define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
84#define ETH_P_ATALK 0x809B /* Appletalk DDP */
85#define ETH_P_AARP 0x80F3 /* Appletalk AARP */
86#define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
87#define ETH_P_IPX 0x8137 /* IPX over DIX */
88#define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
89#define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
90#define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
91#define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */
92#define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport
93 * over Ethernet
94 */
95
96/*
97 * Non DIX types. Won't clash for 1500 types.
98 */
99
100#define ETH_P_802_3 0x0001 /* Dummy type for 802.3 frames */
101#define ETH_P_AX25 0x0002 /* Dummy protocol id for AX.25 */
102#define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */
103#define ETH_P_802_2 0x0004 /* 802.2 frames */
104#define ETH_P_SNAP 0x0005 /* Internal only */
105#define ETH_P_DDCMP 0x0006 /* DEC DDCMP: Internal only */
106#define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/
107#define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */
108#define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */
109#define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/
110#define ETH_P_TR_802_2 0x0011i /* 802.2 frames */
111#define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */
112#define ETH_P_CONTROL 0x0016 /* Card specific control frames */
113#define ETH_P_IRDA 0x0017 /* Linux-IrDA */
114#define ETH_P_ECONET 0x0018 /* Acorn Econet */
115
116/*
117 * This is an Ethernet frame header.
118 */
119
120struct ethhdr {
121 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
122 unsigned char h_source[ETH_ALEN]; /* source ether addr */
123 unsigned short h_proto; /* packet type ID field */
124};
125
126struct _vlan {
127 unsigned short h_vlan_TCI; /* Encapsulates priority and VLAN ID*/
128 unsigned short h_vlan_encapsulated_proto;
129};
130
131
132
133#define get_vlan_id(pvlan) ((ntohs((unsigned short)pvlan->h_vlan_TCI)) & 0xfff)
134#define get_vlan_priority(pvlan) ((ntohs((unsigned short)\
135 pvlan->h_vlan_TCI)) >> 13)
136#define get_vlan_encap_proto(pvlan) (ntohs((unsigned short)\
137 pvlan->h_vlan_encapsulated_proto))
138
139
140#endif /* _LINUX_IF_ETHER_H */
141
diff --git a/drivers/staging/rtl8712/ip.h b/drivers/staging/rtl8712/ip.h
deleted file mode 100644
index f37b0f8d14d4..000000000000
--- a/drivers/staging/rtl8712/ip.h
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the IP protocol.
7 *
8 * Version: @(#)ip.h 1.0.2 04/28/93
9 *
10 * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 */
17#ifndef _LINUX_IP_H
18#define _LINUX_IP_H
19
20#include "rtl871x_byteorder.h"
21
22/* SOL_IP socket options */
23
24#define IPTOS_TOS_MASK 0x1E
25#define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)
26#define IPTOS_LOWDELAY 0x10
27#define IPTOS_THROUGHPUT 0x08
28#define IPTOS_RELIABILITY 0x04
29#define IPTOS_MINCOST 0x02
30
31#define IPTOS_PREC_MASK 0xE0
32#define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)
33#define IPTOS_PREC_NETCONTROL 0xe0
34#define IPTOS_PREC_INTERNETCONTROL 0xc0
35#define IPTOS_PREC_CRITIC_ECP 0xa0
36#define IPTOS_PREC_FLASHOVERRIDE 0x80
37#define IPTOS_PREC_FLASH 0x60
38#define IPTOS_PREC_IMMEDIATE 0x40
39#define IPTOS_PREC_PRIORITY 0x20
40#define IPTOS_PREC_ROUTINE 0x00
41
42/* IP options */
43#define IPOPT_COPY 0x80
44#define IPOPT_CLASS_MASK 0x60
45#define IPOPT_NUMBER_MASK 0x1f
46
47#define IPOPT_COPIED(o) ((o)&IPOPT_COPY)
48#define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK)
49#define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK)
50
51#define IPOPT_CONTROL 0x00
52#define IPOPT_RESERVED1 0x20
53#define IPOPT_MEASUREMENT 0x40
54#define IPOPT_RESERVED2 0x60
55
56#define IPOPT_END (0 | IPOPT_CONTROL)
57#define IPOPT_NOOP (1 | IPOPT_CONTROL)
58#define IPOPT_SEC (2 | IPOPT_CONTROL|IPOPT_COPY)
59#define IPOPT_LSRR (3 | IPOPT_CONTROL|IPOPT_COPY)
60#define IPOPT_TIMESTAMP (4 | IPOPT_MEASUREMENT)
61#define IPOPT_RR (7 | IPOPT_CONTROL)
62#define IPOPT_SID (8 | IPOPT_CONTROL | IPOPT_COPY)
63#define IPOPT_SSRR (9 | IPOPT_CONTROL | IPOPT_COPY)
64#define IPOPT_RA (20 | IPOPT_CONTROL | IPOPT_COPY)
65
66#define IPVERSION 4
67#define MAXTTL 255
68#define IPDEFTTL 64
69
70/* struct timestamp, struct route and MAX_ROUTES are removed.
71 *
72 * REASONS: it is clear that nobody used them because:
73 * - MAX_ROUTES value was wrong.
74 * - "struct route" was wrong.
75 * - "struct timestamp" had fatally misaligned bitfields and was completely
76 * unusable.
77 */
78
79#define IPOPT_OPTVAL 0
80#define IPOPT_OLEN 1
81#define IPOPT_OFFSET 2
82#define IPOPT_MINOFF 4
83#define MAX_IPOPTLEN 40
84#define IPOPT_NOP IPOPT_NOOP
85#define IPOPT_EOL IPOPT_END
86#define IPOPT_TS IPOPT_TIMESTAMP
87
88#define IPOPT_TS_TSONLY 0 /* timestamps only */
89#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
90#define IPOPT_TS_PRESPEC 3 /* specified modules only */
91
92struct ip_options {
93 __u32 faddr; /* Saved first hop address */
94 unsigned char optlen;
95 unsigned char srr;
96 unsigned char rr;
97 unsigned char ts;
98 unsigned char is_setbyuser:1, /* Set by setsockopt? */
99 is_data:1, /* Options in __data, rather than skb */
100 is_strictroute:1, /* Strict source route */
101 srr_is_hit:1, /* Packet destination addr was our one*/
102 is_changed:1, /* IP checksum more not valid */
103 rr_needaddr:1, /* Need to record addr of outgoing dev*/
104 ts_needtime:1, /* Need to record timestamp */
105 ts_needaddr:1; /* Need to record addr of outgoing dev*/
106 unsigned char router_alert;
107 unsigned char __pad1;
108 unsigned char __pad2;
109 unsigned char __data[0];
110};
111
112#define optlength(opt) (sizeof(struct ip_options) + opt->optlen)
113
114struct iphdr {
115#if defined(__LITTLE_ENDIAN_BITFIELD)
116 __u8 ihl:4,
117 version:4;
118#elif defined(__BIG_ENDIAN_BITFIELD)
119 __u8 version:4,
120 ihl:4;
121#else
122#error "Please fix <asm/byteorder.h>"
123#endif
124 __u8 tos;
125 __u16 tot_len;
126 __u16 id;
127 __u16 frag_off;
128 __u8 ttl;
129 __u8 protocol;
130 __u16 check;
131 __u32 saddr;
132 __u32 daddr;
133 /*The options start here. */
134};
135
136#endif /* _LINUX_IP_H */
137
diff --git a/drivers/staging/rtl8712/little_endian.h b/drivers/staging/rtl8712/little_endian.h
deleted file mode 100644
index cd57d6c2850f..000000000000
--- a/drivers/staging/rtl8712/little_endian.h
+++ /dev/null
@@ -1,94 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
24 *
25 ******************************************************************************/
26#ifndef _LINUX_BYTEORDER_LITTLE_ENDIAN_H
27#define _LINUX_BYTEORDER_LITTLE_ENDIAN_H
28
29#ifndef __LITTLE_ENDIAN
30#define __LITTLE_ENDIAN 1234
31#endif
32#ifndef __LITTLE_ENDIAN_BITFIELD
33#define __LITTLE_ENDIAN_BITFIELD
34#endif
35
36#include "swab.h"
37
38#define __constant_htonl(x) ___constant_swab32((x))
39#define __constant_ntohl(x) ___constant_swab32((x))
40#define __constant_htons(x) ___constant_swab16((x))
41#define __constant_ntohs(x) ___constant_swab16((x))
42#define __constant_cpu_to_le64(x) ((__u64)(x))
43#define __constant_le64_to_cpu(x) ((__u64)(x))
44#define __constant_cpu_to_le32(x) ((__u32)(x))
45#define __constant_le32_to_cpu(x) ((__u32)(x))
46#define __constant_cpu_to_le16(x) ((__u16)(x))
47#define __constant_le16_to_cpu(x) ((__u16)(x))
48#define __constant_cpu_to_be64(x) ___constant_swab64((x))
49#define __constant_be64_to_cpu(x) ___constant_swab64((x))
50#define __constant_cpu_to_be32(x) ___constant_swab32((x))
51#define __constant_be32_to_cpu(x) ___constant_swab32((x))
52#define __constant_cpu_to_be16(x) ___constant_swab16((x))
53#define __constant_be16_to_cpu(x) ___constant_swab16((x))
54#define __cpu_to_le64(x) ((__u64)(x))
55#define __le64_to_cpu(x) ((__u64)(x))
56#define __cpu_to_le32(x) ((__u32)(x))
57#define __le32_to_cpu(x) ((__u32)(x))
58#define __cpu_to_le16(x) ((__u16)(x))
59#define __le16_to_cpu(x) ((__u16)(x))
60#define __cpu_to_be64(x) __swab64((x))
61#define __be64_to_cpu(x) __swab64((x))
62#define __cpu_to_be32(x) __swab32((x))
63#define __be32_to_cpu(x) __swab32((x))
64#define __cpu_to_be16(x) __swab16((x))
65#define __be16_to_cpu(x) __swab16((x))
66#define __cpu_to_le64p(x) (*(__u64 *)(x))
67#define __le64_to_cpup(x) (*(__u64 *)(x))
68#define __cpu_to_le32p(x) (*(__u32 *)(x))
69#define __le32_to_cpup(x) (*(__u32 *)(x))
70#define __cpu_to_le16p(x) (*(__u16 *)(x))
71#define __le16_to_cpup(x) (*(__u16 *)(x))
72#define __cpu_to_be64p(x) __swab64p((x))
73#define __be64_to_cpup(x) __swab64p((x))
74#define __cpu_to_be32p(x) __swab32p((x))
75#define __be32_to_cpup(x) __swab32p((x))
76#define __cpu_to_be16p(x) __swab16p((x))
77#define __be16_to_cpup(x) __swab16p((x))
78#define __cpu_to_le64s(x) do {} while (0)
79#define __le64_to_cpus(x) do {} while (0)
80#define __cpu_to_le32s(x) do {} while (0)
81#define __le32_to_cpus(x) do {} while (0)
82#define __cpu_to_le16s(x) do {} while (0)
83#define __le16_to_cpus(x) do {} while (0)
84#define __cpu_to_be64s(x) __swab64s((x))
85#define __be64_to_cpus(x) __swab64s((x))
86#define __cpu_to_be32s(x) __swab32s((x))
87#define __be32_to_cpus(x) __swab32s((x))
88#define __cpu_to_be16s(x) __swab16s((x))
89#define __be16_to_cpus(x) __swab16s((x))
90
91#include "generic.h"
92
93#endif /* _LINUX_BYTEORDER_LITTLE_ENDIAN_H */
94
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index 7bbd53a410e3..448f00dd68fe 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -52,7 +52,7 @@ static int lbkmode = RTL8712_AIR_TRX;
52static int hci = RTL8712_USB; 52static int hci = RTL8712_USB;
53static int ampdu_enable = 1;/*for enable tx_ampdu*/ 53static int ampdu_enable = 1;/*for enable tx_ampdu*/
54 54
55/* The video_mode variable is for vedio mode.*/ 55/* The video_mode variable is for video mode.*/
56/* It may be specify when inserting module with video_mode=1 parameter.*/ 56/* It may be specify when inserting module with video_mode=1 parameter.*/
57static int video_mode = 1; /* enable video mode*/ 57static int video_mode = 1; /* enable video mode*/
58 58
@@ -248,7 +248,7 @@ static u32 start_drv_threads(struct _adapter *padapter)
248 248
249void r8712_stop_drv_threads(struct _adapter *padapter) 249void r8712_stop_drv_threads(struct _adapter *padapter)
250{ 250{
251 /*Below is to termindate r8712_cmd_thread & event_thread...*/ 251 /*Below is to terminate r8712_cmd_thread & event_thread...*/
252 up(&padapter->cmdpriv.cmd_queue_sema); 252 up(&padapter->cmdpriv.cmd_queue_sema);
253 if (padapter->cmdThread) 253 if (padapter->cmdThread)
254 _down_sema(&padapter->cmdpriv.terminate_cmdthread_sema); 254 _down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index 9ba603310fdc..f1ccc7ebbda7 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -29,7 +29,6 @@
29#define _SUCCESS 1 29#define _SUCCESS 1
30#define _FAIL 0 30#define _FAIL 0
31 31
32#include <linux/version.h>
33#include <linux/spinlock.h> 32#include <linux/spinlock.h>
34 33
35#include <linux/interrupt.h> 34#include <linux/interrupt.h>
@@ -107,8 +106,6 @@ static inline void _set_workitem(_workitem *pwork)
107 schedule_work(pwork); 106 schedule_work(pwork);
108} 107}
109 108
110#include "rtl871x_byteorder.h"
111
112#ifndef BIT 109#ifndef BIT
113 #define BIT(x) (1 << (x)) 110 #define BIT(x) (1 << (x))
114#endif 111#endif
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 9f6ebc419b0b..088647cdca99 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -50,7 +50,6 @@
50#include "drv_types.h" 50#include "drv_types.h"
51#include "recv_osdep.h" 51#include "recv_osdep.h"
52#include "mlme_osdep.h" 52#include "mlme_osdep.h"
53#include "rtl871x_byteorder.h"
54#include "rtl871x_ioctl_set.h" 53#include "rtl871x_ioctl_set.h"
55 54
56static void check_hw_pbc(struct _adapter *padapter) 55static void check_hw_pbc(struct _adapter *padapter)
@@ -69,7 +68,7 @@ static void check_hw_pbc(struct _adapter *padapter)
69 * After trigger PBC, the variable will be set to false */ 68 * After trigger PBC, the variable will be set to false */
70 DBG_8712("CheckPbcGPIO - PBC is pressed !!!!\n"); 69 DBG_8712("CheckPbcGPIO - PBC is pressed !!!!\n");
71 /* 0 is the default value and it means the application monitors 70 /* 0 is the default value and it means the application monitors
72 * the HW PBC doesn't privde its pid to driver. */ 71 * the HW PBC doesn't provide its pid to driver. */
73 if (padapter->pid == 0) 72 if (padapter->pid == 0)
74 return; 73 return;
75 kill_pid(find_vpid(padapter->pid), SIGUSR1, 1); 74 kill_pid(find_vpid(padapter->pid), SIGUSR1, 1);
@@ -382,7 +381,7 @@ _next:
382 *pcmdbuf = cpu_to_le32((cmdsz & 0x0000ffff) | 381 *pcmdbuf = cpu_to_le32((cmdsz & 0x0000ffff) |
383 (pcmd->cmdcode << 16) | 382 (pcmd->cmdcode << 16) |
384 (pcmdpriv->cmd_seq << 24)); 383 (pcmdpriv->cmd_seq << 24));
385 pcmdbuf += 2 ; /* 8 bytes aligment */ 384 pcmdbuf += 2 ; /* 8 bytes alignment */
386 memcpy((u8 *)pcmdbuf, pcmd->parmbuf, pcmd->cmdsz); 385 memcpy((u8 *)pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
387 while (check_cmd_fifo(padapter, wr_sz) == _FAIL) { 386 while (check_cmd_fifo(padapter, wr_sz) == _FAIL) {
388 if ((padapter->bDriverStopped == true) || 387 if ((padapter->bDriverStopped == true) ||
@@ -471,7 +470,7 @@ void r8712_event_handle(struct _adapter *padapter, uint *peventbuf)
471 pevt_priv->event_seq++; /* update evt_seq */ 470 pevt_priv->event_seq++; /* update evt_seq */
472 if (pevt_priv->event_seq > 127) 471 if (pevt_priv->event_seq > 127)
473 pevt_priv->event_seq = 0; 472 pevt_priv->event_seq = 0;
474 peventbuf = peventbuf + 2; /* move to event content, 8 bytes aligment */ 473 peventbuf = peventbuf + 2; /* move to event content, 8 bytes alignment */
475 if (peventbuf) { 474 if (peventbuf) {
476 event_callback = wlanevents[evt_code].event_callback; 475 event_callback = wlanevents[evt_code].event_callback;
477 if (event_callback) 476 if (event_callback)
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.h b/drivers/staging/rtl8712/rtl8712_cmd.h
index 766a6463266a..039ab3e97172 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.h
+++ b/drivers/staging/rtl8712/rtl8712_cmd.h
@@ -121,7 +121,7 @@ enum rtl8712_h2c_cmd {
121 GEN_CMD_CODE(_GetCurDataRate) , 121 GEN_CMD_CODE(_GetCurDataRate) ,
122 122
123 GEN_CMD_CODE(_GetTxRetrycnt), /* to record times that Tx retry to 123 GEN_CMD_CODE(_GetTxRetrycnt), /* to record times that Tx retry to
124 * transmmit packet after association 124 * transmit packet after association
125 */ 125 */
126 GEN_CMD_CODE(_GetRxRetrycnt), /* to record total number of the 126 GEN_CMD_CODE(_GetRxRetrycnt), /* to record total number of the
127 * received frame with ReTry bit set in 127 * received frame with ReTry bit set in
diff --git a/drivers/staging/rtl8712/rtl8712_efuse.c b/drivers/staging/rtl8712/rtl8712_efuse.c
index b08e9a25c9c5..377fca905801 100644
--- a/drivers/staging/rtl8712/rtl8712_efuse.c
+++ b/drivers/staging/rtl8712/rtl8712_efuse.c
@@ -417,7 +417,7 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
417 } else { /* write header fail */ 417 } else { /* write header fail */
418 bResult = false; 418 bResult = false;
419 if (0xFF == efuse_data) 419 if (0xFF == efuse_data)
420 return bResult; /* not thing damaged. */ 420 return bResult; /* nothing damaged. */
421 /* call rescue procedure */ 421 /* call rescue procedure */
422 if (fix_header(padapter, efuse_data, efuse_addr) == 422 if (fix_header(padapter, efuse_data, efuse_addr) ==
423 false) 423 false)
diff --git a/drivers/staging/rtl8712/rtl8712_gp_bitdef.h b/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
index 884a8212176d..138ea453d9df 100644
--- a/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
@@ -70,7 +70,7 @@
70#define GPIOSEL_BT 2 /* BT_coex*/ 70#define GPIOSEL_BT 2 /* BT_coex*/
71#define GPIOSEL_WLANDBG 3 /* WLANDBG*/ 71#define GPIOSEL_WLANDBG 3 /* WLANDBG*/
72#define GPIOSEL_GPIO_MASK (~(BIT(0)|BIT(1))) 72#define GPIOSEL_GPIO_MASK (~(BIT(0)|BIT(1)))
73/* HW Readio OFF switch (GPIO BIT) */ 73/* HW Radio OFF switch (GPIO BIT) */
74#define HAL_8192S_HW_GPIO_OFF_BIT BIT(3) 74#define HAL_8192S_HW_GPIO_OFF_BIT BIT(3)
75#define HAL_8192S_HW_GPIO_OFF_MASK 0xF7 75#define HAL_8192S_HW_GPIO_OFF_MASK 0xF7
76#define HAL_8192S_HW_GPIO_WPS_BIT BIT(4) 76#define HAL_8192S_HW_GPIO_WPS_BIT BIT(4)
diff --git a/drivers/staging/rtl8712/rtl8712_hal.h b/drivers/staging/rtl8712/rtl8712_hal.h
index d19865a5a50c..4c51fa373b54 100644
--- a/drivers/staging/rtl8712/rtl8712_hal.h
+++ b/drivers/staging/rtl8712/rtl8712_hal.h
@@ -83,7 +83,7 @@ struct fw_priv { /*8-bytes alignment required*/
83 unsigned char rfintfs; /* 0:SWSI, 1:HWSI, 2:HWPI*/ 83 unsigned char rfintfs; /* 0:SWSI, 1:HWSI, 2:HWPI*/
84 unsigned char def_nettype; 84 unsigned char def_nettype;
85 unsigned char turboMode; 85 unsigned char turboMode;
86 unsigned char lowPowerMode;/* 0: noral mode, 1: low power mode*/ 86 unsigned char lowPowerMode;/* 0: normal mode, 1: low power mode*/
87 /*--- long word 2 ----*/ 87 /*--- long word 2 ----*/
88 unsigned char lbk_mode; /*0x00: normal, 0x03: MACLBK, 0x01: PHYLBK*/ 88 unsigned char lbk_mode; /*0x00: normal, 0x03: MACLBK, 0x01: PHYLBK*/
89 unsigned char mp_mode; /* 1: for MP use, 0: for normal driver */ 89 unsigned char mp_mode; /* 1: for MP use, 0: for normal driver */
@@ -123,7 +123,7 @@ struct fw_priv { /*8-bytes alignment required*/
123 unsigned char rsvd053; 123 unsigned char rsvd053;
124}; 124};
125 125
126struct fw_hdr {/*8-byte alinment required*/ 126struct fw_hdr {/*8-byte alignment required*/
127 unsigned short signature; 127 unsigned short signature;
128 unsigned short version; /*0x8000 ~ 0x8FFF for FPGA version, 128 unsigned short version; /*0x8000 ~ 0x8FFF for FPGA version,
129 *0x0000 ~ 0x7FFF for ASIC version,*/ 129 *0x0000 ~ 0x7FFF for ASIC version,*/
diff --git a/drivers/staging/rtl8712/rtl8712_led.c b/drivers/staging/rtl8712/rtl8712_led.c
index bac56e5caf12..c9eb4b74799b 100644
--- a/drivers/staging/rtl8712/rtl8712_led.c
+++ b/drivers/staging/rtl8712/rtl8712_led.c
@@ -60,7 +60,7 @@ enum _LED_STATE_871x {
60 * the # of times to blink is depend on time 60 * the # of times to blink is depend on time
61 * for scanning. */ 61 * for scanning. */
62 LED_NO_LINK_BLINK = 7, /* LED is blinking during no link state. */ 62 LED_NO_LINK_BLINK = 7, /* LED is blinking during no link state. */
63 LED_BLINK_StartToBlink = 8,/* Customzied for Sercomm Printer 63 LED_BLINK_StartToBlink = 8,/* Customized for Sercomm Printer
64 * Server case */ 64 * Server case */
65 LED_BLINK_WPS = 9, /* LED is blinkg during WPS communication */ 65 LED_BLINK_WPS = 9, /* LED is blinkg during WPS communication */
66 LED_TXRX_BLINK = 10, 66 LED_TXRX_BLINK = 10,
@@ -826,7 +826,7 @@ static void BlinkTimerCallback(unsigned long data)
826{ 826{
827 struct LED_871x *pLed = (struct LED_871x *)data; 827 struct LED_871x *pLed = (struct LED_871x *)data;
828 828
829 /* This fixed the crash problem on Fedora 12 when trying to do thei 829 /* This fixed the crash problem on Fedora 12 when trying to do the
830 * insmod;ifconfig up;rmmod commands. */ 830 * insmod;ifconfig up;rmmod commands. */
831 if ((pLed->padapter->bSurpriseRemoved == true) || 831 if ((pLed->padapter->bSurpriseRemoved == true) ||
832 (pLed->padapter->bDriverStopped == true)) 832 (pLed->padapter->bDriverStopped == true))
@@ -836,7 +836,7 @@ static void BlinkTimerCallback(unsigned long data)
836 836
837/* Description: 837/* Description:
838 * Callback function of LED BlinkWorkItem. 838 * Callback function of LED BlinkWorkItem.
839 * We dispatch acture LED blink action according to LedStrategy. 839 * We dispatch actual LED blink action according to LedStrategy.
840 */ 840 */
841static void BlinkWorkItemCallback(struct work_struct *work) 841static void BlinkWorkItemCallback(struct work_struct *work)
842{ 842{
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index fa6dc9c09b3f..8e82ce2fee38 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -28,12 +28,13 @@
28 28
29#define _RTL8712_RECV_C_ 29#define _RTL8712_RECV_C_
30 30
31#include <linux/if_ether.h>
32#include <linux/ip.h>
33
31#include "osdep_service.h" 34#include "osdep_service.h"
32#include "drv_types.h" 35#include "drv_types.h"
33#include "recv_osdep.h" 36#include "recv_osdep.h"
34#include "mlme_osdep.h" 37#include "mlme_osdep.h"
35#include "ip.h"
36#include "if_ether.h"
37#include "ethernet.h" 38#include "ethernet.h"
38#include "usb_ops.h" 39#include "usb_ops.h"
39#include "wifi.h" 40#include "wifi.h"
@@ -459,7 +460,7 @@ void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
459 cmd_seq = (u8)((le32_to_cpu(voffset) >> 24) & 0x7f); 460 cmd_seq = (u8)((le32_to_cpu(voffset) >> 24) & 0x7f);
460 eid = (u8)((le32_to_cpu(voffset) >> 16) & 0xff); 461 eid = (u8)((le32_to_cpu(voffset) >> 16) & 0xff);
461 r8712_event_handle(padapter, (uint *)poffset); 462 r8712_event_handle(padapter, (uint *)poffset);
462 poffset += (cmd_len + 8);/*8 bytes aligment*/ 463 poffset += (cmd_len + 8);/*8 bytes alignment*/
463 } while (le32_to_cpu(voffset) & BIT(31)); 464 } while (le32_to_cpu(voffset) & BIT(31));
464 465
465} 466}
@@ -603,7 +604,7 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
603 } 604 }
604 } 605 }
605 spin_lock_irqsave(&ppending_recvframe_queue->lock, irql); 606 spin_lock_irqsave(&ppending_recvframe_queue->lock, irql);
606 /*s2. check if winstart_b(indicate_seq) needs to been updated*/ 607 /*s2. check if winstart_b(indicate_seq) needs to be updated*/
607 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) 608 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num))
608 goto _err_exit; 609 goto _err_exit;
609 /*s3. Insert all packet into Reorder Queue to maintain its ordering.*/ 610 /*s3. Insert all packet into Reorder Queue to maintain its ordering.*/
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index 693331955d67..3d23514c0222 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -30,7 +30,6 @@
30 30
31#include "osdep_service.h" 31#include "osdep_service.h"
32#include "drv_types.h" 32#include "drv_types.h"
33#include "rtl871x_byteorder.h"
34#include "wifi.h" 33#include "wifi.h"
35#include "osdep_intf.h" 34#include "osdep_intf.h"
36#include "usb_ops.h" 35#include "usb_ops.h"
diff --git a/drivers/staging/rtl8712/rtl871x_byteorder.h b/drivers/staging/rtl8712/rtl871x_byteorder.h
deleted file mode 100644
index bd3703b98bce..000000000000
--- a/drivers/staging/rtl8712/rtl871x_byteorder.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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 ******************************************************************************/
20#ifndef _RTL871X_BYTEORDER_H_
21#define _RTL871X_BYTEORDER_H_
22
23#if defined(__LITTLE_ENDIAN)
24# include "little_endian.h"
25#elif defined(__BIG_ENDIAN)
26# include "big_endian.h"
27#else
28# error "Must be LITTLE/BIG Endian Host"
29#endif
30
31#endif /* _RTL871X_BYTEORDER_H_ */
32
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index d77388bdba7b..659683e022b9 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -50,7 +50,6 @@
50#include "drv_types.h" 50#include "drv_types.h"
51#include "recv_osdep.h" 51#include "recv_osdep.h"
52#include "mlme_osdep.h" 52#include "mlme_osdep.h"
53#include "rtl871x_byteorder.h"
54 53
55/* 54/*
56Caller and the r8712_cmd_thread can protect cmd_q by spin_lock. 55Caller and the r8712_cmd_thread can protect cmd_q by spin_lock.
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index 757ebf77e9d6..9d93189d8700 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -720,7 +720,7 @@ struct DisconnectCtrlEx_param {
720 * Result: 720 * Result:
721 * 0x00: success 721 * 0x00: success
722 * 0x01: success, and check Response. 722 * 0x01: success, and check Response.
723 * 0x02: cmd ignored due to duplicated sequcne number 723 * 0x02: cmd ignored due to duplicated sequence number
724 * 0x03: cmd dropped due to invalid cmd code 724 * 0x03: cmd dropped due to invalid cmd code
725 * 0x04: reserved. 725 * 0x04: reserved.
726 */ 726 */
diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
index d3d8727c2ec5..dc23395fec3b 100644
--- a/drivers/staging/rtl8712/rtl871x_io.h
+++ b/drivers/staging/rtl8712/rtl871x_io.h
@@ -117,7 +117,7 @@ struct io_req {
117 u32 command; 117 u32 command;
118 u32 status; 118 u32 status;
119 u8 *pbuf; 119 u8 *pbuf;
120 void (*_async_io_callback)(struct _adapter *padater, 120 void (*_async_io_callback)(struct _adapter *padapter,
121 struct io_req *pio_req, u8 *cnxt); 121 struct io_req *pio_req, u8 *cnxt);
122 u8 *cnxt; 122 u8 *cnxt;
123}; 123};
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index ef35bc29a3fa..35e781fca4a0 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -43,7 +43,6 @@
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/kernel.h> 44#include <linux/kernel.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/version.h>
47#include <linux/io.h> 46#include <linux/io.h>
48#include <linux/semaphore.h> 47#include <linux/semaphore.h>
49#include <net/iw_handler.h> 48#include <net/iw_handler.h>
@@ -242,7 +241,7 @@ static inline char *translate_scan(struct _adapter *padapter,
242 /* Add frequency/channel */ 241 /* Add frequency/channel */
243 iwe.cmd = SIOCGIWFREQ; 242 iwe.cmd = SIOCGIWFREQ;
244 { 243 {
245 /* check legel index */ 244 /* check legal index */
246 u8 dsconfig = pnetwork->network.Configuration.DSConfig; 245 u8 dsconfig = pnetwork->network.Configuration.DSConfig;
247 if (dsconfig >= 1 && dsconfig <= sizeof( 246 if (dsconfig >= 1 && dsconfig <= sizeof(
248 ieee80211_wlan_frequencies) / sizeof(long)) 247 ieee80211_wlan_frequencies) / sizeof(long))
@@ -810,11 +809,11 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
810 809
811/* 810/*
812 There are the BSSID information in the bssid.sa_data array. 811 There are the BSSID information in the bssid.sa_data array.
813 If cmd is IW_PMKSA_FLUSH, it means the wpa_suppplicant wants to clear 812 If cmd is IW_PMKSA_FLUSH, it means the wpa_supplicant wants to clear
814 all the PMKID information. If cmd is IW_PMKSA_ADD, it means the 813 all the PMKID information. If cmd is IW_PMKSA_ADD, it means the
815 wpa_supplicant wants to add a PMKID/BSSID to driver. 814 wpa_supplicant wants to add a PMKID/BSSID to driver.
816 If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to 815 If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to
817 remove a PMKID/BSSID from driver. 816 remove a PMKID/BSSID from driver.
818*/ 817*/
819 if (pPMK == NULL) 818 if (pPMK == NULL)
820 return -EINVAL; 819 return -EINVAL;
@@ -924,7 +923,7 @@ static int r8711_wx_get_range(struct net_device *dev,
924 range->max_qual.noise = 100; 923 range->max_qual.noise = 100;
925 range->max_qual.updated = 7; /* Updated all three */ 924 range->max_qual.updated = 7; /* Updated all three */
926 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */ 925 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
927 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ 926 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
928 range->avg_qual.level = 20 + -98; 927 range->avg_qual.level = 20 + -98;
929 range->avg_qual.noise = 0; 928 range->avg_qual.noise = 0;
930 range->avg_qual.updated = 7; /* Updated all three */ 929 range->avg_qual.updated = 7; /* Updated all three */
@@ -1071,7 +1070,7 @@ FREE_EXT:
1071 * MAC# of a preferred Access Point. 1070 * MAC# of a preferred Access Point.
1072 * Currently, the request comes via Wireless Extensions' SIOCSIWAP ioctl. 1071 * Currently, the request comes via Wireless Extensions' SIOCSIWAP ioctl.
1073 * 1072 *
1074 * For this operation to succeed, there is no need for the interface to be Up. 1073 * For this operation to succeed, there is no need for the interface to be up.
1075 * 1074 *
1076 */ 1075 */
1077static int r8711_wx_set_wap(struct net_device *dev, 1076static int r8711_wx_set_wap(struct net_device *dev,
@@ -2389,10 +2388,10 @@ static struct iw_statistics *r871x_get_wireless_stats(struct net_device *dev)
2389 2388
2390struct iw_handler_def r871x_handlers_def = { 2389struct iw_handler_def r871x_handlers_def = {
2391 .standard = r8711_handlers, 2390 .standard = r8711_handlers,
2392 .num_standard = sizeof(r8711_handlers) / sizeof(iw_handler), 2391 .num_standard = ARRAY_SIZE(r8711_handlers),
2393 .private = r8711_private_handler, 2392 .private = r8711_private_handler,
2394 .private_args = (struct iw_priv_args *)r8711_private_args, 2393 .private_args = (struct iw_priv_args *)r8711_private_args,
2395 .num_private = sizeof(r8711_private_handler) / sizeof(iw_handler), 2394 .num_private = ARRAY_SIZE(r8711_private_handler),
2396 .num_private_args = sizeof(r8711_private_args) / 2395 .num_private_args = sizeof(r8711_private_args) /
2397 sizeof(struct iw_priv_args), 2396 sizeof(struct iw_priv_args),
2398 .get_wireless_stats = r871x_get_wireless_stats 2397 .get_wireless_stats = r871x_get_wireless_stats
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index fb29b423752f..f352b32355a0 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -264,7 +264,7 @@ void r8712_set_802_11_infrastructure_mode(struct _adapter *padapter,
264 (*pold_state == Ndis802_11Infrastructure) || 264 (*pold_state == Ndis802_11Infrastructure) ||
265 (*pold_state == Ndis802_11IBSS)) { 265 (*pold_state == Ndis802_11IBSS)) {
266 /* will clr Linked_state before this function, 266 /* will clr Linked_state before this function,
267 * we must have chked whether issue dis-assoc_cmd or 267 * we must have checked whether issue dis-assoc_cmd or
268 * not */ 268 * not */
269 r8712_ind_disconnect(padapter); 269 r8712_ind_disconnect(padapter);
270 } 270 }
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 4277d0304b7a..dc7adc132d12 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -137,7 +137,7 @@ static void _free_network_nolock(struct mlme_priv *pmlmepriv,
137 137
138/* 138/*
139 return the wlan_network with the matching addr 139 return the wlan_network with the matching addr
140 Shall be calle under atomic context... 140 Shall be called under atomic context...
141 to avoid possible racing condition... 141 to avoid possible racing condition...
142*/ 142*/
143static struct wlan_network *_r8712_find_network(struct __queue *scanned_queue, 143static struct wlan_network *_r8712_find_network(struct __queue *scanned_queue,
@@ -255,7 +255,7 @@ void r8712_free_network_queue(struct _adapter *dev)
255/* 255/*
256 return the wlan_network with the matching addr 256 return the wlan_network with the matching addr
257 257
258 Shall be calle under atomic context... 258 Shall be called under atomic context...
259 to avoid possible racing condition... 259 to avoid possible racing condition...
260*/ 260*/
261static struct wlan_network *r8712_find_network(struct __queue *scanned_queue, 261static struct wlan_network *r8712_find_network(struct __queue *scanned_queue,
@@ -1037,7 +1037,7 @@ void r8712_cpwm_event_callback(struct _adapter *adapter, u8 *pbuf)
1037 * and the WiFi client will drop the data with seq number 0. 1037 * and the WiFi client will drop the data with seq number 0.
1038 * So, the 8712 firmware has to inform driver with receiving the 1038 * So, the 8712 firmware has to inform driver with receiving the
1039 * ADDBA-Req frame so that the driver can reset the 1039 * ADDBA-Req frame so that the driver can reset the
1040 * sequence value of Rx reorder contorl. 1040 * sequence value of Rx reorder control.
1041 */ 1041 */
1042void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf) 1042void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf)
1043{ 1043{
@@ -1775,7 +1775,7 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
1775 phtpriv->rx_ampdu_maxlen = max_ampdu_sz; 1775 phtpriv->rx_ampdu_maxlen = max_ampdu_sz;
1776 } 1776 }
1777 /* for A-MPDU Rx reordering buffer control for bmc_sta & sta_info 1777 /* for A-MPDU Rx reordering buffer control for bmc_sta & sta_info
1778 * if A-MPDU Rx is enabled, reseting rx_ordering_ctrl 1778 * if A-MPDU Rx is enabled, resetting rx_ordering_ctrl
1779 * wstart_b(indicate_seq) to default value=0xffff 1779 * wstart_b(indicate_seq) to default value=0xffff
1780 * todo: check if AP can send A-MPDU packets 1780 * todo: check if AP can send A-MPDU packets
1781 */ 1781 */
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.h b/drivers/staging/rtl8712/rtl871x_mlme.h
index 71ca01350b5e..42bd0bf8a816 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.h
+++ b/drivers/staging/rtl8712/rtl871x_mlme.h
@@ -69,8 +69,8 @@ since mlme_priv is a shared resource between many threads,
69like ISR/Call-Back functions, the OID handlers, and even timer functions. 69like ISR/Call-Back functions, the OID handlers, and even timer functions.
70Each _queue has its own locks, already. 70Each _queue has its own locks, already.
71Other items are protected by mlme_priv.lock. 71Other items are protected by mlme_priv.lock.
72To avoid possible dead lock, any thread trying to modifiying mlme_priv 72To avoid possible dead lock, any thread trying to modify mlme_priv
73SHALL not lock up more than one locks at a time! 73SHALL not lock up more than one lock at a time!
74*/ 74*/
75 75
76#define traffic_threshold 10 76#define traffic_threshold 10
@@ -132,7 +132,7 @@ static inline sint get_fwstate(struct mlme_priv *pmlmepriv)
132 * therefore set it to be the critical section... 132 * therefore set it to be the critical section...
133 * 133 *
134 * ### NOTE:#### (!!!!) 134 * ### NOTE:#### (!!!!)
135 * TAKE CARE THAT BEFORE CALLING THIS FUNC, LOCK pmlmepriv->lock 135 * TAKE CARE BEFORE CALLING THIS FUNC, LOCK pmlmepriv->lock
136 */ 136 */
137static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state) 137static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
138{ 138{
diff --git a/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h b/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h
index 23532a793859..8e2586231ffd 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h
+++ b/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h
@@ -184,7 +184,7 @@
184 184
185/*RxIQ DC offset, Rx digital filter, DC notch filter */ 185/*RxIQ DC offset, Rx digital filter, DC notch filter */
186#define rOFDM0_XARxAFE 0xc10 186#define rOFDM0_XARxAFE 0xc10
187#define rOFDM0_XARxIQImbalance 0xc14 /* RxIQ imblance matrix */ 187#define rOFDM0_XARxIQImbalance 0xc14 /* RxIQ imbalance matrix */
188#define rOFDM0_XBRxAFE 0xc18 188#define rOFDM0_XBRxAFE 0xc18
189#define rOFDM0_XBRxIQImbalance 0xc1c 189#define rOFDM0_XBRxIQImbalance 0xc1c
190#define rOFDM0_XCRxAFE 0xc20 190#define rOFDM0_XCRxAFE 0xc20
@@ -603,7 +603,7 @@
603#define bCCKRxIG 0x7f00 603#define bCCKRxIG 0x7f00
604#define bCCKLNAPolarity 0x800000 604#define bCCKLNAPolarity 0x800000
605#define bCCKRx1stGain 0x7f0000 605#define bCCKRx1stGain 0x7f0000
606#define bCCKRFExtend 0x20000000 /* CCK Rx Iinital gain polarity */ 606#define bCCKRFExtend 0x20000000 /* CCK Rx inital gain polarity */
607#define bCCKRxAGCSatLevel 0x1f000000 607#define bCCKRxAGCSatLevel 0x1f000000
608#define bCCKRxAGCSatCount 0xe0 608#define bCCKRxAGCSatCount 0xe0
609#define bCCKRxRFSettle 0x1f /* AGCsamp_dly */ 609#define bCCKRxRFSettle 0x1f /* AGCsamp_dly */
diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 5b03b405883e..c9d1743e5c5d 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -28,15 +28,15 @@
28 28
29#define _RTL871X_RECV_C_ 29#define _RTL871X_RECV_C_
30 30
31#include <linux/ip.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/if_ether.h>
32#include <linux/kmemleak.h> 34#include <linux/kmemleak.h>
33 35
34#include "osdep_service.h" 36#include "osdep_service.h"
35#include "drv_types.h" 37#include "drv_types.h"
36#include "recv_osdep.h" 38#include "recv_osdep.h"
37#include "mlme_osdep.h" 39#include "mlme_osdep.h"
38#include "ip.h"
39#include "if_ether.h"
40#include "ethernet.h" 40#include "ethernet.h"
41#include "usb_ops.h" 41#include "usb_ops.h"
42#include "wifi.h" 42#include "wifi.h"
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index aa57e7754f04..78f570b571a7 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -30,7 +30,6 @@
30 30
31#include "osdep_service.h" 31#include "osdep_service.h"
32#include "drv_types.h" 32#include "drv_types.h"
33#include "rtl871x_byteorder.h"
34#include "wifi.h" 33#include "wifi.h"
35#include "osdep_intf.h" 34#include "osdep_intf.h"
36#include "usb_ops.h" 35#include "usb_ops.h"
@@ -72,7 +71,7 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
72 memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv)); 71 memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv));
73 spin_lock_init(&pxmitpriv->lock); 72 spin_lock_init(&pxmitpriv->lock);
74 /* 73 /*
75 Please insert all the queue initializaiton using _init_queue below 74 Please insert all the queue initialization using _init_queue below
76 */ 75 */
77 pxmitpriv->adapter = padapter; 76 pxmitpriv->adapter = padapter;
78 _init_queue(&pxmitpriv->be_pending); 77 _init_queue(&pxmitpriv->be_pending);
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.h b/drivers/staging/rtl8712/rtl871x_xmit.h
index 638b79b4c5a8..ee906987735a 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.h
+++ b/drivers/staging/rtl8712/rtl871x_xmit.h
@@ -119,7 +119,7 @@ struct pkt_attrib {
119 119
120 u8 priority; 120 u8 priority;
121 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, 121 u8 encrypt; /* when 0 indicate no encrypt. when non-zero,
122 * indicate the encrypt algorith*/ 122 * indicate the encrypt algorithm*/
123 u8 iv_len; 123 u8 iv_len;
124 u8 icv_len; 124 u8 icv_len;
125 unsigned char iv[8]; 125 unsigned char iv[8];
diff --git a/drivers/staging/rtl8712/swab.h b/drivers/staging/rtl8712/swab.h
deleted file mode 100644
index f12781829c1b..000000000000
--- a/drivers/staging/rtl8712/swab.h
+++ /dev/null
@@ -1,131 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
24 *
25 ******************************************************************************/
26#ifndef _LINUX_BYTEORDER_SWAB_H
27#define _LINUX_BYTEORDER_SWAB_H
28
29#ifndef __u16
30 #define __u16 unsigned short
31#endif
32
33#ifndef __u32
34 #define __u32 unsigned int
35#endif
36
37#ifndef __u8
38 #define __u8 unsigned char
39#endif
40
41#ifndef __u64
42 #define __u64 unsigned long long
43#endif
44
45
46static inline __u16 ___swab16(__u16 x)
47{
48 __u16 __x = x;
49 return (__u16)(
50 (((__u16)(__x) & (__u16)0x00ffU) << 8) |
51 (((__u16)(__x) & (__u16)0xff00U) >> 8));
52
53}
54
55static inline __u32 ___swab32(__u32 x)
56{
57 __u32 __x = (x);
58 return (__u32)(
59 (((__u32)(__x) & (__u32)0x000000ffUL) << 24) |
60 (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) |
61 (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) |
62 (((__u32)(__x) & (__u32)0xff000000UL) >> 24));
63}
64
65static inline __u64 ___swab64(__u64 x)
66{
67 __u64 __x = (x);
68
69 return (__u64)( \
70 (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \
71 (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \
72 (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \
73 (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \
74 (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \
75 (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
76 (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
77 (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56));
78}
79
80#ifndef __arch__swab16
81static inline __u16 __arch__swab16(__u16 x)
82{
83 return ___swab16(x);
84}
85
86#endif
87
88#ifndef __arch__swab32
89static inline __u32 __arch__swab32(__u32 x)
90{
91 __u32 __tmp = (x) ;
92 return ___swab32(__tmp);
93}
94#endif
95
96#ifndef __arch__swab64
97
98static inline __u64 __arch__swab64(__u64 x)
99{
100 __u64 __tmp = (x) ;
101 return ___swab64(__tmp);
102}
103
104
105#endif
106
107#define __swab16(x) __fswab16(x)
108#define __swab32(x) __fswab32(x)
109#define __swab64(x) __fswab64(x)
110
111static inline const __u16 __fswab16(__u16 x)
112{
113 return __arch__swab16(x);
114}
115static inline const __u32 __fswab32(__u32 x)
116{
117 return __arch__swab32(x);
118}
119
120#define swab16 __swab16
121#define swab32 __swab32
122#define swab64 __swab64
123#define swab16p __swab16p
124#define swab32p __swab32p
125#define swab64p __swab64p
126#define swab16s __swab16s
127#define swab32s __swab32s
128#define swab64s __swab64s
129
130#endif /* _LINUX_BYTEORDER_SWAB_H */
131
diff --git a/drivers/staging/rtl8712/usb_halinit.c b/drivers/staging/rtl8712/usb_halinit.c
index 46287c17a417..b4ae11a78b46 100644
--- a/drivers/staging/rtl8712/usb_halinit.c
+++ b/drivers/staging/rtl8712/usb_halinit.c
@@ -141,7 +141,7 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
141 /* Enable AFE PLL Macro Block */ 141 /* Enable AFE PLL Macro Block */
142 val8 = r8712_read8(padapter, AFE_PLL_CTRL); 142 val8 = r8712_read8(padapter, AFE_PLL_CTRL);
143 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11)); 143 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
144 /* Attatch AFE PLL to MACTOP/BB/PCIe Digital */ 144 /* Attach AFE PLL to MACTOP/BB/PCIe Digital */
145 val8 = r8712_read8(padapter, SYS_ISO_CTRL); 145 val8 = r8712_read8(padapter, SYS_ISO_CTRL);
146 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE)); 146 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
147 /* Switch to 40M clock */ 147 /* Switch to 40M clock */
@@ -234,7 +234,7 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
234 udelay(500); 234 udelay(500);
235 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11)); 235 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
236 udelay(500); 236 udelay(500);
237 /* Attatch AFE PLL to MACTOP/BB/PCIe Digital */ 237 /* Attach AFE PLL to MACTOP/BB/PCIe Digital */
238 val8 = r8712_read8(padapter, SYS_ISO_CTRL); 238 val8 = r8712_read8(padapter, SYS_ISO_CTRL);
239 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE)); 239 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
240 /* Switch to 40M clock */ 240 /* Switch to 40M clock */
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index e419b4fd82b9..9bd18e2d0513 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -621,30 +621,28 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf)
621 struct usb_device *udev = interface_to_usbdev(pusb_intf); 621 struct usb_device *udev = interface_to_usbdev(pusb_intf);
622 622
623 usb_set_intfdata(pusb_intf, NULL); 623 usb_set_intfdata(pusb_intf, NULL);
624 if (padapter) { 624 if (padapter->fw_found)
625 if (padapter->fw_found) 625 release_firmware(padapter->fw);
626 release_firmware(padapter->fw); 626 /* never exit with a firmware callback pending */
627 /* never exit with a firmware callback pending */ 627 wait_for_completion(&padapter->rtl8712_fw_ready);
628 wait_for_completion(&padapter->rtl8712_fw_ready); 628 if (drvpriv.drv_registered == true)
629 if (drvpriv.drv_registered == true) 629 padapter->bSurpriseRemoved = true;
630 padapter->bSurpriseRemoved = true; 630 if (pnetdev != NULL) {
631 if (pnetdev != NULL) { 631 /* will call netdev_close() */
632 /* will call netdev_close() */ 632 unregister_netdev(pnetdev);
633 unregister_netdev(pnetdev);
634 }
635 flush_scheduled_work();
636 udelay(1);
637 /*Stop driver mlme relation timer */
638 if (padapter->fw_found)
639 r8712_stop_drv_timers(padapter);
640 r871x_dev_unload(padapter);
641 r8712_free_drv_sw(padapter);
642 } 633 }
634 flush_scheduled_work();
635 udelay(1);
636 /*Stop driver mlme relation timer */
637 if (padapter->fw_found)
638 r8712_stop_drv_timers(padapter);
639 r871x_dev_unload(padapter);
640 r8712_free_drv_sw(padapter);
643 usb_set_intfdata(pusb_intf, NULL); 641 usb_set_intfdata(pusb_intf, NULL);
644 /* decrease the reference count of the usb device structure 642 /* decrease the reference count of the usb device structure
645 * when disconnect */ 643 * when disconnect */
646 usb_put_dev(udev); 644 usb_put_dev(udev);
647 /* If we didn't unplug usb dongle and remove/insert modlue, driver 645 /* If we didn't unplug usb dongle and remove/insert module, driver
648 * fails on sitesurvey for the first time when device is up. 646 * fails on sitesurvey for the first time when device is up.
649 * Reset usb port for sitesurvey fail issue. */ 647 * Reset usb port for sitesurvey fail issue. */
650 if (udev->state != USB_STATE_NOTATTACHED) 648 if (udev->state != USB_STATE_NOTATTACHED)
diff --git a/drivers/staging/rtl8712/usb_ops.c b/drivers/staging/rtl8712/usb_ops.c
index 5a8b0ebd0b79..c03508d935f2 100644
--- a/drivers/staging/rtl8712/usb_ops.c
+++ b/drivers/staging/rtl8712/usb_ops.c
@@ -33,7 +33,6 @@
33#include "osdep_intf.h" 33#include "osdep_intf.h"
34#include "usb_ops.h" 34#include "usb_ops.h"
35#include "recv_osdep.h" 35#include "recv_osdep.h"
36#include "rtl871x_byteorder.h"
37 36
38static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr) 37static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
39{ 38{
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 277398cff0a7..793443e758ac 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -26,7 +26,6 @@
26#ifndef _WIFI_H_ 26#ifndef _WIFI_H_
27#define _WIFI_H_ 27#define _WIFI_H_
28 28
29#include "rtl871x_byteorder.h"
30#include <linux/compiler.h> 29#include <linux/compiler.h>
31 30
32#ifdef BIT 31#ifdef BIT
diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c
index c9703627c8f5..65542cb7168f 100644
--- a/drivers/staging/rtl8712/xmit_linux.c
+++ b/drivers/staging/rtl8712/xmit_linux.c
@@ -29,14 +29,12 @@
29#define _XMIT_OSDEP_C_ 29#define _XMIT_OSDEP_C_
30 30
31#include <linux/usb.h> 31#include <linux/usb.h>
32#include <linux/ip.h>
33#include <linux/if_ether.h>
32 34
33#include "osdep_service.h" 35#include "osdep_service.h"
34#include "drv_types.h" 36#include "drv_types.h"
35 37
36
37#include "if_ether.h"
38#include "ip.h"
39#include "rtl871x_byteorder.h"
40#include "wifi.h" 38#include "wifi.h"
41#include "mlme_osdep.h" 39#include "mlme_osdep.h"
42#include "xmit_osdep.h" 40#include "xmit_osdep.h"
diff --git a/drivers/staging/rts5139/ms.c b/drivers/staging/rts5139/ms.c
index b0e9071c8e52..6eef33b03f55 100644
--- a/drivers/staging/rts5139/ms.c
+++ b/drivers/staging/rts5139/ms.c
@@ -2680,7 +2680,7 @@ static int mspro_set_rw_cmd(struct rts51x_chip *chip, u32 start_sec,
2680 return STATUS_SUCCESS; 2680 return STATUS_SUCCESS;
2681} 2681}
2682 2682
2683void mspro_stop_seq_mode(struct rts51x_chip *chip) 2683static void mspro_stop_seq_mode(struct rts51x_chip *chip)
2684{ 2684{
2685 struct ms_info *ms_card = &(chip->ms_card); 2685 struct ms_info *ms_card = &(chip->ms_card);
2686 int retval; 2686 int retval;
@@ -3149,7 +3149,7 @@ Fail:
3149 TRACE_RET(chip, STATUS_FAIL); 3149 TRACE_RET(chip, STATUS_FAIL);
3150 3150
3151 sec_cnt = chip->rsp_buf[0]; 3151 sec_cnt = chip->rsp_buf[0];
3152 RTS51X_DEBUGP("%d pages need be trasferred, %d pages remained\n", 3152 RTS51X_DEBUGP("%d pages need be transferred, %d pages remained\n",
3153 (int)page_cnt, (int)sec_cnt); 3153 (int)page_cnt, (int)sec_cnt);
3154 page_addr = start_page + (page_cnt - sec_cnt); 3154 page_addr = start_page + (page_cnt - sec_cnt);
3155 3155
@@ -3864,7 +3864,7 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rts51x_chip *chip,
3864 log_blk = (u16) (start_sector >> ms_card->block_shift); 3864 log_blk = (u16) (start_sector >> ms_card->block_shift);
3865 start_page = (u8) (start_sector & ms_card->page_off); 3865 start_page = (u8) (start_sector & ms_card->page_off);
3866 3866
3867 for (seg_no = 0; seg_no < sizeof(ms_start_idx) / 2; seg_no++) { 3867 for (seg_no = 0; seg_no < ARRAY_SIZE(ms_start_idx) - 1; seg_no++) {
3868 if (log_blk < ms_start_idx[seg_no + 1]) 3868 if (log_blk < ms_start_idx[seg_no + 1])
3869 break; 3869 break;
3870 } 3870 }
@@ -4020,7 +4020,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rts51x_chip *chip,
4020 4020
4021 log_blk++; 4021 log_blk++;
4022 4022
4023 for (seg_no = 0; seg_no < sizeof(ms_start_idx) / 2; seg_no++) { 4023 for (seg_no = 0; seg_no < ARRAY_SIZE(ms_start_idx) - 1;
4024 seg_no++) {
4024 if (log_blk < ms_start_idx[seg_no + 1]) 4025 if (log_blk < ms_start_idx[seg_no + 1])
4025 break; 4026 break;
4026 } 4027 }
@@ -4134,7 +4135,7 @@ void ms_cleanup_work(struct rts51x_chip *chip)
4134 } 4135 }
4135} 4136}
4136 4137
4137int ms_power_off_card3v3(struct rts51x_chip *chip) 4138static int ms_power_off_card3v3(struct rts51x_chip *chip)
4138{ 4139{
4139 int retval; 4140 int retval;
4140 4141
diff --git a/drivers/staging/rts5139/ms.h b/drivers/staging/rts5139/ms.h
index 3ce1dc90f19d..0321d06e776d 100644
--- a/drivers/staging/rts5139/ms.h
+++ b/drivers/staging/rts5139/ms.h
@@ -234,7 +234,6 @@
234void mspro_polling_format_status(struct rts51x_chip *chip); 234void mspro_polling_format_status(struct rts51x_chip *chip);
235void mspro_format_sense(struct rts51x_chip *chip, unsigned int lun); 235void mspro_format_sense(struct rts51x_chip *chip, unsigned int lun);
236 236
237void mspro_stop_seq_mode(struct rts51x_chip *chip);
238int reset_ms_card(struct rts51x_chip *chip); 237int reset_ms_card(struct rts51x_chip *chip);
239int ms_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector, 238int ms_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector,
240 u16 sector_cnt); 239 u16 sector_cnt);
@@ -242,7 +241,6 @@ int mspro_format(struct scsi_cmnd *srb, struct rts51x_chip *chip,
242 int short_data_len, int quick_format); 241 int short_data_len, int quick_format);
243void ms_free_l2p_tbl(struct rts51x_chip *chip); 242void ms_free_l2p_tbl(struct rts51x_chip *chip);
244void ms_cleanup_work(struct rts51x_chip *chip); 243void ms_cleanup_work(struct rts51x_chip *chip);
245int ms_power_off_card3v3(struct rts51x_chip *chip);
246int release_ms_card(struct rts51x_chip *chip); 244int release_ms_card(struct rts51x_chip *chip);
247int ms_delay_write(struct rts51x_chip *chip); 245int ms_delay_write(struct rts51x_chip *chip);
248 246
diff --git a/drivers/staging/rts5139/ms_mg.c b/drivers/staging/rts5139/ms_mg.c
index 154b5230aa5e..057d96c1a937 100644
--- a/drivers/staging/rts5139/ms_mg.c
+++ b/drivers/staging/rts5139/ms_mg.c
@@ -38,7 +38,7 @@
38 38
39#ifdef SUPPORT_MAGIC_GATE 39#ifdef SUPPORT_MAGIC_GATE
40 40
41int mg_check_int_error(struct rts51x_chip *chip) 41static int mg_check_int_error(struct rts51x_chip *chip)
42{ 42{
43 u8 value; 43 u8 value;
44 44
@@ -444,7 +444,7 @@ int mg_rsp(struct scsi_cmnd *srb, struct rts51x_chip *chip)
444 * 444 *
445 * Since the extra 4 bytes data is just only a prefix to original data 445 * Since the extra 4 bytes data is just only a prefix to original data
446 * that read from medium, so that the 4-byte data pushed into Ring buffer 446 * that read from medium, so that the 4-byte data pushed into Ring buffer
447 * precedes data tramsinssion from medium to Ring buffer by DMA mechanisim 447 * precedes data transmission from medium to Ring buffer by DMA mechanism
448 * in order to get maximum performance and minimum code size simultaneously. 448 * in order to get maximum performance and minimum code size simultaneously.
449 */ 449 */
450int mg_get_ICV(struct scsi_cmnd *srb, struct rts51x_chip *chip) 450int mg_get_ICV(struct scsi_cmnd *srb, struct rts51x_chip *chip)
diff --git a/drivers/staging/rts5139/rts51x.c b/drivers/staging/rts5139/rts51x.c
index 2b9f785954df..c3fe7dda1f4e 100644
--- a/drivers/staging/rts5139/rts51x.c
+++ b/drivers/staging/rts5139/rts51x.c
@@ -56,12 +56,6 @@ MODULE_DESCRIPTION(RTS51X_DESC);
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57MODULE_VERSION(DRIVER_VERSION); 57MODULE_VERSION(DRIVER_VERSION);
58 58
59#ifdef SCSI_SCAN_DELAY
60static unsigned int delay_use = 5;
61module_param(delay_use, uint, S_IRUGO | S_IWUSR);
62MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
63#endif
64
65static int auto_delink_en; 59static int auto_delink_en;
66module_param(auto_delink_en, int, S_IRUGO | S_IWUSR); 60module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
67MODULE_PARM_DESC(auto_delink_en, "enable auto delink"); 61MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
@@ -114,7 +108,7 @@ static inline void usb_autopm_disable(struct usb_interface *intf)
114 usb_autopm_get_interface(intf); 108 usb_autopm_get_interface(intf);
115} 109}
116 110
117void rts51x_try_to_enter_ss(struct rts51x_chip *chip) 111static void rts51x_try_to_enter_ss(struct rts51x_chip *chip)
118{ 112{
119 RTS51X_DEBUGP("Ready to enter SS state\n"); 113 RTS51X_DEBUGP("Ready to enter SS state\n");
120 usb_autopm_enable(chip->usb->pusb_intf); 114 usb_autopm_enable(chip->usb->pusb_intf);
@@ -207,7 +201,7 @@ int rts51x_reset_resume(struct usb_interface *iface)
207 201
208#else /* CONFIG_PM */ 202#else /* CONFIG_PM */
209 203
210void rts51x_try_to_enter_ss(struct rts51x_chip *chip) 204static void rts51x_try_to_enter_ss(struct rts51x_chip *chip)
211{ 205{
212} 206}
213 207
@@ -364,11 +358,6 @@ static int rts51x_polling_thread(void *__chip)
364{ 358{
365 struct rts51x_chip *chip = (struct rts51x_chip *)__chip; 359 struct rts51x_chip *chip = (struct rts51x_chip *)__chip;
366 360
367#ifdef SCSI_SCAN_DELAY
368 /* Wait until SCSI scan finished */
369 wait_timeout((delay_use + 5) * HZ);
370#endif
371
372 for (;;) { 361 for (;;) {
373 wait_timeout(POLLING_INTERVAL); 362 wait_timeout(POLLING_INTERVAL);
374 363
@@ -432,38 +421,6 @@ static int rts51x_polling_thread(void *__chip)
432 return 0; 421 return 0;
433} 422}
434 423
435#ifdef SCSI_SCAN_DELAY
436/* Thread to carry out delayed SCSI-device scanning */
437static int rts51x_scan_thread(void *__chip)
438{
439 struct rts51x_chip *chip = (struct rts51x_chip *)__chip;
440
441 printk(KERN_DEBUG
442 "rts51x: device found at %d\n", chip->usb->pusb_dev->devnum);
443
444 set_freezable();
445 /* Wait for the timeout to expire or for a disconnect */
446 if (delay_use > 0) {
447 printk(KERN_DEBUG "rts51x: waiting for device "
448 "to settle before scanning\n");
449 wait_event_freezable_timeout(chip->usb->delay_wait,
450 test_bit(FLIDX_DONT_SCAN,
451 &chip->usb->dflags),
452 delay_use * HZ);
453 }
454
455 /* If the device is still connected, perform the scanning */
456 if (!test_bit(FLIDX_DONT_SCAN, &chip->usb->dflags)) {
457 scsi_scan_host(rts51x_to_host(chip));
458 printk(KERN_DEBUG "rts51x: device scan complete\n");
459
460 /* Should we unbind if no devices were detected? */
461 }
462
463 complete_and_exit(&chip->usb->scanning_done, 0);
464}
465#endif
466
467/* Associate our private data with the USB device */ 424/* Associate our private data with the USB device */
468static int associate_dev(struct rts51x_chip *chip, struct usb_interface *intf) 425static int associate_dev(struct rts51x_chip *chip, struct usb_interface *intf)
469{ 426{
@@ -521,7 +478,6 @@ static void rts51x_init_options(struct rts51x_chip *chip)
521{ 478{
522 struct rts51x_option *option = &(chip->option); 479 struct rts51x_option *option = &(chip->option);
523 480
524 option->led_blink_speed = 7;
525 option->mspro_formatter_enable = 1; 481 option->mspro_formatter_enable = 1;
526 482
527 option->fpga_sd_sdr104_clk = CLK_100; 483 option->fpga_sd_sdr104_clk = CLK_100;
@@ -549,7 +505,6 @@ static void rts51x_init_options(struct rts51x_chip *chip)
549 505
550 option->ss_en = ss_en; 506 option->ss_en = ss_en;
551 option->ss_delay = ss_delay; 507 option->ss_delay = ss_delay;
552 option->needs_remote_wakeup = needs_remote_wakeup;
553 508
554 option->auto_delink_en = auto_delink_en; 509 option->auto_delink_en = auto_delink_en;
555 510
@@ -561,10 +516,7 @@ static void rts51x_init_options(struct rts51x_chip *chip)
561 option->rts5129_D3318_off_enable = 0; 516 option->rts5129_D3318_off_enable = 0;
562 option->sd20_pad_drive = 0; 517 option->sd20_pad_drive = 0;
563 option->reset_or_rw_fail_set_pad_drive = 1; 518 option->reset_or_rw_fail_set_pad_drive = 1;
564 option->rcc_fail_flag = 0;
565 option->rcc_bug_fix_en = 1;
566 option->debounce_num = 2; 519 option->debounce_num = 2;
567 option->polling_time = 100;
568 option->led_toggle_interval = 6; 520 option->led_toggle_interval = 6;
569 option->xd_rwn_step = 0; 521 option->xd_rwn_step = 0;
570 option->sd_send_status_en = 0; 522 option->sd_send_status_en = 0;
@@ -737,15 +689,6 @@ static void quiesce_and_remove_host(struct rts51x_chip *chip)
737 if (rts51x->pusb_dev->state == USB_STATE_NOTATTACHED) 689 if (rts51x->pusb_dev->state == USB_STATE_NOTATTACHED)
738 set_bit(FLIDX_DISCONNECTING, &rts51x->dflags); 690 set_bit(FLIDX_DISCONNECTING, &rts51x->dflags);
739 691
740#ifdef SCSI_SCAN_DELAY
741 /* Prevent SCSI-scanning (if it hasn't started yet)
742 * and wait for the SCSI-scanning thread to stop.
743 */
744 set_bit(FLIDX_DONT_SCAN, &rts51x->dflags);
745 wake_up(&rts51x->delay_wait);
746 wait_for_completion(&rts51x->scanning_done);
747#endif
748
749 /* Removing the host will perform an orderly shutdown: caches 692 /* Removing the host will perform an orderly shutdown: caches
750 * synchronized, disks spun down, etc. 693 * synchronized, disks spun down, etc.
751 */ 694 */
@@ -757,9 +700,6 @@ static void quiesce_and_remove_host(struct rts51x_chip *chip)
757 scsi_lock(host); 700 scsi_lock(host);
758 set_bit(FLIDX_DISCONNECTING, &rts51x->dflags); 701 set_bit(FLIDX_DISCONNECTING, &rts51x->dflags);
759 scsi_unlock(host); 702 scsi_unlock(host);
760#ifdef SCSI_SCAN_DELAY
761 wake_up(&rts51x->delay_wait);
762#endif
763} 703}
764 704
765/* Second stage of disconnect processing: deallocate all resources */ 705/* Second stage of disconnect processing: deallocate all resources */
@@ -818,10 +758,6 @@ static int rts51x_probe(struct usb_interface *intf,
818 init_completion(&rts51x->control_exit); 758 init_completion(&rts51x->control_exit);
819 init_completion(&rts51x->polling_exit); 759 init_completion(&rts51x->polling_exit);
820 init_completion(&(rts51x->notify)); 760 init_completion(&(rts51x->notify));
821#ifdef SCSI_SCAN_DELAY
822 init_waitqueue_head(&rts51x->delay_wait);
823 init_completion(&rts51x->scanning_done);
824#endif
825 761
826 chip->usb = rts51x; 762 chip->usb = rts51x;
827 763
@@ -855,22 +791,7 @@ static int rts51x_probe(struct usb_interface *intf,
855 printk(KERN_WARNING RTS51X_TIP "Unable to add the scsi host\n"); 791 printk(KERN_WARNING RTS51X_TIP "Unable to add the scsi host\n");
856 goto BadDevice; 792 goto BadDevice;
857 } 793 }
858#ifdef SCSI_SCAN_DELAY
859 /* Start up the thread for delayed SCSI-device scanning */
860 th = kthread_create(rts51x_scan_thread, chip, RTS51X_SCAN_THREAD);
861 if (IS_ERR(th)) {
862 printk(KERN_WARNING RTS51X_TIP
863 "Unable to start the device-scanning thread\n");
864 complete(&rts51x->scanning_done);
865 quiesce_and_remove_host(chip);
866 result = PTR_ERR(th);
867 goto BadDevice;
868 }
869
870 wake_up_process(th);
871#else
872 scsi_scan_host(rts51x_to_host(chip)); 794 scsi_scan_host(rts51x_to_host(chip));
873#endif
874 795
875 /* Start up our polling thread */ 796 /* Start up our polling thread */
876 th = kthread_run(rts51x_polling_thread, chip, RTS51X_POLLING_THREAD); 797 th = kthread_run(rts51x_polling_thread, chip, RTS51X_POLLING_THREAD);
diff --git a/drivers/staging/rts5139/rts51x.h b/drivers/staging/rts5139/rts51x.h
index b2c58390bfc5..ecc0109a5b1a 100644
--- a/drivers/staging/rts5139/rts51x.h
+++ b/drivers/staging/rts5139/rts51x.h
@@ -47,11 +47,9 @@
47#define RTS51X_DESC "Realtek RTS5139/29 USB card reader driver" 47#define RTS51X_DESC "Realtek RTS5139/29 USB card reader driver"
48#define RTS51X_NAME "rts5139" 48#define RTS51X_NAME "rts5139"
49#define RTS51X_CTL_THREAD "rts5139-control" 49#define RTS51X_CTL_THREAD "rts5139-control"
50#define RTS51X_SCAN_THREAD "rts5139-scan"
51#define RTS51X_POLLING_THREAD "rts5139-polling" 50#define RTS51X_POLLING_THREAD "rts5139-polling"
52 51
53#define POLLING_IN_THREAD 52#define POLLING_IN_THREAD
54/* #define SCSI_SCAN_DELAY */
55#define SUPPORT_FILE_OP 53#define SUPPORT_FILE_OP
56 54
57#define wait_timeout_x(task_state, msecs) \ 55#define wait_timeout_x(task_state, msecs) \
@@ -66,8 +64,6 @@ do { \
66 64
67/* Size of the DMA-mapped I/O buffer */ 65/* Size of the DMA-mapped I/O buffer */
68#define RTS51X_IOBUF_SIZE 1024 66#define RTS51X_IOBUF_SIZE 1024
69/* Size of the autosense data buffer */
70#define RTS51X_SENSE_SIZE 18
71 67
72/* Dynamic bitflag definitions (dflags): used in set_bit() etc. */ 68/* Dynamic bitflag definitions (dflags): used in set_bit() etc. */
73#define FLIDX_URB_ACTIVE 0 /* current_urb is in use */ 69#define FLIDX_URB_ACTIVE 0 /* current_urb is in use */
@@ -76,7 +72,6 @@ do { \
76#define FLIDX_DISCONNECTING 3 /* disconnect in progress */ 72#define FLIDX_DISCONNECTING 3 /* disconnect in progress */
77#define FLIDX_RESETTING 4 /* device reset in progress */ 73#define FLIDX_RESETTING 4 /* device reset in progress */
78#define FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ 74#define FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
79#define FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
80 75
81struct rts51x_chip; 76struct rts51x_chip;
82 77
@@ -116,10 +111,6 @@ struct rts51x_usb {
116 struct completion control_exit; /* control thread exit */ 111 struct completion control_exit; /* control thread exit */
117 struct completion polling_exit; /* polling thread exit */ 112 struct completion polling_exit; /* polling thread exit */
118 struct completion notify; /* thread begin/end */ 113 struct completion notify; /* thread begin/end */
119#ifdef SCSI_SCAN_DELAY
120 wait_queue_head_t delay_wait; /* wait during scan, reset */
121 struct completion scanning_done; /* wait for scan thread */
122#endif
123}; 114};
124 115
125extern struct usb_driver rts51x_driver; 116extern struct usb_driver rts51x_driver;
@@ -188,7 +179,6 @@ enum xfer_buf_dir { TO_XFER_BUF, FROM_XFER_BUF };
188 179
189/* General routines provided by the usb-storage standard core */ 180/* General routines provided by the usb-storage standard core */
190#ifdef CONFIG_PM 181#ifdef CONFIG_PM
191void rts51x_try_to_enter_ss(struct rts51x_chip *chip);
192void rts51x_try_to_exit_ss(struct rts51x_chip *chip); 182void rts51x_try_to_exit_ss(struct rts51x_chip *chip);
193int rts51x_suspend(struct usb_interface *iface, pm_message_t message); 183int rts51x_suspend(struct usb_interface *iface, pm_message_t message);
194int rts51x_resume(struct usb_interface *iface); 184int rts51x_resume(struct usb_interface *iface);
diff --git a/drivers/staging/rts5139/rts51x_card.c b/drivers/staging/rts5139/rts51x_card.c
index 424a84581b86..4192c3bac12f 100644
--- a/drivers/staging/rts5139/rts51x_card.c
+++ b/drivers/staging/rts5139/rts51x_card.c
@@ -37,7 +37,6 @@
37#include "rts51x_chip.h" 37#include "rts51x_chip.h"
38#include "rts51x_card.h" 38#include "rts51x_card.h"
39#include "rts51x_transport.h" 39#include "rts51x_transport.h"
40#include "rts51x_sys.h"
41#include "xd.h" 40#include "xd.h"
42#include "sd.h" 41#include "sd.h"
43#include "ms.h" 42#include "ms.h"
@@ -94,7 +93,7 @@ void do_remaining_work(struct rts51x_chip *chip)
94 ms_cleanup_work(chip); 93 ms_cleanup_work(chip);
95} 94}
96 95
97void do_reset_xd_card(struct rts51x_chip *chip) 96static void do_reset_xd_card(struct rts51x_chip *chip)
98{ 97{
99 int retval; 98 int retval;
100 99
@@ -148,7 +147,7 @@ void do_reset_sd_card(struct rts51x_chip *chip)
148 } 147 }
149} 148}
150 149
151void do_reset_ms_card(struct rts51x_chip *chip) 150static void do_reset_ms_card(struct rts51x_chip *chip)
152{ 151{
153 int retval; 152 int retval;
154 153
@@ -175,7 +174,7 @@ void do_reset_ms_card(struct rts51x_chip *chip)
175 } 174 }
176} 175}
177 176
178void card_cd_debounce(struct rts51x_chip *chip, u8 *need_reset, 177static void card_cd_debounce(struct rts51x_chip *chip, u8 *need_reset,
179 u8 *need_release) 178 u8 *need_release)
180{ 179{
181 int retval; 180 int retval;
@@ -191,7 +190,6 @@ void card_cd_debounce(struct rts51x_chip *chip, u8 *need_reset,
191 goto Exit_Debounce; 190 goto Exit_Debounce;
192 191
193 if (chip->card_exist) { 192 if (chip->card_exist) {
194 rts51x_clear_start_time(chip);
195 retval = rts51x_read_register(chip, CARD_INT_PEND, &value); 193 retval = rts51x_read_register(chip, CARD_INT_PEND, &value);
196 if (retval != STATUS_SUCCESS) { 194 if (retval != STATUS_SUCCESS) {
197 rts51x_ep0_write_register(chip, MC_FIFO_CTL, FIFO_FLUSH, 195 rts51x_ep0_write_register(chip, MC_FIFO_CTL, FIFO_FLUSH,
@@ -214,17 +212,11 @@ void card_cd_debounce(struct rts51x_chip *chip, u8 *need_reset,
214 } 212 }
215 } else { 213 } else {
216 if (chip->card_status & XD_CD) { 214 if (chip->card_status & XD_CD) {
217 rts51x_clear_start_time(chip);
218 reset_map |= XD_CARD; 215 reset_map |= XD_CARD;
219 } else if (chip->card_status & SD_CD) { 216 } else if (chip->card_status & SD_CD) {
220 rts51x_clear_start_time(chip);
221 reset_map |= SD_CARD; 217 reset_map |= SD_CARD;
222 } else if (chip->card_status & MS_CD) { 218 } else if (chip->card_status & MS_CD) {
223 rts51x_clear_start_time(chip);
224 reset_map |= MS_CARD; 219 reset_map |= MS_CARD;
225 } else {
226 if (rts51x_check_start_time(chip))
227 rts51x_set_start_time(chip);
228 } 220 }
229 } 221 }
230 222
@@ -709,7 +701,7 @@ u8 get_lun_card(struct rts51x_chip *chip, unsigned int lun)
709 return 0; 701 return 0;
710} 702}
711 703
712int card_share_mode(struct rts51x_chip *chip, int card) 704static int card_share_mode(struct rts51x_chip *chip, int card)
713{ 705{
714 u8 value; 706 u8 value;
715 707
@@ -823,22 +815,6 @@ int enable_card_clock(struct rts51x_chip *chip, u8 card)
823 return STATUS_SUCCESS; 815 return STATUS_SUCCESS;
824} 816}
825 817
826int disable_card_clock(struct rts51x_chip *chip, u8 card)
827{
828 u8 clk_en = 0;
829
830 if (card & XD_CARD)
831 clk_en |= XD_CLK_EN;
832 if (card & SD_CARD)
833 clk_en |= SD_CLK_EN;
834 if (card & MS_CARD)
835 clk_en |= MS_CLK_EN;
836
837 RTS51X_WRITE_REG(chip, CARD_CLK_EN, clk_en, 0);
838
839 return STATUS_SUCCESS;
840}
841
842int card_power_on(struct rts51x_chip *chip, u8 card) 818int card_power_on(struct rts51x_chip *chip, u8 card)
843{ 819{
844 u8 mask, val1, val2; 820 u8 mask, val1, val2;
@@ -851,16 +827,7 @@ int card_power_on(struct rts51x_chip *chip, u8 card)
851 if ((card == SD_CARD) || (card == XD_CARD)) { 827 if ((card == SD_CARD) || (card == XD_CARD)) {
852 RTS51X_WRITE_REG(chip, CARD_PWR_CTL, mask | LDO3318_PWR_MASK, 828 RTS51X_WRITE_REG(chip, CARD_PWR_CTL, mask | LDO3318_PWR_MASK,
853 val1 | LDO_SUSPEND); 829 val1 | LDO_SUSPEND);
854 /* RTS51X_WRITE_REG(chip, CARD_PWR_CTL,
855 LDO3318_PWR_MASK, LDO_SUSPEND); */
856 } 830 }
857 /* else if(card==XD_CARD)
858 {
859 RTS51X_WRITE_REG(chip, CARD_PWR_CTL,
860 mask|LDO3318_PWR_MASK, val1|LDO_SUSPEND);
861 //RTS51X_WRITE_REG(chip, CARD_PWR_CTL,
862 // LDO3318_PWR_MASK, LDO_SUSPEND);
863 } */
864 else { 831 else {
865#endif 832#endif
866 RTS51X_WRITE_REG(chip, CARD_PWR_CTL, mask, val1); 833 RTS51X_WRITE_REG(chip, CARD_PWR_CTL, mask, val1);
@@ -879,17 +846,6 @@ int card_power_on(struct rts51x_chip *chip, u8 card)
879 return STATUS_SUCCESS; 846 return STATUS_SUCCESS;
880} 847}
881 848
882int card_power_off(struct rts51x_chip *chip, u8 card)
883{
884 u8 mask, val;
885
886 mask = POWER_MASK;
887 val = POWER_OFF;
888 RTS51X_WRITE_REG(chip, CARD_PWR_CTL, mask, val);
889
890 return STATUS_SUCCESS;
891}
892
893int monitor_card_cd(struct rts51x_chip *chip, u8 card) 849int monitor_card_cd(struct rts51x_chip *chip, u8 card)
894{ 850{
895 int retval; 851 int retval;
diff --git a/drivers/staging/rts5139/rts51x_card.h b/drivers/staging/rts5139/rts51x_card.h
index ac3c1e741ab9..c5c03cce98bd 100644
--- a/drivers/staging/rts5139/rts51x_card.h
+++ b/drivers/staging/rts5139/rts51x_card.h
@@ -204,13 +204,7 @@
204 204
205/* LDO_POWER_CFG */ 205/* LDO_POWER_CFG */
206#define TUNE_SD18_MASK 0x1C 206#define TUNE_SD18_MASK 0x1C
207#define TUNE_SD18_1V7 0x00
208#define TUNE_SD18_1V8 (0x01 << 2) 207#define TUNE_SD18_1V8 (0x01 << 2)
209#define TUNE_SD18_1V9 (0x02 << 2)
210#define TUNE_SD18_2V0 (0x03 << 2)
211#define TUNE_SD18_2V7 (0x04 << 2)
212#define TUNE_SD18_2V8 (0x05 << 2)
213#define TUNE_SD18_2V9 (0x06 << 2)
214#define TUNE_SD18_3V3 (0x07 << 2) 208#define TUNE_SD18_3V3 (0x07 << 2)
215 209
216/* XD_CP_WAITTIME */ 210/* XD_CP_WAITTIME */
@@ -744,9 +738,7 @@
744int monitor_card_cd(struct rts51x_chip *chip, u8 card); 738int monitor_card_cd(struct rts51x_chip *chip, u8 card);
745 739
746void do_remaining_work(struct rts51x_chip *chip); 740void do_remaining_work(struct rts51x_chip *chip);
747void do_reset_xd_card(struct rts51x_chip *chip);
748void do_reset_sd_card(struct rts51x_chip *chip); 741void do_reset_sd_card(struct rts51x_chip *chip);
749void do_reset_ms_card(struct rts51x_chip *chip);
750void rts51x_init_cards(struct rts51x_chip *chip); 742void rts51x_init_cards(struct rts51x_chip *chip);
751void rts51x_release_cards(struct rts51x_chip *chip); 743void rts51x_release_cards(struct rts51x_chip *chip);
752int switch_ssc_clock(struct rts51x_chip *chip, int clk); 744int switch_ssc_clock(struct rts51x_chip *chip, int clk);
@@ -754,15 +746,12 @@ int switch_normal_clock(struct rts51x_chip *chip, int clk);
754int card_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 sec_addr, 746int card_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 sec_addr,
755 u16 sec_cnt); 747 u16 sec_cnt);
756u8 get_lun_card(struct rts51x_chip *chip, unsigned int lun); 748u8 get_lun_card(struct rts51x_chip *chip, unsigned int lun);
757int card_share_mode(struct rts51x_chip *chip, int card);
758int rts51x_select_card(struct rts51x_chip *chip, int card); 749int rts51x_select_card(struct rts51x_chip *chip, int card);
759void eject_card(struct rts51x_chip *chip, unsigned int lun); 750void eject_card(struct rts51x_chip *chip, unsigned int lun);
760void trans_dma_enable(enum dma_data_direction dir, struct rts51x_chip *chip, 751void trans_dma_enable(enum dma_data_direction dir, struct rts51x_chip *chip,
761 u32 byte_cnt, u8 pack_size); 752 u32 byte_cnt, u8 pack_size);
762int enable_card_clock(struct rts51x_chip *chip, u8 card); 753int enable_card_clock(struct rts51x_chip *chip, u8 card);
763int disable_card_clock(struct rts51x_chip *chip, u8 card);
764int card_power_on(struct rts51x_chip *chip, u8 card); 754int card_power_on(struct rts51x_chip *chip, u8 card);
765int card_power_off(struct rts51x_chip *chip, u8 card);
766int toggle_gpio(struct rts51x_chip *chip, u8 gpio); 755int toggle_gpio(struct rts51x_chip *chip, u8 gpio);
767int turn_on_led(struct rts51x_chip *chip, u8 gpio); 756int turn_on_led(struct rts51x_chip *chip, u8 gpio);
768int turn_off_led(struct rts51x_chip *chip, u8 gpio); 757int turn_off_led(struct rts51x_chip *chip, u8 gpio);
diff --git a/drivers/staging/rts5139/rts51x_chip.c b/drivers/staging/rts5139/rts51x_chip.c
index b3e0bb22b0ff..db88d7a194b8 100644
--- a/drivers/staging/rts5139/rts51x_chip.c
+++ b/drivers/staging/rts5139/rts51x_chip.c
@@ -34,7 +34,6 @@
34#include "rts51x_chip.h" 34#include "rts51x_chip.h"
35#include "rts51x_card.h" 35#include "rts51x_card.h"
36#include "rts51x_transport.h" 36#include "rts51x_transport.h"
37#include "rts51x_sys.h"
38#include "xd.h" 37#include "xd.h"
39#include "ms.h" 38#include "ms.h"
40#include "sd.h" 39#include "sd.h"
@@ -79,20 +78,18 @@ int rts51x_reset_chip(struct rts51x_chip *chip)
79 chip->option.sd20_pad_drive); 78 chip->option.sd20_pad_drive);
80 if (chip->rts5179) 79 if (chip->rts5179)
81 rts51x_write_register(chip, CARD_PULL_CTL5, 0x03, 0x01); 80 rts51x_write_register(chip, CARD_PULL_CTL5, 0x03, 0x01);
82 if (!chip->option.ww_enable) { 81 if (CHECK_PKG(chip, LQFP48)) {
83 if (CHECK_PKG(chip, LQFP48)) { 82 rts51x_write_register(chip, CARD_PULL_CTL3,
84 rts51x_write_register(chip, CARD_PULL_CTL3, 83 0x80, 0x80);
85 0x80, 0x80); 84 rts51x_write_register(chip, CARD_PULL_CTL6,
86 rts51x_write_register(chip, CARD_PULL_CTL6, 85 0xf0, 0xA0);
87 0xf0, 0xA0); 86 } else {
88 } else { 87 rts51x_write_register(chip, CARD_PULL_CTL1,
89 rts51x_write_register(chip, CARD_PULL_CTL1, 88 0x30, 0x20);
90 0x30, 0x20); 89 rts51x_write_register(chip, CARD_PULL_CTL3,
91 rts51x_write_register(chip, CARD_PULL_CTL3, 90 0x80, 0x80);
92 0x80, 0x80); 91 rts51x_write_register(chip, CARD_PULL_CTL6,
93 rts51x_write_register(chip, CARD_PULL_CTL6, 92 0x0c, 0x08);
94 0x0c, 0x08);
95 }
96 } 93 }
97 } 94 }
98 if (chip->option.sd_ctl & SUPPORT_UHS50_MMC44) { 95 if (chip->option.sd_ctl & SUPPORT_UHS50_MMC44) {
@@ -121,12 +118,6 @@ int rts51x_reset_chip(struct rts51x_chip *chip)
121 118
122 /* GPIO OE */ 119 /* GPIO OE */
123 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_GPIO, GPIO_OE, GPIO_OE); 120 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_GPIO, GPIO_OE, GPIO_OE);
124#ifdef LED_AUTO_BLINK
125 /* LED autoblink */
126 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_AUTO_BLINK,
127 BLINK_ENABLE | BLINK_SPEED_MASK,
128 BLINK_ENABLE | chip->option.led_blink_speed);
129#endif
130 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_DMA1_CTL, 121 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_DMA1_CTL,
131 EXTEND_DMA1_ASYNC_SIGNAL, EXTEND_DMA1_ASYNC_SIGNAL); 122 EXTEND_DMA1_ASYNC_SIGNAL, EXTEND_DMA1_ASYNC_SIGNAL);
132 123
@@ -144,7 +135,6 @@ int rts51x_reset_chip(struct rts51x_chip *chip)
144 card_power_on(chip, SD_CARD | MS_CARD | XD_CARD); 135 card_power_on(chip, SD_CARD | MS_CARD | XD_CARD);
145 wait_timeout(10); 136 wait_timeout(10);
146 } 137 }
147 rts51x_clear_start_time(chip);
148 138
149 return STATUS_SUCCESS; 139 return STATUS_SUCCESS;
150} 140}
@@ -164,12 +154,6 @@ int rts51x_init_chip(struct rts51x_chip *chip)
164 chip->card_ejected = 0; 154 chip->card_ejected = 0;
165 155
166 chip->lun2card[0] = XD_CARD | SD_CARD | MS_CARD; 156 chip->lun2card[0] = XD_CARD | SD_CARD | MS_CARD;
167#if 0
168 chip->option.sdr50_tx_phase = 0x01;
169 chip->option.sdr50_rx_phase = 0x05;
170 chip->option.ddr50_tx_phase = 0x09;
171 chip->option.ddr50_rx_phase = 0x06; /* add for debug */
172#endif
173#ifdef CLOSE_SSC_POWER 157#ifdef CLOSE_SSC_POWER
174 rts51x_write_register(chip, FPDCTL, SSC_POWER_MASK, SSC_POWER_ON); 158 rts51x_write_register(chip, FPDCTL, SSC_POWER_MASK, SSC_POWER_ON);
175 udelay(100); 159 udelay(100);
@@ -178,9 +162,6 @@ int rts51x_init_chip(struct rts51x_chip *chip)
178 RTS51X_SET_STAT(chip, STAT_RUN); 162 RTS51X_SET_STAT(chip, STAT_RUN);
179 163
180 RTS51X_READ_REG(chip, HW_VERSION, &val); 164 RTS51X_READ_REG(chip, HW_VERSION, &val);
181 if ((val & 0x0f) >= 2)
182 chip->option.rcc_bug_fix_en = 0;
183 RTS51X_DEBUGP("rcc bug fix enable:%d\n", chip->option.rcc_bug_fix_en);
184 RTS51X_DEBUGP("HW_VERSION: 0x%x\n", val); 165 RTS51X_DEBUGP("HW_VERSION: 0x%x\n", val);
185 if (val & FPGA_VER) { 166 if (val & FPGA_VER) {
186 chip->asic_code = 0; 167 chip->asic_code = 0;
@@ -237,7 +218,6 @@ int rts51x_release_chip(struct rts51x_chip *chip)
237 return STATUS_SUCCESS; 218 return STATUS_SUCCESS;
238} 219}
239 220
240#ifndef LED_AUTO_BLINK
241static inline void rts51x_blink_led(struct rts51x_chip *chip) 221static inline void rts51x_blink_led(struct rts51x_chip *chip)
242{ 222{
243 /* Read/Write */ 223 /* Read/Write */
@@ -251,20 +231,6 @@ static inline void rts51x_blink_led(struct rts51x_chip *chip)
251 } 231 }
252 } 232 }
253} 233}
254#endif
255
256int rts51x_check_start_time(struct rts51x_chip *chip)
257{
258 return 0;
259}
260
261void rts51x_set_start_time(struct rts51x_chip *chip)
262{
263}
264
265void rts51x_clear_start_time(struct rts51x_chip *chip)
266{
267}
268 234
269static void rts51x_auto_delink_cmd(struct rts51x_chip *chip) 235static void rts51x_auto_delink_cmd(struct rts51x_chip *chip)
270{ 236{
@@ -287,7 +253,6 @@ static void rts51x_auto_delink_polling_cycle(struct rts51x_chip *chip)
287 chip->option.delink_delay * 2) { 253 chip->option.delink_delay * 2) {
288 if (chip->auto_delink_counter == 254 if (chip->auto_delink_counter ==
289 chip->option.delink_delay) { 255 chip->option.delink_delay) {
290 clear_first_install_mark(chip);
291 if (chip->card_exist) { 256 if (chip->card_exist) {
292 /* False card */ 257 /* False card */
293 if (!chip->card_ejected) { 258 if (!chip->card_ejected) {
@@ -321,91 +286,13 @@ static void rts51x_auto_delink(struct rts51x_chip *chip)
321} 286}
322#else 287#else
323/* some of called funcs are not implemented, so comment it out */ 288/* some of called funcs are not implemented, so comment it out */
324#if 0
325/* using precise time as delink time */
326static void rts51x_auto_delink_precise_time(struct rts51x_chip *chip)
327{
328 int retvalue = 0;
329
330 retvalue = rts51x_get_card_status(chip, &chip->card_status);
331 /* get card CD status success and card CD not exist,
332 * then check whether delink */
333 if ((retvalue == STATUS_SUCCESS)
334 && (!(chip->card_status & (SD_CD | MS_CD | XD_CD)))) {
335 if (rts51x_count_delink_time(chip) >=
336 chip->option.delink_delay) {
337 clear_first_install_mark(chip);
338 RTS51X_DEBUGP("No card inserted, do delink\n");
339 /* sangdy2010-05-17:disable because there is error
340 * after SSC clock closed and card power
341 * has been closed before */
342 /* rts51x_write_register(chip, CARD_PWR_CTL,
343 DV3318_AUTO_PWR_OFF, 0); */
344 rts51x_auto_delink_cmd(chip);
345 }
346 /* card CD exist and not ready, then do force delink */
347 if ((retvalue == STATUS_SUCCESS)
348 && (chip->card_status & (SD_CD | MS_CD | XD_CD))) {
349 /* if card is not ejected or safely remove,
350 * then do force delink */
351 if (!chip->card_ejected) {
352 /* sangdy2010-11-16:polling at least 2 cycles
353 * then do force delink for card may force delink
354 * if card is extracted and insert quickly
355 * after ready. */
356 if (chip->auto_delink_counter > 1) {
357 if (rts51x_count_delink_time(chip) >
358 chip->option.delink_delay * 2) {
359 RTS51X_DEBUGP("Try to do force"
360 "delink\n");
361 rts51x_auto_delink_force_cmd(chip);
362 }
363 }
364 }
365 }
366 chip->auto_delink_counter++;
367}
368#else
369static void rts51x_auto_delink_precise_time(struct rts51x_chip *chip)
370{
371}
372#endif
373
374static void rts51x_auto_delink(struct rts51x_chip *chip) 289static void rts51x_auto_delink(struct rts51x_chip *chip)
375{ 290{
376 rts51x_auto_delink_precise_time(chip);
377} 291}
378#endif 292#endif
379 293
380void rts51x_polling_func(struct rts51x_chip *chip) 294void rts51x_polling_func(struct rts51x_chip *chip)
381{ 295{
382#ifdef SUPPORT_SD_LOCK
383 struct sd_info *sd_card = &(chip->sd_card);
384
385 if (sd_card->sd_erase_status) {
386 if (chip->card_exist & SD_CARD) {
387 u8 val;
388 rts51x_read_register(chip, SD_BUS_STAT, &val);
389 if (val & SD_DAT0_STATUS) {
390 /* Erase completed */
391 sd_card->sd_erase_status = SD_NOT_ERASE;
392 sd_card->sd_lock_notify = 1;
393
394 /* SD card should be reinited,
395 * so we release it here. */
396 sd_cleanup_work(chip);
397 release_sd_card(chip);
398 chip->card_ready &= ~SD_CARD;
399 chip->card_exist &= ~SD_CARD;
400 chip->rw_card[chip->card2lun[SD_CARD]] = NULL;
401 clear_bit(chip->card2lun[SD_CARD],
402 &(chip->lun_mc));
403 }
404 } else {
405 sd_card->sd_erase_status = SD_NOT_ERASE;
406 }
407 }
408#endif
409 296
410 rts51x_init_cards(chip); 297 rts51x_init_cards(chip);
411 298
@@ -431,9 +318,7 @@ void rts51x_polling_func(struct rts51x_chip *chip)
431 if (!RTS51X_CHK_STAT(chip, STAT_IDLE)) { 318 if (!RTS51X_CHK_STAT(chip, STAT_IDLE)) {
432 RTS51X_DEBUGP("Idle state!\n"); 319 RTS51X_DEBUGP("Idle state!\n");
433 RTS51X_SET_STAT(chip, STAT_IDLE); 320 RTS51X_SET_STAT(chip, STAT_IDLE);
434#ifndef LED_AUTO_BLINK
435 chip->led_toggle_counter = 0; 321 chip->led_toggle_counter = 0;
436#endif
437 /* Idle state, turn off LED 322 /* Idle state, turn off LED
438 * to reduce power consumption */ 323 * to reduce power consumption */
439 if (chip->option.led_always_on 324 if (chip->option.led_always_on
@@ -467,9 +352,7 @@ void rts51x_polling_func(struct rts51x_chip *chip)
467 352
468 switch (RTS51X_GET_STAT(chip)) { 353 switch (RTS51X_GET_STAT(chip)) {
469 case STAT_RUN: 354 case STAT_RUN:
470#ifndef LED_AUTO_BLINK
471 rts51x_blink_led(chip); 355 rts51x_blink_led(chip);
472#endif
473 do_remaining_work(chip); 356 do_remaining_work(chip);
474 break; 357 break;
475 358
@@ -484,7 +367,6 @@ void rts51x_polling_func(struct rts51x_chip *chip)
484 rts51x_auto_delink(chip); 367 rts51x_auto_delink(chip);
485 } else { 368 } else {
486 chip->auto_delink_counter = 0; 369 chip->auto_delink_counter = 0;
487 rts51x_clear_start_time(chip);
488 } 370 }
489} 371}
490 372
@@ -831,7 +713,7 @@ void rts51x_do_before_power_down(struct rts51x_chip *chip)
831 chip->cur_clk = 0; 713 chip->cur_clk = 0;
832 chip->card_exist = 0; 714 chip->card_exist = 0;
833 chip->cur_card = 0; 715 chip->cur_card = 0;
834 if (chip->asic_code && !chip->option.ww_enable) { 716 if (chip->asic_code) {
835 if (CHECK_PKG(chip, LQFP48)) { 717 if (CHECK_PKG(chip, LQFP48)) {
836 rts51x_write_register(chip, CARD_PULL_CTL3, 0x80, 0x00); 718 rts51x_write_register(chip, CARD_PULL_CTL3, 0x80, 0x00);
837 rts51x_write_register(chip, CARD_PULL_CTL6, 0xf0, 0x50); 719 rts51x_write_register(chip, CARD_PULL_CTL6, 0xf0, 0x50);
@@ -863,16 +745,6 @@ void rts51x_prepare_run(struct rts51x_chip *chip)
863 rts51x_write_register(chip, CLK_DIV, CLK_CHANGE, 0x00); 745 rts51x_write_register(chip, CLK_DIV, CLK_CHANGE, 0x00);
864 } 746 }
865#endif 747#endif
866#if 0
867 if (chip->option.ss_en && RTS51X_CHK_STAT(chip, STAT_SS)) {
868 rts51x_try_to_exit_ss(chip);
869 wait_timeout(100);
870 rts51x_init_chip(chip);
871 rts51x_init_cards(chip);
872 }
873
874 RTS51X_SET_STAT(chip, STAT_RUN);
875#endif
876} 748}
877 749
878#ifdef _MSG_TRACE 750#ifdef _MSG_TRACE
@@ -1017,24 +889,6 @@ void rts51x_pp_status(struct rts51x_chip *chip, unsigned int lun, u8 *status,
1017 status[0x0F] = 0x00; 889 status[0x0F] = 0x00;
1018 } 890 }
1019 } 891 }
1020#ifdef SUPPORT_SD_LOCK
1021 /* SD Lock/Unlock */
1022 if (card == SD_CARD) {
1023 status[0x17] = 0x80;
1024 if (sd_card->sd_erase_status)
1025 status[0x17] |= 0x01; /* Under erasing */
1026 if (sd_card->sd_lock_status & SD_LOCKED) {
1027 status[0x17] |= 0x02; /* Locked */
1028 status[0x07] |= 0x40; /* Read protected */
1029 }
1030 if (sd_card->sd_lock_status & SD_PWD_EXIST)
1031 status[0x17] |= 0x04; /* Contain PWD */
1032 } else {
1033 status[0x17] = 0x00;
1034 }
1035
1036 RTS51X_DEBUGP("status[0x17] = 0x%x\n", status[0x17]);
1037#endif
1038 892
1039 /* Function 0 893 /* Function 0
1040 * Support Magic Gate, CPRM and PhyRegister R/W */ 894 * Support Magic Gate, CPRM and PhyRegister R/W */
@@ -1044,12 +898,6 @@ void rts51x_pp_status(struct rts51x_chip *chip, unsigned int lun, u8 *status,
1044 * Support OC LUN status & WP LUN status */ 898 * Support OC LUN status & WP LUN status */
1045 status[0x1A] = 0x28; 899 status[0x1A] = 0x28;
1046 900
1047 /* Function 7 */
1048#ifdef SUPPORT_SD_LOCK
1049 /* Support SD Lock/Unlock */
1050 status[0x1F] = 0x01;
1051#endif
1052
1053 /* Function 2 901 /* Function 2
1054 * Support OC LUN status & WP LUN status */ 902 * Support OC LUN status & WP LUN status */
1055 status[0x1A] = 0x28; 903 status[0x1A] = 0x28;
diff --git a/drivers/staging/rts5139/rts51x_chip.h b/drivers/staging/rts5139/rts51x_chip.h
index 13fc2a410d90..6d395b6533a8 100644
--- a/drivers/staging/rts5139/rts51x_chip.h
+++ b/drivers/staging/rts5139/rts51x_chip.h
@@ -39,12 +39,7 @@
39#define SUPPORT_CPRM 39#define SUPPORT_CPRM
40#define SUPPORT_MAGIC_GATE 40#define SUPPORT_MAGIC_GATE
41#define SUPPORT_MSXC 41#define SUPPORT_MSXC
42/* #define LED_AUTO_BLINK */ 42#define USING_POLLING_CYCLE_DELINK
43
44/* { wwang, 2010-07-26
45 * Add support for SD lock/unlock */
46/* #define SUPPORT_SD_LOCK */
47/* } wwang, 2010-07-26 */
48 43
49#ifdef SUPPORT_MAGIC_GA 44#ifdef SUPPORT_MAGIC_GA
50/* Using NORMAL_WRITE instead of AUTO_WRITE to set ICVTE */ 45/* Using NORMAL_WRITE instead of AUTO_WRITE to set ICVTE */
@@ -63,7 +58,6 @@
63#define SUPPORT_OCP 58#define SUPPORT_OCP
64 59
65#define MS_SPEEDUP 60#define MS_SPEEDUP
66/* #define XD_SPEEDUP */
67 61
68#define SD_XD_IO_FOLLOW_PWR 62#define SD_XD_IO_FOLLOW_PWR
69 63
@@ -81,7 +75,6 @@
81 75
82#define MAX_ALLOWED_LUN_CNT 8 76#define MAX_ALLOWED_LUN_CNT 8
83#define CMD_BUF_LEN 1024 77#define CMD_BUF_LEN 1024
84#define RSP_BUF_LEN 1024
85#define POLLING_INTERVAL 50 /* 50ms */ 78#define POLLING_INTERVAL 50 /* 50ms */
86 79
87#define XD_FREE_TABLE_CNT 1200 80#define XD_FREE_TABLE_CNT 1200
@@ -128,8 +121,6 @@
128#endif 121#endif
129 122
130#define STATUS_FAIL 1 123#define STATUS_FAIL 1
131#define STATUS_READ_FAIL 2
132#define STATUS_WRITE_FAIL 3
133#define STATUS_TIMEDOUT 4 124#define STATUS_TIMEDOUT 4
134#define STATUS_NOMEM 5 125#define STATUS_NOMEM 5
135#define STATUS_TRANS_SHORT 6 126#define STATUS_TRANS_SHORT 6
@@ -139,8 +130,6 @@
139 130
140#define IDLE_MAX_COUNT 10 131#define IDLE_MAX_COUNT 10
141#define POLLING_WAIT_CNT 1 132#define POLLING_WAIT_CNT 1
142#define DELINK_DELAY 100
143#define LED_TOGGLE_INTERVAL 6
144#define LED_GPIO 0 133#define LED_GPIO 0
145 134
146/* package */ 135/* package */
@@ -157,8 +146,6 @@
157#define TRANSPORT_GOOD 0 146#define TRANSPORT_GOOD 0
158/* Transport good, command failed */ 147/* Transport good, command failed */
159#define TRANSPORT_FAILED 1 148#define TRANSPORT_FAILED 1
160/* Command failed, no auto-sense */
161#define TRANSPORT_NO_SENSE 2
162/* Transport bad (i.e. device dead) */ 149/* Transport bad (i.e. device dead) */
163#define TRANSPORT_ERROR 3 150#define TRANSPORT_ERROR 3
164 151
@@ -195,7 +182,6 @@ struct trace_msg_t {
195#define SENSE_TYPE_MEDIA_INVALID_CMD_FIELD 6 182#define SENSE_TYPE_MEDIA_INVALID_CMD_FIELD 6
196#define SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR 7 183#define SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR 7
197#define SENSE_TYPE_MEDIA_WRITE_ERR 8 184#define SENSE_TYPE_MEDIA_WRITE_ERR 8
198#define SENSE_TYPE_FORMAT_IN_PROGRESS 9
199#define SENSE_TYPE_FORMAT_CMD_FAILED 10 185#define SENSE_TYPE_FORMAT_CMD_FAILED 10
200#ifdef SUPPORT_MAGIC_GATE 186#ifdef SUPPORT_MAGIC_GATE
201/* COPY PROTECTION KEY EXCHANGE FAILURE - KEY NOT ESTABLISHED */ 187/* COPY PROTECTION KEY EXCHANGE FAILURE - KEY NOT ESTABLISHED */
@@ -207,83 +193,27 @@ struct trace_msg_t {
207/* WRITE ERROR */ 193/* WRITE ERROR */
208#define SENSE_TYPE_MG_WRITE_ERR 0x0e 194#define SENSE_TYPE_MG_WRITE_ERR 0x0e
209#endif 195#endif
210#ifdef SUPPORT_SD_LOCK
211/* FOR Locked SD card */
212#define SENSE_TYPE_MEDIA_READ_FORBIDDEN 0x10
213#endif
214 196
215/*---- sense key ----*/ 197/*---- sense key ----*/
216#define ILI 0x20 /* ILI bit is on */
217
218#define NO_SENSE 0x00 /* not exist sense key */
219#define RECOVER_ERR 0x01 /* Target/Logical unit is recoverd */
220#define NOT_READY 0x02 /* Logical unit is not ready */
221#define MEDIA_ERR 0x03 /* medium/data error */
222#define HARDWARE_ERR 0x04 /* hardware error */
223#define ILGAL_REQ 0x05 /* CDB/parameter/identify msg error */ 198#define ILGAL_REQ 0x05 /* CDB/parameter/identify msg error */
224#define UNIT_ATTENTION 0x06 /* unit attention condition occur */
225#define DAT_PRTCT 0x07 /* read/write is desable */
226#define BLNC_CHK 0x08 /* find blank/DOF in read */
227 /* write to unblank area */
228#define CPY_ABRT 0x0a /* Copy/Compare/Copy&Verify illgal */
229#define ABRT_CMD 0x0b /* Target make the command in error */
230#define EQUAL 0x0c /* Search Data end with Equal */
231#define VLM_OVRFLW 0x0d /* Some data are left in buffer */
232#define MISCMP 0x0e /* find inequality */
233 199
234/*----------------------------------- 200/*-----------------------------------
235 SENSE_DATA 201 SENSE_DATA
236-----------------------------------*/ 202-----------------------------------*/
237/*---- valid ----*/
238#define SENSE_VALID 0x80 /* Sense data is valid as SCSI2 */
239#define SENSE_INVALID 0x00 /* Sense data is invalid as SCSI2 */
240 203
241/*---- error code ----*/ 204/*---- error code ----*/
242#define CUR_ERR 0x70 /* current error */ 205#define CUR_ERR 0x70 /* current error */
243#define DEF_ERR 0x71 /* specific command error */
244 206
245/*---- sense key Infomation ----*/ 207/*---- sense key Infomation ----*/
246#define SNSKEYINFO_LEN 3 /* length of sense key infomation */
247 208
248#define SKSV 0x80 209#define SKSV 0x80
249#define CDB_ILLEGAL 0x40 210#define CDB_ILLEGAL 0x40
250#define DAT_ILLEGAL 0x00
251#define BPV 0x08
252#define BIT_ILLEGAL0 0 /* bit0 is illegal */
253#define BIT_ILLEGAL1 1 /* bit1 is illegal */
254#define BIT_ILLEGAL2 2 /* bit2 is illegal */
255#define BIT_ILLEGAL3 3 /* bit3 is illegal */
256#define BIT_ILLEGAL4 4 /* bit4 is illegal */
257#define BIT_ILLEGAL5 5 /* bit5 is illegal */
258#define BIT_ILLEGAL6 6 /* bit6 is illegal */
259#define BIT_ILLEGAL7 7 /* bit7 is illegal */
260 211
261/*---- ASC ----*/ 212/*---- ASC ----*/
262#define ASC_NO_INFO 0x00
263#define ASC_MISCMP 0x1d
264#define ASC_INVLD_CDB 0x24 213#define ASC_INVLD_CDB 0x24
265#define ASC_INVLD_PARA 0x26
266#define ASC_LU_NOT_READY 0x04
267#define ASC_WRITE_ERR 0x0c
268#define ASC_READ_ERR 0x11
269#define ASC_LOAD_EJCT_ERR 0x53
270#define ASC_MEDIA_NOT_PRESENT 0x3A
271#define ASC_MEDIA_CHANGED 0x28
272#define ASC_MEDIA_IN_PROCESS 0x04
273#define ASC_WRITE_PROTECT 0x27
274#define ASC_LUN_NOT_SUPPORTED 0x25
275 214
276/*---- ASQC ----*/ 215/*---- ASQC ----*/
277#define ASCQ_NO_INFO 0x00
278#define ASCQ_MEDIA_IN_PROCESS 0x01
279#define ASCQ_MISCMP 0x00
280#define ASCQ_INVLD_CDB 0x00 216#define ASCQ_INVLD_CDB 0x00
281#define ASCQ_INVLD_PARA 0x02
282#define ASCQ_LU_NOT_READY 0x02
283#define ASCQ_WRITE_ERR 0x02
284#define ASCQ_READ_ERR 0x00
285#define ASCQ_LOAD_EJCT_ERR 0x00
286#define ASCQ_WRITE_PROTECT 0x00
287 217
288struct sense_data_t { 218struct sense_data_t {
289 unsigned char err_code; /* error code */ 219 unsigned char err_code; /* error code */
@@ -296,13 +226,13 @@ struct sense_data_t {
296 unsigned char seg_no; /* segment No. */ 226 unsigned char seg_no; /* segment No. */
297 unsigned char sense_key; /* byte5 : ILI */ 227 unsigned char sense_key; /* byte5 : ILI */
298 /* bit3-0 : sense key */ 228 /* bit3-0 : sense key */
299 unsigned char info[4]; /* infomation */ 229 unsigned char info[4]; /* information */
300 unsigned char ad_sense_len; /* additional sense data length */ 230 unsigned char ad_sense_len; /* additional sense data length */
301 unsigned char cmd_info[4]; /* command specific infomation */ 231 unsigned char cmd_info[4]; /* command specific information */
302 unsigned char asc; /* ASC */ 232 unsigned char asc; /* ASC */
303 unsigned char ascq; /* ASCQ */ 233 unsigned char ascq; /* ASCQ */
304 unsigned char rfu; /* FRU */ 234 unsigned char rfu; /* FRU */
305 unsigned char sns_key_info[3]; /* sense key specific infomation */ 235 unsigned char sns_key_info[3]; /* sense key specific information */
306}; 236};
307 237
308/* sd_ctl bit map */ 238/* sd_ctl bit map */
@@ -323,8 +253,6 @@ struct sense_data_t {
323#define SUPPORT_UHS50_MMC44 0x40 253#define SUPPORT_UHS50_MMC44 0x40
324 254
325struct rts51x_option { 255struct rts51x_option {
326 u8 led_blink_speed;
327
328 int mspro_formatter_enable; 256 int mspro_formatter_enable;
329 257
330 /* card clock expected by user for fpga platform */ 258 /* card clock expected by user for fpga platform */
@@ -368,8 +296,6 @@ struct rts51x_option {
368 int ss_en; 296 int ss_en;
369 /* Interval to enter SS from IDLE state (second) */ 297 /* Interval to enter SS from IDLE state (second) */
370 int ss_delay; 298 int ss_delay;
371 int needs_remote_wakeup;
372 u8 ww_enable; /* sangdy2010-08-03:add for remote wakeup */
373 299
374 /* Enable SSC clock */ 300 /* Enable SSC clock */
375 int ssc_en; 301 int ssc_en;
@@ -392,10 +318,7 @@ struct rts51x_option {
392 /*if reset or rw fail,then set SD20 pad drive again */ 318 /*if reset or rw fail,then set SD20 pad drive again */
393 u8 reset_or_rw_fail_set_pad_drive; 319 u8 reset_or_rw_fail_set_pad_drive;
394 320
395 u8 rcc_fail_flag; /* add to indicate whether rcc bug happen */
396 u8 rcc_bug_fix_en; /* if set,then support fixing rcc bug */
397 u8 debounce_num; /* debounce number */ 321 u8 debounce_num; /* debounce number */
398 int polling_time; /* polling delay time */
399 u8 led_toggle_interval; /* used to control led toggle speed */ 322 u8 led_toggle_interval; /* used to control led toggle speed */
400 int xd_rwn_step; 323 int xd_rwn_step;
401 u8 sd_send_status_en; 324 u8 sd_send_status_en;
@@ -405,7 +328,7 @@ struct rts51x_option {
405 u8 ddr50_rx_phase; 328 u8 ddr50_rx_phase;
406 u8 sdr50_tx_phase; 329 u8 sdr50_tx_phase;
407 u8 sdr50_rx_phase; 330 u8 sdr50_rx_phase;
408 /* used to enable select sdr50 tx phase according to proportion. */ 331 /* used to enable select sdr50 tx phase according to proportion. */
409 u8 sdr50_phase_sel; 332 u8 sdr50_phase_sel;
410 u8 ms_errreg_fix; 333 u8 ms_errreg_fix;
411 u8 reset_mmc_first; 334 u8 reset_mmc_first;
@@ -614,11 +537,6 @@ struct sd_info {
614 u8 sd_reset_fail; /* sangdy2010-07-01 */ 537 u8 sd_reset_fail; /* sangdy2010-07-01 */
615 u8 sd_send_status_en; 538 u8 sd_send_status_en;
616 539
617#ifdef SUPPORT_SD_LOCK
618 u8 sd_lock_status;
619 u8 sd_erase_status;
620 u8 sd_lock_notify;
621#endif
622}; 540};
623 541
624#define MODE_512_SEQ 0x01 542#define MODE_512_SEQ 0x01
@@ -720,9 +638,8 @@ struct rts51x_chip {
720 struct scsi_cmnd *srb; 638 struct scsi_cmnd *srb;
721 struct sense_data_t sense_buffer[MAX_ALLOWED_LUN_CNT]; 639 struct sense_data_t sense_buffer[MAX_ALLOWED_LUN_CNT];
722 640
723#ifndef LED_AUTO_BLINK
724 int led_toggle_counter; 641 int led_toggle_counter;
725#endif 642
726 int ss_counter; 643 int ss_counter;
727 int idle_counter; 644 int idle_counter;
728 int auto_delink_counter; 645 int auto_delink_counter;
diff --git a/drivers/staging/rts5139/rts51x_fop.c b/drivers/staging/rts5139/rts51x_fop.c
index 6eaebb6223c9..ef893c8cdec6 100644
--- a/drivers/staging/rts5139/rts51x_fop.c
+++ b/drivers/staging/rts5139/rts51x_fop.c
@@ -234,12 +234,7 @@ ssize_t rts51x_write(struct file *filp, const char __user *buf, size_t count,
234 return 0; 234 return 0;
235} 235}
236 236
237#if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) */
238int rts51x_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
239 unsigned long arg)
240#else
241long rts51x_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 237long rts51x_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
242#endif
243{ 238{
244 struct rts51x_chip *chip; 239 struct rts51x_chip *chip;
245 struct sd_direct_cmnd cmnd; 240 struct sd_direct_cmnd cmnd;
diff --git a/drivers/staging/rts5139/rts51x_fop.h b/drivers/staging/rts5139/rts51x_fop.h
index 94d75f08d255..eb45acf50d1a 100644
--- a/drivers/staging/rts5139/rts51x_fop.h
+++ b/drivers/staging/rts5139/rts51x_fop.h
@@ -50,12 +50,7 @@ ssize_t rts51x_read(struct file *filp, char __user *buf, size_t count,
50 loff_t *f_pos); 50 loff_t *f_pos);
51ssize_t rts51x_write(struct file *filp, const char __user *buf, size_t count, 51ssize_t rts51x_write(struct file *filp, const char __user *buf, size_t count,
52 loff_t *f_pos); 52 loff_t *f_pos);
53#if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) */
54int rts51x_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
55 unsigned long arg);
56#else
57long rts51x_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 53long rts51x_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
58#endif
59 54
60#endif 55#endif
61 56
diff --git a/drivers/staging/rts5139/rts51x_scsi.c b/drivers/staging/rts5139/rts51x_scsi.c
index 87c9cdc8bd29..e07a1f4f58cf 100644
--- a/drivers/staging/rts5139/rts51x_scsi.c
+++ b/drivers/staging/rts5139/rts51x_scsi.c
@@ -40,7 +40,6 @@
40#include "rts51x_scsi.h" 40#include "rts51x_scsi.h"
41#include "rts51x_card.h" 41#include "rts51x_card.h"
42#include "rts51x_transport.h" 42#include "rts51x_transport.h"
43#include "rts51x_sys.h"
44#include "sd_cprm.h" 43#include "sd_cprm.h"
45#include "ms_mg.h" 44#include "ms_mg.h"
46#include "trace.h" 45#include "trace.h"
@@ -370,10 +369,6 @@ void set_sense_type(struct rts51x_chip *chip, unsigned int lun, int sense_type)
370 ASC_INVLD_CDB, ASCQ_INVLD_CDB, CDB_ILLEGAL, 1); 369 ASC_INVLD_CDB, ASCQ_INVLD_CDB, CDB_ILLEGAL, 1);
371 break; 370 break;
372 371
373 case SENSE_TYPE_FORMAT_IN_PROGRESS:
374 set_sense_data(chip, lun, CUR_ERR, 0x02, 0, 0x04, 0x04, 0, 0);
375 break;
376
377 case SENSE_TYPE_FORMAT_CMD_FAILED: 372 case SENSE_TYPE_FORMAT_CMD_FAILED:
378 set_sense_data(chip, lun, CUR_ERR, 0x03, 0, 0x31, 0x01, 0, 0); 373 set_sense_data(chip, lun, CUR_ERR, 0x03, 0, 0x31, 0x01, 0, 0);
379 break; 374 break;
@@ -396,12 +391,6 @@ void set_sense_type(struct rts51x_chip *chip, unsigned int lun, int sense_type)
396 break; 391 break;
397#endif 392#endif
398 393
399#ifdef SUPPORT_SD_LOCK
400 case SENSE_TYPE_MEDIA_READ_FORBIDDEN:
401 set_sense_data(chip, lun, CUR_ERR, 0x07, 0, 0x11, 0x13, 0, 0);
402 break;
403#endif
404
405 case SENSE_TYPE_NO_SENSE: 394 case SENSE_TYPE_NO_SENSE:
406 default: 395 default:
407 set_sense_data(chip, lun, CUR_ERR, 0, 0, 0, 0, 0, 0); 396 set_sense_data(chip, lun, CUR_ERR, 0, 0, 0, 0, 0, 0);
@@ -448,20 +437,6 @@ static int test_unit_ready(struct scsi_cmnd *srb, struct rts51x_chip *chip)
448 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); 437 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
449 return TRANSPORT_FAILED; 438 return TRANSPORT_FAILED;
450 } 439 }
451#ifdef SUPPORT_SD_LOCK
452 if (get_lun_card(chip, SCSI_LUN(srb)) == SD_CARD) {
453 struct sd_info *sd_card = &(chip->sd_card);
454 if (sd_card->sd_lock_notify) {
455 sd_card->sd_lock_notify = 0;
456 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
457 return TRANSPORT_FAILED;
458 } else if (sd_card->sd_lock_status & SD_LOCKED) {
459 set_sense_type(chip, lun,
460 SENSE_TYPE_MEDIA_READ_FORBIDDEN);
461 return TRANSPORT_FAILED;
462 }
463 }
464#endif
465 440
466 return TRANSPORT_GOOD; 441 return TRANSPORT_GOOD;
467} 442}
@@ -797,9 +772,6 @@ static int request_sense(struct scsi_cmnd *srb, struct rts51x_chip *chip)
797 772
798static int read_write(struct scsi_cmnd *srb, struct rts51x_chip *chip) 773static int read_write(struct scsi_cmnd *srb, struct rts51x_chip *chip)
799{ 774{
800#ifdef SUPPORT_SD_LOCK
801 struct sd_info *sd_card = &(chip->sd_card);
802#endif
803 unsigned int lun = SCSI_LUN(srb); 775 unsigned int lun = SCSI_LUN(srb);
804 int retval; 776 int retval;
805 u32 start_sec; 777 u32 start_sec;
@@ -819,25 +791,6 @@ static int read_write(struct scsi_cmnd *srb, struct rts51x_chip *chip)
819 rts51x_prepare_run(chip); 791 rts51x_prepare_run(chip);
820 RTS51X_SET_STAT(chip, STAT_RUN); 792 RTS51X_SET_STAT(chip, STAT_RUN);
821 793
822#ifdef SUPPORT_SD_LOCK
823 if (sd_card->sd_erase_status) {
824 /* Accessing to any card is forbidden
825 * until the erase procedure of SD is completed */
826 RTS51X_DEBUGP("SD card being erased!\n");
827 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_READ_FORBIDDEN);
828 TRACE_RET(chip, TRANSPORT_FAILED);
829 }
830
831 if (get_lun_card(chip, lun) == SD_CARD) {
832 if (sd_card->sd_lock_status & SD_LOCKED) {
833 RTS51X_DEBUGP("SD card locked!\n");
834 set_sense_type(chip, lun,
835 SENSE_TYPE_MEDIA_READ_FORBIDDEN);
836 TRACE_RET(chip, TRANSPORT_FAILED);
837 }
838 }
839#endif
840
841 if ((srb->cmnd[0] == READ_10) || (srb->cmnd[0] == WRITE_10)) { 794 if ((srb->cmnd[0] == READ_10) || (srb->cmnd[0] == WRITE_10)) {
842 start_sec = 795 start_sec =
843 ((u32) srb->cmnd[2] << 24) | 796 ((u32) srb->cmnd[2] << 24) |
@@ -883,20 +836,12 @@ static int read_write(struct scsi_cmnd *srb, struct rts51x_chip *chip)
883 836
884 retval = card_rw(srb, chip, start_sec, sec_cnt); 837 retval = card_rw(srb, chip, start_sec, sec_cnt);
885 if (retval != STATUS_SUCCESS) { 838 if (retval != STATUS_SUCCESS) {
886#if 0
887 if (chip->need_release & chip->lun2card[lun]) {
888 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
889 } else {
890#endif
891 if (srb->sc_data_direction == DMA_FROM_DEVICE) { 839 if (srb->sc_data_direction == DMA_FROM_DEVICE) {
892 set_sense_type(chip, lun, 840 set_sense_type(chip, lun,
893 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); 841 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
894 } else { 842 } else {
895 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); 843 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR);
896 } 844 }
897#if 0
898 }
899#endif
900 TRACE_RET(chip, TRANSPORT_FAILED); 845 TRACE_RET(chip, TRANSPORT_FAILED);
901 } 846 }
902 847
@@ -1516,7 +1461,7 @@ static int ms_format_cmnd(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1516} 1461}
1517 1462
1518#ifdef SUPPORT_PCGL_1P18 1463#ifdef SUPPORT_PCGL_1P18
1519int get_ms_information(struct scsi_cmnd *srb, struct rts51x_chip *chip) 1464static int get_ms_information(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1520{ 1465{
1521 struct ms_info *ms_card = &(chip->ms_card); 1466 struct ms_info *ms_card = &(chip->ms_card);
1522 unsigned int lun = SCSI_LUN(srb); 1467 unsigned int lun = SCSI_LUN(srb);
@@ -1677,7 +1622,7 @@ static int sd_extention_cmnd(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1677#endif 1622#endif
1678 1623
1679#ifdef SUPPORT_MAGIC_GATE 1624#ifdef SUPPORT_MAGIC_GATE
1680int mg_report_key(struct scsi_cmnd *srb, struct rts51x_chip *chip) 1625static int mg_report_key(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1681{ 1626{
1682 struct ms_info *ms_card = &(chip->ms_card); 1627 struct ms_info *ms_card = &(chip->ms_card);
1683 unsigned int lun = SCSI_LUN(srb); 1628 unsigned int lun = SCSI_LUN(srb);
@@ -1764,7 +1709,7 @@ int mg_report_key(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1764 return TRANSPORT_GOOD; 1709 return TRANSPORT_GOOD;
1765} 1710}
1766 1711
1767int mg_send_key(struct scsi_cmnd *srb, struct rts51x_chip *chip) 1712static int mg_send_key(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1768{ 1713{
1769 struct ms_info *ms_card = &(chip->ms_card); 1714 struct ms_info *ms_card = &(chip->ms_card);
1770 unsigned int lun = SCSI_LUN(srb); 1715 unsigned int lun = SCSI_LUN(srb);
@@ -1871,30 +1816,10 @@ int mg_send_key(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1871 1816
1872int rts51x_scsi_handler(struct scsi_cmnd *srb, struct rts51x_chip *chip) 1817int rts51x_scsi_handler(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1873{ 1818{
1874#ifdef SUPPORT_SD_LOCK
1875 struct sd_info *sd_card = &(chip->sd_card);
1876#endif
1877 struct ms_info *ms_card = &(chip->ms_card); 1819 struct ms_info *ms_card = &(chip->ms_card);
1878 unsigned int lun = SCSI_LUN(srb); 1820 unsigned int lun = SCSI_LUN(srb);
1879 int result = TRANSPORT_GOOD; 1821 int result = TRANSPORT_GOOD;
1880 1822
1881#ifdef SUPPORT_SD_LOCK
1882 if (sd_card->sd_erase_status) {
1883 /* Block all SCSI command except for REQUEST_SENSE
1884 * and rs_ppstatus */
1885 if (!
1886 ((srb->cmnd[0] == VENDOR_CMND)
1887 && (srb->cmnd[1] == SCSI_APP_CMD)
1888 && (srb->cmnd[2] == GET_DEV_STATUS))
1889 && (srb->cmnd[0] != REQUEST_SENSE)) {
1890 /* Logical Unit Not Ready Format in Progress */
1891 set_sense_data(chip, lun, CUR_ERR, 0x02, 0, 0x04, 0x04,
1892 0, 0);
1893 TRACE_RET(chip, TRANSPORT_FAILED);
1894 }
1895 }
1896#endif
1897
1898 if ((get_lun_card(chip, lun) == MS_CARD) && 1823 if ((get_lun_card(chip, lun) == MS_CARD) &&
1899 (ms_card->format_status == FORMAT_IN_PROGRESS)) { 1824 (ms_card->format_status == FORMAT_IN_PROGRESS)) {
1900 if ((srb->cmnd[0] != REQUEST_SENSE) 1825 if ((srb->cmnd[0] != REQUEST_SENSE)
@@ -1994,11 +1919,6 @@ int rts51x_scsi_handler(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1994 * Host functions 1919 * Host functions
1995 ***********************************************************************/ 1920 ***********************************************************************/
1996 1921
1997const char *host_info(struct Scsi_Host *host)
1998{
1999 return "SCSI emulation for RTS51xx USB driver-based card reader";
2000}
2001
2002int slave_alloc(struct scsi_device *sdev) 1922int slave_alloc(struct scsi_device *sdev)
2003{ 1923{
2004 /* 1924 /*
@@ -2111,14 +2031,7 @@ int queuecommand_lck(struct scsi_cmnd *srb, void (*done) (struct scsi_cmnd *))
2111 return 0; 2031 return 0;
2112} 2032}
2113 2033
2114#if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) */
2115int queuecommand(struct scsi_cmnd *srb, void (*done) (struct scsi_cmnd *))
2116{
2117 return queuecommand_lck(srb, done);
2118}
2119#else
2120DEF_SCSI_QCMD(queuecommand) 2034DEF_SCSI_QCMD(queuecommand)
2121#endif
2122/*********************************************************************** 2035/***********************************************************************
2123 * Error handling functions 2036 * Error handling functions
2124 ***********************************************************************/ 2037 ***********************************************************************/
diff --git a/drivers/staging/rts5139/rts51x_scsi.h b/drivers/staging/rts5139/rts51x_scsi.h
index 3a8ca069b278..060d2c2e77ec 100644
--- a/drivers/staging/rts5139/rts51x_scsi.h
+++ b/drivers/staging/rts5139/rts51x_scsi.h
@@ -145,16 +145,11 @@ struct Scsi_Host;
145struct scsi_device; 145struct scsi_device;
146struct scsi_cmnd; 146struct scsi_cmnd;
147 147
148const char *host_info(struct Scsi_Host *host);
149int slave_alloc(struct scsi_device *sdev); 148int slave_alloc(struct scsi_device *sdev);
150int slave_configure(struct scsi_device *sdev); 149int slave_configure(struct scsi_device *sdev);
151int proc_info(struct Scsi_Host *host, char *buffer, 150int proc_info(struct Scsi_Host *host, char *buffer,
152 char **start, off_t offset, int length, int inout); 151 char **start, off_t offset, int length, int inout);
153#if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) */
154int queuecommand(struct scsi_cmnd *srb, void (*done) (struct scsi_cmnd *));
155#else
156int queuecommand(struct Scsi_Host *, struct scsi_cmnd *); 152int queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
157#endif
158int command_abort(struct scsi_cmnd *srb); 153int command_abort(struct scsi_cmnd *srb);
159int device_reset(struct scsi_cmnd *srb); 154int device_reset(struct scsi_cmnd *srb);
160int bus_reset(struct scsi_cmnd *srb); 155int bus_reset(struct scsi_cmnd *srb);
diff --git a/drivers/staging/rts5139/rts51x_sys.h b/drivers/staging/rts5139/rts51x_sys.h
deleted file mode 100644
index b09cd34a6c02..000000000000
--- a/drivers/staging/rts5139/rts51x_sys.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/* Driver for Realtek USB RTS51xx card reader
2 * Header file
3 *
4 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author:
20 * wwang (wei_wang@realsil.com.cn)
21 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
22 * Maintainer:
23 * Edwin Rong (edwin_rong@realsil.com.cn)
24 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
25 */
26
27#ifndef __RTS51X_SYS_H
28#define __RTS51X_SYS_H
29
30#include "rts51x.h"
31#include "rts51x_chip.h"
32#include "rts51x_card.h"
33
34#define USING_POLLING_CYCLE_DELINK
35
36extern int rts51x_check_start_time(struct rts51x_chip *chip);
37extern void rts51x_set_start_time(struct rts51x_chip *chip);
38extern void rts51x_clear_start_time(struct rts51x_chip *chip);
39
40/* typedef dma_addr_t ULONG_PTR; */
41
42static inline void rts51x_reset_detected_cards(struct rts51x_chip *chip)
43{
44/* rts51x_reset_cards(chip); */
45}
46
47static inline void clear_first_install_mark(struct rts51x_chip *chip)
48{
49}
50
51void rts51x_enter_ss(struct rts51x_chip *chip);
52void rts51x_exit_ss(struct rts51x_chip *chip);
53
54#endif /* __RTS51X_SYS_H */
diff --git a/drivers/staging/rts5139/rts51x_transport.c b/drivers/staging/rts5139/rts51x_transport.c
index da9c83b49426..89e4d805a345 100644
--- a/drivers/staging/rts5139/rts51x_transport.c
+++ b/drivers/staging/rts5139/rts51x_transport.c
@@ -120,7 +120,7 @@ unsigned int rts51x_access_sglist(unsigned char *buffer,
120 return cnt; 120 return cnt;
121} 121}
122 122
123unsigned int rts51x_access_xfer_buf(unsigned char *buffer, 123static unsigned int rts51x_access_xfer_buf(unsigned char *buffer,
124 unsigned int buflen, struct scsi_cmnd *srb, 124 unsigned int buflen, struct scsi_cmnd *srb,
125 struct scatterlist **sgptr, 125 struct scatterlist **sgptr,
126 unsigned int *offset, enum xfer_buf_dir dir) 126 unsigned int *offset, enum xfer_buf_dir dir)
@@ -252,6 +252,8 @@ static int rts51x_msg_common(struct rts51x_chip *chip, struct urb *urb,
252 return status; 252 return status;
253} 253}
254 254
255static int rts51x_clear_halt(struct rts51x_chip *chip, unsigned int pipe);
256
255/* 257/*
256 * Interpret the results of a URB transfer 258 * Interpret the results of a URB transfer
257 */ 259 */
@@ -359,7 +361,7 @@ int rts51x_ctrl_transfer(struct rts51x_chip *chip, unsigned int pipe,
359 rts51x->current_urb->actual_length); 361 rts51x->current_urb->actual_length);
360} 362}
361 363
362int rts51x_clear_halt(struct rts51x_chip *chip, unsigned int pipe) 364static int rts51x_clear_halt(struct rts51x_chip *chip, unsigned int pipe)
363{ 365{
364 int result; 366 int result;
365 int endp = usb_pipeendpoint(pipe); 367 int endp = usb_pipeendpoint(pipe);
@@ -378,11 +380,6 @@ int rts51x_clear_halt(struct rts51x_chip *chip, unsigned int pipe)
378 return STATUS_SUCCESS; 380 return STATUS_SUCCESS;
379} 381}
380 382
381int rts51x_reset_pipe(struct rts51x_chip *chip, char pipe)
382{
383 return rts51x_clear_halt(chip, pipe);
384}
385
386static void rts51x_sg_clean(struct usb_sg_request *io) 383static void rts51x_sg_clean(struct usb_sg_request *io)
387{ 384{
388 if (io->urbs) { 385 if (io->urbs) {
@@ -391,226 +388,17 @@ static void rts51x_sg_clean(struct usb_sg_request *io)
391 kfree(io->urbs); 388 kfree(io->urbs);
392 io->urbs = NULL; 389 io->urbs = NULL;
393 } 390 }
394#if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) */
395 if (io->dev->dev.dma_mask != NULL)
396 usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe),
397 io->sg, io->nents);
398#endif
399 io->dev = NULL; 391 io->dev = NULL;
400} 392}
401#if 0
402static void rts51x_sg_complete(struct urb *urb)
403{
404 struct usb_sg_request *io = urb->context;
405 int status = urb->status;
406
407 spin_lock(&io->lock);
408
409 /* In 2.5 we require hcds' endpoint queues not to progress after fault
410 * reports, until the completion callback (this!) returns. That lets
411 * device driver code (like this routine) unlink queued urbs first,
412 * if it needs to, since the HC won't work on them at all. So it's
413 * not possible for page N+1 to overwrite page N, and so on.
414 *
415 * That's only for "hard" faults; "soft" faults (unlinks) sometimes
416 * complete before the HCD can get requests away from hardware,
417 * though never during cleanup after a hard fault.
418 */
419 if (io->status
420 && (io->status != -ECONNRESET
421 || status != -ECONNRESET)
422 && urb->actual_length) {
423 dev_err(io->dev->bus->controller,
424 "dev %s ep%d%s scatterlist error %d/%d\n",
425 io->dev->devpath,
426 usb_endpoint_num(&urb->ep->desc),
427 usb_urb_dir_in(urb) ? "in" : "out",
428 status, io->status);
429 /* BUG (); */
430 }
431
432 if (io->status == 0 && status && status != -ECONNRESET) {
433 int i, found, retval;
434
435 io->status = status;
436
437 /* the previous urbs, and this one, completed already.
438 * unlink pending urbs so they won't rx/tx bad data.
439 * careful: unlink can sometimes be synchronous...
440 */
441 spin_unlock(&io->lock);
442 for (i = 0, found = 0; i < io->entries; i++) {
443 if (!io->urbs[i] || !io->urbs[i]->dev)
444 continue;
445 if (found) {
446 retval = usb_unlink_urb(io->urbs[i]);
447 if (retval != -EINPROGRESS &&
448 retval != -ENODEV &&
449 retval != -EBUSY)
450 dev_err(&io->dev->dev,
451 "%s, unlink --> %d\n",
452 __func__, retval);
453 } else if (urb == io->urbs[i])
454 found = 1;
455 }
456 spin_lock(&io->lock);
457 }
458 urb->dev = NULL;
459
460 /* on the last completion, signal usb_sg_wait() */
461 io->bytes += urb->actual_length;
462 io->count--;
463 if (!io->count)
464 complete(&io->complete);
465
466 spin_unlock(&io->lock);
467}
468
469/* This function is ported from usb_sg_init, which can transfer
470 * sg list partially */
471int rts51x_sg_init_partial(struct usb_sg_request *io, struct usb_device *dev,
472 unsigned pipe, unsigned period, void *buf, struct scatterlist **sgptr,
473 unsigned int *offset, int nents, size_t length, gfp_t mem_flags)
474{
475 int i;
476 int urb_flags;
477 int dma;
478 struct scatterlist *sg = *sgptr, *first_sg;
479
480 first_sg = (struct scatterlist *)buf;
481 if (!sg)
482 sg = first_sg;
483
484 if (!io || !dev || !sg
485 || usb_pipecontrol(pipe)
486 || usb_pipeisoc(pipe)
487 || (nents <= 0))
488 return -EINVAL;
489
490 spin_lock_init(&io->lock);
491 io->dev = dev;
492 io->pipe = pipe;
493 io->sg = first_sg; /* used by unmap */
494 io->nents = nents;
495
496 RTS51X_DEBUGP("Before map, sg address: 0x%x\n", (unsigned int)sg);
497 RTS51X_DEBUGP("Before map, dev address: 0x%x\n", (unsigned int)dev);
498
499 /* not all host controllers use DMA (like the mainstream pci ones);
500 * they can use PIO (sl811) or be software over another transport.
501 */
502 dma = (dev->dev.dma_mask != NULL);
503 if (dma) {
504 /* map the whole sg list, because here we only know the
505 * total nents */
506 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe),
507 first_sg, nents);
508 } else {
509 io->entries = nents;
510 }
511
512 /* initialize all the urbs we'll use */
513 if (io->entries <= 0)
514 return io->entries;
515
516 io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
517 if (!io->urbs)
518 goto nomem;
519
520 urb_flags = URB_NO_INTERRUPT;
521 if (dma)
522 urb_flags |= URB_NO_TRANSFER_DMA_MAP;
523 if (usb_pipein(pipe))
524 urb_flags |= URB_SHORT_NOT_OK;
525
526 RTS51X_DEBUGP("io->entries = %d\n", io->entries);
527
528 for (i = 0; (sg != NULL) && (length > 0); i++) {
529 unsigned len;
530
531 RTS51X_DEBUGP("sg address: 0x%x\n", (unsigned int)sg);
532 RTS51X_DEBUGP("length = %d, *offset = %d\n", length, *offset);
533
534 io->urbs[i] = usb_alloc_urb(0, mem_flags);
535 if (!io->urbs[i]) {
536 io->entries = i;
537 goto nomem;
538 }
539
540 io->urbs[i]->dev = NULL;
541 io->urbs[i]->pipe = pipe;
542 io->urbs[i]->interval = period;
543 io->urbs[i]->transfer_flags = urb_flags;
544
545 io->urbs[i]->complete = rts51x_sg_complete;
546 io->urbs[i]->context = io;
547
548 if (dma) {
549 io->urbs[i]->transfer_dma =
550 sg_dma_address(sg) + *offset;
551 len = sg_dma_len(sg) - *offset;
552 io->urbs[i]->transfer_buffer = NULL;
553 RTS51X_DEBUGP(" -- sg entry dma length = %d\n",
554 sg_dma_len(sg));
555 } else {
556 /* hc may use _only_ transfer_buffer */
557 io->urbs[i]->transfer_buffer = sg_virt(sg) + *offset;
558 len = sg->length - *offset;
559 RTS51X_DEBUGP(" -- sg entry length = %d\n",
560 sg->length);
561 }
562
563 if (length >= len) {
564 *offset = 0;
565 io->urbs[i]->transfer_buffer_length = len;
566 length -= len;
567 sg = sg_next(sg);
568 } else {
569 *offset += length;
570 io->urbs[i]->transfer_buffer_length = length;
571 length = 0;
572 }
573 if (length == 0)
574 io->entries = i + 1;
575#if 0
576 if (length) {
577 len = min_t(unsigned, len, length);
578 length -= len;
579 if (length == 0) {
580 io->entries = i + 1;
581 *offset += len;
582 } else {
583 *offset = 0;
584 }
585 }
586#endif
587 }
588 RTS51X_DEBUGP("In %s, urb count: %d\n", __func__, i);
589 io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
590
591 RTS51X_DEBUGP("sg address stored in sgptr: 0x%x\n", (unsigned int)sg);
592 *sgptr = sg;
593
594 /* transaction state */
595 io->count = io->entries;
596 io->status = 0;
597 io->bytes = 0;
598 init_completion(&io->complete);
599 return 0;
600 393
601nomem: 394static int rts51x_sg_init(struct usb_sg_request *io, struct usb_device *dev,
602 rts51x_sg_clean(io);
603 return -ENOMEM;
604}
605#endif
606int rts51x_sg_init(struct usb_sg_request *io, struct usb_device *dev,
607 unsigned pipe, unsigned period, struct scatterlist *sg, 395 unsigned pipe, unsigned period, struct scatterlist *sg,
608 int nents, size_t length, gfp_t mem_flags) 396 int nents, size_t length, gfp_t mem_flags)
609{ 397{
610 return usb_sg_init(io, dev, pipe, period, sg, nents, length, mem_flags); 398 return usb_sg_init(io, dev, pipe, period, sg, nents, length, mem_flags);
611} 399}
612 400
613int rts51x_sg_wait(struct usb_sg_request *io, int timeout) 401static int rts51x_sg_wait(struct usb_sg_request *io, int timeout)
614{ 402{
615 long timeleft; 403 long timeleft;
616 int i; 404 int i;
@@ -630,7 +418,7 @@ int rts51x_sg_wait(struct usb_sg_request *io, int timeout)
630 */ 418 */
631 spin_unlock_irq(&io->lock); 419 spin_unlock_irq(&io->lock);
632 switch (retval) { 420 switch (retval) {
633 /* maybe we retrying will recover */ 421 /* maybe the retry will recover */
634 case -ENXIO: /* hc didn't queue this one */ 422 case -ENXIO: /* hc didn't queue this one */
635 case -EAGAIN: 423 case -EAGAIN:
636 case -ENOMEM: 424 case -ENOMEM:
@@ -740,56 +528,9 @@ static int rts51x_bulk_transfer_sglist(struct rts51x_chip *chip,
740 return interpret_urb_result(chip, pipe, length, result, 528 return interpret_urb_result(chip, pipe, length, result,
741 chip->usb->current_sg.bytes); 529 chip->usb->current_sg.bytes);
742} 530}
743#if 0
744static int rts51x_bulk_transfer_sglist_partial(struct rts51x_chip *chip,
745 unsigned int pipe, void *buf, struct scatterlist **sgptr,
746 unsigned int *offset, int num_sg, unsigned int length,
747 unsigned int *act_len, int timeout)
748{
749 int result;
750
751 /* don't submit s-g requests during abort processing */
752 if (test_bit(FLIDX_ABORTING, &chip->usb->dflags))
753 TRACE_RET(chip, STATUS_ERROR);
754 531
755 /* initialize the scatter-gather request block */ 532static int rts51x_bulk_transfer_buf(struct rts51x_chip *chip,
756 RTS51X_DEBUGP("%s: xfer %u bytes, %d entries\n", __func__, 533 unsigned int pipe,
757 length, num_sg);
758 result = rts51x_sg_init_partial(&chip->usb->current_sg,
759 chip->usb->pusb_dev, pipe, 0, buf, sgptr, offset,
760 num_sg, length, GFP_NOIO);
761 if (result) {
762 RTS51X_DEBUGP("rts51x_sg_init_partial returned %d\n", result);
763 TRACE_RET(chip, STATUS_ERROR);
764 }
765
766 /* since the block has been initialized successfully, it's now
767 * okay to cancel it */
768 set_bit(FLIDX_SG_ACTIVE, &chip->usb->dflags);
769
770 /* did an abort occur during the submission? */
771 if (test_bit(FLIDX_ABORTING, &chip->usb->dflags)) {
772
773 /* cancel the request, if it hasn't been cancelled already */
774 if (test_and_clear_bit(FLIDX_SG_ACTIVE, &chip->usb->dflags)) {
775 RTS51X_DEBUGP("-- cancelling sg request\n");
776 usb_sg_cancel(&chip->usb->current_sg);
777 }
778 }
779
780 /* wait for the completion of the transfer */
781 result = rts51x_sg_wait(&chip->usb->current_sg, timeout);
782
783 clear_bit(FLIDX_SG_ACTIVE, &chip->usb->dflags);
784
785 /* result = us->current_sg.status; */
786 if (act_len)
787 *act_len = chip->usb->current_sg.bytes;
788 return interpret_urb_result(chip, pipe, length, result,
789 chip->usb->current_sg.bytes);
790}
791#endif
792int rts51x_bulk_transfer_buf(struct rts51x_chip *chip, unsigned int pipe,
793 void *buf, unsigned int length, 534 void *buf, unsigned int length,
794 unsigned int *act_len, int timeout) 535 unsigned int *act_len, int timeout)
795{ 536{
@@ -860,11 +601,6 @@ int rts51x_transfer_data_partial(struct rts51x_chip *chip, unsigned int pipe,
860 } 601 }
861 602
862 kfree(tmp_buf); 603 kfree(tmp_buf);
863#if 0
864 result = rts51x_bulk_transfer_sglist_partial(chip, pipe, buf,
865 (struct scatterlist **)ptr, offset,
866 use_sg, len, act_len, timeout);
867#endif
868 } else { 604 } else {
869 unsigned int step = 0; 605 unsigned int step = 0;
870 if (offset) 606 if (offset)
diff --git a/drivers/staging/rts5139/rts51x_transport.h b/drivers/staging/rts5139/rts51x_transport.h
index 9dd556ea9c08..024f115540a6 100644
--- a/drivers/staging/rts5139/rts51x_transport.h
+++ b/drivers/staging/rts5139/rts51x_transport.h
@@ -40,11 +40,6 @@ unsigned int rts51x_access_sglist(unsigned char *buffer,
40 unsigned int buflen, void *sglist, 40 unsigned int buflen, void *sglist,
41 void **sgptr, unsigned int *offset, 41 void **sgptr, unsigned int *offset,
42 enum xfer_buf_dir dir); 42 enum xfer_buf_dir dir);
43unsigned int rts51x_access_xfer_buf(unsigned char *buffer, unsigned int buflen,
44 struct scsi_cmnd *srb,
45 struct scatterlist **sgptr,
46 unsigned int *offset,
47 enum xfer_buf_dir dir);
48void rts51x_set_xfer_buf(unsigned char *buffer, unsigned int buflen, 43void rts51x_set_xfer_buf(unsigned char *buffer, unsigned int buflen,
49 struct scsi_cmnd *srb); 44 struct scsi_cmnd *srb);
50void rts51x_get_xfer_buf(unsigned char *buffer, unsigned int buflen, 45void rts51x_get_xfer_buf(unsigned char *buffer, unsigned int buflen,
@@ -53,7 +48,6 @@ void rts51x_get_xfer_buf(unsigned char *buffer, unsigned int buflen,
53int rts51x_ctrl_transfer(struct rts51x_chip *chip, unsigned int pipe, 48int rts51x_ctrl_transfer(struct rts51x_chip *chip, unsigned int pipe,
54 u8 request, u8 requesttype, u16 value, u16 index, 49 u8 request, u8 requesttype, u16 value, u16 index,
55 void *data, u16 size, int timeout); 50 void *data, u16 size, int timeout);
56int rts51x_clear_halt(struct rts51x_chip *chip, unsigned int pipe);
57int rts51x_transfer_data(struct rts51x_chip *chip, unsigned int pipe, 51int rts51x_transfer_data(struct rts51x_chip *chip, unsigned int pipe,
58 void *buf, unsigned int len, int use_sg, 52 void *buf, unsigned int len, int use_sg,
59 unsigned int *act_len, int timeout); 53 unsigned int *act_len, int timeout);
@@ -62,12 +56,6 @@ int rts51x_transfer_data_partial(struct rts51x_chip *chip, unsigned int pipe,
62 unsigned int len, int use_sg, 56 unsigned int len, int use_sg,
63 unsigned int *act_len, int timeout); 57 unsigned int *act_len, int timeout);
64 58
65/* whichPipe:
66 * 0: bulk in pipe
67 * 1: bulk out pipe
68 * 2: intr in pipe */
69int rts51x_reset_pipe(struct rts51x_chip *chip, char pipe);
70
71#ifndef POLLING_IN_THREAD 59#ifndef POLLING_IN_THREAD
72int rts51x_start_epc_transfer(struct rts51x_chip *chip); 60int rts51x_start_epc_transfer(struct rts51x_chip *chip);
73void rts51x_cancel_epc_transfer(struct rts51x_chip *chip); 61void rts51x_cancel_epc_transfer(struct rts51x_chip *chip);
diff --git a/drivers/staging/rts5139/sd.c b/drivers/staging/rts5139/sd.c
index d5dd2f926d1d..b739f26f78cc 100644
--- a/drivers/staging/rts5139/sd.c
+++ b/drivers/staging/rts5139/sd.c
@@ -246,12 +246,7 @@ RTY_SEND_CMD:
246 if (buf[1] & 0x80) 246 if (buf[1] & 0x80)
247 TRACE_RET(chip, STATUS_FAIL); 247 TRACE_RET(chip, STATUS_FAIL);
248 } 248 }
249#ifdef SUPPORT_SD_LOCK
250 /* exclude bit25 CARD_IS_LOCKED */
251 if (buf[1] & 0x7D) {
252#else
253 if (buf[1] & 0x7F) { 249 if (buf[1] & 0x7F) {
254#endif
255 RTS51X_DEBUGP("buf[1]: 0x%02x\n", buf[1]); 250 RTS51X_DEBUGP("buf[1]: 0x%02x\n", buf[1]);
256 TRACE_RET(chip, STATUS_FAIL); 251 TRACE_RET(chip, STATUS_FAIL);
257 } 252 }
@@ -709,37 +704,7 @@ int sd_select_card(struct rts51x_chip *chip, int select)
709 return STATUS_SUCCESS; 704 return STATUS_SUCCESS;
710} 705}
711 706
712#ifdef SUPPORT_SD_LOCK 707static int sd_wait_currentstate_dataready(struct rts51x_chip *chip, u8 statechk,
713int sd_update_lock_status(struct rts51x_chip *chip)
714{
715 struct sd_info *sd_card = &(chip->sd_card);
716 int retval;
717 u8 rsp[5];
718
719 retval =
720 sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
721 SD_RSP_TYPE_R1, rsp, 5);
722 if (retval != STATUS_SUCCESS)
723 TRACE_RET(chip, STATUS_FAIL);
724
725 if (rsp[1] & 0x02)
726 sd_card->sd_lock_status |= SD_LOCKED;
727 else
728 sd_card->sd_lock_status &= ~SD_LOCKED;
729
730 RTS51X_DEBUGP("sd_card->sd_lock_status = 0x%x\n",
731 sd_card->sd_lock_status);
732
733 if (rsp[1] & 0x01) {
734 /* LOCK_UNLOCK_FAILED */
735 TRACE_RET(chip, STATUS_FAIL);
736 }
737
738 return STATUS_SUCCESS;
739}
740#endif
741
742int sd_wait_currentstate_dataready(struct rts51x_chip *chip, u8 statechk,
743 u8 rdychk, u16 pollingcnt) 708 u8 rdychk, u16 pollingcnt)
744{ 709{
745 struct sd_info *sd_card = &(chip->sd_card); 710 struct sd_info *sd_card = &(chip->sd_card);
@@ -1197,15 +1162,6 @@ static int sd_switch_function(struct rts51x_chip *chip, u8 bus_width)
1197 RTS51X_DEBUGP("SD_FUNC_GROUP_1: func_to_switch = 0x%02x", 1162 RTS51X_DEBUGP("SD_FUNC_GROUP_1: func_to_switch = 0x%02x",
1198 func_to_switch); 1163 func_to_switch);
1199 1164
1200#ifdef SUPPORT_SD_LOCK
1201 if ((sd_card->sd_lock_status & SD_SDR_RST)
1202 && (DDR50_SUPPORT == func_to_switch)
1203 && (sd_card->func_group1_mask & SDR50_SUPPORT_MASK)) {
1204 func_to_switch = SDR50_SUPPORT;
1205 RTS51X_DEBUGP("Using SDR50 instead of DDR50 for SD Lock\n");
1206 }
1207#endif
1208
1209 if (func_to_switch) { 1165 if (func_to_switch) {
1210 retval = 1166 retval =
1211 sd_check_switch(chip, SD_FUNC_GROUP_1, func_to_switch, 1167 sd_check_switch(chip, SD_FUNC_GROUP_1, func_to_switch,
@@ -1562,7 +1518,7 @@ static u8 sd_search_final_phase(struct rts51x_chip *chip, u32 phase_map,
1562 } 1518 }
1563 1519
1564Search_Finish: 1520Search_Finish:
1565 RTS51X_DEBUGP("Final choosen phase: %d\n", final_phase); 1521 RTS51X_DEBUGP("Final chosen phase: %d\n", final_phase);
1566 return final_phase; 1522 return final_phase;
1567} 1523}
1568 1524
@@ -2024,10 +1980,6 @@ Switch_Fail:
2024 k = 0; 1980 k = 0;
2025 hi_cap_flow = 0; 1981 hi_cap_flow = 0;
2026 support_1v8 = 0; 1982 support_1v8 = 0;
2027#ifdef SUPPORT_SD_LOCK
2028 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON)
2029 goto SD_UNLOCK_ENTRY;
2030#endif
2031 1983
2032 retval = sd_prepare_reset(chip); 1984 retval = sd_prepare_reset(chip);
2033 if (retval != STATUS_SUCCESS) 1985 if (retval != STATUS_SUCCESS)
@@ -2182,7 +2134,7 @@ RTY_CMD55:
2182 sd_card->sd_addr += (u32) rsp[2] << 16; 2134 sd_card->sd_addr += (u32) rsp[2] << 16;
2183 2135
2184 /* Get CSD register for Calculating Timing,Capacity, 2136 /* Get CSD register for Calculating Timing,Capacity,
2185 * Check CSD to determaine as if this is the SD ROM card */ 2137 * Check CSD to determine as if this is the SD ROM card */
2186 retval = sd_check_csd(chip, 1); 2138 retval = sd_check_csd(chip, 1);
2187 if (retval != STATUS_SUCCESS) 2139 if (retval != STATUS_SUCCESS)
2188 TRACE_RET(chip, retval); 2140 TRACE_RET(chip, retval);
@@ -2190,20 +2142,6 @@ RTY_CMD55:
2190 retval = sd_select_card(chip, 1); 2142 retval = sd_select_card(chip, 1);
2191 if (retval != STATUS_SUCCESS) 2143 if (retval != STATUS_SUCCESS)
2192 TRACE_RET(chip, retval); 2144 TRACE_RET(chip, retval);
2193#ifdef SUPPORT_SD_LOCK
2194SD_UNLOCK_ENTRY:
2195 /* Get SD lock status */
2196 retval = sd_update_lock_status(chip);
2197 if (retval != STATUS_SUCCESS)
2198 TRACE_RET(chip, STATUS_FAIL);
2199
2200 if (sd_card->sd_lock_status & SD_LOCKED) {
2201 sd_card->sd_lock_status |= (SD_LOCK_1BIT_MODE | SD_PWD_EXIST);
2202 return STATUS_SUCCESS;
2203 } else if (!(sd_card->sd_lock_status & SD_UNLOCK_POW_ON)) {
2204 sd_card->sd_lock_status &= ~SD_PWD_EXIST;
2205 }
2206#endif
2207 2145
2208 /* ACMD42 */ 2146 /* ACMD42 */
2209 retval = 2147 retval =
@@ -2294,10 +2232,6 @@ SD_UNLOCK_ENTRY:
2294 if (retval != STATUS_SUCCESS) 2232 if (retval != STATUS_SUCCESS)
2295 TRACE_RET(chip, retval); 2233 TRACE_RET(chip, retval);
2296 } 2234 }
2297#ifdef SUPPORT_SD_LOCK
2298 /* clear 1 bit mode status */
2299 sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE;
2300#endif
2301 2235
2302 if (CHK_SD30_SPEED(sd_card)) { 2236 if (CHK_SD30_SPEED(sd_card)) {
2303 rts51x_write_register(chip, SD30_DRIVE_SEL, SD30_DRIVE_MASK, 2237 rts51x_write_register(chip, SD30_DRIVE_SEL, SD30_DRIVE_MASK,
@@ -2380,19 +2314,6 @@ SD_UNLOCK_ENTRY:
2380 2314
2381 chip->card_bus_width[chip->card2lun[SD_CARD]] = 4; 2315 chip->card_bus_width[chip->card2lun[SD_CARD]] = 4;
2382 2316
2383#ifdef SUPPORT_SD_LOCK
2384 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) {
2385 rts51x_init_cmd(chip);
2386
2387 rts51x_add_cmd(chip, WRITE_REG_CMD, SD_BLOCK_CNT_H, 0xFF, 0x02);
2388 rts51x_add_cmd(chip, WRITE_REG_CMD, SD_BLOCK_CNT_L, 0xFF, 0x00);
2389
2390 retval = rts51x_send_cmd(chip, MODE_C, 100);
2391 if (retval != STATUS_SUCCESS)
2392 TRACE_RET(chip, retval);
2393 }
2394#endif
2395
2396 return STATUS_SUCCESS; 2317 return STATUS_SUCCESS;
2397} 2318}
2398 2319
@@ -2587,17 +2508,10 @@ static int mmc_switch_timing_bus(struct rts51x_chip *chip)
2587 sd_card->capacity = 2508 sd_card->capacity =
2588 ((u32) buf[5] << 24) | ((u32) buf[4] << 16) | 2509 ((u32) buf[5] << 24) | ((u32) buf[4] << 16) |
2589 ((u32) buf[3] << 8) | ((u32) buf[2]); 2510 ((u32) buf[3] << 8) | ((u32) buf[2]);
2590#ifdef SUPPORT_SD_LOCK
2591 if (!(sd_card->sd_lock_status & SD_SDR_RST) && CHECK_UHS50(chip))
2592 card_type_mask = 0x07;
2593 else
2594 card_type_mask = 0x03;
2595#else
2596 if (CHECK_UHS50(chip)) 2511 if (CHECK_UHS50(chip))
2597 card_type_mask = 0x07; 2512 card_type_mask = 0x07;
2598 else 2513 else
2599 card_type_mask = 0x03; 2514 card_type_mask = 0x03;
2600#endif
2601 2515
2602 card_type = buf[1] & card_type_mask; 2516 card_type = buf[1] & card_type_mask;
2603 if (card_type) { 2517 if (card_type) {
@@ -2626,15 +2540,9 @@ static int mmc_switch_timing_bus(struct rts51x_chip *chip)
2626 if (mmc_test_switch_bus(chip, MMC_8BIT_BUS) == STATUS_SUCCESS) { 2540 if (mmc_test_switch_bus(chip, MMC_8BIT_BUS) == STATUS_SUCCESS) {
2627 SET_MMC_8BIT(sd_card); 2541 SET_MMC_8BIT(sd_card);
2628 chip->card_bus_width[chip->card2lun[SD_CARD]] = 8; 2542 chip->card_bus_width[chip->card2lun[SD_CARD]] = 8;
2629#ifdef SUPPORT_SD_LOCK
2630 sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE;
2631#endif
2632 } else if (mmc_test_switch_bus(chip, MMC_4BIT_BUS) == STATUS_SUCCESS) { 2543 } else if (mmc_test_switch_bus(chip, MMC_4BIT_BUS) == STATUS_SUCCESS) {
2633 SET_MMC_4BIT(sd_card); 2544 SET_MMC_4BIT(sd_card);
2634 chip->card_bus_width[chip->card2lun[SD_CARD]] = 4; 2545 chip->card_bus_width[chip->card2lun[SD_CARD]] = 4;
2635#ifdef SUPPORT_SD_LOCK
2636 sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE;
2637#endif
2638 } else { 2546 } else {
2639 CLR_MMC_8BIT(sd_card); 2547 CLR_MMC_8BIT(sd_card);
2640 CLR_MMC_4BIT(sd_card); 2548 CLR_MMC_4BIT(sd_card);
@@ -2652,11 +2560,6 @@ static int reset_mmc(struct rts51x_chip *chip)
2652 u8 change_to_ddr52 = 1; 2560 u8 change_to_ddr52 = 1;
2653 u8 cmd[5]; 2561 u8 cmd[5];
2654 2562
2655#ifdef SUPPORT_SD_LOCK
2656 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON)
2657 goto MMC_UNLOCK_ENTRY;
2658#endif
2659
2660MMC_DDR_FAIL: 2563MMC_DDR_FAIL:
2661 2564
2662 retval = sd_prepare_reset(chip); 2565 retval = sd_prepare_reset(chip);
@@ -2745,7 +2648,7 @@ RTY_MMC_RST:
2745 TRACE_RET(chip, retval); 2648 TRACE_RET(chip, retval);
2746 2649
2747 /* Get CSD register for Calculating Timing,Capacity 2650 /* Get CSD register for Calculating Timing,Capacity
2748 * Check CSD to determaine as if this is the SD ROM card */ 2651 * Check CSD to determine as if this is the SD ROM card */
2749 retval = sd_check_csd(chip, 1); 2652 retval = sd_check_csd(chip, 1);
2750 if (retval != STATUS_SUCCESS) 2653 if (retval != STATUS_SUCCESS)
2751 TRACE_RET(chip, retval); 2654 TRACE_RET(chip, retval);
@@ -2763,13 +2666,6 @@ RTY_MMC_RST:
2763 0); 2666 0);
2764 if (retval != STATUS_SUCCESS) 2667 if (retval != STATUS_SUCCESS)
2765 TRACE_RET(chip, retval); 2668 TRACE_RET(chip, retval);
2766#ifdef SUPPORT_SD_LOCK
2767MMC_UNLOCK_ENTRY:
2768 /* Get SD lock status */
2769 retval = sd_update_lock_status(chip);
2770 if (retval != STATUS_SUCCESS)
2771 TRACE_RET(chip, STATUS_FAIL);
2772#endif
2773 2669
2774 RTS51X_WRITE_REG(chip, SD_CFG1, SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); 2670 RTS51X_WRITE_REG(chip, SD_CFG1, SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0);
2775 2671
@@ -2842,18 +2738,6 @@ MMC_UNLOCK_ENTRY:
2842 } 2738 }
2843 } 2739 }
2844 } 2740 }
2845#ifdef SUPPORT_SD_LOCK
2846 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) {
2847 rts51x_init_cmd(chip);
2848
2849 rts51x_add_cmd(chip, WRITE_REG_CMD, SD_BLOCK_CNT_H, 0xFF, 0x02);
2850 rts51x_add_cmd(chip, WRITE_REG_CMD, SD_BLOCK_CNT_L, 0xFF, 0x00);
2851
2852 retval = rts51x_send_cmd(chip, MODE_C, 100);
2853 if (retval != STATUS_SUCCESS)
2854 TRACE_RET(chip, retval);
2855 }
2856#endif
2857 2741
2858 retval = rts51x_get_card_status(chip, &(chip->card_status)); 2742 retval = rts51x_get_card_status(chip, &(chip->card_status));
2859 if (retval != STATUS_SUCCESS) 2743 if (retval != STATUS_SUCCESS)
@@ -2879,11 +2763,6 @@ int reset_sd_card(struct rts51x_chip *chip)
2879 sd_card->capacity = 0; 2763 sd_card->capacity = 0;
2880 sd_card->sd_switch_fail = 0; 2764 sd_card->sd_switch_fail = 0;
2881 2765
2882#ifdef SUPPORT_SD_LOCK
2883 sd_card->sd_lock_status = 0;
2884 sd_card->sd_erase_status = 0;
2885#endif
2886
2887 sd_clear_reset_fail(chip); 2766 sd_clear_reset_fail(chip);
2888 enable_card_clock(chip, SD_CARD); 2767 enable_card_clock(chip, SD_CARD);
2889 2768
@@ -3006,7 +2885,7 @@ static int wait_data_buf_ready(struct rts51x_chip *chip)
3006 TRACE_RET(chip, STATUS_FAIL); 2885 TRACE_RET(chip, STATUS_FAIL);
3007} 2886}
3008 2887
3009void sd_stop_seq_mode(struct rts51x_chip *chip) 2888static void sd_stop_seq_mode(struct rts51x_chip *chip)
3010{ 2889{
3011 struct sd_info *sd_card = &(chip->sd_card); 2890 struct sd_info *sd_card = &(chip->sd_card);
3012 int retval; 2891 int retval;
@@ -3300,7 +3179,7 @@ void sd_cleanup_work(struct rts51x_chip *chip)
3300 } 3179 }
3301} 3180}
3302 3181
3303inline void sd_fill_power_off_card3v3(struct rts51x_chip *chip) 3182static inline void sd_fill_power_off_card3v3(struct rts51x_chip *chip)
3304{ 3183{
3305 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_CLK_EN, SD_CLK_EN, 0); 3184 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_CLK_EN, SD_CLK_EN, 0);
3306 3185
@@ -3322,7 +3201,7 @@ inline void sd_fill_power_off_card3v3(struct rts51x_chip *chip)
3322 } 3201 }
3323} 3202}
3324 3203
3325int sd_power_off_card3v3(struct rts51x_chip *chip) 3204static int sd_power_off_card3v3(struct rts51x_chip *chip)
3326{ 3205{
3327 int retval; 3206 int retval;
3328 3207
@@ -3346,17 +3225,12 @@ int release_sd_card(struct rts51x_chip *chip)
3346 struct sd_info *sd_card = &(chip->sd_card); 3225 struct sd_info *sd_card = &(chip->sd_card);
3347 int retval; 3226 int retval;
3348 3227
3349 RTS51X_DEBUGP("elease_sd_card\n"); 3228 RTS51X_DEBUGP("release_sd_card\n");
3350 3229
3351 chip->card_ready &= ~SD_CARD; 3230 chip->card_ready &= ~SD_CARD;
3352 chip->card_fail &= ~SD_CARD; 3231 chip->card_fail &= ~SD_CARD;
3353 chip->card_wp &= ~SD_CARD; 3232 chip->card_wp &= ~SD_CARD;
3354 3233
3355#ifdef SUPPORT_SD_LOCK
3356 sd_card->sd_lock_status = 0;
3357 sd_card->sd_erase_status = 0;
3358#endif
3359
3360 memset(sd_card->raw_csd, 0, 16); 3234 memset(sd_card->raw_csd, 0, 16);
3361 memset(sd_card->raw_scr, 0, 8); 3235 memset(sd_card->raw_scr, 0, 8);
3362 3236
diff --git a/drivers/staging/rts5139/sd.h b/drivers/staging/rts5139/sd.h
index 0805edcaea86..de155d8e682d 100644
--- a/drivers/staging/rts5139/sd.h
+++ b/drivers/staging/rts5139/sd.h
@@ -141,29 +141,6 @@
141#define SWITCH_MODE_ERR 0x06 141#define SWITCH_MODE_ERR 0x06
142#define SWITCH_PASS 0x07 142#define SWITCH_PASS 0x07
143 143
144#ifdef SUPPORT_SD_LOCK
145/* CMD42 Parameter */
146#define SD_ERASE 0x08
147#define SD_LOCK 0x04
148#define SD_UNLOCK 0x00
149#define SD_CLR_PWD 0x02
150#define SD_SET_PWD 0x01
151
152#define SD_PWD_LEN 0x10
153
154/* SD lock unlock Status */
155#define SD_LOCKED 0x80 /* Global lock status */
156#define SD_LOCK_1BIT_MODE 0x40 /**/
157#define SD_PWD_EXIST 0x20
158#define SD_UNLOCK_POW_ON 0x01 /**/
159#define SD_SDR_RST 0x02 /* Reset SD30 card with current DDR mode to SDR mode. */
160/* g_bySDEraseStatus */
161#define SD_NOT_ERASE 0x00
162#define SD_UNDER_ERASING 0x01
163#define SD_COMPLETE_ERASE 0x02
164/* SD_RW FAIL status */
165#define SD_RW_FORBIDDEN 0x0F /* read/write is forbidden (SD card) */
166#endif
167/* Function Group Definition */ 144/* Function Group Definition */
168/* Function Group 1 */ 145/* Function Group 1 */
169#define HS_SUPPORT 0x01 146#define HS_SUPPORT 0x01
@@ -282,17 +259,11 @@ struct timing_phase_path {
282int sd_select_card(struct rts51x_chip *chip, int select); 259int sd_select_card(struct rts51x_chip *chip, int select);
283int reset_sd_card(struct rts51x_chip *chip); 260int reset_sd_card(struct rts51x_chip *chip);
284int sd_switch_clock(struct rts51x_chip *chip); 261int sd_switch_clock(struct rts51x_chip *chip);
285void sd_stop_seq_mode(struct rts51x_chip *chip);
286int sd_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector, 262int sd_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector,
287 u16 sector_cnt); 263 u16 sector_cnt);
288void sd_cleanup_work(struct rts51x_chip *chip); 264void sd_cleanup_work(struct rts51x_chip *chip);
289int sd_power_off_card3v3(struct rts51x_chip *chip);
290int release_sd_card(struct rts51x_chip *chip); 265int release_sd_card(struct rts51x_chip *chip);
291 266
292#ifdef SUPPORT_SD_LOCK
293int sd_update_lock_status(struct rts51x_chip *chip);
294#endif
295
296#ifdef SUPPORT_CPRM 267#ifdef SUPPORT_CPRM
297extern int reset_sd(struct rts51x_chip *chip); 268extern int reset_sd(struct rts51x_chip *chip);
298extern int sd_check_data0_status(struct rts51x_chip *chip); 269extern int sd_check_data0_status(struct rts51x_chip *chip);
diff --git a/drivers/staging/rts5139/sd_cprm.c b/drivers/staging/rts5139/sd_cprm.c
index d5969d992d84..f8c60711f710 100644
--- a/drivers/staging/rts5139/sd_cprm.c
+++ b/drivers/staging/rts5139/sd_cprm.c
@@ -77,12 +77,7 @@ static inline int get_rsp_type(u8 rsp_code, u8 *rsp_type, int *rsp_len)
77 return STATUS_SUCCESS; 77 return STATUS_SUCCESS;
78} 78}
79 79
80int soft_reset_sd_card(struct rts51x_chip *chip) 80static int ext_sd_send_cmd_get_rsp(struct rts51x_chip *chip, u8 cmd_idx,
81{
82 return reset_sd(chip);
83}
84
85int ext_sd_send_cmd_get_rsp(struct rts51x_chip *chip, u8 cmd_idx,
86 u32 arg, u8 rsp_type, u8 *rsp, int rsp_len, 81 u32 arg, u8 rsp_type, u8 *rsp, int rsp_len,
87 int special_check) 82 int special_check)
88{ 83{
@@ -206,11 +201,7 @@ RTY_SEND_CMD:
206 if (buf[1] & 0x80) 201 if (buf[1] & 0x80)
207 TRACE_RET(chip, STATUS_FAIL); 202 TRACE_RET(chip, STATUS_FAIL);
208 } 203 }
209#ifdef SUPPORT_SD_LOCK
210 if (buf[1] & 0x7D) {
211#else
212 if (buf[1] & 0x7F) { 204 if (buf[1] & 0x7F) {
213#endif
214 TRACE_RET(chip, STATUS_FAIL); 205 TRACE_RET(chip, STATUS_FAIL);
215 } 206 }
216 if (buf[2] & 0xF8) 207 if (buf[2] & 0xF8)
@@ -233,7 +224,7 @@ RTY_SEND_CMD:
233 return STATUS_SUCCESS; 224 return STATUS_SUCCESS;
234} 225}
235 226
236int ext_sd_get_rsp(struct rts51x_chip *chip, int len, u8 *rsp, u8 rsp_type) 227static int ext_sd_get_rsp(struct rts51x_chip *chip, int len, u8 *rsp, u8 rsp_type)
237{ 228{
238 int retval, rsp_len; 229 int retval, rsp_len;
239 u16 reg_addr; 230 u16 reg_addr;
@@ -305,26 +296,8 @@ int ext_sd_execute_no_data(struct rts51x_chip *chip, unsigned int lun,
305 retval = sd_switch_clock(chip); 296 retval = sd_switch_clock(chip);
306 if (retval != STATUS_SUCCESS) 297 if (retval != STATUS_SUCCESS)
307 TRACE_RET(chip, TRANSPORT_FAILED); 298 TRACE_RET(chip, TRANSPORT_FAILED);
308#ifdef SUPPORT_SD_LOCK
309 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
310 if (CHK_MMC_8BIT(sd_card)) {
311 retval =
312 rts51x_write_register(chip, SD_CFG1, 0x03,
313 SD_BUS_WIDTH_8);
314 if (retval != STATUS_SUCCESS)
315 TRACE_RET(chip, TRANSPORT_FAILED);
316 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) {
317 retval =
318 rts51x_write_register(chip, SD_CFG1, 0x03,
319 SD_BUS_WIDTH_4);
320 if (retval != STATUS_SUCCESS)
321 TRACE_RET(chip, TRANSPORT_FAILED);
322 }
323 }
324#else
325 /* Set H/W SD/MMC Bus Width */ 299 /* Set H/W SD/MMC Bus Width */
326 rts51x_write_register(chip, SD_CFG1, 0x03, SD_BUS_WIDTH_4); 300 rts51x_write_register(chip, SD_CFG1, 0x03, SD_BUS_WIDTH_4);
327#endif
328 301
329 if (standby) { 302 if (standby) {
330 retval = sd_select_card(chip, 0); 303 retval = sd_select_card(chip, 0);
@@ -350,12 +323,6 @@ int ext_sd_execute_no_data(struct rts51x_chip *chip, unsigned int lun,
350 if (retval != STATUS_SUCCESS) 323 if (retval != STATUS_SUCCESS)
351 TRACE_GOTO(chip, SD_Execute_Cmd_Failed); 324 TRACE_GOTO(chip, SD_Execute_Cmd_Failed);
352 } 325 }
353#ifdef SUPPORT_SD_LOCK
354 /* Get SD lock status */
355 retval = sd_update_lock_status(chip);
356 if (retval != STATUS_SUCCESS)
357 TRACE_GOTO(chip, SD_Execute_Cmd_Failed);
358#endif
359 326
360 return TRANSPORT_GOOD; 327 return TRANSPORT_GOOD;
361 328
@@ -399,21 +366,7 @@ int ext_sd_execute_read_data(struct rts51x_chip *chip, unsigned int lun,
399 retval = sd_switch_clock(chip); 366 retval = sd_switch_clock(chip);
400 if (retval != STATUS_SUCCESS) 367 if (retval != STATUS_SUCCESS)
401 TRACE_RET(chip, TRANSPORT_FAILED); 368 TRACE_RET(chip, TRANSPORT_FAILED);
402#ifdef SUPPORT_SD_LOCK
403 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
404 if (CHK_MMC_8BIT(sd_card))
405 bus_width = SD_BUS_WIDTH_8;
406 else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card))
407 bus_width = SD_BUS_WIDTH_4;
408 else
409 bus_width = SD_BUS_WIDTH_1;
410 } else {
411 bus_width = SD_BUS_WIDTH_4;
412 }
413 RTS51X_DEBUGP("bus_width = %d\n", bus_width);
414#else
415 bus_width = SD_BUS_WIDTH_4; 369 bus_width = SD_BUS_WIDTH_4;
416#endif
417 370
418 if (data_len < 512) { 371 if (data_len < 512) {
419 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, 372 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len,
@@ -599,11 +552,6 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
599 int cmd13_checkbit = 0, write_err = 0; 552 int cmd13_checkbit = 0, write_err = 0;
600 u8 rsp_type; 553 u8 rsp_type;
601 u32 i; 554 u32 i;
602#ifdef SUPPORT_SD_LOCK
603 int lock_cmd_fail = 0;
604 u8 sd_lock_state = 0;
605 u8 lock_cmd_type = 0;
606#endif
607 555
608 if (sd_card->pre_cmd_err) { 556 if (sd_card->pre_cmd_err) {
609 sd_card->pre_cmd_err = 0; 557 sd_card->pre_cmd_err = 0;
@@ -614,12 +562,6 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
614 retval = sd_switch_clock(chip); 562 retval = sd_switch_clock(chip);
615 if (retval != STATUS_SUCCESS) 563 if (retval != STATUS_SUCCESS)
616 TRACE_RET(chip, STATUS_FAIL); 564 TRACE_RET(chip, STATUS_FAIL);
617#ifdef SUPPORT_SD_LOCK
618 if (cmd_idx == LOCK_UNLOCK) {
619 sd_lock_state = sd_card->sd_lock_status;
620 sd_lock_state &= SD_LOCKED;
621 }
622#endif
623 565
624 retval = get_rsp_type(rsp_code, &rsp_type, &rsp_len); 566 retval = get_rsp_type(rsp_code, &rsp_type, &rsp_len);
625 if (retval != STATUS_SUCCESS) { 567 if (retval != STATUS_SUCCESS) {
@@ -631,25 +573,7 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
631 retval = sd_switch_clock(chip); 573 retval = sd_switch_clock(chip);
632 if (retval != STATUS_SUCCESS) 574 if (retval != STATUS_SUCCESS)
633 TRACE_RET(chip, TRANSPORT_FAILED); 575 TRACE_RET(chip, TRANSPORT_FAILED);
634#ifdef SUPPORT_SD_LOCK
635 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
636 if (CHK_MMC_8BIT(sd_card)) {
637 retval =
638 rts51x_write_register(chip, SD_CFG1, 0x03,
639 SD_BUS_WIDTH_8);
640 if (retval != STATUS_SUCCESS)
641 TRACE_RET(chip, TRANSPORT_FAILED);
642 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) {
643 retval =
644 rts51x_write_register(chip, SD_CFG1, 0x03,
645 SD_BUS_WIDTH_4);
646 if (retval != STATUS_SUCCESS)
647 TRACE_RET(chip, TRANSPORT_FAILED);
648 }
649 }
650#else
651 rts51x_write_register(chip, SD_CFG1, 0x03, SD_BUS_WIDTH_4); 576 rts51x_write_register(chip, SD_CFG1, 0x03, SD_BUS_WIDTH_4);
652#endif
653 577
654 if (data_len < 512) { 578 if (data_len < 512) {
655 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, 579 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len,
@@ -692,10 +616,6 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
692 else 616 else
693 memcpy(buf, data_buf, data_len); 617 memcpy(buf, data_buf, data_len);
694 618
695#ifdef SUPPORT_SD_LOCK
696 if (cmd_idx == LOCK_UNLOCK)
697 lock_cmd_type = buf[0] & 0x0F;
698#endif
699 619
700 if (data_len > 256) { 620 if (data_len > 256) {
701 rts51x_init_cmd(chip); 621 rts51x_init_cmd(chip);
@@ -802,29 +722,6 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
802 SD_STOP | SD_CLR_ERR); 722 SD_STOP | SD_CLR_ERR);
803 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); 723 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
804 } 724 }
805#ifdef SUPPORT_SD_LOCK
806 if (cmd_idx == LOCK_UNLOCK) {
807 if (lock_cmd_type == SD_ERASE) {
808 sd_card->sd_erase_status = SD_UNDER_ERASING;
809 scsi_set_resid(srb, 0);
810 return TRANSPORT_GOOD;
811 }
812
813 rts51x_init_cmd(chip);
814 rts51x_add_cmd(chip, CHECK_REG_CMD, SD_BUS_STAT, SD_DAT0_STATUS,
815 SD_DAT0_STATUS);
816 retval = rts51x_send_cmd(chip, MODE_CR, 250);
817 if (retval != STATUS_SUCCESS)
818 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
819 rts51x_get_rsp(chip, 1, 200); /* Don't care return value */
820
821 retval = sd_update_lock_status(chip);
822 if (retval != STATUS_SUCCESS) {
823 RTS51X_DEBUGP("Lock command fail!\n");
824 lock_cmd_fail = 1;
825 }
826 }
827#endif /* SUPPORT_SD_LOCK */
828 725
829 if (standby) { 726 if (standby) {
830 retval = sd_select_card(chip, 1); 727 retval = sd_select_card(chip, 1);
@@ -865,51 +762,6 @@ int ext_sd_execute_write_data(struct rts51x_chip *chip, unsigned int lun,
865 } 762 }
866 if (retval != STATUS_SUCCESS) 763 if (retval != STATUS_SUCCESS)
867 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); 764 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
868#ifdef SUPPORT_SD_LOCK
869 if (cmd_idx == LOCK_UNLOCK) {
870 if (!lock_cmd_fail) {
871 RTS51X_DEBUGP("lock_cmd_type = 0x%x\n",
872 lock_cmd_type);
873 if (lock_cmd_type & SD_CLR_PWD)
874 sd_card->sd_lock_status &= ~SD_PWD_EXIST;
875 if (lock_cmd_type & SD_SET_PWD)
876 sd_card->sd_lock_status |= SD_PWD_EXIST;
877 }
878
879 RTS51X_DEBUGP("sd_lock_state = 0x%x,"
880 "sd_card->sd_lock_status = 0x%x\n",
881 sd_lock_state, sd_card->sd_lock_status);
882 if (sd_lock_state ^ (sd_card->sd_lock_status & SD_LOCKED)) {
883 sd_card->sd_lock_notify = 1;
884 if (sd_lock_state) {
885 if (sd_card->sd_lock_status &
886 SD_LOCK_1BIT_MODE) {
887 sd_card->sd_lock_status |=
888 (SD_UNLOCK_POW_ON | SD_SDR_RST);
889 if (CHK_SD(sd_card)) {
890 retval = reset_sd(chip);
891 if (retval != STATUS_SUCCESS) {
892 sd_card->sd_lock_status
893 &= ~(SD_UNLOCK_POW_ON |
894 SD_SDR_RST);
895 TRACE_GOTO(chip,
896 SD_Execute_Write_Cmd_Failed);
897 }
898 }
899
900 sd_card->sd_lock_status &=
901 ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
902 }
903 }
904 }
905 }
906
907 if (lock_cmd_fail) {
908 scsi_set_resid(srb, 0);
909 set_sense_type(chip, lun, SENSE_TYPE_NO_SENSE);
910 TRACE_RET(chip, TRANSPORT_FAILED);
911 }
912#endif /* SUPPORT_SD_LOCK */
913 765
914 return TRANSPORT_GOOD; 766 return TRANSPORT_GOOD;
915 767
@@ -1173,30 +1025,18 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rts51x_chip *chip)
1173 switch (srb->cmnd[1] & 0x0F) { 1025 switch (srb->cmnd[1] & 0x0F) {
1174 case 0: 1026 case 0:
1175 /* SD Card Power Off -> ON and Initialization */ 1027 /* SD Card Power Off -> ON and Initialization */
1176#ifdef SUPPORT_SD_LOCK
1177 if (0x64 == srb->cmnd[9]) {
1178 /* Command Mode */
1179 sd_card->sd_lock_status |= SD_SDR_RST;
1180 }
1181#endif /* SUPPORT_SD_LOCK */
1182 retval = reset_sd_card(chip); 1028 retval = reset_sd_card(chip);
1183 if (retval != STATUS_SUCCESS) { 1029 if (retval != STATUS_SUCCESS) {
1184#ifdef SUPPORT_SD_LOCK
1185 sd_card->sd_lock_status &= ~SD_SDR_RST;
1186#endif
1187 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); 1030 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
1188 sd_card->pre_cmd_err = 1; 1031 sd_card->pre_cmd_err = 1;
1189 TRACE_RET(chip, TRANSPORT_FAILED); 1032 TRACE_RET(chip, TRANSPORT_FAILED);
1190 } 1033 }
1191#ifdef SUPPORT_SD_LOCK
1192 sd_card->sd_lock_status &= ~SD_SDR_RST;
1193#endif
1194 break; 1034 break;
1195 1035
1196 case 1: 1036 case 1:
1197 /* reset CMD(CMD0) and Initialization 1037 /* reset CMD(CMD0) and Initialization
1198 * (without SD Card Power Off -> ON) */ 1038 * (without SD Card Power Off -> ON) */
1199 retval = soft_reset_sd_card(chip); 1039 retval = reset_sd(chip);
1200 if (retval != STATUS_SUCCESS) { 1040 if (retval != STATUS_SUCCESS) {
1201 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); 1041 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
1202 sd_card->pre_cmd_err = 1; 1042 sd_card->pre_cmd_err = 1;
diff --git a/drivers/staging/rts5139/xd.c b/drivers/staging/rts5139/xd.c
index 5820605d1806..58f8ba24caed 100644
--- a/drivers/staging/rts5139/xd.c
+++ b/drivers/staging/rts5139/xd.c
@@ -47,13 +47,6 @@ static inline void xd_set_err_code(struct rts51x_chip *chip, u8 err_code)
47 xd_card->err_code = err_code; 47 xd_card->err_code = err_code;
48} 48}
49 49
50static inline int xd_check_err_code(struct rts51x_chip *chip, u8 err_code)
51{
52 struct xd_info *xd_card = &(chip->xd_card);
53
54 return (xd_card->err_code == err_code);
55}
56
57static int xd_set_init_para(struct rts51x_chip *chip) 50static int xd_set_init_para(struct rts51x_chip *chip)
58{ 51{
59 struct xd_info *xd_card = &(chip->xd_card); 52 struct xd_info *xd_card = &(chip->xd_card);
@@ -862,6 +855,8 @@ static void xd_set_l2p_tbl(struct rts51x_chip *chip, int zone_no, u16 log_off,
862 zone->l2p_table[log_off] = phy_off; 855 zone->l2p_table[log_off] = phy_off;
863} 856}
864 857
858static int xd_delay_write(struct rts51x_chip *chip);
859
865static u32 xd_get_l2p_tbl(struct rts51x_chip *chip, int zone_no, u16 log_off) 860static u32 xd_get_l2p_tbl(struct rts51x_chip *chip, int zone_no, u16 log_off)
866{ 861{
867 struct xd_info *xd_card = &(chip->xd_card); 862 struct xd_info *xd_card = &(chip->xd_card);
@@ -1182,91 +1177,6 @@ static int xd_copy_page(struct rts51x_chip *chip,
1182 return STATUS_SUCCESS; 1177 return STATUS_SUCCESS;
1183} 1178}
1184 1179
1185#ifdef XD_SPEEDUP
1186static int xd_auto_copy_page(struct rts51x_chip *chip,
1187 u32 old_blk, u32 new_blk,
1188 u8 start_page, u8 end_page)
1189{
1190 struct xd_info *xd_card = &(chip->xd_card);
1191 u32 old_page, new_page;
1192 int retval;
1193 u8 page_count;
1194
1195 RTS51X_DEBUGP("Auto copy page from block 0x%x to block 0x%x\n",
1196 old_blk, new_blk);
1197
1198 if (start_page > end_page)
1199 TRACE_RET(chip, STATUS_FAIL);
1200
1201 page_count = end_page - start_page;
1202
1203 if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND))
1204 TRACE_RET(chip, STATUS_FAIL);
1205
1206 old_page = (old_blk << xd_card->block_shift) + start_page;
1207 new_page = (new_blk << xd_card->block_shift) + start_page;
1208
1209 XD_CLR_BAD_NEWBLK(xd_card);
1210
1211 rts51x_init_cmd(chip);
1212
1213 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WAITTIME, 0x03, WAIT_FF);
1214 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_PAGELEN, 0xFF, page_count);
1215
1216 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_READADDR0, 0xFF, 0);
1217 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_READADDR1, 0xFF,
1218 (u8) old_page);
1219 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_READADDR2, 0xFF,
1220 (u8) (old_page >> 8));
1221 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_READADDR3, 0xFF,
1222 (u8) (old_page >> 16));
1223 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_READADDR4, 0xFF, 0);
1224
1225 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WRITEADDR0, 0xFF, 0);
1226 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WRITEADDR1, 0xFF,
1227 (u8) new_page);
1228 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WRITEADDR2, 0xFF,
1229 (u8) (new_page >> 8));
1230 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WRITEADDR3, 0xFF,
1231 (u8) (new_page >> 16));
1232 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CP_WRITEADDR4, 0xFF, 0);
1233
1234 rts51x_add_cmd(chip, WRITE_REG_CMD, CARD_DATA_SOURCE, 0x01,
1235 PINGPONG_BUFFER);
1236
1237 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CFG,
1238 XD_BA_TRANSFORM | XD_ADDR_MASK, 0 | xd_card->addr_cycle);
1239
1240 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_CHK_DATA_STATUS,
1241 XD_AUTO_CHK_DATA_STATUS, 0);
1242 rts51x_add_cmd(chip, WRITE_REG_CMD, XD_TRANSFER, 0xFF,
1243 XD_TRANSFER_START | XD_COPY_PAGES);
1244 rts51x_add_cmd(chip, CHECK_REG_CMD, XD_TRANSFER, XD_TRANSFER_END,
1245 XD_TRANSFER_END);
1246
1247 retval = rts51x_send_cmd(chip, MODE_CR, 100);
1248 if (retval != STATUS_SUCCESS) {
1249 rts51x_clear_xd_error(chip);
1250 TRACE_GOTO(chip, Copy_Fail);
1251 }
1252
1253 retval = rts51x_get_rsp(chip, 1, 800);
1254 if (retval != STATUS_SUCCESS) {
1255 rts51x_clear_xd_error(chip);
1256 TRACE_GOTO(chip, Copy_Fail);
1257 }
1258
1259 return STATUS_SUCCESS;
1260
1261Copy_Fail:
1262 retval = xd_copy_page(chip, old_blk, new_blk, start_page, end_page);
1263 if (retval != STATUS_SUCCESS)
1264 TRACE_RET(chip, retval);
1265
1266 return STATUS_SUCCESS;
1267}
1268#endif
1269
1270static int xd_reset_cmd(struct rts51x_chip *chip) 1180static int xd_reset_cmd(struct rts51x_chip *chip)
1271{ 1181{
1272 int retval; 1182 int retval;
@@ -1686,15 +1596,9 @@ Fail:
1686 XD_CLR_BAD_OLDBLK(xd_card); 1596 XD_CLR_BAD_OLDBLK(xd_card);
1687 TRACE_RET(chip, STATUS_FAIL); 1597 TRACE_RET(chip, STATUS_FAIL);
1688 } 1598 }
1689#ifdef XD_SPEEDUP
1690 retval =
1691 xd_auto_copy_page(chip, phy_blk, new_blk, 0,
1692 xd_card->page_off + 1);
1693#else
1694 retval = 1599 retval =
1695 xd_copy_page(chip, phy_blk, new_blk, 0, 1600 xd_copy_page(chip, phy_blk, new_blk, 0,
1696 xd_card->page_off + 1); 1601 xd_card->page_off + 1);
1697#endif
1698 if (retval != STATUS_SUCCESS) { 1602 if (retval != STATUS_SUCCESS) {
1699 if (!XD_CHK_BAD_NEWBLK(xd_card)) { 1603 if (!XD_CHK_BAD_NEWBLK(xd_card)) {
1700 retval = xd_erase_block(chip, new_blk); 1604 retval = xd_erase_block(chip, new_blk);
@@ -1741,13 +1645,8 @@ static int xd_finish_write(struct rts51x_chip *chip,
1741 TRACE_RET(chip, STATUS_FAIL); 1645 TRACE_RET(chip, STATUS_FAIL);
1742 } 1646 }
1743 } else { 1647 } else {
1744#ifdef XD_SPEEDUP
1745 retval = xd_auto_copy_page(chip, old_blk, new_blk,
1746 page_off, xd_card->page_off + 1);
1747#else
1748 retval = xd_copy_page(chip, old_blk, new_blk, 1648 retval = xd_copy_page(chip, old_blk, new_blk,
1749 page_off, xd_card->page_off + 1); 1649 page_off, xd_card->page_off + 1);
1750#endif
1751 if (retval != STATUS_SUCCESS) { 1650 if (retval != STATUS_SUCCESS) {
1752 if (!XD_CHK_BAD_NEWBLK(xd_card)) { 1651 if (!XD_CHK_BAD_NEWBLK(xd_card)) {
1753 retval = xd_erase_block(chip, new_blk); 1652 retval = xd_erase_block(chip, new_blk);
@@ -1789,11 +1688,7 @@ static int xd_prepare_write(struct rts51x_chip *chip,
1789 old_blk, new_blk, log_blk, (int)page_off); 1688 old_blk, new_blk, log_blk, (int)page_off);
1790 1689
1791 if (page_off) { 1690 if (page_off) {
1792#ifdef XD_SPEEDUP
1793 retval = xd_auto_copy_page(chip, old_blk, new_blk, 0, page_off);
1794#else
1795 retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off); 1691 retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off);
1796#endif
1797 if (retval != STATUS_SUCCESS) 1692 if (retval != STATUS_SUCCESS)
1798 TRACE_RET(chip, retval); 1693 TRACE_RET(chip, retval);
1799 } 1694 }
@@ -1922,7 +1817,7 @@ Fail:
1922 TRACE_RET(chip, STATUS_FAIL); 1817 TRACE_RET(chip, STATUS_FAIL);
1923} 1818}
1924 1819
1925int xd_delay_write(struct rts51x_chip *chip) 1820static int xd_delay_write(struct rts51x_chip *chip)
1926{ 1821{
1927 struct xd_info *xd_card = &(chip->xd_card); 1822 struct xd_info *xd_card = &(chip->xd_card);
1928 struct xd_delay_write_tag *delay_write = &(xd_card->delay_write); 1823 struct xd_delay_write_tag *delay_write = &(xd_card->delay_write);
@@ -1999,18 +1894,11 @@ int xd_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector,
1999 (start_page > delay_write->pageoff)) { 1894 (start_page > delay_write->pageoff)) {
2000 delay_write->delay_write_flag = 0; 1895 delay_write->delay_write_flag = 0;
2001 if (delay_write->old_phyblock != BLK_NOT_FOUND) { 1896 if (delay_write->old_phyblock != BLK_NOT_FOUND) {
2002#ifdef XD_SPEEDUP
2003 retval = xd_auto_copy_page(chip,
2004 delay_write->old_phyblock,
2005 delay_write->new_phyblock,
2006 delay_write->pageoff, start_page);
2007#else
2008 retval = xd_copy_page(chip, 1897 retval = xd_copy_page(chip,
2009 delay_write->old_phyblock, 1898 delay_write->old_phyblock,
2010 delay_write->new_phyblock, 1899 delay_write->new_phyblock,
2011 delay_write->pageoff, 1900 delay_write->pageoff,
2012 start_page); 1901 start_page);
2013#endif
2014 if (retval != STATUS_SUCCESS) { 1902 if (retval != STATUS_SUCCESS) {
2015 set_sense_type(chip, lun, 1903 set_sense_type(chip, lun,
2016 SENSE_TYPE_MEDIA_WRITE_ERR); 1904 SENSE_TYPE_MEDIA_WRITE_ERR);
@@ -2198,7 +2086,7 @@ void xd_cleanup_work(struct rts51x_chip *chip)
2198 } 2086 }
2199} 2087}
2200 2088
2201int xd_power_off_card3v3(struct rts51x_chip *chip) 2089static int xd_power_off_card3v3(struct rts51x_chip *chip)
2202{ 2090{
2203 int retval; 2091 int retval;
2204 2092
@@ -2232,7 +2120,7 @@ int release_xd_card(struct rts51x_chip *chip)
2232 struct xd_info *xd_card = &(chip->xd_card); 2120 struct xd_info *xd_card = &(chip->xd_card);
2233 int retval; 2121 int retval;
2234 2122
2235 RTS51X_DEBUGP("elease_xd_card\n"); 2123 RTS51X_DEBUGP("release_xd_card\n");
2236 2124
2237 chip->card_ready &= ~XD_CARD; 2125 chip->card_ready &= ~XD_CARD;
2238 chip->card_fail &= ~XD_CARD; 2126 chip->card_fail &= ~XD_CARD;
diff --git a/drivers/staging/rts5139/xd.h b/drivers/staging/rts5139/xd.h
index fa695903ba65..55e4205e23fa 100644
--- a/drivers/staging/rts5139/xd.h
+++ b/drivers/staging/rts5139/xd.h
@@ -182,12 +182,10 @@
182#define CIS1_9 (256 + 9) 182#define CIS1_9 (256 + 9)
183 183
184int reset_xd_card(struct rts51x_chip *chip); 184int reset_xd_card(struct rts51x_chip *chip);
185int xd_delay_write(struct rts51x_chip *chip);
186int xd_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector, 185int xd_rw(struct scsi_cmnd *srb, struct rts51x_chip *chip, u32 start_sector,
187 u16 sector_cnt); 186 u16 sector_cnt);
188void xd_free_l2p_tbl(struct rts51x_chip *chip); 187void xd_free_l2p_tbl(struct rts51x_chip *chip);
189void xd_cleanup_work(struct rts51x_chip *chip); 188void xd_cleanup_work(struct rts51x_chip *chip);
190int xd_power_off_card3v3(struct rts51x_chip *chip);
191int release_xd_card(struct rts51x_chip *chip); 189int release_xd_card(struct rts51x_chip *chip);
192 190
193#endif /* __RTS51X_XD_H */ 191#endif /* __RTS51X_XD_H */
diff --git a/drivers/staging/rts_pstor/ms.c b/drivers/staging/rts_pstor/ms.c
index f9a4498984cc..0bf6d95b3fab 100644
--- a/drivers/staging/rts_pstor/ms.c
+++ b/drivers/staging/rts_pstor/ms.c
@@ -4136,7 +4136,7 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4136#else 4136#else
4137 retval = ms_transfer_data(chip, MS_TM_AUTO_WRITE, PRO_WRITE_LONG_DATA, 4137 retval = ms_transfer_data(chip, MS_TM_AUTO_WRITE, PRO_WRITE_LONG_DATA,
4138 2, WAIT_INT, 0, 0, buf + 4, 1024); 4138 2, WAIT_INT, 0, 0, buf + 4, 1024);
4139 if ((retval != STATUS_SUCCESS) || check_ms_err(chip) { 4139 if ((retval != STATUS_SUCCESS) || check_ms_err(chip)) {
4140 rtsx_clear_ms_error(chip); 4140 rtsx_clear_ms_error(chip);
4141 if (ms_card->mg_auth == 0) { 4141 if (ms_card->mg_auth == 0) {
4142 if ((buf[5] & 0xC0) != 0) { 4142 if ((buf[5] & 0xC0) != 0) {
diff --git a/drivers/staging/rts_pstor/rtsx_transport.c b/drivers/staging/rts_pstor/rtsx_transport.c
index 9b2e5c99870f..54a474235f26 100644
--- a/drivers/staging/rts_pstor/rtsx_transport.c
+++ b/drivers/staging/rts_pstor/rtsx_transport.c
@@ -130,7 +130,7 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
130/* Store the contents of buffer into srb's transfer buffer and set the 130/* Store the contents of buffer into srb's transfer buffer and set the
131* SCSI residue. */ 131* SCSI residue. */
132void rtsx_stor_set_xfer_buf(unsigned char *buffer, 132void rtsx_stor_set_xfer_buf(unsigned char *buffer,
133 unsigned int buflen, struct scsi_cmnd *srb) 133 unsigned int buflen, struct scsi_cmnd *srb)
134{ 134{
135 unsigned int index = 0, offset = 0; 135 unsigned int index = 0, offset = 0;
136 136
@@ -141,7 +141,7 @@ void rtsx_stor_set_xfer_buf(unsigned char *buffer,
141} 141}
142 142
143void rtsx_stor_get_xfer_buf(unsigned char *buffer, 143void rtsx_stor_get_xfer_buf(unsigned char *buffer,
144 unsigned int buflen, struct scsi_cmnd *srb) 144 unsigned int buflen, struct scsi_cmnd *srb)
145{ 145{
146 unsigned int index = 0, offset = 0; 146 unsigned int index = 0, offset = 0;
147 147
diff --git a/drivers/staging/sep/sep_driver_config.h b/drivers/staging/sep/sep_driver_config.h
index fa7c0d09bfa5..9d9fc7c94a6e 100644
--- a/drivers/staging/sep/sep_driver_config.h
+++ b/drivers/staging/sep/sep_driver_config.h
@@ -68,11 +68,11 @@
68#define SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE 16 68#define SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE 16
69 69
70/* flag that signifies tah the lock is 70/* flag that signifies tah the lock is
71currently held by the proccess (struct file) */ 71currently held by the process (struct file) */
72#define SEP_DRIVER_OWN_LOCK_FLAG 1 72#define SEP_DRIVER_OWN_LOCK_FLAG 1
73 73
74/* flag that signifies tah the lock is currently NOT 74/* flag that signifies tah the lock is currently NOT
75held by the proccess (struct file) */ 75held by the process (struct file) */
76#define SEP_DRIVER_DISOWN_LOCK_FLAG 0 76#define SEP_DRIVER_DISOWN_LOCK_FLAG 0
77 77
78/* indicates whether driver has mapped/unmapped shared area */ 78/* indicates whether driver has mapped/unmapped shared area */
@@ -280,7 +280,7 @@ held by the proccess (struct file) */
280 280
281/* 281/*
282 * Used to limit number of concurrent processes 282 * Used to limit number of concurrent processes
283 * allowed to allocte dynamic buffers in fastcall 283 * allowed to allocate dynamic buffers in fastcall
284 * interface. 284 * interface.
285 */ 285 */
286#define SEP_DOUBLEBUF_USERS_LIMIT 3 286#define SEP_DOUBLEBUF_USERS_LIMIT 3
diff --git a/drivers/staging/sep/sep_main.c b/drivers/staging/sep/sep_main.c
index f1701bc6e312..df1d13e96fcd 100644
--- a/drivers/staging/sep/sep_main.c
+++ b/drivers/staging/sep/sep_main.c
@@ -786,7 +786,7 @@ static unsigned int sep_poll(struct file *filp, poll_table *wait)
786 "[PID%d] poll: send_ct is %lx reply ct is %lx\n", 786 "[PID%d] poll: send_ct is %lx reply ct is %lx\n",
787 current->pid, sep->send_ct, sep->reply_ct); 787 current->pid, sep->send_ct, sep->reply_ct);
788 788
789 /* Check if error occured during poll */ 789 /* Check if error occurred during poll */
790 retval2 = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR); 790 retval2 = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
791 if ((retval2 != 0x0) && (retval2 != 0x8)) { 791 if ((retval2 != 0x0) && (retval2 != 0x8)) {
792 dev_dbg(&sep->pdev->dev, "[PID%d] poll; poll error %x\n", 792 dev_dbg(&sep->pdev->dev, "[PID%d] poll; poll error %x\n",
@@ -1160,7 +1160,7 @@ static int sep_lock_kernel_pages(struct sep_device *sep,
1160 1160
1161 /* Put mapped kernel sg into kernel resource array */ 1161 /* Put mapped kernel sg into kernel resource array */
1162 1162
1163 /* Set output params acording to the in_out flag */ 1163 /* Set output params according to the in_out flag */
1164 if (in_out_flag == SEP_DRIVER_IN_FLAG) { 1164 if (in_out_flag == SEP_DRIVER_IN_FLAG) {
1165 *lli_array_ptr = lli_array; 1165 *lli_array_ptr = lli_array;
1166 dma_ctx->dma_res_arr[dma_ctx->nr_dcb_creat].in_num_pages = 1166 dma_ctx->dma_res_arr[dma_ctx->nr_dcb_creat].in_num_pages =
@@ -1358,7 +1358,7 @@ static int sep_lock_user_pages(struct sep_device *sep,
1358 lli_array[num_pages - 1].block_size); 1358 lli_array[num_pages - 1].block_size);
1359 } 1359 }
1360 1360
1361 /* Set output params acording to the in_out flag */ 1361 /* Set output params according to the in_out flag */
1362 if (in_out_flag == SEP_DRIVER_IN_FLAG) { 1362 if (in_out_flag == SEP_DRIVER_IN_FLAG) {
1363 *lli_array_ptr = lli_array; 1363 *lli_array_ptr = lli_array;
1364 dma_ctx->dma_res_arr[dma_ctx->nr_dcb_creat].in_num_pages = 1364 dma_ctx->dma_res_arr[dma_ctx->nr_dcb_creat].in_num_pages =
@@ -2038,7 +2038,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
2038 2038
2039 /* 2039 /*
2040 * If this is not the last table - 2040 * If this is not the last table -
2041 * then allign it to the block size 2041 * then align it to the block size
2042 */ 2042 */
2043 if (!last_table_flag) 2043 if (!last_table_flag)
2044 table_data_size = 2044 table_data_size =
@@ -3033,7 +3033,7 @@ static int sep_free_dcb_handler(struct sep_device *sep,
3033 * @cmd: command 3033 * @cmd: command
3034 * @arg: pointer to argument structure 3034 * @arg: pointer to argument structure
3035 * 3035 *
3036 * Implement the ioctl methods availble on the SEP device. 3036 * Implement the ioctl methods available on the SEP device.
3037 */ 3037 */
3038static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 3038static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3039{ 3039{
@@ -4460,7 +4460,7 @@ static int sep_pm_runtime_suspend(struct device *dev)
4460 * @sep_pm_runtime_resume: resume- no communication with cpu & main memory 4460 * @sep_pm_runtime_resume: resume- no communication with cpu & main memory
4461 * @sep_pm_runtime_suspend: suspend- no communication with cpu & main memory 4461 * @sep_pm_runtime_suspend: suspend- no communication with cpu & main memory
4462 * @sep_pci_suspend: suspend - main memory is still ON 4462 * @sep_pci_suspend: suspend - main memory is still ON
4463 * @sep_pci_resume: resume - main meory is still ON 4463 * @sep_pci_resume: resume - main memory is still ON
4464 */ 4464 */
4465static const struct dev_pm_ops sep_pm = { 4465static const struct dev_pm_ops sep_pm = {
4466 .runtime_resume = sep_pm_runtime_resume, 4466 .runtime_resume = sep_pm_runtime_resume,
diff --git a/drivers/staging/serial/68360serial.c b/drivers/staging/serial/68360serial.c
deleted file mode 100644
index 23ee50e25e44..000000000000
--- a/drivers/staging/serial/68360serial.c
+++ /dev/null
@@ -1,2979 +0,0 @@
1/*
2 * UART driver for 68360 CPM SCC or SMC
3 * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
4 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
5 * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
6 *
7 * I used the serial.c driver as the framework for this driver.
8 * Give credit to those guys.
9 * The original code was written for the MBX860 board. I tried to make
10 * it generic, but there may be some assumptions in the structures that
11 * have to be fixed later.
12 * To save porting time, I did not bother to change any object names
13 * that are not accessed outside of this file.
14 * It still needs lots of work........When it was easy, I included code
15 * to support the SCCs, but this has never been tested, nor is it complete.
16 * Only the SCCs support modem control, so that is not complete either.
17 *
18 * This module exports the following rs232 io functions:
19 *
20 * int rs_360_init(void);
21 */
22
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/timer.h>
28#include <linux/interrupt.h>
29#include <linux/tty.h>
30#include <linux/tty_flip.h>
31#include <linux/serial.h>
32#include <linux/serialP.h>
33#include <linux/major.h>
34#include <linux/string.h>
35#include <linux/fcntl.h>
36#include <linux/ptrace.h>
37#include <linux/mm.h>
38#include <linux/init.h>
39#include <linux/delay.h>
40#include <asm/irq.h>
41#include <asm/m68360.h>
42#include <asm/commproc.h>
43
44
45#ifdef CONFIG_KGDB
46extern void breakpoint(void);
47extern void set_debug_traps(void);
48extern int kgdb_output_string (const char* s, unsigned int count);
49#endif
50
51
52/* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
53#include <linux/console.h>
54#include <linux/jiffies.h>
55
56/* this defines the index into rs_table for the port to use
57 */
58#ifndef CONFIG_SERIAL_CONSOLE_PORT
59#define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
60#endif
61/* #endif */
62
63#if 0
64/* SCC2 for console
65 */
66#undef CONFIG_SERIAL_CONSOLE_PORT
67#define CONFIG_SERIAL_CONSOLE_PORT 2
68#endif
69
70
71#define TX_WAKEUP ASYNC_SHARE_IRQ
72
73static char *serial_name = "CPM UART driver";
74static char *serial_version = "0.03";
75
76static struct tty_driver *serial_driver;
77int serial_console_setup(struct console *co, char *options);
78
79/*
80 * Serial driver configuration section. Here are the various options:
81 */
82#define SERIAL_PARANOIA_CHECK
83#define CONFIG_SERIAL_NOPAUSE_IO
84#define SERIAL_DO_RESTART
85
86/* Set of debugging defines */
87
88#undef SERIAL_DEBUG_INTR
89#undef SERIAL_DEBUG_OPEN
90#undef SERIAL_DEBUG_FLOW
91#undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
92
93#define _INLINE_ inline
94
95#define DBG_CNT(s)
96
97/* We overload some of the items in the data structure to meet our
98 * needs. For example, the port address is the CPM parameter ram
99 * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
100 * 2 SMCs. The "hub6" field is used to indicate the channel number, with
101 * a flag indicating SCC or SMC, and the number is used as an index into
102 * the CPM parameter area for this device.
103 * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
104 * not currently used. I should probably use it to indicate the port
105 * type of SMC or SCC.
106 * The SMCs do not support any modem control signals.
107 */
108#define smc_scc_num hub6
109#define NUM_IS_SCC ((int)0x00010000)
110#define PORT_NUM(P) ((P) & 0x0000ffff)
111
112
113#if defined (CONFIG_UCQUICC)
114
115volatile extern void *_periph_base;
116/* sipex transceiver
117 * mode bits for are on pins
118 *
119 * SCC2 d16..19
120 * SCC3 d20..23
121 * SCC4 d24..27
122 */
123#define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
124
125static uint sipex_mode_bits = 0x00000000;
126
127#endif
128
129/* There is no `serial_state' defined back here in 2.0.
130 * Try to get by with serial_struct
131 */
132/* #define serial_state serial_struct */
133
134/* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
135 * extras: */
136
137#if 0
138struct async_icount_24 {
139 __u32 cts, dsr, rng, dcd, tx, rx;
140 __u32 frame, parity, overrun, brk;
141 __u32 buf_overrun;
142} icount;
143#endif
144
145#if 0
146
147struct serial_state {
148 int magic;
149 int baud_base;
150 unsigned long port;
151 int irq;
152 int flags;
153 int hub6;
154 int type;
155 int line;
156 int revision; /* Chip revision (950) */
157 int xmit_fifo_size;
158 int custom_divisor;
159 int count;
160 u8 *iomem_base;
161 u16 iomem_reg_shift;
162 unsigned short close_delay;
163 unsigned short closing_wait; /* time to wait before closing */
164 struct async_icount_24 icount;
165 int io_type;
166 struct async_struct *info;
167};
168#endif
169
170#define SSTATE_MAGIC 0x5302
171
172
173
174/* SMC2 is sometimes used for low performance TDM interfaces. Define
175 * this as 1 if you want SMC2 as a serial port UART managed by this driver.
176 * Define this as 0 if you wish to use SMC2 for something else.
177 */
178#define USE_SMC2 1
179
180#if 0
181/* Define SCC to ttySx mapping. */
182#define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
183
184/* Define which SCC is the first one to use for a serial port. These
185 * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
186 * for Ethernet, and the first available SCC for serial UART is SCC2.
187 * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
188 * interrupt vectors in the table below to match.
189 */
190#define SCC_IDX_BASE 1 /* table index */
191#endif
192
193
194/* Processors other than the 860 only get SMCs configured by default.
195 * Either they don't have SCCs or they are allocated somewhere else.
196 * Of course, there are now 860s without some SCCs, so we will need to
197 * address that someday.
198 * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
199 * stereo codec parts, and we use SMC2 to help support that.
200 */
201static struct serial_state rs_table[] = {
202/* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
203 { 0, 0, PRSLOT_SMC1, CPMVEC_SMC1, 0, 0 } /* SMC1 ttyS0 */
204#if USE_SMC2
205 ,{ 0, 0, PRSLOT_SMC2, CPMVEC_SMC2, 0, 1 } /* SMC2 ttyS1 */
206#endif
207
208#if defined(CONFIG_SERIAL_68360_SCC)
209 ,{ 0, 0, PRSLOT_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) } /* SCC2 ttyS2 */
210 ,{ 0, 0, PRSLOT_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) } /* SCC3 ttyS3 */
211 ,{ 0, 0, PRSLOT_SCC4, CPMVEC_SCC4, 0, (NUM_IS_SCC | 3) } /* SCC4 ttyS4 */
212#endif
213};
214
215#define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
216
217/* The number of buffer descriptors and their sizes.
218 */
219#define RX_NUM_FIFO 4
220#define RX_BUF_SIZE 32
221#define TX_NUM_FIFO 4
222#define TX_BUF_SIZE 32
223
224#define CONSOLE_NUM_FIFO 2
225#define CONSOLE_BUF_SIZE 4
226
227char *console_fifos[CONSOLE_NUM_FIFO * CONSOLE_BUF_SIZE];
228
229/* The async_struct in serial.h does not really give us what we
230 * need, so define our own here.
231 */
232typedef struct serial_info {
233 int magic;
234 int flags;
235
236 struct serial_state *state;
237 /* struct serial_struct *state; */
238 /* struct async_struct *state; */
239
240 struct tty_struct *tty;
241 int read_status_mask;
242 int ignore_status_mask;
243 int timeout;
244 int line;
245 int x_char; /* xon/xoff character */
246 int close_delay;
247 unsigned short closing_wait;
248 unsigned short closing_wait2;
249 unsigned long event;
250 unsigned long last_active;
251 int blocked_open; /* # of blocked opens */
252 struct work_struct tqueue;
253 struct work_struct tqueue_hangup;
254 wait_queue_head_t open_wait;
255 wait_queue_head_t close_wait;
256
257
258/* CPM Buffer Descriptor pointers.
259 */
260 QUICC_BD *rx_bd_base;
261 QUICC_BD *rx_cur;
262 QUICC_BD *tx_bd_base;
263 QUICC_BD *tx_cur;
264} ser_info_t;
265
266
267/* since kmalloc_init() does not get called until much after this initialization: */
268static ser_info_t quicc_ser_info[NR_PORTS];
269static char rx_buf_pool[NR_PORTS * RX_NUM_FIFO * RX_BUF_SIZE];
270static char tx_buf_pool[NR_PORTS * TX_NUM_FIFO * TX_BUF_SIZE];
271
272static void change_speed(ser_info_t *info);
273static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout);
274
275static inline int serial_paranoia_check(ser_info_t *info,
276 char *name, const char *routine)
277{
278#ifdef SERIAL_PARANOIA_CHECK
279 static const char *badmagic =
280 "Warning: bad magic number for serial struct (%s) in %s\n";
281 static const char *badinfo =
282 "Warning: null async_struct for (%s) in %s\n";
283
284 if (!info) {
285 printk(badinfo, name, routine);
286 return 1;
287 }
288 if (info->magic != SERIAL_MAGIC) {
289 printk(badmagic, name, routine);
290 return 1;
291 }
292#endif
293 return 0;
294}
295
296/*
297 * This is used to figure out the divisor speeds and the timeouts,
298 * indexed by the termio value. The generic CPM functions are responsible
299 * for setting and assigning baud rate generators for us.
300 */
301static int baud_table[] = {
302 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
303 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
304
305/* This sucks. There is a better way: */
306#if defined(CONFIG_CONSOLE_9600)
307 #define CONSOLE_BAUDRATE 9600
308#elif defined(CONFIG_CONSOLE_19200)
309 #define CONSOLE_BAUDRATE 19200
310#elif defined(CONFIG_CONSOLE_115200)
311 #define CONSOLE_BAUDRATE 115200
312#else
313 #warning "console baud rate undefined"
314 #define CONSOLE_BAUDRATE 9600
315#endif
316
317/*
318 * ------------------------------------------------------------
319 * rs_stop() and rs_start()
320 *
321 * This routines are called before setting or resetting tty->stopped.
322 * They enable or disable transmitter interrupts, as necessary.
323 * ------------------------------------------------------------
324 */
325static void rs_360_stop(struct tty_struct *tty)
326{
327 ser_info_t *info = (ser_info_t *)tty->driver_data;
328 int idx;
329 unsigned long flags;
330 volatile struct scc_regs *sccp;
331 volatile struct smc_regs *smcp;
332
333 if (serial_paranoia_check(info, tty->name, "rs_stop"))
334 return;
335
336 local_irq_save(flags);
337 idx = PORT_NUM(info->state->smc_scc_num);
338 if (info->state->smc_scc_num & NUM_IS_SCC) {
339 sccp = &pquicc->scc_regs[idx];
340 sccp->scc_sccm &= ~UART_SCCM_TX;
341 } else {
342 /* smcp = &cpmp->cp_smc[idx]; */
343 smcp = &pquicc->smc_regs[idx];
344 smcp->smc_smcm &= ~SMCM_TX;
345 }
346 local_irq_restore(flags);
347}
348
349
350static void rs_360_start(struct tty_struct *tty)
351{
352 ser_info_t *info = (ser_info_t *)tty->driver_data;
353 int idx;
354 unsigned long flags;
355 volatile struct scc_regs *sccp;
356 volatile struct smc_regs *smcp;
357
358 if (serial_paranoia_check(info, tty->name, "rs_stop"))
359 return;
360
361 local_irq_save(flags);
362 idx = PORT_NUM(info->state->smc_scc_num);
363 if (info->state->smc_scc_num & NUM_IS_SCC) {
364 sccp = &pquicc->scc_regs[idx];
365 sccp->scc_sccm |= UART_SCCM_TX;
366 } else {
367 smcp = &pquicc->smc_regs[idx];
368 smcp->smc_smcm |= SMCM_TX;
369 }
370 local_irq_restore(flags);
371}
372
373/*
374 * ----------------------------------------------------------------------
375 *
376 * Here starts the interrupt handling routines. All of the following
377 * subroutines are declared as inline and are folded into
378 * rs_interrupt(). They were separated out for readability's sake.
379 *
380 * Note: rs_interrupt() is a "fast" interrupt, which means that it
381 * runs with interrupts turned off. People who may want to modify
382 * rs_interrupt() should try to keep the interrupt handler as fast as
383 * possible. After you are done making modifications, it is not a bad
384 * idea to do:
385 *
386 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
387 *
388 * and look at the resulting assemble code in serial.s.
389 *
390 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
391 * -----------------------------------------------------------------------
392 */
393
394static _INLINE_ void receive_chars(ser_info_t *info)
395{
396 struct tty_struct *tty = info->port.tty;
397 unsigned char ch, flag, *cp;
398 /*int ignored = 0;*/
399 int i;
400 ushort status;
401 struct async_icount *icount;
402 /* struct async_icount_24 *icount; */
403 volatile QUICC_BD *bdp;
404
405 icount = &info->state->icount;
406
407 /* Just loop through the closed BDs and copy the characters into
408 * the buffer.
409 */
410 bdp = info->rx_cur;
411 for (;;) {
412 if (bdp->status & BD_SC_EMPTY) /* If this one is empty */
413 break; /* we are all done */
414
415 /* The read status mask tell us what we should do with
416 * incoming characters, especially if errors occur.
417 * One special case is the use of BD_SC_EMPTY. If
418 * this is not set, we are supposed to be ignoring
419 * inputs. In this case, just mark the buffer empty and
420 * continue.
421 */
422 if (!(info->read_status_mask & BD_SC_EMPTY)) {
423 bdp->status |= BD_SC_EMPTY;
424 bdp->status &=
425 ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
426
427 if (bdp->status & BD_SC_WRAP)
428 bdp = info->rx_bd_base;
429 else
430 bdp++;
431 continue;
432 }
433
434 /* Get the number of characters and the buffer pointer.
435 */
436 i = bdp->length;
437 /* cp = (unsigned char *)__va(bdp->buf); */
438 cp = (char *)bdp->buf;
439 status = bdp->status;
440
441 while (i-- > 0) {
442 ch = *cp++;
443 icount->rx++;
444
445#ifdef SERIAL_DEBUG_INTR
446 printk("DR%02x:%02x...", ch, status);
447#endif
448 flag = TTY_NORMAL;
449
450 if (status & (BD_SC_BR | BD_SC_FR |
451 BD_SC_PR | BD_SC_OV)) {
452 /*
453 * For statistics only
454 */
455 if (status & BD_SC_BR)
456 icount->brk++;
457 else if (status & BD_SC_PR)
458 icount->parity++;
459 else if (status & BD_SC_FR)
460 icount->frame++;
461 if (status & BD_SC_OV)
462 icount->overrun++;
463
464 /*
465 * Now check to see if character should be
466 * ignored, and mask off conditions which
467 * should be ignored.
468 if (status & info->ignore_status_mask) {
469 if (++ignored > 100)
470 break;
471 continue;
472 }
473 */
474 status &= info->read_status_mask;
475
476 if (status & (BD_SC_BR)) {
477#ifdef SERIAL_DEBUG_INTR
478 printk("handling break....");
479#endif
480 *tty->flip.flag_buf_ptr = TTY_BREAK;
481 if (info->flags & ASYNC_SAK)
482 do_SAK(tty);
483 } else if (status & BD_SC_PR)
484 flag = TTY_PARITY;
485 else if (status & BD_SC_FR)
486 flag = TTY_FRAME;
487 }
488 tty_insert_flip_char(tty, ch, flag);
489 if (status & BD_SC_OV)
490 /*
491 * Overrun is special, since it's
492 * reported immediately, and doesn't
493 * affect the current character
494 */
495 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
496 }
497
498 /* This BD is ready to be used again. Clear status.
499 * Get next BD.
500 */
501 bdp->status |= BD_SC_EMPTY;
502 bdp->status &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
503
504 if (bdp->status & BD_SC_WRAP)
505 bdp = info->rx_bd_base;
506 else
507 bdp++;
508 }
509
510 info->rx_cur = (QUICC_BD *)bdp;
511
512 tty_schedule_flip(tty);
513}
514
515static _INLINE_ void receive_break(ser_info_t *info)
516{
517 struct tty_struct *tty = info->port.tty;
518
519 info->state->icount.brk++;
520 /* Check to see if there is room in the tty buffer for
521 * the break. If not, we exit now, losing the break. FIXME
522 */
523 tty_insert_flip_char(tty, 0, TTY_BREAK);
524 tty_schedule_flip(tty);
525}
526
527static _INLINE_ void transmit_chars(ser_info_t *info)
528{
529
530 if ((info->flags & TX_WAKEUP) ||
531 (info->port.tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
532 schedule_work(&info->tqueue);
533 }
534
535#ifdef SERIAL_DEBUG_INTR
536 printk("THRE...");
537#endif
538}
539
540#ifdef notdef
541 /* I need to do this for the SCCs, so it is left as a reminder.
542 */
543static _INLINE_ void check_modem_status(struct async_struct *info)
544{
545 int status;
546 /* struct async_icount *icount; */
547 struct async_icount_24 *icount;
548
549 status = serial_in(info, UART_MSR);
550
551 if (status & UART_MSR_ANY_DELTA) {
552 icount = &info->state->icount;
553 /* update input line counters */
554 if (status & UART_MSR_TERI)
555 icount->rng++;
556 if (status & UART_MSR_DDSR)
557 icount->dsr++;
558 if (status & UART_MSR_DDCD) {
559 icount->dcd++;
560#ifdef CONFIG_HARD_PPS
561 if ((info->flags & ASYNC_HARDPPS_CD) &&
562 (status & UART_MSR_DCD))
563 hardpps();
564#endif
565 }
566 if (status & UART_MSR_DCTS)
567 icount->cts++;
568 wake_up_interruptible(&info->delta_msr_wait);
569 }
570
571 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
572#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
573 printk("ttys%d CD now %s...", info->line,
574 (status & UART_MSR_DCD) ? "on" : "off");
575#endif
576 if (status & UART_MSR_DCD)
577 wake_up_interruptible(&info->open_wait);
578 else {
579#ifdef SERIAL_DEBUG_OPEN
580 printk("scheduling hangup...");
581#endif
582 queue_task(&info->tqueue_hangup,
583 &tq_scheduler);
584 }
585 }
586 if (info->flags & ASYNC_CTS_FLOW) {
587 if (info->port.tty->hw_stopped) {
588 if (status & UART_MSR_CTS) {
589#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
590 printk("CTS tx start...");
591#endif
592 info->port.tty->hw_stopped = 0;
593 info->IER |= UART_IER_THRI;
594 serial_out(info, UART_IER, info->IER);
595 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
596 return;
597 }
598 } else {
599 if (!(status & UART_MSR_CTS)) {
600#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
601 printk("CTS tx stop...");
602#endif
603 info->port.tty->hw_stopped = 1;
604 info->IER &= ~UART_IER_THRI;
605 serial_out(info, UART_IER, info->IER);
606 }
607 }
608 }
609}
610#endif
611
612/*
613 * This is the serial driver's interrupt routine for a single port
614 */
615/* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
616static void rs_360_interrupt(int vec, void *dev_id)
617{
618 u_char events;
619 int idx;
620 ser_info_t *info;
621 volatile struct smc_regs *smcp;
622 volatile struct scc_regs *sccp;
623
624 info = dev_id;
625
626 idx = PORT_NUM(info->state->smc_scc_num);
627 if (info->state->smc_scc_num & NUM_IS_SCC) {
628 sccp = &pquicc->scc_regs[idx];
629 events = sccp->scc_scce;
630 if (events & SCCM_RX)
631 receive_chars(info);
632 if (events & SCCM_TX)
633 transmit_chars(info);
634 sccp->scc_scce = events;
635 } else {
636 smcp = &pquicc->smc_regs[idx];
637 events = smcp->smc_smce;
638 if (events & SMCM_BRKE)
639 receive_break(info);
640 if (events & SMCM_RX)
641 receive_chars(info);
642 if (events & SMCM_TX)
643 transmit_chars(info);
644 smcp->smc_smce = events;
645 }
646
647#ifdef SERIAL_DEBUG_INTR
648 printk("rs_interrupt_single(%d, %x)...",
649 info->state->smc_scc_num, events);
650#endif
651#ifdef modem_control
652 check_modem_status(info);
653#endif
654 info->last_active = jiffies;
655#ifdef SERIAL_DEBUG_INTR
656 printk("end.\n");
657#endif
658}
659
660
661/*
662 * -------------------------------------------------------------------
663 * Here ends the serial interrupt routines.
664 * -------------------------------------------------------------------
665 */
666
667
668static void do_softint(void *private_)
669{
670 ser_info_t *info = (ser_info_t *) private_;
671 struct tty_struct *tty;
672
673 tty = info->port.tty;
674 if (!tty)
675 return;
676
677 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
678 tty_wakeup(tty);
679}
680
681
682/*
683 * This routine is called from the scheduler tqueue when the interrupt
684 * routine has signalled that a hangup has occurred. The path of
685 * hangup processing is:
686 *
687 * serial interrupt routine -> (scheduler tqueue) ->
688 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
689 *
690 */
691static void do_serial_hangup(void *private_)
692{
693 struct async_struct *info = (struct async_struct *) private_;
694 struct tty_struct *tty;
695
696 tty = info->port.tty;
697 if (!tty)
698 return;
699
700 tty_hangup(tty);
701}
702
703
704static int startup(ser_info_t *info)
705{
706 unsigned long flags;
707 int retval=0;
708 int idx;
709 /*struct serial_state *state = info->state;*/
710 volatile struct smc_regs *smcp;
711 volatile struct scc_regs *sccp;
712 volatile struct smc_uart_pram *up;
713 volatile struct uart_pram *scup;
714
715
716 local_irq_save(flags);
717
718 if (info->flags & ASYNC_INITIALIZED) {
719 goto errout;
720 }
721
722#ifdef maybe
723 if (!state->port || !state->type) {
724 if (info->port.tty)
725 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
726 goto errout;
727 }
728#endif
729
730#ifdef SERIAL_DEBUG_OPEN
731 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
732#endif
733
734
735#ifdef modem_control
736 info->MCR = 0;
737 if (info->port.tty->termios->c_cflag & CBAUD)
738 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
739#endif
740
741 if (info->port.tty)
742 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
743
744 /*
745 * and set the speed of the serial port
746 */
747 change_speed(info);
748
749 idx = PORT_NUM(info->state->smc_scc_num);
750 if (info->state->smc_scc_num & NUM_IS_SCC) {
751 sccp = &pquicc->scc_regs[idx];
752 scup = &pquicc->pram[info->state->port].scc.pscc.u;
753
754 scup->mrblr = RX_BUF_SIZE;
755 scup->max_idl = RX_BUF_SIZE;
756
757 sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
758 sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
759
760 } else {
761 smcp = &pquicc->smc_regs[idx];
762
763 /* Enable interrupts and I/O.
764 */
765 smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
766 smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
767
768 /* We can tune the buffer length and idle characters
769 * to take advantage of the entire incoming buffer size.
770 * If mrblr is something other than 1, maxidl has to be
771 * non-zero or we never get an interrupt. The maxidl
772 * is the number of character times we wait after reception
773 * of the last character before we decide no more characters
774 * are coming.
775 */
776 /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
777 /* holy unionized structures, Batman: */
778 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
779
780 up->mrblr = RX_BUF_SIZE;
781 up->max_idl = RX_BUF_SIZE;
782
783 up->brkcr = 1; /* number of break chars */
784 }
785
786 info->flags |= ASYNC_INITIALIZED;
787 local_irq_restore(flags);
788 return 0;
789
790errout:
791 local_irq_restore(flags);
792 return retval;
793}
794
795/*
796 * This routine will shutdown a serial port; interrupts are disabled, and
797 * DTR is dropped if the hangup on close termio flag is on.
798 */
799static void shutdown(ser_info_t *info)
800{
801 unsigned long flags;
802 struct serial_state *state;
803 int idx;
804 volatile struct smc_regs *smcp;
805 volatile struct scc_regs *sccp;
806
807 if (!(info->flags & ASYNC_INITIALIZED))
808 return;
809
810 state = info->state;
811
812#ifdef SERIAL_DEBUG_OPEN
813 printk("Shutting down serial port %d (irq %d)....", info->line,
814 state->irq);
815#endif
816
817 local_irq_save(flags);
818
819 idx = PORT_NUM(state->smc_scc_num);
820 if (state->smc_scc_num & NUM_IS_SCC) {
821 sccp = &pquicc->scc_regs[idx];
822 sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
823#ifdef CONFIG_SERIAL_CONSOLE
824 /* We can't disable the transmitter if this is the
825 * system console.
826 */
827 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
828#endif
829 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
830 } else {
831 smcp = &pquicc->smc_regs[idx];
832
833 /* Disable interrupts and I/O.
834 */
835 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
836#ifdef CONFIG_SERIAL_CONSOLE
837 /* We can't disable the transmitter if this is the
838 * system console.
839 */
840 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
841#endif
842 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
843 }
844
845 if (info->port.tty)
846 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
847
848 info->flags &= ~ASYNC_INITIALIZED;
849 local_irq_restore(flags);
850}
851
852/*
853 * This routine is called to set the UART divisor registers to match
854 * the specified baud rate for a serial port.
855 */
856static void change_speed(ser_info_t *info)
857{
858 int baud_rate;
859 unsigned cflag, cval, scval, prev_mode;
860 int i, bits, sbits, idx;
861 unsigned long flags;
862 struct serial_state *state;
863 volatile struct smc_regs *smcp;
864 volatile struct scc_regs *sccp;
865
866 if (!info->port.tty || !info->port.tty->termios)
867 return;
868 cflag = info->port.tty->termios->c_cflag;
869
870 state = info->state;
871
872 /* Character length programmed into the mode register is the
873 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
874 * 1 or 2 stop bits, minus 1.
875 * The value 'bits' counts this for us.
876 */
877 cval = 0;
878 scval = 0;
879
880 /* byte size and parity */
881 switch (cflag & CSIZE) {
882 case CS5: bits = 5; break;
883 case CS6: bits = 6; break;
884 case CS7: bits = 7; break;
885 case CS8: bits = 8; break;
886 /* Never happens, but GCC is too dumb to figure it out */
887 default: bits = 8; break;
888 }
889 sbits = bits - 5;
890
891 if (cflag & CSTOPB) {
892 cval |= SMCMR_SL; /* Two stops */
893 scval |= SCU_PMSR_SL;
894 bits++;
895 }
896 if (cflag & PARENB) {
897 cval |= SMCMR_PEN;
898 scval |= SCU_PMSR_PEN;
899 bits++;
900 }
901 if (!(cflag & PARODD)) {
902 cval |= SMCMR_PM_EVEN;
903 scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
904 }
905
906 /* Determine divisor based on baud rate */
907 i = cflag & CBAUD;
908 if (i >= (sizeof(baud_table)/sizeof(int)))
909 baud_rate = 9600;
910 else
911 baud_rate = baud_table[i];
912
913 info->timeout = (TX_BUF_SIZE*HZ*bits);
914 info->timeout += HZ/50; /* Add .02 seconds of slop */
915
916#ifdef modem_control
917 /* CTS flow control flag and modem status interrupts */
918 info->IER &= ~UART_IER_MSI;
919 if (info->flags & ASYNC_HARDPPS_CD)
920 info->IER |= UART_IER_MSI;
921 if (cflag & CRTSCTS) {
922 info->flags |= ASYNC_CTS_FLOW;
923 info->IER |= UART_IER_MSI;
924 } else
925 info->flags &= ~ASYNC_CTS_FLOW;
926 if (cflag & CLOCAL)
927 info->flags &= ~ASYNC_CHECK_CD;
928 else {
929 info->flags |= ASYNC_CHECK_CD;
930 info->IER |= UART_IER_MSI;
931 }
932 serial_out(info, UART_IER, info->IER);
933#endif
934
935 /*
936 * Set up parity check flag
937 */
938 info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
939 if (I_INPCK(info->port.tty))
940 info->read_status_mask |= BD_SC_FR | BD_SC_PR;
941 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
942 info->read_status_mask |= BD_SC_BR;
943
944 /*
945 * Characters to ignore
946 */
947 info->ignore_status_mask = 0;
948 if (I_IGNPAR(info->port.tty))
949 info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
950 if (I_IGNBRK(info->port.tty)) {
951 info->ignore_status_mask |= BD_SC_BR;
952 /*
953 * If we're ignore parity and break indicators, ignore
954 * overruns too. (For real raw support).
955 */
956 if (I_IGNPAR(info->port.tty))
957 info->ignore_status_mask |= BD_SC_OV;
958 }
959 /*
960 * !!! ignore all characters if CREAD is not set
961 */
962 if ((cflag & CREAD) == 0)
963 info->read_status_mask &= ~BD_SC_EMPTY;
964 local_irq_save(flags);
965
966 /* Start bit has not been added (so don't, because we would just
967 * subtract it later), and we need to add one for the number of
968 * stops bits (there is always at least one).
969 */
970 bits++;
971 idx = PORT_NUM(state->smc_scc_num);
972 if (state->smc_scc_num & NUM_IS_SCC) {
973 sccp = &pquicc->scc_regs[idx];
974 sccp->scc_psmr = (sbits << 12) | scval;
975 } else {
976 smcp = &pquicc->smc_regs[idx];
977
978 /* Set the mode register. We want to keep a copy of the
979 * enables, because we want to put them back if they were
980 * present.
981 */
982 prev_mode = smcp->smc_smcmr;
983 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
984 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
985 }
986
987 m360_cpm_setbrg((state - rs_table), baud_rate);
988
989 local_irq_restore(flags);
990}
991
992static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
993{
994 ser_info_t *info = (ser_info_t *)tty->driver_data;
995 volatile QUICC_BD *bdp;
996
997 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
998 return 0;
999
1000 if (!tty)
1001 return 0;
1002
1003 bdp = info->tx_cur;
1004 while (bdp->status & BD_SC_READY);
1005
1006 /* *((char *)__va(bdp->buf)) = ch; */
1007 *((char *)bdp->buf) = ch;
1008 bdp->length = 1;
1009 bdp->status |= BD_SC_READY;
1010
1011 /* Get next BD.
1012 */
1013 if (bdp->status & BD_SC_WRAP)
1014 bdp = info->tx_bd_base;
1015 else
1016 bdp++;
1017
1018 info->tx_cur = (QUICC_BD *)bdp;
1019 return 1;
1020
1021}
1022
1023static int rs_360_write(struct tty_struct * tty,
1024 const unsigned char *buf, int count)
1025{
1026 int c, ret = 0;
1027 ser_info_t *info = (ser_info_t *)tty->driver_data;
1028 volatile QUICC_BD *bdp;
1029
1030#ifdef CONFIG_KGDB
1031 /* Try to let stub handle output. Returns true if it did. */
1032 if (kgdb_output_string(buf, count))
1033 return ret;
1034#endif
1035
1036 if (serial_paranoia_check(info, tty->name, "rs_write"))
1037 return 0;
1038
1039 if (!tty)
1040 return 0;
1041
1042 bdp = info->tx_cur;
1043
1044 while (1) {
1045 c = min(count, TX_BUF_SIZE);
1046
1047 if (c <= 0)
1048 break;
1049
1050 if (bdp->status & BD_SC_READY) {
1051 info->flags |= TX_WAKEUP;
1052 break;
1053 }
1054
1055 /* memcpy(__va(bdp->buf), buf, c); */
1056 memcpy((void *)bdp->buf, buf, c);
1057
1058 bdp->length = c;
1059 bdp->status |= BD_SC_READY;
1060
1061 buf += c;
1062 count -= c;
1063 ret += c;
1064
1065 /* Get next BD.
1066 */
1067 if (bdp->status & BD_SC_WRAP)
1068 bdp = info->tx_bd_base;
1069 else
1070 bdp++;
1071 info->tx_cur = (QUICC_BD *)bdp;
1072 }
1073 return ret;
1074}
1075
1076static int rs_360_write_room(struct tty_struct *tty)
1077{
1078 ser_info_t *info = (ser_info_t *)tty->driver_data;
1079 int ret;
1080
1081 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1082 return 0;
1083
1084 if ((info->tx_cur->status & BD_SC_READY) == 0) {
1085 info->flags &= ~TX_WAKEUP;
1086 ret = TX_BUF_SIZE;
1087 }
1088 else {
1089 info->flags |= TX_WAKEUP;
1090 ret = 0;
1091 }
1092 return ret;
1093}
1094
1095/* I could track this with transmit counters....maybe later.
1096*/
1097static int rs_360_chars_in_buffer(struct tty_struct *tty)
1098{
1099 ser_info_t *info = (ser_info_t *)tty->driver_data;
1100
1101 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1102 return 0;
1103 return 0;
1104}
1105
1106static void rs_360_flush_buffer(struct tty_struct *tty)
1107{
1108 ser_info_t *info = (ser_info_t *)tty->driver_data;
1109
1110 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1111 return;
1112
1113 /* There is nothing to "flush", whatever we gave the CPM
1114 * is on its way out.
1115 */
1116 tty_wakeup(tty);
1117 info->flags &= ~TX_WAKEUP;
1118}
1119
1120/*
1121 * This function is used to send a high-priority XON/XOFF character to
1122 * the device
1123 */
1124static void rs_360_send_xchar(struct tty_struct *tty, char ch)
1125{
1126 volatile QUICC_BD *bdp;
1127
1128 ser_info_t *info = (ser_info_t *)tty->driver_data;
1129
1130 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
1131 return;
1132
1133 bdp = info->tx_cur;
1134 while (bdp->status & BD_SC_READY);
1135
1136 /* *((char *)__va(bdp->buf)) = ch; */
1137 *((char *)bdp->buf) = ch;
1138 bdp->length = 1;
1139 bdp->status |= BD_SC_READY;
1140
1141 /* Get next BD.
1142 */
1143 if (bdp->status & BD_SC_WRAP)
1144 bdp = info->tx_bd_base;
1145 else
1146 bdp++;
1147
1148 info->tx_cur = (QUICC_BD *)bdp;
1149}
1150
1151/*
1152 * ------------------------------------------------------------
1153 * rs_throttle()
1154 *
1155 * This routine is called by the upper-layer tty layer to signal that
1156 * incoming characters should be throttled.
1157 * ------------------------------------------------------------
1158 */
1159static void rs_360_throttle(struct tty_struct * tty)
1160{
1161 ser_info_t *info = (ser_info_t *)tty->driver_data;
1162#ifdef SERIAL_DEBUG_THROTTLE
1163 char buf[64];
1164
1165 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1166 tty->ldisc.chars_in_buffer(tty));
1167#endif
1168
1169 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1170 return;
1171
1172 if (I_IXOFF(tty))
1173 rs_360_send_xchar(tty, STOP_CHAR(tty));
1174
1175#ifdef modem_control
1176 if (tty->termios->c_cflag & CRTSCTS)
1177 info->MCR &= ~UART_MCR_RTS;
1178
1179 local_irq_disable();
1180 serial_out(info, UART_MCR, info->MCR);
1181 local_irq_enable();
1182#endif
1183}
1184
1185static void rs_360_unthrottle(struct tty_struct * tty)
1186{
1187 ser_info_t *info = (ser_info_t *)tty->driver_data;
1188#ifdef SERIAL_DEBUG_THROTTLE
1189 char buf[64];
1190
1191 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1192 tty->ldisc.chars_in_buffer(tty));
1193#endif
1194
1195 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1196 return;
1197
1198 if (I_IXOFF(tty)) {
1199 if (info->x_char)
1200 info->x_char = 0;
1201 else
1202 rs_360_send_xchar(tty, START_CHAR(tty));
1203 }
1204#ifdef modem_control
1205 if (tty->termios->c_cflag & CRTSCTS)
1206 info->MCR |= UART_MCR_RTS;
1207 local_irq_disable();
1208 serial_out(info, UART_MCR, info->MCR);
1209 local_irq_enable();
1210#endif
1211}
1212
1213/*
1214 * ------------------------------------------------------------
1215 * rs_ioctl() and friends
1216 * ------------------------------------------------------------
1217 */
1218
1219#ifdef maybe
1220/*
1221 * get_lsr_info - get line status register info
1222 *
1223 * Purpose: Let user call ioctl() to get info when the UART physically
1224 * is emptied. On bus types like RS485, the transmitter must
1225 * release the bus after transmitting. This must be done when
1226 * the transmit shift register is empty, not be done when the
1227 * transmit holding register is empty. This functionality
1228 * allows an RS485 driver to be written in user space.
1229 */
1230static int get_lsr_info(struct async_struct * info, unsigned int *value)
1231{
1232 unsigned char status;
1233 unsigned int result;
1234
1235 local_irq_disable();
1236 status = serial_in(info, UART_LSR);
1237 local_irq_enable();
1238 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1239 return put_user(result,value);
1240}
1241#endif
1242
1243static int rs_360_tiocmget(struct tty_struct *tty)
1244{
1245 ser_info_t *info = (ser_info_t *)tty->driver_data;
1246 unsigned int result = 0;
1247#ifdef modem_control
1248 unsigned char control, status;
1249
1250 if (serial_paranoia_check(info, tty->name, __func__))
1251 return -ENODEV;
1252
1253 if (tty->flags & (1 << TTY_IO_ERROR))
1254 return -EIO;
1255
1256 control = info->MCR;
1257 local_irq_disable();
1258 status = serial_in(info, UART_MSR);
1259 local_irq_enable();
1260 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1261 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1262#ifdef TIOCM_OUT1
1263 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
1264 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
1265#endif
1266 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1267 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1268 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1269 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1270#endif
1271 return result;
1272}
1273
1274static int rs_360_tiocmset(struct tty_struct *tty,
1275 unsigned int set, unsigned int clear)
1276{
1277#ifdef modem_control
1278 ser_info_t *info = (ser_info_t *)tty->driver_data;
1279 unsigned int arg;
1280
1281 if (serial_paranoia_check(info, tty->name, __func__))
1282 return -ENODEV;
1283
1284 if (tty->flags & (1 << TTY_IO_ERROR))
1285 return -EIO;
1286 /* FIXME: locking on info->mcr */
1287 if (set & TIOCM_RTS)
1288 info->mcr |= UART_MCR_RTS;
1289 if (set & TIOCM_DTR)
1290 info->mcr |= UART_MCR_DTR;
1291 if (clear & TIOCM_RTS)
1292 info->MCR &= ~UART_MCR_RTS;
1293 if (clear & TIOCM_DTR)
1294 info->MCR &= ~UART_MCR_DTR;
1295
1296#ifdef TIOCM_OUT1
1297 if (set & TIOCM_OUT1)
1298 info->MCR |= UART_MCR_OUT1;
1299 if (set & TIOCM_OUT2)
1300 info->MCR |= UART_MCR_OUT2;
1301 if (clear & TIOCM_OUT1)
1302 info->MCR &= ~UART_MCR_OUT1;
1303 if (clear & TIOCM_OUT2)
1304 info->MCR &= ~UART_MCR_OUT2;
1305#endif
1306
1307 local_irq_disable();
1308 serial_out(info, UART_MCR, info->MCR);
1309 local_irq_enable();
1310#endif
1311 return 0;
1312}
1313
1314/* Sending a break is a two step process on the SMC/SCC. It is accomplished
1315 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1316 * command. We take advantage of the begin/end functions to make this
1317 * happen.
1318 */
1319static ushort smc_chan_map[] = {
1320 CPM_CR_CH_SMC1,
1321 CPM_CR_CH_SMC2
1322};
1323
1324static ushort scc_chan_map[] = {
1325 CPM_CR_CH_SCC1,
1326 CPM_CR_CH_SCC2,
1327 CPM_CR_CH_SCC3,
1328 CPM_CR_CH_SCC4
1329};
1330
1331static void begin_break(ser_info_t *info)
1332{
1333 volatile QUICC *cp;
1334 ushort chan;
1335 int idx;
1336
1337 cp = pquicc;
1338
1339 idx = PORT_NUM(info->state->smc_scc_num);
1340 if (info->state->smc_scc_num & NUM_IS_SCC)
1341 chan = scc_chan_map[idx];
1342 else
1343 chan = smc_chan_map[idx];
1344
1345 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
1346 while (cp->cp_cr & CPM_CR_FLG);
1347}
1348
1349static void end_break(ser_info_t *info)
1350{
1351 volatile QUICC *cp;
1352 ushort chan;
1353 int idx;
1354
1355 cp = pquicc;
1356
1357 idx = PORT_NUM(info->state->smc_scc_num);
1358 if (info->state->smc_scc_num & NUM_IS_SCC)
1359 chan = scc_chan_map[idx];
1360 else
1361 chan = smc_chan_map[idx];
1362
1363 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
1364 while (cp->cp_cr & CPM_CR_FLG);
1365}
1366
1367/*
1368 * This routine sends a break character out the serial port.
1369 */
1370static void send_break(ser_info_t *info, unsigned int duration)
1371{
1372#ifdef SERIAL_DEBUG_SEND_BREAK
1373 printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
1374#endif
1375 begin_break(info);
1376 msleep_interruptible(duration);
1377 end_break(info);
1378#ifdef SERIAL_DEBUG_SEND_BREAK
1379 printk("done jiffies=%lu\n", jiffies);
1380#endif
1381}
1382
1383
1384/*
1385 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1386 * Return: write counters to the user passed counter struct
1387 * NB: both 1->0 and 0->1 transitions are counted except for
1388 * RI where only 0->1 is counted.
1389 */
1390static int rs_360_get_icount(struct tty_struct *tty,
1391 struct serial_icounter_struct *icount)
1392{
1393 ser_info_t *info = (ser_info_t *)tty->driver_data;
1394 struct async_icount cnow;
1395
1396 local_irq_disable();
1397 cnow = info->state->icount;
1398 local_irq_enable();
1399
1400 icount->cts = cnow.cts;
1401 icount->dsr = cnow.dsr;
1402 icount->rng = cnow.rng;
1403 icount->dcd = cnow.dcd;
1404
1405 return 0;
1406}
1407
1408static int rs_360_ioctl(struct tty_struct *tty,
1409 unsigned int cmd, unsigned long arg)
1410{
1411 int error;
1412 ser_info_t *info = (ser_info_t *)tty->driver_data;
1413 int retval;
1414 struct async_icount cnow;
1415 /* struct async_icount_24 cnow;*/ /* kernel counter temps */
1416 struct serial_icounter_struct *p_cuser; /* user space */
1417
1418 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1419 return -ENODEV;
1420
1421 if (cmd != TIOCMIWAIT) {
1422 if (tty->flags & (1 << TTY_IO_ERROR))
1423 return -EIO;
1424 }
1425
1426 switch (cmd) {
1427 case TCSBRK: /* SVID version: non-zero arg --> no break */
1428 retval = tty_check_change(tty);
1429 if (retval)
1430 return retval;
1431 tty_wait_until_sent(tty, 0);
1432 if (signal_pending(current))
1433 return -EINTR;
1434 if (!arg) {
1435 send_break(info, 250); /* 1/4 second */
1436 if (signal_pending(current))
1437 return -EINTR;
1438 }
1439 return 0;
1440 case TCSBRKP: /* support for POSIX tcsendbreak() */
1441 retval = tty_check_change(tty);
1442 if (retval)
1443 return retval;
1444 tty_wait_until_sent(tty, 0);
1445 if (signal_pending(current))
1446 return -EINTR;
1447 send_break(info, arg ? arg*100 : 250);
1448 if (signal_pending(current))
1449 return -EINTR;
1450 return 0;
1451 case TIOCSBRK:
1452 retval = tty_check_change(tty);
1453 if (retval)
1454 return retval;
1455 tty_wait_until_sent(tty, 0);
1456 begin_break(info);
1457 return 0;
1458 case TIOCCBRK:
1459 retval = tty_check_change(tty);
1460 if (retval)
1461 return retval;
1462 end_break(info);
1463 return 0;
1464#ifdef maybe
1465 case TIOCSERGETLSR: /* Get line status register */
1466 return get_lsr_info(info, (unsigned int *) arg);
1467#endif
1468 /*
1469 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1470 * - mask passed in arg for lines of interest
1471 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1472 * Caller should use TIOCGICOUNT to see which one it was
1473 */
1474 case TIOCMIWAIT:
1475#ifdef modem_control
1476 local_irq_disable();
1477 /* note the counters on entry */
1478 cprev = info->state->icount;
1479 local_irq_enable();
1480 while (1) {
1481 interruptible_sleep_on(&info->delta_msr_wait);
1482 /* see if a signal did it */
1483 if (signal_pending(current))
1484 return -ERESTARTSYS;
1485 local_irq_disable();
1486 cnow = info->state->icount; /* atomic copy */
1487 local_irq_enable();
1488 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1489 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1490 return -EIO; /* no change => error */
1491 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1492 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1493 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1494 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1495 return 0;
1496 }
1497 cprev = cnow;
1498 }
1499 /* NOTREACHED */
1500#else
1501 return 0;
1502#endif
1503
1504
1505 default:
1506 return -ENOIOCTLCMD;
1507 }
1508 return 0;
1509}
1510
1511/* FIX UP modem control here someday......
1512*/
1513static void rs_360_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1514{
1515 ser_info_t *info = (ser_info_t *)tty->driver_data;
1516
1517 change_speed(info);
1518
1519#ifdef modem_control
1520 /* Handle transition to B0 status */
1521 if ((old_termios->c_cflag & CBAUD) &&
1522 !(tty->termios->c_cflag & CBAUD)) {
1523 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1524 local_irq_disable();
1525 serial_out(info, UART_MCR, info->MCR);
1526 local_irq_enable();
1527 }
1528
1529 /* Handle transition away from B0 status */
1530 if (!(old_termios->c_cflag & CBAUD) &&
1531 (tty->termios->c_cflag & CBAUD)) {
1532 info->MCR |= UART_MCR_DTR;
1533 if (!tty->hw_stopped ||
1534 !(tty->termios->c_cflag & CRTSCTS)) {
1535 info->MCR |= UART_MCR_RTS;
1536 }
1537 local_irq_disable();
1538 serial_out(info, UART_MCR, info->MCR);
1539 local_irq_enable();
1540 }
1541
1542 /* Handle turning off CRTSCTS */
1543 if ((old_termios->c_cflag & CRTSCTS) &&
1544 !(tty->termios->c_cflag & CRTSCTS)) {
1545 tty->hw_stopped = 0;
1546 rs_360_start(tty);
1547 }
1548#endif
1549
1550#if 0
1551 /*
1552 * No need to wake up processes in open wait, since they
1553 * sample the CLOCAL flag once, and don't recheck it.
1554 * XXX It's not clear whether the current behavior is correct
1555 * or not. Hence, this may change.....
1556 */
1557 if (!(old_termios->c_cflag & CLOCAL) &&
1558 (tty->termios->c_cflag & CLOCAL))
1559 wake_up_interruptible(&info->open_wait);
1560#endif
1561}
1562
1563/*
1564 * ------------------------------------------------------------
1565 * rs_close()
1566 *
1567 * This routine is called when the serial port gets closed. First, we
1568 * wait for the last remaining data to be sent. Then, we unlink its
1569 * async structure from the interrupt chain if necessary, and we free
1570 * that IRQ if nothing is left in the chain.
1571 * ------------------------------------------------------------
1572 */
1573static void rs_360_close(struct tty_struct *tty, struct file * filp)
1574{
1575 ser_info_t *info = (ser_info_t *)tty->driver_data;
1576 /* struct async_state *state; */
1577 struct serial_state *state;
1578 unsigned long flags;
1579 int idx;
1580 volatile struct smc_regs *smcp;
1581 volatile struct scc_regs *sccp;
1582
1583 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1584 return;
1585
1586 state = info->state;
1587
1588 local_irq_save(flags);
1589
1590 if (tty_hung_up_p(filp)) {
1591 DBG_CNT("before DEC-hung");
1592 local_irq_restore(flags);
1593 return;
1594 }
1595
1596#ifdef SERIAL_DEBUG_OPEN
1597 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1598#endif
1599 if ((tty->count == 1) && (state->count != 1)) {
1600 /*
1601 * Uh, oh. tty->count is 1, which means that the tty
1602 * structure will be freed. state->count should always
1603 * be one in these conditions. If it's greater than
1604 * one, we've got real problems, since it means the
1605 * serial port won't be shutdown.
1606 */
1607 printk("rs_close: bad serial port count; tty->count is 1, "
1608 "state->count is %d\n", state->count);
1609 state->count = 1;
1610 }
1611 if (--state->count < 0) {
1612 printk("rs_close: bad serial port count for ttys%d: %d\n",
1613 info->line, state->count);
1614 state->count = 0;
1615 }
1616 if (state->count) {
1617 DBG_CNT("before DEC-2");
1618 local_irq_restore(flags);
1619 return;
1620 }
1621 info->flags |= ASYNC_CLOSING;
1622 /*
1623 * Now we wait for the transmit buffer to clear; and we notify
1624 * the line discipline to only process XON/XOFF characters.
1625 */
1626 tty->closing = 1;
1627 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1628 tty_wait_until_sent(tty, info->closing_wait);
1629 /*
1630 * At this point we stop accepting input. To do this, we
1631 * disable the receive line status interrupts, and tell the
1632 * interrupt driver to stop checking the data ready bit in the
1633 * line status register.
1634 */
1635 info->read_status_mask &= ~BD_SC_EMPTY;
1636 if (info->flags & ASYNC_INITIALIZED) {
1637
1638 idx = PORT_NUM(info->state->smc_scc_num);
1639 if (info->state->smc_scc_num & NUM_IS_SCC) {
1640 sccp = &pquicc->scc_regs[idx];
1641 sccp->scc_sccm &= ~UART_SCCM_RX;
1642 sccp->scc_gsmr.w.low &= ~SCC_GSMRL_ENR;
1643 } else {
1644 smcp = &pquicc->smc_regs[idx];
1645 smcp->smc_smcm &= ~SMCM_RX;
1646 smcp->smc_smcmr &= ~SMCMR_REN;
1647 }
1648 /*
1649 * Before we drop DTR, make sure the UART transmitter
1650 * has completely drained; this is especially
1651 * important if there is a transmit FIFO!
1652 */
1653 rs_360_wait_until_sent(tty, info->timeout);
1654 }
1655 shutdown(info);
1656 rs_360_flush_buffer(tty);
1657 tty_ldisc_flush(tty);
1658 tty->closing = 0;
1659 info->event = 0;
1660 info->port.tty = NULL;
1661 if (info->blocked_open) {
1662 if (info->close_delay) {
1663 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1664 }
1665 wake_up_interruptible(&info->open_wait);
1666 }
1667 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1668 wake_up_interruptible(&info->close_wait);
1669 local_irq_restore(flags);
1670}
1671
1672/*
1673 * rs_wait_until_sent() --- wait until the transmitter is empty
1674 */
1675static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1676{
1677 ser_info_t *info = (ser_info_t *)tty->driver_data;
1678 unsigned long orig_jiffies, char_time;
1679 /*int lsr;*/
1680 volatile QUICC_BD *bdp;
1681
1682 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1683 return;
1684
1685#ifdef maybe
1686 if (info->state->type == PORT_UNKNOWN)
1687 return;
1688#endif
1689
1690 orig_jiffies = jiffies;
1691 /*
1692 * Set the check interval to be 1/5 of the estimated time to
1693 * send a single character, and make it at least 1. The check
1694 * interval should also be less than the timeout.
1695 *
1696 * Note: we have to use pretty tight timings here to satisfy
1697 * the NIST-PCTS.
1698 */
1699 char_time = 1;
1700 if (timeout)
1701 char_time = min(char_time, (unsigned long)timeout);
1702#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1703 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1704 printk("jiff=%lu...", jiffies);
1705#endif
1706
1707 /* We go through the loop at least once because we can't tell
1708 * exactly when the last character exits the shifter. There can
1709 * be at least two characters waiting to be sent after the buffers
1710 * are empty.
1711 */
1712 do {
1713#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1714 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1715#endif
1716/* current->counter = 0; make us low-priority */
1717 msleep_interruptible(jiffies_to_msecs(char_time));
1718 if (signal_pending(current))
1719 break;
1720 if (timeout && (time_after(jiffies, orig_jiffies + timeout)))
1721 break;
1722 /* The 'tx_cur' is really the next buffer to send. We
1723 * have to back up to the previous BD and wait for it
1724 * to go. This isn't perfect, because all this indicates
1725 * is the buffer is available. There are still characters
1726 * in the CPM FIFO.
1727 */
1728 bdp = info->tx_cur;
1729 if (bdp == info->tx_bd_base)
1730 bdp += (TX_NUM_FIFO-1);
1731 else
1732 bdp--;
1733 } while (bdp->status & BD_SC_READY);
1734 current->state = TASK_RUNNING;
1735#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1736 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1737#endif
1738}
1739
1740/*
1741 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1742 */
1743static void rs_360_hangup(struct tty_struct *tty)
1744{
1745 ser_info_t *info = (ser_info_t *)tty->driver_data;
1746 struct serial_state *state = info->state;
1747
1748 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1749 return;
1750
1751 state = info->state;
1752
1753 rs_360_flush_buffer(tty);
1754 shutdown(info);
1755 info->event = 0;
1756 state->count = 0;
1757 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1758 info->port.tty = NULL;
1759 wake_up_interruptible(&info->open_wait);
1760}
1761
1762/*
1763 * ------------------------------------------------------------
1764 * rs_open() and friends
1765 * ------------------------------------------------------------
1766 */
1767static int block_til_ready(struct tty_struct *tty, struct file * filp,
1768 ser_info_t *info)
1769{
1770#ifdef DO_THIS_LATER
1771 DECLARE_WAITQUEUE(wait, current);
1772#endif
1773 struct serial_state *state = info->state;
1774 int retval;
1775 int do_clocal = 0;
1776
1777 /*
1778 * If the device is in the middle of being closed, then block
1779 * until it's done, and then try again.
1780 */
1781 if (tty_hung_up_p(filp) ||
1782 (info->flags & ASYNC_CLOSING)) {
1783 if (info->flags & ASYNC_CLOSING)
1784 interruptible_sleep_on(&info->close_wait);
1785#ifdef SERIAL_DO_RESTART
1786 if (info->flags & ASYNC_HUP_NOTIFY)
1787 return -EAGAIN;
1788 else
1789 return -ERESTARTSYS;
1790#else
1791 return -EAGAIN;
1792#endif
1793 }
1794
1795 /*
1796 * If non-blocking mode is set, or the port is not enabled,
1797 * then make the check up front and then exit.
1798 * If this is an SMC port, we don't have modem control to wait
1799 * for, so just get out here.
1800 */
1801 if ((filp->f_flags & O_NONBLOCK) ||
1802 (tty->flags & (1 << TTY_IO_ERROR)) ||
1803 !(info->state->smc_scc_num & NUM_IS_SCC)) {
1804 info->flags |= ASYNC_NORMAL_ACTIVE;
1805 return 0;
1806 }
1807
1808 if (tty->termios->c_cflag & CLOCAL)
1809 do_clocal = 1;
1810
1811 /*
1812 * Block waiting for the carrier detect and the line to become
1813 * free (i.e., not in use by the callout). While we are in
1814 * this loop, state->count is dropped by one, so that
1815 * rs_close() knows when to free things. We restore it upon
1816 * exit, either normal or abnormal.
1817 */
1818 retval = 0;
1819#ifdef DO_THIS_LATER
1820 add_wait_queue(&info->open_wait, &wait);
1821#ifdef SERIAL_DEBUG_OPEN
1822 printk("block_til_ready before block: ttys%d, count = %d\n",
1823 state->line, state->count);
1824#endif
1825 local_irq_disable();
1826 if (!tty_hung_up_p(filp))
1827 state->count--;
1828 local_irq_enable();
1829 info->blocked_open++;
1830 while (1) {
1831 local_irq_disable();
1832 if (tty->termios->c_cflag & CBAUD)
1833 serial_out(info, UART_MCR,
1834 serial_inp(info, UART_MCR) |
1835 (UART_MCR_DTR | UART_MCR_RTS));
1836 local_irq_enable();
1837 set_current_state(TASK_INTERRUPTIBLE);
1838 if (tty_hung_up_p(filp) ||
1839 !(info->flags & ASYNC_INITIALIZED)) {
1840#ifdef SERIAL_DO_RESTART
1841 if (info->flags & ASYNC_HUP_NOTIFY)
1842 retval = -EAGAIN;
1843 else
1844 retval = -ERESTARTSYS;
1845#else
1846 retval = -EAGAIN;
1847#endif
1848 break;
1849 }
1850 if (!(info->flags & ASYNC_CLOSING) &&
1851 (do_clocal || (serial_in(info, UART_MSR) &
1852 UART_MSR_DCD)))
1853 break;
1854 if (signal_pending(current)) {
1855 retval = -ERESTARTSYS;
1856 break;
1857 }
1858#ifdef SERIAL_DEBUG_OPEN
1859 printk("block_til_ready blocking: ttys%d, count = %d\n",
1860 info->line, state->count);
1861#endif
1862 tty_unlock(tty);
1863 schedule();
1864 tty_lock(tty);
1865 }
1866 current->state = TASK_RUNNING;
1867 remove_wait_queue(&info->open_wait, &wait);
1868 if (!tty_hung_up_p(filp))
1869 state->count++;
1870 info->blocked_open--;
1871#ifdef SERIAL_DEBUG_OPEN
1872 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1873 info->line, state->count);
1874#endif
1875#endif /* DO_THIS_LATER */
1876 if (retval)
1877 return retval;
1878 info->flags |= ASYNC_NORMAL_ACTIVE;
1879 return 0;
1880}
1881
1882static int get_async_struct(int line, ser_info_t **ret_info)
1883{
1884 struct serial_state *sstate;
1885
1886 sstate = rs_table + line;
1887 if (sstate->info) {
1888 sstate->count++;
1889 *ret_info = (ser_info_t *)sstate->info;
1890 return 0;
1891 }
1892 else {
1893 return -ENOMEM;
1894 }
1895}
1896
1897/*
1898 * This routine is called whenever a serial port is opened. It
1899 * enables interrupts for a serial port, linking in its async structure into
1900 * the IRQ chain. It also performs the serial-specific
1901 * initialization for the tty structure.
1902 */
1903static int rs_360_open(struct tty_struct *tty, struct file * filp)
1904{
1905 ser_info_t *info;
1906 int retval, line;
1907
1908 line = tty->index;
1909 if ((line < 0) || (line >= NR_PORTS))
1910 return -ENODEV;
1911 retval = get_async_struct(line, &info);
1912 if (retval)
1913 return retval;
1914 if (serial_paranoia_check(info, tty->name, "rs_open"))
1915 return -ENODEV;
1916
1917#ifdef SERIAL_DEBUG_OPEN
1918 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
1919#endif
1920 tty->driver_data = info;
1921 info->port.tty = tty;
1922
1923 /*
1924 * Start up serial port
1925 */
1926 retval = startup(info);
1927 if (retval)
1928 return retval;
1929
1930 retval = block_til_ready(tty, filp, info);
1931 if (retval) {
1932#ifdef SERIAL_DEBUG_OPEN
1933 printk("rs_open returning after block_til_ready with %d\n",
1934 retval);
1935#endif
1936 return retval;
1937 }
1938
1939#ifdef SERIAL_DEBUG_OPEN
1940 printk("rs_open %s successful...", tty->name);
1941#endif
1942 return 0;
1943}
1944
1945/*
1946 * /proc fs routines....
1947 */
1948
1949static inline int line_info(char *buf, struct serial_state *state)
1950{
1951#ifdef notdef
1952 struct async_struct *info = state->info, scr_info;
1953 char stat_buf[30], control, status;
1954#endif
1955 int ret;
1956
1957 ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
1958 state->line,
1959 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
1960 (unsigned int)(state->port), state->irq);
1961
1962 if (!state->port || (state->type == PORT_UNKNOWN)) {
1963 ret += sprintf(buf+ret, "\n");
1964 return ret;
1965 }
1966
1967#ifdef notdef
1968 /*
1969 * Figure out the current RS-232 lines
1970 */
1971 if (!info) {
1972 info = &scr_info; /* This is just for serial_{in,out} */
1973
1974 info->magic = SERIAL_MAGIC;
1975 info->port = state->port;
1976 info->flags = state->flags;
1977 info->quot = 0;
1978 info->port.tty = NULL;
1979 }
1980 local_irq_disable();
1981 status = serial_in(info, UART_MSR);
1982 control = info ? info->MCR : serial_in(info, UART_MCR);
1983 local_irq_enable();
1984
1985 stat_buf[0] = 0;
1986 stat_buf[1] = 0;
1987 if (control & UART_MCR_RTS)
1988 strcat(stat_buf, "|RTS");
1989 if (status & UART_MSR_CTS)
1990 strcat(stat_buf, "|CTS");
1991 if (control & UART_MCR_DTR)
1992 strcat(stat_buf, "|DTR");
1993 if (status & UART_MSR_DSR)
1994 strcat(stat_buf, "|DSR");
1995 if (status & UART_MSR_DCD)
1996 strcat(stat_buf, "|CD");
1997 if (status & UART_MSR_RI)
1998 strcat(stat_buf, "|RI");
1999
2000 if (info->quot) {
2001 ret += sprintf(buf+ret, " baud:%d",
2002 state->baud_base / info->quot);
2003 }
2004
2005 ret += sprintf(buf+ret, " tx:%d rx:%d",
2006 state->icount.tx, state->icount.rx);
2007
2008 if (state->icount.frame)
2009 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
2010
2011 if (state->icount.parity)
2012 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
2013
2014 if (state->icount.brk)
2015 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
2016
2017 if (state->icount.overrun)
2018 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
2019
2020 /*
2021 * Last thing is the RS-232 status lines
2022 */
2023 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
2024#endif
2025 return ret;
2026}
2027
2028int rs_360_read_proc(char *page, char **start, off_t off, int count,
2029 int *eof, void *data)
2030{
2031 int i, len = 0;
2032 off_t begin = 0;
2033
2034 len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
2035 for (i = 0; i < NR_PORTS && len < 4000; i++) {
2036 len += line_info(page + len, &rs_table[i]);
2037 if (len+begin > off+count)
2038 goto done;
2039 if (len+begin < off) {
2040 begin += len;
2041 len = 0;
2042 }
2043 }
2044 *eof = 1;
2045done:
2046 if (off >= len+begin)
2047 return 0;
2048 *start = page + (begin-off);
2049 return ((count < begin+len-off) ? count : begin+len-off);
2050}
2051
2052/*
2053 * ---------------------------------------------------------------------
2054 * rs_init() and friends
2055 *
2056 * rs_init() is called at boot-time to initialize the serial driver.
2057 * ---------------------------------------------------------------------
2058 */
2059
2060/*
2061 * This routine prints out the appropriate serial driver version
2062 * number, and identifies which options were configured into this
2063 * driver.
2064 */
2065static _INLINE_ void show_serial_version(void)
2066{
2067 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
2068}
2069
2070
2071/*
2072 * The serial console driver used during boot. Note that these names
2073 * clash with those found in "serial.c", so we currently can't support
2074 * the 16xxx uarts and these at the same time. I will fix this to become
2075 * an indirect function call from tty_io.c (or something).
2076 */
2077
2078#ifdef CONFIG_SERIAL_CONSOLE
2079
2080/*
2081 * Print a string to the serial port trying not to disturb any possible
2082 * real use of the port...
2083 */
2084static void my_console_write(int idx, const char *s,
2085 unsigned count)
2086{
2087 struct serial_state *ser;
2088 ser_info_t *info;
2089 unsigned i;
2090 QUICC_BD *bdp, *bdbase;
2091 volatile struct smc_uart_pram *up;
2092 volatile u_char *cp;
2093
2094 ser = rs_table + idx;
2095
2096
2097 /* If the port has been initialized for general use, we have
2098 * to use the buffer descriptors allocated there. Otherwise,
2099 * we simply use the single buffer allocated.
2100 */
2101 if ((info = (ser_info_t *)ser->info) != NULL) {
2102 bdp = info->tx_cur;
2103 bdbase = info->tx_bd_base;
2104 }
2105 else {
2106 /* Pointer to UART in parameter ram.
2107 */
2108 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2109 up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
2110
2111 /* Get the address of the host memory buffer.
2112 */
2113 bdp = bdbase = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
2114 }
2115
2116 /*
2117 * We need to gracefully shut down the transmitter, disable
2118 * interrupts, then send our bytes out.
2119 */
2120
2121 /*
2122 * Now, do each character. This is not as bad as it looks
2123 * since this is a holding FIFO and not a transmitting FIFO.
2124 * We could add the complexity of filling the entire transmit
2125 * buffer, but we would just wait longer between accesses......
2126 */
2127 for (i = 0; i < count; i++, s++) {
2128 /* Wait for transmitter fifo to empty.
2129 * Ready indicates output is ready, and xmt is doing
2130 * that, not that it is ready for us to send.
2131 */
2132 while (bdp->status & BD_SC_READY);
2133
2134 /* Send the character out.
2135 */
2136 cp = bdp->buf;
2137 *cp = *s;
2138
2139 bdp->length = 1;
2140 bdp->status |= BD_SC_READY;
2141
2142 if (bdp->status & BD_SC_WRAP)
2143 bdp = bdbase;
2144 else
2145 bdp++;
2146
2147 /* if a LF, also do CR... */
2148 if (*s == 10) {
2149 while (bdp->status & BD_SC_READY);
2150 /* cp = __va(bdp->buf); */
2151 cp = bdp->buf;
2152 *cp = 13;
2153 bdp->length = 1;
2154 bdp->status |= BD_SC_READY;
2155
2156 if (bdp->status & BD_SC_WRAP) {
2157 bdp = bdbase;
2158 }
2159 else {
2160 bdp++;
2161 }
2162 }
2163 }
2164
2165 /*
2166 * Finally, Wait for transmitter & holding register to empty
2167 * and restore the IER
2168 */
2169 while (bdp->status & BD_SC_READY);
2170
2171 if (info)
2172 info->tx_cur = (QUICC_BD *)bdp;
2173}
2174
2175static void serial_console_write(struct console *c, const char *s,
2176 unsigned count)
2177{
2178#ifdef CONFIG_KGDB
2179 /* Try to let stub handle output. Returns true if it did. */
2180 if (kgdb_output_string(s, count))
2181 return;
2182#endif
2183 my_console_write(c->index, s, count);
2184}
2185
2186
2187
2188/*void console_print_68360(const char *p)
2189{
2190 const char *cp = p;
2191 int i;
2192
2193 for (i=0;cp[i]!=0;i++);
2194
2195 serial_console_write (p, i);
2196
2197 //Comment this if you want to have a strict interrupt-driven output
2198 //rs_fair_output();
2199
2200 return;
2201}*/
2202
2203
2204
2205
2206
2207
2208#ifdef CONFIG_XMON
2209int
2210xmon_360_write(const char *s, unsigned count)
2211{
2212 my_console_write(0, s, count);
2213 return(count);
2214}
2215#endif
2216
2217#ifdef CONFIG_KGDB
2218void
2219putDebugChar(char ch)
2220{
2221 my_console_write(0, &ch, 1);
2222}
2223#endif
2224
2225/*
2226 * Receive character from the serial port. This only works well
2227 * before the port is initialized for real use.
2228 */
2229static int my_console_wait_key(int idx, int xmon, char *obuf)
2230{
2231 struct serial_state *ser;
2232 u_char c, *cp;
2233 ser_info_t *info;
2234 QUICC_BD *bdp;
2235 volatile struct smc_uart_pram *up;
2236 int i;
2237
2238 ser = rs_table + idx;
2239
2240 /* Get the address of the host memory buffer.
2241 * If the port has been initialized for general use, we must
2242 * use information from the port structure.
2243 */
2244 if ((info = (ser_info_t *)ser->info))
2245 bdp = info->rx_cur;
2246 else
2247 /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
2248 bdp = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
2249
2250 /* Pointer to UART in parameter ram.
2251 */
2252 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2253 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
2254
2255 /*
2256 * We need to gracefully shut down the receiver, disable
2257 * interrupts, then read the input.
2258 * XMON just wants a poll. If no character, return -1, else
2259 * return the character.
2260 */
2261 if (!xmon) {
2262 while (bdp->status & BD_SC_EMPTY);
2263 }
2264 else {
2265 if (bdp->status & BD_SC_EMPTY)
2266 return -1;
2267 }
2268
2269 cp = (char *)bdp->buf;
2270
2271 if (obuf) {
2272 i = c = bdp->length;
2273 while (i-- > 0)
2274 *obuf++ = *cp++;
2275 }
2276 else {
2277 c = *cp;
2278 }
2279 bdp->status |= BD_SC_EMPTY;
2280
2281 if (info) {
2282 if (bdp->status & BD_SC_WRAP) {
2283 bdp = info->rx_bd_base;
2284 }
2285 else {
2286 bdp++;
2287 }
2288 info->rx_cur = (QUICC_BD *)bdp;
2289 }
2290
2291 return((int)c);
2292}
2293
2294static int serial_console_wait_key(struct console *co)
2295{
2296 return(my_console_wait_key(co->index, 0, NULL));
2297}
2298
2299#ifdef CONFIG_XMON
2300int
2301xmon_360_read_poll(void)
2302{
2303 return(my_console_wait_key(0, 1, NULL));
2304}
2305
2306int
2307xmon_360_read_char(void)
2308{
2309 return(my_console_wait_key(0, 0, NULL));
2310}
2311#endif
2312
2313#ifdef CONFIG_KGDB
2314static char kgdb_buf[RX_BUF_SIZE], *kgdp;
2315static int kgdb_chars;
2316
2317unsigned char
2318getDebugChar(void)
2319{
2320 if (kgdb_chars <= 0) {
2321 kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);
2322 kgdp = kgdb_buf;
2323 }
2324 kgdb_chars--;
2325
2326 return(*kgdp++);
2327}
2328
2329void kgdb_interruptible(int state)
2330{
2331}
2332void kgdb_map_scc(void)
2333{
2334 struct serial_state *ser;
2335 uint mem_addr;
2336 volatile QUICC_BD *bdp;
2337 volatile smc_uart_t *up;
2338
2339 cpmp = (cpm360_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
2340
2341 /* To avoid data cache CPM DMA coherency problems, allocate a
2342 * buffer in the CPM DPRAM. This will work until the CPM and
2343 * serial ports are initialized. At that time a memory buffer
2344 * will be allocated.
2345 * The port is already initialized from the boot procedure, all
2346 * we do here is give it a different buffer and make it a FIFO.
2347 */
2348
2349 ser = rs_table;
2350
2351 /* Right now, assume we are using SMCs.
2352 */
2353 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2354
2355 /* Allocate space for an input FIFO, plus a few bytes for output.
2356 * Allocate bytes to maintain word alignment.
2357 */
2358 mem_addr = (uint)(&cpmp->cp_dpmem[0x1000]);
2359
2360 /* Set the physical address of the host memory buffers in
2361 * the buffer descriptors.
2362 */
2363 bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase];
2364 bdp->buf = mem_addr;
2365
2366 bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_tbase];
2367 bdp->buf = mem_addr+RX_BUF_SIZE;
2368
2369 up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
2370 up->smc_maxidl = RX_BUF_SIZE;
2371}
2372#endif
2373
2374static struct tty_struct *serial_console_device(struct console *c, int *index)
2375{
2376 *index = c->index;
2377 return serial_driver;
2378}
2379
2380
2381struct console sercons = {
2382 .name = "ttyS",
2383 .write = serial_console_write,
2384 .device = serial_console_device,
2385 .wait_key = serial_console_wait_key,
2386 .setup = serial_console_setup,
2387 .flags = CON_PRINTBUFFER,
2388 .index = CONFIG_SERIAL_CONSOLE_PORT,
2389};
2390
2391
2392
2393/*
2394 * Register console.
2395 */
2396long console_360_init(long kmem_start, long kmem_end)
2397{
2398 register_console(&sercons);
2399 /*register_console (console_print_68360); - 2.0.38 only required a write
2400 function pointer. */
2401 return kmem_start;
2402}
2403
2404#endif
2405
2406/* Index in baud rate table of the default console baud rate.
2407*/
2408static int baud_idx;
2409
2410static const struct tty_operations rs_360_ops = {
2411 .owner = THIS_MODULE,
2412 .open = rs_360_open,
2413 .close = rs_360_close,
2414 .write = rs_360_write,
2415 .put_char = rs_360_put_char,
2416 .write_room = rs_360_write_room,
2417 .chars_in_buffer = rs_360_chars_in_buffer,
2418 .flush_buffer = rs_360_flush_buffer,
2419 .ioctl = rs_360_ioctl,
2420 .throttle = rs_360_throttle,
2421 .unthrottle = rs_360_unthrottle,
2422 /* .send_xchar = rs_360_send_xchar, */
2423 .set_termios = rs_360_set_termios,
2424 .stop = rs_360_stop,
2425 .start = rs_360_start,
2426 .hangup = rs_360_hangup,
2427 /* .wait_until_sent = rs_360_wait_until_sent, */
2428 /* .read_proc = rs_360_read_proc, */
2429 .tiocmget = rs_360_tiocmget,
2430 .tiocmset = rs_360_tiocmset,
2431 .get_icount = rs_360_get_icount,
2432};
2433
2434static int __init rs_360_init(void)
2435{
2436 struct serial_state * state;
2437 ser_info_t *info;
2438 void *mem_addr;
2439 uint dp_addr, iobits;
2440 int i, j, idx;
2441 ushort chan;
2442 QUICC_BD *bdp;
2443 volatile QUICC *cp;
2444 volatile struct smc_regs *sp;
2445 volatile struct smc_uart_pram *up;
2446 volatile struct scc_regs *scp;
2447 volatile struct uart_pram *sup;
2448 /* volatile immap_t *immap; */
2449
2450 serial_driver = alloc_tty_driver(NR_PORTS);
2451 if (!serial_driver)
2452 return -1;
2453
2454 show_serial_version();
2455
2456 serial_driver->name = "ttyS";
2457 serial_driver->major = TTY_MAJOR;
2458 serial_driver->minor_start = 64;
2459 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2460 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2461 serial_driver->init_termios = tty_std_termios;
2462 serial_driver->init_termios.c_cflag =
2463 baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
2464 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2465 tty_set_operations(serial_driver, &rs_360_ops);
2466
2467 if (tty_register_driver(serial_driver))
2468 panic("Couldn't register serial driver\n");
2469
2470 cp = pquicc; /* Get pointer to Communication Processor */
2471 /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
2472
2473
2474 /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
2475 */
2476 /* The "standard" configuration through the 860.
2477 */
2478/* immap->im_ioport.iop_papar |= 0x00fc; */
2479/* immap->im_ioport.iop_padir &= ~0x00fc; */
2480/* immap->im_ioport.iop_paodr &= ~0x00fc; */
2481 cp->pio_papar |= 0x00fc;
2482 cp->pio_padir &= ~0x00fc;
2483 /* cp->pio_paodr &= ~0x00fc; */
2484
2485
2486 /* Since we don't yet do modem control, connect the port C pins
2487 * as general purpose I/O. This will assert CTS and CD for the
2488 * SCC ports.
2489 */
2490 /* FIXME: see 360um p.7-365 and 860um p.34-12
2491 * I can't make sense of these bits - mleslie*/
2492/* immap->im_ioport.iop_pcdir |= 0x03c6; */
2493/* immap->im_ioport.iop_pcpar &= ~0x03c6; */
2494
2495/* cp->pio_pcdir |= 0x03c6; */
2496/* cp->pio_pcpar &= ~0x03c6; */
2497
2498
2499
2500 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2501 * BRG4 to SCC3.
2502 */
2503 cp->si_sicr &= ~0x00ffff00;
2504 cp->si_sicr |= 0x001b1200;
2505
2506#ifdef CONFIG_PP04
2507 /* Frequentis PP04 forced to RS-232 until we know better.
2508 * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
2509 */
2510 immap->im_ioport.iop_pcdir |= 0x000c;
2511 immap->im_ioport.iop_pcpar &= ~0x000c;
2512 immap->im_ioport.iop_pcdat &= ~0x000c;
2513
2514 /* This enables the TX driver.
2515 */
2516 cp->cp_pbpar &= ~0x6000;
2517 cp->cp_pbdat &= ~0x6000;
2518#endif
2519
2520 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
2521 state->magic = SSTATE_MAGIC;
2522 state->line = i;
2523 state->type = PORT_UNKNOWN;
2524 state->custom_divisor = 0;
2525 state->close_delay = 5*HZ/10;
2526 state->closing_wait = 30*HZ;
2527 state->icount.cts = state->icount.dsr =
2528 state->icount.rng = state->icount.dcd = 0;
2529 state->icount.rx = state->icount.tx = 0;
2530 state->icount.frame = state->icount.parity = 0;
2531 state->icount.overrun = state->icount.brk = 0;
2532 printk(KERN_INFO "ttyS%d at irq 0x%02x is an %s\n",
2533 i, (unsigned int)(state->irq),
2534 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
2535
2536#ifdef CONFIG_SERIAL_CONSOLE
2537 /* If we just printed the message on the console port, and
2538 * we are about to initialize it for general use, we have
2539 * to wait a couple of character times for the CR/NL to
2540 * make it out of the transmit buffer.
2541 */
2542 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2543 mdelay(8);
2544
2545
2546/* idx = PORT_NUM(info->state->smc_scc_num); */
2547/* if (info->state->smc_scc_num & NUM_IS_SCC) */
2548/* chan = scc_chan_map[idx]; */
2549/* else */
2550/* chan = smc_chan_map[idx]; */
2551
2552/* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
2553/* while (cp->cp_cr & CPM_CR_FLG); */
2554
2555#endif
2556 /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
2557 info = &quicc_ser_info[i];
2558 if (info) {
2559 memset (info, 0, sizeof(ser_info_t));
2560 info->magic = SERIAL_MAGIC;
2561 info->line = i;
2562 info->flags = state->flags;
2563 INIT_WORK(&info->tqueue, do_softint, info);
2564 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
2565 init_waitqueue_head(&info->open_wait);
2566 init_waitqueue_head(&info->close_wait);
2567 info->state = state;
2568 state->info = (struct async_struct *)info;
2569
2570 /* We need to allocate a transmit and receive buffer
2571 * descriptors from dual port ram, and a character
2572 * buffer area from host mem.
2573 */
2574 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_NUM_FIFO);
2575
2576 /* Allocate space for FIFOs in the host memory.
2577 * (for now this is from a static array of buffers :(
2578 */
2579 /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
2580 /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
2581 mem_addr = &rx_buf_pool[i * RX_NUM_FIFO * RX_BUF_SIZE];
2582
2583 /* Set the physical address of the host memory
2584 * buffers in the buffer descriptors, and the
2585 * virtual address for us to work with.
2586 */
2587 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2588 info->rx_cur = info->rx_bd_base = bdp;
2589
2590 /* initialize rx buffer descriptors */
2591 for (j=0; j<(RX_NUM_FIFO-1); j++) {
2592 bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
2593 bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
2594 mem_addr += RX_BUF_SIZE;
2595 bdp++;
2596 }
2597 bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
2598 bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
2599
2600
2601 idx = PORT_NUM(info->state->smc_scc_num);
2602 if (info->state->smc_scc_num & NUM_IS_SCC) {
2603
2604#if defined (CONFIG_UCQUICC) && 1
2605 /* set the transceiver mode to RS232 */
2606 sipex_mode_bits &= ~(uint)SIPEX_MODE(idx,0x0f); /* clear current mode */
2607 sipex_mode_bits |= (uint)SIPEX_MODE(idx,0x02);
2608 *(uint *)_periph_base = sipex_mode_bits;
2609 /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
2610#endif
2611 }
2612
2613 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_NUM_FIFO);
2614
2615 /* Allocate space for FIFOs in the host memory.
2616 */
2617 /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
2618 /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
2619 mem_addr = &tx_buf_pool[i * TX_NUM_FIFO * TX_BUF_SIZE];
2620
2621 /* Set the physical address of the host memory
2622 * buffers in the buffer descriptors, and the
2623 * virtual address for us to work with.
2624 */
2625 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2626 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2627 info->tx_cur = info->tx_bd_base = (QUICC_BD *)bdp;
2628
2629 /* initialize tx buffer descriptors */
2630 for (j=0; j<(TX_NUM_FIFO-1); j++) {
2631 bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
2632 bdp->status = BD_SC_INTRPT;
2633 mem_addr += TX_BUF_SIZE;
2634 bdp++;
2635 }
2636 bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
2637 bdp->status = (BD_SC_WRAP | BD_SC_INTRPT);
2638
2639 if (info->state->smc_scc_num & NUM_IS_SCC) {
2640 scp = &pquicc->scc_regs[idx];
2641 sup = &pquicc->pram[info->state->port].scc.pscc.u;
2642 sup->rbase = dp_addr;
2643 sup->tbase = dp_addr;
2644
2645 /* Set up the uart parameters in the
2646 * parameter ram.
2647 */
2648 sup->rfcr = SMC_EB;
2649 sup->tfcr = SMC_EB;
2650
2651 /* Set this to 1 for now, so we get single
2652 * character interrupts. Using idle character
2653 * time requires some additional tuning.
2654 */
2655 sup->mrblr = 1;
2656 sup->max_idl = 0;
2657 sup->brkcr = 1;
2658 sup->parec = 0;
2659 sup->frmer = 0;
2660 sup->nosec = 0;
2661 sup->brkec = 0;
2662 sup->uaddr1 = 0;
2663 sup->uaddr2 = 0;
2664 sup->toseq = 0;
2665 {
2666 int i;
2667 for (i=0;i<8;i++)
2668 sup->cc[i] = 0x8000;
2669 }
2670 sup->rccm = 0xc0ff;
2671
2672 /* Send the CPM an initialize command.
2673 */
2674 chan = scc_chan_map[idx];
2675
2676 /* execute the INIT RX & TX PARAMS command for this channel. */
2677 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2678 while (cp->cp_cr & CPM_CR_FLG);
2679
2680 /* Set UART mode, 8 bit, no parity, one stop.
2681 * Enable receive and transmit.
2682 */
2683 scp->scc_gsmr.w.high = 0;
2684 scp->scc_gsmr.w.low =
2685 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2686
2687 /* Disable all interrupts and clear all pending
2688 * events.
2689 */
2690 scp->scc_sccm = 0;
2691 scp->scc_scce = 0xffff;
2692 scp->scc_dsr = 0x7e7e;
2693 scp->scc_psmr = 0x3000;
2694
2695 /* If the port is the console, enable Rx and Tx.
2696 */
2697#ifdef CONFIG_SERIAL_CONSOLE
2698 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2699 scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2700#endif
2701 }
2702 else {
2703 /* Configure SMCs Tx/Rx instead of port B
2704 * parallel I/O.
2705 */
2706 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
2707 up->rbase = dp_addr;
2708
2709 iobits = 0xc0 << (idx * 4);
2710 cp->pip_pbpar |= iobits;
2711 cp->pip_pbdir &= ~iobits;
2712 cp->pip_pbodr &= ~iobits;
2713
2714
2715 /* Connect the baud rate generator to the
2716 * SMC based upon index in rs_table. Also
2717 * make sure it is connected to NMSI.
2718 */
2719 cp->si_simode &= ~(0xffff << (idx * 16));
2720 cp->si_simode |= (i << ((idx * 16) + 12));
2721
2722 up->tbase = dp_addr;
2723
2724 /* Set up the uart parameters in the
2725 * parameter ram.
2726 */
2727 up->rfcr = SMC_EB;
2728 up->tfcr = SMC_EB;
2729
2730 /* Set this to 1 for now, so we get single
2731 * character interrupts. Using idle character
2732 * time requires some additional tuning.
2733 */
2734 up->mrblr = 1;
2735 up->max_idl = 0;
2736 up->brkcr = 1;
2737
2738 /* Send the CPM an initialize command.
2739 */
2740 chan = smc_chan_map[idx];
2741
2742 cp->cp_cr = mk_cr_cmd(chan,
2743 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2744#ifdef CONFIG_SERIAL_CONSOLE
2745 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2746 printk("");
2747#endif
2748 while (cp->cp_cr & CPM_CR_FLG);
2749
2750 /* Set UART mode, 8 bit, no parity, one stop.
2751 * Enable receive and transmit.
2752 */
2753 sp = &cp->smc_regs[idx];
2754 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2755
2756 /* Disable all interrupts and clear all pending
2757 * events.
2758 */
2759 sp->smc_smcm = 0;
2760 sp->smc_smce = 0xff;
2761
2762 /* If the port is the console, enable Rx and Tx.
2763 */
2764#ifdef CONFIG_SERIAL_CONSOLE
2765 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2766 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2767#endif
2768 }
2769
2770 /* Install interrupt handler.
2771 */
2772 /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
2773 /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
2774 request_irq(state->irq, rs_360_interrupt, 0, "ttyS",
2775 (void *)info);
2776
2777 /* Set up the baud rate generator.
2778 */
2779 m360_cpm_setbrg(i, baud_table[baud_idx]);
2780
2781 }
2782 }
2783
2784 return 0;
2785}
2786module_init(rs_360_init);
2787
2788/* This must always be called before the rs_360_init() function, otherwise
2789 * it blows away the port control information.
2790 */
2791//static int __init serial_console_setup( struct console *co, char *options)
2792int serial_console_setup( struct console *co, char *options)
2793{
2794 struct serial_state *ser;
2795 uint mem_addr, dp_addr, bidx, idx, iobits;
2796 ushort chan;
2797 QUICC_BD *bdp;
2798 volatile QUICC *cp;
2799 volatile struct smc_regs *sp;
2800 volatile struct scc_regs *scp;
2801 volatile struct smc_uart_pram *up;
2802 volatile struct uart_pram *sup;
2803
2804/* mleslie TODO:
2805 * add something to the 68k bootloader to store a desired initial console baud rate */
2806
2807/* bd_t *bd; */ /* a board info struct used by EPPC-bug */
2808/* bd = (bd_t *)__res; */
2809
2810 for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
2811 /* if (bd->bi_baudrate == baud_table[bidx]) */
2812 if (CONSOLE_BAUDRATE == baud_table[bidx])
2813 break;
2814
2815 /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
2816 baud_idx = bidx;
2817
2818 ser = rs_table + CONFIG_SERIAL_CONSOLE_PORT;
2819
2820 cp = pquicc; /* Get pointer to Communication Processor */
2821
2822 idx = PORT_NUM(ser->smc_scc_num);
2823 if (ser->smc_scc_num & NUM_IS_SCC) {
2824
2825 /* TODO: need to set up SCC pin assignment etc. here */
2826
2827 }
2828 else {
2829 iobits = 0xc0 << (idx * 4);
2830 cp->pip_pbpar |= iobits;
2831 cp->pip_pbdir &= ~iobits;
2832 cp->pip_pbodr &= ~iobits;
2833
2834 /* Connect the baud rate generator to the
2835 * SMC based upon index in rs_table. Also
2836 * make sure it is connected to NMSI.
2837 */
2838 cp->si_simode &= ~(0xffff << (idx * 16));
2839 cp->si_simode |= (idx << ((idx * 16) + 12));
2840 }
2841
2842 /* When we get here, the CPM has been reset, so we need
2843 * to configure the port.
2844 * We need to allocate a transmit and receive buffer descriptor
2845 * from dual port ram, and a character buffer area from host mem.
2846 */
2847
2848 /* Allocate space for two buffer descriptors in the DP ram.
2849 */
2850 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * CONSOLE_NUM_FIFO);
2851
2852 /* Allocate space for two 2 byte FIFOs in the host memory.
2853 */
2854 /* mem_addr = m360_cpm_hostalloc(8); */
2855 mem_addr = (uint)console_fifos;
2856
2857
2858 /* Set the physical address of the host memory buffers in
2859 * the buffer descriptors.
2860 */
2861 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2862 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2863 bdp->buf = (char *)mem_addr;
2864 (bdp+1)->buf = (char *)(mem_addr+4);
2865
2866 /* For the receive, set empty and wrap.
2867 * For transmit, set wrap.
2868 */
2869 bdp->status = BD_SC_EMPTY | BD_SC_WRAP;
2870 (bdp+1)->status = BD_SC_WRAP;
2871
2872 /* Set up the uart parameters in the parameter ram.
2873 */
2874 if (ser->smc_scc_num & NUM_IS_SCC) {
2875 scp = &cp->scc_regs[idx];
2876 /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
2877 sup = &pquicc->pram[ser->port].scc.pscc.u;
2878
2879 sup->rbase = dp_addr;
2880 sup->tbase = dp_addr + sizeof(QUICC_BD);
2881
2882 /* Set up the uart parameters in the
2883 * parameter ram.
2884 */
2885 sup->rfcr = SMC_EB;
2886 sup->tfcr = SMC_EB;
2887
2888 /* Set this to 1 for now, so we get single
2889 * character interrupts. Using idle character
2890 * time requires some additional tuning.
2891 */
2892 sup->mrblr = 1;
2893 sup->max_idl = 0;
2894 sup->brkcr = 1;
2895 sup->parec = 0;
2896 sup->frmer = 0;
2897 sup->nosec = 0;
2898 sup->brkec = 0;
2899 sup->uaddr1 = 0;
2900 sup->uaddr2 = 0;
2901 sup->toseq = 0;
2902 {
2903 int i;
2904 for (i=0;i<8;i++)
2905 sup->cc[i] = 0x8000;
2906 }
2907 sup->rccm = 0xc0ff;
2908
2909 /* Send the CPM an initialize command.
2910 */
2911 chan = scc_chan_map[idx];
2912
2913 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2914 while (cp->cp_cr & CPM_CR_FLG);
2915
2916 /* Set UART mode, 8 bit, no parity, one stop.
2917 * Enable receive and transmit.
2918 */
2919 scp->scc_gsmr.w.high = 0;
2920 scp->scc_gsmr.w.low =
2921 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2922
2923 /* Disable all interrupts and clear all pending
2924 * events.
2925 */
2926 scp->scc_sccm = 0;
2927 scp->scc_scce = 0xffff;
2928 scp->scc_dsr = 0x7e7e;
2929 scp->scc_psmr = 0x3000;
2930
2931 scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2932
2933 }
2934 else {
2935 /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
2936 up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
2937
2938 up->rbase = dp_addr; /* Base of receive buffer desc. */
2939 up->tbase = dp_addr+sizeof(QUICC_BD); /* Base of xmt buffer desc. */
2940 up->rfcr = SMC_EB;
2941 up->tfcr = SMC_EB;
2942
2943 /* Set this to 1 for now, so we get single character interrupts.
2944 */
2945 up->mrblr = 1; /* receive buffer length */
2946 up->max_idl = 0; /* wait forever for next char */
2947
2948 /* Send the CPM an initialize command.
2949 */
2950 chan = smc_chan_map[idx];
2951 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2952 while (cp->cp_cr & CPM_CR_FLG);
2953
2954 /* Set UART mode, 8 bit, no parity, one stop.
2955 * Enable receive and transmit.
2956 */
2957 sp = &cp->smc_regs[idx];
2958 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2959
2960 /* And finally, enable Rx and Tx.
2961 */
2962 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2963 }
2964
2965 /* Set up the baud rate generator.
2966 */
2967 /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
2968 m360_cpm_setbrg((ser - rs_table), CONSOLE_BAUDRATE);
2969
2970 return 0;
2971}
2972
2973/*
2974 * Local variables:
2975 * c-indent-level: 4
2976 * c-basic-offset: 4
2977 * tab-width: 4
2978 * End:
2979 */
diff --git a/drivers/staging/serial/Kconfig b/drivers/staging/serial/Kconfig
deleted file mode 100644
index 9489688397e0..000000000000
--- a/drivers/staging/serial/Kconfig
+++ /dev/null
@@ -1,16 +0,0 @@
1config SERIAL_68360_SMC
2 bool "68360 SMC uart support"
3 depends on M68360
4 help
5 This driver supports the SMC serial ports of the Motorola 68360 CPU.
6
7config SERIAL_68360_SCC
8 bool "68360 SCC uart support"
9 depends on M68360
10 help
11 This driver supports the SCC serial ports of the Motorola 68360 CPU.
12
13config SERIAL_68360
14 bool
15 depends on SERIAL_68360_SMC || SERIAL_68360_SCC
16 default y
diff --git a/drivers/staging/serial/Makefile b/drivers/staging/serial/Makefile
deleted file mode 100644
index 37a6a0b35fba..000000000000
--- a/drivers/staging/serial/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_SERIAL_68360) += 68360serial.o
diff --git a/drivers/staging/serial/TODO b/drivers/staging/serial/TODO
deleted file mode 100644
index a19cda81dab4..000000000000
--- a/drivers/staging/serial/TODO
+++ /dev/null
@@ -1,6 +0,0 @@
1These are a few serial drivers that either do not build, or do not work if they
2do build, or if they seem to work, are for obsolete hardware, or are full of
3unfixable races and no one uses them anymore.
4
5If no one steps up to adopt any of these drivers, they will be removed
6in the 3.4 release.
diff --git a/drivers/staging/sm7xx/smtcfb.c b/drivers/staging/sm7xx/smtcfb.c
index 83c582ed12e5..746c4cd5d30e 100644
--- a/drivers/staging/sm7xx/smtcfb.c
+++ b/drivers/staging/sm7xx/smtcfb.c
@@ -2,31 +2,19 @@
2 * Silicon Motion SM7XX frame buffer device 2 * Silicon Motion SM7XX frame buffer device
3 * 3 *
4 * Copyright (C) 2006 Silicon Motion Technology Corp. 4 * Copyright (C) 2006 Silicon Motion Technology Corp.
5 * Authors: Ge Wang, gewang@siliconmotion.com 5 * Authors: Ge Wang, gewang@siliconmotion.com
6 * Boyod boyod.yang@siliconmotion.com.cn 6 * Boyod boyod.yang@siliconmotion.com.cn
7 * 7 *
8 * Copyright (C) 2009 Lemote, Inc. 8 * Copyright (C) 2009 Lemote, Inc.
9 * Author: Wu Zhangjin, wuzhangjin@gmail.com 9 * Author: Wu Zhangjin, wuzhangjin@gmail.com
10 * 10 *
11 * Copyright (C) 2011 Igalia, S.L. 11 * Copyright (C) 2011 Igalia, S.L.
12 * Author: Javier M. Mellid <jmunhoz@igalia.com> 12 * Author: Javier M. Mellid <jmunhoz@igalia.com>
13 * 13 *
14 * This file is subject to the terms and conditions of the GNU General Public 14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file COPYING in the main directory of this archive for 15 * License. See the file COPYING in the main directory of this archive for
16 * more details. 16 * more details.
17 * 17 *
18 * Version 0.10.26192.21.01
19 * - Add PowerPC/Big endian support
20 * - Verified on 2.6.19.2
21 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
22 *
23 * Version 0.09.2621.00.01
24 * - Only support Linux Kernel's version 2.6.21
25 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
26 *
27 * Version 0.09
28 * - Only support Linux Kernel's version 2.6.12
29 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
30 */ 18 */
31 19
32#include <linux/io.h> 20#include <linux/io.h>
@@ -45,40 +33,19 @@
45 33
46#include "smtcfb.h" 34#include "smtcfb.h"
47 35
48#ifdef DEBUG
49#define smdbg(format, arg...) printk(KERN_DEBUG format , ## arg)
50#else
51#define smdbg(format, arg...)
52#endif
53
54struct screen_info smtc_screen_info; 36struct screen_info smtc_screen_info;
55 37
56/* 38/*
57* Private structure 39* Private structure
58*/ 40*/
59struct smtcfb_info { 41struct smtcfb_info {
60 /*
61 * The following is a pointer to be passed into the
62 * functions below. The modules outside the main
63 * voyager.c driver have no knowledge as to what
64 * is within this structure.
65 */
66 struct fb_info fb; 42 struct fb_info fb;
67 struct display_switch *dispsw; 43 struct pci_dev *pdev;
68 struct pci_dev *dev;
69 signed int currcon;
70
71 struct { 44 struct {
72 u8 red, green, blue; 45 u8 red, green, blue;
73 } palette[NR_RGB]; 46 } palette[NR_RGB];
74
75 u_int palette_size; 47 u_int palette_size;
76};
77 48
78struct par_info {
79 /*
80 * Hardware
81 */
82 u16 chipID; 49 u16 chipID;
83 unsigned char __iomem *m_pMMIO; 50 unsigned char __iomem *m_pMMIO;
84 char __iomem *m_pLFB; 51 char __iomem *m_pLFB;
@@ -121,15 +88,6 @@ char __iomem *smtc_RegBaseAddress; /* Memory Map IO starting address */
121char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */ 88char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */
122 89
123static u32 colreg[17]; 90static u32 colreg[17];
124static struct par_info hw; /* hardware information */
125
126u16 smtc_ChipIDs[] = {
127 0x710,
128 0x712,
129 0x720
130};
131
132#define numSMTCchipIDs ARRAY_SIZE(smtc_ChipIDs)
133 91
134static struct fb_var_screeninfo smtcfb_var = { 92static struct fb_var_screeninfo smtcfb_var = {
135 .xres = 1024, 93 .xres = 1024,
@@ -154,30 +112,29 @@ static struct fb_fix_screeninfo smtcfb_fix = {
154 .accel = FB_ACCEL_SMI_LYNX, 112 .accel = FB_ACCEL_SMI_LYNX,
155}; 113};
156 114
157static void sm712_set_timing(struct smtcfb_info *sfb, 115static void sm712_set_timing(struct smtcfb_info *sfb)
158 struct par_info *ppar_info)
159{ 116{
160 int i = 0, j = 0; 117 int i = 0, j = 0;
161 u32 m_nScreenStride; 118 u32 m_nScreenStride;
162 119
163 smdbg("\nppar_info->width = %d ppar_info->height = %d" 120 dev_dbg(&sfb->pdev->dev,
164 "sfb->fb.var.bits_per_pixel = %d ppar_info->hz = %d\n", 121 "sfb->width=%d sfb->height=%d "
165 ppar_info->width, ppar_info->height, 122 "sfb->fb.var.bits_per_pixel=%d sfb->hz=%d\n",
166 sfb->fb.var.bits_per_pixel, ppar_info->hz); 123 sfb->width, sfb->height, sfb->fb.var.bits_per_pixel, sfb->hz);
167 124
168 for (j = 0; j < numVGAModes; j++) { 125 for (j = 0; j < numVGAModes; j++) {
169 if (VGAMode[j].mmSizeX == ppar_info->width && 126 if (VGAMode[j].mmSizeX == sfb->width &&
170 VGAMode[j].mmSizeY == ppar_info->height && 127 VGAMode[j].mmSizeY == sfb->height &&
171 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel && 128 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel &&
172 VGAMode[j].hz == ppar_info->hz) { 129 VGAMode[j].hz == sfb->hz) {
173 130
174 smdbg("\nVGAMode[j].mmSizeX = %d VGAMode[j].mmSizeY =" 131 dev_dbg(&sfb->pdev->dev,
175 "%d VGAMode[j].bpp = %d" 132 "VGAMode[j].mmSizeX=%d VGAMode[j].mmSizeY=%d "
176 "VGAMode[j].hz=%d\n", 133 "VGAMode[j].bpp=%d VGAMode[j].hz=%d\n",
177 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY, 134 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY,
178 VGAMode[j].bpp, VGAMode[j].hz); 135 VGAMode[j].bpp, VGAMode[j].hz);
179 136
180 smdbg("VGAMode index=%d\n", j); 137 dev_dbg(&sfb->pdev->dev, "VGAMode index=%d\n", j);
181 138
182 smtc_mmiowb(0x0, 0x3c6); 139 smtc_mmiowb(0x0, 0x3c6);
183 140
@@ -238,37 +195,37 @@ static void sm712_set_timing(struct smtcfb_info *sfb,
238 smtc_mmiowb(0x67, 0x3c2); 195 smtc_mmiowb(0x67, 0x3c2);
239 196
240 /* set VPR registers */ 197 /* set VPR registers */
241 writel(0x0, ppar_info->m_pVPR + 0x0C); 198 writel(0x0, sfb->m_pVPR + 0x0C);
242 writel(0x0, ppar_info->m_pVPR + 0x40); 199 writel(0x0, sfb->m_pVPR + 0x40);
243 200
244 /* set data width */ 201 /* set data width */
245 m_nScreenStride = 202 m_nScreenStride =
246 (ppar_info->width * sfb->fb.var.bits_per_pixel) / 64; 203 (sfb->width * sfb->fb.var.bits_per_pixel) / 64;
247 switch (sfb->fb.var.bits_per_pixel) { 204 switch (sfb->fb.var.bits_per_pixel) {
248 case 8: 205 case 8:
249 writel(0x0, ppar_info->m_pVPR + 0x0); 206 writel(0x0, sfb->m_pVPR + 0x0);
250 break; 207 break;
251 case 16: 208 case 16:
252 writel(0x00020000, ppar_info->m_pVPR + 0x0); 209 writel(0x00020000, sfb->m_pVPR + 0x0);
253 break; 210 break;
254 case 24: 211 case 24:
255 writel(0x00040000, ppar_info->m_pVPR + 0x0); 212 writel(0x00040000, sfb->m_pVPR + 0x0);
256 break; 213 break;
257 case 32: 214 case 32:
258 writel(0x00030000, ppar_info->m_pVPR + 0x0); 215 writel(0x00030000, sfb->m_pVPR + 0x0);
259 break; 216 break;
260 } 217 }
261 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride), 218 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride),
262 ppar_info->m_pVPR + 0x10); 219 sfb->m_pVPR + 0x10);
263 220
264} 221}
265 222
266static void sm712_setpalette(int regno, unsigned red, unsigned green, 223static void sm712_setpalette(int regno, unsigned red, unsigned green,
267 unsigned blue, struct fb_info *info) 224 unsigned blue, struct fb_info *info)
268{ 225{
269 struct par_info *cur_par = (struct par_info *)info->par; 226 struct smtcfb_info *sfb = info->par;
270 227
271 if (cur_par->BaseAddressInVRAM) 228 if (sfb->BaseAddressInVRAM)
272 /* 229 /*
273 * second display palette for dual head. Enable CRT RAM, 6-bit 230 * second display palette for dual head. Enable CRT RAM, 6-bit
274 * RAM 231 * RAM
@@ -283,14 +240,13 @@ static void sm712_setpalette(int regno, unsigned red, unsigned green,
283 smtc_mmiowb(blue >> 10, dac_val); 240 smtc_mmiowb(blue >> 10, dac_val);
284} 241}
285 242
286static void smtc_set_timing(struct smtcfb_info *sfb, struct par_info 243static void smtc_set_timing(struct smtcfb_info *sfb)
287 *ppar_info)
288{ 244{
289 switch (ppar_info->chipID) { 245 switch (sfb->chipID) {
290 case 0x710: 246 case 0x710:
291 case 0x712: 247 case 0x712:
292 case 0x720: 248 case 0x720:
293 sm712_set_timing(sfb, ppar_info); 249 sm712_set_timing(sfb);
294 break; 250 break;
295 } 251 }
296} 252}
@@ -310,7 +266,7 @@ static inline unsigned int chan_to_field(unsigned int chan,
310 return chan << bf->offset; 266 return chan << bf->offset;
311} 267}
312 268
313static int cfb_blank(int blank_mode, struct fb_info *info) 269static int smtc_blank(int blank_mode, struct fb_info *info)
314{ 270{
315 /* clear DPMS setting */ 271 /* clear DPMS setting */
316 switch (blank_mode) { 272 switch (blank_mode) {
@@ -660,10 +616,10 @@ void smtcfb_setmode(struct smtcfb_info *sfb)
660 break; 616 break;
661 } 617 }
662 618
663 hw.width = sfb->fb.var.xres; 619 sfb->width = sfb->fb.var.xres;
664 hw.height = sfb->fb.var.yres; 620 sfb->height = sfb->fb.var.yres;
665 hw.hz = 60; 621 sfb->hz = 60;
666 smtc_set_timing(sfb, &hw); 622 smtc_set_timing(sfb);
667} 623}
668 624
669static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 625static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -697,7 +653,7 @@ static struct fb_ops smtcfb_ops = {
697 .fb_check_var = smtc_check_var, 653 .fb_check_var = smtc_check_var,
698 .fb_set_par = smtc_set_par, 654 .fb_set_par = smtc_set_par,
699 .fb_setcolreg = smtc_setcolreg, 655 .fb_setcolreg = smtc_setcolreg,
700 .fb_blank = cfb_blank, 656 .fb_blank = smtc_blank,
701 .fb_fillrect = cfb_fillrect, 657 .fb_fillrect = cfb_fillrect,
702 .fb_imageblit = cfb_imageblit, 658 .fb_imageblit = cfb_imageblit,
703 .fb_copyarea = cfb_copyarea, 659 .fb_copyarea = cfb_copyarea,
@@ -710,8 +666,7 @@ static struct fb_ops smtcfb_ops = {
710/* 666/*
711 * Alloc struct smtcfb_info and assign the default value 667 * Alloc struct smtcfb_info and assign the default value
712 */ 668 */
713static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *dev, 669static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *pdev, char *name)
714 char *name)
715{ 670{
716 struct smtcfb_info *sfb; 671 struct smtcfb_info *sfb;
717 672
@@ -720,8 +675,7 @@ static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *dev,
720 if (!sfb) 675 if (!sfb)
721 return NULL; 676 return NULL;
722 677
723 sfb->currcon = -1; 678 sfb->pdev = pdev;
724 sfb->dev = dev;
725 679
726 /*** Init sfb->fb with default value ***/ 680 /*** Init sfb->fb with default value ***/
727 sfb->fb.flags = FBINFO_FLAG_DEFAULT; 681 sfb->fb.flags = FBINFO_FLAG_DEFAULT;
@@ -745,7 +699,9 @@ static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *dev,
745 /* text mode acceleration */ 699 /* text mode acceleration */
746 sfb->fb.var.accel_flags = FB_ACCELF_TEXT; 700 sfb->fb.var.accel_flags = FB_ACCELF_TEXT;
747 sfb->fb.var.vmode = FB_VMODE_NONINTERLACED; 701 sfb->fb.var.vmode = FB_VMODE_NONINTERLACED;
748 sfb->fb.par = &hw; 702
703 sfb->fb.par = sfb;
704
749 sfb->fb.pseudo_palette = colreg; 705 sfb->fb.pseudo_palette = colreg;
750 706
751 return sfb; 707 return sfb;
@@ -766,17 +722,17 @@ static void smtc_unmap_mmio(struct smtcfb_info *sfb)
766 */ 722 */
767 723
768static int smtc_map_smem(struct smtcfb_info *sfb, 724static int smtc_map_smem(struct smtcfb_info *sfb,
769 struct pci_dev *dev, u_long smem_len) 725 struct pci_dev *pdev, u_long smem_len)
770{ 726{
771 if (sfb->fb.var.bits_per_pixel == 32) { 727 if (sfb->fb.var.bits_per_pixel == 32) {
772#ifdef __BIG_ENDIAN 728#ifdef __BIG_ENDIAN
773 sfb->fb.fix.smem_start = pci_resource_start(dev, 0) 729 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0)
774 + 0x800000; 730 + 0x800000;
775#else 731#else
776 sfb->fb.fix.smem_start = pci_resource_start(dev, 0); 732 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
777#endif 733#endif
778 } else { 734 } else {
779 sfb->fb.fix.smem_start = pci_resource_start(dev, 0); 735 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
780 } 736 }
781 737
782 sfb->fb.fix.smem_len = smem_len; 738 sfb->fb.fix.smem_len = smem_len;
@@ -784,8 +740,8 @@ static int smtc_map_smem(struct smtcfb_info *sfb,
784 sfb->fb.screen_base = smtc_VRAMBaseAddress; 740 sfb->fb.screen_base = smtc_VRAMBaseAddress;
785 741
786 if (!sfb->fb.screen_base) { 742 if (!sfb->fb.screen_base) {
787 printk(KERN_ERR "%s: unable to map screen memory\n", 743 dev_err(&pdev->dev,
788 sfb->fb.fix.id); 744 "%s: unable to map screen memory\n", sfb->fb.fix.id);
789 return -ENOMEM; 745 return -ENOMEM;
790 } 746 }
791 747
@@ -831,16 +787,14 @@ static int __init sm712vga_setup(char *options)
831{ 787{
832 int index; 788 int index;
833 789
834 if (!options || !*options) { 790 if (!options || !*options)
835 smdbg("\n No vga parameter\n");
836 return -EINVAL; 791 return -EINVAL;
837 }
838 792
839 smtc_screen_info.lfb_width = 0; 793 smtc_screen_info.lfb_width = 0;
840 smtc_screen_info.lfb_height = 0; 794 smtc_screen_info.lfb_height = 0;
841 smtc_screen_info.lfb_depth = 0; 795 smtc_screen_info.lfb_depth = 0;
842 796
843 smdbg("\nsm712vga_setup = %s\n", options); 797 pr_debug("sm712vga_setup = %s\n", options);
844 798
845 for (index = 0; 799 for (index = 0;
846 index < ARRAY_SIZE(vesa_mode); 800 index < ARRAY_SIZE(vesa_mode);
@@ -858,10 +812,6 @@ static int __init sm712vga_setup(char *options)
858} 812}
859__setup("vga=", sm712vga_setup); 813__setup("vga=", sm712vga_setup);
860 814
861/* Jason (08/13/2009)
862 * Original init function changed to probe method to be used by pci_drv
863 * process used to detect chips replaced with kernel process in pci_drv
864 */
865static int __devinit smtcfb_pci_probe(struct pci_dev *pdev, 815static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
866 const struct pci_device_id *ent) 816 const struct pci_device_id *ent)
867{ 817{
@@ -871,23 +821,20 @@ static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
871 int err; 821 int err;
872 unsigned long pFramebufferPhysical; 822 unsigned long pFramebufferPhysical;
873 823
874 printk(KERN_INFO 824 dev_info(&pdev->dev, "Silicon Motion display driver.");
875 "Silicon Motion display driver " SMTC_LINUX_FB_VERSION "\n");
876 825
877 err = pci_enable_device(pdev); /* enable SMTC chip */ 826 err = pci_enable_device(pdev); /* enable SMTC chip */
878 if (err) 827 if (err)
879 return err; 828 return err;
880 829
881 hw.chipID = ent->device;
882 sprintf(name, "sm%Xfb", hw.chipID);
883
884 sfb = smtc_alloc_fb_info(pdev, name); 830 sfb = smtc_alloc_fb_info(pdev, name);
885 831
886 if (!sfb) 832 if (!sfb)
887 goto failed_free; 833 goto failed_free;
888 /* Jason (08/13/2009) 834
889 * Store fb_info to be further used when suspending and resuming 835 sfb->chipID = ent->device;
890 */ 836 sprintf(name, "sm%Xfb", sfb->chipID);
837
891 pci_set_drvdata(pdev, sfb); 838 pci_set_drvdata(pdev, sfb);
892 839
893 sm7xx_init_hw(); 840 sm7xx_init_hw();
@@ -910,37 +857,37 @@ static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
910#endif 857#endif
911 /* Map address and memory detection */ 858 /* Map address and memory detection */
912 pFramebufferPhysical = pci_resource_start(pdev, 0); 859 pFramebufferPhysical = pci_resource_start(pdev, 0);
913 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw.chipRevID); 860 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chipRevID);
914 861
915 switch (hw.chipID) { 862 switch (sfb->chipID) {
916 case 0x710: 863 case 0x710:
917 case 0x712: 864 case 0x712:
918 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000; 865 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000;
919 sfb->fb.fix.mmio_len = 0x00400000; 866 sfb->fb.fix.mmio_len = 0x00400000;
920 smem_size = SM712_VIDEOMEMORYSIZE; 867 smem_size = SM712_VIDEOMEMORYSIZE;
921#ifdef __BIG_ENDIAN 868#ifdef __BIG_ENDIAN
922 hw.m_pLFB = (smtc_VRAMBaseAddress = 869 sfb->m_pLFB = (smtc_VRAMBaseAddress =
923 ioremap(pFramebufferPhysical, 0x00c00000)); 870 ioremap(pFramebufferPhysical, 0x00c00000));
924#else 871#else
925 hw.m_pLFB = (smtc_VRAMBaseAddress = 872 sfb->m_pLFB = (smtc_VRAMBaseAddress =
926 ioremap(pFramebufferPhysical, 0x00800000)); 873 ioremap(pFramebufferPhysical, 0x00800000));
927#endif 874#endif
928 hw.m_pMMIO = (smtc_RegBaseAddress = 875 sfb->m_pMMIO = (smtc_RegBaseAddress =
929 smtc_VRAMBaseAddress + 0x00700000); 876 smtc_VRAMBaseAddress + 0x00700000);
930 hw.m_pDPR = smtc_VRAMBaseAddress + 0x00408000; 877 sfb->m_pDPR = smtc_VRAMBaseAddress + 0x00408000;
931 hw.m_pVPR = hw.m_pLFB + 0x0040c000; 878 sfb->m_pVPR = sfb->m_pLFB + 0x0040c000;
932#ifdef __BIG_ENDIAN 879#ifdef __BIG_ENDIAN
933 if (sfb->fb.var.bits_per_pixel == 32) { 880 if (sfb->fb.var.bits_per_pixel == 32) {
934 smtc_VRAMBaseAddress += 0x800000; 881 smtc_VRAMBaseAddress += 0x800000;
935 hw.m_pLFB += 0x800000; 882 sfb->m_pLFB += 0x800000;
936 printk(KERN_INFO 883 dev_info(&pdev->dev,
937 "\nsmtc_VRAMBaseAddress=%p hw.m_pLFB=%p\n", 884 "smtc_VRAMBaseAddress=%p sfb->m_pLFB=%p",
938 smtc_VRAMBaseAddress, hw.m_pLFB); 885 smtc_VRAMBaseAddress, sfb->m_pLFB);
939 } 886 }
940#endif 887#endif
941 if (!smtc_RegBaseAddress) { 888 if (!smtc_RegBaseAddress) {
942 printk(KERN_ERR 889 dev_err(&pdev->dev,
943 "%s: unable to map memory mapped IO\n", 890 "%s: unable to map memory mapped IO!",
944 sfb->fb.fix.id); 891 sfb->fb.fix.id);
945 err = -ENOMEM; 892 err = -ENOMEM;
946 goto failed_fb; 893 goto failed_fb;
@@ -962,20 +909,20 @@ static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
962 sfb->fb.fix.mmio_start = pFramebufferPhysical; 909 sfb->fb.fix.mmio_start = pFramebufferPhysical;
963 sfb->fb.fix.mmio_len = 0x00200000; 910 sfb->fb.fix.mmio_len = 0x00200000;
964 smem_size = SM722_VIDEOMEMORYSIZE; 911 smem_size = SM722_VIDEOMEMORYSIZE;
965 hw.m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000); 912 sfb->m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000);
966 hw.m_pLFB = (smtc_VRAMBaseAddress = 913 sfb->m_pLFB = (smtc_VRAMBaseAddress =
967 hw.m_pDPR + 0x00200000); 914 sfb->m_pDPR + 0x00200000);
968 hw.m_pMMIO = (smtc_RegBaseAddress = 915 sfb->m_pMMIO = (smtc_RegBaseAddress =
969 hw.m_pDPR + 0x000c0000); 916 sfb->m_pDPR + 0x000c0000);
970 hw.m_pVPR = hw.m_pDPR + 0x800; 917 sfb->m_pVPR = sfb->m_pDPR + 0x800;
971 918
972 smtc_seqw(0x62, 0xff); 919 smtc_seqw(0x62, 0xff);
973 smtc_seqw(0x6a, 0x0d); 920 smtc_seqw(0x6a, 0x0d);
974 smtc_seqw(0x6b, 0x02); 921 smtc_seqw(0x6b, 0x02);
975 break; 922 break;
976 default: 923 default:
977 printk(KERN_ERR 924 dev_err(&pdev->dev,
978 "No valid Silicon Motion display chip was detected!\n"); 925 "No valid Silicon Motion display chip was detected!");
979 926
980 goto failed_fb; 927 goto failed_fb;
981 } 928 }
@@ -992,22 +939,21 @@ static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
992 939
993 smtcfb_setmode(sfb); 940 smtcfb_setmode(sfb);
994 /* Primary display starting from 0 position */ 941 /* Primary display starting from 0 position */
995 hw.BaseAddressInVRAM = 0; 942 sfb->BaseAddressInVRAM = 0;
996 sfb->fb.par = &hw;
997 943
998 err = register_framebuffer(&sfb->fb); 944 err = register_framebuffer(&sfb->fb);
999 if (err < 0) 945 if (err < 0)
1000 goto failed; 946 goto failed;
1001 947
1002 printk(KERN_INFO "Silicon Motion SM%X Rev%X primary display mode" 948 dev_info(&pdev->dev,
1003 "%dx%d-%d Init Complete.\n", hw.chipID, hw.chipRevID, 949 "Silicon Motion SM%X Rev%X primary display mode %dx%d-%d Init Complete.",
1004 sfb->fb.var.xres, sfb->fb.var.yres, 950 sfb->chipID, sfb->chipRevID, sfb->fb.var.xres,
1005 sfb->fb.var.bits_per_pixel); 951 sfb->fb.var.yres, sfb->fb.var.bits_per_pixel);
1006 952
1007 return 0; 953 return 0;
1008 954
1009failed: 955failed:
1010 printk(KERN_ERR "Silicon Motion, Inc. primary display init fail\n"); 956 dev_err(&pdev->dev, "Silicon Motion, Inc. primary display init fail.");
1011 957
1012 smtc_unmap_smem(sfb); 958 smtc_unmap_smem(sfb);
1013 smtc_unmap_mmio(sfb); 959 smtc_unmap_mmio(sfb);
@@ -1021,7 +967,6 @@ failed_free:
1021} 967}
1022 968
1023 969
1024/* Jason (08/11/2009) PCI_DRV wrapper essential structs */
1025static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = { 970static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
1026 { PCI_DEVICE(0x126f, 0x710), }, 971 { PCI_DEVICE(0x126f, 0x710), },
1027 { PCI_DEVICE(0x126f, 0x712), }, 972 { PCI_DEVICE(0x126f, 0x712), },
@@ -1030,9 +975,6 @@ static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
1030}; 975};
1031 976
1032 977
1033/* Jason (08/14/2009)
1034 * do some clean up when the driver module is removed
1035 */
1036static void __devexit smtcfb_pci_remove(struct pci_dev *pdev) 978static void __devexit smtcfb_pci_remove(struct pci_dev *pdev)
1037{ 979{
1038 struct smtcfb_info *sfb; 980 struct smtcfb_info *sfb;
@@ -1078,7 +1020,7 @@ static int smtcfb_pci_resume(struct device *device)
1078 1020
1079 /* reinit hardware */ 1021 /* reinit hardware */
1080 sm7xx_init_hw(); 1022 sm7xx_init_hw();
1081 switch (hw.chipID) { 1023 switch (sfb->chipID) {
1082 case 0x710: 1024 case 0x710:
1083 case 0x712: 1025 case 0x712:
1084 /* set MCLK = 14.31818 * (0x16 / 0x2) */ 1026 /* set MCLK = 14.31818 * (0x16 / 0x2) */
diff --git a/drivers/staging/sm7xx/smtcfb.h b/drivers/staging/sm7xx/smtcfb.h
index ab95af2b9c07..43d86f873410 100644
--- a/drivers/staging/sm7xx/smtcfb.h
+++ b/drivers/staging/sm7xx/smtcfb.h
@@ -13,19 +13,11 @@
13 * more details. 13 * more details.
14 */ 14 */
15 15
16#define SMTC_LINUX_FB_VERSION "version 0.11.2619.21.01 July 27, 2008"
17
18#define NR_PALETTE 256 16#define NR_PALETTE 256
19#define NR_RGB 2 17#define NR_RGB 2
20 18
21#define FB_ACCEL_SMI_LYNX 88 19#define FB_ACCEL_SMI_LYNX 88
22 20
23#ifdef __BIG_ENDIAN
24#define PC_VGA 0
25#else
26#define PC_VGA 1
27#endif
28
29#define SCREEN_X_RES 1024 21#define SCREEN_X_RES 1024
30#define SCREEN_Y_RES 600 22#define SCREEN_Y_RES 600
31#define SCREEN_BPP 16 23#define SCREEN_BPP 16
diff --git a/drivers/staging/telephony/ixj.c b/drivers/staging/telephony/ixj.c
index f96027921f60..fd7757ad7fa3 100644
--- a/drivers/staging/telephony/ixj.c
+++ b/drivers/staging/telephony/ixj.c
@@ -19,20 +19,20 @@
19 * David W. Erhart, <derhart@quicknet.net> 19 * David W. Erhart, <derhart@quicknet.net>
20 * John Sellers, <jsellers@quicknet.net> 20 * John Sellers, <jsellers@quicknet.net>
21 * Mike Preston, <mpreston@quicknet.net> 21 * Mike Preston, <mpreston@quicknet.net>
22 * 22 *
23 * Fixes: David Huggins-Daines, <dhd@cepstral.com> 23 * Fixes: David Huggins-Daines, <dhd@cepstral.com>
24 * Fabio Ferrari, <fabio.ferrari@digitro.com.br> 24 * Fabio Ferrari, <fabio.ferrari@digitro.com.br>
25 * Artis Kugevics, <artis@mt.lv> 25 * Artis Kugevics, <artis@mt.lv>
26 * Daniele Bellucci, <bellucda@tiscali.it> 26 * Daniele Bellucci, <bellucda@tiscali.it>
27 * 27 *
28 * More information about the hardware related to this driver can be found 28 * More information about the hardware related to this driver can be found
29 * at our website: http://www.quicknet.net 29 * at our website: http://www.quicknet.net
30 * 30 *
31 * IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR 31 * IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR
32 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 32 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
33 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET 33 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET
34 * TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * 35 *
36 * QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES, 36 * QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES,
37 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 37 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
38 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 38 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
@@ -317,7 +317,7 @@ static IXJ *ixj[IXJMAX];
317/* 317/*
318 * Allocate a free IXJ device 318 * Allocate a free IXJ device
319 */ 319 */
320 320
321static IXJ *ixj_alloc() 321static IXJ *ixj_alloc()
322{ 322{
323 for(cnt=0; cnt<IXJMAX; cnt++) 323 for(cnt=0; cnt<IXJMAX; cnt++)
@@ -366,7 +366,7 @@ static IXJ ixj[IXJMAX];
366/* 366/*
367 * Allocate a free IXJ device 367 * Allocate a free IXJ device
368 */ 368 */
369 369
370static IXJ *ixj_alloc(void) 370static IXJ *ixj_alloc(void)
371{ 371{
372 int cnt; 372 int cnt;
@@ -1084,7 +1084,7 @@ static void ixj_pstn_state(IXJ *j)
1084 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board, 1084 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1085 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max); 1085 j->cadence_f[4].on3, j->cadence_f[4].on3min, j->cadence_f[4].on3dot, j->cadence_f[4].on3max);
1086 break; 1086 break;
1087 case 6: 1087 case 6:
1088 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board, 1088 printk(KERN_INFO "IXJ /dev/phone%d Next Ring Cadence state at %u min %ld - %ld - max %ld\n", j->board,
1089 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max); 1089 j->cadence_f[4].off3, j->cadence_f[4].off3min, j->cadence_f[4].off3dot, j->cadence_f[4].off3max);
1090 break; 1090 break;
@@ -1109,7 +1109,7 @@ static void ixj_pstn_state(IXJ *j)
1109 } 1109 }
1110 j->pstn_ring_stop = j->pstn_ring_int = 0; 1110 j->pstn_ring_stop = j->pstn_ring_int = 0;
1111 daa_set_mode(j, SOP_PU_SLEEP); 1111 daa_set_mode(j, SOP_PU_SLEEP);
1112 } 1112 }
1113 outb_p(j->pld_scrw.byte, j->XILINXbase); 1113 outb_p(j->pld_scrw.byte, j->XILINXbase);
1114 if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) { 1114 if (j->pstn_cid_intr && time_after(jiffies, j->pstn_cid_received + hertz)) {
1115 ixj_daa_cid_read(j); 1115 ixj_daa_cid_read(j);
@@ -1133,7 +1133,7 @@ static void ixj_pstn_state(IXJ *j)
1133 printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies); 1133 printk("IXJ DAA possible wink /dev/phone%d %ld\n", j->board, jiffies);
1134 } 1134 }
1135 j->pstn_winkstart = jiffies; 1135 j->pstn_winkstart = jiffies;
1136 } 1136 }
1137 } else { 1137 } else {
1138 if (j->pstn_winkstart) { 1138 if (j->pstn_winkstart) {
1139 if(ixjdebug & 0x0008) { 1139 if(ixjdebug & 0x0008) {
@@ -1524,7 +1524,7 @@ static inline void LED_SetState(int state, IXJ *j)
1524/********************************************************************* 1524/*********************************************************************
1525* GPIO Pins are configured as follows on the Quicknet Internet 1525* GPIO Pins are configured as follows on the Quicknet Internet
1526* PhoneJACK Telephony Cards 1526* PhoneJACK Telephony Cards
1527* 1527*
1528* POTS Select GPIO_6=0 GPIO_7=0 1528* POTS Select GPIO_6=0 GPIO_7=0
1529* Mic/Speaker Select GPIO_6=0 GPIO_7=1 1529* Mic/Speaker Select GPIO_6=0 GPIO_7=1
1530* Handset Select GPIO_6=1 GPIO_7=0 1530* Handset Select GPIO_6=1 GPIO_7=0
@@ -1932,7 +1932,7 @@ static int ixj_hookstate(IXJ *j)
1932 if(fOffHook != j->p_hook) { 1932 if(fOffHook != j->p_hook) {
1933 if(!j->checkwait) { 1933 if(!j->checkwait) {
1934 j->checkwait = jiffies; 1934 j->checkwait = jiffies;
1935 } 1935 }
1936 if(time_before(jiffies, j->checkwait + 2)) { 1936 if(time_before(jiffies, j->checkwait + 2)) {
1937 fOffHook ^= 1; 1937 fOffHook ^= 1;
1938 } else { 1938 } else {
@@ -2342,8 +2342,8 @@ static int ixj_release(struct inode *inode, struct file *file_p)
2342 j->ixj_signals[cnt] = SIGIO; 2342 j->ixj_signals[cnt] = SIGIO;
2343 2343
2344 /* Set the excetion signal enable flags */ 2344 /* Set the excetion signal enable flags */
2345 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 2345 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring =
2346 j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 = 2346 j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 =
2347 j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1; 2347 j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1;
2348 2348
2349 file_p->private_data = NULL; 2349 file_p->private_data = NULL;
@@ -2506,7 +2506,7 @@ static int read_filters(IXJ *j)
2506 j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max); 2506 j->cadence_f[cnt].on1, j->cadence_f[cnt].on1min, j->cadence_f[cnt].on1dot, j->cadence_f[cnt].on1max);
2507 break; 2507 break;
2508 case 2: 2508 case 2:
2509 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min, 2509 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off1min,
2510 j->cadence_f[cnt].off1max); 2510 j->cadence_f[cnt].off1max);
2511 break; 2511 break;
2512 case 3: 2512 case 3:
@@ -2521,12 +2521,12 @@ static int read_filters(IXJ *j)
2521 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min, 2521 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].on3min,
2522 j->cadence_f[cnt].on3max); 2522 j->cadence_f[cnt].on3max);
2523 break; 2523 break;
2524 case 6: 2524 case 6:
2525 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min, 2525 printk(KERN_INFO "IXJ /dev/phone%d Next Tone Cadence state at %ld - %ld\n", j->board, j->cadence_f[cnt].off3min,
2526 j->cadence_f[cnt].off3max); 2526 j->cadence_f[cnt].off3max);
2527 break; 2527 break;
2528 } 2528 }
2529 } 2529 }
2530 } 2530 }
2531 if (j->cadence_f[cnt].state == 7) { 2531 if (j->cadence_f[cnt].state == 7) {
2532 j->cadence_f[cnt].state = 0; 2532 j->cadence_f[cnt].state = 0;
@@ -2656,37 +2656,37 @@ static void ulaw2alaw(unsigned char *buff, unsigned long len)
2656{ 2656{
2657 static unsigned char table_ulaw2alaw[] = 2657 static unsigned char table_ulaw2alaw[] =
2658 { 2658 {
2659 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D, 2659 0x2A, 0x2B, 0x28, 0x29, 0x2E, 0x2F, 0x2C, 0x2D,
2660 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, 2660 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25,
2661 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D, 2661 0x3A, 0x3B, 0x38, 0x39, 0x3E, 0x3F, 0x3C, 0x3D,
2662 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, 2662 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35,
2663 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02, 2663 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 0x02,
2664 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A, 2664 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x1A,
2665 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12, 2665 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 0x12,
2666 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B, 2666 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x6B,
2667 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63, 2667 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 0x62, 0x63,
2668 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79, 2668 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 0x7B, 0x79,
2669 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71, 2669 0x7E, 0x7F, 0x7C, 0x7D, 0x72, 0x73, 0x70, 0x71,
2670 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D, 2670 0x76, 0x77, 0x74, 0x75, 0x4B, 0x49, 0x4F, 0x4D,
2671 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45, 2671 0x42, 0x43, 0x40, 0x41, 0x46, 0x47, 0x44, 0x45,
2672 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D, 2672 0x5A, 0x5B, 0x58, 0x59, 0x5E, 0x5F, 0x5C, 0x5D,
2673 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51, 2673 0x52, 0x52, 0x53, 0x53, 0x50, 0x50, 0x51, 0x51,
2674 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5, 2674 0x56, 0x56, 0x57, 0x57, 0x54, 0x54, 0x55, 0xD5,
2675 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD, 2675 0xAA, 0xAB, 0xA8, 0xA9, 0xAE, 0xAF, 0xAC, 0xAD,
2676 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5, 2676 0xA2, 0xA3, 0xA0, 0xA1, 0xA6, 0xA7, 0xA4, 0xA5,
2677 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD, 2677 0xBA, 0xBB, 0xB8, 0xB9, 0xBE, 0xBF, 0xBC, 0xBD,
2678 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5, 2678 0xB2, 0xB3, 0xB0, 0xB1, 0xB6, 0xB7, 0xB4, 0xB5,
2679 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82, 2679 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 0x82,
2680 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A, 2680 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 0x9A,
2681 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92, 2681 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 0x92,
2682 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB, 2682 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 0xEB,
2683 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3, 2683 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 0xE2, 0xE3,
2684 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9, 2684 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 0xFB, 0xF9,
2685 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1, 2685 0xFE, 0xFF, 0xFC, 0xFD, 0xF2, 0xF3, 0xF0, 0xF1,
2686 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD, 2686 0xF6, 0xF7, 0xF4, 0xF5, 0xCB, 0xC9, 0xCF, 0xCD,
2687 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5, 2687 0xC2, 0xC3, 0xC0, 0xC1, 0xC6, 0xC7, 0xC4, 0xC5,
2688 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD, 2688 0xDA, 0xDB, 0xD8, 0xD9, 0xDE, 0xDF, 0xDC, 0xDD,
2689 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1, 2689 0xD2, 0xD2, 0xD3, 0xD3, 0xD0, 0xD0, 0xD1, 0xD1,
2690 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5 2690 0xD6, 0xD6, 0xD7, 0xD7, 0xD4, 0xD4, 0xD5, 0xD5
2691 }; 2691 };
2692 2692
@@ -2701,37 +2701,37 @@ static void alaw2ulaw(unsigned char *buff, unsigned long len)
2701{ 2701{
2702 static unsigned char table_alaw2ulaw[] = 2702 static unsigned char table_alaw2ulaw[] =
2703 { 2703 {
2704 0x29, 0x2A, 0x27, 0x28, 0x2D, 0x2E, 0x2B, 0x2C, 2704 0x29, 0x2A, 0x27, 0x28, 0x2D, 0x2E, 0x2B, 0x2C,
2705 0x21, 0x22, 0x1F, 0x20, 0x25, 0x26, 0x23, 0x24, 2705 0x21, 0x22, 0x1F, 0x20, 0x25, 0x26, 0x23, 0x24,
2706 0x39, 0x3A, 0x37, 0x38, 0x3D, 0x3E, 0x3B, 0x3C, 2706 0x39, 0x3A, 0x37, 0x38, 0x3D, 0x3E, 0x3B, 0x3C,
2707 0x31, 0x32, 0x2F, 0x30, 0x35, 0x36, 0x33, 0x34, 2707 0x31, 0x32, 0x2F, 0x30, 0x35, 0x36, 0x33, 0x34,
2708 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D, 2708 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D,
2709 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 2709 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
2710 0x1A, 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D, 2710 0x1A, 0x1B, 0x18, 0x19, 0x1E, 0x1F, 0x1C, 0x1D,
2711 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 2711 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15,
2712 0x62, 0x63, 0x60, 0x61, 0x66, 0x67, 0x64, 0x65, 2712 0x62, 0x63, 0x60, 0x61, 0x66, 0x67, 0x64, 0x65,
2713 0x5D, 0x5D, 0x5C, 0x5C, 0x5F, 0x5F, 0x5E, 0x5E, 2713 0x5D, 0x5D, 0x5C, 0x5C, 0x5F, 0x5F, 0x5E, 0x5E,
2714 0x74, 0x76, 0x70, 0x72, 0x7C, 0x7E, 0x78, 0x7A, 2714 0x74, 0x76, 0x70, 0x72, 0x7C, 0x7E, 0x78, 0x7A,
2715 0x6A, 0x6B, 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D, 2715 0x6A, 0x6B, 0x68, 0x69, 0x6E, 0x6F, 0x6C, 0x6D,
2716 0x48, 0x49, 0x46, 0x47, 0x4C, 0x4D, 0x4A, 0x4B, 2716 0x48, 0x49, 0x46, 0x47, 0x4C, 0x4D, 0x4A, 0x4B,
2717 0x40, 0x41, 0x3F, 0x3F, 0x44, 0x45, 0x42, 0x43, 2717 0x40, 0x41, 0x3F, 0x3F, 0x44, 0x45, 0x42, 0x43,
2718 0x56, 0x57, 0x54, 0x55, 0x5A, 0x5B, 0x58, 0x59, 2718 0x56, 0x57, 0x54, 0x55, 0x5A, 0x5B, 0x58, 0x59,
2719 0x4F, 0x4F, 0x4E, 0x4E, 0x52, 0x53, 0x50, 0x51, 2719 0x4F, 0x4F, 0x4E, 0x4E, 0x52, 0x53, 0x50, 0x51,
2720 0xA9, 0xAA, 0xA7, 0xA8, 0xAD, 0xAE, 0xAB, 0xAC, 2720 0xA9, 0xAA, 0xA7, 0xA8, 0xAD, 0xAE, 0xAB, 0xAC,
2721 0xA1, 0xA2, 0x9F, 0xA0, 0xA5, 0xA6, 0xA3, 0xA4, 2721 0xA1, 0xA2, 0x9F, 0xA0, 0xA5, 0xA6, 0xA3, 0xA4,
2722 0xB9, 0xBA, 0xB7, 0xB8, 0xBD, 0xBE, 0xBB, 0xBC, 2722 0xB9, 0xBA, 0xB7, 0xB8, 0xBD, 0xBE, 0xBB, 0xBC,
2723 0xB1, 0xB2, 0xAF, 0xB0, 0xB5, 0xB6, 0xB3, 0xB4, 2723 0xB1, 0xB2, 0xAF, 0xB0, 0xB5, 0xB6, 0xB3, 0xB4,
2724 0x8A, 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D, 2724 0x8A, 0x8B, 0x88, 0x89, 0x8E, 0x8F, 0x8C, 0x8D,
2725 0x82, 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85, 2725 0x82, 0x83, 0x80, 0x81, 0x86, 0x87, 0x84, 0x85,
2726 0x9A, 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D, 2726 0x9A, 0x9B, 0x98, 0x99, 0x9E, 0x9F, 0x9C, 0x9D,
2727 0x92, 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95, 2727 0x92, 0x93, 0x90, 0x91, 0x96, 0x97, 0x94, 0x95,
2728 0xE2, 0xE3, 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5, 2728 0xE2, 0xE3, 0xE0, 0xE1, 0xE6, 0xE7, 0xE4, 0xE5,
2729 0xDD, 0xDD, 0xDC, 0xDC, 0xDF, 0xDF, 0xDE, 0xDE, 2729 0xDD, 0xDD, 0xDC, 0xDC, 0xDF, 0xDF, 0xDE, 0xDE,
2730 0xF4, 0xF6, 0xF0, 0xF2, 0xFC, 0xFE, 0xF8, 0xFA, 2730 0xF4, 0xF6, 0xF0, 0xF2, 0xFC, 0xFE, 0xF8, 0xFA,
2731 0xEA, 0xEB, 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED, 2731 0xEA, 0xEB, 0xE8, 0xE9, 0xEE, 0xEF, 0xEC, 0xED,
2732 0xC8, 0xC9, 0xC6, 0xC7, 0xCC, 0xCD, 0xCA, 0xCB, 2732 0xC8, 0xC9, 0xC6, 0xC7, 0xCC, 0xCD, 0xCA, 0xCB,
2733 0xC0, 0xC1, 0xBF, 0xBF, 0xC4, 0xC5, 0xC2, 0xC3, 2733 0xC0, 0xC1, 0xBF, 0xBF, 0xC4, 0xC5, 0xC2, 0xC3,
2734 0xD6, 0xD7, 0xD4, 0xD5, 0xDA, 0xDB, 0xD8, 0xD9, 2734 0xD6, 0xD7, 0xD4, 0xD5, 0xDA, 0xDB, 0xD8, 0xD9,
2735 0xCF, 0xCF, 0xCE, 0xCE, 0xD2, 0xD3, 0xD0, 0xD1 2735 0xCF, 0xCF, 0xCE, 0xCE, 0xD2, 0xD3, 0xD0, 0xD1
2736 }; 2736 };
2737 2737
@@ -3090,7 +3090,7 @@ static int ixj_write_cid_string(IXJ *j, char *s, int checksum)
3090 3090
3091static void ixj_pad_fsk(IXJ *j, int pad) 3091static void ixj_pad_fsk(IXJ *j, int pad)
3092{ 3092{
3093 int cnt; 3093 int cnt;
3094 3094
3095 for (cnt = 0; cnt < pad; cnt++) { 3095 for (cnt = 0; cnt < pad; cnt++) {
3096 if(j->fskdcnt < (j->fsksize - 1)) 3096 if(j->fskdcnt < (j->fsksize - 1))
@@ -3474,7 +3474,7 @@ static void ixj_write_frame(IXJ *j)
3474 ixj_post_cid(j); 3474 ixj_post_cid(j);
3475 } 3475 }
3476 /* This may seem rude, but if we just played one frame of FSK data for CallerID 3476 /* This may seem rude, but if we just played one frame of FSK data for CallerID
3477 and there is real audio data in the buffer, we need to throw it away because 3477 and there is real audio data in the buffer, we need to throw it away because
3478 we just used it's time slot */ 3478 we just used it's time slot */
3479 if (j->write_buffer_rp > j->write_buffer_wp) { 3479 if (j->write_buffer_rp > j->write_buffer_wp) {
3480 j->write_buffer_rp += j->cid_play_frame_size * 2; 3480 j->write_buffer_rp += j->cid_play_frame_size * 2;
@@ -3486,7 +3486,7 @@ static void ixj_write_frame(IXJ *j)
3486 3486
3487 wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */ 3487 wake_up_interruptible(&j->poll_q); /* Wake any blocked selects */
3488 } 3488 }
3489 } else if (j->write_buffer && j->write_buffers_empty < 1) { 3489 } else if (j->write_buffer && j->write_buffers_empty < 1) {
3490 if (j->write_buffer_wp > j->write_buffer_rp) { 3490 if (j->write_buffer_wp > j->write_buffer_rp) {
3491 frame_count = 3491 frame_count =
3492 (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2); 3492 (j->write_buffer_wp - j->write_buffer_rp) / (j->play_frame_size * 2);
@@ -4150,7 +4150,7 @@ static void ixj_aec_start(IXJ *j, int level)
4150 4150
4151 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */ 4151 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4152 ixj_WriteDSPCommand(0x0000, j); /* to off */ 4152 ixj_WriteDSPCommand(0x0000, j); /* to off */
4153 4153
4154 break; 4154 break;
4155 4155
4156 case AEC_MED: 4156 case AEC_MED:
@@ -4161,7 +4161,7 @@ static void ixj_aec_start(IXJ *j, int level)
4161 4161
4162 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */ 4162 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4163 ixj_WriteDSPCommand(0x0000, j); /* to off */ 4163 ixj_WriteDSPCommand(0x0000, j); /* to off */
4164 4164
4165 break; 4165 break;
4166 4166
4167 case AEC_HIGH: 4167 case AEC_HIGH:
@@ -4172,7 +4172,7 @@ static void ixj_aec_start(IXJ *j, int level)
4172 4172
4173 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */ 4173 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4174 ixj_WriteDSPCommand(0x0000, j); /* to off */ 4174 ixj_WriteDSPCommand(0x0000, j); /* to off */
4175 4175
4176 break; 4176 break;
4177 4177
4178 case AEC_AGC: 4178 case AEC_AGC:
@@ -4197,28 +4197,28 @@ static void ixj_aec_start(IXJ *j, int level)
4197 /* Now we can set the AGC initial parameters and turn it on */ 4197 /* Now we can set the AGC initial parameters and turn it on */
4198 ixj_WriteDSPCommand(0xCF90, j); /* Set AGC Minimum gain */ 4198 ixj_WriteDSPCommand(0xCF90, j); /* Set AGC Minimum gain */
4199 ixj_WriteDSPCommand(0x0020, j); /* to 0.125 (-18dB) */ 4199 ixj_WriteDSPCommand(0x0020, j); /* to 0.125 (-18dB) */
4200 4200
4201 ixj_WriteDSPCommand(0xCF91, j); /* Set AGC Maximum gain */ 4201 ixj_WriteDSPCommand(0xCF91, j); /* Set AGC Maximum gain */
4202 ixj_WriteDSPCommand(0x1000, j); /* to 16 (24dB) */ 4202 ixj_WriteDSPCommand(0x1000, j); /* to 16 (24dB) */
4203 4203
4204 ixj_WriteDSPCommand(0xCF92, j); /* Set AGC start gain */ 4204 ixj_WriteDSPCommand(0xCF92, j); /* Set AGC start gain */
4205 ixj_WriteDSPCommand(0x0800, j); /* to 8 (+18dB) */ 4205 ixj_WriteDSPCommand(0x0800, j); /* to 8 (+18dB) */
4206 4206
4207 ixj_WriteDSPCommand(0xCF93, j); /* Set AGC hold time */ 4207 ixj_WriteDSPCommand(0xCF93, j); /* Set AGC hold time */
4208 ixj_WriteDSPCommand(0x1F40, j); /* to 2 seconds (units are 250us) */ 4208 ixj_WriteDSPCommand(0x1F40, j); /* to 2 seconds (units are 250us) */
4209 4209
4210 ixj_WriteDSPCommand(0xCF94, j); /* Set AGC Attack Time Constant */ 4210 ixj_WriteDSPCommand(0xCF94, j); /* Set AGC Attack Time Constant */
4211 ixj_WriteDSPCommand(0x0005, j); /* to 8ms */ 4211 ixj_WriteDSPCommand(0x0005, j); /* to 8ms */
4212 4212
4213 ixj_WriteDSPCommand(0xCF95, j); /* Set AGC Decay Time Constant */ 4213 ixj_WriteDSPCommand(0xCF95, j); /* Set AGC Decay Time Constant */
4214 ixj_WriteDSPCommand(0x000D, j); /* to 4096ms */ 4214 ixj_WriteDSPCommand(0x000D, j); /* to 4096ms */
4215 4215
4216 ixj_WriteDSPCommand(0xCF96, j); /* Set AGC Attack Threshold */ 4216 ixj_WriteDSPCommand(0xCF96, j); /* Set AGC Attack Threshold */
4217 ixj_WriteDSPCommand(0x1200, j); /* to 25% */ 4217 ixj_WriteDSPCommand(0x1200, j); /* to 25% */
4218 4218
4219 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */ 4219 ixj_WriteDSPCommand(0xCF97, j); /* Set AGC Enable */
4220 ixj_WriteDSPCommand(0x0001, j); /* to on */ 4220 ixj_WriteDSPCommand(0x0001, j); /* to on */
4221 4221
4222 break; 4222 break;
4223 4223
4224 case AEC_AUTO: 4224 case AEC_AUTO:
@@ -4495,7 +4495,7 @@ static int ixj_play_start(IXJ *j)
4495 return -ENOMEM; 4495 return -ENOMEM;
4496 } 4496 }
4497/* j->write_buffers_empty = 2; */ 4497/* j->write_buffers_empty = 2; */
4498 j->write_buffers_empty = 1; 4498 j->write_buffers_empty = 1;
4499 j->write_buffer_size = j->play_frame_size * 2; 4499 j->write_buffer_size = j->play_frame_size * 2;
4500 j->write_buffer_end = j->write_buffer + j->play_frame_size * 2; 4500 j->write_buffer_end = j->write_buffer + j->play_frame_size * 2;
4501 j->write_buffer_rp = j->write_buffer_wp = j->write_buffer; 4501 j->write_buffer_rp = j->write_buffer_wp = j->write_buffer;
@@ -6465,9 +6465,9 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6465 ixj_ringback(j); 6465 ixj_ringback(j);
6466 break; 6466 break;
6467 case PHONE_WINK: 6467 case PHONE_WINK:
6468 if(j->cardtype == QTI_PHONEJACK) 6468 if(j->cardtype == QTI_PHONEJACK)
6469 retval = -1; 6469 retval = -1;
6470 else 6470 else
6471 retval = ixj_wink(j); 6471 retval = ixj_wink(j);
6472 break; 6472 break;
6473 case PHONE_CPT_STOP: 6473 case PHONE_CPT_STOP:
@@ -6553,7 +6553,7 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6553 ixj_write_vmwi(j, arg); 6553 ixj_write_vmwi(j, arg);
6554 break; 6554 break;
6555 case IXJCTL_CID: 6555 case IXJCTL_CID:
6556 if (copy_to_user(argp, &j->cid, sizeof(PHONE_CID))) 6556 if (copy_to_user(argp, &j->cid, sizeof(PHONE_CID)))
6557 retval = -EFAULT; 6557 retval = -EFAULT;
6558 j->ex.bits.caller_id = 0; 6558 j->ex.bits.caller_id = 0;
6559 break; 6559 break;
@@ -6575,13 +6575,13 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6575 break; 6575 break;
6576 case PHONE_CAPABILITIES_LIST: 6576 case PHONE_CAPABILITIES_LIST:
6577 add_caps(j); 6577 add_caps(j);
6578 if (copy_to_user(argp, j->caplist, sizeof(struct phone_capability) * j->caps)) 6578 if (copy_to_user(argp, j->caplist, sizeof(struct phone_capability) * j->caps))
6579 retval = -EFAULT; 6579 retval = -EFAULT;
6580 break; 6580 break;
6581 case PHONE_CAPABILITIES_CHECK: 6581 case PHONE_CAPABILITIES_CHECK:
6582 { 6582 {
6583 struct phone_capability cap; 6583 struct phone_capability cap;
6584 if (copy_from_user(&cap, argp, sizeof(cap))) 6584 if (copy_from_user(&cap, argp, sizeof(cap)))
6585 retval = -EFAULT; 6585 retval = -EFAULT;
6586 else { 6586 else {
6587 add_caps(j); 6587 add_caps(j);
@@ -6597,13 +6597,13 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6597 j->ex.bits.pstn_ring = 0; 6597 j->ex.bits.pstn_ring = 0;
6598 break; 6598 break;
6599 case IXJCTL_SET_FILTER: 6599 case IXJCTL_SET_FILTER:
6600 if (copy_from_user(&jf, argp, sizeof(jf))) 6600 if (copy_from_user(&jf, argp, sizeof(jf)))
6601 retval = -EFAULT; 6601 retval = -EFAULT;
6602 else 6602 else
6603 retval = ixj_init_filter(j, &jf); 6603 retval = ixj_init_filter(j, &jf);
6604 break; 6604 break;
6605 case IXJCTL_SET_FILTER_RAW: 6605 case IXJCTL_SET_FILTER_RAW:
6606 if (copy_from_user(&jfr, argp, sizeof(jfr))) 6606 if (copy_from_user(&jfr, argp, sizeof(jfr)))
6607 retval = -EFAULT; 6607 retval = -EFAULT;
6608 else 6608 else
6609 retval = ixj_init_filter_raw(j, &jfr); 6609 retval = ixj_init_filter_raw(j, &jfr);
@@ -6638,9 +6638,9 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6638 raise *= 2; 6638 raise *= 2;
6639 } 6639 }
6640 if(j->sigdef.signal) 6640 if(j->sigdef.signal)
6641 j->ex_sig.bytes |= raise; 6641 j->ex_sig.bytes |= raise;
6642 else 6642 else
6643 j->ex_sig.bytes &= (raise^0xffff); 6643 j->ex_sig.bytes &= (raise^0xffff);
6644 } 6644 }
6645 break; 6645 break;
6646 case IXJCTL_INTERCOM_STOP: 6646 case IXJCTL_INTERCOM_STOP:
@@ -7040,9 +7040,9 @@ static int ixj_selfprobe(IXJ *j)
7040 7040
7041 /* initialise the DTMF prescale to a sensible value */ 7041 /* initialise the DTMF prescale to a sensible value */
7042 if (j->cardtype == QTI_LINEJACK) { 7042 if (j->cardtype == QTI_LINEJACK) {
7043 set_dtmf_prescale(j, 0x10); 7043 set_dtmf_prescale(j, 0x10);
7044 } else { 7044 } else {
7045 set_dtmf_prescale(j, 0x40); 7045 set_dtmf_prescale(j, 0x40);
7046 } 7046 }
7047 set_play_volume(j, 0x100); 7047 set_play_volume(j, 0x100);
7048 set_rec_volume(j, 0x100); 7048 set_rec_volume(j, 0x100);
@@ -7095,15 +7095,15 @@ static int ixj_selfprobe(IXJ *j)
7095 j->ixj_signals[cnt] = SIGIO; 7095 j->ixj_signals[cnt] = SIGIO;
7096 7096
7097 /* Set the excetion signal enable flags */ 7097 /* Set the excetion signal enable flags */
7098 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 7098 j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring =
7099 j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 = 7099 j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 =
7100 j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1; 7100 j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1;
7101#ifdef IXJ_DYN_ALLOC 7101#ifdef IXJ_DYN_ALLOC
7102 j->fskdata = NULL; 7102 j->fskdata = NULL;
7103#endif 7103#endif
7104 j->fskdcnt = 0; 7104 j->fskdcnt = 0;
7105 j->cidcw_wait = 0; 7105 j->cidcw_wait = 0;
7106 7106
7107 /* Register with the Telephony for Linux subsystem */ 7107 /* Register with the Telephony for Linux subsystem */
7108 j->p.f_op = &ixj_fops; 7108 j->p.f_op = &ixj_fops;
7109 j->p.open = ixj_open; 7109 j->p.open = ixj_open;
@@ -7118,7 +7118,7 @@ static int ixj_selfprobe(IXJ *j)
7118/* 7118/*
7119 * Exported service for pcmcia card handling 7119 * Exported service for pcmcia card handling
7120 */ 7120 */
7121 7121
7122IXJ *ixj_pcmcia_probe(unsigned long dsp, unsigned long xilinx) 7122IXJ *ixj_pcmcia_probe(unsigned long dsp, unsigned long xilinx)
7123{ 7123{
7124 IXJ *j = ixj_alloc(); 7124 IXJ *j = ixj_alloc();
@@ -7320,7 +7320,7 @@ static int ixj_get_status_proc(char *buf)
7320 len += sprintf(buf + len, "\nRec volume 0x%x", get_rec_volume(j)); 7320 len += sprintf(buf + len, "\nRec volume 0x%x", get_rec_volume(j));
7321 len += sprintf(buf + len, "\nPlay volume 0x%x", get_play_volume(j)); 7321 len += sprintf(buf + len, "\nPlay volume 0x%x", get_play_volume(j));
7322 len += sprintf(buf + len, "\nDTMF prescale 0x%x", get_dtmf_prescale(j)); 7322 len += sprintf(buf + len, "\nDTMF prescale 0x%x", get_dtmf_prescale(j));
7323 7323
7324 len += sprintf(buf + len, "\nHook state %d", j->hookstate); /* j->r_hook); */ 7324 len += sprintf(buf + len, "\nHook state %d", j->hookstate); /* j->r_hook); */
7325 7325
7326 if (j->cardtype == QTI_LINEJACK) { 7326 if (j->cardtype == QTI_LINEJACK) {
@@ -7417,7 +7417,7 @@ static int ixj_get_status_proc(char *buf)
7417 len += sprintf(buf + len, "\nPControl Wait Fails %ld", j->pcontrolwaitfail); 7417 len += sprintf(buf + len, "\nPControl Wait Fails %ld", j->pcontrolwaitfail);
7418 len += sprintf(buf + len, "\nIs Control Ready Checks %ld", j->iscontrolready); 7418 len += sprintf(buf + len, "\nIs Control Ready Checks %ld", j->iscontrolready);
7419 len += sprintf(buf + len, "\nIs Control Ready Check failures %ld", j->iscontrolreadyfail); 7419 len += sprintf(buf + len, "\nIs Control Ready Check failures %ld", j->iscontrolreadyfail);
7420 7420
7421#endif 7421#endif
7422 len += sprintf(buf + len, "\n"); 7422 len += sprintf(buf + len, "\n");
7423 } 7423 }
@@ -7608,7 +7608,7 @@ static IXJ *new_ixj(unsigned long port)
7608} 7608}
7609 7609
7610static int __init ixj_probe_isapnp(int *cnt) 7610static int __init ixj_probe_isapnp(int *cnt)
7611{ 7611{
7612 int probe = 0; 7612 int probe = 0;
7613 int func = 0x110; 7613 int func = 0x110;
7614 struct pnp_dev *dev = NULL, *old_dev = NULL; 7614 struct pnp_dev *dev = NULL, *old_dev = NULL;
@@ -7686,7 +7686,7 @@ static int __init ixj_probe_isapnp(int *cnt)
7686 } 7686 }
7687 return probe; 7687 return probe;
7688} 7688}
7689 7689
7690static int __init ixj_probe_isa(int *cnt) 7690static int __init ixj_probe_isa(int *cnt)
7691{ 7691{
7692 int i, probe; 7692 int i, probe;
@@ -7713,7 +7713,7 @@ static int __init ixj_probe_isa(int *cnt)
7713 7713
7714static int __init ixj_probe_pci(int *cnt) 7714static int __init ixj_probe_pci(int *cnt)
7715{ 7715{
7716 struct pci_dev *pci = NULL; 7716 struct pci_dev *pci = NULL;
7717 int i, probe = 0; 7717 int i, probe = 0;
7718 IXJ *j = NULL; 7718 IXJ *j = NULL;
7719 7719
@@ -7745,7 +7745,7 @@ static int __init ixj_probe_pci(int *cnt)
7745static int __init ixj_init(void) 7745static int __init ixj_init(void)
7746{ 7746{
7747 int cnt = 0; 7747 int cnt = 0;
7748 int probe = 0; 7748 int probe = 0;
7749 7749
7750 cnt = 0; 7750 cnt = 0;
7751 7751
@@ -7887,7 +7887,7 @@ static void DAA_Coeff_US(IXJ *j)
7887/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x2D; */ 7887/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[2] = 0x2D; */
7888/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0x62; */ 7888/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[1] = 0x62; */
7889/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x2D; */ 7889/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_1[0] = 0x2D; */
7890 /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */ 7890 /* Bytes for Ringing part 2 (06):13,42,A6,BA,D4,73,CA,D5 */
7891/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x2D; */ 7891/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[7] = 0x2D; */
7892/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x62; */ 7892/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[6] = 0x62; */
7893/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6; */ 7893/* j->m_DAAShadowRegs.COP_REGS.COP.RingerImpendance_2[5] = 0xA6; */
diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
index 9b50b5bd4edb..c51f651dfd1b 100644
--- a/drivers/staging/tidspbridge/core/io_sm.c
+++ b/drivers/staging/tidspbridge/core/io_sm.c
@@ -2212,7 +2212,7 @@ void dump_dl_modules(struct bridge_dev_context *bridge_context)
2212 2212
2213 if (status) { 2213 if (status) {
2214 pr_debug( 2214 pr_debug(
2215 "%s: Failed to read dll_module stuct for 0x%x.\n", 2215 "%s: Failed to read dll_module struct for 0x%x.\n",
2216 __func__, module_dsp_addr); 2216 __func__, module_dsp_addr);
2217 break; 2217 break;
2218 } 2218 }
diff --git a/drivers/staging/tidspbridge/core/ue_deh.c b/drivers/staging/tidspbridge/core/ue_deh.c
index 006ffd752895..3d28b2345fbd 100644
--- a/drivers/staging/tidspbridge/core/ue_deh.c
+++ b/drivers/staging/tidspbridge/core/ue_deh.c
@@ -215,7 +215,7 @@ static inline const char *event_to_string(int event)
215 case DSP_MMUFAULT: return "DSP_MMUFAULT"; break; 215 case DSP_MMUFAULT: return "DSP_MMUFAULT"; break;
216 case DSP_PWRERROR: return "DSP_PWRERROR"; break; 216 case DSP_PWRERROR: return "DSP_PWRERROR"; break;
217 case DSP_WDTOVERFLOW: return "DSP_WDTOVERFLOW"; break; 217 case DSP_WDTOVERFLOW: return "DSP_WDTOVERFLOW"; break;
218 default: return "unkown event"; break; 218 default: return "unknown event"; break;
219 } 219 }
220} 220}
221 221
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index fa870e3f7f6a..92ced35e6b7f 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -113,8 +113,8 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
113 113
114 spin_unlock(&sdev->ud.lock); 114 spin_unlock(&sdev->ud.lock);
115 115
116 sdev->ud.tcp_rx = kthread_run(stub_rx_loop, &sdev->ud, "stub_rx"); 116 sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud, "stub_rx");
117 sdev->ud.tcp_tx = kthread_run(stub_tx_loop, &sdev->ud, "stub_tx"); 117 sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud, "stub_tx");
118 118
119 spin_lock(&sdev->ud.lock); 119 spin_lock(&sdev->ud.lock);
120 sdev->ud.status = SDEV_ST_USED; 120 sdev->ud.status = SDEV_ST_USED;
@@ -187,10 +187,10 @@ static void stub_shutdown_connection(struct usbip_device *ud)
187 } 187 }
188 188
189 /* 1. stop threads */ 189 /* 1. stop threads */
190 if (ud->tcp_rx && !task_is_dead(ud->tcp_rx)) 190 if (ud->tcp_rx)
191 kthread_stop(ud->tcp_rx); 191 kthread_stop_put(ud->tcp_rx);
192 if (ud->tcp_tx && !task_is_dead(ud->tcp_tx)) 192 if (ud->tcp_tx)
193 kthread_stop(ud->tcp_tx); 193 kthread_stop_put(ud->tcp_tx);
194 194
195 /* 195 /*
196 * 2. close the socket 196 * 2. close the socket
diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
index c7b888ca54f5..5d89c0fd6f7b 100644
--- a/drivers/staging/usbip/usbip_common.h
+++ b/drivers/staging/usbip/usbip_common.h
@@ -292,6 +292,23 @@ struct usbip_device {
292 } eh_ops; 292 } eh_ops;
293}; 293};
294 294
295#define kthread_get_run(threadfn, data, namefmt, ...) \
296({ \
297 struct task_struct *__k \
298 = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
299 if (!IS_ERR(__k)) { \
300 get_task_struct(__k); \
301 wake_up_process(__k); \
302 } \
303 __k; \
304})
305
306#define kthread_stop_put(k) \
307 do { \
308 kthread_stop(k); \
309 put_task_struct(k); \
310 } while (0)
311
295/* usbip_common.c */ 312/* usbip_common.c */
296void usbip_dump_urb(struct urb *purb); 313void usbip_dump_urb(struct urb *purb);
297void usbip_dump_header(struct usbip_header *pdu); 314void usbip_dump_header(struct usbip_header *pdu);
diff --git a/drivers/staging/usbip/usbip_protocol.txt b/drivers/staging/usbip/usbip_protocol.txt
index 0f102081e86c..16b6fe27284c 100644
--- a/drivers/staging/usbip/usbip_protocol.txt
+++ b/drivers/staging/usbip/usbip_protocol.txt
@@ -27,7 +27,7 @@ Once the client knows the list of exported USB devices it may decide to use one
27of them. First the client opens a TCP/IP connection towards the server and 27of them. First the client opens a TCP/IP connection towards the server and
28sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the 28sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the
29import was successful the TCP/IP connection remains open and will be used 29import was successful the TCP/IP connection remains open and will be used
30to trasfer the URB traffic between the client and the server. The client may 30to transfer the URB traffic between the client and the server. The client may
31send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and 31send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and
32USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the 32USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the
33server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively. 33server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively.
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
index 269787751b20..0958ba53e94a 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
@@ -59,7 +59,10 @@ static int parse_status(char *value)
59 59
60 60
61 /* skip a header line */ 61 /* skip a header line */
62 c = strchr(value, '\n') + 1; 62 c = strchr(value, '\n');
63 if (!c)
64 return -1;
65 c++;
63 66
64 while (*c != '\0') { 67 while (*c != '\0') {
65 int port, status, speed, devid; 68 int port, status, speed, devid;
@@ -109,7 +112,10 @@ static int parse_status(char *value)
109 112
110 113
111 /* go to the next line */ 114 /* go to the next line */
112 c = strchr(c, '\n') + 1; 115 c = strchr(c, '\n');
116 if (!c)
117 break;
118 c++;
113 } 119 }
114 120
115 dbg("exit"); 121 dbg("exit");
@@ -264,11 +270,17 @@ static int get_nports(void)
264 attr_status->method, attr_status->value); 270 attr_status->method, attr_status->value);
265 271
266 /* skip a header line */ 272 /* skip a header line */
267 c = strchr(attr_status->value, '\n') + 1; 273 c = strchr(attr_status->value, '\n');
274 if (!c)
275 return 0;
276 c++;
268 277
269 while (*c != '\0') { 278 while (*c != '\0') {
270 /* go to the next line */ 279 /* go to the next line */
271 c = strchr(c, '\n') + 1; 280 c = strchr(c, '\n');
281 if (!c)
282 return nports;
283 c++;
272 nports += 1; 284 nports += 1;
273 } 285 }
274 286
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index dca9bf11f0c2..f708cbaee16b 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -821,10 +821,10 @@ static void vhci_shutdown_connection(struct usbip_device *ud)
821 } 821 }
822 822
823 /* kill threads related to this sdev, if v.c. exists */ 823 /* kill threads related to this sdev, if v.c. exists */
824 if (vdev->ud.tcp_rx && !task_is_dead(vdev->ud.tcp_rx)) 824 if (vdev->ud.tcp_rx)
825 kthread_stop(vdev->ud.tcp_rx); 825 kthread_stop_put(vdev->ud.tcp_rx);
826 if (vdev->ud.tcp_tx && !task_is_dead(vdev->ud.tcp_tx)) 826 if (vdev->ud.tcp_tx)
827 kthread_stop(vdev->ud.tcp_tx); 827 kthread_stop_put(vdev->ud.tcp_tx);
828 828
829 pr_info("stop threads\n"); 829 pr_info("stop threads\n");
830 830
diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
index f5fba7320c5a..f0eaf04fa25b 100644
--- a/drivers/staging/usbip/vhci_rx.c
+++ b/drivers/staging/usbip/vhci_rx.c
@@ -162,7 +162,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
162 * already received the result of its submit result and gave 162 * already received the result of its submit result and gave
163 * back the URB. 163 * back the URB.
164 */ 164 */
165 pr_info("the urb (seqnum %d) was already given backed\n", 165 pr_info("the urb (seqnum %d) was already given back\n",
166 pdu->base.seqnum); 166 pdu->base.seqnum);
167 } else { 167 } else {
168 usbip_dbg_vhci_rx("now giveback urb %p\n", urb); 168 usbip_dbg_vhci_rx("now giveback urb %p\n", urb);
diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
index 0cd039bb5fd6..7ce9c2f7e442 100644
--- a/drivers/staging/usbip/vhci_sysfs.c
+++ b/drivers/staging/usbip/vhci_sysfs.c
@@ -222,8 +222,8 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
222 spin_unlock(&the_controller->lock); 222 spin_unlock(&the_controller->lock);
223 /* end the lock */ 223 /* end the lock */
224 224
225 vdev->ud.tcp_rx = kthread_run(vhci_rx_loop, &vdev->ud, "vhci_rx"); 225 vdev->ud.tcp_rx = kthread_get_run(vhci_rx_loop, &vdev->ud, "vhci_rx");
226 vdev->ud.tcp_tx = kthread_run(vhci_tx_loop, &vdev->ud, "vhci_tx"); 226 vdev->ud.tcp_tx = kthread_get_run(vhci_tx_loop, &vdev->ud, "vhci_tx");
227 227
228 rh_port_connect(rhport, speed); 228 rh_port_connect(rhport, speed);
229 229
diff --git a/drivers/staging/vme/Makefile b/drivers/staging/vme/Makefile
index b4ea3f8d0a50..accdb72e39e2 100644
--- a/drivers/staging/vme/Makefile
+++ b/drivers/staging/vme/Makefile
@@ -1,8 +1 @@
1#
2# Makefile for the VME bridge device drivers.
3#
4obj-$(CONFIG_VME_BUS) += vme.o
5
6obj-y += bridges/
7obj-y += devices/ obj-y += devices/
8obj-y += boards/
diff --git a/drivers/staging/vme/TODO b/drivers/staging/vme/TODO
deleted file mode 100644
index 79f00333e7ef..000000000000
--- a/drivers/staging/vme/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
1 TODO
2 ====
3
4- Add one or more device drivers which use the VME framework.
5
diff --git a/drivers/staging/vme/devices/Kconfig b/drivers/staging/vme/devices/Kconfig
index 55ec30cb1fa2..d0cab1766190 100644
--- a/drivers/staging/vme/devices/Kconfig
+++ b/drivers/staging/vme/devices/Kconfig
@@ -2,6 +2,7 @@ comment "VME Device Drivers"
2 2
3config VME_USER 3config VME_USER
4 tristate "VME user space access driver" 4 tristate "VME user space access driver"
5 depends on STAGING
5 help 6 help
6 If you say Y here you want to be able to access a limited number of 7 If you say Y here you want to be able to access a limited number of
7 VME windows in a manner at least semi-compatible with the interface 8 VME windows in a manner at least semi-compatible with the interface
@@ -9,7 +10,7 @@ config VME_USER
9 10
10config VME_PIO2 11config VME_PIO2
11 tristate "GE PIO2 VME" 12 tristate "GE PIO2 VME"
12 depends on GPIOLIB 13 depends on STAGING && GPIOLIB
13 help 14 help
14 Say Y here to include support for the GE PIO2. The PIO2 is a 6U VME 15 Say Y here to include support for the GE PIO2. The PIO2 is a 6U VME
15 slave card, implementing 32 solid-state relay switched IO lines, in 16 slave card, implementing 32 solid-state relay switched IO lines, in
diff --git a/drivers/staging/vme/devices/vme_pio2_cntr.c b/drivers/staging/vme/devices/vme_pio2_cntr.c
index 08e0d59806ca..6335471faa36 100644
--- a/drivers/staging/vme/devices/vme_pio2_cntr.c
+++ b/drivers/staging/vme/devices/vme_pio2_cntr.c
@@ -17,8 +17,8 @@
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/gpio.h> 19#include <linux/gpio.h>
20#include <linux/vme.h>
20 21
21#include "../vme.h"
22#include "vme_pio2.h" 22#include "vme_pio2.h"
23 23
24static int pio2_cntr_irq_set(struct pio2_card *card, int id) 24static int pio2_cntr_irq_set(struct pio2_card *card, int id)
diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c
index 573c80003f0c..4bf8e05ac312 100644
--- a/drivers/staging/vme/devices/vme_pio2_core.c
+++ b/drivers/staging/vme/devices/vme_pio2_core.c
@@ -10,7 +10,6 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13#include <linux/version.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
16#include <linux/types.h> 15#include <linux/types.h>
@@ -20,8 +19,8 @@
20#include <linux/ctype.h> 19#include <linux/ctype.h>
21#include <linux/gpio.h> 20#include <linux/gpio.h>
22#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/vme.h>
23 23
24#include "../vme.h"
25#include "vme_pio2.h" 24#include "vme_pio2.h"
26 25
27 26
diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c b/drivers/staging/vme/devices/vme_pio2_gpio.c
index 858484915f08..ad76a477825b 100644
--- a/drivers/staging/vme/devices/vme_pio2_gpio.c
+++ b/drivers/staging/vme/devices/vme_pio2_gpio.c
@@ -10,7 +10,6 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13#include <linux/version.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
16#include <linux/types.h> 15#include <linux/types.h>
@@ -21,8 +20,8 @@
21#include <linux/ctype.h> 20#include <linux/ctype.h>
22#include <linux/gpio.h> 21#include <linux/gpio.h>
23#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/vme.h>
24 24
25#include "../vme.h"
26#include "vme_pio2.h" 25#include "vme_pio2.h"
27 26
28static const char driver_name[] = "pio2_gpio"; 27static const char driver_name[] = "pio2_gpio";
@@ -79,7 +78,7 @@ static void pio2_gpio_set(struct gpio_chip *chip, unsigned int offset,
79 if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) | 78 if ((card->bank[PIO2_CHANNEL_BANK[offset]].config == INPUT) |
80 (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) { 79 (card->bank[PIO2_CHANNEL_BANK[offset]].config == NOFIT)) {
81 80
82 dev_err(&card->vdev->dev, "Channel not availabe as output\n"); 81 dev_err(&card->vdev->dev, "Channel not available as output\n");
83 return; 82 return;
84 } 83 }
85 84
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 7dcd1622b5f5..e24a6f95db12 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -27,7 +27,7 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pagemap.h> 28#include <linux/pagemap.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/semaphore.h> 30#include <linux/mutex.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/spinlock.h> 32#include <linux/spinlock.h>
33#include <linux/syscalls.h> 33#include <linux/syscalls.h>
@@ -36,8 +36,8 @@
36 36
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/vme.h>
39 40
40#include "../vme.h"
41#include "vme_user.h" 41#include "vme_user.h"
42 42
43static DEFINE_MUTEX(vme_user_mutex); 43static DEFINE_MUTEX(vme_user_mutex);
@@ -95,7 +95,7 @@ struct image_desc {
95 void *kern_buf; /* Buffer address in kernel space */ 95 void *kern_buf; /* Buffer address in kernel space */
96 dma_addr_t pci_buf; /* Buffer address in PCI address space */ 96 dma_addr_t pci_buf; /* Buffer address in PCI address space */
97 unsigned long long size_buf; /* Buffer size */ 97 unsigned long long size_buf; /* Buffer size */
98 struct semaphore sem; /* Semaphore for locking image */ 98 struct mutex mutex; /* Mutex for locking image */
99 struct device *device; /* Sysfs device */ 99 struct device *device; /* Sysfs device */
100 struct vme_resource *resource; /* VME resource */ 100 struct vme_resource *resource; /* VME resource */
101 int users; /* Number of current users */ 101 int users; /* Number of current users */
@@ -168,7 +168,7 @@ static int vme_user_open(struct inode *inode, struct file *file)
168 int err; 168 int err;
169 unsigned int minor = MINOR(inode->i_rdev); 169 unsigned int minor = MINOR(inode->i_rdev);
170 170
171 down(&image[minor].sem); 171 mutex_lock(&image[minor].mutex);
172 /* Allow device to be opened if a resource is needed and allocated. */ 172 /* Allow device to be opened if a resource is needed and allocated. */
173 if (minor < CONTROL_MINOR && image[minor].resource == NULL) { 173 if (minor < CONTROL_MINOR && image[minor].resource == NULL) {
174 printk(KERN_ERR "No resources allocated for device\n"); 174 printk(KERN_ERR "No resources allocated for device\n");
@@ -179,12 +179,12 @@ static int vme_user_open(struct inode *inode, struct file *file)
179 /* Increment user count */ 179 /* Increment user count */
180 image[minor].users++; 180 image[minor].users++;
181 181
182 up(&image[minor].sem); 182 mutex_unlock(&image[minor].mutex);
183 183
184 return 0; 184 return 0;
185 185
186err_res: 186err_res:
187 up(&image[minor].sem); 187 mutex_unlock(&image[minor].mutex);
188 188
189 return err; 189 return err;
190} 190}
@@ -193,12 +193,12 @@ static int vme_user_release(struct inode *inode, struct file *file)
193{ 193{
194 unsigned int minor = MINOR(inode->i_rdev); 194 unsigned int minor = MINOR(inode->i_rdev);
195 195
196 down(&image[minor].sem); 196 mutex_lock(&image[minor].mutex);
197 197
198 /* Decrement user count */ 198 /* Decrement user count */
199 image[minor].users--; 199 image[minor].users--;
200 200
201 up(&image[minor].sem); 201 mutex_unlock(&image[minor].mutex);
202 202
203 return 0; 203 return 0;
204} 204}
@@ -325,14 +325,14 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
325 if (minor == CONTROL_MINOR) 325 if (minor == CONTROL_MINOR)
326 return 0; 326 return 0;
327 327
328 down(&image[minor].sem); 328 mutex_lock(&image[minor].mutex);
329 329
330 /* XXX Do we *really* want this helper - we can use vme_*_get ? */ 330 /* XXX Do we *really* want this helper - we can use vme_*_get ? */
331 image_size = vme_get_size(image[minor].resource); 331 image_size = vme_get_size(image[minor].resource);
332 332
333 /* Ensure we are starting at a valid location */ 333 /* Ensure we are starting at a valid location */
334 if ((*ppos < 0) || (*ppos > (image_size - 1))) { 334 if ((*ppos < 0) || (*ppos > (image_size - 1))) {
335 up(&image[minor].sem); 335 mutex_unlock(&image[minor].mutex);
336 return 0; 336 return 0;
337 } 337 }
338 338
@@ -353,8 +353,7 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
353 retval = -EINVAL; 353 retval = -EINVAL;
354 } 354 }
355 355
356 up(&image[minor].sem); 356 mutex_unlock(&image[minor].mutex);
357
358 if (retval > 0) 357 if (retval > 0)
359 *ppos += retval; 358 *ppos += retval;
360 359
@@ -372,13 +371,13 @@ static ssize_t vme_user_write(struct file *file, const char __user *buf,
372 if (minor == CONTROL_MINOR) 371 if (minor == CONTROL_MINOR)
373 return 0; 372 return 0;
374 373
375 down(&image[minor].sem); 374 mutex_lock(&image[minor].mutex);
376 375
377 image_size = vme_get_size(image[minor].resource); 376 image_size = vme_get_size(image[minor].resource);
378 377
379 /* Ensure we are starting at a valid location */ 378 /* Ensure we are starting at a valid location */
380 if ((*ppos < 0) || (*ppos > (image_size - 1))) { 379 if ((*ppos < 0) || (*ppos > (image_size - 1))) {
381 up(&image[minor].sem); 380 mutex_unlock(&image[minor].mutex);
382 return 0; 381 return 0;
383 } 382 }
384 383
@@ -398,8 +397,8 @@ static ssize_t vme_user_write(struct file *file, const char __user *buf,
398 default: 397 default:
399 retval = -EINVAL; 398 retval = -EINVAL;
400 } 399 }
401 400
402 up(&image[minor].sem); 401 mutex_unlock(&image[minor].mutex);
403 402
404 if (retval > 0) 403 if (retval > 0)
405 *ppos += retval; 404 *ppos += retval;
@@ -416,7 +415,7 @@ static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
416 if (minor == CONTROL_MINOR) 415 if (minor == CONTROL_MINOR)
417 return -EINVAL; 416 return -EINVAL;
418 417
419 down(&image[minor].sem); 418 mutex_lock(&image[minor].mutex);
420 image_size = vme_get_size(image[minor].resource); 419 image_size = vme_get_size(image[minor].resource);
421 420
422 switch (whence) { 421 switch (whence) {
@@ -430,19 +429,19 @@ static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
430 absolute = image_size + off; 429 absolute = image_size + off;
431 break; 430 break;
432 default: 431 default:
433 up(&image[minor].sem); 432 mutex_unlock(&image[minor].mutex);
434 return -EINVAL; 433 return -EINVAL;
435 break; 434 break;
436 } 435 }
437 436
438 if ((absolute < 0) || (absolute >= image_size)) { 437 if ((absolute < 0) || (absolute >= image_size)) {
439 up(&image[minor].sem); 438 mutex_unlock(&image[minor].mutex);
440 return -EINVAL; 439 return -EINVAL;
441 } 440 }
442 441
443 file->f_pos = absolute; 442 file->f_pos = absolute;
444 443
445 up(&image[minor].sem); 444 mutex_unlock(&image[minor].mutex);
446 445
447 return absolute; 446 return absolute;
448} 447}
@@ -696,7 +695,7 @@ static int __devinit vme_user_probe(struct vme_dev *vdev)
696 for (i = 0; i < VME_DEVS; i++) { 695 for (i = 0; i < VME_DEVS; i++) {
697 image[i].kern_buf = NULL; 696 image[i].kern_buf = NULL;
698 image[i].pci_buf = 0; 697 image[i].pci_buf = 0;
699 sema_init(&image[i].sem, 1); 698 mutex_init(&image[i].mutex);
700 image[i].device = NULL; 699 image[i].device = NULL;
701 image[i].resource = NULL; 700 image[i].resource = NULL;
702 image[i].users = 0; 701 image[i].users = 0;
@@ -858,8 +857,10 @@ static int __devexit vme_user_remove(struct vme_dev *dev)
858 int i; 857 int i;
859 858
860 /* Remove sysfs Entries */ 859 /* Remove sysfs Entries */
861 for (i = 0; i < VME_DEVS; i++) 860 for (i = 0; i < VME_DEVS; i++) {
861 mutex_destroy(&image[i].mutex);
862 device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 862 device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i));
863 }
863 class_destroy(vme_user_sysfs_class); 864 class_destroy(vme_user_sysfs_class);
864 865
865 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) { 866 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) {
diff --git a/drivers/staging/vt6655/wpa.c b/drivers/staging/vt6655/wpa.c
index 61ac46fa505e..0afb9fe0379a 100644
--- a/drivers/staging/vt6655/wpa.c
+++ b/drivers/staging/vt6655/wpa.c
@@ -148,7 +148,7 @@ WPA_ParseRSN (
148 { 148 {
149 j = 0; 149 j = 0;
150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType)); 150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
151 for(i = 0; (i < pRSN->wPKCount) && (j < sizeof(pBSSList->abyPKType)/sizeof(unsigned char)); i++) { 151 for(i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
152 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i) 152 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
153 if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4)) 153 if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
154 pBSSList->abyPKType[j++] = WPA_NONE; 154 pBSSList->abyPKType[j++] = WPA_NONE;
@@ -180,7 +180,7 @@ WPA_ParseRSN (
180 j = 0; 180 j = 0;
181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n", 181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
182 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType)); 182 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
183 for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < sizeof(pBSSList->abyAuthType)/sizeof(unsigned char)); i++) { 183 for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
184 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i) 184 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
185 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4)) 185 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
186 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X; 186 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c
index c0edf97535dc..e4bdf2a2b582 100644
--- a/drivers/staging/vt6656/dpc.c
+++ b/drivers/staging/vt6656/dpc.c
@@ -452,7 +452,7 @@ RXbBulkInProcessData (
452 } 452 }
453 } 453 }
454 454
455 if (!is_multicast_ether_addr(pMACHeader->abyAddr1) && !is_broadcast_ether_addr(pMACHeader->abyAddr1)) { 455 if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) {
456 if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) { 456 if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
457 pDevice->s802_11Counter.FrameDuplicateCount++; 457 pDevice->s802_11Counter.FrameDuplicateCount++;
458 return FALSE; 458 return FALSE;
diff --git a/drivers/staging/vt6656/ioctl.c b/drivers/staging/vt6656/ioctl.c
index d59456c29df1..5b9a84f95185 100644
--- a/drivers/staging/vt6656/ioctl.c
+++ b/drivers/staging/vt6656/ioctl.c
@@ -90,18 +90,17 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
90 spin_lock_irq(&pDevice->lock); 90 spin_lock_irq(&pDevice->lock);
91 91
92 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0) 92 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
93 BSSvClearBSSList((void *)pDevice, FALSE); 93 BSSvClearBSSList(pDevice, FALSE);
94 else 94 else
95 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass); 95 BSSvClearBSSList(pDevice, pDevice->bLinkPass);
96 96
97 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin\n"); 97 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin\n");
98 98
99 if (pItemSSID->len != 0) 99 if (pItemSSID->len != 0)
100 bScheduleCommand((void *)pDevice, 100 bScheduleCommand(pDevice, WLAN_CMD_BSSID_SCAN,
101 WLAN_CMD_BSSID_SCAN,
102 abyScanSSID); 101 abyScanSSID);
103 else 102 else
104 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); 103 bScheduleCommand(pDevice, WLAN_CMD_BSSID_SCAN, NULL);
105 104
106 spin_unlock_irq(&pDevice->lock); 105 spin_unlock_irq(&pDevice->lock);
107 break; 106 break;
@@ -150,6 +149,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
150 } 149 }
151 } 150 }
152 break; 151 break;
152
153 case WLAN_CMD_BSS_JOIN: 153 case WLAN_CMD_BSS_JOIN:
154 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) { 154 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
155 result = -EFAULT; 155 result = -EFAULT;
@@ -190,10 +190,9 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
190 netif_stop_queue(pDevice->dev); 190 netif_stop_queue(pDevice->dev);
191 spin_lock_irq(&pDevice->lock); 191 spin_lock_irq(&pDevice->lock);
192 pMgmt->eCurrState = WMAC_STATE_IDLE; 192 pMgmt->eCurrState = WMAC_STATE_IDLE;
193 bScheduleCommand((void *) pDevice, 193 bScheduleCommand(pDevice, WLAN_CMD_BSSID_SCAN,
194 WLAN_CMD_BSSID_SCAN,
195 pMgmt->abyDesireSSID); 194 pMgmt->abyDesireSSID);
196 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL); 195 bScheduleCommand(pDevice, WLAN_CMD_SSID, NULL);
197 spin_unlock_irq(&pDevice->lock); 196 spin_unlock_irq(&pDevice->lock);
198 break; 197 break;
199 198
@@ -299,7 +298,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
299 result = -EINVAL; 298 result = -EINVAL;
300 break; 299 break;
301 } 300 }
302 pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC); 301 pList = kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), GFP_ATOMIC);
303 if (pList == NULL) { 302 if (pList == NULL) {
304 result = -ENOMEM; 303 result = -ENOMEM;
305 break; 304 break;
@@ -313,7 +312,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
313 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval; 312 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
314 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo; 313 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
315 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm); 314 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
316 pList->sBSSIDList[ii].uRSSI = (unsigned int) ldBm; 315 pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm;
317 /* pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI; */ 316 /* pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI; */
318 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN); 317 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
319 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID; 318 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
@@ -356,6 +355,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
356 break; 355 break;
357 } 356 }
358 break; 357 break;
358
359 case WLAN_CMD_STOP_MAC: 359 case WLAN_CMD_STOP_MAC:
360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n"); 360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
361 /* Todo xxxxxx */ 361 /* Todo xxxxxx */
@@ -534,7 +534,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
534 534
535 netif_stop_queue(pDevice->dev); 535 netif_stop_queue(pDevice->dev);
536 spin_lock_irq(&pDevice->lock); 536 spin_lock_irq(&pDevice->lock);
537 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL); 537 bScheduleCommand(pDevice, WLAN_CMD_RUN_AP, NULL);
538 spin_unlock_irq(&pDevice->lock); 538 spin_unlock_irq(&pDevice->lock);
539 break; 539 break;
540 540
@@ -565,7 +565,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
565 result = -ENOMEM; 565 result = -ENOMEM;
566 break; 566 break;
567 } 567 }
568 pNodeList = kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC); 568 pNodeList = kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), GFP_ATOMIC);
569 if (pNodeList == NULL) { 569 if (pNodeList == NULL) {
570 result = -ENOMEM; 570 result = -ENOMEM;
571 break; 571 break;
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index 763e028a5cc5..ee5261a36886 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -1257,9 +1257,7 @@ static void __devexit vt6656_disconnect(struct usb_interface *intf)
1257 } 1257 }
1258 1258
1259 device_release_WPADEV(device); 1259 device_release_WPADEV(device);
1260 1260 release_firmware(device->firmware);
1261 if (device->firmware)
1262 release_firmware(device->firmware);
1263 1261
1264 usb_set_intfdata(intf, NULL); 1262 usb_set_intfdata(intf, NULL);
1265 usb_put_dev(interface_to_usbdev(intf)); 1263 usb_put_dev(interface_to_usbdev(intf));
diff --git a/drivers/staging/vt6656/wpa.c b/drivers/staging/vt6656/wpa.c
index 7dde3d6941ab..b16d4ddc117b 100644
--- a/drivers/staging/vt6656/wpa.c
+++ b/drivers/staging/vt6656/wpa.c
@@ -149,7 +149,7 @@ WPA_ParseRSN(
149 j = 0; 149 j = 0;
150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType)); 150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
151 for (i = 0; (i < pRSN->wPKCount) && 151 for (i = 0; (i < pRSN->wPKCount) &&
152 (j < sizeof(pBSSList->abyPKType)/sizeof(BYTE)); i++) { 152 (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
153 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i) 153 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
154 if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4)) 154 if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
155 pBSSList->abyPKType[j++] = WPA_NONE; 155 pBSSList->abyPKType[j++] = WPA_NONE;
@@ -182,7 +182,7 @@ WPA_ParseRSN(
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n", 182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
183 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType)); 183 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
184 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) && 184 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) &&
185 (j < sizeof(pBSSList->abyAuthType)/sizeof(BYTE)); i++) { 185 (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
186 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i) 186 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
187 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4)) 187 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
188 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X; 188 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
diff --git a/drivers/staging/wlags49_h2/README.ubuntu b/drivers/staging/wlags49_h2/README.ubuntu
index edee8b9385be..5f1cfb8fd427 100644
--- a/drivers/staging/wlags49_h2/README.ubuntu
+++ b/drivers/staging/wlags49_h2/README.ubuntu
@@ -87,7 +87,7 @@ The linux driver files (wl_xxxx.c) are changed in the following ways:
87-- Recovery actions added 87-- Recovery actions added
88 88
89The major problem was the order in which calls can be made. The original 89The major problem was the order in which calls can be made. The original
90looks like a traditonal UNIX driver. To call an "ioctl" function you 90looks like a traditional UNIX driver. To call an "ioctl" function you
91have to "open" the device first to get a handle and after "close" no 91have to "open" the device first to get a handle and after "close" no
92"ioctl" function can be called anymore. With the 2.6 driver this all 92"ioctl" function can be called anymore. With the 2.6 driver this all
93changed; the former ioctl functions are now called before "open" and 93changed; the former ioctl functions are now called before "open" and
diff --git a/drivers/staging/wlags49_h2/hcf.c b/drivers/staging/wlags49_h2/hcf.c
index 5957c3a439ac..366e4a4b75c5 100644
--- a/drivers/staging/wlags49_h2/hcf.c
+++ b/drivers/staging/wlags49_h2/hcf.c
@@ -2871,8 +2871,8 @@ or
2871* The Assert validates the HCF assumption about Hermes implementation upon which the range of 2871* The Assert validates the HCF assumption about Hermes implementation upon which the range of
2872* Pseudo-RIDs is based. 2872* Pseudo-RIDs is based.
2873* Then the control fields up to the start of the 802.3 frame are read from the NIC into the lookahead buffer. 2873* Then the control fields up to the start of the 802.3 frame are read from the NIC into the lookahead buffer.
2874* The status field is converted to native Endianess. 2874* The status field is converted to native Endianness.
2875* The length is, after implicit Endianess conversion if needed, and adjustment for the 14 bytes of the 2875* The length is, after implicit Endianness conversion if needed, and adjustment for the 14 bytes of the
2876* 802.3 MAC header, stored in IFB_RxLen. 2876* 802.3 MAC header, stored in IFB_RxLen.
2877* In MAC Monitor mode, 802.11 control frames with a TOTAL length of 14 are received, so without this 2877* In MAC Monitor mode, 802.11 control frames with a TOTAL length of 14 are received, so without this
2878* length adjustment, IFB_RxLen could not be used to distinguish these frames from "no frame". 2878* length adjustment, IFB_RxLen could not be used to distinguish these frames from "no frame".
@@ -2894,7 +2894,7 @@ or
2894* - the Hermes reported Tunnel encapsulation or 2894* - the Hermes reported Tunnel encapsulation or
2895* - the Hermes reported 1042 Encapsulation and hcf_encap reports that the HCF would not have used 2895* - the Hermes reported 1042 Encapsulation and hcf_encap reports that the HCF would not have used
2896* 1042 as the encapsulation mechanism 2896* 1042 as the encapsulation mechanism
2897* Note that the first field of the RxFS in bufp has Native Endianess due to the conversion done by the 2897* Note that the first field of the RxFS in bufp has Native Endianness due to the conversion done by the
2898* BE_PAR in get_frag. 2898* BE_PAR in get_frag.
2899*36: The Type field is the only word kept (after moving) of the just read 8 bytes, it is moved to the 2899*36: The Type field is the only word kept (after moving) of the just read 8 bytes, it is moved to the
2900* L-field. The original L-field and 6 byte SNAP header are discarded, so IFB_RxLen and buf_addr must 2900* L-field. The original L-field and 6 byte SNAP header are discarded, so IFB_RxLen and buf_addr must
@@ -3831,7 +3831,7 @@ get_fid( IFBP ifbp )
3831 *.DESCRIPTION 3831 *.DESCRIPTION
3832 * process the single byte (if applicable) read by the previous get_frag and copy len (or len-1) bytes from 3832 * process the single byte (if applicable) read by the previous get_frag and copy len (or len-1) bytes from
3833 * NIC to bufp. 3833 * NIC to bufp.
3834 * On a Big Endian platform, the parameter word_len controls the number of leading bytes whose endianess is 3834 * On a Big Endian platform, the parameter word_len controls the number of leading bytes whose endianness is
3835 * converted (i.e. byte swapped) 3835 * converted (i.e. byte swapped)
3836 * 3836 *
3837 * 3837 *
@@ -3980,7 +3980,7 @@ get_frag( IFBP ifbp, wci_bufp bufp, int len BE_PAR( int word_len ) )
3980 * appropriate means on H-I: always 3980 * appropriate means on H-I: always
3981 * and on H-II if F/W supplier reflects a primary (i.e. only after an Hermes Reset or Init 3981 * and on H-II if F/W supplier reflects a primary (i.e. only after an Hermes Reset or Init
3982 * command). 3982 * command).
3983 * QUESTION ;? !!!!!! should, For each of the above RIDs the Endianess is converted to native Endianess. 3983 * QUESTION ;? !!!!!! should, For each of the above RIDs the Endianness is converted to native Endianness.
3984 * Only the return code of the first hcf_get_info is used. All hcf_get_info calls are made, regardless of 3984 * Only the return code of the first hcf_get_info is used. All hcf_get_info calls are made, regardless of
3985 * the success or failure of the 1st hcf_get_info. The assumptions are: 3985 * the success or failure of the 1st hcf_get_info. The assumptions are:
3986 * - if any call fails, they all fail, so remembering the result of the 1st call is adequate 3986 * - if any call fails, they all fail, so remembering the result of the 1st call is adequate
diff --git a/drivers/staging/wlags49_h2/hcf.h b/drivers/staging/wlags49_h2/hcf.h
index 95527b5cf863..68e23303b5e8 100644
--- a/drivers/staging/wlags49_h2/hcf.h
+++ b/drivers/staging/wlags49_h2/hcf.h
@@ -90,7 +90,7 @@
90 90
91#define LOF(x) (sizeof(x)/sizeof(hcf_16)-1) 91#define LOF(x) (sizeof(x)/sizeof(hcf_16)-1)
92 92
93/* Endianess 93/* Endianness
94 * Little Endian (a.k.a. Intel), least significant byte first 94 * Little Endian (a.k.a. Intel), least significant byte first
95 * Big Endian (a.k.a. Motorola), most significant byte first 95 * Big Endian (a.k.a. Motorola), most significant byte first
96 * 96 *
@@ -101,7 +101,7 @@
101 */ 101 */
102 102
103/* To increase portability, use unsigned char and unsigned char * when accessing parts of larger 103/* To increase portability, use unsigned char and unsigned char * when accessing parts of larger
104 * types to convert their Endianess 104 * types to convert their Endianness
105 */ 105 */
106 106
107#define CNV_END_SHORT(w) (hcf_16)( ((hcf_16)(w) & 0x00FF) << 8 | ((hcf_16)(w) & 0xFF00) >> 8 ) 107#define CNV_END_SHORT(w) (hcf_16)( ((hcf_16)(w) & 0x00FF) << 8 | ((hcf_16)(w) & 0xFF00) >> 8 )
@@ -109,14 +109,14 @@
109 109
110#if HCF_BIG_ENDIAN 110#if HCF_BIG_ENDIAN
111//******************************************** B I G E N D I A N ******************************************* 111//******************************************** B I G E N D I A N *******************************************
112#define CNV_LITTLE_TO_SHORT(w) CNV_END_SHORT(w) // endianess conversion needed 112#define CNV_LITTLE_TO_SHORT(w) CNV_END_SHORT(w) // endianness conversion needed
113#define CNV_BIG_TO_SHORT(w) (w) // no endianess conversion needed 113#define CNV_BIG_TO_SHORT(w) (w) // no endianness conversion needed
114#define CNV_LITTLE_TO_LONG(dw) CNV_END_LONG(dw) 114#define CNV_LITTLE_TO_LONG(dw) CNV_END_LONG(dw)
115#define CNV_LONG_TO_LITTLE(dw) CNV_END_LONG(dw) 115#define CNV_LONG_TO_LITTLE(dw) CNV_END_LONG(dw)
116#else 116#else
117//****************************************** L I T T L E E N D I A N **************************************** 117//****************************************** L I T T L E E N D I A N ****************************************
118#define CNV_LITTLE_TO_SHORT(w) (w) // no endianess conversion needed 118#define CNV_LITTLE_TO_SHORT(w) (w) // no endianness conversion needed
119#define CNV_BIG_TO_SHORT(w) CNV_END_SHORT(w) // endianess conversion needed 119#define CNV_BIG_TO_SHORT(w) CNV_END_SHORT(w) // endianness conversion needed
120#define CNV_LITTLE_TO_LONG(dw) (dw) 120#define CNV_LITTLE_TO_LONG(dw) (dw)
121#define CNV_LONG_TO_LITTLE(dw) (dw) 121#define CNV_LONG_TO_LITTLE(dw) (dw)
122 122
diff --git a/drivers/staging/wlags49_h2/mmd.c b/drivers/staging/wlags49_h2/mmd.c
index c8f52107e6ca..7204a373bc51 100644
--- a/drivers/staging/wlags49_h2/mmd.c
+++ b/drivers/staging/wlags49_h2/mmd.c
@@ -101,10 +101,10 @@
101* supp address of the supplier specification 101* supp address of the supplier specification
102* 102*
103* Description: mmd_check_comp is a support routine to check the compatibility between an actor and a 103* Description: mmd_check_comp is a support routine to check the compatibility between an actor and a
104* supplier. mmd_check_comp is independent of the endianess of the actp and supp structures. This is 104* supplier. mmd_check_comp is independent of the endianness of the actp and supp structures. This is
105* achieved by checking the "bottom" or "role" fields of these structures. Since these fields are restricted 105* achieved by checking the "bottom" or "role" fields of these structures. Since these fields are restricted
106* to a limited range, comparing the contents to a value with a known endian-ess gives a clue to their actual 106* to a limited range, comparing the contents to a value with a known endian-ess gives a clue to their actual
107* endianess. 107* endianness.
108* 108*
109*.DIAGRAM 109*.DIAGRAM
110*1a: The role-field of the actor structure has a known non-zero, not "byte symmetric" value (namely 110*1a: The role-field of the actor structure has a known non-zero, not "byte symmetric" value (namely
@@ -114,16 +114,16 @@
114* for a supplier. A supplier has always exactly 1 variant,top,bottom record with (officially, but see the 114* for a supplier. A supplier has always exactly 1 variant,top,bottom record with (officially, but see the
115* note below) each of these 3 values in the range 1 through 99, so one byte of the word value of variant, 115* note below) each of these 3 values in the range 1 through 99, so one byte of the word value of variant,
116* top and bottom words is 0x00 and the other byte is non-zero. Whether the lowest address byte or the 116* top and bottom words is 0x00 and the other byte is non-zero. Whether the lowest address byte or the
117* highest address byte is non-zero depends on the Endianess of the LTV. If and only if the word value of 117* highest address byte is non-zero depends on the Endianness of the LTV. If and only if the word value of
118* bottom is less than 0x0100, the supplier is Native Endian. 118* bottom is less than 0x0100, the supplier is Native Endian.
119* NOTE: the variant field of the supplier structure can not be used for the Endian Detection Algorithm, 119* NOTE: the variant field of the supplier structure can not be used for the Endian Detection Algorithm,
120* because a a zero-valued variant has been used as Controlled Deployment indication in the past. 120* because a a zero-valued variant has been used as Controlled Deployment indication in the past.
121* Note: An actor may have multiple sets of variant,top,bottom records, including dummy sets with variant, 121* Note: An actor may have multiple sets of variant,top,bottom records, including dummy sets with variant,
122* top and bottom fields with a zero-value. As a consequence the endianess of the actor can not be determined 122* top and bottom fields with a zero-value. As a consequence the endianness of the actor can not be determined
123* based on its variant,top,bottom values. 123* based on its variant,top,bottom values.
124* 124*
125* Note: the L and T field of the structures are always in Native Endian format, so you can not draw 125* Note: the L and T field of the structures are always in Native Endian format, so you can not draw
126* conclusions concerning the Endianess of the structure based on these two fields. 126* conclusions concerning the Endianness of the structure based on these two fields.
127* 127*
128*1b/2b 128*1b/2b
129* The only purpose of the CFG_RANGE_SPEC_BYTE_STRCT is to give easy access to the non-zero byte of the word 129* The only purpose of the CFG_RANGE_SPEC_BYTE_STRCT is to give easy access to the non-zero byte of the word
@@ -149,7 +149,7 @@
149* 149*
150* This is implemented as: 150* This is implemented as:
151* #if HCF_BIG_ENDIAN == 0 //platform is LE 151* #if HCF_BIG_ENDIAN == 0 //platform is LE
152* sup/act_endian becomes reverse of structure-endianess as determined in 1a/1b 152* sup/act_endian becomes reverse of structure-endianness as determined in 1a/1b
153* #endif 153* #endif
154*6: Each of the actor variant-bottom-top records is checked against the (single) supplier variant-bottom-top 154*6: Each of the actor variant-bottom-top records is checked against the (single) supplier variant-bottom-top
155* range till either an acceptable match is found or all actor records are tried. As explained above, due to 155* range till either an acceptable match is found or all actor records are tried. As explained above, due to
diff --git a/drivers/staging/wlags49_h2/wl_cs.c b/drivers/staging/wlags49_h2/wl_cs.c
index 7084f414846e..7c7c77f9c862 100644
--- a/drivers/staging/wlags49_h2/wl_cs.c
+++ b/drivers/staging/wlags49_h2/wl_cs.c
@@ -177,10 +177,9 @@ static void wl_adapter_detach(struct pcmcia_device *link)
177 if (dev) { 177 if (dev) {
178 unregister_wlags_sysfs(dev); 178 unregister_wlags_sysfs(dev);
179 unregister_netdev(dev); 179 unregister_netdev(dev);
180 wl_device_dealloc(dev);
180 } 181 }
181 182
182 wl_device_dealloc(dev);
183
184 DBG_LEAVE(DbgInfo); 183 DBG_LEAVE(DbgInfo);
185} /* wl_adapter_detach */ 184} /* wl_adapter_detach */
186/*============================================================================*/ 185/*============================================================================*/
diff --git a/drivers/staging/wlags49_h2/wl_netdev.c b/drivers/staging/wlags49_h2/wl_netdev.c
index 90820ff1aced..824b85232353 100644
--- a/drivers/staging/wlags49_h2/wl_netdev.c
+++ b/drivers/staging/wlags49_h2/wl_netdev.c
@@ -1063,7 +1063,7 @@ void wl_multicast( struct net_device *dev )
1063#if DBG 1063#if DBG
1064 if( DBG_FLAGS( DbgInfo ) & DBG_PARAM_ON ) { 1064 if( DBG_FLAGS( DbgInfo ) & DBG_PARAM_ON ) {
1065 DBG_PRINT(" flags: %s%s%s\n", 1065 DBG_PRINT(" flags: %s%s%s\n",
1066 ( dev->flags & IFF_PROMISC ) ? "Promiscous " : "", 1066 ( dev->flags & IFF_PROMISC ) ? "Promiscuous " : "",
1067 ( dev->flags & IFF_MULTICAST ) ? "Multicast " : "", 1067 ( dev->flags & IFF_MULTICAST ) ? "Multicast " : "",
1068 ( dev->flags & IFF_ALLMULTI ) ? "All-Multicast" : "" ); 1068 ( dev->flags & IFF_ALLMULTI ) ? "All-Multicast" : "" );
1069 1069
@@ -1510,8 +1510,11 @@ void wl_wds_device_alloc( struct wl_private *lp )
1510 for( count = 0; count < NUM_WDS_PORTS; count++ ) { 1510 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1511 struct net_device *dev_wds = NULL; 1511 struct net_device *dev_wds = NULL;
1512 1512
1513 dev_wds = kmalloc( sizeof( struct net_device ), GFP_KERNEL ); 1513 dev_wds = kzalloc(sizeof(struct net_device), GFP_KERNEL);
1514 memset( dev_wds, 0, sizeof( struct net_device )); 1514 if (!dev_wds) {
1515 DBG_LEAVE(DbgInfo);
1516 return;
1517 }
1515 1518
1516 ether_setup( dev_wds ); 1519 ether_setup( dev_wds );
1517 1520
diff --git a/drivers/staging/wlags49_h2/wl_pci.c b/drivers/staging/wlags49_h2/wl_pci.c
index 3df990c7306a..0b31b01bd490 100644
--- a/drivers/staging/wlags49_h2/wl_pci.c
+++ b/drivers/staging/wlags49_h2/wl_pci.c
@@ -524,6 +524,7 @@ int wl_pci_setup( struct pci_dev *pdev )
524 /* Make sure that space was allocated for our private adapter struct */ 524 /* Make sure that space was allocated for our private adapter struct */
525 if( dev->priv == NULL ) { 525 if( dev->priv == NULL ) {
526 DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" ); 526 DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" );
527 wl_device_dealloc(dev);
527 DBG_LEAVE( DbgInfo ); 528 DBG_LEAVE( DbgInfo );
528 return -ENOMEM; 529 return -ENOMEM;
529 } 530 }
@@ -532,6 +533,7 @@ int wl_pci_setup( struct pci_dev *pdev )
532 /* Allocate DMA Descriptors */ 533 /* Allocate DMA Descriptors */
533 if( wl_pci_dma_alloc( pdev, dev->priv ) < 0 ) { 534 if( wl_pci_dma_alloc( pdev, dev->priv ) < 0 ) {
534 DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" ); 535 DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" );
536 wl_device_dealloc(dev);
535 DBG_LEAVE( DbgInfo ); 537 DBG_LEAVE( DbgInfo );
536 return -ENOMEM; 538 return -ENOMEM;
537 } 539 }
@@ -561,6 +563,8 @@ int wl_pci_setup( struct pci_dev *pdev )
561 result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev); 563 result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev);
562 if( result ) { 564 if( result ) {
563 DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" ); 565 DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" );
566 wl_remove(dev);
567 wl_device_dealloc(dev);
564 DBG_LEAVE( DbgInfo ); 568 DBG_LEAVE( DbgInfo );
565 return result; 569 return result;
566 } 570 }
diff --git a/drivers/staging/wlags49_h2/wl_profile.c b/drivers/staging/wlags49_h2/wl_profile.c
index b8c96cf18de5..0e49272bc7a8 100644
--- a/drivers/staging/wlags49_h2/wl_profile.c
+++ b/drivers/staging/wlags49_h2/wl_profile.c
@@ -401,7 +401,7 @@ void translate_option(char *buffer, struct wl_private *lp)
401 if ((value_convert >= PARM_MIN_BRSC) || (value_convert <= PARM_MAX_BRSC)) 401 if ((value_convert >= PARM_MIN_BRSC) || (value_convert <= PARM_MAX_BRSC))
402 lp->brsc[0] = value_convert; 402 lp->brsc[0] = value_convert;
403 else 403 else
404 DBG_WARNING(DbgInfo, "%s invaid; will be ignored\n", PARM_NAME_BRSC_2GHZ); 404 DBG_WARNING(DbgInfo, "%s invalid; will be ignored\n", PARM_NAME_BRSC_2GHZ);
405 } else if (strcmp(key, PARM_NAME_BRSC_5GHZ) == 0) { 405 } else if (strcmp(key, PARM_NAME_BRSC_5GHZ) == 0) {
406 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_BRSC_5GHZ, value); 406 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_BRSC_5GHZ, value);
407 407
@@ -409,7 +409,7 @@ void translate_option(char *buffer, struct wl_private *lp)
409 if ((value_convert >= PARM_MIN_BRSC) || (value_convert <= PARM_MAX_BRSC)) 409 if ((value_convert >= PARM_MIN_BRSC) || (value_convert <= PARM_MAX_BRSC))
410 lp->brsc[1] = value_convert; 410 lp->brsc[1] = value_convert;
411 else 411 else
412 DBG_WARNING(DbgInfo, "%s invaid; will be ignored\n", PARM_NAME_BRSC_5GHZ); 412 DBG_WARNING(DbgInfo, "%s invalid; will be ignored\n", PARM_NAME_BRSC_5GHZ);
413 } else if ((strcmp(key, PARM_NAME_DESIRED_SSID) == 0) || (strcmp(key, PARM_NAME_OWN_SSID) == 0)) { 413 } else if ((strcmp(key, PARM_NAME_DESIRED_SSID) == 0) || (strcmp(key, PARM_NAME_OWN_SSID) == 0)) {
414 DBG_TRACE(DbgInfo, "SSID, value: %s\n", value); 414 DBG_TRACE(DbgInfo, "SSID, value: %s\n", value);
415 415
@@ -556,7 +556,7 @@ void translate_option(char *buffer, struct wl_private *lp)
556 if ((value_convert >= PARM_MIN_SRSC) || (value_convert <= PARM_MAX_SRSC)) 556 if ((value_convert >= PARM_MIN_SRSC) || (value_convert <= PARM_MAX_SRSC))
557 lp->srsc[0] = value_convert; 557 lp->srsc[0] = value_convert;
558 else 558 else
559 DBG_WARNING(DbgInfo, "%s invaid; will be ignored\n", PARM_NAME_SRSC_2GHZ); 559 DBG_WARNING(DbgInfo, "%s invalid; will be ignored\n", PARM_NAME_SRSC_2GHZ);
560 } else if (strcmp(key, PARM_NAME_SRSC_5GHZ) == 0) { 560 } else if (strcmp(key, PARM_NAME_SRSC_5GHZ) == 0) {
561 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_SRSC_5GHZ, value); 561 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_SRSC_5GHZ, value);
562 562
@@ -564,7 +564,7 @@ void translate_option(char *buffer, struct wl_private *lp)
564 if ((value_convert >= PARM_MIN_SRSC) || (value_convert <= PARM_MAX_SRSC)) 564 if ((value_convert >= PARM_MIN_SRSC) || (value_convert <= PARM_MAX_SRSC))
565 lp->srsc[1] = value_convert; 565 lp->srsc[1] = value_convert;
566 else 566 else
567 DBG_WARNING(DbgInfo, "%s invaid; will be ignored\n", PARM_NAME_SRSC_5GHZ); 567 DBG_WARNING(DbgInfo, "%s invalid; will be ignored\n", PARM_NAME_SRSC_5GHZ);
568 } else if (strcmp(key, PARM_NAME_SYSTEM_SCALE) == 0) { 568 } else if (strcmp(key, PARM_NAME_SYSTEM_SCALE) == 0) {
569 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_SYSTEM_SCALE, value); 569 DBG_TRACE(DbgInfo, "%s, value: %s\n", PARM_NAME_SYSTEM_SCALE, value);
570 570
diff --git a/drivers/staging/wlags49_h2/wl_util.c b/drivers/staging/wlags49_h2/wl_util.c
index f104e6f1e980..404ec7da0348 100644
--- a/drivers/staging/wlags49_h2/wl_util.c
+++ b/drivers/staging/wlags49_h2/wl_util.c
@@ -98,8 +98,7 @@
98 ******************************************************************************/ 98 ******************************************************************************/
99 99
100/* A matrix which maps channels to frequencies */ 100/* A matrix which maps channels to frequencies */
101#define MAX_CHAN_FREQ_MAP_ENTRIES 50 101static const long chan_freq_list[][2] =
102static const long chan_freq_list[][MAX_CHAN_FREQ_MAP_ENTRIES] =
103{ 102{
104 {1,2412}, 103 {1,2412},
105 {2,2417}, 104 {2,2417},
@@ -846,7 +845,7 @@ int wl_is_a_valid_chan( int channel )
846 } 845 }
847 846
848 /* Iterate through the matrix and retrieve the frequency */ 847 /* Iterate through the matrix and retrieve the frequency */
849 for( i = 0; i < MAX_CHAN_FREQ_MAP_ENTRIES; i++ ) { 848 for( i = 0; i < ARRAY_SIZE(chan_freq_list); i++ ) {
850 if( chan_freq_list[i][0] == channel ) { 849 if( chan_freq_list[i][0] == channel ) {
851 return 1; 850 return 1;
852 } 851 }
@@ -884,7 +883,7 @@ int wl_is_a_valid_freq( long frequency )
884 883
885 884
886 /* Iterate through the matrix and retrieve the channel */ 885 /* Iterate through the matrix and retrieve the channel */
887 for( i = 0; i < MAX_CHAN_FREQ_MAP_ENTRIES; i++ ) { 886 for( i = 0; i < ARRAY_SIZE(chan_freq_list); i++ ) {
888 if( chan_freq_list[i][1] == frequency ) { 887 if( chan_freq_list[i][1] == frequency ) {
889 return 1; 888 return 1;
890 } 889 }
@@ -927,7 +926,7 @@ long wl_get_freq_from_chan( int channel )
927 } 926 }
928 927
929 /* Iterate through the matrix and retrieve the frequency */ 928 /* Iterate through the matrix and retrieve the frequency */
930 for( i = 0; i < MAX_CHAN_FREQ_MAP_ENTRIES; i++ ) { 929 for( i = 0; i < ARRAY_SIZE(chan_freq_list); i++ ) {
931 if( chan_freq_list[i][0] == channel ) { 930 if( chan_freq_list[i][0] == channel ) {
932 return chan_freq_list[i][1]; 931 return chan_freq_list[i][1];
933 } 932 }
@@ -965,7 +964,7 @@ int wl_get_chan_from_freq( long frequency )
965 964
966 965
967 /* Iterate through the matrix and retrieve the channel */ 966 /* Iterate through the matrix and retrieve the channel */
968 for( i = 0; i < MAX_CHAN_FREQ_MAP_ENTRIES; i++ ) { 967 for( i = 0; i < ARRAY_SIZE(chan_freq_list); i++ ) {
969 if( chan_freq_list[i][1] == frequency ) { 968 if( chan_freq_list[i][1] == frequency ) {
970 return chan_freq_list[i][0]; 969 return chan_freq_list[i][0];
971 } 970 }
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index 4cd3ba5d5646..8bc562b8c4d9 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -332,6 +332,7 @@ int prism2_scan(struct wiphy *wiphy, struct net_device *dev,
332 wlandevice_t *wlandev = dev->ml_priv; 332 wlandevice_t *wlandev = dev->ml_priv;
333 struct p80211msg_dot11req_scan msg1; 333 struct p80211msg_dot11req_scan msg1;
334 struct p80211msg_dot11req_scan_results msg2; 334 struct p80211msg_dot11req_scan_results msg2;
335 struct cfg80211_bss *bss;
335 int result; 336 int result;
336 int err = 0; 337 int err = 0;
337 int numbss = 0; 338 int numbss = 0;
@@ -401,7 +402,7 @@ int prism2_scan(struct wiphy *wiphy, struct net_device *dev,
401 ie_buf[1] = msg2.ssid.data.len; 402 ie_buf[1] = msg2.ssid.data.len;
402 ie_len = ie_buf[1] + 2; 403 ie_len = ie_buf[1] + 2;
403 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len); 404 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len);
404 cfg80211_inform_bss(wiphy, 405 bss = cfg80211_inform_bss(wiphy,
405 ieee80211_get_channel(wiphy, ieee80211_dsss_chan_to_freq(msg2.dschannel.data)), 406 ieee80211_get_channel(wiphy, ieee80211_dsss_chan_to_freq(msg2.dschannel.data)),
406 (const u8 *) &(msg2.bssid.data.data), 407 (const u8 *) &(msg2.bssid.data.data),
407 msg2.timestamp.data, msg2.capinfo.data, 408 msg2.timestamp.data, msg2.capinfo.data,
@@ -411,6 +412,13 @@ int prism2_scan(struct wiphy *wiphy, struct net_device *dev,
411 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */ 412 (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
412 GFP_KERNEL 413 GFP_KERNEL
413 ); 414 );
415
416 if (!bss) {
417 err = -ENOMEM;
418 goto exit;
419 }
420
421 cfg80211_put_bss(bss);
414 } 422 }
415 423
416 if (result) 424 if (result)
diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
index c3bb05dd744f..4efa9bc0fcf0 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.c
+++ b/drivers/staging/wlan-ng/prism2mgmt.c
@@ -380,8 +380,8 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
380 } 380 }
381 381
382 count = (hw->scanresults->framelen - 3) / 32; 382 count = (hw->scanresults->framelen - 3) / 32;
383 if (count > 32) 383 if (count > HFA384x_SCANRESULT_MAX)
384 count = 32; 384 count = HFA384x_SCANRESULT_MAX;
385 385
386 if (req->bssindex.data >= count) { 386 if (req->bssindex.data >= count) {
387 pr_debug("requested index (%d) out of range (%d)\n", 387 pr_debug("requested index (%d) out of range (%d)\n",
diff --git a/drivers/staging/xgifb/XGI_main.h b/drivers/staging/xgifb/XGI_main.h
index e828fd403c35..9c62aeb9ede9 100644
--- a/drivers/staging/xgifb/XGI_main.h
+++ b/drivers/staging/xgifb/XGI_main.h
@@ -12,9 +12,6 @@
12 12
13#define XGIFAIL(x) do { printk(x "\n"); return -EINVAL; } while (0) 13#define XGIFAIL(x) do { printk(x "\n"); return -EINVAL; } while (0)
14 14
15#ifndef PCI_DEVICE_ID_XGI_41
16#define PCI_DEVICE_ID_XGI_41 0x041
17#endif
18#ifndef PCI_DEVICE_ID_XGI_42 15#ifndef PCI_DEVICE_ID_XGI_42
19#define PCI_DEVICE_ID_XGI_42 0x042 16#define PCI_DEVICE_ID_XGI_42 0x042
20#endif 17#endif
@@ -82,177 +79,79 @@ static int XGIfb_tvplug = -1;
82/* TW: For ioctl XGIFB_GET_INFO */ 79/* TW: For ioctl XGIFB_GET_INFO */
83/* XGIfb_info XGIfbinfo; */ 80/* XGIfb_info XGIfbinfo; */
84 81
85#define MD_XGI300 1 82#define MD_XGI315 1
86#define MD_XGI315 2
87 83
88/* mode table */ 84/* mode table */
89static const struct _XGIbios_mode { 85static const struct _XGIbios_mode {
90 char name[15];
91 u8 mode_no; 86 u8 mode_no;
92 u16 vesa_mode_no_1; /* "XGI defined" VESA mode number */ 87 u16 vesa_mode_no_1; /* "XGI defined" VESA mode number */
93 u16 vesa_mode_no_2; /* Real VESA mode numbers */ 88 u16 vesa_mode_no_2; /* Real VESA mode numbers */
94 u16 xres; 89 u16 xres;
95 u16 yres; 90 u16 yres;
96 u16 bpp; 91 u16 bpp;
97 u16 rate_idx;
98 u16 cols;
99 u16 rows;
100 u8 chipset; 92 u8 chipset;
101} XGIbios_mode[] = { 93} XGIbios_mode[] = {
102 {"320x240x16", 0x56, 0x0000, 0x0000, 320, 240, 16, 1, 40, 15, 94 { 0x56, 0x0000, 0x0000, 320, 240, 16, MD_XGI315 },
103 MD_XGI315}, 95 { 0x5A, 0x0000, 0x0000, 320, 480, 8, MD_XGI315 },
104 {"320x480x8", 0x5A, 0x0000, 0x0000, 320, 480, 8, 1, 40, 30, 96 { 0x5B, 0x0000, 0x0000, 320, 480, 16, MD_XGI315 },
105 MD_XGI315}, /* TW: FSTN */ 97 { 0x2E, 0x0101, 0x0101, 640, 480, 8, MD_XGI315 },
106 {"320x480x16", 0x5B, 0x0000, 0x0000, 320, 480, 16, 1, 40, 30, 98 { 0x44, 0x0111, 0x0111, 640, 480, 16, MD_XGI315 },
107 MD_XGI315}, /* TW: FSTN */ 99 { 0x62, 0x013a, 0x0112, 640, 480, 32, MD_XGI315 },
108 {"640x480x8", 0x2E, 0x0101, 0x0101, 640, 480, 8, 1, 80, 30, 100 { 0x31, 0x0000, 0x0000, 720, 480, 8, MD_XGI315 },
109 MD_XGI300|MD_XGI315}, 101 { 0x33, 0x0000, 0x0000, 720, 480, 16, MD_XGI315 },
110 {"640x480x16", 0x44, 0x0111, 0x0111, 640, 480, 16, 1, 80, 30, 102 { 0x35, 0x0000, 0x0000, 720, 480, 32, MD_XGI315 },
111 MD_XGI300|MD_XGI315}, 103 { 0x32, 0x0000, 0x0000, 720, 576, 8, MD_XGI315 },
112 {"640x480x24", 0x62, 0x013a, 0x0112, 640, 480, 32, 1, 80, 30, 104 { 0x34, 0x0000, 0x0000, 720, 576, 16, MD_XGI315 },
113 MD_XGI300|MD_XGI315}, /* TW: That's for people who mix up color- 105 { 0x36, 0x0000, 0x0000, 720, 576, 32, MD_XGI315 },
114 and fb depth */ 106 { 0x36, 0x0000, 0x0000, 720, 576, 32, MD_XGI315 },
115 {"640x480x32", 0x62, 0x013a, 0x0112, 640, 480, 32, 1, 80, 30, 107 { 0x70, 0x0000, 0x0000, 800, 480, 8, MD_XGI315 },
116 MD_XGI300|MD_XGI315}, 108 { 0x7a, 0x0000, 0x0000, 800, 480, 16, MD_XGI315 },
117 {"720x480x8", 0x31, 0x0000, 0x0000, 720, 480, 8, 1, 90, 30, 109 { 0x76, 0x0000, 0x0000, 800, 480, 32, MD_XGI315 },
118 MD_XGI300|MD_XGI315}, 110 { 0x30, 0x0103, 0x0103, 800, 600, 8, MD_XGI315 },
119 {"720x480x16", 0x33, 0x0000, 0x0000, 720, 480, 16, 1, 90, 30, 111#define DEFAULT_MODE 17 /* index for 800x600x16 */
120 MD_XGI300|MD_XGI315}, 112 { 0x47, 0x0114, 0x0114, 800, 600, 16, MD_XGI315 },
121 {"720x480x24", 0x35, 0x0000, 0x0000, 720, 480, 32, 1, 90, 30, 113 { 0x63, 0x013b, 0x0115, 800, 600, 32, MD_XGI315 },
122 MD_XGI300|MD_XGI315}, 114 { 0x71, 0x0000, 0x0000, 1024, 576, 8, MD_XGI315 },
123 {"720x480x32", 0x35, 0x0000, 0x0000, 720, 480, 32, 1, 90, 30, 115 { 0x74, 0x0000, 0x0000, 1024, 576, 16, MD_XGI315 },
124 MD_XGI300|MD_XGI315}, 116 { 0x77, 0x0000, 0x0000, 1024, 576, 32, MD_XGI315 },
125 {"720x576x8", 0x32, 0x0000, 0x0000, 720, 576, 8, 1, 90, 36, 117 { 0x77, 0x0000, 0x0000, 1024, 576, 32, MD_XGI315 },
126 MD_XGI300|MD_XGI315}, 118 { 0x20, 0x0000, 0x0000, 1024, 600, 8, },
127 {"720x576x16", 0x34, 0x0000, 0x0000, 720, 576, 16, 1, 90, 36, 119 { 0x21, 0x0000, 0x0000, 1024, 600, 16, },
128 MD_XGI300|MD_XGI315}, 120 { 0x22, 0x0000, 0x0000, 1024, 600, 32, },
129 {"720x576x24", 0x36, 0x0000, 0x0000, 720, 576, 32, 1, 90, 36, 121 { 0x38, 0x0105, 0x0105, 1024, 768, 8, MD_XGI315 },
130 MD_XGI300|MD_XGI315}, 122 { 0x4A, 0x0117, 0x0117, 1024, 768, 16, MD_XGI315 },
131 {"720x576x32", 0x36, 0x0000, 0x0000, 720, 576, 32, 1, 90, 36, 123 { 0x64, 0x013c, 0x0118, 1024, 768, 32, MD_XGI315 },
132 MD_XGI300|MD_XGI315}, 124 { 0x64, 0x013c, 0x0118, 1024, 768, 32, MD_XGI315 },
133 {"800x480x8", 0x70, 0x0000, 0x0000, 800, 480, 8, 1, 100, 30, 125 { 0x23, 0x0000, 0x0000, 1152, 768, 8, },
134 MD_XGI300|MD_XGI315}, 126 { 0x24, 0x0000, 0x0000, 1152, 768, 16, },
135 {"800x480x16", 0x7a, 0x0000, 0x0000, 800, 480, 16, 1, 100, 30, 127 { 0x25, 0x0000, 0x0000, 1152, 768, 32, },
136 MD_XGI300|MD_XGI315}, 128 { 0x79, 0x0000, 0x0000, 1280, 720, 8, MD_XGI315 },
137 {"800x480x24", 0x76, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, 129 { 0x75, 0x0000, 0x0000, 1280, 720, 16, MD_XGI315 },
138 MD_XGI300|MD_XGI315}, 130 { 0x78, 0x0000, 0x0000, 1280, 720, 32, MD_XGI315 },
139 {"800x480x32", 0x76, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, 131 { 0x23, 0x0000, 0x0000, 1280, 768, 8, MD_XGI315 },
140 MD_XGI300|MD_XGI315}, 132 { 0x24, 0x0000, 0x0000, 1280, 768, 16, MD_XGI315 },
141 {"800x600x8", 0x30, 0x0103, 0x0103, 800, 600, 8, 1, 100, 37, 133 { 0x25, 0x0000, 0x0000, 1280, 768, 32, MD_XGI315 },
142 MD_XGI300|MD_XGI315}, 134 { 0x7C, 0x0000, 0x0000, 1280, 960, 8, MD_XGI315 },
143#define DEFAULT_MODE 20 /* index for 800x600x16 */ 135 { 0x7D, 0x0000, 0x0000, 1280, 960, 16, MD_XGI315 },
144 {"800x600x16", 0x47, 0x0114, 0x0114, 800, 600, 16, 1, 100, 37, 136 { 0x7E, 0x0000, 0x0000, 1280, 960, 32, MD_XGI315 },
145 MD_XGI300|MD_XGI315}, 137 { 0x3A, 0x0107, 0x0107, 1280, 1024, 8, MD_XGI315 },
146 {"800x600x24", 0x63, 0x013b, 0x0115, 800, 600, 32, 1, 100, 37, 138 { 0x4D, 0x011a, 0x011a, 1280, 1024, 16, MD_XGI315 },
147 MD_XGI300|MD_XGI315}, 139 { 0x65, 0x013d, 0x011b, 1280, 1024, 32, MD_XGI315 },
148 {"800x600x32", 0x63, 0x013b, 0x0115, 800, 600, 32, 1, 100, 37, 140 { 0x26, 0x0000, 0x0000, 1400, 1050, 8, MD_XGI315 },
149 MD_XGI300|MD_XGI315}, 141 { 0x27, 0x0000, 0x0000, 1400, 1050, 16, MD_XGI315 },
150 {"1024x576x8", 0x71, 0x0000, 0x0000, 1024, 576, 8, 1, 128, 36, 142 { 0x28, 0x0000, 0x0000, 1400, 1050, 32, MD_XGI315 },
151 MD_XGI300|MD_XGI315}, 143 { 0x3C, 0x0130, 0x011c, 1600, 1200, 8, MD_XGI315 },
152 {"1024x576x16", 0x74, 0x0000, 0x0000, 1024, 576, 16, 1, 128, 36, 144 { 0x3D, 0x0131, 0x011e, 1600, 1200, 16, MD_XGI315 },
153 MD_XGI300|MD_XGI315}, 145 { 0x66, 0x013e, 0x011f, 1600, 1200, 32, MD_XGI315 },
154 {"1024x576x24", 0x77, 0x0000, 0x0000, 1024, 576, 32, 1, 128, 36, 146 { 0x68, 0x013f, 0x0000, 1920, 1440, 8, MD_XGI315 },
155 MD_XGI300|MD_XGI315}, 147 { 0x69, 0x0140, 0x0000, 1920, 1440, 16, MD_XGI315 },
156 {"1024x576x32", 0x77, 0x0000, 0x0000, 1024, 576, 32, 1, 128, 36, 148 { 0x6B, 0x0141, 0x0000, 1920, 1440, 32, MD_XGI315 },
157 MD_XGI300|MD_XGI315}, 149 { 0x6c, 0x0000, 0x0000, 2048, 1536, 8, MD_XGI315 },
158 {"1024x600x8", 0x20, 0x0000, 0x0000, 1024, 600, 8, 1, 128, 37, 150 { 0x6d, 0x0000, 0x0000, 2048, 1536, 16, MD_XGI315 },
159 MD_XGI300 }, /* TW: 300 series only */ 151 { 0x6e, 0x0000, 0x0000, 2048, 1536, 32, MD_XGI315 },
160 {"1024x600x16", 0x21, 0x0000, 0x0000, 1024, 600, 16, 1, 128, 37, 152 { 0 },
161 MD_XGI300 },
162 {"1024x600x24", 0x22, 0x0000, 0x0000, 1024, 600, 32, 1, 128, 37,
163 MD_XGI300 },
164 {"1024x600x32", 0x22, 0x0000, 0x0000, 1024, 600, 32, 1, 128, 37,
165 MD_XGI300 },
166 {"1024x768x8", 0x38, 0x0105, 0x0105, 1024, 768, 8, 1, 128, 48,
167 MD_XGI300|MD_XGI315},
168 {"1024x768x16", 0x4A, 0x0117, 0x0117, 1024, 768, 16, 1, 128, 48,
169 MD_XGI300|MD_XGI315},
170 {"1024x768x24", 0x64, 0x013c, 0x0118, 1024, 768, 32, 1, 128, 48,
171 MD_XGI300|MD_XGI315},
172 {"1024x768x32", 0x64, 0x013c, 0x0118, 1024, 768, 32, 1, 128, 48,
173 MD_XGI300|MD_XGI315},
174 {"1152x768x8", 0x23, 0x0000, 0x0000, 1152, 768, 8, 1, 144, 48,
175 MD_XGI300 }, /* TW: 300 series only */
176 {"1152x768x16", 0x24, 0x0000, 0x0000, 1152, 768, 16, 1, 144, 48,
177 MD_XGI300 },
178 {"1152x768x24", 0x25, 0x0000, 0x0000, 1152, 768, 32, 1, 144, 48,
179 MD_XGI300 },
180 {"1152x768x32", 0x25, 0x0000, 0x0000, 1152, 768, 32, 1, 144, 48,
181 MD_XGI300 },
182 {"1280x720x8", 0x79, 0x0000, 0x0000, 1280, 720, 8, 1, 160, 45,
183 MD_XGI300|MD_XGI315},
184 {"1280x720x16", 0x75, 0x0000, 0x0000, 1280, 720, 16, 1, 160, 45,
185 MD_XGI300|MD_XGI315},
186 {"1280x720x24", 0x78, 0x0000, 0x0000, 1280, 720, 32, 1, 160, 45,
187 MD_XGI300|MD_XGI315},
188 {"1280x720x32", 0x78, 0x0000, 0x0000, 1280, 720, 32, 1, 160, 45,
189 MD_XGI300|MD_XGI315},
190 {"1280x768x8", 0x23, 0x0000, 0x0000, 1280, 768, 8, 1, 160, 48,
191 MD_XGI315}, /* TW: 310/325 series only */
192 {"1280x768x16", 0x24, 0x0000, 0x0000, 1280, 768, 16, 1, 160, 48,
193 MD_XGI315},
194 {"1280x768x24", 0x25, 0x0000, 0x0000, 1280, 768, 32, 1, 160, 48,
195 MD_XGI315},
196 {"1280x768x32", 0x25, 0x0000, 0x0000, 1280, 768, 32, 1, 160, 48,
197 MD_XGI315},
198 {"1280x960x8", 0x7C, 0x0000, 0x0000, 1280, 960, 8, 1, 160, 60,
199 MD_XGI300|MD_XGI315},
200 {"1280x960x16", 0x7D, 0x0000, 0x0000, 1280, 960, 16, 1, 160, 60,
201 MD_XGI300|MD_XGI315},
202 {"1280x960x24", 0x7E, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60,
203 MD_XGI300|MD_XGI315},
204 {"1280x960x32", 0x7E, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60,
205 MD_XGI300|MD_XGI315},
206 {"1280x1024x8", 0x3A, 0x0107, 0x0107, 1280, 1024, 8, 1, 160, 64,
207 MD_XGI300|MD_XGI315},
208 {"1280x1024x16", 0x4D, 0x011a, 0x011a, 1280, 1024, 16, 1, 160, 64,
209 MD_XGI300|MD_XGI315},
210 {"1280x1024x24", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 1, 160, 64,
211 MD_XGI300|MD_XGI315},
212 {"1280x1024x32", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 1, 160, 64,
213 MD_XGI300|MD_XGI315},
214 {"1400x1050x8", 0x26, 0x0000, 0x0000, 1400, 1050, 8, 1, 175, 65,
215 MD_XGI315}, /* TW: 310/325 series only */
216 {"1400x1050x16", 0x27, 0x0000, 0x0000, 1400, 1050, 16, 1, 175, 65,
217 MD_XGI315},
218 {"1400x1050x24", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,
219 MD_XGI315},
220 {"1400x1050x32", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,
221 MD_XGI315},
222 {"1600x1200x8", 0x3C, 0x0130, 0x011c, 1600, 1200, 8, 1, 200, 75,
223 MD_XGI300|MD_XGI315},
224 {"1600x1200x16", 0x3D, 0x0131, 0x011e, 1600, 1200, 16, 1, 200, 75,
225 MD_XGI300|MD_XGI315},
226 {"1600x1200x24", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75,
227 MD_XGI300|MD_XGI315},
228 {"1600x1200x32", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75,
229 MD_XGI300|MD_XGI315},
230 {"1920x1440x8", 0x68, 0x013f, 0x0000, 1920, 1440, 8, 1, 240, 75,
231 MD_XGI300|MD_XGI315},
232 {"1920x1440x16", 0x69, 0x0140, 0x0000, 1920, 1440, 16, 1, 240, 75,
233 MD_XGI300|MD_XGI315},
234 {"1920x1440x24", 0x6B, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75,
235 MD_XGI300|MD_XGI315},
236 {"1920x1440x32", 0x6B, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75,
237 MD_XGI300|MD_XGI315},
238 {"2048x1536x8", 0x6c, 0x0000, 0x0000, 2048, 1536, 8, 1, 256, 96,
239 MD_XGI315}, /* TW: 310/325 series only */
240 {"2048x1536x16", 0x6d, 0x0000, 0x0000, 2048, 1536, 16, 1, 256, 96,
241 MD_XGI315},
242 {"2048x1536x24", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,
243 MD_XGI315},
244 {"2048x1536x32", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,
245 MD_XGI315},
246 {"\0", 0x00, 0, 0, 0, 0, 0, 0, 0}
247}; 153};
248 154
249/* TW: CR36 evaluation */
250static const unsigned short XGI300paneltype[] = {
251 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024,
252 LCD_1280x960, LCD_640x480, LCD_1024x600, LCD_1152x768,
253 LCD_1024x768, LCD_1024x768, LCD_1024x768,
254 LCD_1024x768, LCD_1024x768, LCD_1024x768, LCD_1024x768};
255
256static const unsigned short XGI310paneltype[] = { 155static const unsigned short XGI310paneltype[] = {
257 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024, 156 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024,
258 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960, 157 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960,
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index 21c037827de4..85dbf32b1f66 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -156,25 +156,14 @@ static int XGIfb_mode_rate_to_dclock(struct vb_device_info *XGI_Pr,
156 unsigned short ModeNo = modeno; 156 unsigned short ModeNo = modeno;
157 unsigned short ModeIdIndex = 0, ClockIndex = 0; 157 unsigned short ModeIdIndex = 0, ClockIndex = 0;
158 unsigned short RefreshRateTableIndex = 0; 158 unsigned short RefreshRateTableIndex = 0;
159
160 /* unsigned long temp = 0; */
161 int Clock; 159 int Clock;
162 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr); 160 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr);
163 161
162 XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr);
163
164 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo, 164 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
165 ModeIdIndex, XGI_Pr); 165 ModeIdIndex, XGI_Pr);
166 166
167 /*
168 temp = XGI_SearchModeID(ModeNo , &ModeIdIndex, XGI_Pr) ;
169 if (!temp) {
170 printk(KERN_ERR "Could not find mode %x\n", ModeNo);
171 return 65000;
172 }
173
174 RefreshRateTableIndex = XGI_Pr->EModeIDTable[ModeIdIndex].REFindex;
175 RefreshRateTableIndex += (rateindex - 1);
176
177 */
178 ClockIndex = XGI_Pr->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; 167 ClockIndex = XGI_Pr->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
179 168
180 Clock = XGI_Pr->VCLKData[ClockIndex].CLOCK * 1000; 169 Clock = XGI_Pr->VCLKData[ClockIndex].CLOCK * 1000;
@@ -190,7 +179,7 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
190 u32 *vmode) 179 u32 *vmode)
191{ 180{
192 unsigned short ModeNo = modeno; 181 unsigned short ModeNo = modeno;
193 unsigned short ModeIdIndex = 0, index = 0; 182 unsigned short ModeIdIndex, index = 0;
194 unsigned short RefreshRateTableIndex = 0; 183 unsigned short RefreshRateTableIndex = 0;
195 184
196 unsigned short VRE, VBE, VRS, VBS, VDE, VT; 185 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
@@ -199,16 +188,10 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
199 unsigned long cr_data3; 188 unsigned long cr_data3;
200 int A, B, C, D, E, F, temp, j; 189 int A, B, C, D, E, F, temp, j;
201 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr); 190 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr);
191 if (!XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr))
192 return 0;
202 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo, 193 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
203 ModeIdIndex, XGI_Pr); 194 ModeIdIndex, XGI_Pr);
204 /*
205 temp = XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr);
206 if (!temp)
207 return 0;
208
209 RefreshRateTableIndex = XGI_Pr->EModeIDTable[ModeIdIndex].REFindex;
210 RefreshRateTableIndex += (rateindex - 1);
211 */
212 index = XGI_Pr->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 195 index = XGI_Pr->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
213 196
214 sr_data = XGI_Pr->XGINEWUB_CRT1Table[index].CR[5]; 197 sr_data = XGI_Pr->XGINEWUB_CRT1Table[index].CR[5];
@@ -219,12 +202,6 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
219 HT = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8); 202 HT = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8);
220 A = HT + 5; 203 A = HT + 5;
221 204
222 /*
223 cr_data = XGI_Pr->XGINEWUB_CRT1Table[index].CR[1];
224
225 Horizontal display enable end
226 HDE = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x0C) << 6);
227 */
228 HDE = (XGI_Pr->RefIndex[RefreshRateTableIndex].XRes >> 3) - 1; 205 HDE = (XGI_Pr->RefIndex[RefreshRateTableIndex].XRes >> 3) - 1;
229 E = HDE + 1; 206 E = HDE + 1;
230 207
@@ -358,7 +335,6 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
358 335
359static void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr) 336static void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr)
360{ 337{
361 XGI_Pr->RelIO = BaseAddr;
362 XGI_Pr->P3c4 = BaseAddr + 0x14; 338 XGI_Pr->P3c4 = BaseAddr + 0x14;
363 XGI_Pr->P3d4 = BaseAddr + 0x24; 339 XGI_Pr->P3d4 = BaseAddr + 0x24;
364 XGI_Pr->P3c0 = BaseAddr + 0x10; 340 XGI_Pr->P3c0 = BaseAddr + 0x10;
@@ -414,19 +390,26 @@ static int XGIfb_GetXG21DefaultLVDSModeIdx(struct xgifb_video_info *xgifb_info)
414static void XGIfb_search_mode(struct xgifb_video_info *xgifb_info, 390static void XGIfb_search_mode(struct xgifb_video_info *xgifb_info,
415 const char *name) 391 const char *name)
416{ 392{
417 int i = 0, j = 0, l; 393 unsigned int xres;
394 unsigned int yres;
395 unsigned int bpp;
396 int i;
418 397
419 while (XGIbios_mode[i].mode_no != 0) { 398 if (sscanf(name, "%ux%ux%u", &xres, &yres, &bpp) != 3)
420 l = min(strlen(name), strlen(XGIbios_mode[i].name)); 399 goto invalid_mode;
421 if (!strncmp(name, XGIbios_mode[i].name, l)) { 400
401 if (bpp == 24)
402 bpp = 32; /* That's for people who mix up color and fb depth. */
403
404 for (i = 0; XGIbios_mode[i].mode_no != 0; i++)
405 if (XGIbios_mode[i].xres == xres &&
406 XGIbios_mode[i].yres == yres &&
407 XGIbios_mode[i].bpp == bpp) {
422 xgifb_info->mode_idx = i; 408 xgifb_info->mode_idx = i;
423 j = 1; 409 return;
424 break;
425 } 410 }
426 i++; 411invalid_mode:
427 } 412 pr_info("Invalid mode '%s'\n", name);
428 if (!j)
429 pr_info("Invalid mode '%s'\n", name);
430} 413}
431 414
432static void XGIfb_search_vesamode(struct xgifb_video_info *xgifb_info, 415static void XGIfb_search_vesamode(struct xgifb_video_info *xgifb_info,
@@ -1088,7 +1071,7 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1088 unsigned int vtotal = var->upper_margin + var->yres + var->lower_margin 1071 unsigned int vtotal = var->upper_margin + var->yres + var->lower_margin
1089 + var->vsync_len; 1072 + var->vsync_len;
1090#if defined(__powerpc__) 1073#if defined(__powerpc__)
1091 u8 sr_data, cr_data; 1074 u8 cr_data;
1092#endif 1075#endif
1093 unsigned int drate = 0, hrate = 0; 1076 unsigned int drate = 0, hrate = 0;
1094 int found_mode = 0; 1077 int found_mode = 0;
@@ -1162,8 +1145,7 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1162 1145
1163 if (XGIfb_search_refresh_rate(xgifb_info, 1146 if (XGIfb_search_refresh_rate(xgifb_info,
1164 xgifb_info->refresh_rate) == 0) { 1147 xgifb_info->refresh_rate) == 0) {
1165 xgifb_info->rate_idx = 1148 xgifb_info->rate_idx = 1;
1166 XGIbios_mode[xgifb_info->mode_idx].rate_idx;
1167 xgifb_info->refresh_rate = 60; 1149 xgifb_info->refresh_rate = 60;
1168 } 1150 }
1169 1151
@@ -1680,17 +1662,6 @@ static int XGIfb_get_dram_size(struct xgifb_video_info *xgifb_info)
1680 ChannelNum = 1; 1662 ChannelNum = 1;
1681 break; 1663 break;
1682 1664
1683 case XG45:
1684 if (tmp == 1)
1685 ChannelNum = 2;
1686 else if (tmp == 2)
1687 ChannelNum = 3;
1688 else if (tmp == 3)
1689 ChannelNum = 4;
1690 else
1691 ChannelNum = 1;
1692 break;
1693
1694 case XG40: 1665 case XG40:
1695 default: 1666 default:
1696 if (tmp == 2) 1667 if (tmp == 2)
@@ -1911,11 +1882,9 @@ static int __devinit xgifb_probe(struct pci_dev *pdev,
1911 xgifb_info->mmio_base = pci_resource_start(pdev, 1); 1882 xgifb_info->mmio_base = pci_resource_start(pdev, 1);
1912 xgifb_info->mmio_size = pci_resource_len(pdev, 1); 1883 xgifb_info->mmio_size = pci_resource_len(pdev, 1);
1913 xgifb_info->vga_base = pci_resource_start(pdev, 2) + 0x30; 1884 xgifb_info->vga_base = pci_resource_start(pdev, 2) + 0x30;
1914 hw_info->pjIOAddress = (unsigned char *)xgifb_info->vga_base; 1885 pr_info("Relocate IO address: %Lx [%08lx]\n",
1915 /* XGI_Pr.RelIO = ioremap(pci_resource_start(pdev, 2), 128) + 0x30; */ 1886 (u64) pci_resource_start(pdev, 2),
1916 pr_info("Relocate IO address: %lx [%08lx]\n", 1887 xgifb_info->vga_base);
1917 (unsigned long)pci_resource_start(pdev, 2),
1918 xgifb_info->dev_info.RelIO);
1919 1888
1920 if (pci_enable_device(pdev)) { 1889 if (pci_enable_device(pdev)) {
1921 ret = -EIO; 1890 ret = -EIO;
@@ -1927,7 +1896,7 @@ static int __devinit xgifb_probe(struct pci_dev *pdev,
1927 xgifb_info->display2_force = true; 1896 xgifb_info->display2_force = true;
1928 } 1897 }
1929 1898
1930 XGIRegInit(&xgifb_info->dev_info, (unsigned long)hw_info->pjIOAddress); 1899 XGIRegInit(&xgifb_info->dev_info, xgifb_info->vga_base);
1931 1900
1932 xgifb_reg_set(XGISR, IND_SIS_PASSWORD, SIS_PASSWORD); 1901 xgifb_reg_set(XGISR, IND_SIS_PASSWORD, SIS_PASSWORD);
1933 reg1 = xgifb_reg_get(XGISR, IND_SIS_PASSWORD); 1902 reg1 = xgifb_reg_get(XGISR, IND_SIS_PASSWORD);
@@ -1950,9 +1919,6 @@ static int __devinit xgifb_probe(struct pci_dev *pdev,
1950 case PCI_DEVICE_ID_XGI_40: 1919 case PCI_DEVICE_ID_XGI_40:
1951 xgifb_info->chip = XG40; 1920 xgifb_info->chip = XG40;
1952 break; 1921 break;
1953 case PCI_DEVICE_ID_XGI_41:
1954 xgifb_info->chip = XG41;
1955 break;
1956 case PCI_DEVICE_ID_XGI_42: 1922 case PCI_DEVICE_ID_XGI_42:
1957 xgifb_info->chip = XG42; 1923 xgifb_info->chip = XG42;
1958 break; 1924 break;
@@ -2006,13 +1972,13 @@ static int __devinit xgifb_probe(struct pci_dev *pdev,
2006 xgifb_info->mmio_vbase = ioremap(xgifb_info->mmio_base, 1972 xgifb_info->mmio_vbase = ioremap(xgifb_info->mmio_base,
2007 xgifb_info->mmio_size); 1973 xgifb_info->mmio_size);
2008 1974
2009 pr_info("Framebuffer at 0x%lx, mapped to 0x%p, size %dk\n", 1975 pr_info("Framebuffer at 0x%Lx, mapped to 0x%p, size %dk\n",
2010 xgifb_info->video_base, 1976 (u64) xgifb_info->video_base,
2011 xgifb_info->video_vbase, 1977 xgifb_info->video_vbase,
2012 xgifb_info->video_size / 1024); 1978 xgifb_info->video_size / 1024);
2013 1979
2014 pr_info("MMIO at 0x%lx, mapped to 0x%p, size %ldk\n", 1980 pr_info("MMIO at 0x%Lx, mapped to 0x%p, size %ldk\n",
2015 xgifb_info->mmio_base, xgifb_info->mmio_vbase, 1981 (u64) xgifb_info->mmio_base, xgifb_info->mmio_vbase,
2016 xgifb_info->mmio_size / 1024); 1982 xgifb_info->mmio_size / 1024);
2017 1983
2018 pci_set_drvdata(pdev, xgifb_info); 1984 pci_set_drvdata(pdev, xgifb_info);
@@ -2174,8 +2140,7 @@ static int __devinit xgifb_probe(struct pci_dev *pdev,
2174 xgifb_info->refresh_rate = 60; 2140 xgifb_info->refresh_rate = 60;
2175 if (XGIfb_search_refresh_rate(xgifb_info, 2141 if (XGIfb_search_refresh_rate(xgifb_info,
2176 xgifb_info->refresh_rate) == 0) { 2142 xgifb_info->refresh_rate) == 0) {
2177 xgifb_info->rate_idx = 2143 xgifb_info->rate_idx = 1;
2178 XGIbios_mode[xgifb_info->mode_idx].rate_idx;
2179 xgifb_info->refresh_rate = 60; 2144 xgifb_info->refresh_rate = 60;
2180 } 2145 }
2181 2146
diff --git a/drivers/staging/xgifb/XGIfb.h b/drivers/staging/xgifb/XGIfb.h
index 37bb730de047..9068c5ad76ec 100644
--- a/drivers/staging/xgifb/XGIfb.h
+++ b/drivers/staging/xgifb/XGIfb.h
@@ -23,9 +23,7 @@ enum xgifb_display_type {
23 23
24enum XGI_CHIP_TYPE { 24enum XGI_CHIP_TYPE {
25 XG40 = 32, 25 XG40 = 32,
26 XG41,
27 XG42, 26 XG42,
28 XG45,
29 XG20 = 48, 27 XG20 = 48,
30 XG21, 28 XG21,
31 XG27, 29 XG27,
@@ -66,9 +64,9 @@ struct xgifb_video_info {
66 64
67 int chip_id; 65 int chip_id;
68 unsigned int video_size; 66 unsigned int video_size;
69 unsigned long video_base; 67 phys_addr_t video_base;
70 void __iomem *video_vbase; 68 void __iomem *video_vbase;
71 unsigned long mmio_base; 69 phys_addr_t mmio_base;
72 unsigned long mmio_size; 70 unsigned long mmio_size;
73 void __iomem *mmio_vbase; 71 void __iomem *mmio_vbase;
74 unsigned long vga_base; 72 unsigned long vga_base;
diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 3650bbff7686..c222d611431d 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -353,7 +353,6 @@ static void XGINew_DDR1x_DefaultRegister(
353 XGINew_SetMemoryClock(HwDeviceExtension, pVBInfo); 353 XGINew_SetMemoryClock(HwDeviceExtension, pVBInfo);
354 354
355 switch (HwDeviceExtension->jChipType) { 355 switch (HwDeviceExtension->jChipType) {
356 case XG41:
357 case XG42: 356 case XG42:
358 /* CR82 */ 357 /* CR82 */
359 xgifb_reg_set(P3d4, 358 xgifb_reg_set(P3d4,
@@ -556,8 +555,7 @@ static void XGINew_SetDRAMDefaultRegister340(
556 xgifb_reg_set(P3d4, (0x8A + j), 555 xgifb_reg_set(P3d4, (0x8A + j),
557 pVBInfo->CR40[1 + j][pVBInfo->ram_type]); 556 pVBInfo->CR40[1 + j][pVBInfo->ram_type]);
558 557
559 if ((HwDeviceExtension->jChipType == XG41) || 558 if (HwDeviceExtension->jChipType == XG42)
560 (HwDeviceExtension->jChipType == XG42))
561 xgifb_reg_set(P3d4, 0x8C, 0x87); 559 xgifb_reg_set(P3d4, 0x8C, 0x87);
562 560
563 xgifb_reg_set(P3d4, 561 xgifb_reg_set(P3d4,
@@ -854,78 +852,6 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
854 pVBInfo->ram_channel = 1; /* Single channel */ 852 pVBInfo->ram_channel = 1; /* Single channel */
855 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x51); /* 32Mx16 bit*/ 853 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x51); /* 32Mx16 bit*/
856 break; 854 break;
857 case XG41:
858 if (XGINew_CheckFrequence(pVBInfo) == 1) {
859 pVBInfo->ram_bus = 32; /* 32 bits */
860 pVBInfo->ram_channel = 3; /* Quad Channel */
861 xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xA1);
862 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x4C);
863
864 if (XGINew_ReadWriteRest(25, 23, pVBInfo) == 1)
865 return;
866
867 pVBInfo->ram_channel = 2; /* Dual channels */
868 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x48);
869
870 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
871 return;
872
873 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x49);
874
875 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
876 return;
877
878 pVBInfo->ram_channel = 3;
879 xgifb_reg_set(pVBInfo->P3c4, 0x13, 0x21);
880 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x3C);
881
882 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
883 return;
884
885 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x38);
886
887 if (XGINew_ReadWriteRest(8, 4, pVBInfo) == 1)
888 return;
889 else
890 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x39);
891 } else { /* DDR */
892 pVBInfo->ram_bus = 64; /* 64 bits */
893 pVBInfo->ram_channel = 2; /* Dual channels */
894 xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xA1);
895 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x5A);
896
897 if (XGINew_ReadWriteRest(25, 24, pVBInfo) == 1)
898 return;
899
900 pVBInfo->ram_channel = 1; /* Single channels */
901 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x52);
902
903 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
904 return;
905
906 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x53);
907
908 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
909 return;
910
911 pVBInfo->ram_channel = 2; /* Dual channels */
912 xgifb_reg_set(pVBInfo->P3c4, 0x13, 0x21);
913 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x4A);
914
915 if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
916 return;
917
918 pVBInfo->ram_channel = 1; /* Single channels */
919 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x42);
920
921 if (XGINew_ReadWriteRest(8, 4, pVBInfo) == 1)
922 return;
923 else
924 xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x43);
925 }
926
927 break;
928
929 case XG42: 855 case XG42:
930 /* 856 /*
931 XG42 SR14 D[3] Reserve 857 XG42 SR14 D[3] Reserve
@@ -1478,7 +1404,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
1478 1404
1479 pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress; 1405 pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress;
1480 1406
1481 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress; 1407 pVBInfo->BaseAddr = xgifb_info->vga_base;
1482 1408
1483 /* Newdebugcode(0x99); */ 1409 /* Newdebugcode(0x99); */
1484 1410
diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index 60d4adf99923..b2f4338b1109 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -16,36 +16,6 @@
16 16
17#define IndexMask 0xff 17#define IndexMask 0xff
18 18
19static const unsigned short XGINew_MDA_DAC[] = {
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
28
29static const unsigned short XGINew_CGA_DAC[] = {
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
38
39static const unsigned short XGINew_EGA_DAC[] = {
40 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
48
49static const unsigned short XGINew_VGA_DAC[] = { 19static const unsigned short XGINew_VGA_DAC[] = {
50 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15, 20 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F, 21 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
@@ -60,8 +30,7 @@ static const unsigned short XGINew_VGA_DAC[] = {
60 30
61void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo) 31void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
62{ 32{
63 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable; 33 pVBInfo->StandTable = (struct SiS_StandTable_S *) &XGI330_StandTable;
64 pVBInfo->StandTable = (struct SiS_StandTable_S *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable; 34 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex; 35 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table 36 pVBInfo->XGINEWUB_CRT1Table
@@ -182,38 +151,17 @@ void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
182 151
183} 152}
184 153
185static unsigned char XGI_GetModePtr(unsigned short ModeNo,
186 unsigned short ModeIdIndex,
187 struct vb_device_info *pVBInfo)
188{
189 unsigned char index;
190
191 if (ModeNo <= 0x13)
192 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
193 else {
194 if (pVBInfo->ModeType <= 0x02)
195 index = 0x1B; /* 02 -> ModeEGA */
196 else
197 index = 0x0F;
198 }
199 return index; /* Get pVBInfo->StandTable index */
200}
201
202static void XGI_SetSeqRegs(unsigned short ModeNo, 154static void XGI_SetSeqRegs(unsigned short ModeNo,
203 unsigned short StandTableIndex,
204 unsigned short ModeIdIndex, 155 unsigned short ModeIdIndex,
205 struct vb_device_info *pVBInfo) 156 struct vb_device_info *pVBInfo)
206{ 157{
207 unsigned char tempah, SRdata; 158 unsigned char tempah, SRdata;
208 unsigned short i, modeflag; 159 unsigned short i, modeflag;
209 160
210 if (ModeNo <= 0x13) 161 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
211 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
212 else
213 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
214 162
215 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */ 163 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
216 tempah = pVBInfo->StandTable[StandTableIndex].SR[0]; 164 tempah = pVBInfo->StandTable->SR[0];
217 165
218 i = XGI_SetCRT2ToLCDA; 166 i = XGI_SetCRT2ToLCDA;
219 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { 167 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
@@ -230,13 +178,12 @@ static void XGI_SetSeqRegs(unsigned short ModeNo,
230 178
231 for (i = 02; i <= 04; i++) { 179 for (i = 02; i <= 04; i++) {
232 /* Get SR2,3,4 from file */ 180 /* Get SR2,3,4 from file */
233 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1]; 181 SRdata = pVBInfo->StandTable->SR[i - 1];
234 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */ 182 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
235 } 183 }
236} 184}
237 185
238static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension, 186static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
239 unsigned short StandTableIndex,
240 struct vb_device_info *pVBInfo) 187 struct vb_device_info *pVBInfo)
241{ 188{
242 unsigned char CRTCdata; 189 unsigned char CRTCdata;
@@ -248,26 +195,22 @@ static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
248 195
249 for (i = 0; i <= 0x18; i++) { 196 for (i = 0; i <= 0x18; i++) {
250 /* Get CRTC from file */ 197 /* Get CRTC from file */
251 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i]; 198 CRTCdata = pVBInfo->StandTable->CRTC[i];
252 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */ 199 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
253 } 200 }
254} 201}
255 202
256static void XGI_SetATTRegs(unsigned short ModeNo, 203static void XGI_SetATTRegs(unsigned short ModeNo,
257 unsigned short StandTableIndex,
258 unsigned short ModeIdIndex, 204 unsigned short ModeIdIndex,
259 struct vb_device_info *pVBInfo) 205 struct vb_device_info *pVBInfo)
260{ 206{
261 unsigned char ARdata; 207 unsigned char ARdata;
262 unsigned short i, modeflag; 208 unsigned short i, modeflag;
263 209
264 if (ModeNo <= 0x13) 210 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
265 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
266 else
267 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
268 211
269 for (i = 0; i <= 0x13; i++) { 212 for (i = 0; i <= 0x13; i++) {
270 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i]; 213 ARdata = pVBInfo->StandTable->ATTR[i];
271 if (modeflag & Charx8Dot) { /* ifndef Dot9 */ 214 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
272 if (i == 0x13) { 215 if (i == 0x13) {
273 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { 216 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
@@ -295,15 +238,14 @@ static void XGI_SetATTRegs(unsigned short ModeNo,
295 outb(0x20, pVBInfo->P3c0); 238 outb(0x20, pVBInfo->P3c0);
296} 239}
297 240
298static void XGI_SetGRCRegs(unsigned short StandTableIndex, 241static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
299 struct vb_device_info *pVBInfo)
300{ 242{
301 unsigned char GRdata; 243 unsigned char GRdata;
302 unsigned short i; 244 unsigned short i;
303 245
304 for (i = 0; i <= 0x08; i++) { 246 for (i = 0; i <= 0x08; i++) {
305 /* Get GR from file */ 247 /* Get GR from file */
306 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i]; 248 GRdata = pVBInfo->StandTable->GRC[i];
307 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */ 249 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
308 } 250 }
309 251
@@ -344,12 +286,7 @@ static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
344{ 286{
345 unsigned short tempax, tempbx, resinfo, modeflag, infoflag; 287 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
346 288
347 if (ModeNo <= 0x13) 289 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
348 /* si+St_ModeFlag */
349 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
350 else
351 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
352
353 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO; 290 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
354 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID; 291 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
355 tempax = 0; 292 tempax = 0;
@@ -584,11 +521,7 @@ static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
584 data &= 0x80; 521 data &= 0x80;
585 data = data >> 2; 522 data = data >> 2;
586 523
587 if (ModeNo <= 0x13) 524 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
588 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
589 else
590 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
591
592 i &= DoubleScanMode; 525 i &= DoubleScanMode;
593 if (i) 526 if (i)
594 data |= 0x80; 527 data |= 0x80;
@@ -641,158 +574,97 @@ static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
641 unsigned short RefreshRateTableIndex, 574 unsigned short RefreshRateTableIndex,
642 struct vb_device_info *pVBInfo) 575 struct vb_device_info *pVBInfo)
643{ 576{
644 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx; 577 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
645 unsigned short Temp1, Temp2, Temp3; 578 unsigned short Temp1, Temp2, Temp3;
646 579
647 if (ModeNo <= 0x13) { 580 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
648 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo); 581 /* Tempax: CR4 HRS */
649 /* CR04 HRS */ 582 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
650 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4]; 583 Tempcx = Tempax; /* Tempcx: HRS */
651 /* SR2E [7:0]->HRS */ 584 /* SR2E[7:0]->HRS */
652 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax); 585 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
653 /* Tempbx: CR05 HRE */ 586
654 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5]; 587 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
655 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */ 588 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
656 Tempcx = Tempax; 589 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
657 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */ 590 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
658 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */ 591 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
659 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */ 592
660 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */ 593 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
661 Tempdx <<= 2; /* Tempdx << 2 */ 594 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
662 /* SR2F [7:2]->HRE */ 595
663 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx); 596 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
664 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00); 597 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
665 598 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
666 /* Tempax: CR16 VRS */ 599 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
667 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16]; 600
668 Tempbx = Tempax; /* Tempbx=Tempax */ 601 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
669 Tempax &= 0x01; /* Tempax: VRS[0] */ 602 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
670 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */ 603
671 604 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
672 /* Tempax: CR7 VRS */ 605 if (Tempax < Tempcx) /* HRE < HRS */
673 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7]; 606 Temp2 |= 0x40; /* Temp2 + 0x40 */
674 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */ 607
675 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */ 608 Temp2 &= 0xFF;
676 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */ 609 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
677 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */ 610 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
678 /* SR34[7:0]: VRS[8:1] */ 611 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
679 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx); 612 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
680 613 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
681 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */ 614 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
682 Temp1 = Tempcx << 1; 615 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
683 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */ 616
684 Tempax &= 0x80; /* Tempax[7]: CR7[7] */ 617 /* CR10 VRS */
685 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */ 618 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
686 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */ 619 Tempbx = Tempax; /* Tempbx: VRS */
687 620 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
688 /* CR16 VRE */ 621 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
689 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17]; 622 /* CR7[2][7] VRE */
690 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */ 623 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
691 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */ 624 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
692 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */ 625 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
693 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */ 626 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
694 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */ 627 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
695 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */ 628 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
696 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */ 629
697 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */ 630 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
698 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */ 631 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
699 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */ 632 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
700 Temp1 >>= 9; /* [10:9]->[1:0] */ 633 Tempax &= 0x80;
701 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */ 634 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
702 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */ 635 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
703 Tempax &= 0x7F; 636 /* Tempax: SRA */
704 /* SR3F D[7:2]->VRE D[1:0]->VRS */ 637 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
705 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax); 638 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
706 } else { 639 Temp2 = Tempax;
707 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 640 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
708 /* Tempax: CR4 HRS */ 641 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
709 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3]; 642
710 Tempcx = Tempax; /* Tempcx: HRS */ 643 /* Tempax: CR11 VRE */
711 /* SR2E[7:0]->HRS */ 644 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
712 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax); 645 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
713 646 /* Tempbx: SRA */
714 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */ 647 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
715 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */ 648 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
716 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */ 649 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
717 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */ 650 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
718 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */ 651 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
719 652 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
720 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */ 653
721 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */ 654 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
722 655 if (Tempax < Temp3) /* VRE < VRS */
723 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */ 656 Temp2 |= 0x20; /* VRE + 0x20 */
724 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */ 657
725 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */ 658 Temp2 &= 0xFF;
726 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */ 659 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
727 660 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
728 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */ 661 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
729 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */ 662 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
730 663 Tempbx = (unsigned char) Temp1;
731 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */ 664 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
732 if (Tempax < Tempcx) /* HRE < HRS */ 665 Tempax &= 0x7F;
733 Temp2 |= 0x40; /* Temp2 + 0x40 */ 666 /* SR3F D[7:2]->VRE D[1:0]->VRS */
734 667 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
735 Temp2 &= 0xFF;
736 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
737 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
738 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
739 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
740 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
741 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
742 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
743
744 /* CR10 VRS */
745 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
746 Tempbx = Tempax; /* Tempbx: VRS */
747 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
748 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
749 /* CR7[2][7] VRE */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
751 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
752 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
753 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
754 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
755 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
756
757 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
758 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
759 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
760 Tempax &= 0x80;
761 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
762 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
763 /* Tempax: SRA */
764 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
765 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
766 Temp2 = Tempax;
767 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
768 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
769
770 /* Tempax: CR11 VRE */
771 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
772 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
773 /* Tempbx: SRA */
774 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
775 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
776 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
777 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
778 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
779 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
780
781 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
782 if (Tempax < Temp3) /* VRE < VRS */
783 Temp2 |= 0x20; /* VRE + 0x20 */
784
785 Temp2 &= 0xFF;
786 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
787 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
788 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
789 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
790 Tempbx = (unsigned char) Temp1;
791 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
792 Tempax &= 0x7F;
793 /* SR3F D[7:2]->VRE D[1:0]->VRS */
794 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
795 }
796} 668}
797 669
798static void XGI_SetXG27CRTC(unsigned short ModeNo, 670static void XGI_SetXG27CRTC(unsigned short ModeNo,
@@ -800,139 +672,88 @@ static void XGI_SetXG27CRTC(unsigned short ModeNo,
800 unsigned short RefreshRateTableIndex, 672 unsigned short RefreshRateTableIndex,
801 struct vb_device_info *pVBInfo) 673 struct vb_device_info *pVBInfo)
802{ 674{
803 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx; 675 unsigned short index, Tempax, Tempbx, Tempcx;
804 676
805 if (ModeNo <= 0x13) { 677 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
806 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo); 678 /* Tempax: CR4 HRS */
807 /* CR04 HRS */ 679 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
808 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4]; 680 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
809 /* SR2E [7:0]->HRS */ 681 /* SR2E[7:0]->HRS */
810 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax); 682 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
811 /* Tempbx: CR05 HRE */ 683
812 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5]; 684 /* SR0B */
813 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */ 685 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
814 Tempcx = Tempax; 686 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
815 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */ 687 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
816 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */ 688
817 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */ 689 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
818 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */ 690 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
819 Tempdx <<= 2; /* Tempdx << 2 */ 691 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
820 /* SR2F [7:2]->HRE */ 692
821 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx); 693 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
822 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00); 694 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
823 695 Tempax <<= 3; /* Tempax[5]: HRE[5] */
824 /* Tempax: CR10 VRS */ 696 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
825 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16]; 697
826 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */ 698 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
827 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */ 699 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
828 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */ 700
829 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7]; 701 /* Tempax: CR4 HRS */
830 Tempbx = Tempax; /* Tempbx=CR07 */ 702 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
831 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */ 703 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
832 Tempax >>= 2; 704 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
833 /* SR35 D[0]->VRS D[8] */ 705 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
834 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax); 706
835 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */ 707 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
836 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */ 708 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
837 709 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
838 /* CR11 VRE */ 710 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
839 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17]; 711 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
840 Tempax &= 0x0F; /* Tempax: VRE[3:0] */ 712 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
841 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */ 713 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
842 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */ 714
843 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */ 715 /* CR10 VRS */
844 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */ 716 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
845 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */ 717 /* SR34[7:0]->VRS[7:0] */
846 /* Tempax[7:0]: VRE[7:0] */ 718 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
847 Tempax = (unsigned char) Tempbx & 0xFF; 719
848 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */ 720 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
849 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */ 721 /* CR7[7][2] VRS[9][8] */
850 /* SR3F D[7:2]->VRE D[5:0] */ 722 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
851 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax); 723 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
852 /* SR35 D[2:1]->VRS[10:9] */ 724 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
853 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx); 725 Tempax >>= 2; /* Tempax[0]: VRS[8] */
854 } else { 726 /* SR35[0]: VRS[8] */
855 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 727 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
856 /* Tempax: CR4 HRS */ 728 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
857 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3]; 729 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
858 Tempbx = Tempax; /* Tempbx: HRS[7:0] */ 730 /* Tempax: SR0A */
859 /* SR2E[7:0]->HRS */ 731 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
860 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax); 732 Tempax &= 0x08; /* SR0A[3] VRS[10] */
861 733 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
862 /* SR0B */ 734
863 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; 735 /* Tempax: CR11 VRE */
864 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/ 736 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
865 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */ 737 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
866 738 /* Tempbx: SR0A */
867 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */ 739 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
868 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */ 740 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
869 Tempcx = Tempax; /* Tempcx: HRE[4:0] */ 741 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
870 742 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
871 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */ 743 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
872 Tempax &= 0x04; /* Tempax[2]: HRE[5] */ 744 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
873 Tempax <<= 3; /* Tempax[5]: HRE[5] */ 745 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
874 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */ 746
875 747 if (Tempbx <= Tempcx) /* VRE <= VRS */
876 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */ 748 Tempbx |= 0x20; /* VRE + 0x20 */
877 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */ 749
878 750 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
879 /* Tempax: CR4 HRS */ 751 Tempax = (Tempbx << 2) & 0xFF;
880 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3]; 752 /* SR3F[7:2]:VRE[5:0] */
881 Tempax &= 0x3F; /* Tempax: HRS[5:0] */ 753 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
882 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */ 754 Tempax = Tempcx >> 8;
883 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/ 755 /* SR35[2:0]:VRS[10:8] */
884 756 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
885 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
886 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
887 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
888 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
889 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
890 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
891 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
892
893 /* CR10 VRS */
894 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
895 /* SR34[7:0]->VRS[7:0] */
896 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
897
898 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
899 /* CR7[7][2] VRS[9][8] */
900 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
901 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
902 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
903 Tempax >>= 2; /* Tempax[0]: VRS[8] */
904 /* SR35[0]: VRS[8] */
905 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
906 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
907 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
908 /* Tempax: SR0A */
909 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
910 Tempax &= 0x08; /* SR0A[3] VRS[10] */
911 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
912
913 /* Tempax: CR11 VRE */
914 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
915 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
916 /* Tempbx: SR0A */
917 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
918 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
919 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
920 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
921 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
922 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
923 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
924
925 if (Tempbx <= Tempcx) /* VRE <= VRS */
926 Tempbx |= 0x20; /* VRE + 0x20 */
927
928 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
929 Tempax = (Tempbx << 2) & 0xFF;
930 /* SR3F[7:2]:VRE[5:0] */
931 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
932 Tempax = Tempcx >> 8;
933 /* SR35[2:0]:VRS[10:8] */
934 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
935 }
936} 757}
937 758
938static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo) 759static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
@@ -954,7 +775,7 @@ static void xgifb_set_lcd(int chip_id,
954 unsigned short RefreshRateTableIndex, 775 unsigned short RefreshRateTableIndex,
955 unsigned short ModeNo) 776 unsigned short ModeNo)
956{ 777{
957 unsigned short Data, Temp, b3CC; 778 unsigned short Data, Temp;
958 unsigned short XGI_P3cc; 779 unsigned short XGI_P3cc;
959 780
960 XGI_P3cc = pVBInfo->P3cc; 781 XGI_P3cc = pVBInfo->P3cc;
@@ -995,23 +816,13 @@ static void xgifb_set_lcd(int chip_id,
995 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */ 816 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
996 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */ 817 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
997 818
998 if (ModeNo <= 0x13) { 819 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
999 b3CC = (unsigned char) inb(XGI_P3cc); 820 if (Data & 0x4000)
1000 if (b3CC & 0x40) 821 /* Hsync polarity */
1001 /* Hsync polarity */ 822 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1002 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20); 823 if (Data & 0x8000)
1003 if (b3CC & 0x80) 824 /* Vsync polarity */
1004 /* Vsync polarity */ 825 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1005 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1006 } else {
1007 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1008 if (Data & 0x4000)
1009 /* Hsync polarity */
1010 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1011 if (Data & 0x8000)
1012 /* Vsync polarity */
1013 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1014 }
1015} 826}
1016 827
1017/* --------------------------------------------------------------------- */ 828/* --------------------------------------------------------------------- */
@@ -1024,30 +835,22 @@ static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1024 struct vb_device_info *pVBInfo, 835 struct vb_device_info *pVBInfo,
1025 unsigned short RefreshRateTableIndex) 836 unsigned short RefreshRateTableIndex)
1026{ 837{
1027 int i, index = -1; 838 int index = -1;
1028 839
1029 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */ 840 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
1030 if (ModeNo <= 0x13) { 841 if (ModeNo == 0x2E &&
1031 for (i = 0; i < 12; i++) { 842 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1032 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID) 843 RES640x480x60))
1033 index = i; 844 index = 12;
1034 } 845 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
1035 } else {
1036 if (ModeNo == 0x2E &&
1037 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1038 RES640x480x60))
1039 index = 12;
1040 else if (ModeNo == 0x2E &&
1041 (pVBInfo->RefIndex[RefreshRateTableIndex].
1042 Ext_CRT1CRTC == RES640x480x72)) 846 Ext_CRT1CRTC == RES640x480x72))
1043 index = 13; 847 index = 13;
1044 else if (ModeNo == 0x2F) 848 else if (ModeNo == 0x2F)
1045 index = 14; 849 index = 14;
1046 else if (ModeNo == 0x50) 850 else if (ModeNo == 0x50)
1047 index = 15; 851 index = 15;
1048 else if (ModeNo == 0x59) 852 else if (ModeNo == 0x59)
1049 index = 16; 853 index = 16;
1050 }
1051 854
1052 if (index != -1) { 855 if (index != -1) {
1053 xgifb_reg_set(pVBInfo->P3d4, 0x02, 856 xgifb_reg_set(pVBInfo->P3d4, 0x02,
@@ -1061,20 +864,6 @@ static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1061 } 864 }
1062} 865}
1063 866
1064static unsigned short XGI_GetResInfo(unsigned short ModeNo,
1065 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1066{
1067 unsigned short resindex;
1068
1069 if (ModeNo <= 0x13)
1070 /* si+St_ResInfo */
1071 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1072 else
1073 /* si+Ext_ResInfo */
1074 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1075 return resindex;
1076}
1077
1078static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension, 867static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1079 unsigned short ModeNo, unsigned short ModeIdIndex, 868 unsigned short ModeNo, unsigned short ModeIdIndex,
1080 unsigned short RefreshRateTableIndex, 869 unsigned short RefreshRateTableIndex,
@@ -1084,33 +873,25 @@ static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1084 873
1085 unsigned char data; 874 unsigned char data;
1086 875
1087 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); 876 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1088 877
1089 if (ModeNo <= 0x13) { 878 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1090 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 879 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1091 tempax = pVBInfo->StResInfo[resindex].HTotal; 880 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1092 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1093 } else {
1094 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1095 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1096 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1097 }
1098 881
1099 if (modeflag & HalfDCLK) 882 if (modeflag & HalfDCLK)
1100 tempax = tempax >> 1; 883 tempax = tempax >> 1;
1101 884
1102 if (ModeNo > 0x13) { 885 if (modeflag & HalfDCLK)
1103 if (modeflag & HalfDCLK) 886 tempax = tempax << 1;
1104 tempax = tempax << 1;
1105 887
1106 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 888 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1107 889
1108 if (temp & InterlaceMode) 890 if (temp & InterlaceMode)
1109 tempbx = tempbx >> 1; 891 tempbx = tempbx >> 1;
1110 892
1111 if (modeflag & DoubleScanMode) 893 if (modeflag & DoubleScanMode)
1112 tempbx = tempbx << 1; 894 tempbx = tempbx << 1;
1113 }
1114 895
1115 tempcx = 8; 896 tempcx = 8;
1116 897
@@ -1258,18 +1039,10 @@ static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1258 unsigned short CRT2Index, VCLKIndex; 1039 unsigned short CRT2Index, VCLKIndex;
1259 unsigned short modeflag, resinfo; 1040 unsigned short modeflag, resinfo;
1260 1041
1261 if (ModeNo <= 0x13) { 1042 /* si+Ext_ResInfo */
1262 /* si+St_ResInfo */ 1043 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1263 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 1044 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1264 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo; 1045 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1265 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1266 } else {
1267 /* si+Ext_ResInfo */
1268 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1269 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1270 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1271 Ext_CRT2CRTC;
1272 }
1273 1046
1274 if (pVBInfo->IF_DEF_LVDS == 0) { 1047 if (pVBInfo->IF_DEF_LVDS == 0) {
1275 CRT2Index = CRT2Index >> 6; /* for LCD */ 1048 CRT2Index = CRT2Index >> 6; /* for LCD */
@@ -1318,23 +1091,13 @@ static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1318 VCLKIndex += 25; 1091 VCLKIndex += 25;
1319 } 1092 }
1320 } else { /* for CRT2 */ 1093 } else { /* for CRT2 */
1321 /* Port 3cch */ 1094 /* di+Ext_CRTVCLK */
1322 VCLKIndex = (unsigned char) inb((pVBInfo->P3ca + 0x02)); 1095 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
1323 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1324 if (ModeNo > 0x13) {
1325 /* di+Ext_CRTVCLK */
1326 VCLKIndex = pVBInfo->RefIndex[
1327 RefreshRateTableIndex].
1328 Ext_CRTVCLK; 1096 Ext_CRTVCLK;
1329 VCLKIndex &= IndexMask; 1097 VCLKIndex &= IndexMask;
1330 }
1331 } 1098 }
1332 } else { /* LVDS */ 1099 } else { /* LVDS */
1333 if (ModeNo <= 0x13) 1100 VCLKIndex = CRT2Index;
1334 VCLKIndex = CRT2Index;
1335 else
1336 VCLKIndex = CRT2Index;
1337
1338 VCLKIndex = VCLKIndex >> 6; 1101 VCLKIndex = VCLKIndex >> 6;
1339 if ((pVBInfo->LCDResInfo == Panel_800x600) || 1102 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1340 (pVBInfo->LCDResInfo == Panel_320x480)) 1103 (pVBInfo->LCDResInfo == Panel_320x480))
@@ -1431,27 +1194,13 @@ static void XGI_SetCRT1FIFO(unsigned short ModeNo,
1431 data &= 0xfe; 1194 data &= 0xfe;
1432 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */ 1195 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
1433 1196
1434 if (ModeNo > 0x13) { 1197 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1435 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34); 1198 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1436 data = xgifb_reg_get(pVBInfo->P3c4, 0x09); 1199 data &= 0xC0;
1437 data &= 0xC0; 1200 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1438 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30); 1201 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1439 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D); 1202 data |= 0x01;
1440 data |= 0x01; 1203 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1441 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1442 } else {
1443 if (HwDeviceExtension->jChipType == XG27) {
1444 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
1445 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1446 data &= 0xC0;
1447 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
1448 } else {
1449 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
1450 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1451 data &= 0xF0;
1452 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
1453 }
1454 }
1455 1204
1456 if (HwDeviceExtension->jChipType == XG21) 1205 if (HwDeviceExtension->jChipType == XG21)
1457 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */ 1206 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
@@ -1466,13 +1215,9 @@ static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1466 1215
1467 unsigned char index; 1216 unsigned char index;
1468 1217
1469 if (ModeNo <= 0x13) 1218 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1470 VCLK = 0; 1219 index &= IndexMask;
1471 else { 1220 VCLK = pVBInfo->VCLKData[index].CLOCK;
1472 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1473 index &= IndexMask;
1474 VCLK = pVBInfo->VCLKData[index].CLOCK;
1475 }
1476 1221
1477 data = xgifb_reg_get(pVBInfo->P3c4, 0x32); 1222 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1478 data &= 0xf3; 1223 data &= 0xf3;
@@ -1508,44 +1253,26 @@ static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1508 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex, 1253 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1509 xres; 1254 xres;
1510 1255
1511 if (ModeNo > 0x13) { 1256 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1512 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; 1257 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1513 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1514 Ext_InfoFlag;
1515 } else
1516 /* si+St_ModeFlag */
1517 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1518 1258
1519 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01) 1259 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1520 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00); 1260 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1521 1261
1522 if (ModeNo > 0x13) 1262 data = infoflag;
1523 data = infoflag;
1524 else
1525 data = 0;
1526
1527 data2 = 0; 1263 data2 = 0;
1528 1264 data2 |= 0x02;
1529 if (ModeNo > 0x13) { 1265 data3 = pVBInfo->ModeType - ModeVGA;
1530 if (pVBInfo->ModeType > 0x02) { 1266 data3 = data3 << 2;
1531 data2 |= 0x02; 1267 data2 |= data3;
1532 data3 = pVBInfo->ModeType - ModeVGA;
1533 data3 = data3 << 2;
1534 data2 |= data3;
1535 }
1536 }
1537
1538 data &= InterlaceMode; 1268 data &= InterlaceMode;
1539 1269
1540 if (data) 1270 if (data)
1541 data2 |= 0x20; 1271 data2 |= 0x20;
1542 1272
1543 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2); 1273 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1544 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); 1274 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1545 if (ModeNo <= 0x13) 1275 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1546 xres = pVBInfo->StResInfo[resindex].HTotal;
1547 else
1548 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1549 1276
1550 data = 0x0000; 1277 data = 0x0000;
1551 if (infoflag & InterlaceMode) { 1278 if (infoflag & InterlaceMode) {
@@ -1568,18 +1295,10 @@ static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1568 if (modeflag & LineCompareOff) 1295 if (modeflag & LineCompareOff)
1569 data2 |= 0x08; 1296 data2 |= 0x08;
1570 1297
1571 if (ModeNo > 0x13) {
1572 if (pVBInfo->ModeType == ModeEGA)
1573 data2 |= 0x40;
1574 }
1575
1576 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2); 1298 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1577 data = 0x60; 1299 data = 0x60;
1578 if (pVBInfo->ModeType != ModeText) { 1300 data = data ^ 0x60;
1579 data = data ^ 0x60; 1301 data = data ^ 0xA0;
1580 if (pVBInfo->ModeType != ModeEGA)
1581 data = data ^ 0xA0;
1582 }
1583 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data); 1302 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1584 1303
1585 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex, 1304 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
@@ -1644,38 +1363,13 @@ static void XGI_WriteDAC(unsigned short dl,
1644static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex, 1363static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1645 struct vb_device_info *pVBInfo) 1364 struct vb_device_info *pVBInfo)
1646{ 1365{
1647 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al, 1366 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1648 ah, dh; 1367 const unsigned short *table = XGINew_VGA_DAC;
1649 const unsigned short *table = NULL;
1650
1651 if (ModeNo <= 0x13)
1652 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1653 else
1654 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1655
1656 data &= DACInfoFlag;
1657 time = 64;
1658
1659 if (data == 0x00)
1660 table = XGINew_MDA_DAC;
1661 else if (data == 0x08)
1662 table = XGINew_CGA_DAC;
1663 else if (data == 0x10)
1664 table = XGINew_EGA_DAC;
1665 else if (data == 0x18) {
1666 time = 256;
1667 table = XGINew_VGA_DAC;
1668 }
1669
1670 if (time == 256)
1671 j = 16;
1672 else
1673 j = time;
1674 1368
1675 outb(0xFF, pVBInfo->P3c6); 1369 outb(0xFF, pVBInfo->P3c6);
1676 outb(0x00, pVBInfo->P3c8); 1370 outb(0x00, pVBInfo->P3c8);
1677 1371
1678 for (i = 0; i < j; i++) { 1372 for (i = 0; i < 16; i++) {
1679 data = table[i]; 1373 data = table[i];
1680 1374
1681 for (k = 0; k < 3; k++) { 1375 for (k = 0; k < 3; k++) {
@@ -1692,45 +1386,43 @@ static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1692 } 1386 }
1693 } 1387 }
1694 1388
1695 if (time == 256) { 1389 for (i = 16; i < 32; i++) {
1696 for (i = 16; i < 32; i++) { 1390 data = table[i];
1697 data = table[i];
1698
1699 for (k = 0; k < 3; k++)
1700 outb(data, pVBInfo->P3c9);
1701 }
1702 1391
1703 si = 32; 1392 for (k = 0; k < 3; k++)
1393 outb(data, pVBInfo->P3c9);
1394 }
1704 1395
1705 for (m = 0; m < 9; m++) { 1396 si = 32;
1706 di = si;
1707 bx = si + 0x04;
1708 dl = 0;
1709 1397
1710 for (n = 0; n < 3; n++) { 1398 for (m = 0; m < 9; m++) {
1711 for (o = 0; o < 5; o++) { 1399 di = si;
1712 dh = table[si]; 1400 bx = si + 0x04;
1713 ah = table[di]; 1401 dl = 0;
1714 al = table[bx];
1715 si++;
1716 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1717 }
1718 1402
1719 si -= 2; 1403 for (n = 0; n < 3; n++) {
1404 for (o = 0; o < 5; o++) {
1405 dh = table[si];
1406 ah = table[di];
1407 al = table[bx];
1408 si++;
1409 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1410 }
1720 1411
1721 for (o = 0; o < 3; o++) { 1412 si -= 2;
1722 dh = table[bx];
1723 ah = table[di];
1724 al = table[si];
1725 si--;
1726 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1727 }
1728 1413
1729 dl++; 1414 for (o = 0; o < 3; o++) {
1415 dh = table[bx];
1416 ah = table[di];
1417 al = table[si];
1418 si--;
1419 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1730 } 1420 }
1731 1421
1732 si += 5; 1422 dl++;
1733 } 1423 }
1424
1425 si += 5;
1734 } 1426 }
1735} 1427}
1736 1428
@@ -1740,34 +1432,20 @@ static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1740{ 1432{
1741 unsigned short resindex, xres, yres, modeflag; 1433 unsigned short resindex, xres, yres, modeflag;
1742 1434
1743 if (ModeNo <= 0x13) 1435 /* si+Ext_ResInfo */
1744 /* si+St_ResInfo */ 1436 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1745 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1746 else
1747 /* si+Ext_ResInfo */
1748 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1749 1437
1750 if (ModeNo <= 0x13) 1438 /* si+Ext_ResInfo */
1751 /* si+St_ResInfo */ 1439 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1752 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1753 else
1754 /* si+Ext_ResInfo */
1755 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1756 1440
1757 if (ModeNo <= 0x13) { 1441 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1758 xres = pVBInfo->StResInfo[resindex].HTotal; 1442 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1759 yres = pVBInfo->StResInfo[resindex].VTotal;
1760 } else {
1761 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1762 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1763 }
1764 if (ModeNo > 0x13) {
1765 if (modeflag & HalfDCLK)
1766 xres = xres << 1;
1767 1443
1768 if (modeflag & DoubleScanMode) 1444 if (modeflag & HalfDCLK)
1769 yres = yres << 1; 1445 xres = xres << 1;
1770 } 1446
1447 if (modeflag & DoubleScanMode)
1448 yres = yres << 1;
1771 1449
1772 if (xres == 720) 1450 if (xres == 720)
1773 xres = 640; 1451 xres = 640;
@@ -1789,32 +1467,16 @@ static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1789 1467
1790 tempbx = BX; 1468 tempbx = BX;
1791 1469
1792 if (ModeNo <= 0x13) { 1470 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1793 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 1471 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1794 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1795 } else {
1796 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1797 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1798 }
1799 1472
1800 tempal = tempal & 0x0f; 1473 tempal = tempal & 0x0f;
1801 1474
1802 if (tempbx <= 1) { /* ExpLink */ 1475 if (tempbx <= 1) { /* ExpLink */
1803 if (ModeNo <= 0x13) { 1476 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1804 /* find no Ext_CRT2CRTC2 */
1805 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1806 } else {
1807 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1808 Ext_CRT2CRTC;
1809 }
1810 1477
1811 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { 1478 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
1812 if (ModeNo <= 0x13) 1479 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1813 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1814 St_CRT2CRTC2;
1815 else
1816 tempal = pVBInfo->RefIndex[
1817 RefreshRateTableIndex].
1818 Ext_CRT2CRTC2; 1480 Ext_CRT2CRTC2;
1819 } 1481 }
1820 1482
@@ -1882,9 +1544,6 @@ static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1882 tempbx = tempdi[i].MASK; 1544 tempbx = tempdi[i].MASK;
1883 tempdx = pVBInfo->LCDInfo; 1545 tempdx = pVBInfo->LCDInfo;
1884 1546
1885 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1886 tempdx |= SetLCDStdMode;
1887
1888 if (modeflag & HalfDCLK) 1547 if (modeflag & HalfDCLK)
1889 tempdx |= SetLCDLowResolution; 1548 tempdx |= SetLCDLowResolution;
1890 1549
@@ -2238,15 +1897,8 @@ static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2238 struct XGI330_TVDataTablStruct *tempdi = NULL; 1897 struct XGI330_TVDataTablStruct *tempdi = NULL;
2239 1898
2240 tempbx = BX; 1899 tempbx = BX;
2241 1900 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2242 if (ModeNo <= 0x13) { 1901 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2243 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2244 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2245 } else {
2246 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2247 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2248 }
2249
2250 tempal = tempal & 0x3f; 1902 tempal = tempal & 0x3f;
2251 table = tempbx; 1903 table = tempbx;
2252 1904
@@ -2413,11 +2065,7 @@ static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2413 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL; 2065 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2414 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL; 2066 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2415 2067
2416 if (ModeNo <= 0x13) 2068 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2417 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2418 else
2419 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2420
2421 index = index & IndexMask; 2069 index = index & IndexMask;
2422 2070
2423 tempbx = 0; 2071 tempbx = 0;
@@ -2530,14 +2178,10 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2530{ 2178{
2531 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag; 2179 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2532 unsigned long temp, temp1, temp2, temp3, push3; 2180 unsigned long temp, temp1, temp2, temp3, push3;
2533 struct XGI330_LCDDataDesStruct *LCDPtr = NULL; 2181 struct XGI_LCDDesStruct *LCDPtr = NULL;
2534 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL; 2182 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2535 2183
2536 if (ModeNo > 0x13) 2184 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2537 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2538 else
2539 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2540
2541 tempbx = 3; 2185 tempbx = 3;
2542 if (pVBInfo->LCDInfo & EnableScalingLCD) 2186 if (pVBInfo->LCDInfo & EnableScalingLCD)
2543 LCDPtr1 = 2187 LCDPtr1 =
@@ -2550,7 +2194,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2550 pVBInfo); 2194 pVBInfo);
2551 else 2195 else
2552 LCDPtr = 2196 LCDPtr =
2553 (struct XGI330_LCDDataDesStruct *) 2197 (struct XGI_LCDDesStruct *)
2554 XGI_GetLcdPtr( 2198 XGI_GetLcdPtr(
2555 tempbx, 2199 tempbx,
2556 ModeNo, 2200 ModeNo,
@@ -2829,12 +2473,8 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2829 unsigned short index, modeflag; 2473 unsigned short index, modeflag;
2830 unsigned char tempal; 2474 unsigned char tempal;
2831 2475
2832 if (ModeNo <= 0x13) 2476 /* si+Ext_ResInfo */
2833 /* si+St_ResInfo */ 2477 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2834 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2835 else
2836 /* si+Ext_ResInfo */
2837 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2838 2478
2839 if ((pVBInfo->SetFlag & ProgrammingCRT2) && 2479 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2840 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */ 2480 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
@@ -2895,9 +2535,6 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2895 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot)) 2535 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2896 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */ 2536 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2897 2537
2898 if (ModeNo <= 0x13)
2899 return tempal;
2900
2901 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; 2538 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2902 return tempal; 2539 return tempal;
2903} 2540}
@@ -3079,11 +2716,7 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3079{ 2716{
3080 unsigned short tempax, push, tempbx, temp, modeflag; 2717 unsigned short tempax, push, tempbx, temp, modeflag;
3081 2718
3082 if (ModeNo <= 0x13) 2719 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3083 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3084 else
3085 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3086
3087 pVBInfo->SetFlag = 0; 2720 pVBInfo->SetFlag = 0;
3088 pVBInfo->ModeType = modeflag & ModeTypeMask; 2721 pVBInfo->ModeType = modeflag & ModeTypeMask;
3089 tempbx = 0; 2722 tempbx = 0;
@@ -3283,17 +2916,8 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3283 resinfo = 0; 2916 resinfo = 0;
3284 2917
3285 if (pVBInfo->VBInfo & SetCRT2ToTV) { 2918 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3286 if (ModeNo <= 0x13) { 2919 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3287 modeflag = pVBInfo->SModeIDTable[ModeIdIndex]. 2920 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3288 St_ModeFlag; /* si+St_ModeFlag */
3289 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3290 St_ResInfo; /* si+St_ResInfo */
3291 } else {
3292 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3293 Ext_ModeFlag;
3294 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3295 Ext_RESINFO; /* si+Ext_ResInfo */
3296 }
3297 2921
3298 if (pVBInfo->VBInfo & SetCRT2ToTV) { 2922 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3299 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35); 2923 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
@@ -3380,15 +3004,9 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3380 pVBInfo->LCDTypeInfo = 0; 3004 pVBInfo->LCDTypeInfo = 0;
3381 pVBInfo->LCDInfo = 0; 3005 pVBInfo->LCDInfo = 0;
3382 3006
3383 if (ModeNo <= 0x13) { 3007 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3384 /* si+St_ModeFlag // */ 3008 /* si+Ext_ResInfo // */
3385 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 3009 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3386 } else {
3387 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3388 /* si+Ext_ResInfo // */
3389 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3390 }
3391
3392 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */ 3010 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
3393 tempbx = temp & 0x0F; 3011 tempbx = temp & 0x0F;
3394 3012
@@ -3442,8 +3060,8 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3442 3060
3443 if (pVBInfo->IF_DEF_LVDS == 0) { 3061 if (pVBInfo->IF_DEF_LVDS == 0) {
3444 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo 3062 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
3445 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo 3063 & SetCRT2ToLCD) && (resinfo == 9) &&
3446 == 9) && (!(tempbx & EnableScalingLCD))) 3064 (!(tempbx & EnableScalingLCD)))
3447 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */ 3065 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
3448 tempbx |= SetLCDtoNonExpanding; 3066 tempbx |= SetLCDtoNonExpanding;
3449 } 3067 }
@@ -3453,12 +3071,9 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3453 if (!(tempbx & SetLCDtoNonExpanding)) { 3071 if (!(tempbx & SetLCDtoNonExpanding)) {
3454 tempbx |= XGI_EnableLVDSDDA; 3072 tempbx |= XGI_EnableLVDSDDA;
3455 } else { 3073 } else {
3456 if (ModeNo > 0x13) { 3074 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3457 if (pVBInfo->LCDResInfo 3075 if (resinfo == 4) {/* 512x384 */
3458 == Panel_1024x768) { 3076 tempbx |= XGI_EnableLVDSDDA;
3459 if (resinfo == 4) {/* 512x384 */
3460 tempbx |= XGI_EnableLVDSDDA;
3461 }
3462 } 3077 }
3463 } 3078 }
3464 } 3079 }
@@ -3474,56 +3089,17 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3474 3089
3475 pVBInfo->LCDInfo = tempbx; 3090 pVBInfo->LCDInfo = tempbx;
3476 3091
3477 if (pVBInfo->IF_DEF_LVDS == 0) {
3478 if (tempax & (LockLCDBToA | StLCDBToA)) {
3479 if (pVBInfo->VBInfo & SetInSlaveMode) {
3480 if (!(tempax & LockLCDBToA)) {
3481 if (ModeNo <= 0x13) {
3482 pVBInfo->VBInfo &=
3483 ~(SetSimuScanMode |
3484 SetInSlaveMode |
3485 SetCRT2ToLCD);
3486 pVBInfo->VBInfo |=
3487 XGI_SetCRT2ToLCDA |
3488 SetCRT2ToDualEdge;
3489 }
3490 }
3491 }
3492 }
3493 }
3494
3495 return 1; 3092 return 1;
3496} 3093}
3497 3094
3498unsigned char XGI_SearchModeID(unsigned short ModeNo, 3095unsigned char XGI_SearchModeID(unsigned short ModeNo,
3499 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo) 3096 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3500{ 3097{
3501 if (ModeNo <= 5) 3098 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3502 ModeNo |= 1; 3099 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3503 if (ModeNo <= 0x13) { 3100 break;
3504 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) { 3101 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3505 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID == 3102 return 0;
3506 ModeNo)
3507 break;
3508 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3509 0xFF)
3510 return 0;
3511 }
3512
3513 if (ModeNo == 0x07)
3514 (*ModeIdIndex)++; /* 400 lines */
3515 if (ModeNo <= 3)
3516 (*ModeIdIndex) += 2; /* 400 lines */
3517 /* else 350 lines */
3518 } else {
3519 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3520 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3521 ModeNo)
3522 break;
3523 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3524 0xFF)
3525 return 0;
3526 }
3527 } 3103 }
3528 3104
3529 return 1; 3105 return 1;
@@ -3789,22 +3365,17 @@ static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3789{ 3365{
3790 unsigned short xres, yres, modeflag, resindex; 3366 unsigned short xres, yres, modeflag, resindex;
3791 3367
3792 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); 3368 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3793 if (ModeNo <= 0x13) { 3369 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3794 xres = pVBInfo->StResInfo[resindex].HTotal; 3370 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3795 yres = pVBInfo->StResInfo[resindex].VTotal; 3371 /* si+St_ModeFlag */
3796 } else { 3372 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3797 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3798 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3799 /* si+St_ModeFlag */
3800 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3801 3373
3802 if (modeflag & HalfDCLK) 3374 if (modeflag & HalfDCLK)
3803 xres *= 2; 3375 xres *= 2;
3804 3376
3805 if (modeflag & DoubleScanMode) 3377 if (modeflag & DoubleScanMode)
3806 yres *= 2; 3378 yres *= 2;
3807 }
3808 3379
3809 if (pVBInfo->VBInfo & SetCRT2ToLCD) { 3380 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3810 if (pVBInfo->IF_DEF_LVDS == 0) { 3381 if (pVBInfo->IF_DEF_LVDS == 0) {
@@ -3868,37 +3439,23 @@ static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3868 struct vb_device_info *pVBInfo) 3439 struct vb_device_info *pVBInfo)
3869{ 3440{
3870 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx, 3441 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3871 StandTableIndex, CRT1Index; 3442 CRT1Index;
3872 3443
3873 pVBInfo->RVBHCMAX = 1; 3444 pVBInfo->RVBHCMAX = 1;
3874 pVBInfo->RVBHCFACT = 1; 3445 pVBInfo->RVBHCFACT = 1;
3875 3446 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3876 if (ModeNo <= 0x13) { 3447 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3877 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 3448 CRT1Index &= IndexMask;
3878 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo); 3449 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3879 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0]; 3450 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3880 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6]; 3451 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3881 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7]; 3452 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3882 } else { 3453 tempcx = (unsigned short)
3883 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3454 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3884 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex]. 3455 tempcx &= 0x0100;
3885 Ext_CRT1CRTC; 3456 tempcx = tempcx << 2;
3886 CRT1Index &= IndexMask; 3457 tempbx |= tempcx;
3887 temp1 = (unsigned short) pVBInfo-> 3458 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
3888 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3889 temp2 = (unsigned short) pVBInfo->
3890 XGINEWUB_CRT1Table[CRT1Index].CR[5];
3891 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3892 tempbx = (unsigned short) pVBInfo->
3893 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3894 tempcx = (unsigned short) pVBInfo->
3895 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3896 tempcx &= 0x0100;
3897 tempcx = tempcx << 2;
3898 tempbx |= tempcx;
3899 temp1 = (unsigned short) pVBInfo->
3900 XGINEWUB_CRT1Table[CRT1Index].CR[9];
3901 }
3902 3459
3903 if (temp1 & 0x01) 3460 if (temp1 & 0x01)
3904 tempbx |= 0x0100; 3461 tempbx |= 0x0100;
@@ -3928,16 +3485,9 @@ static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
3928 struct SiS_LCDData *LCDPtr = NULL; 3485 struct SiS_LCDData *LCDPtr = NULL;
3929 struct SiS_TVData *TVPtr = NULL; 3486 struct SiS_TVData *TVPtr = NULL;
3930 3487
3931 if (ModeNo <= 0x13) { 3488 /* si+Ext_ResInfo */
3932 /* si+St_ResInfo */ 3489 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3933 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 3490 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3934 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
3935 } else {
3936 /* si+Ext_ResInfo */
3937 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3938 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3939 }
3940
3941 pVBInfo->NewFlickerMode = 0; 3491 pVBInfo->NewFlickerMode = 0;
3942 pVBInfo->RVBHRS = 50; 3492 pVBInfo->RVBHRS = 50;
3943 3493
@@ -4141,11 +3691,7 @@ static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4141 short index; 3691 short index;
4142 unsigned short modeflag; 3692 unsigned short modeflag;
4143 3693
4144 if (ModeNo <= 0x13) 3694 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4145 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4146 else
4147 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4148
4149 index = (modeflag & ModeTypeMask) - ModeEGA; 3695 index = (modeflag & ModeTypeMask) - ModeEGA;
4150 3696
4151 if (index < 0) 3697 if (index < 0)
@@ -4164,11 +3710,7 @@ static unsigned short XGI_GetOffset(unsigned short ModeNo,
4164 ColorDepth[] = { 0x01, 0x02, 0x04 }; 3710 ColorDepth[] = { 0x01, 0x02, 0x04 };
4165 3711
4166 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo; 3712 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4167 if (ModeNo <= 0x14) 3713 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4168 infoflag = 0;
4169 else
4170 infoflag = pVBInfo->
4171 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4172 3714
4173 index = (modeinfo >> 8) & 0xFF; 3715 index = (modeinfo >> 8) & 0xFF;
4174 3716
@@ -4228,12 +3770,9 @@ static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4228{ 3770{
4229 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0; 3771 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
4230 3772
4231 if (ModeNo > 0x13) { 3773 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4232 CRT1Index = pVBInfo-> 3774 CRT1Index &= IndexMask;
4233 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 3775 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4234 CRT1Index &= IndexMask;
4235 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4236 }
4237 3776
4238 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, 3777 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4239 HwDeviceExtension, pVBInfo); 3778 HwDeviceExtension, pVBInfo);
@@ -4254,17 +3793,10 @@ static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4254 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0, 3793 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4255 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0; 3794 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4256 3795
4257 if (ModeNo > 0x13) { 3796 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4258 CRT1Index = pVBInfo-> 3797 CRT1Index &= IndexMask;
4259 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 3798 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4260 CRT1Index &= IndexMask; 3799 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4261 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4262 }
4263
4264 if (ModeNo <= 0x13)
4265 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4266 else
4267 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4268 3800
4269 /* bainy change table name */ 3801 /* bainy change table name */
4270 if (modeflag & HalfDCLK) { 3802 if (modeflag & HalfDCLK) {
@@ -4422,18 +3954,11 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4422 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo, 3954 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4423 modeflag, CRT1Index; 3955 modeflag, CRT1Index;
4424 3956
4425 if (ModeNo <= 0x13) { 3957 /* si+Ext_ResInfo */
4426 /* si+St_ResInfo */ 3958 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4427 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 3959 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4428 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo; 3960 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4429 } else { 3961 CRT1Index &= IndexMask;
4430 /* si+Ext_ResInfo */
4431 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4432 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4433 CRT1Index = pVBInfo->
4434 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4435 CRT1Index &= IndexMask;
4436 }
4437 3962
4438 if (!(pVBInfo->VBInfo & SetInSlaveMode)) 3963 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4439 return; 3964 return;
@@ -4500,8 +4025,7 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4500 temp -= 6; 4025 temp -= 6;
4501 if (pVBInfo->TVInfo & TVSimuMode) { 4026 if (pVBInfo->TVInfo & TVSimuMode) {
4502 temp -= 4; 4027 temp -= 4;
4503 if (ModeNo > 0x13) 4028 temp -= 10;
4504 temp -= 10;
4505 } 4029 }
4506 } 4030 }
4507 } else { 4031 } else {
@@ -4523,14 +4047,6 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4523 if (pVBInfo->LCDResInfo != Panel_1280x960 && 4047 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
4524 pVBInfo->VGAHDE >= 800) { 4048 pVBInfo->VGAHDE >= 800) {
4525 temp -= 7; 4049 temp -= 7;
4526 if (pVBInfo->ModeType == ModeEGA &&
4527 pVBInfo->VGAVDE == 1024) {
4528 temp += 15;
4529 if (pVBInfo->LCDResInfo !=
4530 Panel_1280x1024)
4531 temp += 7;
4532 }
4533
4534 if (pVBInfo->VGAHDE >= 1280 && 4050 if (pVBInfo->VGAHDE >= 1280 &&
4535 pVBInfo->LCDResInfo != Panel_1280x960 && 4051 pVBInfo->LCDResInfo != Panel_1280x960 &&
4536 (pVBInfo->LCDInfo & LCDNonExpanding)) 4052 (pVBInfo->LCDInfo & LCDNonExpanding))
@@ -4546,48 +4062,7 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4546 4062
4547 if (pVBInfo->VBInfo & SetCRT2ToTV) { 4063 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4548 if (pVBInfo->TVInfo & TVSimuMode) { 4064 if (pVBInfo->TVInfo & TVSimuMode) {
4549 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo 4065 if (ModeNo == 0x50) {
4550 == 0x11) || (ModeNo == 0x13) || (ModeNo
4551 == 0x0F)) {
4552 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4553 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
4554 }
4555
4556 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4557 if (pVBInfo->TVInfo & SetNTSCTV) {
4558 xgifb_reg_set(pVBInfo->Part1Port,
4559 0x07, 0x2A);
4560 xgifb_reg_set(pVBInfo->Part1Port,
4561 0x08, 0x61);
4562 } else {
4563 xgifb_reg_set(pVBInfo->Part1Port,
4564 0x07, 0x2A);
4565 xgifb_reg_set(pVBInfo->Part1Port,
4566 0x08, 0x41);
4567 xgifb_reg_set(pVBInfo->Part1Port,
4568 0x0C, 0xF0);
4569 }
4570 }
4571
4572 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4573 == 0x07)) {
4574 if (pVBInfo->TVInfo & SetNTSCTV) {
4575 xgifb_reg_set(pVBInfo->Part1Port,
4576 0x07, 0x54);
4577 xgifb_reg_set(pVBInfo->Part1Port,
4578 0x08, 0x00);
4579 } else {
4580 xgifb_reg_set(pVBInfo->Part1Port,
4581 0x07, 0x55);
4582 xgifb_reg_set(pVBInfo->Part1Port,
4583 0x08, 0x00);
4584 xgifb_reg_set(pVBInfo->Part1Port,
4585 0x0C, 0xF0);
4586 }
4587 }
4588
4589 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4590 == 0x0D) || (ModeNo == 0x50)) {
4591 if (pVBInfo->TVInfo & SetNTSCTV) { 4066 if (pVBInfo->TVInfo & SetNTSCTV) {
4592 xgifb_reg_set(pVBInfo->Part1Port, 4067 xgifb_reg_set(pVBInfo->Part1Port,
4593 0x07, 0x30); 4068 0x07, 0x30);
@@ -4796,18 +4271,10 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4796 4271
4797 unsigned long longtemp, tempeax, tempebx, temp2, tempecx; 4272 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4798 4273
4799 if (ModeNo <= 0x13) { 4274 /* si+Ext_ResInfo */
4800 /* si+St_ResInfo */ 4275 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4801 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 4276 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4802 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo; 4277 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
4803 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4804 } else {
4805 /* si+Ext_ResInfo */
4806 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4807 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4808 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4809 Ext_CRT2CRTC;
4810 }
4811 4278
4812 tempax = 0; 4279 tempax = 0;
4813 4280
@@ -5245,18 +4712,11 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5245 4712
5246 struct XGI_LCDDesStruct *LCDBDesPtr = NULL; 4713 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5247 4714
5248 if (ModeNo <= 0x13) { 4715 /* si+Ext_ResInfo */
5249 /* si+St_ResInfo */ 4716 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5250 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; 4717 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5251 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo; 4718 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
5252 } else { 4719 CRT1Index &= IndexMask;
5253 /* si+Ext_ResInfo */
5254 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5255 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5256 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5257 Ext_CRT1CRTC;
5258 CRT1Index &= IndexMask;
5259 }
5260 4720
5261 if (!(pVBInfo->VBInfo & SetCRT2ToLCD)) 4721 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5262 return; 4722 return;
@@ -5274,16 +4734,6 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5274 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp); 4734 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
5275 temp = 0x01; 4735 temp = 0x01;
5276 4736
5277 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
5278 if (pVBInfo->ModeType == ModeEGA) {
5279 if (pVBInfo->VGAHDE >= 1024) {
5280 temp = 0x02;
5281 if (pVBInfo->LCDInfo & XGI_LCDVESATiming)
5282 temp = 0x01;
5283 }
5284 }
5285 }
5286
5287 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp); 4737 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
5288 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */ 4738 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5289 push1 = tempbx; 4739 push1 = tempbx;
@@ -5542,12 +4992,8 @@ static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5542 unsigned char *tempdi; 4992 unsigned char *tempdi;
5543 unsigned short modeflag; 4993 unsigned short modeflag;
5544 4994
5545 if (ModeNo <= 0x13) 4995 /* si+Ext_ResInfo */
5546 /* si+St_ResInfo */ 4996 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5547 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5548 else
5549 /* si+Ext_ResInfo */
5550 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5551 4997
5552 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00); 4998 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
5553 if (pVBInfo->TVInfo & TVSetPAL) { 4999 if (pVBInfo->TVInfo & TVSetPAL) {
@@ -5605,13 +5051,8 @@ static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5605 5051
5606 unsigned long tempebx, tempeax, templong; 5052 unsigned long tempebx, tempeax, templong;
5607 5053
5608 if (ModeNo <= 0x13) 5054 /* si+Ext_ResInfo */
5609 /* si+St_ResInfo */ 5055 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5610 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5611 else
5612 /* si+Ext_ResInfo */
5613 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5614
5615 temp = pVBInfo->RVBHCFACT; 5056 temp = pVBInfo->RVBHCFACT;
5616 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp); 5057 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5617 5058
@@ -5818,32 +5259,22 @@ static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5818{ 5259{
5819 unsigned short xres, yres, colordepth, modeflag, resindex; 5260 unsigned short xres, yres, colordepth, modeflag, resindex;
5820 5261
5821 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); 5262 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5822 if (ModeNo <= 0x13) { 5263 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5823 xres = pVBInfo->StResInfo[resindex].HTotal; 5264 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5824 yres = pVBInfo->StResInfo[resindex].VTotal; 5265 /* si+St_ModeFlag */
5825 /* si+St_ResInfo */ 5266 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5826 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5827 } else {
5828 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5829 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5830 /* si+St_ModeFlag */
5831 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5832 }
5833 5267
5834 if (!(modeflag & Charx8Dot)) { 5268 if (!(modeflag & Charx8Dot)) {
5835 xres /= 9; 5269 xres /= 9;
5836 xres *= 8; 5270 xres *= 8;
5837 } 5271 }
5838 5272
5839 if (ModeNo > 0x13) { 5273 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5840 if ((ModeNo > 0x13) && (modeflag & HalfDCLK)) 5274 xres *= 2;
5841 xres *= 2;
5842
5843 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5844 yres *= 2;
5845 5275
5846 } 5276 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5277 yres *= 2;
5847 5278
5848 if (xres > xgifb_info->lvds_data.LVDSHDE) 5279 if (xres > xgifb_info->lvds_data.LVDSHDE)
5849 return 0; 5280 return 0;
@@ -5851,16 +5282,11 @@ static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5851 if (yres > xgifb_info->lvds_data.LVDSVDE) 5282 if (yres > xgifb_info->lvds_data.LVDSVDE)
5852 return 0; 5283 return 0;
5853 5284
5854 if (ModeNo > 0x13) { 5285 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5855 if (xres != xgifb_info->lvds_data.LVDSHDE || 5286 yres != xgifb_info->lvds_data.LVDSVDE) {
5856 yres != xgifb_info->lvds_data.LVDSVDE) { 5287 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5857 colordepth = XGI_GetColorDepth(ModeNo, 5288 if (colordepth > 2)
5858 ModeIdIndex, 5289 return 0;
5859 pVBInfo);
5860 if (colordepth > 2)
5861 return 0;
5862
5863 }
5864 } 5290 }
5865 return 1; 5291 return 1;
5866} 5292}
@@ -5895,18 +5321,11 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5895 else 5321 else
5896 XGI_SetXG21FPBits(pVBInfo); 5322 XGI_SetXG21FPBits(pVBInfo);
5897 5323
5898 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); 5324 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5899 if (ModeNo <= 0x13) { 5325 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5900 xres = pVBInfo->StResInfo[resindex].HTotal; 5326 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5901 yres = pVBInfo->StResInfo[resindex].VTotal; 5327 /* si+St_ModeFlag */
5902 /* si+St_ResInfo */ 5328 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5903 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5904 } else {
5905 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5906 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5907 /* si+St_ModeFlag */
5908 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5909 }
5910 5329
5911 if (!(modeflag & Charx8Dot)) 5330 if (!(modeflag & Charx8Dot))
5912 xres = xres * 8 / 9; 5331 xres = xres * 8 / 9;
@@ -5914,8 +5333,6 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5914 LVDSHT = xgifb_info->lvds_data.LVDSHT; 5333 LVDSHT = xgifb_info->lvds_data.LVDSHT;
5915 5334
5916 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2; 5335 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
5917 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
5918 LVDSHBS -= xres / 4;
5919 5336
5920 if (LVDSHBS > LVDSHT) 5337 if (LVDSHBS > LVDSHT)
5921 LVDSHBS -= LVDSHT; 5338 LVDSHBS -= LVDSHT;
@@ -5933,7 +5350,7 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5933 LVDSVT = xgifb_info->lvds_data.LVDSVT; 5350 LVDSVT = xgifb_info->lvds_data.LVDSVT;
5934 5351
5935 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2; 5352 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
5936 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode)) 5353 if (modeflag & DoubleScanMode)
5937 LVDSVBS += yres / 2; 5354 LVDSVBS += yres / 2;
5938 5355
5939 if (LVDSVBS > LVDSVT) 5356 if (LVDSVBS > LVDSVT)
@@ -6527,7 +5944,7 @@ static void XGI_SetAntiFlicker(unsigned short ModeNo,
6527 unsigned short ModeIdIndex, 5944 unsigned short ModeIdIndex,
6528 struct vb_device_info *pVBInfo) 5945 struct vb_device_info *pVBInfo)
6529{ 5946{
6530 unsigned short tempbx, index; 5947 unsigned short tempbx;
6531 5948
6532 unsigned char tempah; 5949 unsigned char tempah;
6533 5950
@@ -6536,13 +5953,6 @@ static void XGI_SetAntiFlicker(unsigned short ModeNo,
6536 5953
6537 tempbx = XGI_GetTVPtrIndex(pVBInfo); 5954 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6538 tempbx &= 0xFE; 5955 tempbx &= 0xFE;
6539
6540 if (ModeNo <= 0x13)
6541 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6542 else
6543 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
6544
6545 tempbx += index;
6546 tempah = TVAntiFlickList[tempbx]; 5956 tempah = TVAntiFlickList[tempbx];
6547 tempah = tempah << 4; 5957 tempah = tempah << 4;
6548 5958
@@ -6553,19 +5963,12 @@ static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6553 unsigned short ModeIdIndex, 5963 unsigned short ModeIdIndex,
6554 struct vb_device_info *pVBInfo) 5964 struct vb_device_info *pVBInfo)
6555{ 5965{
6556 unsigned short tempbx, index; 5966 unsigned short tempbx;
6557 5967
6558 unsigned char tempah; 5968 unsigned char tempah;
6559 5969
6560 tempbx = XGI_GetTVPtrIndex(pVBInfo); 5970 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6561 tempbx &= 0xFE; 5971 tempbx &= 0xFE;
6562
6563 if (ModeNo <= 0x13)
6564 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6565 else
6566 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
6567
6568 tempbx += index;
6569 tempah = TVEdgeList[tempbx]; 5972 tempah = TVEdgeList[tempbx];
6570 tempah = tempah << 5; 5973 tempah = tempah << 5;
6571 5974
@@ -6631,13 +6034,7 @@ static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6631 return; 6034 return;
6632 } 6035 }
6633 6036
6634 if (ModeNo <= 0x13) 6037 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
6635 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6636 VB_StTVYFilterIndex;
6637 else
6638 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6639 VB_ExtTVYFilterIndex;
6640
6641 if (tempcl == 0) 6038 if (tempcl == 0)
6642 index = tempal * 4; 6039 index = tempal * 4;
6643 else 6040 else
@@ -6712,16 +6109,14 @@ static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6712 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV 6109 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6713 | SetCRT2ToLCD)) { 6110 | SetCRT2ToLCD)) {
6714 tempah = 0x40; /* BTDRAM */ 6111 tempah = 0x40; /* BTDRAM */
6715 if (ModeNo > 0x13) { 6112 tempcl = pVBInfo->ModeType;
6716 tempcl = pVBInfo->ModeType; 6113 tempcl -= ModeVGA;
6717 tempcl -= ModeVGA; 6114 if (tempcl >= 0) {
6718 if (tempcl >= 0) { 6115 /* BT Color */
6719 /* BT Color */ 6116 tempah = (0x008 >> tempcl);
6720 tempah = (0x008 >> tempcl); 6117 if (tempah == 0)
6721 if (tempah == 0) 6118 tempah = 1;
6722 tempah = 1; 6119 tempah |= 0x040;
6723 tempah |= 0x040;
6724 }
6725 } 6120 }
6726 if (pVBInfo->VBInfo & SetInSlaveMode) 6121 if (pVBInfo->VBInfo & SetInSlaveMode)
6727 tempah ^= 0x50; /* BTDAC */ 6122 tempah ^= 0x50; /* BTDAC */
@@ -6797,10 +6192,8 @@ static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6797 6192
6798 if (pVBInfo->VBInfo & SetCRT2ToTV) { 6193 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6799 tempah |= 0x020; 6194 tempah |= 0x020;
6800 if (ModeNo > 0x13) { 6195 if (pVBInfo->VBInfo & DriverMode)
6801 if (pVBInfo->VBInfo & DriverMode) 6196 tempah = tempah ^ 0x20;
6802 tempah = tempah ^ 0x20;
6803 }
6804 } 6197 }
6805 6198
6806 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah); 6199 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
@@ -6925,13 +6318,7 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6925 6318
6926 unsigned short RefreshRateTableIndex, i, modeflag, index, temp; 6319 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
6927 6320
6928 if (ModeNo <= 0x13) 6321 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6929 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6930 else
6931 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6932
6933 if (ModeNo < 0x14)
6934 return 0xFFFF;
6935 6322
6936 index = xgifb_reg_get(pVBInfo->P3d4, 0x33); 6323 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
6937 index = index >> pVBInfo->SelectCRT2Rate; 6324 index = index >> pVBInfo->SelectCRT2Rate;
@@ -7297,16 +6684,13 @@ static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
7297 unsigned short ModeNo, unsigned short ModeIdIndex, 6684 unsigned short ModeNo, unsigned short ModeIdIndex,
7298 struct vb_device_info *pVBInfo) 6685 struct vb_device_info *pVBInfo)
7299{ 6686{
7300 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp; 6687 unsigned short RefreshRateTableIndex, temp;
7301 6688
7302 unsigned short XGINew_P3cc = pVBInfo->P3cc; 6689 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
7303 6690 outb(pVBInfo->StandTable->MISC, pVBInfo->P3c2);
7304 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo); 6691 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
7305 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo); 6692 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
7306 outb(pVBInfo->StandTable[StandTableIndex].MISC, pVBInfo->P3c2); 6693 XGI_SetGRCRegs(pVBInfo);
7307 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7308 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7309 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7310 XGI_ClearExt1Regs(pVBInfo); 6694 XGI_ClearExt1Regs(pVBInfo);
7311 6695
7312 if (HwDeviceExtension->jChipType == XG27) { 6696 if (HwDeviceExtension->jChipType == XG27) {
@@ -7340,22 +6724,6 @@ static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
7340 RefreshRateTableIndex, pVBInfo); 6724 RefreshRateTableIndex, pVBInfo);
7341 } 6725 }
7342 6726
7343 if ((HwDeviceExtension->jChipType >= XG20) &&
7344 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
7345 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
7346 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7347 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
7348 b3CC = (unsigned char) inb(XGINew_P3cc);
7349 outb((b3CC |= 0x0C), XGINew_P3cc);
7350 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7351 == 0x0D)) {
7352 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7353 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
7354 b3CC = (unsigned char) inb(XGINew_P3cc);
7355 outb((b3CC |= 0x0C), XGINew_P3cc);
7356 }
7357 }
7358
7359 if (HwDeviceExtension->jChipType >= XG21) { 6727 if (HwDeviceExtension->jChipType >= XG21) {
7360 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38); 6728 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
7361 if (temp & 0xA0) { 6729 if (temp & 0xA0) {
@@ -7394,7 +6762,7 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
7394 unsigned short ModeIdIndex; 6762 unsigned short ModeIdIndex;
7395 struct vb_device_info VBINF; 6763 struct vb_device_info VBINF;
7396 struct vb_device_info *pVBInfo = &VBINF; 6764 struct vb_device_info *pVBInfo = &VBINF;
7397 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress; 6765 pVBInfo->BaseAddr = xgifb_info->vga_base;
7398 pVBInfo->IF_DEF_LVDS = 0; 6766 pVBInfo->IF_DEF_LVDS = 0;
7399 pVBInfo->IF_DEF_LCDA = 1; 6767 pVBInfo->IF_DEF_LCDA = 1;
7400 6768
@@ -7509,13 +6877,8 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
7509 pVBInfo)) 6877 pVBInfo))
7510 return 0; 6878 return 0;
7511 6879
7512 if (ModeNo <= 0x13) { 6880 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7513 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7514 St_ModeFlag & ModeTypeMask;
7515 } else {
7516 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7517 Ext_ModeFlag & ModeTypeMask; 6881 Ext_ModeFlag & ModeTypeMask;
7518 }
7519 6882
7520 pVBInfo->SetFlag = 0; 6883 pVBInfo->SetFlag = 0;
7521 pVBInfo->VBInfo = DisableCRT2Display; 6884 pVBInfo->VBInfo = DisableCRT2Display;
diff --git a/drivers/staging/xgifb/vb_struct.h b/drivers/staging/xgifb/vb_struct.h
index a5bd56af92b1..38f47ffc69c4 100644
--- a/drivers/staging/xgifb/vb_struct.h
+++ b/drivers/staging/xgifb/vb_struct.h
@@ -10,28 +10,11 @@ struct XGI_LVDSCRT1VDataStruct {
10 unsigned char Reg[7]; 10 unsigned char Reg[7];
11}; 11};
12 12
13struct XGI_StStruct {
14 unsigned char St_ModeID;
15 unsigned short St_ModeFlag;
16 unsigned char St_StTableIndex;
17 unsigned char St_CRT2CRTC;
18 unsigned char St_CRT2CRTC2;
19 unsigned char St_ResInfo;
20 unsigned char VB_StTVFlickerIndex;
21 unsigned char VB_StTVEdgeIndex;
22 unsigned char VB_StTVYFilterIndex;
23};
24
25struct XGI_ExtStruct { 13struct XGI_ExtStruct {
26 unsigned char Ext_ModeID; 14 unsigned char Ext_ModeID;
27 unsigned short Ext_ModeFlag; 15 unsigned short Ext_ModeFlag;
28 unsigned short Ext_ModeInfo; 16 unsigned short Ext_ModeInfo;
29 unsigned short Ext_Point;
30 unsigned short Ext_VESAID;
31 unsigned char Ext_VESAMEMSize;
32 unsigned char Ext_RESINFO; 17 unsigned char Ext_RESINFO;
33 unsigned char VB_ExtTVFlickerIndex;
34 unsigned char VB_ExtTVEdgeIndex;
35 unsigned char VB_ExtTVYFilterIndex; 18 unsigned char VB_ExtTVYFilterIndex;
36 unsigned char REFindex; 19 unsigned char REFindex;
37}; 20};
@@ -68,14 +51,6 @@ struct XGI_LCDDataTablStruct {
68 unsigned short DATAPTR; 51 unsigned short DATAPTR;
69}; 52};
70 53
71struct XGI330_LCDDataDesStruct {
72 unsigned short LCDHDES;
73 unsigned short LCDHRS;
74 unsigned short LCDVDES;
75 unsigned short LCDVRS;
76};
77
78
79struct XGI330_LVDSDataStruct { 54struct XGI330_LVDSDataStruct {
80 unsigned short VGAHT; 55 unsigned short VGAHT;
81 unsigned short VGAVT; 56 unsigned short VGAVT;
@@ -236,7 +211,6 @@ struct vb_device_info {
236 211
237 void __iomem *FBAddr; 212 void __iomem *FBAddr;
238 unsigned long BaseAddr; 213 unsigned long BaseAddr;
239 unsigned long RelIO;
240 214
241 unsigned char (*CR6B)[4]; 215 unsigned char (*CR6B)[4];
242 unsigned char (*CR6E)[4]; 216 unsigned char (*CR6E)[4];
@@ -314,7 +288,6 @@ struct vb_device_info {
314 struct XGI_TimingHStruct *TimingH; 288 struct XGI_TimingHStruct *TimingH;
315 struct XGI_TimingVStruct *TimingV; 289 struct XGI_TimingVStruct *TimingV;
316 290
317 struct XGI_StStruct *SModeIDTable;
318 struct SiS_StandTable_S *StandTable; 291 struct SiS_StandTable_S *StandTable;
319 struct XGI_ExtStruct *EModeIDTable; 292 struct XGI_ExtStruct *EModeIDTable;
320 struct XGI_Ext2Struct *RefIndex; 293 struct XGI_Ext2Struct *RefIndex;
diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h
index e8d6f674b274..d22e599cb305 100644
--- a/drivers/staging/xgifb/vb_table.h
+++ b/drivers/staging/xgifb/vb_table.h
@@ -135,609 +135,92 @@ static unsigned char XGI330_SR33;
135static unsigned char XG40_CRCF = 0x13; 135static unsigned char XG40_CRCF = 0x13;
136static unsigned char XG40_DRAMTypeDefinition = 0xFF ; 136static unsigned char XG40_DRAMTypeDefinition = 0xFF ;
137 137
138static struct XGI_StStruct XGI330_SModeIDTable[] = {
139 {0x01, 0x9208, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00},
140 {0x01, 0x1210, 0x14, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00},
141 {0x01, 0x1010, 0x17, 0x02, 0x11, 0x00, 0x00, 0x01, 0x01},
142 {0x03, 0x8208, 0x03, 0x00, 0x14, 0x00, 0x00, 0x01, 0x02},
143 {0x03, 0x0210, 0x16, 0x01, 0x04, 0x01, 0x00, 0x01, 0x02},
144 {0x03, 0x0010, 0x18, 0x02, 0x15, 0x00, 0x00, 0x01, 0x03},
145 {0x05, 0x9209, 0x05, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04},
146 {0x06, 0x8209, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05},
147 {0x07, 0x0000, 0x07, 0x03, 0x05, 0x03, 0x00, 0x01, 0x03},
148 {0x07, 0x0000, 0x19, 0x02, 0x15, 0x02, 0x00, 0x01, 0x03},
149 {0x0d, 0x920a, 0x0d, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04},
150 {0x0e, 0x820a, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05},
151 {0x0f, 0x0202, 0x11, 0x01, 0x04, 0x01, 0x00, 0x00, 0x05},
152 {0x10, 0x0212, 0x12, 0x01, 0x04, 0x01, 0x00, 0x00, 0x05},
153 {0x11, 0x0212, 0x1a, 0x04, 0x24, 0x04, 0x00, 0x00, 0x05},
154 {0x12, 0x0212, 0x1b, 0x04, 0x24, 0x04, 0x00, 0x00, 0x05},
155 {0x13, 0x021b, 0x1c, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04},
156 {0x12, 0x0010, 0x18, 0x02, 0x24, 0x02, 0x00, 0x00, 0x05},/* St_CRT2CRTC2
157 not sure */
158 {0x12, 0x0210, 0x18, 0x01, 0x24, 0x01, 0x00, 0x00, 0x05},/* St_CRT2CRTC2
159 not sure */
160 {0xff, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
161};
162
163
164static struct XGI_ExtStruct XGI330_EModeIDTable[] = { 138static struct XGI_ExtStruct XGI330_EModeIDTable[] = {
165 {0x6a, 0x2212, 0x0407, 0x3a81, 0x0102, 0x08, 139 {0x2e, 0x0a1b, 0x0306, 0x06, 0x05, 0x06},
166 0x07, 0x00, 0x00, 0x07, 0x0e}, 140 {0x2f, 0x0a1b, 0x0305, 0x05, 0x05, 0x05},
167 {0x2e, 0x0a1b, 0x0306, 0x3a57, 0x0101, 0x08, 141 {0x30, 0x2a1b, 0x0407, 0x07, 0x07, 0x0e},
168 0x06, 0x00, 0x00, 0x05, 0x06}, 142 {0x31, 0x0a1b, 0x030d, 0x0d, 0x06, 0x3d},
169 {0x2f, 0x0a1b, 0x0305, 0x3a50, 0x0100, 0x08, 143 {0x32, 0x0a1b, 0x0a0e, 0x0e, 0x06, 0x3e},
170 0x05, 0x00, 0x00, 0x05, 0x05}, 144 {0x33, 0x0a1d, 0x0a0d, 0x0d, 0x06, 0x3d},
171 {0x30, 0x2a1b, 0x0407, 0x3a81, 0x0103, 0x08, 145 {0x34, 0x2a1d, 0x0a0e, 0x0e, 0x06, 0x3e},
172 0x07, 0x00, 0x00, 0x07, 0x0e}, 146 {0x35, 0x0a1f, 0x0a0d, 0x0d, 0x06, 0x3d},
173 {0x31, 0x0a1b, 0x030d, 0x3b85, 0x0000, 0x08, 147 {0x36, 0x2a1f, 0x0a0e, 0x0e, 0x06, 0x3e},
174 0x0d, 0x00, 0x00, 0x06, 0x3d}, 148 {0x38, 0x0a1b, 0x0508, 0x08, 0x00, 0x16},
175 {0x32, 0x0a1b, 0x0a0e, 0x3b8c, 0x0000, 0x08, 149 {0x3a, 0x0e3b, 0x0609, 0x09, 0x00, 0x1e},
176 0x0e, 0x00, 0x00, 0x06, 0x3e}, 150 {0x3c, 0x0e3b, 0x070a, 0x0a, 0x00, 0x22}, /* mode 1600x1200
177 {0x33, 0x0a1d, 0x0a0d, 0x3b85, 0x0000, 0x08,
178 0x0d, 0x00, 0x00, 0x06, 0x3d},
179 {0x34, 0x2a1d, 0x0a0e, 0x3b8c, 0x0000, 0x08,
180 0x0e, 0x00, 0x00, 0x06, 0x3e},
181 {0x35, 0x0a1f, 0x0a0d, 0x3b85, 0x0000, 0x08,
182 0x0d, 0x00, 0x00, 0x06, 0x3d},
183 {0x36, 0x2a1f, 0x0a0e, 0x3b8c, 0x0000, 0x08,
184 0x0e, 0x00, 0x00, 0x06, 0x3e},
185 {0x37, 0x0212, 0x0508, 0x3aab, 0x0104, 0x08,
186 0x08, 0x00, 0x00, 0x00, 0x16},
187 {0x38, 0x0a1b, 0x0508, 0x3aab, 0x0105, 0x08,
188 0x08, 0x00, 0x00, 0x00, 0x16},
189 {0x3a, 0x0e3b, 0x0609, 0x3adc, 0x0107, 0x08,
190 0x09, 0x00, 0x00, 0x00, 0x1e},
191 {0x3c, 0x0e3b, 0x070a, 0x3af2, 0x0130, 0x08,
192 0x0a, 0x00, 0x00, 0x00, 0x22}, /* mode 1600x1200
193 add CRT2MODE [2003/10/07] */ 151 add CRT2MODE [2003/10/07] */
194 {0x3d, 0x0e7d, 0x070a, 0x3af2, 0x0131, 0x08, 152 {0x3d, 0x0e7d, 0x070a, 0x0a, 0x00, 0x22}, /* mode 1600x1200
195 0x0a, 0x00, 0x00, 0x00, 0x22}, /* mode 1600x1200
196 add CRT2MODE */ 153 add CRT2MODE */
197 {0x40, 0x9a1c, 0x0000, 0x3a34, 0x010d, 0x08, 154 {0x40, 0x9a1c, 0x0000, 0x00, 0x04, 0x00},
198 0x00, 0x00, 0x00, 0x04, 0x00}, 155 {0x41, 0x9a1d, 0x0000, 0x00, 0x04, 0x00},
199 {0x41, 0x9a1d, 0x0000, 0x3a34, 0x010e, 0x08, 156 {0x43, 0x0a1c, 0x0306, 0x06, 0x05, 0x06},
200 0x00, 0x00, 0x00, 0x04, 0x00}, /* ModeIdIndex = 0x10 */ 157 {0x44, 0x0a1d, 0x0306, 0x06, 0x05, 0x06},
201 {0x43, 0x0a1c, 0x0306, 0x3a57, 0x0110, 0x08, 158 {0x46, 0x2a1c, 0x0407, 0x07, 0x07, 0x0e},
202 0x06, 0x00, 0x00, 0x05, 0x06}, 159 {0x47, 0x2a1d, 0x0407, 0x07, 0x07, 0x0e},
203 {0x44, 0x0a1d, 0x0306, 0x3a57, 0x0111, 0x08, 160 {0x49, 0x0a3c, 0x0508, 0x08, 0x00, 0x16},
204 0x06, 0x00, 0x00, 0x05, 0x06}, 161 {0x4a, 0x0a3d, 0x0508, 0x08, 0x00, 0x16},
205 {0x46, 0x2a1c, 0x0407, 0x3a81, 0x0113, 0x08, 162 {0x4c, 0x0e7c, 0x0609, 0x09, 0x00, 0x1e},
206 0x07, 0x00, 0x00, 0x07, 0x0e}, 163 {0x4d, 0x0e7d, 0x0609, 0x09, 0x00, 0x1e},
207 {0x47, 0x2a1d, 0x0407, 0x3a81, 0x0114, 0x08, 164 {0x50, 0x9a1b, 0x0001, 0x01, 0x04, 0x02},
208 0x07, 0x00, 0x00, 0x07, 0x0e}, 165 {0x51, 0xba1b, 0x0103, 0x03, 0x07, 0x03},
209 {0x49, 0x0a3c, 0x0508, 0x3aab, 0x0116, 0x08, 166 {0x52, 0x9a1b, 0x0204, 0x04, 0x00, 0x04},
210 0x08, 0x00, 0x00, 0x00, 0x16}, 167 {0x56, 0x9a1d, 0x0001, 0x01, 0x04, 0x02},
211 {0x4a, 0x0a3d, 0x0508, 0x3aab, 0x0117, 0x08, 168 {0x57, 0xba1d, 0x0103, 0x03, 0x07, 0x03},
212 0x08, 0x00, 0x00, 0x00, 0x16}, 169 {0x58, 0x9a1d, 0x0204, 0x04, 0x00, 0x04},
213 {0x4c, 0x0e7c, 0x0609, 0x3adc, 0x0119, 0x08, 170 {0x59, 0x9a1b, 0x0000, 0x00, 0x04, 0x00},
214 0x09, 0x00, 0x00, 0x00, 0x1e}, 171 {0x5A, 0x021b, 0x0014, 0x01, 0x04, 0x3f},
215 {0x4d, 0x0e7d, 0x0609, 0x3adc, 0x011a, 0x08, 172 {0x5B, 0x0a1d, 0x0014, 0x01, 0x04, 0x3f},
216 0x09, 0x00, 0x00, 0x00, 0x1e}, 173 {0x5d, 0x0a1d, 0x0305, 0x05, 0x07, 0x05},
217 {0x50, 0x9a1b, 0x0001, 0x3a3b, 0x0132, 0x08, 174 {0x62, 0x0a3f, 0x0306, 0x06, 0x05, 0x06},
218 0x01, 0x00, 0x00, 0x04, 0x02}, 175 {0x63, 0x2a3f, 0x0407, 0x07, 0x07, 0x0e},
219 {0x51, 0xba1b, 0x0103, 0x3a42, 0x0133, 0x08, 176 {0x64, 0x0a7f, 0x0508, 0x08, 0x00, 0x16},
220 0x03, 0x00, 0x00, 0x07, 0x03}, 177 {0x65, 0x0eff, 0x0609, 0x09, 0x00, 0x1e},
221 {0x52, 0x9a1b, 0x0204, 0x3a49, 0x0134, 0x08, 178 {0x66, 0x0eff, 0x070a, 0x0a, 0x00, 0x22}, /* mode 1600x1200
222 0x04, 0x00, 0x00, 0x00, 0x04},
223 {0x56, 0x9a1d, 0x0001, 0x3a3b, 0x0135, 0x08,
224 0x01, 0x00, 0x00, 0x04, 0x02},
225 {0x57, 0xba1d, 0x0103, 0x3a42, 0x0136, 0x08,
226 0x03, 0x00, 0x00, 0x07, 0x03},
227 {0x58, 0x9a1d, 0x0204, 0x3a49, 0x0137, 0x08,
228 0x04, 0x00, 0x00, 0x00, 0x04},
229 {0x59, 0x9a1b, 0x0000, 0x3a34, 0x0138, 0x08,
230 0x00, 0x00, 0x00, 0x04, 0x00},
231 {0x5A, 0x021b, 0x0014, 0x3b83, 0x0138, 0x08,
232 0x01, 0x00, 0x00, 0x04, 0x3f}, /* ModeIdIndex = 0x20 */
233 {0x5B, 0x0a1d, 0x0014, 0x3b83, 0x0135, 0x08,
234 0x01, 0x00, 0x00, 0x04, 0x3f},
235 {0x5d, 0x0a1d, 0x0305, 0x3a50, 0x0139, 0x08,
236 0x05, 0x00, 0x00, 0x07, 0x05},
237 {0x62, 0x0a3f, 0x0306, 0x3a57, 0x013a, 0x08,
238 0x06, 0x00, 0x00, 0x05, 0x06},
239 {0x63, 0x2a3f, 0x0407, 0x3a81, 0x013b, 0x08,
240 0x07, 0x00, 0x00, 0x07, 0x0e},
241 {0x64, 0x0a7f, 0x0508, 0x3aab, 0x013c, 0x08,
242 0x08, 0x00, 0x00, 0x00, 0x16},
243 {0x65, 0x0eff, 0x0609, 0x3adc, 0x013d, 0x08,
244 0x09, 0x00, 0x00, 0x00, 0x1e},
245 {0x66, 0x0eff, 0x070a, 0x3af2, 0x013e, 0x08,
246 0x0a, 0x00, 0x00, 0x00, 0x22}, /* mode 1600x1200
247 add CRT2MODE */ 179 add CRT2MODE */
248 {0x68, 0x067b, 0x080b, 0x3b17, 0x013f, 0x08, 180 {0x68, 0x067b, 0x080b, 0x0b, 0x00, 0x29},
249 0x0b, 0x00, 0x00, 0x00, 0x29}, 181 {0x69, 0x06fd, 0x080b, 0x0b, 0x00, 0x29},
250 {0x69, 0x06fd, 0x080b, 0x3b17, 0x0140, 0x08, 182 {0x6b, 0x07ff, 0x080b, 0x0b, 0x00, 0x29},
251 0x0b, 0x00, 0x00, 0x00, 0x29}, 183 {0x6c, 0x067b, 0x090c, 0x0c, 0x00, 0x2f},
252 {0x6b, 0x07ff, 0x080b, 0x3b17, 0x0141, 0x10, 184 {0x6d, 0x06fd, 0x090c, 0x0c, 0x00, 0x2f},
253 0x0b, 0x00, 0x00, 0x00, 0x29}, 185 {0x6e, 0x07ff, 0x090c, 0x0c, 0x00, 0x2f},
254 {0x6c, 0x067b, 0x090c, 0x3b37, 0x0000, 0x08, 186 {0x70, 0x2a1b, 0x0410, 0x10, 0x07, 0x34},
255 0x0c, 0x00, 0x00, 0x00, 0x2f}, 187 {0x71, 0x0a1b, 0x0511, 0x11, 0x00, 0x37},
256 {0x6d, 0x06fd, 0x090c, 0x3b37, 0x0000, 0x10, 188 {0x74, 0x0a1d, 0x0511, 0x11, 0x00, 0x37},
257 0x0c, 0x00, 0x00, 0x00, 0x2f}, 189 {0x75, 0x0a3d, 0x0612, 0x12, 0x00, 0x3a},
258 {0x6e, 0x07ff, 0x090c, 0x3b37, 0x0000, 0x10, 190 {0x76, 0x2a1f, 0x0410, 0x10, 0x07, 0x34},
259 0x0c, 0x00, 0x00, 0x00, 0x2f}, 191 {0x77, 0x0a1f, 0x0511, 0x11, 0x00, 0x37},
260 {0x70, 0x2a1b, 0x0410, 0x3b52, 0x0000, 0x08, 192 {0x78, 0x0a3f, 0x0612, 0x12, 0x00, 0x3a},
261 0x10, 0x00, 0x00, 0x07, 0x34}, 193 {0x79, 0x0a3b, 0x0612, 0x12, 0x00, 0x3a},
262 {0x71, 0x0a1b, 0x0511, 0x3b63, 0x0000, 0x08, 194 {0x7a, 0x2a1d, 0x0410, 0x10, 0x07, 0x34},
263 0x11, 0x00, 0x00, 0x00, 0x37}, 195 {0x7b, 0x0e3b, 0x060f, 0x0f, 0x00, 0x1d},
264 {0x74, 0x0a1d, 0x0511, 0x3b63, 0x0000, 0x08, 196 {0x7c, 0x0e7d, 0x060f, 0x0f, 0x00, 0x1d},
265 0x11, 0x00, 0x00, 0x00, 0x37}, /* ModeIdIndex = 0x30 */ 197 {0x7d, 0x0eff, 0x060f, 0x0f, 0x00, 0x1d},
266 {0x75, 0x0a3d, 0x0612, 0x3b74, 0x0000, 0x08, 198 {0x20, 0x0e3b, 0x0D16, 0x16, 0x00, 0x43},
267 0x12, 0x00, 0x00, 0x00, 0x3a}, 199 {0x21, 0x0e7d, 0x0D16, 0x16, 0x00, 0x43},
268 {0x76, 0x2a1f, 0x0410, 0x3b52, 0x0000, 0x08, 200 {0x22, 0x0eff, 0x0D16, 0x16, 0x00, 0x43},
269 0x10, 0x00, 0x00, 0x07, 0x34}, 201 {0x23, 0x0e3b, 0x0614, 0x14, 0x00, 0x41},
270 {0x77, 0x0a1f, 0x0511, 0x3b63, 0x0000, 0x08, 202 {0x24, 0x0e7d, 0x0614, 0x14, 0x00, 0x41},
271 0x11, 0x00, 0x00, 0x00, 0x37}, 203 {0x25, 0x0eff, 0x0614, 0x14, 0x00, 0x41},
272 {0x78, 0x0a3f, 0x0612, 0x3b74, 0x0000, 0x08, 204 {0x26, 0x063b, 0x0c15, 0x15, 0x00, 0x42},
273 0x12, 0x00, 0x00, 0x00, 0x3a}, 205 {0x27, 0x067d, 0x0c15, 0x15, 0x00, 0x42},
274 {0x79, 0x0a3b, 0x0612, 0x3b74, 0x0000, 0x08, 206 {0x28, 0x06ff, 0x0c15, 0x15, 0x00, 0x42},
275 0x12, 0x00, 0x00, 0x00, 0x3a}, 207 {0xff, 0x0000, 0x0000, 0x00, 0x00, 0x00}
276 {0x7a, 0x2a1d, 0x0410, 0x3b52, 0x0000, 0x08, 208};
277 0x10, 0x00, 0x00, 0x07, 0x34}, 209
278 {0x7b, 0x0e3b, 0x060f, 0x3ad0, 0x0000, 0x08, 210static struct SiS_StandTable_S XGI330_StandTable = {
279 0x0f, 0x00, 0x00, 0x00, 0x1d},
280 {0x7c, 0x0e7d, 0x060f, 0x3ad0, 0x0000, 0x08,
281 0x0f, 0x00, 0x00, 0x00, 0x1d},
282 {0x7d, 0x0eff, 0x060f, 0x3ad0, 0x0000, 0x08,
283 0x0f, 0x00, 0x00, 0x00, 0x1d},
284 {0x20, 0x0e3b, 0x0D16, 0x49e0, 0x0000, 0x08,
285 0x16, 0x00, 0x00, 0x00, 0x43},
286 {0x21, 0x0e7d, 0x0D16, 0x49e0, 0x0000, 0x08,
287 0x16, 0x00, 0x00, 0x00, 0x43},
288 {0x22, 0x0eff, 0x0D16, 0x49e0, 0x0000, 0x08,
289 0x16, 0x00, 0x00, 0x00, 0x43},
290 {0x23, 0x0e3b, 0x0614, 0x49d5, 0x0000, 0x08,
291 0x14, 0x00, 0x00, 0x00, 0x41},
292 {0x24, 0x0e7d, 0x0614, 0x49d5, 0x0000, 0x08,
293 0x14, 0x00, 0x00, 0x00, 0x41},
294 {0x25, 0x0eff, 0x0614, 0x49d5, 0x0000, 0x08,
295 0x14, 0x00, 0x00, 0x00, 0x41},
296 {0x26, 0x063b, 0x0c15, 0x49dc, 0x0000, 0x08,
297 0x15, 0x00, 0x00, 0x00, 0x42}, /* ModeIdIndex = 0x40 */
298 {0x27, 0x067d, 0x0c15, 0x49dc, 0x0000, 0x08,
299 0x15, 0x00, 0x00, 0x00, 0x42},
300 {0x28, 0x06ff, 0x0c15, 0x49dc, 0x0000, 0x08,
301 0x15, 0x00, 0x00, 0x00, 0x42},
302 {0xff, 0x0000, 0x0000, 0x0000, 0x0000, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00}
304};
305
306static struct SiS_StandTable_S XGI330_StandTable[] = {
307/* MD_0_200 */
308 {
309 0x28, 0x18, 0x08, 0x0800,
310 {0x09, 0x03, 0x00, 0x02},
311 0x63,
312 {0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f,
313 0x00, 0xc7, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
314 0x9c, 0x8e, 0x8f, 0x14, 0x1f, 0x96, 0xb9, 0xa3,
315 0xff},
316 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
317 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
318 0x08, 0x00, 0x0f, 0x00},
319 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
320 0xff}
321 },
322/* MD_1_200 */
323 {
324 0x28, 0x18, 0x08, 0x0800,
325 {0x09, 0x03, 0x00, 0x02},
326 0x63,
327 {0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f,
328 0x00, 0xc7, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
329 0x9c, 0x8e, 0x8f, 0x14, 0x1f, 0x96, 0xb9, 0xa3,
330 0xff},
331 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
332 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
333 0x08, 0x00, 0x0f, 0x00},
334 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
335 0xff}
336 },
337/* MD_2_200 */
338 {
339 0x50, 0x18, 0x08, 0x1000,
340 {0x01, 0x03, 0x00, 0x02},
341 0x63,
342 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
343 0x00, 0xc7, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
344 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
345 0xff},
346 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
347 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
348 0x08, 0x00, 0x0f, 0x00},
349 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
350 0xff}
351 },
352/* MD_3_200 */
353 {
354 0x50, 0x18, 0x08, 0x1000,
355 {0x01, 0x03, 0x00, 0x02},
356 0x63,
357 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
358 0x00, 0xc7, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
359 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
360 0xff},
361 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
362 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
363 0x08, 0x00, 0x0f, 0x00},
364 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
365 0xff}
366 },
367/* MD_4 */
368 {
369 0x28, 0x18, 0x08, 0x4000,
370 {0x09, 0x03, 0x00, 0x02},
371 0x63,
372 {0x2d, 0x27, 0x28, 0x90, 0x2c, 0x80, 0xbf, 0x1f,
373 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374 0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xa2,
375 0xff},
376 {0x00, 0x13, 0x15, 0x17, 0x02, 0x04, 0x06, 0x07,
377 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
378 0x01, 0x00, 0x03, 0x00},
379 {0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0f, 0x00,
380 0xff}
381 },
382/* MD_5 */
383 {
384 0x28, 0x18, 0x08, 0x4000,
385 {0x09, 0x03, 0x00, 0x02},
386 0x63,
387 {0x2d, 0x27, 0x28, 0x90, 0x2c, 0x80, 0xbf, 0x1f,
388 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389 0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xa2,
390 0xff},
391 {0x00, 0x13, 0x15, 0x17, 0x02, 0x04, 0x06, 0x07,
392 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
393 0x01, 0x00, 0x03, 0x00},
394 {0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0f, 0x00,
395 0xff}
396 },
397/* MD_6 */
398 {
399 0x50, 0x18, 0x08, 0x4000,
400 {0x01, 0x01, 0x00, 0x06},
401 0x63,
402 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
403 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404 0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xc2,
405 0xff},
406 {0x00, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
407 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
408 0x01, 0x00, 0x01, 0x00},
409 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00,
410 0xff}
411 },
412/* MD_7 */
413 {
414 0x50, 0x18, 0x0e, 0x1000,
415 {0x00, 0x03, 0x00, 0x03},
416 0xa6,
417 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
418 0x00, 0x4d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
419 0x83, 0x85, 0x5d, 0x28, 0x0d, 0x63, 0xba, 0xa3,
420 0xff},
421 {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
422 0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
423 0x0e, 0x00, 0x0f, 0x08},
424 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x00,
425 0xff}
426 },
427/* MDA_DAC */
428 {
429 0x00, 0x00, 0x00, 0x0000,
430 {0x00, 0x00, 0x00, 0x15},
431 0x15,
432 {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
433 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x3f, 0x3f,
434 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x00,
435 0x00},
436 {0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x15, 0x15,
437 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
438 0x15, 0x15, 0x15, 0x15},
439 {0x15, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
440 0x3f}
441 },
442/* CGA_DAC */
443 {
444 0x00, 0x10, 0x04, 0x0114,
445 {0x11, 0x09, 0x15, 0x00},
446 0x10,
447 {0x04, 0x14, 0x01, 0x11, 0x09, 0x15, 0x2a, 0x3a,
448 0x2e, 0x3e, 0x2b, 0x3b, 0x2f, 0x3f, 0x2a, 0x3a,
449 0x2e, 0x3e, 0x2b, 0x3b, 0x2f, 0x3f, 0x00, 0x10,
450 0x04},
451 {0x14, 0x01, 0x11, 0x09, 0x15, 0x00, 0x10, 0x04,
452 0x14, 0x01, 0x11, 0x09, 0x15, 0x2a, 0x3a, 0x2e,
453 0x3e, 0x2b, 0x3b, 0x2f},
454 {0x3f, 0x2a, 0x3a, 0x2e, 0x3e, 0x2b, 0x3b, 0x2f,
455 0x3f}
456 },
457/* EGA_DAC */
458 {
459 0x00, 0x10, 0x04, 0x0114,
460 {0x11, 0x05, 0x15, 0x20},
461 0x30,
462 {0x24, 0x34, 0x21, 0x31, 0x25, 0x35, 0x08, 0x18,
463 0x0c, 0x1c, 0x09, 0x19, 0x0d, 0x1d, 0x28, 0x38,
464 0x2c, 0x3c, 0x29, 0x39, 0x2d, 0x3d, 0x02, 0x12,
465 0x06},
466 {0x16, 0x03, 0x13, 0x07, 0x17, 0x22, 0x32, 0x26,
467 0x36, 0x23, 0x33, 0x27, 0x37, 0x0a, 0x1a, 0x0e,
468 0x1e, 0x0b, 0x1b, 0x0f},
469 {0x1f, 0x2a, 0x3a, 0x2e, 0x3e, 0x2b, 0x3b, 0x2f,
470 0x3f}
471 },
472/* VGA_DAC */
473 {
474 0x00, 0x10, 0x04, 0x0114,
475 {0x11, 0x09, 0x15, 0x2a},
476 0x3a,
477 {0x2e, 0x3e, 0x2b, 0x3b, 0x2f, 0x3f, 0x00, 0x05,
478 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x18, 0x1c, 0x20,
479 0x24, 0x28, 0x2d, 0x32, 0x38, 0x3f, 0x00, 0x10,
480 0x1f},
481 {0x2f, 0x3f, 0x1f, 0x27, 0x2f, 0x37, 0x3f, 0x2d,
482 0x31, 0x36, 0x3a, 0x3f, 0x00, 0x07, 0x0e, 0x15,
483 0x1c, 0x0e, 0x11, 0x15},
484 {0x18, 0x1c, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x00,
485 0x04}
486 },
487 {
488 0x08, 0x0c, 0x10, 0x0a08,
489 {0x0c, 0x0e, 0x10, 0x0b},
490 0x0c,
491 {0x0d, 0x0f, 0x10, 0x10, 0x01, 0x08, 0x00, 0x00,
492 0x00, 0x00, 0x01, 0x00, 0x02, 0x02, 0x01, 0x00,
493 0x04, 0x04, 0x01, 0x00, 0x05, 0x02, 0x05, 0x00,
494 0x06},
495 {0x01, 0x06, 0x05, 0x06, 0x00, 0x08, 0x01, 0x08,
496 0x00, 0x07, 0x02, 0x07, 0x06, 0x07, 0x00, 0x00,
497 0x00, 0x00, 0x00, 0x00},
498 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
499 0x00}
500 },
501/* MD_D */
502 {
503 0x28, 0x18, 0x08, 0x2000,
504 {0x09, 0x0f, 0x00, 0x06},
505 0x63,
506 {0x2d, 0x27, 0x28, 0x90, 0x2c, 0x80, 0xbf, 0x1f,
507 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
508 0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xe3,
509 0xff},
510 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
511 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
512 0x01, 0x00, 0x0f, 0x00},
513 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
514 0xff}
515 },
516/* MD_E */
517 {
518 0x50, 0x18, 0x08, 0x4000,
519 {0x01, 0x0f, 0x00, 0x06},
520 0x63,
521 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
522 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
523 0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xe3,
524 0xff},
525 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
526 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
527 0x01, 0x00, 0x0f, 0x00},
528 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
529 0xff}
530 },
531/* ExtVGATable */ 211/* ExtVGATable */
532 { 212 0x00, 0x00, 0x00, 0x0000,
533 0x00, 0x00, 0x00, 0x0000, 213 {0x01, 0x0f, 0x00, 0x0e},
534 {0x01, 0x0f, 0x00, 0x0e}, 214 0x23,
535 0x23, 215 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
536 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 216 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
537 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 217 0xea, 0x8c, 0xdf, 0x28, 0x40, 0xe7, 0x04, 0xa3,
538 0xea, 0x8c, 0xdf, 0x28, 0x40, 0xe7, 0x04, 0xa3, 218 0xff},
539 0xff}, 219 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
540 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 220 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
541 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 221 0x01, 0x00, 0x00, 0x00},
542 0x01, 0x00, 0x00, 0x00}, 222 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
543 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 223 0xff}
544 0xff}
545 },
546/* ROM_SAVEPTR */
547 {
548 0x9f, 0x3b, 0x00, 0x00c0,
549 {0x00, 0x00, 0x00, 0x00},
550 0x00,
551 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x3f,
552 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
553 0x00, 0x00, 0x1a, 0x00, 0xac, 0x3e, 0x00, 0xc0,
554 0x00},
555 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
556 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
557 0x00, 0x00, 0x00, 0x00},
558 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
559 0x00}
560 },
561/* MD_F */
562 {
563 0x50, 0x18, 0x0e, 0x8000,
564 {0x01, 0x0f, 0x00, 0x06},
565 0xa2,
566 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
567 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
568 0x82, 0x84, 0x5d, 0x28, 0x0f, 0x63, 0xba, 0xe3,
569 0xff},
570 {0x00, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
571 0x00, 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
572 0x0b, 0x00, 0x05, 0x00},
573 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x05,
574 0xff}
575 },
576/* MD_10 */
577 {
578 0x50, 0x18, 0x0e, 0x8000,
579 {0x01, 0x0f, 0x00, 0x06},
580 0xa3,
581 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
582 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
583 0x82, 0x84, 0x5d, 0x28, 0x0f, 0x63, 0xba, 0xe3,
584 0xff},
585 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
586 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
587 0x01, 0x00, 0x0f, 0x00},
588 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
589 0xff}
590 },
591/* MD_0_350 */
592 {
593 0x28, 0x18, 0x0e, 0x0800,
594 {0x09, 0x03, 0x00, 0x02},
595 0xa3,
596 {0x2d, 0x27, 0x28, 0x90, 0x2b, 0xb1, 0xbf, 0x1f,
597 0x00, 0x4d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
598 0x83, 0x85, 0x5d, 0x14, 0x1f, 0x63, 0xba, 0xa3,
599 0xff},
600 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
601 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
602 0x08, 0x00, 0x0f, 0x00},
603 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
604 0xff}
605 },
606/* MD_1_350 */
607 {
608 0x28, 0x18, 0x0e, 0x0800,
609 {0x09, 0x03, 0x00, 0x02},
610 0xa3,
611 {0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f,
612 0x00, 0x4d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
613 0x83, 0x85, 0x5d, 0x14, 0x1f, 0x63, 0xba, 0xa3,
614 0xff},
615 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
616 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
617 0x08, 0x00, 0x0f, 0x00},
618 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
619 0xff}
620 },
621/* MD_2_350 */
622 {
623 0x50, 0x18, 0x0e, 0x1000,
624 {0x01, 0x03, 0x00, 0x02},
625 0xa3,
626 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
627 0x00, 0x4d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
628 0x83, 0x85, 0x5d, 0x28, 0x1f, 0x63, 0xba, 0xa3,
629 0xff},
630 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
631 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
632 0x08, 0x00, 0x0f, 0x00},
633 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
634 0xff}
635 },
636/* MD_3_350 */
637 {
638 0x50, 0x18, 0x0e, 0x1000,
639 {0x01, 0x03, 0x00, 0x02},
640 0xa3,
641 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
642 0x00, 0x4d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
643 0x83, 0x85, 0x5d, 0x28, 0x1f, 0x63, 0xba, 0xa3,
644 0xff},
645 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
646 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
647 0x08, 0x00, 0x0f, 0x00},
648 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
649 0xff}
650 },
651/* MD_0_1_400 */
652 {
653 0x28, 0x18, 0x10, 0x0800,
654 {0x08, 0x03, 0x00, 0x02},
655 0x67,
656 {0x2d, 0x27, 0x28, 0x90, 0x2b, 0xb1, 0xbf, 0x1f,
657 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
658 0x9c, 0x8e, 0x8f, 0x14, 0x1f, 0x96, 0xb9, 0xa3,
659 0xff},
660 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
661 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
662 0x0c, 0x00, 0x0f, 0x08},
663 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
664 0xff}
665 },
666/* MD_2_3_400 */
667 {
668 0x50, 0x18, 0x10, 0x1000,
669 {0x00, 0x03, 0x00, 0x02},
670 0x67,
671 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
672 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
673 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
674 0xff},
675 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
676 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
677 0x0c, 0x00, 0x0f, 0x08},
678 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00,
679 0xff}
680 },
681/* MD_7_400 */
682 {
683 0x50, 0x18, 0x10, 0x1000,
684 {0x00, 0x03, 0x00, 0x02},
685 0x66,
686 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
687 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
688 0x9c, 0x8e, 0x8f, 0x28, 0x0f, 0x96, 0xb9, 0xa3,
689 0xff},
690 {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
691 0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
692 0x0e, 0x00, 0x0f, 0x08},
693 {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x00,
694 0xff}
695 },
696/* MD_11 */
697 {
698 0x50, 0x1d, 0x10, 0xa000,
699 {0x01, 0x0f, 0x00, 0x06},
700 0xe3,
701 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0x0b, 0x3e,
702 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
703 0xe9, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xc3,
704 0xff},
705 {0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
706 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
707 0x01, 0x00, 0x0f, 0x00},
708 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01,
709 0xff}
710 },
711/* ExtEGATable */
712 {
713 0x50, 0x1d, 0x10, 0xa000,
714 {0x01, 0x0f, 0x00, 0x06},
715 0xe3,
716 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0x0b, 0x3e,
717 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
718 0xe9, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
719 0xff},
720 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
721 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
722 0x01, 0x00, 0x0f, 0x00},
723 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f,
724 0xff}
725 },
726/* MD_13 */
727 {
728 0x28, 0x18, 0x08, 0x2000,
729 {0x01, 0x0f, 0x00, 0x0e},
730 0x63,
731 {0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
732 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
733 0x9c, 0x8e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
734 0xff},
735 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
736 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
737 0x41, 0x00, 0x0f, 0x00},
738 {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
739 0xff}
740 }
741}; 224};
742 225
743static struct XGI_TimingHStruct XGI_TimingH[1]; 226static struct XGI_TimingHStruct XGI_TimingH[1];
@@ -1143,7 +626,7 @@ static struct XGI330_LCDDataStruct XGI_NoScalingDatax75[] = {
1143 {1, 1, 1688, 806, 1688, 806} /* ; 0A (1280x768x75Hz) */ 626 {1, 1, 1688, 806, 1688, 806} /* ; 0A (1280x768x75Hz) */
1144}; 627};
1145 628
1146static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1024x768Data[] = { 629static struct XGI_LCDDesStruct XGI_ExtLCDDes1024x768Data[] = {
1147 {9, 1057, 0, 771}, /* ; 00 (320x200,320x400,640x200,640x400) */ 630 {9, 1057, 0, 771}, /* ; 00 (320x200,320x400,640x200,640x400) */
1148 {9, 1057, 0, 771}, /* ; 01 (320x350,640x350) */ 631 {9, 1057, 0, 771}, /* ; 01 (320x350,640x350) */
1149 {9, 1057, 0, 771}, /* ; 02 (360x400,720x400) */ 632 {9, 1057, 0, 771}, /* ; 02 (360x400,720x400) */
@@ -1153,7 +636,7 @@ static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1024x768Data[] = {
1153 {9, 1057, 805, 770} /* ; 06 (1024x768x60Hz) */ 636 {9, 1057, 805, 770} /* ; 06 (1024x768x60Hz) */
1154}; 637};
1155 638
1156static struct XGI330_LCDDataDesStruct XGI_StLCDDes1024x768Data[] = { 639static struct XGI_LCDDesStruct XGI_StLCDDes1024x768Data[] = {
1157 {9, 1057, 737, 703}, /* ; 00 (320x200,320x400,640x200,640x400) */ 640 {9, 1057, 737, 703}, /* ; 00 (320x200,320x400,640x200,640x400) */
1158 {9, 1057, 686, 651}, /* ; 01 (320x350,640x350) */ 641 {9, 1057, 686, 651}, /* ; 01 (320x350,640x350) */
1159 {9, 1057, 737, 703}, /* ; 02 (360x400,720x400) */ 642 {9, 1057, 737, 703}, /* ; 02 (360x400,720x400) */
@@ -1163,7 +646,7 @@ static struct XGI330_LCDDataDesStruct XGI_StLCDDes1024x768Data[] = {
1163 {9, 1057, 805, 770} /* ; 06 (1024x768x60Hz) */ 646 {9, 1057, 805, 770} /* ; 06 (1024x768x60Hz) */
1164}; 647};
1165 648
1166static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1024x768Data[] = { 649static struct XGI_LCDDesStruct XGI_CetLCDDes1024x768Data[] = {
1167 {1152, 856, 622, 587}, /* ; 00 (320x200,320x400,640x200,640x400) */ 650 {1152, 856, 622, 587}, /* ; 00 (320x200,320x400,640x200,640x400) */
1168 {1152, 856, 597, 562}, /* ; 01 (320x350,640x350) */ 651 {1152, 856, 597, 562}, /* ; 01 (320x350,640x350) */
1169 {1152, 856, 622, 587}, /* ; 02 (360x400,720x400) */ 652 {1152, 856, 622, 587}, /* ; 02 (360x400,720x400) */
@@ -1173,7 +656,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1024x768Data[] = {
1173 {0, 1048, 805, 770} /* ; 06 (1024x768x60Hz) */ 656 {0, 1048, 805, 770} /* ; 06 (1024x768x60Hz) */
1174}; 657};
1175 658
1176static struct XGI330_LCDDataDesStruct XGI_ExtLCDDLDes1280x1024Data[] = { 659static struct XGI_LCDDesStruct XGI_ExtLCDDLDes1280x1024Data[] = {
1177 {18, 1346, 981, 940}, /* 00 (320x200,320x400,640x200,640x400) */ 660 {18, 1346, 981, 940}, /* 00 (320x200,320x400,640x200,640x400) */
1178 {18, 1346, 926, 865}, /* 01 (320x350,640x350) */ 661 {18, 1346, 926, 865}, /* 01 (320x350,640x350) */
1179 {18, 1346, 981, 940}, /* 02 (360x400,720x400) */ 662 {18, 1346, 981, 940}, /* 02 (360x400,720x400) */
@@ -1184,7 +667,7 @@ static struct XGI330_LCDDataDesStruct XGI_ExtLCDDLDes1280x1024Data[] = {
1184 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */ 667 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */
1185}; 668};
1186 669
1187static struct XGI330_LCDDataDesStruct XGI_StLCDDLDes1280x1024Data[] = { 670static struct XGI_LCDDesStruct XGI_StLCDDLDes1280x1024Data[] = {
1188 {18, 1346, 970, 907}, /* 00 (320x200,320x400,640x200,640x400) */ 671 {18, 1346, 970, 907}, /* 00 (320x200,320x400,640x200,640x400) */
1189 {18, 1346, 917, 854}, /* 01 (320x350,640x350) */ 672 {18, 1346, 917, 854}, /* 01 (320x350,640x350) */
1190 {18, 1346, 970, 907}, /* 02 (360x400,720x400) */ 673 {18, 1346, 970, 907}, /* 02 (360x400,720x400) */
@@ -1195,7 +678,7 @@ static struct XGI330_LCDDataDesStruct XGI_StLCDDLDes1280x1024Data[] = {
1195 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */ 678 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */
1196}; 679};
1197 680
1198static struct XGI330_LCDDataDesStruct XGI_CetLCDDLDes1280x1024Data[] = { 681static struct XGI_LCDDesStruct XGI_CetLCDDLDes1280x1024Data[] = {
1199 {1368, 1008, 752, 711}, /* 00 (320x200,320x400,640x200,640x400) */ 682 {1368, 1008, 752, 711}, /* 00 (320x200,320x400,640x200,640x400) */
1200 {1368, 1008, 729, 688}, /* 01 (320x350,640x350) */ 683 {1368, 1008, 729, 688}, /* 01 (320x350,640x350) */
1201 {1368, 1008, 752, 711}, /* 02 (360x400,720x400) */ 684 {1368, 1008, 752, 711}, /* 02 (360x400,720x400) */
@@ -1206,7 +689,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDLDes1280x1024Data[] = {
1206 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */ 689 {18, 1346, 1065, 1024} /* 07 (1280x1024x60Hz) */
1207}; 690};
1208 691
1209static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1280x1024Data[] = { 692static struct XGI_LCDDesStruct XGI_ExtLCDDes1280x1024Data[] = {
1210 {9, 1337, 981, 940}, /* ; 00 (320x200,320x400,640x200,640x400) */ 693 {9, 1337, 981, 940}, /* ; 00 (320x200,320x400,640x200,640x400) */
1211 {9, 1337, 926, 884}, /* ; 01 (320x350,640x350) alan, 2003/09/30 */ 694 {9, 1337, 926, 884}, /* ; 01 (320x350,640x350) alan, 2003/09/30 */
1212 {9, 1337, 981, 940}, /* ; 02 (360x400,720x400) */ 695 {9, 1337, 981, 940}, /* ; 02 (360x400,720x400) */
@@ -1217,7 +700,7 @@ static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1280x1024Data[] = {
1217 {9, 1337, 1065, 1024} /* ; 07 (1280x1024x60Hz) */ 700 {9, 1337, 1065, 1024} /* ; 07 (1280x1024x60Hz) */
1218}; 701};
1219 702
1220static struct XGI330_LCDDataDesStruct XGI_StLCDDes1280x1024Data[] = { 703static struct XGI_LCDDesStruct XGI_StLCDDes1280x1024Data[] = {
1221 {9, 1337, 970, 907}, /* ; 00 (320x200,320x400,640x200,640x400) */ 704 {9, 1337, 970, 907}, /* ; 00 (320x200,320x400,640x200,640x400) */
1222 {9, 1337, 917, 854}, /* ; 01 (320x350,640x350) */ 705 {9, 1337, 917, 854}, /* ; 01 (320x350,640x350) */
1223 {9, 1337, 970, 907}, /* ; 02 (360x400,720x400) */ 706 {9, 1337, 970, 907}, /* ; 02 (360x400,720x400) */
@@ -1228,7 +711,7 @@ static struct XGI330_LCDDataDesStruct XGI_StLCDDes1280x1024Data[] = {
1228 {9, 1337, 1065, 1024} /* ; 07 (1280x1024x60Hz) */ 711 {9, 1337, 1065, 1024} /* ; 07 (1280x1024x60Hz) */
1229}; 712};
1230 713
1231static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1280x1024Data[] = { 714static struct XGI_LCDDesStruct XGI_CetLCDDes1280x1024Data[] = {
1232 {1368, 1008, 752, 711}, /* 00 (320x200,320x400,640x200,640x400) */ 715 {1368, 1008, 752, 711}, /* 00 (320x200,320x400,640x200,640x400) */
1233 {1368, 1008, 729, 688}, /* 01 (320x350,640x350) */ 716 {1368, 1008, 729, 688}, /* 01 (320x350,640x350) */
1234 {1368, 1008, 752, 711}, /* 02 (360x400,720x400) */ 717 {1368, 1008, 752, 711}, /* 02 (360x400,720x400) */
@@ -1239,7 +722,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1280x1024Data[] = {
1239 {9, 1337, 1065, 1024} /* 07 (1280x1024x60Hz) */ 722 {9, 1337, 1065, 1024} /* 07 (1280x1024x60Hz) */
1240}; 723};
1241 724
1242static struct XGI330_LCDDataDesStruct xgifb_lcddldes_1400x1050[] = { 725static struct XGI_LCDDesStruct xgifb_lcddldes_1400x1050[] = {
1243 {18, 1464, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */ 726 {18, 1464, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */
1244 {18, 1464, 0, 1051}, /* 01 (320x350,640x350) */ 727 {18, 1464, 0, 1051}, /* 01 (320x350,640x350) */
1245 {18, 1464, 0, 1051}, /* 02 (360x400,720x400) */ 728 {18, 1464, 0, 1051}, /* 02 (360x400,720x400) */
@@ -1251,7 +734,7 @@ static struct XGI330_LCDDataDesStruct xgifb_lcddldes_1400x1050[] = {
1251 {18, 1464, 0, 1051} /* 08 (1400x1050x60Hz) */ 734 {18, 1464, 0, 1051} /* 08 (1400x1050x60Hz) */
1252}; 735};
1253 736
1254static struct XGI330_LCDDataDesStruct xgifb_lcddes_1400x1050[] = { 737static struct XGI_LCDDesStruct xgifb_lcddes_1400x1050[] = {
1255 {9, 1455, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */ 738 {9, 1455, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */
1256 {9, 1455, 0, 1051}, /* 01 (320x350,640x350) */ 739 {9, 1455, 0, 1051}, /* 01 (320x350,640x350) */
1257 {9, 1455, 0, 1051}, /* 02 (360x400,720x400) */ 740 {9, 1455, 0, 1051}, /* 02 (360x400,720x400) */
@@ -1263,7 +746,7 @@ static struct XGI330_LCDDataDesStruct xgifb_lcddes_1400x1050[] = {
1263 {9, 1455, 0, 1051} /* 08 (1400x1050x60Hz) */ 746 {9, 1455, 0, 1051} /* 08 (1400x1050x60Hz) */
1264}; 747};
1265 748
1266static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1400x1050Data[] = { 749static struct XGI_LCDDesStruct XGI_CetLCDDes1400x1050Data[] = {
1267 {1308, 1068, 781, 766}, /* 00 (320x200,320x400,640x200,640x400) */ 750 {1308, 1068, 781, 766}, /* 00 (320x200,320x400,640x200,640x400) */
1268 {1308, 1068, 781, 766}, /* 01 (320x350,640x350) */ 751 {1308, 1068, 781, 766}, /* 01 (320x350,640x350) */
1269 {1308, 1068, 781, 766}, /* 02 (360x400,720x400) */ 752 {1308, 1068, 781, 766}, /* 02 (360x400,720x400) */
@@ -1275,7 +758,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1400x1050Data[] = {
1275 {18, 1464, 0, 1051} /* 08 (1400x1050x60Hz) */ 758 {18, 1464, 0, 1051} /* 08 (1400x1050x60Hz) */
1276}; 759};
1277 760
1278static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1400x1050Data2[] = { 761static struct XGI_LCDDesStruct XGI_CetLCDDes1400x1050Data2[] = {
1279 {0, 1448, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */ 762 {0, 1448, 0, 1051}, /* 00 (320x200,320x400,640x200,640x400) */
1280 {0, 1448, 0, 1051}, /* 01 (320x350,640x350) */ 763 {0, 1448, 0, 1051}, /* 01 (320x350,640x350) */
1281 {0, 1448, 0, 1051}, /* 02 (360x400,720x400) */ 764 {0, 1448, 0, 1051}, /* 02 (360x400,720x400) */
@@ -1283,7 +766,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1400x1050Data2[] = {
1283 {0, 1448, 0, 1051} /* 04 (640x480x60Hz) */ 766 {0, 1448, 0, 1051} /* 04 (640x480x60Hz) */
1284}; 767};
1285 768
1286static struct XGI330_LCDDataDesStruct XGI_ExtLCDDLDes1600x1200Data[] = { 769static struct XGI_LCDDesStruct XGI_ExtLCDDLDes1600x1200Data[] = {
1287 {18, 1682, 0, 1201}, /* 00 (320x200,320x400,640x200,640x400) */ 770 {18, 1682, 0, 1201}, /* 00 (320x200,320x400,640x200,640x400) */
1288 {18, 1682, 0, 1201}, /* 01 (320x350,640x350) */ 771 {18, 1682, 0, 1201}, /* 01 (320x350,640x350) */
1289 {18, 1682, 0, 1201}, /* 02 (360x400,720x400) */ 772 {18, 1682, 0, 1201}, /* 02 (360x400,720x400) */
@@ -1296,7 +779,7 @@ static struct XGI330_LCDDataDesStruct XGI_ExtLCDDLDes1600x1200Data[] = {
1296 {18, 1682, 0, 1201} /* 09 (1600x1200x60Hz) */ 779 {18, 1682, 0, 1201} /* 09 (1600x1200x60Hz) */
1297}; 780};
1298 781
1299static struct XGI330_LCDDataDesStruct XGI_StLCDDLDes1600x1200Data[] = { 782static struct XGI_LCDDesStruct XGI_StLCDDLDes1600x1200Data[] = {
1300 {18, 1682, 1150, 1101}, /* 00 (320x200,320x400,640x200,640x400) */ 783 {18, 1682, 1150, 1101}, /* 00 (320x200,320x400,640x200,640x400) */
1301 {18, 1682, 1083, 1034}, /* 01 (320x350,640x350) */ 784 {18, 1682, 1083, 1034}, /* 01 (320x350,640x350) */
1302 {18, 1682, 1150, 1101}, /* 02 (360x400,720x400) */ 785 {18, 1682, 1150, 1101}, /* 02 (360x400,720x400) */
@@ -1309,7 +792,7 @@ static struct XGI330_LCDDataDesStruct XGI_StLCDDLDes1600x1200Data[] = {
1309 {18, 1682, 0, 1201} /* 09 (1600x1200x60Hz) */ 792 {18, 1682, 0, 1201} /* 09 (1600x1200x60Hz) */
1310}; 793};
1311 794
1312static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1600x1200Data[] = { 795static struct XGI_LCDDesStruct XGI_ExtLCDDes1600x1200Data[] = {
1313 {9, 1673, 0, 1201}, /* 00 (320x200,320x400,640x200,640x400) */ 796 {9, 1673, 0, 1201}, /* 00 (320x200,320x400,640x200,640x400) */
1314 {9, 1673, 0, 1201}, /* 01 (320x350,640x350) */ 797 {9, 1673, 0, 1201}, /* 01 (320x350,640x350) */
1315 {9, 1673, 0, 1201}, /* 02 (360x400,720x400) */ 798 {9, 1673, 0, 1201}, /* 02 (360x400,720x400) */
@@ -1322,7 +805,7 @@ static struct XGI330_LCDDataDesStruct XGI_ExtLCDDes1600x1200Data[] = {
1322 {9, 1673, 0, 1201} /* 09 (1600x1200x60Hz) */ 805 {9, 1673, 0, 1201} /* 09 (1600x1200x60Hz) */
1323}; 806};
1324 807
1325static struct XGI330_LCDDataDesStruct XGI_StLCDDes1600x1200Data[] = { 808static struct XGI_LCDDesStruct XGI_StLCDDes1600x1200Data[] = {
1326 {9, 1673, 1150, 1101}, /* 00 (320x200,320x400,640x200,640x400) */ 809 {9, 1673, 1150, 1101}, /* 00 (320x200,320x400,640x200,640x400) */
1327 {9, 1673, 1083, 1034}, /* 01 (320x350,640x350) */ 810 {9, 1673, 1083, 1034}, /* 01 (320x350,640x350) */
1328 {9, 1673, 1150, 1101}, /* 02 (360x400,720x400) */ 811 {9, 1673, 1150, 1101}, /* 02 (360x400,720x400) */
@@ -1352,7 +835,7 @@ static struct XGI330_LCDDataDesStruct2 XGI_NoScalingDesData[] = {
1352}; 835};
1353 836
1354/* ;;1024x768x75Hz */ 837/* ;;1024x768x75Hz */
1355static struct XGI330_LCDDataDesStruct xgifb_lcddes_1024x768x75[] = { 838static struct XGI_LCDDesStruct xgifb_lcddes_1024x768x75[] = {
1356 {9, 1049, 0, 769}, /* ; 00 (320x200,320x400,640x200,640x400) */ 839 {9, 1049, 0, 769}, /* ; 00 (320x200,320x400,640x200,640x400) */
1357 {9, 1049, 0, 769}, /* ; 01 (320x350,640x350) */ 840 {9, 1049, 0, 769}, /* ; 01 (320x350,640x350) */
1358 {9, 1049, 0, 769}, /* ; 02 (360x400,720x400) */ 841 {9, 1049, 0, 769}, /* ; 02 (360x400,720x400) */
@@ -1363,7 +846,7 @@ static struct XGI330_LCDDataDesStruct xgifb_lcddes_1024x768x75[] = {
1363}; 846};
1364 847
1365/* ;;1024x768x75Hz */ 848/* ;;1024x768x75Hz */
1366static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1024x768x75Data[] = { 849static struct XGI_LCDDesStruct XGI_CetLCDDes1024x768x75Data[] = {
1367 {1152, 856, 622, 587}, /* ; 00 (320x200,320x400,640x200,640x400) */ 850 {1152, 856, 622, 587}, /* ; 00 (320x200,320x400,640x200,640x400) */
1368 {1152, 856, 597, 562}, /* ; 01 (320x350,640x350) */ 851 {1152, 856, 597, 562}, /* ; 01 (320x350,640x350) */
1369 {1192, 896, 622, 587}, /* ; 02 (360x400,720x400) */ 852 {1192, 896, 622, 587}, /* ; 02 (360x400,720x400) */
@@ -1374,7 +857,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1024x768x75Data[] = {
1374}; 857};
1375 858
1376/* ;;1280x1024x75Hz */ 859/* ;;1280x1024x75Hz */
1377static struct XGI330_LCDDataDesStruct xgifb_lcddldes_1280x1024x75[] = { 860static struct XGI_LCDDesStruct xgifb_lcddldes_1280x1024x75[] = {
1378 {18, 1314, 0, 1025}, /* ; 00 (320x200,320x400,640x200,640x400) */ 861 {18, 1314, 0, 1025}, /* ; 00 (320x200,320x400,640x200,640x400) */
1379 {18, 1314, 0, 1025}, /* ; 01 (320x350,640x350) */ 862 {18, 1314, 0, 1025}, /* ; 01 (320x350,640x350) */
1380 {18, 1314, 0, 1025}, /* ; 02 (360x400,720x400) */ 863 {18, 1314, 0, 1025}, /* ; 02 (360x400,720x400) */
@@ -1386,7 +869,7 @@ static struct XGI330_LCDDataDesStruct xgifb_lcddldes_1280x1024x75[] = {
1386}; 869};
1387 870
1388/* 1280x1024x75Hz */ 871/* 1280x1024x75Hz */
1389static struct XGI330_LCDDataDesStruct XGI_CetLCDDLDes1280x1024x75Data[] = { 872static struct XGI_LCDDesStruct XGI_CetLCDDLDes1280x1024x75Data[] = {
1390 {1368, 1008, 752, 711}, /* ; 00 (320x200,320x400,640x200,640x400) */ 873 {1368, 1008, 752, 711}, /* ; 00 (320x200,320x400,640x200,640x400) */
1391 {1368, 1008, 729, 688}, /* ; 01 (320x350,640x350) */ 874 {1368, 1008, 729, 688}, /* ; 01 (320x350,640x350) */
1392 {1408, 1048, 752, 711}, /* ; 02 (360x400,720x400) */ 875 {1408, 1048, 752, 711}, /* ; 02 (360x400,720x400) */
@@ -1398,7 +881,7 @@ static struct XGI330_LCDDataDesStruct XGI_CetLCDDLDes1280x1024x75Data[] = {
1398}; 881};
1399 882
1400/* ;;1280x1024x75Hz */ 883/* ;;1280x1024x75Hz */
1401static struct XGI330_LCDDataDesStruct xgifb_lcddes_1280x1024x75[] = { 884static struct XGI_LCDDesStruct xgifb_lcddes_1280x1024x75[] = {
1402 {9, 1305, 0, 1025}, /* ; 00 (320x200,320x400,640x200,640x400) */ 885 {9, 1305, 0, 1025}, /* ; 00 (320x200,320x400,640x200,640x400) */
1403 {9, 1305, 0, 1025}, /* ; 01 (320x350,640x350) */ 886 {9, 1305, 0, 1025}, /* ; 01 (320x350,640x350) */
1404 {9, 1305, 0, 1025}, /* ; 02 (360x400,720x400) */ 887 {9, 1305, 0, 1025}, /* ; 02 (360x400,720x400) */
@@ -1410,7 +893,7 @@ static struct XGI330_LCDDataDesStruct xgifb_lcddes_1280x1024x75[] = {
1410}; 893};
1411 894
1412/* 1280x1024x75Hz */ 895/* 1280x1024x75Hz */
1413static struct XGI330_LCDDataDesStruct XGI_CetLCDDes1280x1024x75Data[] = { 896static struct XGI_LCDDesStruct XGI_CetLCDDes1280x1024x75Data[] = {
1414 {1368, 1008, 752, 711}, /* ; 00 (320x200,320x400,640x200,640x400) */ 897 {1368, 1008, 752, 711}, /* ; 00 (320x200,320x400,640x200,640x400) */
1415 {1368, 1008, 729, 688}, /* ; 01 (320x350,640x350) */ 898 {1368, 1008, 729, 688}, /* ; 01 (320x350,640x350) */
1416 {1408, 1048, 752, 711}, /* ; 02 (360x400,720x400) */ 899 {1408, 1048, 752, 711}, /* ; 02 (360x400,720x400) */
diff --git a/drivers/staging/xgifb/vgatypes.h b/drivers/staging/xgifb/vgatypes.h
index a7208e315815..30cdd1af81f1 100644
--- a/drivers/staging/xgifb/vgatypes.h
+++ b/drivers/staging/xgifb/vgatypes.h
@@ -66,8 +66,6 @@ struct xgi_hw_device_info {
66 unsigned long ulVideoMemorySize; /* size, in bytes, of the 66 unsigned long ulVideoMemorySize; /* size, in bytes, of the
67 memory on the board */ 67 memory on the board */
68 68
69 unsigned char *pjIOAddress; /* base I/O address of VGA ports (0x3B0) */
70
71 unsigned char jChipType; /* Used to Identify Graphics Chip */ 69 unsigned char jChipType; /* Used to Identify Graphics Chip */
72 /* defined in the data structure type */ 70 /* defined in the data structure type */
73 /* "XGI_CHIP_TYPE" */ 71 /* "XGI_CHIP_TYPE" */
diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 917461c66014..449673773286 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -45,12 +45,12 @@ static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
45 45
46static int is_first_page(struct page *page) 46static int is_first_page(struct page *page)
47{ 47{
48 return test_bit(PG_private, &page->flags); 48 return PagePrivate(page);
49} 49}
50 50
51static int is_last_page(struct page *page) 51static int is_last_page(struct page *page)
52{ 52{
53 return test_bit(PG_private_2, &page->flags); 53 return PagePrivate2(page);
54} 54}
55 55
56static void get_zspage_mapping(struct page *page, unsigned int *class_idx, 56static void get_zspage_mapping(struct page *page, unsigned int *class_idx,
@@ -180,7 +180,7 @@ out:
180 * link together 3 PAGE_SIZE sized pages to form a zspage 180 * link together 3 PAGE_SIZE sized pages to form a zspage
181 * since then we can perfectly fit in 8 such objects. 181 * since then we can perfectly fit in 8 such objects.
182 */ 182 */
183static int get_zspage_order(int class_size) 183static int get_pages_per_zspage(int class_size)
184{ 184{
185 int i, max_usedpc = 0; 185 int i, max_usedpc = 0;
186 /* zspage order which gives maximum used size per KB */ 186 /* zspage order which gives maximum used size per KB */
@@ -368,7 +368,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
368 * identify the last page. 368 * identify the last page.
369 */ 369 */
370 error = -ENOMEM; 370 error = -ENOMEM;
371 for (i = 0; i < class->zspage_order; i++) { 371 for (i = 0; i < class->pages_per_zspage; i++) {
372 struct page *page, *prev_page; 372 struct page *page, *prev_page;
373 373
374 page = alloc_page(flags); 374 page = alloc_page(flags);
@@ -377,7 +377,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
377 377
378 INIT_LIST_HEAD(&page->lru); 378 INIT_LIST_HEAD(&page->lru);
379 if (i == 0) { /* first page */ 379 if (i == 0) { /* first page */
380 set_bit(PG_private, &page->flags); 380 SetPagePrivate(page);
381 set_page_private(page, 0); 381 set_page_private(page, 0);
382 first_page = page; 382 first_page = page;
383 first_page->inuse = 0; 383 first_page->inuse = 0;
@@ -388,9 +388,8 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
388 page->first_page = first_page; 388 page->first_page = first_page;
389 if (i >= 2) 389 if (i >= 2)
390 list_add(&page->lru, &prev_page->lru); 390 list_add(&page->lru, &prev_page->lru);
391 if (i == class->zspage_order - 1) /* last page */ 391 if (i == class->pages_per_zspage - 1) /* last page */
392 set_bit(PG_private_2, &page->flags); 392 SetPagePrivate2(page);
393
394 prev_page = page; 393 prev_page = page;
395 } 394 }
396 395
@@ -398,7 +397,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
398 397
399 first_page->freelist = obj_location_to_handle(first_page, 0); 398 first_page->freelist = obj_location_to_handle(first_page, 0);
400 /* Maximum number of objects we can store in this zspage */ 399 /* Maximum number of objects we can store in this zspage */
401 first_page->objects = class->zspage_order * PAGE_SIZE / class->size; 400 first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
402 401
403 error = 0; /* Success */ 402 error = 0; /* Success */
404 403
@@ -513,7 +512,7 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
513 class->size = size; 512 class->size = size;
514 class->index = i; 513 class->index = i;
515 spin_lock_init(&class->lock); 514 spin_lock_init(&class->lock);
516 class->zspage_order = get_zspage_order(size); 515 class->pages_per_zspage = get_pages_per_zspage(size);
517 516
518 } 517 }
519 518
@@ -567,13 +566,9 @@ EXPORT_SYMBOL_GPL(zs_destroy_pool);
567 * zs_malloc - Allocate block of given size from pool. 566 * zs_malloc - Allocate block of given size from pool.
568 * @pool: pool to allocate from 567 * @pool: pool to allocate from
569 * @size: size of block to allocate 568 * @size: size of block to allocate
570 * @page: page no. that holds the object
571 * @offset: location of object within page
572 *
573 * On success, <page, offset> identifies block allocated
574 * and 0 is returned. On failure, <page, offset> is set to
575 * 0 and -ENOMEM is returned.
576 * 569 *
570 * On success, handle to the allocated object is returned,
571 * otherwise NULL.
577 * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail. 572 * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.
578 */ 573 */
579void *zs_malloc(struct zs_pool *pool, size_t size) 574void *zs_malloc(struct zs_pool *pool, size_t size)
@@ -604,7 +599,7 @@ void *zs_malloc(struct zs_pool *pool, size_t size)
604 599
605 set_zspage_mapping(first_page, class->index, ZS_EMPTY); 600 set_zspage_mapping(first_page, class->index, ZS_EMPTY);
606 spin_lock(&class->lock); 601 spin_lock(&class->lock);
607 class->pages_allocated += class->zspage_order; 602 class->pages_allocated += class->pages_per_zspage;
608 } 603 }
609 604
610 obj = first_page->freelist; 605 obj = first_page->freelist;
@@ -659,7 +654,7 @@ void zs_free(struct zs_pool *pool, void *obj)
659 fullness = fix_fullness_group(pool, first_page); 654 fullness = fix_fullness_group(pool, first_page);
660 655
661 if (fullness == ZS_EMPTY) 656 if (fullness == ZS_EMPTY)
662 class->pages_allocated -= class->zspage_order; 657 class->pages_allocated -= class->pages_per_zspage;
663 658
664 spin_unlock(&class->lock); 659 spin_unlock(&class->lock);
665 660
@@ -668,6 +663,15 @@ void zs_free(struct zs_pool *pool, void *obj)
668} 663}
669EXPORT_SYMBOL_GPL(zs_free); 664EXPORT_SYMBOL_GPL(zs_free);
670 665
666/**
667 * zs_map_object - get address of allocated object from handle.
668 * @pool: pool from which the object was allocated
669 * @handle: handle returned from zs_malloc
670 *
671 * Before using an object allocated from zs_malloc, it must be mapped using
672 * this function. When done with the object, it must be unmapped using
673 * zs_unmap_object
674*/
671void *zs_map_object(struct zs_pool *pool, void *handle) 675void *zs_map_object(struct zs_pool *pool, void *handle)
672{ 676{
673 struct page *page; 677 struct page *page;
diff --git a/drivers/staging/zsmalloc/zsmalloc_int.h b/drivers/staging/zsmalloc/zsmalloc_int.h
index 92eefc663afc..6fd32a9e0315 100644
--- a/drivers/staging/zsmalloc/zsmalloc_int.h
+++ b/drivers/staging/zsmalloc/zsmalloc_int.h
@@ -124,7 +124,7 @@ struct size_class {
124 unsigned int index; 124 unsigned int index;
125 125
126 /* Number of PAGE_SIZE sized pages to combine to form a 'zspage' */ 126 /* Number of PAGE_SIZE sized pages to combine to form a 'zspage' */
127 int zspage_order; 127 int pages_per_zspage;
128 128
129 spinlock_t lock; 129 spinlock_t lock;
130 130
diff --git a/drivers/staging/vme/Kconfig b/drivers/vme/Kconfig
index 6411ae51ed3f..c5c22465a805 100644
--- a/drivers/staging/vme/Kconfig
+++ b/drivers/vme/Kconfig
@@ -10,10 +10,10 @@ menuconfig VME_BUS
10 10
11if VME_BUS 11if VME_BUS
12 12
13source "drivers/staging/vme/bridges/Kconfig" 13source "drivers/vme/bridges/Kconfig"
14 14
15source "drivers/staging/vme/devices/Kconfig" 15source "drivers/vme/boards/Kconfig"
16 16
17source "drivers/staging/vme/boards/Kconfig" 17source "drivers/staging/vme/devices/Kconfig"
18 18
19endif # VME 19endif # VME
diff --git a/drivers/vme/Makefile b/drivers/vme/Makefile
new file mode 100644
index 000000000000..d7bfcb9fd5a1
--- /dev/null
+++ b/drivers/vme/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the VME bridge device drivers.
3#
4obj-$(CONFIG_VME_BUS) += vme.o
5
6obj-y += bridges/
7obj-y += boards/
diff --git a/drivers/staging/vme/boards/Kconfig b/drivers/vme/boards/Kconfig
index 761631353527..761631353527 100644
--- a/drivers/staging/vme/boards/Kconfig
+++ b/drivers/vme/boards/Kconfig
diff --git a/drivers/staging/vme/boards/Makefile b/drivers/vme/boards/Makefile
index 43658340885d..43658340885d 100644
--- a/drivers/staging/vme/boards/Makefile
+++ b/drivers/vme/boards/Makefile
diff --git a/drivers/staging/vme/boards/vme_vmivme7805.c b/drivers/vme/boards/vme_vmivme7805.c
index 8e05bb4e135a..8e05bb4e135a 100644
--- a/drivers/staging/vme/boards/vme_vmivme7805.c
+++ b/drivers/vme/boards/vme_vmivme7805.c
diff --git a/drivers/staging/vme/boards/vme_vmivme7805.h b/drivers/vme/boards/vme_vmivme7805.h
index 44c2c449808c..44c2c449808c 100644
--- a/drivers/staging/vme/boards/vme_vmivme7805.h
+++ b/drivers/vme/boards/vme_vmivme7805.h
diff --git a/drivers/staging/vme/bridges/Kconfig b/drivers/vme/bridges/Kconfig
index 9331064e0476..9331064e0476 100644
--- a/drivers/staging/vme/bridges/Kconfig
+++ b/drivers/vme/bridges/Kconfig
diff --git a/drivers/staging/vme/bridges/Makefile b/drivers/vme/bridges/Makefile
index 59638afcd502..59638afcd502 100644
--- a/drivers/staging/vme/bridges/Makefile
+++ b/drivers/vme/bridges/Makefile
diff --git a/drivers/staging/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c
index 515b8b8e32a8..e0df92ec44bd 100644
--- a/drivers/staging/vme/bridges/vme_ca91cx42.c
+++ b/drivers/vme/bridges/vme_ca91cx42.c
@@ -29,8 +29,8 @@
29#include <linux/time.h> 29#include <linux/time.h>
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/uaccess.h> 31#include <linux/uaccess.h>
32#include <linux/vme.h>
32 33
33#include "../vme.h"
34#include "../vme_bridge.h" 34#include "../vme_bridge.h"
35#include "vme_ca91cx42.h" 35#include "vme_ca91cx42.h"
36 36
@@ -1501,7 +1501,7 @@ static int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge)
1501 1501
1502} 1502}
1503 1503
1504void *ca91cx42_alloc_consistent(struct device *parent, size_t size, 1504static void *ca91cx42_alloc_consistent(struct device *parent, size_t size,
1505 dma_addr_t *dma) 1505 dma_addr_t *dma)
1506{ 1506{
1507 struct pci_dev *pdev; 1507 struct pci_dev *pdev;
@@ -1512,8 +1512,8 @@ void *ca91cx42_alloc_consistent(struct device *parent, size_t size,
1512 return pci_alloc_consistent(pdev, size, dma); 1512 return pci_alloc_consistent(pdev, size, dma);
1513} 1513}
1514 1514
1515void ca91cx42_free_consistent(struct device *parent, size_t size, void *vaddr, 1515static void ca91cx42_free_consistent(struct device *parent, size_t size,
1516 dma_addr_t dma) 1516 void *vaddr, dma_addr_t dma)
1517{ 1517{
1518 struct pci_dev *pdev; 1518 struct pci_dev *pdev;
1519 1519
diff --git a/drivers/staging/vme/bridges/vme_ca91cx42.h b/drivers/vme/bridges/vme_ca91cx42.h
index 02a7c794db05..02a7c794db05 100644
--- a/drivers/staging/vme/bridges/vme_ca91cx42.h
+++ b/drivers/vme/bridges/vme_ca91cx42.h
diff --git a/drivers/staging/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c
index f50582169b24..f6385f7a66d9 100644
--- a/drivers/staging/vme/bridges/vme_tsi148.c
+++ b/drivers/vme/bridges/vme_tsi148.c
@@ -29,8 +29,9 @@
29#include <linux/time.h> 29#include <linux/time.h>
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/uaccess.h> 31#include <linux/uaccess.h>
32#include <linux/byteorder/generic.h>
33#include <linux/vme.h>
32 34
33#include "../vme.h"
34#include "../vme_bridge.h" 35#include "../vme_bridge.h"
35#include "vme_tsi148.h" 36#include "vme_tsi148.h"
36 37
@@ -1415,51 +1416,55 @@ static unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1415 return result; 1416 return result;
1416} 1417}
1417 1418
1418static int tsi148_dma_set_vme_src_attributes(struct device *dev, u32 *attr, 1419static int tsi148_dma_set_vme_src_attributes(struct device *dev, __be32 *attr,
1419 u32 aspace, u32 cycle, u32 dwidth) 1420 u32 aspace, u32 cycle, u32 dwidth)
1420{ 1421{
1422 u32 val;
1423
1424 val = be32_to_cpu(*attr);
1425
1421 /* Setup 2eSST speeds */ 1426 /* Setup 2eSST speeds */
1422 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { 1427 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1423 case VME_2eSST160: 1428 case VME_2eSST160:
1424 *attr |= TSI148_LCSR_DSAT_2eSSTM_160; 1429 val |= TSI148_LCSR_DSAT_2eSSTM_160;
1425 break; 1430 break;
1426 case VME_2eSST267: 1431 case VME_2eSST267:
1427 *attr |= TSI148_LCSR_DSAT_2eSSTM_267; 1432 val |= TSI148_LCSR_DSAT_2eSSTM_267;
1428 break; 1433 break;
1429 case VME_2eSST320: 1434 case VME_2eSST320:
1430 *attr |= TSI148_LCSR_DSAT_2eSSTM_320; 1435 val |= TSI148_LCSR_DSAT_2eSSTM_320;
1431 break; 1436 break;
1432 } 1437 }
1433 1438
1434 /* Setup cycle types */ 1439 /* Setup cycle types */
1435 if (cycle & VME_SCT) 1440 if (cycle & VME_SCT)
1436 *attr |= TSI148_LCSR_DSAT_TM_SCT; 1441 val |= TSI148_LCSR_DSAT_TM_SCT;
1437 1442
1438 if (cycle & VME_BLT) 1443 if (cycle & VME_BLT)
1439 *attr |= TSI148_LCSR_DSAT_TM_BLT; 1444 val |= TSI148_LCSR_DSAT_TM_BLT;
1440 1445
1441 if (cycle & VME_MBLT) 1446 if (cycle & VME_MBLT)
1442 *attr |= TSI148_LCSR_DSAT_TM_MBLT; 1447 val |= TSI148_LCSR_DSAT_TM_MBLT;
1443 1448
1444 if (cycle & VME_2eVME) 1449 if (cycle & VME_2eVME)
1445 *attr |= TSI148_LCSR_DSAT_TM_2eVME; 1450 val |= TSI148_LCSR_DSAT_TM_2eVME;
1446 1451
1447 if (cycle & VME_2eSST) 1452 if (cycle & VME_2eSST)
1448 *attr |= TSI148_LCSR_DSAT_TM_2eSST; 1453 val |= TSI148_LCSR_DSAT_TM_2eSST;
1449 1454
1450 if (cycle & VME_2eSSTB) { 1455 if (cycle & VME_2eSSTB) {
1451 dev_err(dev, "Currently not setting Broadcast Select " 1456 dev_err(dev, "Currently not setting Broadcast Select "
1452 "Registers\n"); 1457 "Registers\n");
1453 *attr |= TSI148_LCSR_DSAT_TM_2eSSTB; 1458 val |= TSI148_LCSR_DSAT_TM_2eSSTB;
1454 } 1459 }
1455 1460
1456 /* Setup data width */ 1461 /* Setup data width */
1457 switch (dwidth) { 1462 switch (dwidth) {
1458 case VME_D16: 1463 case VME_D16:
1459 *attr |= TSI148_LCSR_DSAT_DBW_16; 1464 val |= TSI148_LCSR_DSAT_DBW_16;
1460 break; 1465 break;
1461 case VME_D32: 1466 case VME_D32:
1462 *attr |= TSI148_LCSR_DSAT_DBW_32; 1467 val |= TSI148_LCSR_DSAT_DBW_32;
1463 break; 1468 break;
1464 default: 1469 default:
1465 dev_err(dev, "Invalid data width\n"); 1470 dev_err(dev, "Invalid data width\n");
@@ -1469,31 +1474,31 @@ static int tsi148_dma_set_vme_src_attributes(struct device *dev, u32 *attr,
1469 /* Setup address space */ 1474 /* Setup address space */
1470 switch (aspace) { 1475 switch (aspace) {
1471 case VME_A16: 1476 case VME_A16:
1472 *attr |= TSI148_LCSR_DSAT_AMODE_A16; 1477 val |= TSI148_LCSR_DSAT_AMODE_A16;
1473 break; 1478 break;
1474 case VME_A24: 1479 case VME_A24:
1475 *attr |= TSI148_LCSR_DSAT_AMODE_A24; 1480 val |= TSI148_LCSR_DSAT_AMODE_A24;
1476 break; 1481 break;
1477 case VME_A32: 1482 case VME_A32:
1478 *attr |= TSI148_LCSR_DSAT_AMODE_A32; 1483 val |= TSI148_LCSR_DSAT_AMODE_A32;
1479 break; 1484 break;
1480 case VME_A64: 1485 case VME_A64:
1481 *attr |= TSI148_LCSR_DSAT_AMODE_A64; 1486 val |= TSI148_LCSR_DSAT_AMODE_A64;
1482 break; 1487 break;
1483 case VME_CRCSR: 1488 case VME_CRCSR:
1484 *attr |= TSI148_LCSR_DSAT_AMODE_CRCSR; 1489 val |= TSI148_LCSR_DSAT_AMODE_CRCSR;
1485 break; 1490 break;
1486 case VME_USER1: 1491 case VME_USER1:
1487 *attr |= TSI148_LCSR_DSAT_AMODE_USER1; 1492 val |= TSI148_LCSR_DSAT_AMODE_USER1;
1488 break; 1493 break;
1489 case VME_USER2: 1494 case VME_USER2:
1490 *attr |= TSI148_LCSR_DSAT_AMODE_USER2; 1495 val |= TSI148_LCSR_DSAT_AMODE_USER2;
1491 break; 1496 break;
1492 case VME_USER3: 1497 case VME_USER3:
1493 *attr |= TSI148_LCSR_DSAT_AMODE_USER3; 1498 val |= TSI148_LCSR_DSAT_AMODE_USER3;
1494 break; 1499 break;
1495 case VME_USER4: 1500 case VME_USER4:
1496 *attr |= TSI148_LCSR_DSAT_AMODE_USER4; 1501 val |= TSI148_LCSR_DSAT_AMODE_USER4;
1497 break; 1502 break;
1498 default: 1503 default:
1499 dev_err(dev, "Invalid address space\n"); 1504 dev_err(dev, "Invalid address space\n");
@@ -1502,58 +1507,64 @@ static int tsi148_dma_set_vme_src_attributes(struct device *dev, u32 *attr,
1502 } 1507 }
1503 1508
1504 if (cycle & VME_SUPER) 1509 if (cycle & VME_SUPER)
1505 *attr |= TSI148_LCSR_DSAT_SUP; 1510 val |= TSI148_LCSR_DSAT_SUP;
1506 if (cycle & VME_PROG) 1511 if (cycle & VME_PROG)
1507 *attr |= TSI148_LCSR_DSAT_PGM; 1512 val |= TSI148_LCSR_DSAT_PGM;
1513
1514 *attr = cpu_to_be32(val);
1508 1515
1509 return 0; 1516 return 0;
1510} 1517}
1511 1518
1512static int tsi148_dma_set_vme_dest_attributes(struct device *dev, u32 *attr, 1519static int tsi148_dma_set_vme_dest_attributes(struct device *dev, __be32 *attr,
1513 u32 aspace, u32 cycle, u32 dwidth) 1520 u32 aspace, u32 cycle, u32 dwidth)
1514{ 1521{
1522 u32 val;
1523
1524 val = be32_to_cpu(*attr);
1525
1515 /* Setup 2eSST speeds */ 1526 /* Setup 2eSST speeds */
1516 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) { 1527 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1517 case VME_2eSST160: 1528 case VME_2eSST160:
1518 *attr |= TSI148_LCSR_DDAT_2eSSTM_160; 1529 val |= TSI148_LCSR_DDAT_2eSSTM_160;
1519 break; 1530 break;
1520 case VME_2eSST267: 1531 case VME_2eSST267:
1521 *attr |= TSI148_LCSR_DDAT_2eSSTM_267; 1532 val |= TSI148_LCSR_DDAT_2eSSTM_267;
1522 break; 1533 break;
1523 case VME_2eSST320: 1534 case VME_2eSST320:
1524 *attr |= TSI148_LCSR_DDAT_2eSSTM_320; 1535 val |= TSI148_LCSR_DDAT_2eSSTM_320;
1525 break; 1536 break;
1526 } 1537 }
1527 1538
1528 /* Setup cycle types */ 1539 /* Setup cycle types */
1529 if (cycle & VME_SCT) 1540 if (cycle & VME_SCT)
1530 *attr |= TSI148_LCSR_DDAT_TM_SCT; 1541 val |= TSI148_LCSR_DDAT_TM_SCT;
1531 1542
1532 if (cycle & VME_BLT) 1543 if (cycle & VME_BLT)
1533 *attr |= TSI148_LCSR_DDAT_TM_BLT; 1544 val |= TSI148_LCSR_DDAT_TM_BLT;
1534 1545
1535 if (cycle & VME_MBLT) 1546 if (cycle & VME_MBLT)
1536 *attr |= TSI148_LCSR_DDAT_TM_MBLT; 1547 val |= TSI148_LCSR_DDAT_TM_MBLT;
1537 1548
1538 if (cycle & VME_2eVME) 1549 if (cycle & VME_2eVME)
1539 *attr |= TSI148_LCSR_DDAT_TM_2eVME; 1550 val |= TSI148_LCSR_DDAT_TM_2eVME;
1540 1551
1541 if (cycle & VME_2eSST) 1552 if (cycle & VME_2eSST)
1542 *attr |= TSI148_LCSR_DDAT_TM_2eSST; 1553 val |= TSI148_LCSR_DDAT_TM_2eSST;
1543 1554
1544 if (cycle & VME_2eSSTB) { 1555 if (cycle & VME_2eSSTB) {
1545 dev_err(dev, "Currently not setting Broadcast Select " 1556 dev_err(dev, "Currently not setting Broadcast Select "
1546 "Registers\n"); 1557 "Registers\n");
1547 *attr |= TSI148_LCSR_DDAT_TM_2eSSTB; 1558 val |= TSI148_LCSR_DDAT_TM_2eSSTB;
1548 } 1559 }
1549 1560
1550 /* Setup data width */ 1561 /* Setup data width */
1551 switch (dwidth) { 1562 switch (dwidth) {
1552 case VME_D16: 1563 case VME_D16:
1553 *attr |= TSI148_LCSR_DDAT_DBW_16; 1564 val |= TSI148_LCSR_DDAT_DBW_16;
1554 break; 1565 break;
1555 case VME_D32: 1566 case VME_D32:
1556 *attr |= TSI148_LCSR_DDAT_DBW_32; 1567 val |= TSI148_LCSR_DDAT_DBW_32;
1557 break; 1568 break;
1558 default: 1569 default:
1559 dev_err(dev, "Invalid data width\n"); 1570 dev_err(dev, "Invalid data width\n");
@@ -1563,31 +1574,31 @@ static int tsi148_dma_set_vme_dest_attributes(struct device *dev, u32 *attr,
1563 /* Setup address space */ 1574 /* Setup address space */
1564 switch (aspace) { 1575 switch (aspace) {
1565 case VME_A16: 1576 case VME_A16:
1566 *attr |= TSI148_LCSR_DDAT_AMODE_A16; 1577 val |= TSI148_LCSR_DDAT_AMODE_A16;
1567 break; 1578 break;
1568 case VME_A24: 1579 case VME_A24:
1569 *attr |= TSI148_LCSR_DDAT_AMODE_A24; 1580 val |= TSI148_LCSR_DDAT_AMODE_A24;
1570 break; 1581 break;
1571 case VME_A32: 1582 case VME_A32:
1572 *attr |= TSI148_LCSR_DDAT_AMODE_A32; 1583 val |= TSI148_LCSR_DDAT_AMODE_A32;
1573 break; 1584 break;
1574 case VME_A64: 1585 case VME_A64:
1575 *attr |= TSI148_LCSR_DDAT_AMODE_A64; 1586 val |= TSI148_LCSR_DDAT_AMODE_A64;
1576 break; 1587 break;
1577 case VME_CRCSR: 1588 case VME_CRCSR:
1578 *attr |= TSI148_LCSR_DDAT_AMODE_CRCSR; 1589 val |= TSI148_LCSR_DDAT_AMODE_CRCSR;
1579 break; 1590 break;
1580 case VME_USER1: 1591 case VME_USER1:
1581 *attr |= TSI148_LCSR_DDAT_AMODE_USER1; 1592 val |= TSI148_LCSR_DDAT_AMODE_USER1;
1582 break; 1593 break;
1583 case VME_USER2: 1594 case VME_USER2:
1584 *attr |= TSI148_LCSR_DDAT_AMODE_USER2; 1595 val |= TSI148_LCSR_DDAT_AMODE_USER2;
1585 break; 1596 break;
1586 case VME_USER3: 1597 case VME_USER3:
1587 *attr |= TSI148_LCSR_DDAT_AMODE_USER3; 1598 val |= TSI148_LCSR_DDAT_AMODE_USER3;
1588 break; 1599 break;
1589 case VME_USER4: 1600 case VME_USER4:
1590 *attr |= TSI148_LCSR_DDAT_AMODE_USER4; 1601 val |= TSI148_LCSR_DDAT_AMODE_USER4;
1591 break; 1602 break;
1592 default: 1603 default:
1593 dev_err(dev, "Invalid address space\n"); 1604 dev_err(dev, "Invalid address space\n");
@@ -1596,25 +1607,28 @@ static int tsi148_dma_set_vme_dest_attributes(struct device *dev, u32 *attr,
1596 } 1607 }
1597 1608
1598 if (cycle & VME_SUPER) 1609 if (cycle & VME_SUPER)
1599 *attr |= TSI148_LCSR_DDAT_SUP; 1610 val |= TSI148_LCSR_DDAT_SUP;
1600 if (cycle & VME_PROG) 1611 if (cycle & VME_PROG)
1601 *attr |= TSI148_LCSR_DDAT_PGM; 1612 val |= TSI148_LCSR_DDAT_PGM;
1613
1614 *attr = cpu_to_be32(val);
1602 1615
1603 return 0; 1616 return 0;
1604} 1617}
1605 1618
1606/* 1619/*
1607 * Add a link list descriptor to the list 1620 * Add a link list descriptor to the list
1621 *
1622 * Note: DMA engine expects the DMA descriptor to be big endian.
1608 */ 1623 */
1609static int tsi148_dma_list_add(struct vme_dma_list *list, 1624static int tsi148_dma_list_add(struct vme_dma_list *list,
1610 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count) 1625 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
1611{ 1626{
1612 struct tsi148_dma_entry *entry, *prev; 1627 struct tsi148_dma_entry *entry, *prev;
1613 u32 address_high, address_low; 1628 u32 address_high, address_low, val;
1614 struct vme_dma_pattern *pattern_attr; 1629 struct vme_dma_pattern *pattern_attr;
1615 struct vme_dma_pci *pci_attr; 1630 struct vme_dma_pci *pci_attr;
1616 struct vme_dma_vme *vme_attr; 1631 struct vme_dma_vme *vme_attr;
1617 dma_addr_t desc_ptr;
1618 int retval = 0; 1632 int retval = 0;
1619 struct vme_bridge *tsi148_bridge; 1633 struct vme_bridge *tsi148_bridge;
1620 1634
@@ -1648,34 +1662,36 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
1648 case VME_DMA_PATTERN: 1662 case VME_DMA_PATTERN:
1649 pattern_attr = src->private; 1663 pattern_attr = src->private;
1650 1664
1651 entry->descriptor.dsal = pattern_attr->pattern; 1665 entry->descriptor.dsal = cpu_to_be32(pattern_attr->pattern);
1652 entry->descriptor.dsat = TSI148_LCSR_DSAT_TYP_PAT; 1666
1667 val = TSI148_LCSR_DSAT_TYP_PAT;
1668
1653 /* Default behaviour is 32 bit pattern */ 1669 /* Default behaviour is 32 bit pattern */
1654 if (pattern_attr->type & VME_DMA_PATTERN_BYTE) 1670 if (pattern_attr->type & VME_DMA_PATTERN_BYTE)
1655 entry->descriptor.dsat |= TSI148_LCSR_DSAT_PSZ; 1671 val |= TSI148_LCSR_DSAT_PSZ;
1656 1672
1657 /* It seems that the default behaviour is to increment */ 1673 /* It seems that the default behaviour is to increment */
1658 if ((pattern_attr->type & VME_DMA_PATTERN_INCREMENT) == 0) 1674 if ((pattern_attr->type & VME_DMA_PATTERN_INCREMENT) == 0)
1659 entry->descriptor.dsat |= TSI148_LCSR_DSAT_NIN; 1675 val |= TSI148_LCSR_DSAT_NIN;
1660 1676 entry->descriptor.dsat = cpu_to_be32(val);
1661 break; 1677 break;
1662 case VME_DMA_PCI: 1678 case VME_DMA_PCI:
1663 pci_attr = src->private; 1679 pci_attr = src->private;
1664 1680
1665 reg_split((unsigned long long)pci_attr->address, &address_high, 1681 reg_split((unsigned long long)pci_attr->address, &address_high,
1666 &address_low); 1682 &address_low);
1667 entry->descriptor.dsau = address_high; 1683 entry->descriptor.dsau = cpu_to_be32(address_high);
1668 entry->descriptor.dsal = address_low; 1684 entry->descriptor.dsal = cpu_to_be32(address_low);
1669 entry->descriptor.dsat = TSI148_LCSR_DSAT_TYP_PCI; 1685 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_PCI);
1670 break; 1686 break;
1671 case VME_DMA_VME: 1687 case VME_DMA_VME:
1672 vme_attr = src->private; 1688 vme_attr = src->private;
1673 1689
1674 reg_split((unsigned long long)vme_attr->address, &address_high, 1690 reg_split((unsigned long long)vme_attr->address, &address_high,
1675 &address_low); 1691 &address_low);
1676 entry->descriptor.dsau = address_high; 1692 entry->descriptor.dsau = cpu_to_be32(address_high);
1677 entry->descriptor.dsal = address_low; 1693 entry->descriptor.dsal = cpu_to_be32(address_low);
1678 entry->descriptor.dsat = TSI148_LCSR_DSAT_TYP_VME; 1694 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_VME);
1679 1695
1680 retval = tsi148_dma_set_vme_src_attributes( 1696 retval = tsi148_dma_set_vme_src_attributes(
1681 tsi148_bridge->parent, &entry->descriptor.dsat, 1697 tsi148_bridge->parent, &entry->descriptor.dsat,
@@ -1691,9 +1707,8 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
1691 } 1707 }
1692 1708
1693 /* Assume last link - this will be over-written by adding another */ 1709 /* Assume last link - this will be over-written by adding another */
1694 entry->descriptor.dnlau = 0; 1710 entry->descriptor.dnlau = cpu_to_be32(0);
1695 entry->descriptor.dnlal = TSI148_LCSR_DNLAL_LLA; 1711 entry->descriptor.dnlal = cpu_to_be32(TSI148_LCSR_DNLAL_LLA);
1696
1697 1712
1698 /* Fill out destination part */ 1713 /* Fill out destination part */
1699 switch (dest->type) { 1714 switch (dest->type) {
@@ -1702,18 +1717,18 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
1702 1717
1703 reg_split((unsigned long long)pci_attr->address, &address_high, 1718 reg_split((unsigned long long)pci_attr->address, &address_high,
1704 &address_low); 1719 &address_low);
1705 entry->descriptor.ddau = address_high; 1720 entry->descriptor.ddau = cpu_to_be32(address_high);
1706 entry->descriptor.ddal = address_low; 1721 entry->descriptor.ddal = cpu_to_be32(address_low);
1707 entry->descriptor.ddat = TSI148_LCSR_DDAT_TYP_PCI; 1722 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_PCI);
1708 break; 1723 break;
1709 case VME_DMA_VME: 1724 case VME_DMA_VME:
1710 vme_attr = dest->private; 1725 vme_attr = dest->private;
1711 1726
1712 reg_split((unsigned long long)vme_attr->address, &address_high, 1727 reg_split((unsigned long long)vme_attr->address, &address_high,
1713 &address_low); 1728 &address_low);
1714 entry->descriptor.ddau = address_high; 1729 entry->descriptor.ddau = cpu_to_be32(address_high);
1715 entry->descriptor.ddal = address_low; 1730 entry->descriptor.ddal = cpu_to_be32(address_low);
1716 entry->descriptor.ddat = TSI148_LCSR_DDAT_TYP_VME; 1731 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_VME);
1717 1732
1718 retval = tsi148_dma_set_vme_dest_attributes( 1733 retval = tsi148_dma_set_vme_dest_attributes(
1719 tsi148_bridge->parent, &entry->descriptor.ddat, 1734 tsi148_bridge->parent, &entry->descriptor.ddat,
@@ -1729,7 +1744,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
1729 } 1744 }
1730 1745
1731 /* Fill out count */ 1746 /* Fill out count */
1732 entry->descriptor.dcnt = (u32)count; 1747 entry->descriptor.dcnt = cpu_to_be32((u32)count);
1733 1748
1734 /* Add to list */ 1749 /* Add to list */
1735 list_add_tail(&entry->list, &list->entries); 1750 list_add_tail(&entry->list, &list->entries);
@@ -1739,9 +1754,15 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
1739 prev = list_entry(entry->list.prev, struct tsi148_dma_entry, 1754 prev = list_entry(entry->list.prev, struct tsi148_dma_entry,
1740 list); 1755 list);
1741 /* We need the bus address for the pointer */ 1756 /* We need the bus address for the pointer */
1742 desc_ptr = virt_to_bus(&entry->descriptor); 1757 entry->dma_handle = dma_map_single(tsi148_bridge->parent,
1743 reg_split(desc_ptr, &prev->descriptor.dnlau, 1758 &entry->descriptor,
1744 &prev->descriptor.dnlal); 1759 sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE);
1760
1761 reg_split((unsigned long long)entry->dma_handle, &address_high,
1762 &address_low);
1763 entry->descriptor.dnlau = cpu_to_be32(address_high);
1764 entry->descriptor.dnlal = cpu_to_be32(address_low);
1765
1745 } 1766 }
1746 1767
1747 return 0; 1768 return 0;
@@ -1784,7 +1805,6 @@ static int tsi148_dma_list_exec(struct vme_dma_list *list)
1784 struct vme_dma_resource *ctrlr; 1805 struct vme_dma_resource *ctrlr;
1785 int channel, retval = 0; 1806 int channel, retval = 0;
1786 struct tsi148_dma_entry *entry; 1807 struct tsi148_dma_entry *entry;
1787 dma_addr_t bus_addr;
1788 u32 bus_addr_high, bus_addr_low; 1808 u32 bus_addr_high, bus_addr_low;
1789 u32 val, dctlreg = 0; 1809 u32 val, dctlreg = 0;
1790 struct vme_bridge *tsi148_bridge; 1810 struct vme_bridge *tsi148_bridge;
@@ -1817,23 +1837,29 @@ static int tsi148_dma_list_exec(struct vme_dma_list *list)
1817 entry = list_first_entry(&list->entries, struct tsi148_dma_entry, 1837 entry = list_first_entry(&list->entries, struct tsi148_dma_entry,
1818 list); 1838 list);
1819 1839
1820 bus_addr = virt_to_bus(&entry->descriptor); 1840 entry->dma_handle = dma_map_single(tsi148_bridge->parent,
1841 &entry->descriptor,
1842 sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE);
1821 1843
1822 mutex_unlock(&ctrlr->mtx); 1844 mutex_unlock(&ctrlr->mtx);
1823 1845
1824 reg_split(bus_addr, &bus_addr_high, &bus_addr_low); 1846 reg_split(entry->dma_handle, &bus_addr_high, &bus_addr_low);
1825 1847
1826 iowrite32be(bus_addr_high, bridge->base + 1848 iowrite32be(bus_addr_high, bridge->base +
1827 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAU); 1849 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAU);
1828 iowrite32be(bus_addr_low, bridge->base + 1850 iowrite32be(bus_addr_low, bridge->base +
1829 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAL); 1851 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAL);
1830 1852
1853 dctlreg = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1854 TSI148_LCSR_OFFSET_DCTL);
1855
1831 /* Start the operation */ 1856 /* Start the operation */
1832 iowrite32be(dctlreg | TSI148_LCSR_DCTL_DGO, bridge->base + 1857 iowrite32be(dctlreg | TSI148_LCSR_DCTL_DGO, bridge->base +
1833 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL); 1858 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL);
1834 1859
1835 wait_event_interruptible(bridge->dma_queue[channel], 1860 wait_event_interruptible(bridge->dma_queue[channel],
1836 tsi148_dma_busy(ctrlr->parent, channel)); 1861 tsi148_dma_busy(ctrlr->parent, channel));
1862
1837 /* 1863 /*
1838 * Read status register, this register is valid until we kick off a 1864 * Read status register, this register is valid until we kick off a
1839 * new transfer. 1865 * new transfer.
@@ -1864,10 +1890,15 @@ static int tsi148_dma_list_empty(struct vme_dma_list *list)
1864 struct list_head *pos, *temp; 1890 struct list_head *pos, *temp;
1865 struct tsi148_dma_entry *entry; 1891 struct tsi148_dma_entry *entry;
1866 1892
1893 struct vme_bridge *tsi148_bridge = list->parent->parent;
1894
1867 /* detach and free each entry */ 1895 /* detach and free each entry */
1868 list_for_each_safe(pos, temp, &list->entries) { 1896 list_for_each_safe(pos, temp, &list->entries) {
1869 list_del(pos); 1897 list_del(pos);
1870 entry = list_entry(pos, struct tsi148_dma_entry, list); 1898 entry = list_entry(pos, struct tsi148_dma_entry, list);
1899
1900 dma_unmap_single(tsi148_bridge->parent, entry->dma_handle,
1901 sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE);
1871 kfree(entry); 1902 kfree(entry);
1872 } 1903 }
1873 1904
@@ -2110,7 +2141,7 @@ static int tsi148_slot_get(struct vme_bridge *tsi148_bridge)
2110 return (int)slot; 2141 return (int)slot;
2111} 2142}
2112 2143
2113void *tsi148_alloc_consistent(struct device *parent, size_t size, 2144static void *tsi148_alloc_consistent(struct device *parent, size_t size,
2114 dma_addr_t *dma) 2145 dma_addr_t *dma)
2115{ 2146{
2116 struct pci_dev *pdev; 2147 struct pci_dev *pdev;
@@ -2121,8 +2152,8 @@ void *tsi148_alloc_consistent(struct device *parent, size_t size,
2121 return pci_alloc_consistent(pdev, size, dma); 2152 return pci_alloc_consistent(pdev, size, dma);
2122} 2153}
2123 2154
2124void tsi148_free_consistent(struct device *parent, size_t size, void *vaddr, 2155static void tsi148_free_consistent(struct device *parent, size_t size,
2125 dma_addr_t dma) 2156 void *vaddr, dma_addr_t dma)
2126{ 2157{
2127 struct pci_dev *pdev; 2158 struct pci_dev *pdev;
2128 2159
diff --git a/drivers/staging/vme/bridges/vme_tsi148.h b/drivers/vme/bridges/vme_tsi148.h
index a3ac2fe98816..f5ed14382a8d 100644
--- a/drivers/staging/vme/bridges/vme_tsi148.h
+++ b/drivers/vme/bridges/vme_tsi148.h
@@ -56,16 +56,16 @@ struct tsi148_driver {
56 * correctly laid out - It must also be aligned on 64-bit boundaries. 56 * correctly laid out - It must also be aligned on 64-bit boundaries.
57 */ 57 */
58struct tsi148_dma_descriptor { 58struct tsi148_dma_descriptor {
59 u32 dsau; /* Source Address */ 59 __be32 dsau; /* Source Address */
60 u32 dsal; 60 __be32 dsal;
61 u32 ddau; /* Destination Address */ 61 __be32 ddau; /* Destination Address */
62 u32 ddal; 62 __be32 ddal;
63 u32 dsat; /* Source attributes */ 63 __be32 dsat; /* Source attributes */
64 u32 ddat; /* Destination attributes */ 64 __be32 ddat; /* Destination attributes */
65 u32 dnlau; /* Next link address */ 65 __be32 dnlau; /* Next link address */
66 u32 dnlal; 66 __be32 dnlal;
67 u32 dcnt; /* Byte count */ 67 __be32 dcnt; /* Byte count */
68 u32 ddbs; /* 2eSST Broadcast select */ 68 __be32 ddbs; /* 2eSST Broadcast select */
69}; 69};
70 70
71struct tsi148_dma_entry { 71struct tsi148_dma_entry {
@@ -75,6 +75,7 @@ struct tsi148_dma_entry {
75 */ 75 */
76 struct tsi148_dma_descriptor descriptor; 76 struct tsi148_dma_descriptor descriptor;
77 struct list_head list; 77 struct list_head list;
78 dma_addr_t dma_handle;
78}; 79};
79 80
80/* 81/*
diff --git a/drivers/staging/vme/vme.c b/drivers/vme/vme.c
index 70722ae52321..95a9f71d793e 100644
--- a/drivers/staging/vme/vme.c
+++ b/drivers/vme/vme.c
@@ -30,8 +30,8 @@
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/vme.h>
33 34
34#include "vme.h"
35#include "vme_bridge.h" 35#include "vme_bridge.h"
36 36
37/* Bitmask and list of registered buses both protected by common mutex */ 37/* Bitmask and list of registered buses both protected by common mutex */
@@ -98,14 +98,13 @@ void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
98 } 98 }
99 99
100 if (bridge->parent == NULL) { 100 if (bridge->parent == NULL) {
101 printk(KERN_ERR "Dev entry NULL for" 101 printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
102 " bridge %s\n", bridge->name);
103 return NULL; 102 return NULL;
104 } 103 }
105 104
106 if (bridge->alloc_consistent == NULL) { 105 if (bridge->alloc_consistent == NULL) {
107 printk(KERN_ERR "alloc_consistent not supported by" 106 printk(KERN_ERR "alloc_consistent not supported by bridge %s\n",
108 " bridge %s\n", bridge->name); 107 bridge->name);
109 return NULL; 108 return NULL;
110 } 109 }
111 110
@@ -133,14 +132,13 @@ void vme_free_consistent(struct vme_resource *resource, size_t size,
133 } 132 }
134 133
135 if (bridge->parent == NULL) { 134 if (bridge->parent == NULL) {
136 printk(KERN_ERR "Dev entry NULL for" 135 printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
137 " bridge %s\n", bridge->name);
138 return; 136 return;
139 } 137 }
140 138
141 if (bridge->free_consistent == NULL) { 139 if (bridge->free_consistent == NULL) {
142 printk(KERN_ERR "free_consistent not supported by" 140 printk(KERN_ERR "free_consistent not supported by bridge %s\n",
143 " bridge %s\n", bridge->name); 141 bridge->name);
144 return; 142 return;
145 } 143 }
146 144
@@ -747,15 +745,13 @@ struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type)
747 745
748 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); 746 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
749 if (attributes == NULL) { 747 if (attributes == NULL) {
750 printk(KERN_ERR "Unable to allocate memory for attributes " 748 printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
751 "structure\n");
752 goto err_attr; 749 goto err_attr;
753 } 750 }
754 751
755 pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL); 752 pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL);
756 if (pattern_attr == NULL) { 753 if (pattern_attr == NULL) {
757 printk(KERN_ERR "Unable to allocate memory for pattern " 754 printk(KERN_ERR "Unable to allocate memory for pattern attributes\n");
758 "attributes\n");
759 goto err_pat; 755 goto err_pat;
760 } 756 }
761 757
@@ -786,15 +782,13 @@ struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address)
786 782
787 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL); 783 attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
788 if (attributes == NULL) { 784 if (attributes == NULL) {
789 printk(KERN_ERR "Unable to allocate memory for attributes " 785 printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
790 "structure\n");
791 goto err_attr; 786 goto err_attr;
792 } 787 }
793 788
794 pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL); 789 pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL);
795 if (pci_attr == NULL) { 790 if (pci_attr == NULL) {
796 printk(KERN_ERR "Unable to allocate memory for pci " 791 printk(KERN_ERR "Unable to allocate memory for pci attributes\n");
797 "attributes\n");
798 goto err_pci; 792 goto err_pci;
799 } 793 }
800 794
@@ -826,15 +820,13 @@ struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address,
826 attributes = kmalloc( 820 attributes = kmalloc(
827 sizeof(struct vme_dma_attr), GFP_KERNEL); 821 sizeof(struct vme_dma_attr), GFP_KERNEL);
828 if (attributes == NULL) { 822 if (attributes == NULL) {
829 printk(KERN_ERR "Unable to allocate memory for attributes " 823 printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
830 "structure\n");
831 goto err_attr; 824 goto err_attr;
832 } 825 }
833 826
834 vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL); 827 vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL);
835 if (vme_attr == NULL) { 828 if (vme_attr == NULL) {
836 printk(KERN_ERR "Unable to allocate memory for vme " 829 printk(KERN_ERR "Unable to allocate memory for vme attributes\n");
837 "attributes\n");
838 goto err_vme; 830 goto err_vme;
839 } 831 }
840 832
@@ -982,8 +974,8 @@ void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
982 if (call != NULL) 974 if (call != NULL)
983 call(level, statid, priv_data); 975 call(level, statid, priv_data);
984 else 976 else
985 printk(KERN_WARNING "Spurilous VME interrupt, level:%x, " 977 printk(KERN_WARNING "Spurilous VME interrupt, level:%x, vector:%x\n",
986 "vector:%x\n", level, statid); 978 level, statid);
987} 979}
988EXPORT_SYMBOL(vme_irq_handler); 980EXPORT_SYMBOL(vme_irq_handler);
989 981
@@ -1112,8 +1104,7 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev)
1112 struct vme_lm_resource, list); 1104 struct vme_lm_resource, list);
1113 1105
1114 if (lm == NULL) { 1106 if (lm == NULL) {
1115 printk(KERN_ERR "Registered NULL Location Monitor " 1107 printk(KERN_ERR "Registered NULL Location Monitor resource\n");
1116 "resource\n");
1117 continue; 1108 continue;
1118 } 1109 }
1119 1110
diff --git a/drivers/staging/vme/vme_bridge.h b/drivers/vme/vme_bridge.h
index 934949abd745..934949abd745 100644
--- a/drivers/staging/vme/vme_bridge.h
+++ b/drivers/vme/vme_bridge.h
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 8007ae7c0d8c..23ade2680a4a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -11,3 +11,20 @@ config PSTORE
11 (e.g. ACPI_APEI on X86) which will select this for you. 11 (e.g. ACPI_APEI on X86) which will select this for you.
12 If you don't have a platform persistent store driver, 12 If you don't have a platform persistent store driver,
13 say N. 13 say N.
14
15config PSTORE_RAM
16 tristate "Log panic/oops to a RAM buffer"
17 depends on PSTORE
18 depends on HAS_IOMEM
19 depends on HAVE_MEMBLOCK
20 select REED_SOLOMON
21 select REED_SOLOMON_ENC8
22 select REED_SOLOMON_DEC8
23 help
24 This enables panic and oops messages to be logged to a circular
25 buffer in RAM where it can be read back at some later point.
26
27 Note that for historical reasons, the module will be named
28 "ramoops.ko".
29
30 For more information, see Documentation/ramoops.txt.
diff --git a/fs/pstore/Makefile b/fs/pstore/Makefile
index 760f4bce7d1d..278a44e0d4e1 100644
--- a/fs/pstore/Makefile
+++ b/fs/pstore/Makefile
@@ -5,3 +5,6 @@
5obj-y += pstore.o 5obj-y += pstore.o
6 6
7pstore-objs += inode.o platform.o 7pstore-objs += inode.o platform.o
8
9ramoops-objs += ram.o ram_core.o
10obj-$(CONFIG_PSTORE_RAM) += ramoops.o
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
new file mode 100644
index 000000000000..9123cce28c1e
--- /dev/null
+++ b/fs/pstore/ram.c
@@ -0,0 +1,383 @@
1/*
2 * RAM Oops/Panic logger
3 *
4 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
5 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
25#include <linux/kernel.h>
26#include <linux/err.h>
27#include <linux/module.h>
28#include <linux/pstore.h>
29#include <linux/time.h>
30#include <linux/io.h>
31#include <linux/ioport.h>
32#include <linux/platform_device.h>
33#include <linux/slab.h>
34#include <linux/pstore_ram.h>
35
36#define RAMOOPS_KERNMSG_HDR "===="
37#define MIN_MEM_SIZE 4096UL
38
39static ulong record_size = MIN_MEM_SIZE;
40module_param(record_size, ulong, 0400);
41MODULE_PARM_DESC(record_size,
42 "size of each dump done on oops/panic");
43
44static ulong mem_address;
45module_param(mem_address, ulong, 0400);
46MODULE_PARM_DESC(mem_address,
47 "start of reserved RAM used to store oops/panic logs");
48
49static ulong mem_size;
50module_param(mem_size, ulong, 0400);
51MODULE_PARM_DESC(mem_size,
52 "size of reserved RAM used to store oops/panic logs");
53
54static int dump_oops = 1;
55module_param(dump_oops, int, 0600);
56MODULE_PARM_DESC(dump_oops,
57 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
58
59static int ramoops_ecc;
60module_param_named(ecc, ramoops_ecc, int, 0600);
61MODULE_PARM_DESC(ramoops_ecc,
62 "set to 1 to enable ECC support");
63
64struct ramoops_context {
65 struct persistent_ram_zone **przs;
66 phys_addr_t phys_addr;
67 unsigned long size;
68 size_t record_size;
69 int dump_oops;
70 bool ecc;
71 unsigned int count;
72 unsigned int max_count;
73 unsigned int read_count;
74 struct pstore_info pstore;
75};
76
77static struct platform_device *dummy;
78static struct ramoops_platform_data *dummy_data;
79
80static int ramoops_pstore_open(struct pstore_info *psi)
81{
82 struct ramoops_context *cxt = psi->data;
83
84 cxt->read_count = 0;
85 return 0;
86}
87
88static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
89 struct timespec *time,
90 char **buf,
91 struct pstore_info *psi)
92{
93 ssize_t size;
94 struct ramoops_context *cxt = psi->data;
95 struct persistent_ram_zone *prz;
96
97 if (cxt->read_count >= cxt->max_count)
98 return -EINVAL;
99
100 *id = cxt->read_count++;
101 prz = cxt->przs[*id];
102
103 /* Only supports dmesg output so far. */
104 *type = PSTORE_TYPE_DMESG;
105 /* TODO(kees): Bogus time for the moment. */
106 time->tv_sec = 0;
107 time->tv_nsec = 0;
108
109 size = persistent_ram_old_size(prz);
110 *buf = kmalloc(size, GFP_KERNEL);
111 if (*buf == NULL)
112 return -ENOMEM;
113 memcpy(*buf, persistent_ram_old(prz), size);
114
115 return size;
116}
117
118static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
119{
120 char *hdr;
121 struct timeval timestamp;
122 size_t len;
123
124 do_gettimeofday(&timestamp);
125 hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
126 (long)timestamp.tv_sec, (long)timestamp.tv_usec);
127 WARN_ON_ONCE(!hdr);
128 len = hdr ? strlen(hdr) : 0;
129 persistent_ram_write(prz, hdr, len);
130 kfree(hdr);
131
132 return len;
133}
134
135static int ramoops_pstore_write(enum pstore_type_id type,
136 enum kmsg_dump_reason reason,
137 u64 *id,
138 unsigned int part,
139 size_t size, struct pstore_info *psi)
140{
141 struct ramoops_context *cxt = psi->data;
142 struct persistent_ram_zone *prz = cxt->przs[cxt->count];
143 size_t hlen;
144
145 /* Currently ramoops is designed to only store dmesg dumps. */
146 if (type != PSTORE_TYPE_DMESG)
147 return -EINVAL;
148
149 /* Out of the various dmesg dump types, ramoops is currently designed
150 * to only store crash logs, rather than storing general kernel logs.
151 */
152 if (reason != KMSG_DUMP_OOPS &&
153 reason != KMSG_DUMP_PANIC)
154 return -EINVAL;
155
156 /* Skip Oopes when configured to do so. */
157 if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
158 return -EINVAL;
159
160 /* Explicitly only take the first part of any new crash.
161 * If our buffer is larger than kmsg_bytes, this can never happen,
162 * and if our buffer is smaller than kmsg_bytes, we don't want the
163 * report split across multiple records.
164 */
165 if (part != 1)
166 return -ENOSPC;
167
168 hlen = ramoops_write_kmsg_hdr(prz);
169 if (size + hlen > prz->buffer_size)
170 size = prz->buffer_size - hlen;
171 persistent_ram_write(prz, cxt->pstore.buf, size);
172
173 cxt->count = (cxt->count + 1) % cxt->max_count;
174
175 return 0;
176}
177
178static int ramoops_pstore_erase(enum pstore_type_id type, u64 id,
179 struct pstore_info *psi)
180{
181 struct ramoops_context *cxt = psi->data;
182
183 if (id >= cxt->max_count)
184 return -EINVAL;
185
186 persistent_ram_free_old(cxt->przs[id]);
187
188 return 0;
189}
190
191static struct ramoops_context oops_cxt = {
192 .pstore = {
193 .owner = THIS_MODULE,
194 .name = "ramoops",
195 .open = ramoops_pstore_open,
196 .read = ramoops_pstore_read,
197 .write = ramoops_pstore_write,
198 .erase = ramoops_pstore_erase,
199 },
200};
201
202static int __init ramoops_probe(struct platform_device *pdev)
203{
204 struct device *dev = &pdev->dev;
205 struct ramoops_platform_data *pdata = pdev->dev.platform_data;
206 struct ramoops_context *cxt = &oops_cxt;
207 int err = -EINVAL;
208 int i;
209
210 /* Only a single ramoops area allowed at a time, so fail extra
211 * probes.
212 */
213 if (cxt->max_count)
214 goto fail_out;
215
216 if (!pdata->mem_size || !pdata->record_size) {
217 pr_err("The memory size and the record size must be "
218 "non-zero\n");
219 goto fail_out;
220 }
221
222 pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
223 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
224
225 /* Check for the minimum memory size */
226 if (pdata->mem_size < MIN_MEM_SIZE &&
227 pdata->record_size < MIN_MEM_SIZE) {
228 pr_err("memory size too small, minimum is %lu\n",
229 MIN_MEM_SIZE);
230 goto fail_out;
231 }
232
233 if (pdata->mem_size < pdata->record_size) {
234 pr_err("The memory size must be larger than the "
235 "records size\n");
236 goto fail_out;
237 }
238
239 cxt->max_count = pdata->mem_size / pdata->record_size;
240 cxt->count = 0;
241 cxt->size = pdata->mem_size;
242 cxt->phys_addr = pdata->mem_address;
243 cxt->record_size = pdata->record_size;
244 cxt->dump_oops = pdata->dump_oops;
245 cxt->ecc = pdata->ecc;
246
247 cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_count, GFP_KERNEL);
248 if (!cxt->przs) {
249 err = -ENOMEM;
250 dev_err(dev, "failed to initialize a prz array\n");
251 goto fail_out;
252 }
253
254 for (i = 0; i < cxt->max_count; i++) {
255 size_t sz = cxt->record_size;
256 phys_addr_t start = cxt->phys_addr + sz * i;
257
258 cxt->przs[i] = persistent_ram_new(start, sz, cxt->ecc);
259 if (IS_ERR(cxt->przs[i])) {
260 err = PTR_ERR(cxt->przs[i]);
261 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
262 sz, (unsigned long long)start, err);
263 goto fail_przs;
264 }
265 }
266
267 cxt->pstore.data = cxt;
268 cxt->pstore.bufsize = cxt->przs[0]->buffer_size;
269 cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);
270 spin_lock_init(&cxt->pstore.buf_lock);
271 if (!cxt->pstore.buf) {
272 pr_err("cannot allocate pstore buffer\n");
273 goto fail_clear;
274 }
275
276 err = pstore_register(&cxt->pstore);
277 if (err) {
278 pr_err("registering with pstore failed\n");
279 goto fail_buf;
280 }
281
282 /*
283 * Update the module parameter variables as well so they are visible
284 * through /sys/module/ramoops/parameters/
285 */
286 mem_size = pdata->mem_size;
287 mem_address = pdata->mem_address;
288 record_size = pdata->record_size;
289 dump_oops = pdata->dump_oops;
290
291 pr_info("attached 0x%lx@0x%llx (%ux0x%zx), ecc: %s\n",
292 cxt->size, (unsigned long long)cxt->phys_addr,
293 cxt->max_count, cxt->record_size,
294 ramoops_ecc ? "on" : "off");
295
296 return 0;
297
298fail_buf:
299 kfree(cxt->pstore.buf);
300fail_clear:
301 cxt->pstore.bufsize = 0;
302 cxt->max_count = 0;
303fail_przs:
304 for (i = 0; cxt->przs[i]; i++)
305 persistent_ram_free(cxt->przs[i]);
306 kfree(cxt->przs);
307fail_out:
308 return err;
309}
310
311static int __exit ramoops_remove(struct platform_device *pdev)
312{
313#if 0
314 /* TODO(kees): We cannot unload ramoops since pstore doesn't support
315 * unregistering yet.
316 */
317 struct ramoops_context *cxt = &oops_cxt;
318
319 iounmap(cxt->virt_addr);
320 release_mem_region(cxt->phys_addr, cxt->size);
321 cxt->max_count = 0;
322
323 /* TODO(kees): When pstore supports unregistering, call it here. */
324 kfree(cxt->pstore.buf);
325 cxt->pstore.bufsize = 0;
326
327 return 0;
328#endif
329 return -EBUSY;
330}
331
332static struct platform_driver ramoops_driver = {
333 .remove = __exit_p(ramoops_remove),
334 .driver = {
335 .name = "ramoops",
336 .owner = THIS_MODULE,
337 },
338};
339
340static int __init ramoops_init(void)
341{
342 int ret;
343 ret = platform_driver_probe(&ramoops_driver, ramoops_probe);
344 if (ret == -ENODEV) {
345 /*
346 * If we didn't find a platform device, we use module parameters
347 * building platform data on the fly.
348 */
349 pr_info("platform device not found, using module parameters\n");
350 dummy_data = kzalloc(sizeof(struct ramoops_platform_data),
351 GFP_KERNEL);
352 if (!dummy_data)
353 return -ENOMEM;
354 dummy_data->mem_size = mem_size;
355 dummy_data->mem_address = mem_address;
356 dummy_data->record_size = record_size;
357 dummy_data->dump_oops = dump_oops;
358 dummy_data->ecc = ramoops_ecc;
359 dummy = platform_create_bundle(&ramoops_driver, ramoops_probe,
360 NULL, 0, dummy_data,
361 sizeof(struct ramoops_platform_data));
362
363 if (IS_ERR(dummy))
364 ret = PTR_ERR(dummy);
365 else
366 ret = 0;
367 }
368
369 return ret;
370}
371
372static void __exit ramoops_exit(void)
373{
374 platform_driver_unregister(&ramoops_driver);
375 kfree(dummy_data);
376}
377
378module_init(ramoops_init);
379module_exit(ramoops_exit);
380
381MODULE_LICENSE("GPL");
382MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
383MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");
diff --git a/drivers/staging/android/persistent_ram.c b/fs/pstore/ram_core.c
index 8d8c1e33e0ff..31f8d184f3a0 100644
--- a/drivers/staging/android/persistent_ram.c
+++ b/fs/pstore/ram_core.c
@@ -23,7 +23,8 @@
23#include <linux/rslib.h> 23#include <linux/rslib.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
26#include "persistent_ram.h" 26#include <linux/pstore_ram.h>
27#include <asm/page.h>
27 28
28struct persistent_ram_buffer { 29struct persistent_ram_buffer {
29 uint32_t sig; 30 uint32_t sig;
@@ -79,23 +80,6 @@ static inline void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
79 } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old); 80 } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old);
80} 81}
81 82
82/* increase the size counter, retuning an error if it hits the max size */
83static inline ssize_t buffer_size_add_clamp(struct persistent_ram_zone *prz,
84 size_t a)
85{
86 size_t old;
87 size_t new;
88
89 do {
90 old = atomic_read(&prz->buffer->size);
91 new = old + a;
92 if (new > prz->buffer_size)
93 return -ENOMEM;
94 } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old);
95
96 return 0;
97}
98
99static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz, 83static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
100 uint8_t *data, size_t len, uint8_t *ecc) 84 uint8_t *data, size_t len, uint8_t *ecc)
101{ 85{
@@ -300,7 +284,7 @@ int notrace persistent_ram_write(struct persistent_ram_zone *prz,
300 c = prz->buffer_size; 284 c = prz->buffer_size;
301 } 285 }
302 286
303 buffer_size_add_clamp(prz, c); 287 buffer_size_add(prz, c);
304 288
305 start = buffer_start_add(prz, c); 289 start = buffer_start_add(prz, c);
306 290
@@ -335,14 +319,14 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz)
335 prz->old_log_size = 0; 319 prz->old_log_size = 0;
336} 320}
337 321
338static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, 322static void *persistent_ram_vmap(phys_addr_t start, size_t size)
339 struct persistent_ram_zone *prz)
340{ 323{
341 struct page **pages; 324 struct page **pages;
342 phys_addr_t page_start; 325 phys_addr_t page_start;
343 unsigned int page_count; 326 unsigned int page_count;
344 pgprot_t prot; 327 pgprot_t prot;
345 unsigned int i; 328 unsigned int i;
329 void *vaddr;
346 330
347 page_start = start - offset_in_page(start); 331 page_start = start - offset_in_page(start);
348 page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE); 332 page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
@@ -353,17 +337,44 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
353 if (!pages) { 337 if (!pages) {
354 pr_err("%s: Failed to allocate array for %u pages\n", __func__, 338 pr_err("%s: Failed to allocate array for %u pages\n", __func__,
355 page_count); 339 page_count);
356 return -ENOMEM; 340 return NULL;
357 } 341 }
358 342
359 for (i = 0; i < page_count; i++) { 343 for (i = 0; i < page_count; i++) {
360 phys_addr_t addr = page_start + i * PAGE_SIZE; 344 phys_addr_t addr = page_start + i * PAGE_SIZE;
361 pages[i] = pfn_to_page(addr >> PAGE_SHIFT); 345 pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
362 } 346 }
363 prz->vaddr = vmap(pages, page_count, VM_MAP, prot); 347 vaddr = vmap(pages, page_count, VM_MAP, prot);
364 kfree(pages); 348 kfree(pages);
349
350 return vaddr;
351}
352
353static void *persistent_ram_iomap(phys_addr_t start, size_t size)
354{
355 if (!request_mem_region(start, size, "persistent_ram")) {
356 pr_err("request mem region (0x%llx@0x%llx) failed\n",
357 (unsigned long long)size, (unsigned long long)start);
358 return NULL;
359 }
360
361 return ioremap(start, size);
362}
363
364static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
365 struct persistent_ram_zone *prz)
366{
367 prz->paddr = start;
368 prz->size = size;
369
370 if (pfn_valid(start >> PAGE_SHIFT))
371 prz->vaddr = persistent_ram_vmap(start, size);
372 else
373 prz->vaddr = persistent_ram_iomap(start, size);
374
365 if (!prz->vaddr) { 375 if (!prz->vaddr) {
366 pr_err("%s: Failed to map %u pages\n", __func__, page_count); 376 pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
377 (unsigned long long)size, (unsigned long long)start);
367 return -ENOMEM; 378 return -ENOMEM;
368 } 379 }
369 380
@@ -373,6 +384,79 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
373 return 0; 384 return 0;
374} 385}
375 386
387static int __init persistent_ram_post_init(struct persistent_ram_zone *prz, bool ecc)
388{
389 int ret;
390
391 prz->ecc = ecc;
392
393 ret = persistent_ram_init_ecc(prz, prz->buffer_size);
394 if (ret)
395 return ret;
396
397 if (prz->buffer->sig == PERSISTENT_RAM_SIG) {
398 if (buffer_size(prz) > prz->buffer_size ||
399 buffer_start(prz) > buffer_size(prz))
400 pr_info("persistent_ram: found existing invalid buffer,"
401 " size %zu, start %zu\n",
402 buffer_size(prz), buffer_start(prz));
403 else {
404 pr_info("persistent_ram: found existing buffer,"
405 " size %zu, start %zu\n",
406 buffer_size(prz), buffer_start(prz));
407 persistent_ram_save_old(prz);
408 }
409 } else {
410 pr_info("persistent_ram: no valid data in buffer"
411 " (sig = 0x%08x)\n", prz->buffer->sig);
412 }
413
414 prz->buffer->sig = PERSISTENT_RAM_SIG;
415 atomic_set(&prz->buffer->start, 0);
416 atomic_set(&prz->buffer->size, 0);
417
418 return 0;
419}
420
421void persistent_ram_free(struct persistent_ram_zone *prz)
422{
423 if (pfn_valid(prz->paddr >> PAGE_SHIFT)) {
424 vunmap(prz->vaddr);
425 } else {
426 iounmap(prz->vaddr);
427 release_mem_region(prz->paddr, prz->size);
428 }
429 persistent_ram_free_old(prz);
430 kfree(prz);
431}
432
433struct persistent_ram_zone * __init persistent_ram_new(phys_addr_t start,
434 size_t size,
435 bool ecc)
436{
437 struct persistent_ram_zone *prz;
438 int ret = -ENOMEM;
439
440 prz = kzalloc(sizeof(struct persistent_ram_zone), GFP_KERNEL);
441 if (!prz) {
442 pr_err("persistent_ram: failed to allocate persistent ram zone\n");
443 goto err;
444 }
445
446 ret = persistent_ram_buffer_map(start, size, prz);
447 if (ret)
448 goto err;
449
450 persistent_ram_post_init(prz, ecc);
451 persistent_ram_update_header_ecc(prz);
452
453 return prz;
454err:
455 kfree(prz);
456 return ERR_PTR(ret);
457}
458
459#ifndef MODULE
376static int __init persistent_ram_buffer_init(const char *name, 460static int __init persistent_ram_buffer_init(const char *name,
377 struct persistent_ram_zone *prz) 461 struct persistent_ram_zone *prz)
378{ 462{
@@ -407,39 +491,13 @@ struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc)
407 goto err; 491 goto err;
408 } 492 }
409 493
410 INIT_LIST_HEAD(&prz->node);
411
412 ret = persistent_ram_buffer_init(dev_name(dev), prz); 494 ret = persistent_ram_buffer_init(dev_name(dev), prz);
413 if (ret) { 495 if (ret) {
414 pr_err("persistent_ram: failed to initialize buffer\n"); 496 pr_err("persistent_ram: failed to initialize buffer\n");
415 goto err; 497 goto err;
416 } 498 }
417 499
418 prz->ecc = ecc; 500 persistent_ram_post_init(prz, ecc);
419 ret = persistent_ram_init_ecc(prz, prz->buffer_size);
420 if (ret)
421 goto err;
422
423 if (prz->buffer->sig == PERSISTENT_RAM_SIG) {
424 if (buffer_size(prz) > prz->buffer_size ||
425 buffer_start(prz) > buffer_size(prz))
426 pr_info("persistent_ram: found existing invalid buffer,"
427 " size %ld, start %ld\n",
428 buffer_size(prz), buffer_start(prz));
429 else {
430 pr_info("persistent_ram: found existing buffer,"
431 " size %ld, start %ld\n",
432 buffer_size(prz), buffer_start(prz));
433 persistent_ram_save_old(prz);
434 }
435 } else {
436 pr_info("persistent_ram: no valid data in buffer"
437 " (sig = 0x%08x)\n", prz->buffer->sig);
438 }
439
440 prz->buffer->sig = PERSISTENT_RAM_SIG;
441 atomic_set(&prz->buffer->start, 0);
442 atomic_set(&prz->buffer->size, 0);
443 501
444 return prz; 502 return prz;
445err: 503err:
@@ -471,3 +529,4 @@ int __init persistent_ram_early_init(struct persistent_ram *ram)
471 529
472 return 0; 530 return 0;
473} 531}
532#endif
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 0237b84ba541..39737839ce29 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -238,6 +238,7 @@ header-y += map_to_7segment.h
238header-y += matroxfb.h 238header-y += matroxfb.h
239header-y += mdio.h 239header-y += mdio.h
240header-y += media.h 240header-y += media.h
241header-y += mei.h
241header-y += mempolicy.h 242header-y += mempolicy.h
242header-y += meye.h 243header-y += meye.h
243header-y += mii.h 244header-y += mii.h
@@ -380,6 +381,7 @@ header-y += unistd.h
380header-y += usbdevice_fs.h 381header-y += usbdevice_fs.h
381header-y += utime.h 382header-y += utime.h
382header-y += utsname.h 383header-y += utsname.h
384header-y += uuid.h
383header-y += uvcvideo.h 385header-y += uvcvideo.h
384header-y += v4l2-mediabus.h 386header-y += v4l2-mediabus.h
385header-y += v4l2-subdev.h 387header-y += v4l2-subdev.h
diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 975009e1cbe6..96c5c249b086 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -76,4 +76,7 @@ static inline int alarmtimer_callback_running(struct alarm *timer)
76} 76}
77 77
78 78
79/* Provide way to access the rtc device being used by alarmtimers */
80struct rtc_device *alarmtimer_get_rtcdev(void);
81
79#endif 82#endif
diff --git a/drivers/staging/iio/buffer.h b/include/linux/iio/buffer.h
index df2046dcb623..fb0fe46fd659 100644
--- a/drivers/staging/iio/buffer.h
+++ b/include/linux/iio/buffer.h
@@ -10,7 +10,7 @@
10#ifndef _IIO_BUFFER_GENERIC_H_ 10#ifndef _IIO_BUFFER_GENERIC_H_
11#define _IIO_BUFFER_GENERIC_H_ 11#define _IIO_BUFFER_GENERIC_H_
12#include <linux/sysfs.h> 12#include <linux/sysfs.h>
13#include "iio.h" 13#include <linux/iio/iio.h>
14 14
15#ifdef CONFIG_IIO_BUFFER 15#ifdef CONFIG_IIO_BUFFER
16 16
@@ -56,7 +56,6 @@ struct iio_buffer_access_funcs {
56 * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode 56 * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode
57 * control method is used 57 * control method is used
58 * @scan_mask: [INTERN] bitmask used in masking scan mode elements 58 * @scan_mask: [INTERN] bitmask used in masking scan mode elements
59 * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
60 * @scan_timestamp: [INTERN] does the scan mode include a timestamp 59 * @scan_timestamp: [INTERN] does the scan mode include a timestamp
61 * @access: [DRIVER] buffer access functions associated with the 60 * @access: [DRIVER] buffer access functions associated with the
62 * implementation. 61 * implementation.
@@ -74,7 +73,6 @@ struct iio_buffer {
74 struct attribute_group *scan_el_attrs; 73 struct attribute_group *scan_el_attrs;
75 long *scan_mask; 74 long *scan_mask;
76 bool scan_timestamp; 75 bool scan_timestamp;
77 unsigned scan_index_timestamp;
78 const struct iio_buffer_access_funcs *access; 76 const struct iio_buffer_access_funcs *access;
79 struct list_head scan_el_dev_attr_list; 77 struct list_head scan_el_dev_attr_list;
80 struct attribute_group scan_el_group; 78 struct attribute_group scan_el_group;
diff --git a/drivers/staging/iio/consumer.h b/include/linux/iio/consumer.h
index 36a060cd3a21..1a15e560a5a1 100644
--- a/drivers/staging/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -9,7 +9,7 @@
9 */ 9 */
10#ifndef _IIO_INKERN_CONSUMER_H_ 10#ifndef _IIO_INKERN_CONSUMER_H_
11#define _IIO_INKERN_CONSUMER_H 11#define _IIO_INKERN_CONSUMER_H
12#include "types.h" 12#include <linux/iio/types.h>
13 13
14struct iio_dev; 14struct iio_dev;
15struct iio_chan_spec; 15struct iio_chan_spec;
diff --git a/drivers/staging/iio/driver.h b/include/linux/iio/driver.h
index a4f8b2e05af5..a4f8b2e05af5 100644
--- a/drivers/staging/iio/driver.h
+++ b/include/linux/iio/driver.h
diff --git a/drivers/staging/iio/events.h b/include/linux/iio/events.h
index c25f0e3c92e9..b5acbf93c5da 100644
--- a/drivers/staging/iio/events.h
+++ b/include/linux/iio/events.h
@@ -11,7 +11,7 @@
11 11
12#include <linux/ioctl.h> 12#include <linux/ioctl.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include "types.h" 14#include <linux/iio/types.h>
15 15
16/** 16/**
17 * struct iio_event_data - The actual event being pushed to userspace 17 * struct iio_event_data - The actual event being pushed to userspace
diff --git a/drivers/staging/iio/iio.h b/include/linux/iio/iio.h
index b9cd454f69e2..3a4f6a3ab80d 100644
--- a/drivers/staging/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -12,22 +12,17 @@
12 12
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/cdev.h> 14#include <linux/cdev.h>
15#include "types.h" 15#include <linux/iio/types.h>
16/* IIO TODO LIST */ 16/* IIO TODO LIST */
17/* 17/*
18 * Provide means of adjusting timer accuracy. 18 * Provide means of adjusting timer accuracy.
19 * Currently assumes nano seconds. 19 * Currently assumes nano seconds.
20 */ 20 */
21 21
22enum iio_data_type {
23 IIO_RAW,
24 IIO_PROCESSED,
25};
26
27/* Could add the raw attributes as well - allowing buffer only devices */
28enum iio_chan_info_enum { 22enum iio_chan_info_enum {
29 /* 0 is reserved for raw attributes */ 23 IIO_CHAN_INFO_RAW = 0,
30 IIO_CHAN_INFO_SCALE = 1, 24 IIO_CHAN_INFO_PROCESSED,
25 IIO_CHAN_INFO_SCALE,
31 IIO_CHAN_INFO_OFFSET, 26 IIO_CHAN_INFO_OFFSET,
32 IIO_CHAN_INFO_CALIBSCALE, 27 IIO_CHAN_INFO_CALIBSCALE,
33 IIO_CHAN_INFO_CALIBBIAS, 28 IIO_CHAN_INFO_CALIBBIAS,
@@ -36,11 +31,19 @@ enum iio_chan_info_enum {
36 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW, 31 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW,
37 IIO_CHAN_INFO_AVERAGE_RAW, 32 IIO_CHAN_INFO_AVERAGE_RAW,
38 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY, 33 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
34 IIO_CHAN_INFO_SAMP_FREQ,
35 IIO_CHAN_INFO_FREQUENCY,
36 IIO_CHAN_INFO_PHASE,
37 IIO_CHAN_INFO_HARDWAREGAIN,
39}; 38};
40 39
41#define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2) 40#define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2)
42#define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1) 41#define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1)
43 42
43#define IIO_CHAN_INFO_RAW_SEPARATE_BIT \
44 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_RAW)
45#define IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT \
46 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PROCESSED)
44#define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \ 47#define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \
45 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE) 48 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE)
46#define IIO_CHAN_INFO_SCALE_SHARED_BIT \ 49#define IIO_CHAN_INFO_SCALE_SHARED_BIT \
@@ -81,6 +84,22 @@ enum iio_chan_info_enum {
81#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \ 84#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \
82 IIO_CHAN_INFO_SEPARATE_BIT( \ 85 IIO_CHAN_INFO_SEPARATE_BIT( \
83 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) 86 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY)
87#define IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT \
88 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SAMP_FREQ)
89#define IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT \
90 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SAMP_FREQ)
91#define IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT \
92 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_FREQUENCY)
93#define IIO_CHAN_INFO_FREQUENCY_SHARED_BIT \
94 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_FREQUENCY)
95#define IIO_CHAN_INFO_PHASE_SEPARATE_BIT \
96 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PHASE)
97#define IIO_CHAN_INFO_PHASE_SHARED_BIT \
98 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PHASE)
99#define IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT \
100 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
101#define IIO_CHAN_INFO_HARDWAREGAIN_SHARED_BIT \
102 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
84 103
85enum iio_endian { 104enum iio_endian {
86 IIO_CPU, 105 IIO_CPU,
@@ -97,14 +116,17 @@ struct iio_dev;
97 * @shared: Whether this attribute is shared between all channels. 116 * @shared: Whether this attribute is shared between all channels.
98 * @read: Read callback for this info attribute, may be NULL. 117 * @read: Read callback for this info attribute, may be NULL.
99 * @write: Write callback for this info attribute, may be NULL. 118 * @write: Write callback for this info attribute, may be NULL.
119 * @private: Data private to the driver.
100 */ 120 */
101struct iio_chan_spec_ext_info { 121struct iio_chan_spec_ext_info {
102 const char *name; 122 const char *name;
103 bool shared; 123 bool shared;
104 ssize_t (*read)(struct iio_dev *, struct iio_chan_spec const *, 124 ssize_t (*read)(struct iio_dev *, uintptr_t private,
105 char *buf); 125 struct iio_chan_spec const *, char *buf);
106 ssize_t (*write)(struct iio_dev *, struct iio_chan_spec const *, 126 ssize_t (*write)(struct iio_dev *, uintptr_t private,
107 const char *buf, size_t len); 127 struct iio_chan_spec const *, const char *buf,
128 size_t len);
129 uintptr_t private;
108}; 130};
109 131
110/** 132/**
@@ -136,8 +158,6 @@ struct iio_chan_spec_ext_info {
136 * correspond to the first name that the channel is referred 158 * correspond to the first name that the channel is referred
137 * to by in the datasheet (e.g. IND), or the nearest 159 * to by in the datasheet (e.g. IND), or the nearest
138 * possible compound name (e.g. IND-INC). 160 * possible compound name (e.g. IND-INC).
139 * @processed_val: Flag to specify the data access attribute should be
140 * *_input rather than *_raw.
141 * @modified: Does a modifier apply to this channel. What these are 161 * @modified: Does a modifier apply to this channel. What these are
142 * depends on the channel type. Modifier is set in 162 * depends on the channel type. Modifier is set in
143 * channel2. Examples are IIO_MOD_X for axial sensors about 163 * channel2. Examples are IIO_MOD_X for axial sensors about
@@ -164,9 +184,8 @@ struct iio_chan_spec {
164 long info_mask; 184 long info_mask;
165 long event_mask; 185 long event_mask;
166 const struct iio_chan_spec_ext_info *ext_info; 186 const struct iio_chan_spec_ext_info *ext_info;
167 char *extend_name; 187 const char *extend_name;
168 const char *datasheet_name; 188 const char *datasheet_name;
169 unsigned processed_val:1;
170 unsigned modified:1; 189 unsigned modified:1;
171 unsigned indexed:1; 190 unsigned indexed:1;
172 unsigned output:1; 191 unsigned output:1;
@@ -176,23 +195,6 @@ struct iio_chan_spec {
176#define IIO_ST(si, rb, sb, sh) \ 195#define IIO_ST(si, rb, sb, sh) \
177 { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh } 196 { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh }
178 197
179/* Macro assumes input channels */
180#define IIO_CHAN(_type, _mod, _indexed, _proc, _name, _chan, _chan2, \
181 _inf_mask, _address, _si, _stype, _event_mask) \
182 { .type = _type, \
183 .output = 0, \
184 .modified = _mod, \
185 .indexed = _indexed, \
186 .processed_val = _proc, \
187 .extend_name = _name, \
188 .channel = _chan, \
189 .channel2 = _chan2, \
190 .info_mask = _inf_mask, \
191 .address = _address, \
192 .scan_index = _si, \
193 .scan_type = _stype, \
194 .event_mask = _event_mask }
195
196#define IIO_CHAN_SOFT_TIMESTAMP(_si) \ 198#define IIO_CHAN_SOFT_TIMESTAMP(_si) \
197 { .type = IIO_TIMESTAMP, .channel = -1, \ 199 { .type = IIO_TIMESTAMP, .channel = -1, \
198 .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) } 200 .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) }
@@ -315,12 +317,15 @@ struct iio_buffer_setup_ops {
315 * and owner 317 * and owner
316 * @event_interface: [INTERN] event chrdevs associated with interrupt lines 318 * @event_interface: [INTERN] event chrdevs associated with interrupt lines
317 * @buffer: [DRIVER] any buffer present 319 * @buffer: [DRIVER] any buffer present
320 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
318 * @mlock: [INTERN] lock used to prevent simultaneous device state 321 * @mlock: [INTERN] lock used to prevent simultaneous device state
319 * changes 322 * changes
320 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks 323 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
321 * @masklength: [INTERN] the length of the mask established from 324 * @masklength: [INTERN] the length of the mask established from
322 * channels 325 * channels
323 * @active_scan_mask: [INTERN] union of all scan masks requested by buffers 326 * @active_scan_mask: [INTERN] union of all scan masks requested by buffers
327 * @scan_timestamp: [INTERN] set if any buffers have requested timestamp
328 * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
324 * @trig: [INTERN] current device trigger (buffer modes) 329 * @trig: [INTERN] current device trigger (buffer modes)
325 * @pollfunc: [DRIVER] function run on trigger being received 330 * @pollfunc: [DRIVER] function run on trigger being received
326 * @channels: [DRIVER] channel specification structure table 331 * @channels: [DRIVER] channel specification structure table
@@ -331,6 +336,8 @@ struct iio_buffer_setup_ops {
331 * @name: [DRIVER] name of the device. 336 * @name: [DRIVER] name of the device.
332 * @info: [DRIVER] callbacks and constant info from driver 337 * @info: [DRIVER] callbacks and constant info from driver
333 * @info_exist_lock: [INTERN] lock to prevent use during removal 338 * @info_exist_lock: [INTERN] lock to prevent use during removal
339 * @setup_ops: [DRIVER] callbacks to call before and after buffer
340 * enable/disable
334 * @chrdev: [INTERN] associated character device 341 * @chrdev: [INTERN] associated character device
335 * @groups: [INTERN] attribute groups 342 * @groups: [INTERN] attribute groups
336 * @groupcounter: [INTERN] index of next attribute group 343 * @groupcounter: [INTERN] index of next attribute group
@@ -348,11 +355,14 @@ struct iio_dev {
348 struct iio_event_interface *event_interface; 355 struct iio_event_interface *event_interface;
349 356
350 struct iio_buffer *buffer; 357 struct iio_buffer *buffer;
358 int scan_bytes;
351 struct mutex mlock; 359 struct mutex mlock;
352 360
353 const unsigned long *available_scan_masks; 361 const unsigned long *available_scan_masks;
354 unsigned masklength; 362 unsigned masklength;
355 const unsigned long *active_scan_mask; 363 const unsigned long *active_scan_mask;
364 bool scan_timestamp;
365 unsigned scan_index_timestamp;
356 struct iio_trigger *trig; 366 struct iio_trigger *trig;
357 struct iio_poll_func *pollfunc; 367 struct iio_poll_func *pollfunc;
358 368
@@ -408,22 +418,33 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
408extern struct bus_type iio_bus_type; 418extern struct bus_type iio_bus_type;
409 419
410/** 420/**
411 * iio_put_device() - reference counted deallocation of struct device 421 * iio_device_put() - reference counted deallocation of struct device
412 * @dev: the iio_device containing the device 422 * @dev: the iio_device containing the device
413 **/ 423 **/
414static inline void iio_put_device(struct iio_dev *indio_dev) 424static inline void iio_device_put(struct iio_dev *indio_dev)
415{ 425{
416 if (indio_dev) 426 if (indio_dev)
417 put_device(&indio_dev->dev); 427 put_device(&indio_dev->dev);
418}; 428};
419 429
430/**
431 * dev_to_iio_dev() - Get IIO device struct from a device struct
432 * @dev: The device embedded in the IIO device
433 *
434 * Note: The device must be a IIO device, otherwise the result is undefined.
435 */
436static inline struct iio_dev *dev_to_iio_dev(struct device *dev)
437{
438 return container_of(dev, struct iio_dev, dev);
439}
440
420/* Can we make this smaller? */ 441/* Can we make this smaller? */
421#define IIO_ALIGN L1_CACHE_BYTES 442#define IIO_ALIGN L1_CACHE_BYTES
422/** 443/**
423 * iio_allocate_device() - allocate an iio_dev from a driver 444 * iio_device_alloc() - allocate an iio_dev from a driver
424 * @sizeof_priv: Space to allocate for private structure. 445 * @sizeof_priv: Space to allocate for private structure.
425 **/ 446 **/
426struct iio_dev *iio_allocate_device(int sizeof_priv); 447struct iio_dev *iio_device_alloc(int sizeof_priv);
427 448
428static inline void *iio_priv(const struct iio_dev *indio_dev) 449static inline void *iio_priv(const struct iio_dev *indio_dev)
429{ 450{
@@ -437,10 +458,10 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv)
437} 458}
438 459
439/** 460/**
440 * iio_free_device() - free an iio_dev from a driver 461 * iio_device_free() - free an iio_dev from a driver
441 * @dev: the iio_dev associated with the device 462 * @dev: the iio_dev associated with the device
442 **/ 463 **/
443void iio_free_device(struct iio_dev *indio_dev); 464void iio_device_free(struct iio_dev *indio_dev);
444 465
445/** 466/**
446 * iio_buffer_enabled() - helper function to test if the buffer is enabled 467 * iio_buffer_enabled() - helper function to test if the buffer is enabled
diff --git a/drivers/staging/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 9f7da016af04..014d5a13b32b 100644
--- a/drivers/staging/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -1,7 +1,7 @@
1 1
2#include <linux/kfifo.h> 2#include <linux/kfifo.h>
3#include "iio.h" 3#include <linux/iio/iio.h>
4#include "buffer.h" 4#include <linux/iio/buffer.h>
5 5
6struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev); 6struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev);
7void iio_kfifo_free(struct iio_buffer *r); 7void iio_kfifo_free(struct iio_buffer *r);
diff --git a/drivers/staging/iio/machine.h b/include/linux/iio/machine.h
index 0b1f19bfdc44..0b1f19bfdc44 100644
--- a/drivers/staging/iio/machine.h
+++ b/include/linux/iio/machine.h
diff --git a/drivers/staging/iio/sysfs.h b/include/linux/iio/sysfs.h
index bfedb73b850e..bfedb73b850e 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/include/linux/iio/sysfs.h
diff --git a/drivers/staging/iio/trigger.h b/include/linux/iio/trigger.h
index 1cfca231db8f..a9819940a84c 100644
--- a/drivers/staging/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -78,13 +78,13 @@ static inline struct iio_trigger *to_iio_trigger(struct device *d)
78 return container_of(d, struct iio_trigger, dev); 78 return container_of(d, struct iio_trigger, dev);
79}; 79};
80 80
81static inline void iio_put_trigger(struct iio_trigger *trig) 81static inline void iio_trigger_put(struct iio_trigger *trig)
82{ 82{
83 module_put(trig->ops->owner); 83 module_put(trig->ops->owner);
84 put_device(&trig->dev); 84 put_device(&trig->dev);
85}; 85};
86 86
87static inline void iio_get_trigger(struct iio_trigger *trig) 87static inline void iio_trigger_get(struct iio_trigger *trig)
88{ 88{
89 get_device(&trig->dev); 89 get_device(&trig->dev);
90 __module_get(trig->ops->owner); 90 __module_get(trig->ops->owner);
@@ -113,7 +113,7 @@ void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
113 113
114irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); 114irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
115 115
116__printf(1, 2) struct iio_trigger *iio_allocate_trigger(const char *fmt, ...); 116__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
117void iio_free_trigger(struct iio_trigger *trig); 117void iio_trigger_free(struct iio_trigger *trig);
118 118
119#endif /* _IIO_TRIGGER_H_ */ 119#endif /* _IIO_TRIGGER_H_ */
diff --git a/drivers/staging/iio/trigger_consumer.h b/include/linux/iio/trigger_consumer.h
index 60d64b356945..60d64b356945 100644
--- a/drivers/staging/iio/trigger_consumer.h
+++ b/include/linux/iio/trigger_consumer.h
diff --git a/drivers/staging/iio/types.h b/include/linux/iio/types.h
index 0c3213666901..1b073b1cc7c2 100644
--- a/drivers/staging/iio/types.h
+++ b/include/linux/iio/types.h
@@ -27,6 +27,7 @@ enum iio_chan_type {
27 IIO_ANGL, 27 IIO_ANGL,
28 IIO_TIMESTAMP, 28 IIO_TIMESTAMP,
29 IIO_CAPACITANCE, 29 IIO_CAPACITANCE,
30 IIO_ALTVOLTAGE,
30}; 31};
31 32
32enum iio_modifier { 33enum iio_modifier {
@@ -49,5 +50,6 @@ enum iio_modifier {
49#define IIO_VAL_INT 1 50#define IIO_VAL_INT 1
50#define IIO_VAL_INT_PLUS_MICRO 2 51#define IIO_VAL_INT_PLUS_MICRO 2
51#define IIO_VAL_INT_PLUS_NANO 3 52#define IIO_VAL_INT_PLUS_NANO 3
53#define IIO_VAL_INT_PLUS_MICRO_DB 4
52 54
53#endif /* _IIO_TYPES_H_ */ 55#endif /* _IIO_TYPES_H_ */
diff --git a/drivers/staging/mei/mei.h b/include/linux/mei.h
index bc0d8b69c49e..bc0d8b69c49e 100644
--- a/drivers/staging/mei/mei.h
+++ b/include/linux/mei.h
diff --git a/include/linux/platform_data/at91_adc.h b/include/linux/platform_data/at91_adc.h
new file mode 100644
index 000000000000..e15745b4f3a5
--- /dev/null
+++ b/include/linux/platform_data/at91_adc.h
@@ -0,0 +1,61 @@
1/*
2 * Copyright (C) 2011 Free Electrons
3 *
4 * Licensed under the GPLv2 or later.
5 */
6
7#ifndef _AT91_ADC_H_
8#define _AT91_ADC_H_
9
10/**
11 * struct at91_adc_reg_desc - Various informations relative to registers
12 * @channel_base: Base offset for the channel data registers
13 * @drdy_mask: Mask of the DRDY field in the relevant registers
14 (Interruptions registers mostly)
15 * @status_register: Offset of the Interrupt Status Register
16 * @trigger_register: Offset of the Trigger setup register
17 */
18struct at91_adc_reg_desc {
19 u8 channel_base;
20 u32 drdy_mask;
21 u8 status_register;
22 u8 trigger_register;
23};
24
25/**
26 * struct at91_adc_trigger - description of triggers
27 * @name: name of the trigger advertised to the user
28 * @value: value to set in the ADC's trigger setup register
29 to enable the trigger
30 * @is_external: Does the trigger rely on an external pin?
31 */
32struct at91_adc_trigger {
33 const char *name;
34 u8 value;
35 bool is_external;
36};
37
38/**
39 * struct at91_adc_data - platform data for ADC driver
40 * @channels_used: channels in use on the board as a bitmask
41 * @num_channels: global number of channels available on the board
42 * @registers: Registers definition on the board
43 * @startup_time: startup time of the ADC in microseconds
44 * @trigger_list: Triggers available in the ADC
45 * @trigger_number: Number of triggers available in the ADC
46 * @use_external_triggers: does the board has external triggers availables
47 * @vref: Reference voltage for the ADC in millivolts
48 */
49struct at91_adc_data {
50 unsigned long channels_used;
51 u8 num_channels;
52 struct at91_adc_reg_desc *registers;
53 u8 startup_time;
54 struct at91_adc_trigger *trigger_list;
55 u8 trigger_number;
56 bool use_external_triggers;
57 u16 vref;
58};
59
60extern void __init at91_add_device_adc(struct at91_adc_data *data);
61#endif
diff --git a/drivers/staging/android/persistent_ram.h b/include/linux/pstore_ram.h
index f41e2086c645..7ed7fd4dba49 100644
--- a/drivers/staging/android/persistent_ram.h
+++ b/include/linux/pstore_ram.h
@@ -1,4 +1,6 @@
1/* 1/*
2 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
3 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
2 * Copyright (C) 2011 Google, Inc. 4 * Copyright (C) 2011 Google, Inc.
3 * 5 *
4 * This software is licensed under the terms of the GNU General Public 6 * This software is licensed under the terms of the GNU General Public
@@ -12,13 +14,14 @@
12 * 14 *
13 */ 15 */
14 16
15#ifndef __LINUX_PERSISTENT_RAM_H__ 17#ifndef __LINUX_PSTORE_RAM_H__
16#define __LINUX_PERSISTENT_RAM_H__ 18#define __LINUX_PSTORE_RAM_H__
17 19
18#include <linux/device.h> 20#include <linux/device.h>
19#include <linux/kernel.h> 21#include <linux/kernel.h>
20#include <linux/list.h> 22#include <linux/list.h>
21#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/init.h>
22 25
23struct persistent_ram_buffer; 26struct persistent_ram_buffer;
24 27
@@ -38,7 +41,8 @@ struct persistent_ram {
38}; 41};
39 42
40struct persistent_ram_zone { 43struct persistent_ram_zone {
41 struct list_head node; 44 phys_addr_t paddr;
45 size_t size;
42 void *vaddr; 46 void *vaddr;
43 struct persistent_ram_buffer *buffer; 47 struct persistent_ram_buffer *buffer;
44 size_t buffer_size; 48 size_t buffer_size;
@@ -57,12 +61,14 @@ struct persistent_ram_zone {
57 61
58 char *old_log; 62 char *old_log;
59 size_t old_log_size; 63 size_t old_log_size;
60 size_t old_log_footer_size;
61 bool early;
62}; 64};
63 65
64int persistent_ram_early_init(struct persistent_ram *ram); 66int persistent_ram_early_init(struct persistent_ram *ram);
65 67
68struct persistent_ram_zone * __init persistent_ram_new(phys_addr_t start,
69 size_t size,
70 bool ecc);
71void persistent_ram_free(struct persistent_ram_zone *prz);
66struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev, 72struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev,
67 bool ecc); 73 bool ecc);
68 74
@@ -75,4 +81,18 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz);
75ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, 81ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
76 char *str, size_t len); 82 char *str, size_t len);
77 83
84/*
85 * Ramoops platform data
86 * @mem_size memory size for ramoops
87 * @mem_address physical memory address to contain ramoops
88 */
89
90struct ramoops_platform_data {
91 unsigned long mem_size;
92 unsigned long mem_address;
93 unsigned long record_size;
94 int dump_oops;
95 bool ecc;
96};
97
78#endif 98#endif
diff --git a/include/linux/ramoops.h b/include/linux/ramoops.h
deleted file mode 100644
index 484fef81cd3a..000000000000
--- a/include/linux/ramoops.h
+++ /dev/null
@@ -1,17 +0,0 @@
1#ifndef __RAMOOPS_H
2#define __RAMOOPS_H
3
4/*
5 * Ramoops platform data
6 * @mem_size memory size for ramoops
7 * @mem_address physical memory address to contain ramoops
8 */
9
10struct ramoops_platform_data {
11 unsigned long mem_size;
12 unsigned long mem_address;
13 unsigned long record_size;
14 int dump_oops;
15};
16
17#endif
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 5b7efbfcee4e..f86c37bfd4a0 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -54,6 +54,8 @@ typedef struct {
54 UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \ 54 UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
55 0x00, 0x00, 0x00, 0x00) 55 0x00, 0x00, 0x00, 0x00)
56 56
57#ifdef __KERNEL__
58
57static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2) 59static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
58{ 60{
59 return memcmp(&u1, &u2, sizeof(uuid_le)); 61 return memcmp(&u1, &u2, sizeof(uuid_le));
@@ -67,4 +69,6 @@ static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)
67extern void uuid_le_gen(uuid_le *u); 69extern void uuid_le_gen(uuid_le *u);
68extern void uuid_be_gen(uuid_be *u); 70extern void uuid_be_gen(uuid_be *u);
69 71
72#endif /* __KERNEL__ */
73
70#endif 74#endif
diff --git a/drivers/staging/vme/vme.h b/include/linux/vme.h
index c9d65bf14cec..c9d65bf14cec 100644
--- a/drivers/staging/vme/vme.h
+++ b/include/linux/vme.h
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 8a538c55fc7b..aa27d391bfc8 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -59,7 +59,7 @@ static DEFINE_SPINLOCK(rtcdev_lock);
59 * If one has not already been chosen, it checks to see if a 59 * If one has not already been chosen, it checks to see if a
60 * functional rtc device is available. 60 * functional rtc device is available.
61 */ 61 */
62static struct rtc_device *alarmtimer_get_rtcdev(void) 62struct rtc_device *alarmtimer_get_rtcdev(void)
63{ 63{
64 unsigned long flags; 64 unsigned long flags;
65 struct rtc_device *ret; 65 struct rtc_device *ret;
@@ -115,7 +115,7 @@ static void alarmtimer_rtc_interface_remove(void)
115 class_interface_unregister(&alarmtimer_rtc_interface); 115 class_interface_unregister(&alarmtimer_rtc_interface);
116} 116}
117#else 117#else
118static inline struct rtc_device *alarmtimer_get_rtcdev(void) 118struct rtc_device *alarmtimer_get_rtcdev(void)
119{ 119{
120 return NULL; 120 return NULL;
121} 121}