Merge git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-2.6-dm
authorLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 03:30:50 +0000 (19:30 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 03:30:50 +0000 (19:30 -0800)
* git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-2.6-dm: (44 commits)
  dm raid1: report fault status
  dm raid1: handle read failures
  dm raid1: fix EIO after log failure
  dm raid1: handle recovery failures
  dm raid1: handle write failures
  dm snapshot: combine consecutive exceptions in memory
  dm: stripe enhanced status return
  dm: stripe trigger event on failure
  dm log: auto load modules
  dm: move deferred bio flushing to workqueue
  dm crypt: use async crypto
  dm crypt: prepare async callback fn
  dm crypt: add completion for async
  dm crypt: add async request mempool
  dm crypt: extract scatterlist processing
  dm crypt: tidy io ref counting
  dm crypt: introduce crypt_write_io_loop
  dm crypt: abstract crypt_write_done
  dm crypt: store sector mapping in dm_crypt_io
  dm crypt: move queue functions
  ...

232 files changed:
Documentation/DocBook/scsi.tmpl
Documentation/hwmon/ads7828 [new file with mode: 0644]
Documentation/hwmon/it87
Documentation/hwmon/lm78
Documentation/hwmon/lm87
Documentation/hwmon/userspace-tools
Documentation/hwmon/w83627ehf
Documentation/hwmon/w83627hf
Documentation/hwmon/w83781d
Documentation/hwmon/w83l786ng [new file with mode: 0644]
Documentation/i2c/busses/i2c-piix4
Documentation/scsi/ChangeLog.arcmsr
Documentation/scsi/scsi_mid_low_api.txt
Documentation/vm/slabinfo.c
MAINTAINERS
arch/m68k/kernel/process.c
arch/powerpc/kernel/asm-offsets.c
arch/x86/Kconfig
drivers/char/pcmcia/Kconfig
drivers/char/pcmcia/Makefile
drivers/char/pcmcia/ipwireless/Makefile [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/hardware.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/hardware.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/main.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/main.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/network.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/network.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/setup_protocol.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/tty.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/tty.h [new file with mode: 0644]
drivers/firmware/dmi_scan.c
drivers/hwmon/Kconfig
drivers/hwmon/Makefile
drivers/hwmon/abituguru3.c
drivers/hwmon/adm1021.c
drivers/hwmon/adm1025.c
drivers/hwmon/adm1026.c
drivers/hwmon/adm1031.c
drivers/hwmon/adm9240.c
drivers/hwmon/ads7828.c [new file with mode: 0644]
drivers/hwmon/adt7470.c
drivers/hwmon/asb100.c
drivers/hwmon/dme1737.c
drivers/hwmon/ds1621.c
drivers/hwmon/f71805f.c
drivers/hwmon/f71882fg.c
drivers/hwmon/fscher.c
drivers/hwmon/fschmd.c
drivers/hwmon/fscpos.c
drivers/hwmon/gl518sm.c
drivers/hwmon/gl520sm.c
drivers/hwmon/it87.c
drivers/hwmon/lm75.c
drivers/hwmon/lm77.c
drivers/hwmon/lm78.c
drivers/hwmon/lm80.c
drivers/hwmon/lm83.c
drivers/hwmon/lm85.c
drivers/hwmon/lm87.c
drivers/hwmon/lm90.c
drivers/hwmon/lm92.c
drivers/hwmon/pc87360.c
drivers/hwmon/pc87427.c
drivers/hwmon/smsc47b397.c
drivers/hwmon/smsc47m1.c
drivers/hwmon/smsc47m192.c
drivers/hwmon/vt1211.c
drivers/hwmon/vt8231.c
drivers/hwmon/w83627ehf.c
drivers/hwmon/w83627hf.c
drivers/hwmon/w83781d.c
drivers/hwmon/w83791d.c
drivers/hwmon/w83793.c
drivers/hwmon/w83l785ts.c
drivers/hwmon/w83l786ng.c [new file with mode: 0644]
drivers/i2c/chips/eeprom.c
drivers/i2c/chips/pcf8574.c
drivers/i2c/chips/pcf8591.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/enclosure.c [new file with mode: 0644]
drivers/scsi/Kconfig
drivers/scsi/Makefile
drivers/scsi/NCR53C9x.c [deleted file]
drivers/scsi/NCR53C9x.h [deleted file]
drivers/scsi/aacraid/aachba.c
drivers/scsi/aacraid/commctrl.c
drivers/scsi/aacraid/linit.c
drivers/scsi/advansys.c
drivers/scsi/arcmsr/arcmsr.h
drivers/scsi/arcmsr/arcmsr_hba.c
drivers/scsi/arm/acornscsi.c
drivers/scsi/arm/scsi.h
drivers/scsi/blz1230.c [deleted file]
drivers/scsi/blz2060.c [deleted file]
drivers/scsi/cyberstorm.c [deleted file]
drivers/scsi/cyberstormII.c [deleted file]
drivers/scsi/dc395x.c
drivers/scsi/dec_esp.c [deleted file]
drivers/scsi/fastlane.c [deleted file]
drivers/scsi/iscsi_tcp.c
drivers/scsi/libiscsi.c
drivers/scsi/mac_esp.c [deleted file]
drivers/scsi/mca_53c9x.c [deleted file]
drivers/scsi/oktagon_esp.c [deleted file]
drivers/scsi/oktagon_io.S [deleted file]
drivers/scsi/ps3rom.c
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_gbl.h
drivers/scsi/qla2xxx/qla_init.c
drivers/scsi/qla2xxx/qla_inline.h
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_mbx.c
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla2xxx/qla_sup.c
drivers/scsi/qla2xxx/qla_version.h
drivers/scsi/qla4xxx/ql4_init.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/scsi.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_transport_iscsi.c
drivers/scsi/sd.c
drivers/scsi/ses.c [new file with mode: 0644]
drivers/scsi/sg.c
drivers/scsi/sr.c
drivers/scsi/sr.h
drivers/scsi/sr_ioctl.c
drivers/scsi/sun3x_esp.c
drivers/scsi/sym53c8xx_2/sym_hipd.c
drivers/scsi/u14-34f.c
fs/Kconfig
fs/nfs/write.c
fs/xfs/Makefile-linux-2.6
fs/xfs/linux-2.6/spin.h [deleted file]
fs/xfs/linux-2.6/xfs_aops.c
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_buf.h
fs/xfs/linux-2.6/xfs_export.c
fs/xfs/linux-2.6/xfs_file.c
fs/xfs/linux-2.6/xfs_globals.c
fs/xfs/linux-2.6/xfs_ioctl.c
fs/xfs/linux-2.6/xfs_ioctl32.c
fs/xfs/linux-2.6/xfs_iops.c
fs/xfs/linux-2.6/xfs_linux.h
fs/xfs/linux-2.6/xfs_lrw.c
fs/xfs/linux-2.6/xfs_lrw.h
fs/xfs/linux-2.6/xfs_super.c
fs/xfs/linux-2.6/xfs_vnode.c
fs/xfs/linux-2.6/xfs_vnode.h
fs/xfs/quota/xfs_dquot.c
fs/xfs/quota/xfs_dquot.h
fs/xfs/quota/xfs_dquot_item.c
fs/xfs/quota/xfs_qm.c
fs/xfs/quota/xfs_qm.h
fs/xfs/quota/xfs_qm_syscalls.c
fs/xfs/support/debug.c
fs/xfs/support/ktrace.c
fs/xfs/support/ktrace.h
fs/xfs/support/uuid.c
fs/xfs/xfs.h
fs/xfs/xfs_acl.c
fs/xfs/xfs_acl.h
fs/xfs/xfs_ag.h
fs/xfs/xfs_alloc.c
fs/xfs/xfs_attr.c
fs/xfs/xfs_attr_leaf.c
fs/xfs/xfs_bit.c
fs/xfs/xfs_bit.h
fs/xfs/xfs_bmap.c
fs/xfs/xfs_bmap.h
fs/xfs/xfs_bmap_btree.c
fs/xfs/xfs_btree.h
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_da_btree.c
fs/xfs/xfs_da_btree.h
fs/xfs/xfs_dfrag.c
fs/xfs/xfs_dinode.h
fs/xfs/xfs_dir2.c
fs/xfs/xfs_error.c
fs/xfs/xfs_error.h
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_filestream.c
fs/xfs/xfs_fs.h
fs/xfs/xfs_fsops.c
fs/xfs/xfs_ialloc_btree.h
fs/xfs/xfs_iget.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode.h
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_iocore.c [deleted file]
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_itable.c
fs/xfs/xfs_log.c
fs/xfs/xfs_log.h
fs/xfs/xfs_log_priv.h
fs/xfs/xfs_log_recover.c
fs/xfs/xfs_mount.c
fs/xfs/xfs_mount.h
fs/xfs/xfs_mru_cache.c
fs/xfs/xfs_qmops.c
fs/xfs/xfs_rename.c
fs/xfs/xfs_rtalloc.c
fs/xfs/xfs_rtalloc.h
fs/xfs/xfs_rw.h
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h
fs/xfs/xfs_trans_ail.c
fs/xfs/xfs_trans_item.c
fs/xfs/xfs_trans_priv.h
fs/xfs/xfs_utils.c
fs/xfs/xfs_utils.h
fs/xfs/xfs_vfsops.c
fs/xfs/xfs_vfsops.h
fs/xfs/xfs_vnodeops.c
fs/xfs/xfs_vnodeops.h
include/linux/dmi.h
include/linux/enclosure.h [new file with mode: 0644]
include/linux/hrtimer.h
include/linux/i2c-id.h
include/linux/ktime.h
include/linux/mm_types.h
include/linux/slub_def.h
include/scsi/iscsi_proto.h
include/scsi/libiscsi.h
include/scsi/scsi.h
include/scsi/scsi_host.h
include/scsi/scsi_transport_iscsi.h
lib/Kconfig.debug
mm/slub.c

index f299ab182bbe0551e6f2c5bf9bb1cd4b1910d7d9..10a150ae2a7e383557c6d7c39be70353f500494f 100644 (file)
@@ -12,7 +12,7 @@
         <surname>Bottomley</surname>
         <affiliation>
           <address>
-            <email>James.Bottomley@steeleye.com</email>
+            <email>James.Bottomley@hansenpartnership.com</email>
           </address>
         </affiliation>
       </author>
diff --git a/Documentation/hwmon/ads7828 b/Documentation/hwmon/ads7828
new file mode 100644 (file)
index 0000000..75bc4be
--- /dev/null
@@ -0,0 +1,36 @@
+Kernel driver ads7828
+=====================
+
+Supported chips:
+  * Texas Instruments/Burr-Brown ADS7828
+    Prefix: 'ads7828'
+    Addresses scanned: I2C 0x48, 0x49, 0x4a, 0x4b
+    Datasheet: Publicly available at the Texas Instruments website :
+               http://focus.ti.com/lit/ds/symlink/ads7828.pdf
+
+Authors:
+        Steve Hardy <steve@linuxrealtime.co.uk>
+
+Module Parameters
+-----------------
+
+* se_input: bool (default Y)
+  Single ended operation - set to N for differential mode
+* int_vref: bool (default Y)
+  Operate with the internal 2.5V reference - set to N for external reference
+* vref_mv: int (default 2500)
+  If using an external reference, set this to the reference voltage in mV
+
+Description
+-----------
+
+This driver implements support for the Texas Instruments ADS7828.
+
+This device is a 12-bit 8-channel A-D converter.
+
+It can operate in single ended mode (8 +ve inputs) or in differential mode,
+where 4 differential pairs can be measured.
+
+The chip also has the facility to use an external voltage reference.  This
+may be required if your hardware supplies the ADS7828 from a 5V supply, see
+the datasheet for more details.
index 5b704a40256b63a2ba896568db72c464e2ab788d..f4ce1fdbeff664b88bd35c735968d977f6d14efd 100644 (file)
@@ -30,7 +30,7 @@ Supported chips:
     Datasheet: No longer be available
 
 Authors:
-    Christophe Gauthron <chrisg@0-in.com>
+    Christophe Gauthron
     Jean Delvare <khali@linux-fr.org>
 
 
index dfc318a60fd46dbce33bcdfdb78f2e7639a0fe6f..60932e26abaaafb28f5aeb199d1a0f80d9c6a492 100644 (file)
@@ -4,12 +4,12 @@ Kernel driver lm78
 Supported chips:
   * National Semiconductor LM78 / LM78-J
     Prefix: 'lm78'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: Publicly available at the National Semiconductor website
                http://www.national.com/
   * National Semiconductor LM79
     Prefix: 'lm79'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: Publicly available at the National Semiconductor website
                http://www.national.com/
 
index c952c57f0e11cb86230e7c9dcbd6c8b7e09dfd16..ec27aa1b94cbc327337ea3a8477fc032eb36bcd2 100644 (file)
@@ -4,8 +4,12 @@ Kernel driver lm87
 Supported chips:
   * National Semiconductor LM87
     Prefix: 'lm87'
-    Addresses scanned: I2C 0x2c - 0x2f
+    Addresses scanned: I2C 0x2c - 0x2e
     Datasheet: http://www.national.com/pf/LM/LM87.html
+  * Analog Devices ADM1024
+    Prefix: 'adm1024'
+    Addresses scanned: I2C 0x2c - 0x2e
+    Datasheet: http://www.analog.com/en/prod/0,2877,ADM1024,00.html
 
 Authors:
         Frodo Looijaard <frodol@dds.nl>,
@@ -19,11 +23,12 @@ Authors:
 Description
 -----------
 
-This driver implements support for the National Semiconductor LM87.
+This driver implements support for the National Semiconductor LM87
+and the Analog Devices ADM1024.
 
 The LM87 implements up to three temperature sensors, up to two fan
 rotation speed sensors, up to seven voltage sensors, alarms, and some
-miscellaneous stuff.
+miscellaneous stuff. The ADM1024 is fully compatible.
 
 Temperatures are measured in degrees Celsius. Each input has a high
 and low alarm settings. A high limit produces an alarm when the value
index 19900a8fe6794b1f9df2354c2f7126b26107146e..9865aeedc58fff5c2051e0d3cb97449c6adb304c 100644 (file)
@@ -14,7 +14,7 @@ Lm-sensors
 
 Core set of utilities that will allow you to obtain health information,
 setup monitoring limits etc. You can get them on their homepage
-http://www.lm-sensors.nu/ or as a package from your Linux distribution.
+http://www.lm-sensors.org/ or as a package from your Linux distribution.
 
 If from website:
 Get lm-sensors from project web site. Please note, you need only userspace
index ccc2bcb610686aaf44a0d38c5f67db44e8985e82..d6e1ae30fa6e61f3da3e523befa708dcfbedb627 100644 (file)
@@ -23,8 +23,9 @@ W83627DHG super I/O chips. We will refer to them collectively as Winbond chips.
 
 The chips implement three temperature sensors, five fan rotation
 speed sensors, ten analog voltage sensors (only nine for the 627DHG), one
-VID (6 pins), alarms with beep warnings (control unimplemented), and
-some automatic fan regulation strategies (plus manual fan control mode).
+VID (6 pins for the 627EHF/EHG, 8 pins for the 627DHG), alarms with beep
+warnings (control unimplemented), and some automatic fan regulation
+strategies (plus manual fan control mode).
 
 Temperatures are measured in degrees Celsius and measurement resolution is 1
 degC for temp1 and 0.5 degC for temp2 and temp3. An alarm is triggered when
index 7922319212413c5e3a32be74495b18f339fc1e25..880a59f53da91d5f24d212945b2f0b6658b0531e 100644 (file)
@@ -73,5 +73,4 @@ doesn't help, you may just ignore the bogus VID reading with no harm done.
 
 For further information on this driver see the w83781d driver documentation.
 
-[1] http://www2.lm-sensors.nu/~lm78/cvs/browse.cgi/lm_sensors2/doc/vid
-
+[1] http://www.lm-sensors.org/browser/lm-sensors/trunk/doc/vid
index b1e9f80098ee55af95aab64d26564f7fdfefa7f0..6f800a0283e9454a8788ba375b310d544faba803 100644 (file)
@@ -4,20 +4,16 @@ Kernel driver w83781d
 Supported chips:
   * Winbond W83781D
     Prefix: 'w83781d'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/w83781d.pdf
   * Winbond W83782D
     Prefix: 'w83782d'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: http://www.winbond.com/PDF/sheet/w83782d.pdf
   * Winbond W83783S
     Prefix: 'w83783s'
     Addresses scanned: I2C 0x2d
     Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/w83783s.pdf
-  * Winbond W83627HF
-    Prefix: 'w83627hf'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
-    Datasheet: http://www.winbond.com/PDF/sheet/w83627hf.pdf
   * Asus AS99127F
     Prefix: 'as99127f'
     Addresses scanned: I2C 0x28 - 0x2f
@@ -50,20 +46,18 @@ force_subclients=bus,caddr,saddr,saddr
 Description
 -----------
 
-This driver implements support for the Winbond W83781D, W83782D, W83783S,
-W83627HF chips, and the Asus AS99127F chips. We will refer to them
-collectively as W8378* chips.
+This driver implements support for the Winbond W83781D, W83782D, W83783S
+chips, and the Asus AS99127F chips. We will refer to them collectively as
+W8378* chips.
 
 There is quite some difference between these chips, but they are similar
 enough that it was sensible to put them together in one driver.
-The W83627HF chip is assumed to be identical to the ISA W83782D.
 The Asus chips are similar to an I2C-only W83782D.
 
 Chip        #vin    #fanin  #pwm    #temp   wchipid vendid  i2c     ISA
 as99127f    7       3       0       3       0x31    0x12c3  yes     no
 as99127f rev.2 (type_name = as99127f)       0x31    0x5ca3  yes     no
 w83781d     7       3       0       3       0x10-1  0x5ca3  yes     yes
-w83627hf    9       3       2       3       0x21    0x5ca3  yes     yes(LPC)
 w83782d     9       3       2-4     3       0x30    0x5ca3  yes     yes
 w83783s     5-6     3       2       1-2     0x40    0x5ca3  yes     no
 
@@ -143,9 +137,9 @@ Individual alarm and beep bits:
 0x000400: in6
 0x000800: fan3
 0x001000: chassis
-0x002000: temp3 (W83782D and W83627HF only)
-0x010000: in7 (W83782D and W83627HF only)
-0x020000: in8 (W83782D and W83627HF only)
+0x002000: temp3 (W83782D only)
+0x010000: in7 (W83782D only)
+0x020000: in8 (W83782D only)
 
 If an alarm triggers, it will remain triggered until the hardware register
 is read at least once. This means that the cause for the alarm may
diff --git a/Documentation/hwmon/w83l786ng b/Documentation/hwmon/w83l786ng
new file mode 100644 (file)
index 0000000..d8f55d7
--- /dev/null
@@ -0,0 +1,54 @@
+Kernel driver w83l786ng
+=====================
+
+Supported chips:
+  * Winbond W83L786NG/W83L786NR
+    Prefix: 'w83l786ng'
+    Addresses scanned: I2C 0x2e - 0x2f
+    Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/W83L786NRNG09.pdf
+
+Author: Kevin Lo <kevlo@kevlo.org>
+
+
+Module Parameters
+-----------------
+
+* reset boolean
+  (default 0)
+  Use 'reset=1' to reset the chip (via index 0x40, bit 7). The default
+  behavior is no chip reset to preserve BIOS settings
+
+
+Description
+-----------
+
+This driver implements support for Winbond W83L786NG/W83L786NR chips.
+
+The driver implements two temperature sensors, two fan rotation speed
+sensors, and three voltage sensors.
+
+Temperatures are measured in degrees Celsius and measurement resolution is 1
+degC for temp1 and temp2.
+
+Fan rotation speeds are reported in RPM (rotations per minute). Fan readings
+readings can be divided by a programmable divider (1, 2, 4, 8, 16, 32, 64
+or 128 for fan 1/2) to give the readings more range or accuracy.
+
+Voltage sensors (also known as IN sensors) report their values in millivolts.
+An alarm is triggered if the voltage has crossed a programmable minimum
+or maximum limit.
+
+/sys files
+----------
+
+pwm[1-2] - this file stores PWM duty cycle or DC value (fan speed) in range:
+           0 (stop) to 255 (full)
+pwm[1-2]_enable - this file controls mode of fan/temperature control:
+            * 0 Manual Mode
+            * 1 Thermal Cruise
+            * 2 Smart Fan II
+            * 4 FAN_SET
+pwm[1-2]_mode - Select PWM of DC mode
+            * 0 DC
+            * 1 PWM
+tolerance[1-2] - Value in degrees of Celsius (degC) for +- T
index cf6b6cb02aa15e8975fb191486e56493f3a06aa3..ef1efa79b1df82dbbd4f7b0a96dcda6021769a4c 100644 (file)
@@ -95,4 +95,4 @@ of all affected systems, so the only safe solution was to prevent access to
 the SMBus on all IBM systems (detected using DMI data.)
 
 For additional information, read:
-http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/README.thinkpad
+http://www.lm-sensors.org/browser/lm-sensors/trunk/README.thinkpad
index cd8403a33ee64ad118000bbfe816611ae39dfeb6..de2bcacfa870a6f1e3bc94369fda343db1e8b4a7 100644 (file)
 **                                             2. modify the arcmsr_pci_slot_reset function
 **                                             3. modify the arcmsr_pci_ers_disconnect_forepart function
 **                                             4. modify the arcmsr_pci_ers_need_reset_forepart function
+** 1.20.00.15   09/27/2007      Erich Chen & Nick Cheng
+**                                             1. add arcmsr_enable_eoi_mode() on adapter Type B
+**                                             2. add readl(reg->iop2drv_doorbell_reg) in arcmsr_handle_hbb_isr()
+**                                             in case of the doorbell interrupt clearance is cached
+** 1.20.00.15   10/01/2007      Erich Chen & Nick Cheng
+**                                             1. modify acb->devstate[i][j]
+**                                             as ARECA_RAID_GOOD instead of
+**                                             ARECA_RAID_GONE in arcmsr_alloc_ccb_pool
+** 1.20.00.15   11/06/2007       Erich Chen & Nick Cheng
+**                                             1. add conditional declaration for
+**                                             arcmsr_pci_error_detected() and
+**                                             arcmsr_pci_slot_reset
+** 1.20.00.15  11/23/2007       Erich Chen & Nick Cheng
+**                                             1.check if the sg list member number
+**                                             exceeds arcmsr default limit in arcmsr_build_ccb()
+**                                             2.change the returned value type of arcmsr_build_ccb()
+**                                             from "void" to "int"
+**                                             3.add the conditional check if arcmsr_build_ccb()
+**                                             returns FAILED
+** 1.20.00.15  12/04/2007       Erich Chen & Nick Cheng
+**                                             1. modify arcmsr_drain_donequeue() to ignore unknown
+**                                             command and let kernel process command timeout.
+**                                             This could handle IO request violating max. segments
+**                                             while Linux XFS over DM-CRYPT.
+**                                             Thanks to Milan Broz's comments <mbroz@redhat.com>
+** 1.20.00.15  12/24/2007       Erich Chen & Nick Cheng
+**                                             1.fix the portability problems
+**                                             2.fix type B where we should _not_ iounmap() acb->pmu;
+**                                             it's not ioremapped.
+**                                             3.add return -ENOMEM if ioremap() fails
+**                                             4.transfer IS_SG64_ADDR w/ cpu_to_le32()
+**                                             in arcmsr_build_ccb
+**                                             5. modify acb->devstate[i][j] as ARECA_RAID_GONE instead of
+**                                             ARECA_RAID_GOOD in arcmsr_alloc_ccb_pool()
+**                                             6.fix arcmsr_cdb->Context as (unsigned long)arcmsr_cdb
+**                                             7.add the checking state of
+**                                             (outbound_intstatus & ARCMSR_MU_OUTBOUND_HANDLE_INT) == 0
+**                                             in arcmsr_handle_hba_isr
+**                                             8.replace pci_alloc_consistent()/pci_free_consistent() with kmalloc()/kfree() in arcmsr_iop_message_xfer()
+**                                             9. fix the release of dma memory for type B in arcmsr_free_ccb_pool()
+**                                             10.fix the arcmsr_polling_hbb_ccbdone()
 **************************************************************************
index 6f70f2b9327e1f0db7bc05bdbf2d6ce3b2fcbdcf..a6d5354639b2ac73e98abe5b297da5dad6f330f2 100644 (file)
@@ -1407,7 +1407,7 @@ Credits
 =======
 The following people have contributed to this document:
         Mike Anderson <andmike at us dot ibm dot com>
-        James Bottomley <James dot Bottomley at steeleye dot com> 
+        James Bottomley <James dot Bottomley at hansenpartnership dot com>
         Patrick Mansfield <patmans at us dot ibm dot com> 
         Christoph Hellwig <hch at infradead dot org>
         Doug Ledford <dledford at redhat dot com>
index 488c1f31b99249b75a9686cf42f08329bea896c9..7123fee708ca9fa3f08c102f6e82247f7a60fbae 100644 (file)
@@ -32,6 +32,13 @@ struct slabinfo {
        int sanity_checks, slab_size, store_user, trace;
        int order, poison, reclaim_account, red_zone;
        unsigned long partial, objects, slabs;
+       unsigned long alloc_fastpath, alloc_slowpath;
+       unsigned long free_fastpath, free_slowpath;
+       unsigned long free_frozen, free_add_partial, free_remove_partial;
+       unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
+       unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
+       unsigned long deactivate_to_head, deactivate_to_tail;
+       unsigned long deactivate_remote_frees;
        int numa[MAX_NODES];
        int numa_partial[MAX_NODES];
 } slabinfo[MAX_SLABS];
@@ -64,8 +71,10 @@ int show_inverted = 0;
 int show_single_ref = 0;
 int show_totals = 0;
 int sort_size = 0;
+int sort_active = 0;
 int set_debug = 0;
 int show_ops = 0;
+int show_activity = 0;
 
 /* Debug options */
 int sanity = 0;
@@ -93,8 +102,10 @@ void usage(void)
        printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
                "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
                "-a|--aliases           Show aliases\n"
+               "-A|--activity          Most active slabs first\n"
                "-d<options>|--debug=<options> Set/Clear Debug options\n"
-               "-e|--empty             Show empty slabs\n"
+               "-D|--display-active    Switch line format to activity\n"
+               "-e|--empty             Show empty slabs\n"
                "-f|--first-alias       Show first alias\n"
                "-h|--help              Show usage information\n"
                "-i|--inverted          Inverted list\n"
@@ -281,8 +292,11 @@ int line = 0;
 
 void first_line(void)
 {
-       printf("Name                   Objects Objsize    Space "
-               "Slabs/Part/Cpu  O/S O %%Fr %%Ef Flg\n");
+       if (show_activity)
+               printf("Name                   Objects    Alloc     Free   %%Fast\n");
+       else
+               printf("Name                   Objects Objsize    Space "
+                       "Slabs/Part/Cpu  O/S O %%Fr %%Ef Flg\n");
 }
 
 /*
@@ -309,6 +323,12 @@ unsigned long slab_size(struct slabinfo *s)
        return  s->slabs * (page_size << s->order);
 }
 
+unsigned long slab_activity(struct slabinfo *s)
+{
+       return  s->alloc_fastpath + s->free_fastpath +
+               s->alloc_slowpath + s->free_slowpath;
+}
+
 void slab_numa(struct slabinfo *s, int mode)
 {
        int node;
@@ -392,6 +412,71 @@ const char *onoff(int x)
        return "Off";
 }
 
+void slab_stats(struct slabinfo *s)
+{
+       unsigned long total_alloc;
+       unsigned long total_free;
+       unsigned long total;
+
+       if (!s->alloc_slab)
+               return;
+
+       total_alloc = s->alloc_fastpath + s->alloc_slowpath;
+       total_free = s->free_fastpath + s->free_slowpath;
+
+       if (!total_alloc)
+               return;
+
+       printf("\n");
+       printf("Slab Perf Counter       Alloc     Free %%Al %%Fr\n");
+       printf("--------------------------------------------------\n");
+       printf("Fastpath             %8lu %8lu %3lu %3lu\n",
+               s->alloc_fastpath, s->free_fastpath,
+               s->alloc_fastpath * 100 / total_alloc,
+               s->free_fastpath * 100 / total_free);
+       printf("Slowpath             %8lu %8lu %3lu %3lu\n",
+               total_alloc - s->alloc_fastpath, s->free_slowpath,
+               (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
+               s->free_slowpath * 100 / total_free);
+       printf("Page Alloc           %8lu %8lu %3lu %3lu\n",
+               s->alloc_slab, s->free_slab,
+               s->alloc_slab * 100 / total_alloc,
+               s->free_slab * 100 / total_free);
+       printf("Add partial          %8lu %8lu %3lu %3lu\n",
+               s->deactivate_to_head + s->deactivate_to_tail,
+               s->free_add_partial,
+               (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
+               s->free_add_partial * 100 / total_free);
+       printf("Remove partial       %8lu %8lu %3lu %3lu\n",
+               s->alloc_from_partial, s->free_remove_partial,
+               s->alloc_from_partial * 100 / total_alloc,
+               s->free_remove_partial * 100 / total_free);
+
+       printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
+               s->deactivate_remote_frees, s->free_frozen,
+               s->deactivate_remote_frees * 100 / total_alloc,
+               s->free_frozen * 100 / total_free);
+
+       printf("Total                %8lu %8lu\n\n", total_alloc, total_free);
+
+       if (s->cpuslab_flush)
+               printf("Flushes %8lu\n", s->cpuslab_flush);
+
+       if (s->alloc_refill)
+               printf("Refill %8lu\n", s->alloc_refill);
+
+       total = s->deactivate_full + s->deactivate_empty +
+                       s->deactivate_to_head + s->deactivate_to_tail;
+
+       if (total)
+               printf("Deactivate Full=%lu(%lu%%) Empty=%lu(%lu%%) "
+                       "ToHead=%lu(%lu%%) ToTail=%lu(%lu%%)\n",
+                       s->deactivate_full, (s->deactivate_full * 100) / total,
+                       s->deactivate_empty, (s->deactivate_empty * 100) / total,
+                       s->deactivate_to_head, (s->deactivate_to_head * 100) / total,
+                       s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
+}
+
 void report(struct slabinfo *s)
 {
        if (strcmp(s->name, "*") == 0)
@@ -430,6 +515,7 @@ void report(struct slabinfo *s)
        ops(s);
        show_tracking(s);
        slab_numa(s, 1);
+       slab_stats(s);
 }
 
 void slabcache(struct slabinfo *s)
@@ -479,13 +565,27 @@ void slabcache(struct slabinfo *s)
                *p++ = 'T';
 
        *p = 0;
-       printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
-               s->name, s->objects, s->object_size, size_str, dist_str,
-               s->objs_per_slab, s->order,
-               s->slabs ? (s->partial * 100) / s->slabs : 100,
-               s->slabs ? (s->objects * s->object_size * 100) /
-                       (s->slabs * (page_size << s->order)) : 100,
-               flags);
+       if (show_activity) {
+               unsigned long total_alloc;
+               unsigned long total_free;
+
+               total_alloc = s->alloc_fastpath + s->alloc_slowpath;
+               total_free = s->free_fastpath + s->free_slowpath;
+
+               printf("%-21s %8ld %8ld %8ld %3ld %3ld \n",
+                       s->name, s->objects,
+                       total_alloc, total_free,
+                       total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
+                       total_free ? (s->free_fastpath * 100 / total_free) : 0);
+       }
+       else
+               printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
+                       s->name, s->objects, s->object_size, size_str, dist_str,
+                       s->objs_per_slab, s->order,
+                       s->slabs ? (s->partial * 100) / s->slabs : 100,
+                       s->slabs ? (s->objects * s->object_size * 100) /
+                               (s->slabs * (page_size << s->order)) : 100,
+                       flags);
 }
 
 /*
@@ -892,6 +992,8 @@ void sort_slabs(void)
 
                        if (sort_size)
                                result = slab_size(s1) < slab_size(s2);
+                       else if (sort_active)
+                               result = slab_activity(s1) < slab_activity(s2);
                        else
                                result = strcasecmp(s1->name, s2->name);
 
@@ -1074,6 +1176,23 @@ void read_slab_dir(void)
                        free(t);
                        slab->store_user = get_obj("store_user");
                        slab->trace = get_obj("trace");
+                       slab->alloc_fastpath = get_obj("alloc_fastpath");
+                       slab->alloc_slowpath = get_obj("alloc_slowpath");
+                       slab->free_fastpath = get_obj("free_fastpath");
+                       slab->free_slowpath = get_obj("free_slowpath");
+                       slab->free_frozen= get_obj("free_frozen");
+                       slab->free_add_partial = get_obj("free_add_partial");
+                       slab->free_remove_partial = get_obj("free_remove_partial");
+                       slab->alloc_from_partial = get_obj("alloc_from_partial");
+                       slab->alloc_slab = get_obj("alloc_slab");
+                       slab->alloc_refill = get_obj("alloc_refill");
+                       slab->free_slab = get_obj("free_slab");
+                       slab->cpuslab_flush = get_obj("cpuslab_flush");
+                       slab->deactivate_full = get_obj("deactivate_full");
+                       slab->deactivate_empty = get_obj("deactivate_empty");
+                       slab->deactivate_to_head = get_obj("deactivate_to_head");
+                       slab->deactivate_to_tail = get_obj("deactivate_to_tail");
+                       slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
                        chdir("..");
                        if (slab->name[0] == ':')
                                alias_targets++;
@@ -1124,7 +1243,9 @@ void output_slabs(void)
 
 struct option opts[] = {
        { "aliases", 0, NULL, 'a' },
+       { "activity", 0, NULL, 'A' },
        { "debug", 2, NULL, 'd' },
+       { "display-activity", 0, NULL, 'D' },
        { "empty", 0, NULL, 'e' },
        { "first-alias", 0, NULL, 'f' },
        { "help", 0, NULL, 'h' },
@@ -1149,7 +1270,7 @@ int main(int argc, char *argv[])
 
        page_size = getpagesize();
 
-       while ((c = getopt_long(argc, argv, "ad::efhil1noprstvzTS",
+       while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTS",
                                                opts, NULL)) != -1)
                switch (c) {
                case '1':
@@ -1158,11 +1279,17 @@ int main(int argc, char *argv[])
                case 'a':
                        show_alias = 1;
                        break;
+               case 'A':
+                       sort_active = 1;
+                       break;
                case 'd':
                        set_debug = 1;
                        if (!debug_opt_scan(optarg))
                                fatal("Invalid debug option '%s'\n", optarg);
                        break;
+               case 'D':
+                       show_activity = 1;
+                       break;
                case 'e':
                        show_empty = 1;
                        break;
index aefd23f892bae93d58fed6db9d20b1e601fcea5f..2cdb591ac0807d6b5b1b6f10702ad5542c91f29f 100644 (file)
@@ -2150,6 +2150,14 @@ M:       acme@ghostprotocols.net
 L:     netdev@vger.kernel.org
 S:     Maintained
 
+IPWIRELES DRIVER
+P:     Jiri Kosina
+M:     jkosina@suse.cz
+P:     David Sterba
+M:     dsterba@suse.cz
+S:     Maintained
+T:     git://git.kernel.org/pub/scm/linux/kernel/git/jikos/ipwireless_cs.git
+
 IRDA SUBSYSTEM
 P:     Samuel Ortiz
 M:     samuel@sortiz.org
index 3ee918695215791b10f01ca19e9095b094cf35f5..f85b928ffac418080315ac0e6aa19038f388ae24 100644 (file)
@@ -335,7 +335,7 @@ void dump_thread(struct pt_regs * regs, struct user * dump)
        if (dump->start_stack < TASK_SIZE)
                dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
 
-       dump->u_ar0 = (struct user_regs_struct *)((int)&dump->regs - (int)dump);
+       dump->u_ar0 = offsetof(struct user, regs);
        sw = ((struct switch_stack *)regs) - 1;
        dump->regs.d1 = regs->d1;
        dump->regs.d2 = regs->d2;
index e6e49289f7882dd11494d9208168e253f806de21..4b749c41646441b70b0216beddfeab7409a661ce 100644 (file)
@@ -313,7 +313,7 @@ int main(void)
        DEFINE(CLOCK_REALTIME, CLOCK_REALTIME);
        DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC);
        DEFINE(NSEC_PER_SEC, NSEC_PER_SEC);
-       DEFINE(CLOCK_REALTIME_RES, (KTIME_MONOTONIC_RES).tv64);
+       DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);
 
 #ifdef CONFIG_BUG
        DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry));
index c95482b6b6dd2f064701000db87519ec9bb621a7..9d0acedf5f3f7674cc558d2042b287c52be58121 100644 (file)
@@ -52,6 +52,10 @@ config HAVE_LATENCYTOP_SUPPORT
 config SEMAPHORE_SLEEPERS
        def_bool y
 
+config FAST_CMPXCHG_LOCAL
+       bool
+       default y
+
 config MMU
        def_bool y
 
index f25facd97bb45a7af74e1268c45dec99f2cb04a0..00b8a84b03195535d1ef68fe74e1dea13b9510e6 100644 (file)
@@ -43,5 +43,14 @@ config CARDMAN_4040
          (http://www.omnikey.com/), or a current development version of OpenCT
          (http://www.opensc.org/).
 
+config IPWIRELESS
+       tristate "IPWireless 3G UMTS PCMCIA card support"
+       depends on PCMCIA
+       select PPP
+       help
+         This is a driver for 3G UMTS PCMCIA card from IPWireless company. In
+         some countries (for example Czech Republic, T-Mobile ISP) this card
+         is shipped for service called UMTS 4G.
+
 endmenu
 
index 0aae20985d5732059700e7fb50dec7d6573682a2..be8f287aa398f0a9697f9af30d4cda25b95ea1f0 100644 (file)
@@ -4,6 +4,8 @@
 # Makefile for the Linux PCMCIA char device drivers.
 #
 
+obj-y += ipwireless/
+
 obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o
 obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o
 obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o
diff --git a/drivers/char/pcmcia/ipwireless/Makefile b/drivers/char/pcmcia/ipwireless/Makefile
new file mode 100644 (file)
index 0000000..b71eb59
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# drivers/char/pcmcia/ipwireless/Makefile
+#
+# Makefile for the IPWireless driver
+#
+
+obj-$(CONFIG_IPWIRELESS) += ipwireless.o
+
+ipwireless-objs := hardware.o main.o network.o tty.o
+
diff --git a/drivers/char/pcmcia/ipwireless/hardware.c b/drivers/char/pcmcia/ipwireless/hardware.c
new file mode 100644 (file)
index 0000000..1f978ff
--- /dev/null
@@ -0,0 +1,1787 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#include "hardware.h"
+#include "setup_protocol.h"
+#include "network.h"
+#include "main.h"
+
+static void ipw_send_setup_packet(struct ipw_hardware *hw);
+static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
+                                        unsigned int address,
+                                        unsigned char *data, int len,
+                                        int is_last);
+static void ipwireless_setup_timer(unsigned long data);
+static void handle_received_CTRL_packet(struct ipw_hardware *hw,
+               unsigned int channel_idx, unsigned char *data, int len);
+
+/*#define TIMING_DIAGNOSTICS*/
+
+#ifdef TIMING_DIAGNOSTICS
+
+static struct timing_stats {
+       unsigned long last_report_time;
+       unsigned long read_time;
+       unsigned long write_time;
+       unsigned long read_bytes;
+       unsigned long write_bytes;
+       unsigned long start_time;
+};
+
+static void start_timing(void)
+{
+       timing_stats.start_time = jiffies;
+}
+
+static void end_read_timing(unsigned length)
+{
+       timing_stats.read_time += (jiffies - start_time);
+       timing_stats.read_bytes += length + 2;
+       report_timing();
+}
+
+static void end_write_timing(unsigned length)
+{
+       timing_stats.write_time += (jiffies - start_time);
+       timing_stats.write_bytes += length + 2;
+       report_timing();
+}
+
+static void report_timing(void)
+{
+       unsigned long since = jiffies - timing_stats.last_report_time;
+
+       /* If it's been more than one second... */
+       if (since >= HZ) {
+               int first = (timing_stats.last_report_time == 0);
+
+               timing_stats.last_report_time = jiffies;
+               if (!first)
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": %u us elapsed - read %lu bytes in %u us, "
+                              "wrote %lu bytes in %u us\n",
+                              jiffies_to_usecs(since),
+                              timing_stats.read_bytes,
+                              jiffies_to_usecs(timing_stats.read_time),
+                              timing_stats.write_bytes,
+                              jiffies_to_usecs(timing_stats.write_time));
+
+               timing_stats.read_time = 0;
+               timing_stats.write_time = 0;
+               timing_stats.read_bytes = 0;
+               timing_stats.write_bytes = 0;
+       }
+}
+#else
+static void start_timing(void) { }
+static void end_read_timing(unsigned length) { }
+static void end_write_timing(unsigned length) { }
+#endif
+
+/* Imported IPW definitions */
+
+#define LL_MTU_V1 318
+#define LL_MTU_V2 250
+#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
+
+#define PRIO_DATA  2
+#define PRIO_CTRL  1
+#define PRIO_SETUP 0
+
+/* Addresses */
+#define ADDR_SETUP_PROT 0
+
+/* Protocol ids */
+enum {
+       /* Identifier for the Com Data protocol */
+       TL_PROTOCOLID_COM_DATA = 0,
+
+       /* Identifier for the Com Control protocol */
+       TL_PROTOCOLID_COM_CTRL = 1,
+
+       /* Identifier for the Setup protocol */
+       TL_PROTOCOLID_SETUP = 2
+};
+
+/* Number of bytes in NL packet header (cannot do
+ * sizeof(nl_packet_header) since it's a bitfield) */
+#define NL_FIRST_PACKET_HEADER_SIZE        3
+
+/* Number of bytes in NL packet header (cannot do
+ * sizeof(nl_packet_header) since it's a bitfield) */
+#define NL_FOLLOWING_PACKET_HEADER_SIZE    1
+
+struct nl_first_packet_header {
+#if defined(__BIG_ENDIAN_BITFIELD)
+       unsigned char packet_rank:2;
+       unsigned char address:3;
+       unsigned char protocol:3;
+#else
+       unsigned char protocol:3;
+       unsigned char address:3;
+       unsigned char packet_rank:2;
+#endif
+       unsigned char length_lsb;
+       unsigned char length_msb;
+};
+
+struct nl_packet_header {
+#if defined(__BIG_ENDIAN_BITFIELD)
+       unsigned char packet_rank:2;
+       unsigned char address:3;
+       unsigned char protocol:3;
+#else
+       unsigned char protocol:3;
+       unsigned char address:3;
+       unsigned char packet_rank:2;
+#endif
+};
+
+/* Value of 'packet_rank' above */
+#define NL_INTERMEDIATE_PACKET    0x0
+#define NL_LAST_PACKET            0x1
+#define NL_FIRST_PACKET           0x2
+
+union nl_packet {
+       /* Network packet header of the first packet (a special case) */
+       struct nl_first_packet_header hdr_first;
+       /* Network packet header of the following packets (if any) */
+       struct nl_packet_header hdr;
+       /* Complete network packet (header + data) */
+       unsigned char rawpkt[LL_MTU_MAX];
+} __attribute__ ((__packed__));
+
+#define HW_VERSION_UNKNOWN -1
+#define HW_VERSION_1 1
+#define HW_VERSION_2 2
+
+/* IPW I/O ports */
+#define IOIER 0x00             /* Interrupt Enable Register */
+#define IOIR  0x02             /* Interrupt Source/ACK register */
+#define IODCR 0x04             /* Data Control Register */
+#define IODRR 0x06             /* Data Read Register */
+#define IODWR 0x08             /* Data Write Register */
+#define IOESR 0x0A             /* Embedded Driver Status Register */
+#define IORXR 0x0C             /* Rx Fifo Register (Host to Embedded) */
+#define IOTXR 0x0E             /* Tx Fifo Register (Embedded to Host) */
+
+/* I/O ports and bit definitions for version 1 of the hardware */
+
+/* IER bits*/
+#define IER_RXENABLED   0x1
+#define IER_TXENABLED   0x2
+
+/* ISR bits */
+#define IR_RXINTR       0x1
+#define IR_TXINTR       0x2
+
+/* DCR bits */
+#define DCR_RXDONE      0x1
+#define DCR_TXDONE      0x2
+#define DCR_RXRESET     0x4
+#define DCR_TXRESET     0x8
+
+/* I/O ports and bit definitions for version 2 of the hardware */
+
+struct MEMCCR {
+       unsigned short reg_config_option;       /* PCCOR: Configuration Option Register */
+       unsigned short reg_config_and_status;   /* PCCSR: Configuration and Status Register */
+       unsigned short reg_pin_replacement;     /* PCPRR: Pin Replacemant Register */
+       unsigned short reg_socket_and_copy;     /* PCSCR: Socket and Copy Register */
+       unsigned short reg_ext_status;          /* PCESR: Extendend Status Register */
+       unsigned short reg_io_base;             /* PCIOB: I/O Base Register */
+};
+
+struct MEMINFREG {
+       unsigned short memreg_tx_old;   /* TX Register (R/W) */
+       unsigned short pad1;
+       unsigned short memreg_rx_done;  /* RXDone Register (R/W) */
+       unsigned short pad2;
+       unsigned short memreg_rx;       /* RX Register (R/W) */
+       unsigned short pad3;
+       unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
+       unsigned short pad4;
+       unsigned long memreg_card_present;/* Mask for Host to check (R) for
+                                          * CARD_PRESENT_VALUE */
+       unsigned short memreg_tx_new;   /* TX2 (new) Register (R/W) */
+};
+
+#define IODMADPR 0x00          /* DMA Data Port Register (R/W) */
+
+#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
+
+#define MEMTX_TX                       0x0001
+#define MEMRX_RX                       0x0001
+#define MEMRX_RX_DONE                  0x0001
+#define MEMRX_PCINTACKK                0x0001
+#define MEMRX_MEMSPURIOUSINT           0x0001
+
+#define NL_NUM_OF_PRIORITIES       3
+#define NL_NUM_OF_PROTOCOLS        3
+#define NL_NUM_OF_ADDRESSES        NO_OF_IPW_CHANNELS
+
+struct ipw_hardware {
+       unsigned int base_port;
+       short hw_version;
+       unsigned short ll_mtu;
+       spinlock_t spinlock;
+
+       int initializing;
+       int init_loops;
+       struct timer_list setup_timer;
+
+       int tx_ready;
+       struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
+       /* True if any packets are queued for transmission */
+       int tx_queued;
+
+       int rx_bytes_queued;
+       struct list_head rx_queue;
+       /* Pool of rx_packet structures that are not currently used. */
+       struct list_head rx_pool;
+       int rx_pool_size;
+       /* True if reception of data is blocked while userspace processes it. */
+       int blocking_rx;
+       /* True if there is RX data ready on the hardware. */
+       int rx_ready;
+       unsigned short last_memtx_serial;
+       /*
+        * Newer versions of the V2 card firmware send serial numbers in the
+        * MemTX register. 'serial_number_detected' is set true when we detect
+        * a non-zero serial number (indicating the new firmware).  Thereafter,
+        * the driver can safely ignore the Timer Recovery re-sends to avoid
+        * out-of-sync problems.
+        */
+       int serial_number_detected;
+       struct work_struct work_rx;
+
+       /* True if we are to send the set-up data to the hardware. */
+       int to_setup;
+
+       /* Card has been removed */
+       int removed;
+       /* Saved irq value when we disable the interrupt. */
+       int irq;
+       /* True if this driver is shutting down. */
+       int shutting_down;
+       /* Modem control lines */
+       unsigned int control_lines[NL_NUM_OF_ADDRESSES];
+       struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
+
+       struct tasklet_struct tasklet;
+
+       /* The handle for the network layer, for the sending of events to it. */
+       struct ipw_network *network;
+       struct MEMINFREG __iomem *memory_info_regs;
+       struct MEMCCR __iomem *memregs_CCR;
+       void (*reboot_callback) (void *data);
+       void *reboot_callback_data;
+
+       unsigned short __iomem *memreg_tx;
+};
+
+/*
+ * Packet info structure for tx packets.
+ * Note: not all the fields defined here are required for all protocols
+ */
+struct ipw_tx_packet {
+       struct list_head queue;
+       /* channel idx + 1 */
+       unsigned char dest_addr;
+       /* SETUP, CTRL or DATA */
+       unsigned char protocol;
+       /* Length of data block, which starts at the end of this structure */
+       unsigned short length;
+       /* Sending state */
+       /* Offset of where we've sent up to so far */
+       unsigned long offset;
+       /* Count of packet fragments, starting at 0 */
+       int fragment_count;
+
+       /* Called after packet is sent and before is freed */
+       void (*packet_callback) (void *cb_data, unsigned int packet_length);
+       void *callback_data;
+};
+
+/* Signals from DTE */
+#define COMCTRL_RTS    0
+#define COMCTRL_DTR    1
+
+/* Signals from DCE */
+#define COMCTRL_CTS    2
+#define COMCTRL_DCD    3
+#define COMCTRL_DSR    4
+#define COMCTRL_RI     5
+
+struct ipw_control_packet_body {
+       /* DTE signal or DCE signal */
+       unsigned char sig_no;
+       /* 0: set signal, 1: clear signal */
+       unsigned char value;
+} __attribute__ ((__packed__));
+
+struct ipw_control_packet {
+       struct ipw_tx_packet header;
+       struct ipw_control_packet_body body;
+};
+
+struct ipw_rx_packet {
+       struct list_head queue;
+       unsigned int capacity;
+       unsigned int length;
+       unsigned int protocol;
+       unsigned int channel_idx;
+};
+
+#ifdef IPWIRELESS_STATE_DEBUG
+int ipwireless_dump_hardware_state(char *p, size_t limit,
+                                  struct ipw_hardware *hw)
+{
+       return snprintf(p, limit,
+                       "debug: initializing=%d\n"
+                       "debug: tx_ready=%d\n"
+                       "debug: tx_queued=%d\n"
+                       "debug: rx_ready=%d\n"
+                       "debug: rx_bytes_queued=%d\n"
+                       "debug: blocking_rx=%d\n"
+                       "debug: removed=%d\n"
+                       "debug: hardware.shutting_down=%d\n"
+                       "debug: to_setup=%d\n",
+                       hw->initializing,
+                       hw->tx_ready,
+                       hw->tx_queued,
+                       hw->rx_ready,
+                       hw->rx_bytes_queued,
+                       hw->blocking_rx,
+                       hw->removed,
+                       hw->shutting_down,
+                       hw->to_setup);
+}
+#endif
+
+static char *data_type(const unsigned char *buf, unsigned length)
+{
+       struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
+
+       if (length == 0)
+               return "     ";
+
+       if (hdr->packet_rank & NL_FIRST_PACKET) {
+               switch (hdr->protocol) {
+               case TL_PROTOCOLID_COM_DATA:    return "DATA ";
+               case TL_PROTOCOLID_COM_CTRL:    return "CTRL ";
+               case TL_PROTOCOLID_SETUP:       return "SETUP";
+               default: return "???? ";
+               }
+       } else
+               return "     ";
+}
+
+#define DUMP_MAX_BYTES 64
+
+static void dump_data_bytes(const char *type, const unsigned char *data,
+                           unsigned length)
+{
+       char prefix[56];
+
+       sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
+                       type, data_type(data, length));
+       print_hex_dump_bytes(prefix, 0, (void *)data,
+                       length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
+}
+
+static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
+                           unsigned length)
+{
+       int i;
+       unsigned long flags;
+
+       start_timing();
+
+       if (length == 0)
+               return 0;
+
+       if (length > hw->ll_mtu)
+               return -1;
+
+       if (ipwireless_debug)
+               dump_data_bytes("send", data, length);
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+
+       if (hw->hw_version == HW_VERSION_1) {
+               outw((unsigned short) length, hw->base_port + IODWR);
+
+               for (i = 0; i < length; i += 2) {
+                       unsigned short d = data[i];
+                       __le16 raw_data;
+
+                       if (likely(i + 1 < length))
+                               d |= data[i + 1] << 8;
+                       raw_data = cpu_to_le16(d);
+                       outw(raw_data, hw->base_port + IODWR);
+               }
+
+               outw(DCR_TXDONE, hw->base_port + IODCR);
+       } else if (hw->hw_version == HW_VERSION_2) {
+               outw((unsigned short) length, hw->base_port + IODMADPR);
+
+               for (i = 0; i < length; i += 2) {
+                       unsigned short d = data[i];
+                       __le16 raw_data;
+
+                       if ((i + 1 < length))
+                               d |= data[i + 1] << 8;
+                       raw_data = cpu_to_le16(d);
+                       outw(raw_data, hw->base_port + IODMADPR);
+               }
+               while ((i & 3) != 2) {
+                       outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR);
+                       i += 2;
+               }
+               writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
+       }
+
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       end_write_timing(length);
+
+       return 0;
+}
+
+static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
+{
+       unsigned short fragment_data_len;
+       unsigned short data_left = packet->length - packet->offset;
+       unsigned short header_size;
+       union nl_packet pkt;
+
+       header_size =
+           (packet->fragment_count == 0)
+           ? NL_FIRST_PACKET_HEADER_SIZE
+           : NL_FOLLOWING_PACKET_HEADER_SIZE;
+       fragment_data_len = hw->ll_mtu - header_size;
+       if (data_left < fragment_data_len)
+               fragment_data_len = data_left;
+
+       pkt.hdr_first.protocol = packet->protocol;
+       pkt.hdr_first.address = packet->dest_addr;
+       pkt.hdr_first.packet_rank = 0;
+
+       /* First packet? */
+       if (packet->fragment_count == 0) {
+               pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
+               pkt.hdr_first.length_lsb = (unsigned char) packet->length;
+               pkt.hdr_first.length_msb =
+                       (unsigned char) (packet->length >> 8);
+       }
+
+       memcpy(pkt.rawpkt + header_size,
+              ((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
+              packet->offset, fragment_data_len);
+       packet->offset += fragment_data_len;
+       packet->fragment_count++;
+
+       /* Last packet? (May also be first packet.) */
+       if (packet->offset == packet->length)
+               pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
+       do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
+
+       /* If this packet has unsent data, then re-queue it. */
+       if (packet->offset < packet->length) {
+               /*
+                * Re-queue it at the head of the highest priority queue so
+                * it goes before all other packets
+                */
+               unsigned long flags;
+
+               spin_lock_irqsave(&hw->spinlock, flags);
+               list_add(&packet->queue, &hw->tx_queue[0]);
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+       } else {
+               if (packet->packet_callback)
+                       packet->packet_callback(packet->callback_data,
+                                       packet->length);
+               kfree(packet);
+       }
+
+       return 0;
+}
+
+static void ipw_setup_hardware(struct ipw_hardware *hw)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->hw_version == HW_VERSION_1) {
+               /* Reset RX FIFO */
+               outw(DCR_RXRESET, hw->base_port + IODCR);
+               /* SB: Reset TX FIFO */
+               outw(DCR_TXRESET, hw->base_port + IODCR);
+
+               /* Enable TX and RX interrupts. */
+               outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
+       } else {
+               /*
+                * Set INTRACK bit (bit 0), which means we must explicitly
+                * acknowledge interrupts by clearing bit 2 of reg_config_and_status.
+                */
+               unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
+
+               csr |= 1;
+               writew(csr, &hw->memregs_CCR->reg_config_and_status);
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+}
+
+/*
+ * If 'packet' is NULL, then this function allocates a new packet, setting its
+ * length to 0 and ensuring it has the specified minimum amount of free space.
+ *
+ * If 'packet' is not NULL, then this function enlarges it if it doesn't
+ * have the specified minimum amount of free space.
+ *
+ */
+static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
+                                          struct ipw_rx_packet *packet,
+                                          int minimum_free_space)
+{
+
+       if (!packet) {
+               unsigned long flags;
+
+               /*
+                * If this is the first fragment, then we will need to fetch a
+                * packet to put it in.
+                */
+               spin_lock_irqsave(&hw->spinlock, flags);
+               /* If we have one in our pool, then pull it out. */
+               if (!list_empty(&hw->rx_pool)) {
+                       packet = list_first_entry(&hw->rx_pool,
+                                       struct ipw_rx_packet, queue);
+                       list_del(&packet->queue);
+                       hw->rx_pool_size--;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               } else {
+                       /* Otherwise allocate a new one. */
+                       static int min_capacity = 256;
+                       int new_capacity;
+
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       new_capacity =
+                           minimum_free_space > min_capacity
+                           ? minimum_free_space
+                           : min_capacity;
+                       packet = kmalloc(sizeof(struct ipw_rx_packet)
+                                       + new_capacity, GFP_ATOMIC);
+                       if (!packet)
+                               return NULL;
+                       packet->capacity = new_capacity;
+               }
+               packet->length = 0;
+       }
+
+       /*
+        * If this packet does not have sufficient capacity for the data we
+        * want to add, then make it bigger.
+        */
+       if (packet->length + minimum_free_space > packet->capacity) {
+               struct ipw_rx_packet *old_packet = packet;
+
+               packet = kmalloc(sizeof(struct ipw_rx_packet) +
+                               old_packet->length + minimum_free_space,
+                               GFP_ATOMIC);
+               if (!packet)
+                       return NULL;
+               memcpy(packet, old_packet,
+                               sizeof(struct ipw_rx_packet)
+                                       + old_packet->length);
+               packet->capacity = old_packet->length + minimum_free_space;
+               kfree(old_packet);
+       }
+
+       return packet;
+}
+
+static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
+{
+       if (hw->rx_pool_size > 6)
+               kfree(packet);
+       else {
+               hw->rx_pool_size++;
+               list_add_tail(&packet->queue, &hw->rx_pool);
+       }
+}
+
+static void queue_received_packet(struct ipw_hardware *hw,
+                                 unsigned int protocol, unsigned int address,
+                                 unsigned char *data, int length, int is_last)
+{
+       unsigned int channel_idx = address - 1;
+       struct ipw_rx_packet *packet = NULL;
+       unsigned long flags;
+
+       /* Discard packet if channel index is out of range. */
+       if (channel_idx >= NL_NUM_OF_ADDRESSES) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": data packet has bad address %u\n", address);
+               return;
+       }
+
+       /*
+        * ->packet_assembler is safe to touch unlocked, this is the only place
+        */
+       if (protocol == TL_PROTOCOLID_COM_DATA) {
+               struct ipw_rx_packet **assem =
+                       &hw->packet_assembler[channel_idx];
+
+               /*
+                * Create a new packet, or assembler already contains one
+                * enlarge it by 'length' bytes.
+                */
+               (*assem) = pool_allocate(hw, *assem, length);
+               if (!(*assem)) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                               ": no memory for incomming data packet, dropped!\n");
+                       return;
+               }
+               (*assem)->protocol = protocol;
+               (*assem)->channel_idx = channel_idx;
+
+               /* Append this packet data onto existing data. */
+               memcpy((unsigned char *)(*assem) +
+                              sizeof(struct ipw_rx_packet)
+                               + (*assem)->length, data, length);
+               (*assem)->length += length;
+               if (is_last) {
+                       packet = *assem;
+                       *assem = NULL;
+                       /* Count queued DATA bytes only */
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->rx_bytes_queued += packet->length;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+       } else {
+               /* If it's a CTRL packet, don't assemble, just queue it. */
+               packet = pool_allocate(hw, NULL, length);
+               if (!packet) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                               ": no memory for incomming ctrl packet, dropped!\n");
+                       return;
+               }
+               packet->protocol = protocol;
+               packet->channel_idx = channel_idx;
+               memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
+                               data, length);
+               packet->length = length;
+       }
+
+       /*
+        * If this is the last packet, then send the assembled packet on to the
+        * network layer.
+        */
+       if (packet) {
+               spin_lock_irqsave(&hw->spinlock, flags);
+               list_add_tail(&packet->queue, &hw->rx_queue);
+               /* Block reception of incoming packets if queue is full. */
+               hw->blocking_rx =
+                       hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
+
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               schedule_work(&hw->work_rx);
+       }
+}
+
+/*
+ * Workqueue callback
+ */
+static void ipw_receive_data_work(struct work_struct *work_rx)
+{
+       struct ipw_hardware *hw =
+           container_of(work_rx, struct ipw_hardware, work_rx);
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       while (!list_empty(&hw->rx_queue)) {
+               struct ipw_rx_packet *packet =
+                       list_first_entry(&hw->rx_queue,
+                                       struct ipw_rx_packet, queue);
+
+               if (hw->shutting_down)
+                       break;
+               list_del(&packet->queue);
+
+               /*
+                * Note: ipwireless_network_packet_received must be called in a
+                * process context (i.e. via schedule_work) because the tty
+                * output code can sleep in the tty_flip_buffer_push call.
+                */
+               if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
+                       if (hw->network != NULL) {
+                               /* If the network hasn't been disconnected. */
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               /*
+                                * This must run unlocked due to tty processing
+                                * and mutex locking
+                                */
+                               ipwireless_network_packet_received(
+                                               hw->network,
+                                               packet->channel_idx,
+                                               (unsigned char *)packet
+                                               + sizeof(struct ipw_rx_packet),
+                                               packet->length);
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                       }
+                       /* Count queued DATA bytes only */
+                       hw->rx_bytes_queued -= packet->length;
+               } else {
+                       /*
+                        * This is safe to be called locked, callchain does
+                        * not block
+                        */
+                       handle_received_CTRL_packet(hw, packet->channel_idx,
+                                       (unsigned char *)packet
+                                       + sizeof(struct ipw_rx_packet),
+                                       packet->length);
+               }
+               pool_free(hw, packet);
+               /*
+                * Unblock reception of incoming packets if queue is no longer
+                * full.
+                */
+               hw->blocking_rx =
+                       hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
+               if (hw->shutting_down)
+                       break;
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+}
+
+static void handle_received_CTRL_packet(struct ipw_hardware *hw,
+                                       unsigned int channel_idx,
+                                       unsigned char *data, int len)
+{
+       struct ipw_control_packet_body *body =
+               (struct ipw_control_packet_body *) data;
+       unsigned int changed_mask;
+
+       if (len != sizeof(struct ipw_control_packet_body)) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": control packet was %d bytes - wrong size!\n",
+                      len);
+               return;
+       }
+
+       switch (body->sig_no) {
+       case COMCTRL_CTS:
+               changed_mask = IPW_CONTROL_LINE_CTS;
+               break;
+       case COMCTRL_DCD:
+               changed_mask = IPW_CONTROL_LINE_DCD;
+               break;
+       case COMCTRL_DSR:
+               changed_mask = IPW_CONTROL_LINE_DSR;
+               break;
+       case COMCTRL_RI:
+               changed_mask = IPW_CONTROL_LINE_RI;
+               break;
+       default:
+               changed_mask = 0;
+       }
+
+       if (changed_mask != 0) {
+               if (body->value)
+                       hw->control_lines[channel_idx] |= changed_mask;
+               else
+                       hw->control_lines[channel_idx] &= ~changed_mask;
+               if (hw->network)
+                       ipwireless_network_notify_control_line_change(
+                                       hw->network,
+                                       channel_idx,
+                                       hw->control_lines[channel_idx],
+                                       changed_mask);
+       }
+}
+
+static void handle_received_packet(struct ipw_hardware *hw,
+                                  union nl_packet *packet,
+                                  unsigned short len)
+{
+       unsigned int protocol = packet->hdr.protocol;
+       unsigned int address = packet->hdr.address;
+       unsigned int header_length;
+       unsigned char *data;
+       unsigned int data_len;
+       int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
+
+       if (packet->hdr.packet_rank & NL_FIRST_PACKET)
+               header_length = NL_FIRST_PACKET_HEADER_SIZE;
+       else
+               header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
+
+       data = packet->rawpkt + header_length;
+       data_len = len - header_length;
+       switch (protocol) {
+       case TL_PROTOCOLID_COM_DATA:
+       case TL_PROTOCOLID_COM_CTRL:
+               queue_received_packet(hw, protocol, address, data, data_len,
+                               is_last);
+               break;
+       case TL_PROTOCOLID_SETUP:
+               handle_received_SETUP_packet(hw, address, data, data_len,
+                               is_last);
+               break;
+       }
+}
+
+static void acknowledge_data_read(struct ipw_hardware *hw)
+{
+       if (hw->hw_version == HW_VERSION_1)
+               outw(DCR_RXDONE, hw->base_port + IODCR);
+       else
+               writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+}
+
+/*
+ * Retrieve a packet from the IPW hardware.
+ */
+static void do_receive_packet(struct ipw_hardware *hw)
+{
+       unsigned len;
+       unsigned int i;
+       unsigned char pkt[LL_MTU_MAX];
+
+       start_timing();
+
+       if (hw->hw_version == HW_VERSION_1) {
+               len = inw(hw->base_port + IODRR);
+               if (len > hw->ll_mtu) {
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": received a packet of %u bytes - "
+                              "longer than the MTU!\n", len);
+                       outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
+                       return;
+               }
+
+               for (i = 0; i < len; i += 2) {
+                       __le16 raw_data = inw(hw->base_port + IODRR);
+                       unsigned short data = le16_to_cpu(raw_data);
+
+                       pkt[i] = (unsigned char) data;
+                       pkt[i + 1] = (unsigned char) (data >> 8);
+               }
+       } else {
+               len = inw(hw->base_port + IODMADPR);
+               if (len > hw->ll_mtu) {
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": received a packet of %u bytes - "
+                              "longer than the MTU!\n", len);
+                       writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+                       return;
+               }
+
+               for (i = 0; i < len; i += 2) {
+                       __le16 raw_data = inw(hw->base_port + IODMADPR);
+                       unsigned short data = le16_to_cpu(raw_data);
+
+                       pkt[i] = (unsigned char) data;
+                       pkt[i + 1] = (unsigned char) (data >> 8);
+               }
+
+               while ((i & 3) != 2) {
+                       inw(hw->base_port + IODMADPR);
+                       i += 2;
+               }
+       }
+
+       acknowledge_data_read(hw);
+
+       if (ipwireless_debug)
+               dump_data_bytes("recv", pkt, len);
+
+       handle_received_packet(hw, (union nl_packet *) pkt, len);
+
+       end_read_timing(len);
+}
+
+static int get_current_packet_priority(struct ipw_hardware *hw)
+{
+       /*
+        * If we're initializing, don't send anything of higher priority than
+        * PRIO_SETUP.  The network layer therefore need not care about
+        * hardware initialization - any of its stuff will simply be queued
+        * until setup is complete.
+        */
+       return (hw->to_setup || hw->initializing
+                       ? PRIO_SETUP + 1 :
+                       NL_NUM_OF_PRIORITIES);
+}
+
+/*
+ * return 1 if something has been received from hw
+ */
+static int get_packets_from_hw(struct ipw_hardware *hw)
+{
+       int received = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       while (hw->rx_ready && !hw->blocking_rx) {
+               received = 1;
+               hw->rx_ready--;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               do_receive_packet(hw);
+
+               spin_lock_irqsave(&hw->spinlock, flags);
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       return received;
+}
+
+/*
+ * Send pending packet up to given priority, prioritize SETUP data until
+ * hardware is fully setup.
+ *
+ * return 1 if more packets can be sent
+ */
+static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
+{
+       int more_to_send = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->tx_queued && hw->tx_ready != 0) {
+               int priority;
+               struct ipw_tx_packet *packet = NULL;
+
+               hw->tx_ready--;
+
+               /* Pick a packet */
+               for (priority = 0; priority < priority_limit; priority++) {
+                       if (!list_empty(&hw->tx_queue[priority])) {
+                               packet = list_first_entry(
+                                               &hw->tx_queue[priority],
+                                               struct ipw_tx_packet,
+                                               queue);
+
+                               list_del(&packet->queue);
+
+                               break;
+                       }
+               }
+               if (!packet) {
+                       hw->tx_queued = 0;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       return 0;
+               }
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               /* Send */
+               do_send_packet(hw, packet);
+
+               /* Check if more to send */
+               spin_lock_irqsave(&hw->spinlock, flags);
+               for (priority = 0; priority < priority_limit; priority++)
+                       if (!list_empty(&hw->tx_queue[priority])) {
+                               more_to_send = 1;
+                               break;
+                       }
+
+               if (!more_to_send)
+                       hw->tx_queued = 0;
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       return more_to_send;
+}
+
+/*
+ * Send and receive all queued packets.
+ */
+static void ipwireless_do_tasklet(unsigned long hw_)
+{
+       struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->shutting_down) {
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               return;
+       }
+
+       if (hw->to_setup == 1) {
+               /*
+                * Initial setup data sent to hardware
+                */
+               hw->to_setup = 2;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               ipw_setup_hardware(hw);
+               ipw_send_setup_packet(hw);
+
+               send_pending_packet(hw, PRIO_SETUP + 1);
+               get_packets_from_hw(hw);
+       } else {
+               int priority_limit = get_current_packet_priority(hw);
+               int again;
+
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               do {
+                       again = send_pending_packet(hw, priority_limit);
+                       again |= get_packets_from_hw(hw);
+               } while (again);
+       }
+}
+
+/*
+ * return true if the card is physically present.
+ */
+static int is_card_present(struct ipw_hardware *hw)
+{
+       if (hw->hw_version == HW_VERSION_1)
+               return inw(hw->base_port + IOIR) != 0xFFFF;
+       else
+               return readl(&hw->memory_info_regs->memreg_card_present) ==
+                   CARD_PRESENT_VALUE;
+}
+
+static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
+                                                 struct ipw_hardware *hw)
+{
+       unsigned short irqn;
+
+       irqn = inw(hw->base_port + IOIR);
+
+       /* Check if card is present */
+       if (irqn == 0xFFFF)
+               return IRQ_NONE;
+       else if (irqn != 0) {
+               unsigned short ack = 0;
+               unsigned long flags;
+
+               /* Transmit complete. */
+               if (irqn & IR_TXINTR) {
+                       ack |= IR_TXINTR;
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->tx_ready++;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+               /* Received data */
+               if (irqn & IR_RXINTR) {
+                       ack |= IR_RXINTR;
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->rx_ready++;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+               if (ack != 0) {
+                       outw(ack, hw->base_port + IOIR);
+                       tasklet_schedule(&hw->tasklet);
+               }
+               return IRQ_HANDLED;
+       }
+       return IRQ_NONE;
+}
+
+static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
+{
+       unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
+
+       csr &= 0xfffd;
+       writew(csr, &hw->memregs_CCR->reg_config_and_status);
+}
+
+static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
+                                                    struct ipw_hardware *hw)
+{
+       int tx = 0;
+       int rx = 0;
+       int rx_repeat = 0;
+       int try_mem_tx_old;
+       unsigned long flags;
+
+       do {
+
+       unsigned short memtx = readw(hw->memreg_tx);
+       unsigned short memtx_serial;
+       unsigned short memrxdone =
+               readw(&hw->memory_info_regs->memreg_rx_done);
+
+       try_mem_tx_old = 0;
+
+       /* check whether the interrupt was generated by ipwireless card */
+       if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
+
+               /* check if the card uses memreg_tx_old register */
+               if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+                       memtx = readw(&hw->memory_info_regs->memreg_tx_old);
+                       if (memtx & MEMTX_TX) {
+                               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                                       ": Using memreg_tx_old\n");
+                               hw->memreg_tx =
+                                       &hw->memory_info_regs->memreg_tx_old;
+                       } else {
+                               return IRQ_NONE;
+                       }
+               } else {
+                       return IRQ_NONE;
+               }
+       }
+
+       /*
+        * See if the card is physically present. Note that while it is
+        * powering up, it appears not to be present.
+        */
+       if (!is_card_present(hw)) {
+               acknowledge_pcmcia_interrupt(hw);
+               return IRQ_HANDLED;
+       }
+
+       memtx_serial = memtx & (unsigned short) 0xff00;
+       if (memtx & MEMTX_TX) {
+               writew(memtx_serial, hw->memreg_tx);
+
+               if (hw->serial_number_detected) {
+                       if (memtx_serial != hw->last_memtx_serial) {
+                               hw->last_memtx_serial = memtx_serial;
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                               hw->rx_ready++;
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               rx = 1;
+                       } else
+                               /* Ignore 'Timer Recovery' duplicates. */
+                               rx_repeat = 1;
+               } else {
+                       /*
+                        * If a non-zero serial number is seen, then enable
+                        * serial number checking.
+                        */
+                       if (memtx_serial != 0) {
+                               hw->serial_number_detected = 1;
+                               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                                       ": memreg_tx serial num detected\n");
+
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                               hw->rx_ready++;
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                       }
+                       rx = 1;
+               }
+       }
+       if (memrxdone & MEMRX_RX_DONE) {
+               writew(0, &hw->memory_info_regs->memreg_rx_done);
+               spin_lock_irqsave(&hw->spinlock, flags);
+               hw->tx_ready++;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               tx = 1;
+       }
+       if (tx)
+               writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+
+       acknowledge_pcmcia_interrupt(hw);
+
+       if (tx || rx)
+               tasklet_schedule(&hw->tasklet);
+       else if (!rx_repeat) {
+               if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+                       if (hw->serial_number_detected)
+                               printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": spurious interrupt - new_tx mode\n");
+                       else {
+                               printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": no valid memreg_tx value - "
+                                       "switching to the old memreg_tx\n");
+                               hw->memreg_tx =
+                                       &hw->memory_info_regs->memreg_tx_old;
+                               try_mem_tx_old = 1;
+                       }
+               } else
+                       printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": spurious interrupt - old_tx mode\n");
+       }
+
+       } while (try_mem_tx_old == 1);
+
+       return IRQ_HANDLED;
+}
+
+irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+       struct ipw_hardware *hw = dev_id;
+
+       if (hw->hw_version == HW_VERSION_1)
+               return ipwireless_handle_v1_interrupt(irq, hw);
+       else
+               return ipwireless_handle_v2_v3_interrupt(irq, hw);
+}
+
+static void flush_packets_to_hw(struct ipw_hardware *hw)
+{
+       int priority_limit;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       priority_limit = get_current_packet_priority(hw);
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       while (send_pending_packet(hw, priority_limit));
+}
+
+static void send_packet(struct ipw_hardware *hw, int priority,
+                       struct ipw_tx_packet *packet)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       list_add_tail(&packet->queue, &hw->tx_queue[priority]);
+       hw->tx_queued = 1;
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       flush_packets_to_hw(hw);
+}
+
+/* Create data packet, non-atomic allocation */
+static void *alloc_data_packet(int data_size,
+                               unsigned char dest_addr,
+                               unsigned char protocol)
+{
+       struct ipw_tx_packet *packet = kzalloc(
+                       sizeof(struct ipw_tx_packet) + data_size,
+                       GFP_ATOMIC);
+
+       if (!packet)
+               return NULL;
+
+       INIT_LIST_HEAD(&packet->queue);
+       packet->dest_addr = dest_addr;
+       packet->protocol = protocol;
+       packet->length = data_size;
+
+       return packet;
+}
+
+static void *alloc_ctrl_packet(int header_size,
+                              unsigned char dest_addr,
+                              unsigned char protocol,
+                              unsigned char sig_no)
+{
+       /*
+        * sig_no is located right after ipw_tx_packet struct in every
+        * CTRL or SETUP packets, we can use ipw_control_packet as a
+        * common struct
+        */
+       struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
+
+       if (!packet)
+               return NULL;
+
+       INIT_LIST_HEAD(&packet->header.queue);
+       packet->header.dest_addr = dest_addr;
+       packet->header.protocol = protocol;
+       packet->header.length = header_size - sizeof(struct ipw_tx_packet);
+       packet->body.sig_no = sig_no;
+
+       return packet;
+}
+
+int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
+                           unsigned char *data, unsigned int length,
+                           void (*callback) (void *cb, unsigned int length),
+                           void *callback_data)
+{
+       struct ipw_tx_packet *packet;
+
+       packet = alloc_data_packet(length,
+                              (unsigned char) (channel_idx + 1),
+                              TL_PROTOCOLID_COM_DATA);
+       if (!packet)
+               return -ENOMEM;
+       packet->packet_callback = callback;
+       packet->callback_data = callback_data;
+       memcpy((unsigned char *) packet +
+                       sizeof(struct ipw_tx_packet), data, length);
+
+       send_packet(hw, PRIO_DATA, packet);
+       return 0;
+}
+
+static int set_control_line(struct ipw_hardware *hw, int prio,
+                          unsigned int channel_idx, int line, int state)
+{
+       struct ipw_control_packet *packet;
+       int protocolid = TL_PROTOCOLID_COM_CTRL;
+
+       if (prio == PRIO_SETUP)
+               protocolid = TL_PROTOCOLID_SETUP;
+
+       packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
+                       (unsigned char) (channel_idx + 1),
+                       protocolid, line);
+       if (!packet)
+               return -ENOMEM;
+       packet->header.length = sizeof(struct ipw_control_packet_body);
+       packet->body.value = (unsigned char) (state == 0 ? 0 : 1);
+       send_packet(hw, prio, &packet->header);
+       return 0;
+}
+
+
+static int set_DTR(struct ipw_hardware *hw, int priority,
+                  unsigned int channel_idx, int state)
+{
+       if (state != 0)
+               hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
+       else
+               hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
+
+       return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
+}
+
+static int set_RTS(struct ipw_hardware *hw, int priority,
+                  unsigned int channel_idx, int state)
+{
+       if (state != 0)
+               hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
+       else
+               hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
+
+       return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
+}
+
+int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
+                      int state)
+{
+       return set_DTR(hw, PRIO_CTRL, channel_idx, state);
+}
+
+int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
+                      int state)
+{
+       return set_RTS(hw, PRIO_CTRL, channel_idx, state);
+}
+
+struct ipw_setup_get_version_query_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_get_version_qry body;
+};
+
+struct ipw_setup_config_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_config_msg body;
+};
+
+struct ipw_setup_config_done_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_config_done_msg body;
+};
+
+struct ipw_setup_open_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_open_msg body;
+};
+
+struct ipw_setup_info_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_info_msg body;
+};
+
+struct ipw_setup_reboot_msg_ack {
+       struct ipw_tx_packet header;
+       struct TlSetupRebootMsgAck body;
+};
+
+/* This handles the actual initialization of the card */
+static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
+{
+       struct ipw_setup_config_packet *config_packet;
+       struct ipw_setup_config_done_packet *config_done_packet;
+       struct ipw_setup_open_packet *open_packet;
+       struct ipw_setup_info_packet *info_packet;
+       int port;
+       unsigned int channel_idx;
+
+       /* generate config packet */
+       for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
+               config_packet = alloc_ctrl_packet(
+                               sizeof(struct ipw_setup_config_packet),
+                               ADDR_SETUP_PROT,
+                               TL_PROTOCOLID_SETUP,
+                               TL_SETUP_SIGNO_CONFIG_MSG);
+               if (!config_packet)
+                       goto exit_nomem;
+               config_packet->header.length = sizeof(struct tl_setup_config_msg);
+               config_packet->body.port_no = port;
+               config_packet->body.prio_data = PRIO_DATA;
+               config_packet->body.prio_ctrl = PRIO_CTRL;
+               send_packet(hw, PRIO_SETUP, &config_packet->header);
+       }
+       config_done_packet = alloc_ctrl_packet(
+                       sizeof(struct ipw_setup_config_done_packet),
+                       ADDR_SETUP_PROT,
+                       TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_CONFIG_DONE_MSG);
+       if (!config_done_packet)
+               goto exit_nomem;
+       config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
+       send_packet(hw, PRIO_SETUP, &config_done_packet->header);
+
+       /* generate open packet */
+       for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
+               open_packet = alloc_ctrl_packet(
+                               sizeof(struct ipw_setup_open_packet),
+                               ADDR_SETUP_PROT,
+                               TL_PROTOCOLID_SETUP,
+                               TL_SETUP_SIGNO_OPEN_MSG);
+               if (!open_packet)
+                       goto exit_nomem;
+               open_packet->header.length = sizeof(struct tl_setup_open_msg);
+               open_packet->body.port_no = port;
+               send_packet(hw, PRIO_SETUP, &open_packet->header);
+       }
+       for (channel_idx = 0;
+                       channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
+               int ret;
+
+               ret = set_DTR(hw, PRIO_SETUP, channel_idx,
+                       (hw->control_lines[channel_idx] &
+                        IPW_CONTROL_LINE_DTR) != 0);
+               if (ret) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": error setting DTR (%d)\n", ret);
+                       return;
+               }
+
+               set_RTS(hw, PRIO_SETUP, channel_idx,
+                       (hw->control_lines [channel_idx] &
+                        IPW_CONTROL_LINE_RTS) != 0);
+               if (ret) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": error setting RTS (%d)\n", ret);
+                       return;
+               }
+       }
+       /*
+        * For NDIS we assume that we are using sync PPP frames, for COM async.
+        * This driver uses NDIS mode too. We don't bother with translation
+        * from async -> sync PPP.
+        */
+       info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
+                       ADDR_SETUP_PROT,
+                       TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_INFO_MSG);
+       if (!info_packet)
+               goto exit_nomem;
+       info_packet->header.length = sizeof(struct tl_setup_info_msg);
+       info_packet->body.driver_type = NDISWAN_DRIVER;
+       info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
+       info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
+       send_packet(hw, PRIO_SETUP, &info_packet->header);
+
+       /* Initialization is now complete, so we clear the 'to_setup' flag */
+       hw->to_setup = 0;
+
+       return;
+
+exit_nomem:
+       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                       ": not enough memory to alloc control packet\n");
+       hw->to_setup = -1;
+}
+
+static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
+               unsigned char vers_no)
+{
+       del_timer(&hw->setup_timer);
+       hw->initializing = 0;
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
+
+       if (vers_no == TL_SETUP_VERSION)
+               __handle_setup_get_version_rsp(hw);
+       else
+               printk(KERN_ERR
+                               IPWIRELESS_PCCARD_NAME
+                               ": invalid hardware version no %u\n",
+                               (unsigned int) vers_no);
+}
+
+static void ipw_send_setup_packet(struct ipw_hardware *hw)
+{
+       struct ipw_setup_get_version_query_packet *ver_packet;
+
+       ver_packet = alloc_ctrl_packet(
+                       sizeof(struct ipw_setup_get_version_query_packet),
+                       ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_GET_VERSION_QRY);
+       ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
+
+       /*
+        * Response is handled in handle_received_SETUP_packet
+        */
+       send_packet(hw, PRIO_SETUP, &ver_packet->header);
+}
+
+static void handle_received_SETUP_packet(struct ipw_hardware *hw,
+                                        unsigned int address,
+                                        unsigned char *data, int len,
+                                        int is_last)
+{
+       union ipw_setup_rx_msg *rx_msg = (union ipw_setup_rx_msg *) data;
+
+       if (address != ADDR_SETUP_PROT) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": setup packet has bad address %d\n", address);
+               return;
+       }
+
+       switch (rx_msg->sig_no) {
+       case TL_SETUP_SIGNO_GET_VERSION_RSP:
+               if (hw->to_setup)
+                       handle_setup_get_version_rsp(hw,
+                                       rx_msg->version_rsp_msg.version);
+               break;
+
+       case TL_SETUP_SIGNO_OPEN_MSG:
+               if (ipwireless_debug) {
+                       unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
+
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": OPEN_MSG [channel %u] reply received\n",
+                              channel_idx);
+               }
+               break;
+
+       case TL_SETUP_SIGNO_INFO_MSG_ACK:
+               if (ipwireless_debug)
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": card successfully configured as NDISWAN\n");
+               break;
+
+       case TL_SETUP_SIGNO_REBOOT_MSG:
+               if (hw->to_setup)
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": Setup not completed - ignoring reboot msg\n");
+               else {
+                       struct ipw_setup_reboot_msg_ack *packet;
+
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": Acknowledging REBOOT message\n");
+                       packet = alloc_ctrl_packet(
+                                       sizeof(struct ipw_setup_reboot_msg_ack),
+                                       ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
+                                       TL_SETUP_SIGNO_REBOOT_MSG_ACK);
+                       packet->header.length =
+                               sizeof(struct TlSetupRebootMsgAck);
+                       send_packet(hw, PRIO_SETUP, &packet->header);
+                       if (hw->reboot_callback)
+                               hw->reboot_callback(hw->reboot_callback_data);
+               }
+               break;
+
+       default:
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": unknown setup message %u received\n",
+                      (unsigned int) rx_msg->sig_no);
+       }
+}
+
+static void do_close_hardware(struct ipw_hardware *hw)
+{
+       unsigned int irqn;
+
+       if (hw->hw_version == HW_VERSION_1) {
+               /* Disable TX and RX interrupts. */
+               outw(0, hw->base_port + IOIER);
+
+               /* Acknowledge any outstanding interrupt requests */
+               irqn = inw(hw->base_port + IOIR);
+               if (irqn & IR_TXINTR)
+                       outw(IR_TXINTR, hw->base_port + IOIR);
+               if (irqn & IR_RXINTR)
+                       outw(IR_RXINTR, hw->base_port + IOIR);
+
+               synchronize_irq(hw->irq);
+       }
+}
+
+struct ipw_hardware *ipwireless_hardware_create(void)
+{
+       int i;
+       struct ipw_hardware *hw =
+               kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
+
+       if (!hw)
+               return NULL;
+
+       hw->irq = -1;
+       hw->initializing = 1;
+       hw->tx_ready = 1;
+       hw->rx_bytes_queued = 0;
+       hw->rx_pool_size = 0;
+       hw->last_memtx_serial = (unsigned short) 0xffff;
+       for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
+               INIT_LIST_HEAD(&hw->tx_queue[i]);
+
+       INIT_LIST_HEAD(&hw->rx_queue);
+       INIT_LIST_HEAD(&hw->rx_pool);
+       spin_lock_init(&hw->spinlock);
+       tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
+       INIT_WORK(&hw->work_rx, ipw_receive_data_work);
+       setup_timer(&hw->setup_timer, ipwireless_setup_timer,
+                       (unsigned long) hw);
+
+       return hw;
+}
+
+void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
+               unsigned int base_port,
+               void __iomem *attr_memory,
+               void __iomem *common_memory,
+               int is_v2_card,
+               void (*reboot_callback) (void *data),
+               void *reboot_callback_data)
+{
+       if (hw->removed) {
+               hw->removed = 0;
+               enable_irq(hw->irq);
+       }
+       hw->base_port = base_port;
+       hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1;
+       hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2;
+       hw->memregs_CCR = (struct MEMCCR __iomem *)
+                       ((unsigned short __iomem *) attr_memory + 0x200);
+       hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
+       hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
+       hw->reboot_callback = reboot_callback;
+       hw->reboot_callback_data = reboot_callback_data;
+}
+
+void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
+{
+       hw->initializing = 1;
+       hw->init_loops = 0;
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": waiting for card to start up...\n");
+       ipwireless_setup_timer((unsigned long) hw);
+}
+
+static void ipwireless_setup_timer(unsigned long data)
+{
+       struct ipw_hardware *hw = (struct ipw_hardware *) data;
+
+       hw->init_loops++;
+
+       if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
+                       hw->hw_version == HW_VERSION_2 &&
+                       hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                               ": failed to startup using TX2, trying TX\n");
+
+               hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
+               hw->init_loops = 0;
+       }
+       /* Give up after a certain number of retries */
+       if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": card failed to start up!\n");
+               hw->initializing = 0;
+       } else {
+               /* Do not attempt to write to the board if it is not present. */
+               if (is_card_present(hw)) {
+                       unsigned long flags;
+
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->to_setup = 1;
+                       hw->tx_ready = 1;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       tasklet_schedule(&hw->tasklet);
+               }
+
+               mod_timer(&hw->setup_timer,
+                       jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
+       }
+}
+
+/*
+ * Stop any interrupts from executing so that, once this function returns,
+ * other layers of the driver can be sure they won't get any more callbacks.
+ * Thus must be called on a proper process context.
+ */
+void ipwireless_stop_interrupts(struct ipw_hardware *hw)
+{
+       if (!hw->shutting_down) {
+               /* Tell everyone we are going down. */
+               hw->shutting_down = 1;
+               del_timer(&hw->setup_timer);
+
+               /* Prevent the hardware from sending any more interrupts */
+               do_close_hardware(hw);
+       }
+}
+
+void ipwireless_hardware_free(struct ipw_hardware *hw)
+{
+       int i;
+       struct ipw_rx_packet *rp, *rq;
+       struct ipw_tx_packet *tp, *tq;
+
+       ipwireless_stop_interrupts(hw);
+
+       flush_scheduled_work();
+
+       for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
+               if (hw->packet_assembler[i] != NULL)
+                       kfree(hw->packet_assembler[i]);
+
+       for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
+               list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
+                       list_del(&tp->queue);
+                       kfree(tp);
+               }
+
+       list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
+               list_del(&rp->queue);
+               kfree(rp);
+       }
+
+       list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
+               list_del(&rp->queue);
+               kfree(rp);
+       }
+       kfree(hw);
+}
+
+/*
+ * Associate the specified network with this hardware, so it will receive events
+ * from it.
+ */
+void ipwireless_associate_network(struct ipw_hardware *hw,
+                                 struct ipw_network *network)
+{
+       hw->network = network;
+}
diff --git a/drivers/char/pcmcia/ipwireless/hardware.h b/drivers/char/pcmcia/ipwireless/hardware.h
new file mode 100644 (file)
index 0000000..c83190f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_HARDWARE_H_
+#define _IPWIRELESS_CS_HARDWARE_H_
+
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+
+#define IPW_CONTROL_LINE_CTS 0x0001
+#define IPW_CONTROL_LINE_DCD 0x0002
+#define IPW_CONTROL_LINE_DSR 0x0004
+#define IPW_CONTROL_LINE_RI  0x0008
+#define IPW_CONTROL_LINE_DTR 0x0010
+#define IPW_CONTROL_LINE_RTS 0x0020
+
+struct ipw_hardware;
+struct ipw_network;
+
+struct ipw_hardware *ipwireless_hardware_create(void);
+void ipwireless_hardware_free(struct ipw_hardware *hw);
+irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
+               int state);
+int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
+               int state);
+int ipwireless_send_packet(struct ipw_hardware *hw,
+                           unsigned int channel_idx,
+                           unsigned char *data,
+                           unsigned int length,
+                           void (*packet_sent_callback) (void *cb,
+                                                         unsigned int length),
+                           void *sent_cb_data);
+void ipwireless_associate_network(struct ipw_hardware *hw,
+               struct ipw_network *net);
+void ipwireless_stop_interrupts(struct ipw_hardware *hw);
+void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
+                                unsigned int base_port,
+                                void __iomem *attr_memory,
+                                void __iomem *common_memory,
+                                int is_v2_card,
+                                void (*reboot_cb) (void *data),
+                                void *reboot_cb_data);
+void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw);
+void ipwireless_sleep(unsigned int tenths);
+int ipwireless_dump_hardware_state(char *p, size_t limit,
+                                  struct ipw_hardware *hw);
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
new file mode 100644 (file)
index 0000000..00c7f84
--- /dev/null
@@ -0,0 +1,501 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include "hardware.h"
+#include "network.h"
+#include "main.h"
+#include "tty.h"
+
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include <pcmcia/version.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/device_id.h>
+#include <pcmcia/ss.h>
+#include <pcmcia/ds.h>
+#include <pcmcia/cs.h>
+
+static struct pcmcia_device_id ipw_ids[] = {
+       PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
+       PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
+
+static void ipwireless_detach(struct pcmcia_device *link);
+
+/*
+ * Module params
+ */
+/* Debug mode: more verbose, print sent/recv bytes */
+int ipwireless_debug;
+int ipwireless_loopback;
+int ipwireless_out_queue = 1;
+
+module_param_named(debug, ipwireless_debug, int, 0);
+module_param_named(loopback, ipwireless_loopback, int, 0);
+module_param_named(out_queue, ipwireless_out_queue, int, 0);
+MODULE_PARM_DESC(debug, "switch on debug messages [0]");
+MODULE_PARM_DESC(loopback,
+               "debug: enable ras_raw channel [0]");
+MODULE_PARM_DESC(out_queue, "debug: set size of outgoing queue [1]");
+
+/* Executes in process context. */
+static void signalled_reboot_work(struct work_struct *work_reboot)
+{
+       struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
+                       work_reboot);
+       struct pcmcia_device *link = ipw->link;
+       int ret = pccard_reset_card(link->socket);
+
+       if (ret != CS_SUCCESS)
+               cs_error(link, ResetCard, ret);
+}
+
+static void signalled_reboot_callback(void *callback_data)
+{
+       struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
+
+       /* Delegate to process context. */
+       schedule_work(&ipw->work_reboot);
+}
+
+static int config_ipwireless(struct ipw_dev *ipw)
+{
+       struct pcmcia_device *link = ipw->link;
+       int ret;
+       config_info_t conf;
+       tuple_t tuple;
+       unsigned short buf[64];
+       cisparse_t parse;
+       unsigned short cor_value;
+       win_req_t request_attr_memory;
+       win_req_t request_common_memory;
+       memreq_t memreq_attr_memory;
+       memreq_t memreq_common_memory;
+
+       ipw->is_v2_card = 0;
+
+       tuple.Attributes = 0;
+       tuple.TupleData = (cisdata_t *) buf;
+       tuple.TupleDataMax = sizeof(buf);
+       tuple.TupleOffset = 0;
+
+       tuple.DesiredTuple = RETURN_FIRST_TUPLE;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       while (ret == 0) {
+               ret = pcmcia_get_tuple_data(link, &tuple);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, GetTupleData, ret);
+                       goto exit0;
+               }
+               ret = pcmcia_get_next_tuple(link, &tuple);
+       }
+
+       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, ParseTuple, ret);
+               goto exit0;
+       }
+
+       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+       link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
+       link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
+       link->io.IOAddrLines = 16;
+
+       link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
+
+       /* 0x40 causes it to generate level mode interrupts. */
+       /* 0x04 enables IREQ pin. */
+       cor_value = parse.cftable_entry.index | 0x44;
+       link->conf.ConfigIndex = cor_value;
+
+       /* IRQ and I/O settings */
+       tuple.DesiredTuple = CISTPL_CONFIG;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+       link->conf.Attributes = CONF_ENABLE_IRQ;
+       link->conf.ConfigBase = parse.config.base;
+       link->conf.Present = parse.config.rmask[0];
+       link->conf.IntType = INT_MEMORY_AND_IO;
+
+       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
+       link->irq.Handler = ipwireless_interrupt;
+       link->irq.Instance = ipw->hardware;
+
+       ret = pcmcia_request_io(link, &link->io);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestIO, ret);
+               goto exit0;
+       }
+
+       /* memory settings */
+
+       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit1;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit1;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, ParseTuple, ret);
+               goto exit1;
+       }
+
+       if (parse.cftable_entry.mem.nwin > 0) {
+               request_common_memory.Attributes =
+                       WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
+               request_common_memory.Base =
+                       parse.cftable_entry.mem.win[0].host_addr;
+               request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
+               if (request_common_memory.Size < 0x1000)
+                       request_common_memory.Size = 0x1000;
+               request_common_memory.AccessSpeed = 0;
+
+               ret = pcmcia_request_window(&link, &request_common_memory,
+                               &ipw->handle_common_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, RequestWindow, ret);
+                       goto exit1;
+               }
+
+               memreq_common_memory.CardOffset =
+                       parse.cftable_entry.mem.win[0].card_addr;
+               memreq_common_memory.Page = 0;
+
+               ret = pcmcia_map_mem_page(ipw->handle_common_memory,
+                               &memreq_common_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, MapMemPage, ret);
+                       goto exit1;
+               }
+
+               ipw->is_v2_card =
+                       parse.cftable_entry.mem.win[0].len == 0x100;
+
+               ipw->common_memory = ioremap(request_common_memory.Base,
+                               request_common_memory.Size);
+
+               request_attr_memory.Attributes =
+                       WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
+               request_attr_memory.Base = 0;
+               request_attr_memory.Size = 0;   /* this used to be 0x1000 */
+               request_attr_memory.AccessSpeed = 0;
+
+               ret = pcmcia_request_window(&link, &request_attr_memory,
+                               &ipw->handle_attr_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, RequestWindow, ret);
+                       goto exit2;
+               }
+
+               memreq_attr_memory.CardOffset = 0;
+               memreq_attr_memory.Page = 0;
+
+               ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
+                               &memreq_attr_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, MapMemPage, ret);
+                       goto exit2;
+               }
+
+               ipw->attr_memory = ioremap(request_attr_memory.Base,
+                               request_attr_memory.Size);
+       }
+
+       INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
+
+       ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
+                                   ipw->attr_memory, ipw->common_memory,
+                                   ipw->is_v2_card, signalled_reboot_callback,
+                                   ipw);
+
+       ret = pcmcia_request_irq(link, &link->irq);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestIRQ, ret);
+               goto exit3;
+       }
+
+       /* Look up current Vcc */
+
+       ret = pcmcia_get_configuration_info(link, &conf);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetConfigurationInfo, ret);
+               goto exit4;
+       }
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
+                       ipw->is_v2_card ? "V2/V3" : "V1");
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                       ": I/O ports 0x%04x-0x%04x, irq %d\n",
+                       (unsigned int) link->io.BasePort1,
+                       (unsigned int) (link->io.BasePort1 +
+                               link->io.NumPorts1 - 1),
+                       (unsigned int) link->irq.AssignedIRQ);
+       if (ipw->attr_memory && ipw->common_memory)
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                               ": attr memory 0x%08lx-0x%08lx, "
+                               "common memory 0x%08lx-0x%08lx\n",
+                               request_attr_memory.Base,
+                               request_attr_memory.Base
+                               + request_attr_memory.Size - 1,
+                               request_common_memory.Base,
+                               request_common_memory.Base
+                               + request_common_memory.Size - 1);
+
+       ipw->network = ipwireless_network_create(ipw->hardware);
+       if (!ipw->network)
+               goto exit3;
+
+       ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
+                       ipw->nodes);
+       if (!ipw->tty)
+               goto exit3;
+
+       ipwireless_init_hardware_v2_v3(ipw->hardware);
+
+       /*
+        * Do the RequestConfiguration last, because it enables interrupts.
+        * Then we don't get any interrupts before we're ready for them.
+        */
+       ret = pcmcia_request_configuration(link, &link->conf);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestConfiguration, ret);
+               goto exit4;
+       }
+
+       link->dev_node = &ipw->nodes[0];
+
+       return 0;
+
+exit4:
+       pcmcia_disable_device(link);
+exit3:
+       if (ipw->attr_memory) {
+               iounmap(ipw->attr_memory);
+               pcmcia_release_window(ipw->handle_attr_memory);
+               pcmcia_disable_device(link);
+       }
+exit2:
+       if (ipw->common_memory) {
+               iounmap(ipw->common_memory);
+               pcmcia_release_window(ipw->handle_common_memory);
+       }
+exit1:
+       pcmcia_disable_device(link);
+exit0:
+       return -1;
+}
+
+static void release_ipwireless(struct ipw_dev *ipw)
+{
+       struct pcmcia_device *link = ipw->link;
+
+       pcmcia_disable_device(link);
+
+       if (ipw->common_memory)
+               iounmap(ipw->common_memory);
+       if (ipw->attr_memory)
+               iounmap(ipw->attr_memory);
+       if (ipw->common_memory)
+               pcmcia_release_window(ipw->handle_common_memory);
+       if (ipw->attr_memory)
+               pcmcia_release_window(ipw->handle_attr_memory);
+       pcmcia_disable_device(link);
+}
+
+/*
+ * ipwireless_attach() creates an "instance" of the driver, allocating
+ * local data structures for one device (one interface).  The device
+ * is registered with Card Services.
+ *
+ * The pcmcia_device structure is initialized, but we don't actually
+ * configure the card at this point -- we wait until we receive a
+ * card insertion event.
+ */
+static int ipwireless_attach(struct pcmcia_device *link)
+{
+       struct ipw_dev *ipw;
+       int ret;
+
+       ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
+       if (!ipw)
+               return -ENOMEM;
+
+       ipw->link = link;
+       link->priv = ipw;
+       link->irq.Instance = ipw;
+
+       /* Link this device into our device list. */
+       link->dev_node = &ipw->nodes[0];
+
+       ipw->hardware = ipwireless_hardware_create();
+       if (!ipw->hardware) {
+               kfree(ipw);
+               return -ENOMEM;
+       }
+       /* RegisterClient will call config_ipwireless */
+
+       ret = config_ipwireless(ipw);
+
+       if (ret != 0) {
+               cs_error(link, RegisterClient, ret);
+               ipwireless_detach(link);
+               return ret;
+       }
+
+       return 0;
+}
+
+/*
+ * This deletes a driver "instance".  The device is de-registered with
+ * Card Services.  If it has been released, all local data structures
+ * are freed.  Otherwise, the structures will be freed when the device
+ * is released.
+ */
+static void ipwireless_detach(struct pcmcia_device *link)
+{
+       struct ipw_dev *ipw = link->priv;
+
+       release_ipwireless(ipw);
+
+       /* Break the link with Card Services */
+       if (link)
+               pcmcia_disable_device(link);
+
+       if (ipw->tty != NULL)
+               ipwireless_tty_free(ipw->tty);
+       if (ipw->network != NULL)
+               ipwireless_network_free(ipw->network);
+       if (ipw->hardware != NULL)
+               ipwireless_hardware_free(ipw->hardware);
+       kfree(ipw);
+}
+
+static struct pcmcia_driver me = {
+       .owner          = THIS_MODULE,
+       .probe          = ipwireless_attach,
+       .remove         = ipwireless_detach,
+       .drv = { .name  = IPWIRELESS_PCCARD_NAME },
+       .id_table       = ipw_ids
+};
+
+/*
+ * Module insertion : initialisation of the module.
+ * Register the card with cardmgr...
+ */
+static int __init init_ipwireless(void)
+{
+       int ret;
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
+              IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
+
+       ret = ipwireless_tty_init();
+       if (ret != 0)
+               return ret;
+
+       ret = pcmcia_register_driver(&me);
+       if (ret != 0)
+               ipwireless_tty_release();
+
+       return ret;
+}
+
+/*
+ * Module removal
+ */
+static void __exit exit_ipwireless(void)
+{
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
+                       IPWIRELESS_PCMCIA_VERSION " removed\n");
+
+       pcmcia_unregister_driver(&me);
+       ipwireless_tty_release();
+}
+
+module_init(init_ipwireless);
+module_exit(exit_ipwireless);
+
+MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
+MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/char/pcmcia/ipwireless/main.h b/drivers/char/pcmcia/ipwireless/main.h
new file mode 100644 (file)
index 0000000..1bfdcc8
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_H_
+#define _IPWIRELESS_CS_H_
+
+#include <linux/sched.h>
+#include <linux/types.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/ds.h>
+
+#include "hardware.h"
+
+#define IPWIRELESS_PCCARD_NAME         "ipwireless"
+#define IPWIRELESS_PCMCIA_VERSION      "1.1"
+#define IPWIRELESS_PCMCIA_AUTHOR        \
+       "Stephen Blackheath, Ben Martel, Jiri Kosina and David Sterba"
+
+#define IPWIRELESS_TX_QUEUE_SIZE  262144
+#define IPWIRELESS_RX_QUEUE_SIZE  262144
+
+#define IPWIRELESS_STATE_DEBUG
+
+struct ipw_hardware;
+struct ipw_network;
+struct ipw_tty;
+
+struct ipw_dev {
+       struct pcmcia_device *link;
+       int is_v2_card;
+       window_handle_t handle_attr_memory;
+       void __iomem *attr_memory;
+       window_handle_t handle_common_memory;
+       void __iomem *common_memory;
+       dev_node_t nodes[2];
+       /* Reference to attribute memory, containing CIS data */
+       void *attribute_memory;
+
+       /* Hardware context */
+       struct ipw_hardware *hardware;
+       /* Network layer context */
+       struct ipw_network *network;
+       /* TTY device context */
+       struct ipw_tty *tty;
+       struct work_struct work_reboot;
+};
+
+/* Module parametres */
+extern int ipwireless_debug;
+extern int ipwireless_loopback;
+extern int ipwireless_out_queue;
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/network.c b/drivers/char/pcmcia/ipwireless/network.c
new file mode 100644 (file)
index 0000000..ff35230
--- /dev/null
@@ -0,0 +1,512 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/ppp_channel.h>
+#include <linux/ppp_defs.h>
+#include <linux/if_ppp.h>
+#include <linux/skbuff.h>
+
+#include "network.h"
+#include "hardware.h"
+#include "main.h"
+#include "tty.h"
+
+#define MAX_OUTGOING_PACKETS_QUEUED   ipwireless_out_queue
+#define MAX_ASSOCIATED_TTYS 2
+
+#define SC_RCV_BITS     (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
+
+struct ipw_network {
+       /* Hardware context, used for calls to hardware layer. */
+       struct ipw_hardware *hardware;
+       /* Context for kernel 'generic_ppp' functionality */
+       struct ppp_channel *ppp_channel;
+       /* tty context connected with IPW console */
+       struct ipw_tty *associated_ttys[NO_OF_IPW_CHANNELS][MAX_ASSOCIATED_TTYS];
+       /* True if ppp needs waking up once we're ready to xmit */
+       int ppp_blocked;
+       /* Number of packets queued up in hardware module. */
+       int outgoing_packets_queued;
+       /* Spinlock to avoid interrupts during shutdown */
+       spinlock_t spinlock;
+       struct mutex close_lock;
+
+       /* PPP ioctl data, not actually used anywere */
+       unsigned int flags;
+       unsigned int rbits;
+       u32 xaccm[8];
+       u32 raccm;
+       int mru;
+
+       int shutting_down;
+       unsigned int ras_control_lines;
+
+       struct work_struct work_go_online;
+       struct work_struct work_go_offline;
+};
+
+
+#ifdef IPWIRELESS_STATE_DEBUG
+int ipwireless_dump_network_state(char *p, size_t limit,
+                                 struct ipw_network *network)
+{
+       return snprintf(p, limit,
+                       "debug: ppp_blocked=%d\n"
+                       "debug: outgoing_packets_queued=%d\n"
+                       "debug: network.shutting_down=%d\n",
+                       network->ppp_blocked,
+                       network->outgoing_packets_queued,
+                       network->shutting_down);
+}
+#endif
+
+static void notify_packet_sent(void *callback_data, unsigned int packet_length)
+{
+       struct ipw_network *network = callback_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       network->outgoing_packets_queued--;
+       if (network->ppp_channel != NULL) {
+               if (network->ppp_blocked) {
+                       network->ppp_blocked = 0;
+                       spin_unlock_irqrestore(&network->spinlock, flags);
+                       ppp_output_wakeup(network->ppp_channel);
+                       if (ipwireless_debug)
+                               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                                      ": ppp unblocked\n");
+               } else
+                       spin_unlock_irqrestore(&network->spinlock, flags);
+       } else
+               spin_unlock_irqrestore(&network->spinlock, flags);
+}
+
+/*
+ * Called by the ppp system when it has a packet to send to the hardware.
+ */
+static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
+                                    struct sk_buff *skb)
+{
+       struct ipw_network *network = ppp_channel->private;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->outgoing_packets_queued < MAX_OUTGOING_PACKETS_QUEUED) {
+               unsigned char *buf;
+               static unsigned char header[] = {
+                       PPP_ALLSTATIONS, /* 0xff */
+                       PPP_UI,          /* 0x03 */
+               };
+               int ret;
+
+               network->outgoing_packets_queued++;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+
+               /*
+                * If we have the requested amount of headroom in the skb we
+                * were handed, then we can add the header efficiently.
+                */
+               if (skb_headroom(skb) >= 2) {
+                       memcpy(skb_push(skb, 2), header, 2);
+                       ret = ipwireless_send_packet(network->hardware,
+                                              IPW_CHANNEL_RAS, skb->data,
+                                              skb->len,
+                                              notify_packet_sent,
+                                              network);
+                       if (ret == -1) {
+                               skb_pull(skb, 2);
+                               return 0;
+                       }
+               } else {
+                       /* Otherwise (rarely) we do it inefficiently. */
+                       buf = kmalloc(skb->len + 2, GFP_ATOMIC);
+                       if (!buf)
+                               return 0;
+                       memcpy(buf + 2, skb->data, skb->len);
+                       memcpy(buf, header, 2);
+                       ret = ipwireless_send_packet(network->hardware,
+                                              IPW_CHANNEL_RAS, buf,
+                                              skb->len + 2,
+                                              notify_packet_sent,
+                                              network);
+                       kfree(buf);
+                       if (ret == -1)
+                               return 0;
+               }
+               kfree_skb(skb);
+               return 1;
+       } else {
+               /*
+                * Otherwise reject the packet, and flag that the ppp system
+                * needs to be unblocked once we are ready to send.
+                */
+               network->ppp_blocked = 1;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               return 0;
+       }
+}
+
+/* Handle an ioctl call that has come in via ppp. (copy of ppp_async_ioctl() */
+static int ipwireless_ppp_ioctl(struct ppp_channel *ppp_channel,
+                               unsigned int cmd, unsigned long arg)
+{
+       struct ipw_network *network = ppp_channel->private;
+       int err, val;
+       u32 accm[8];
+       int __user *user_arg = (int __user *) arg;
+
+       err = -EFAULT;
+       switch (cmd) {
+       case PPPIOCGFLAGS:
+               val = network->flags | network->rbits;
+               if (put_user(val, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSFLAGS:
+               if (get_user(val, user_arg))
+                       break;
+               network->flags = val & ~SC_RCV_BITS;
+               network->rbits = val & SC_RCV_BITS;
+               err = 0;
+               break;
+
+       case PPPIOCGASYNCMAP:
+               if (put_user(network->xaccm[0], user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSASYNCMAP:
+               if (get_user(network->xaccm[0], user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCGRASYNCMAP:
+               if (put_user(network->raccm, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSRASYNCMAP:
+               if (get_user(network->raccm, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCGXASYNCMAP:
+               if (copy_to_user((void __user *) arg, network->xaccm,
+                                       sizeof(network->xaccm)))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSXASYNCMAP:
+               if (copy_from_user(accm, (void __user *) arg, sizeof(accm)))
+                       break;
+               accm[2] &= ~0x40000000U;        /* can't escape 0x5e */
+               accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
+               memcpy(network->xaccm, accm, sizeof(network->xaccm));
+               err = 0;
+               break;
+
+       case PPPIOCGMRU:
+               if (put_user(network->mru, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSMRU:
+               if (get_user(val, user_arg))
+                       break;
+               if (val < PPP_MRU)
+                       val = PPP_MRU;
+               network->mru = val;
+               err = 0;
+               break;
+
+       default:
+               err = -ENOTTY;
+       }
+
+       return err;
+}
+
+static struct ppp_channel_ops ipwireless_ppp_channel_ops = {
+       .start_xmit = ipwireless_ppp_start_xmit,
+       .ioctl      = ipwireless_ppp_ioctl
+};
+
+static void do_go_online(struct work_struct *work_go_online)
+{
+       struct ipw_network *network =
+               container_of(work_go_online, struct ipw_network,
+                               work_go_online);
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (!network->ppp_channel) {
+               struct ppp_channel *channel;
+
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               channel = kzalloc(sizeof(struct ppp_channel), GFP_KERNEL);
+               if (!channel) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": unable to allocate PPP channel\n");
+                       return;
+               }
+               channel->private = network;
+               channel->mtu = 16384;   /* Wild guess */
+               channel->hdrlen = 2;
+               channel->ops = &ipwireless_ppp_channel_ops;
+
+               network->flags = 0;
+               network->rbits = 0;
+               network->mru = PPP_MRU;
+               memset(network->xaccm, 0, sizeof(network->xaccm));
+               network->xaccm[0] = ~0U;
+               network->xaccm[3] = 0x60000000U;
+               network->raccm = ~0U;
+               ppp_register_channel(channel);
+               spin_lock_irqsave(&network->spinlock, flags);
+               network->ppp_channel = channel;
+       }
+       spin_unlock_irqrestore(&network->spinlock, flags);
+}
+
+static void do_go_offline(struct work_struct *work_go_offline)
+{
+       struct ipw_network *network =
+               container_of(work_go_offline, struct ipw_network,
+                               work_go_offline);
+       unsigned long flags;
+
+       mutex_lock(&network->close_lock);
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL) {
+               struct ppp_channel *channel = network->ppp_channel;
+
+               network->ppp_channel = NULL;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               mutex_unlock(&network->close_lock);
+               ppp_unregister_channel(channel);
+       } else {
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               mutex_unlock(&network->close_lock);
+       }
+}
+
+void ipwireless_network_notify_control_line_change(struct ipw_network *network,
+                                                  unsigned int channel_idx,
+                                                  unsigned int control_lines,
+                                                  unsigned int changed_mask)
+{
+       int i;
+
+       if (channel_idx == IPW_CHANNEL_RAS)
+               network->ras_control_lines = control_lines;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
+               struct ipw_tty *tty =
+                       network->associated_ttys[channel_idx][i];
+
+               /*
+                * If it's associated with a tty (other than the RAS channel
+                * when we're online), then send the data to that tty.  The RAS
+                * channel's data is handled above - it always goes through
+                * ppp_generic.
+                */
+               if (tty)
+                       ipwireless_tty_notify_control_line_change(tty,
+                                                                 channel_idx,
+                                                                 control_lines,
+                                                                 changed_mask);
+       }
+}
+
+/*
+ * Some versions of firmware stuff packets with 0xff 0x03 (PPP: ALLSTATIONS, UI)
+ * bytes, which are required on sent packet, but not always present on received
+ * packets
+ */
+static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
+                                              unsigned int length)
+{
+       struct sk_buff *skb;
+
+       if (length > 2 && data[0] == PPP_ALLSTATIONS && data[1] == PPP_UI) {
+               length -= 2;
+               data += 2;
+       }
+
+       skb = dev_alloc_skb(length + 4);
+       skb_reserve(skb, 2);
+       memcpy(skb_put(skb, length), data, length);
+
+       return skb;
+}
+
+void ipwireless_network_packet_received(struct ipw_network *network,
+                                       unsigned int channel_idx,
+                                       unsigned char *data,
+                                       unsigned int length)
+{
+       int i;
+       unsigned long flags;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
+               struct ipw_tty *tty = network->associated_ttys[channel_idx][i];
+
+               /*
+                * If it's associated with a tty (other than the RAS channel
+                * when we're online), then send the data to that tty.  The RAS
+                * channel's data is handled above - it always goes through
+                * ppp_generic.
+                */
+               if (tty && channel_idx == IPW_CHANNEL_RAS
+                               && (network->ras_control_lines &
+                                       IPW_CONTROL_LINE_DCD) != 0
+                               && ipwireless_tty_is_modem(tty)) {
+                       /*
+                        * If data came in on the RAS channel and this tty is
+                        * the modem tty, and we are online, then we send it to
+                        * the PPP layer.
+                        */
+                       mutex_lock(&network->close_lock);
+                       spin_lock_irqsave(&network->spinlock, flags);
+                       if (network->ppp_channel != NULL) {
+                               struct sk_buff *skb;
+
+                               spin_unlock_irqrestore(&network->spinlock,
+                                               flags);
+
+                               /* Send the data to the ppp_generic module. */
+                               skb = ipw_packet_received_skb(data, length);
+                               ppp_input(network->ppp_channel, skb);
+                       } else
+                               spin_unlock_irqrestore(&network->spinlock,
+                                               flags);
+                       mutex_unlock(&network->close_lock);
+               }
+               /* Otherwise we send it out the tty. */
+               else
+                       ipwireless_tty_received(tty, data, length);
+       }
+}
+
+struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw)
+{
+       struct ipw_network *network =
+               kzalloc(sizeof(struct ipw_network), GFP_ATOMIC);
+
+       if (!network)
+               return NULL;
+
+       spin_lock_init(&network->spinlock);
+       mutex_init(&network->close_lock);
+
+       network->hardware = hw;
+
+       INIT_WORK(&network->work_go_online, do_go_online);
+       INIT_WORK(&network->work_go_offline, do_go_offline);
+
+       ipwireless_associate_network(hw, network);
+
+       return network;
+}
+
+void ipwireless_network_free(struct ipw_network *network)
+{
+       network->shutting_down = 1;
+
+       ipwireless_ppp_close(network);
+       flush_scheduled_work();
+
+       ipwireless_stop_interrupts(network->hardware);
+       ipwireless_associate_network(network->hardware, NULL);
+
+       kfree(network);
+}
+
+void ipwireless_associate_network_tty(struct ipw_network *network,
+                                     unsigned int channel_idx,
+                                     struct ipw_tty *tty)
+{
+       int i;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
+               if (network->associated_ttys[channel_idx][i] == NULL) {
+                       network->associated_ttys[channel_idx][i] = tty;
+                       break;
+               }
+}
+
+void ipwireless_disassociate_network_ttys(struct ipw_network *network,
+                                         unsigned int channel_idx)
+{
+       int i;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
+               network->associated_ttys[channel_idx][i] = NULL;
+}
+
+void ipwireless_ppp_open(struct ipw_network *network)
+{
+       if (ipwireless_debug)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": online\n");
+       schedule_work(&network->work_go_online);
+}
+
+void ipwireless_ppp_close(struct ipw_network *network)
+{
+       /* Disconnect from the wireless network. */
+       if (ipwireless_debug)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": offline\n");
+       schedule_work(&network->work_go_offline);
+}
+
+int ipwireless_ppp_channel_index(struct ipw_network *network)
+{
+       int ret = -1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL)
+               ret = ppp_channel_index(network->ppp_channel);
+       spin_unlock_irqrestore(&network->spinlock, flags);
+
+       return ret;
+}
+
+int ipwireless_ppp_unit_number(struct ipw_network *network)
+{
+       int ret = -1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL)
+               ret = ppp_unit_number(network->ppp_channel);
+       spin_unlock_irqrestore(&network->spinlock, flags);
+
+       return ret;
+}
diff --git a/drivers/char/pcmcia/ipwireless/network.h b/drivers/char/pcmcia/ipwireless/network.h
new file mode 100644 (file)
index 0000000..b0e1e95
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_NETWORK_H_
+#define _IPWIRELESS_CS_NETWORK_H_
+
+#include <linux/types.h>
+
+struct ipw_network;
+struct ipw_tty;
+struct ipw_hardware;
+
+/* Definitions of the different channels on the PCMCIA UE */
+#define IPW_CHANNEL_RAS      0
+#define IPW_CHANNEL_DIALLER  1
+#define IPW_CHANNEL_CONSOLE  2
+#define NO_OF_IPW_CHANNELS   5
+
+void ipwireless_network_notify_control_line_change(struct ipw_network *net,
+               unsigned int channel_idx, unsigned int control_lines,
+               unsigned int control_mask);
+void ipwireless_network_packet_received(struct ipw_network *net,
+               unsigned int channel_idx, unsigned char *data,
+               unsigned int length);
+struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw);
+void ipwireless_network_free(struct ipw_network *net);
+void ipwireless_associate_network_tty(struct ipw_network *net,
+               unsigned int channel_idx, struct ipw_tty *tty);
+void ipwireless_disassociate_network_ttys(struct ipw_network *net,
+               unsigned int channel_idx);
+
+void ipwireless_ppp_open(struct ipw_network *net);
+
+void ipwireless_ppp_close(struct ipw_network *net);
+int ipwireless_ppp_channel_index(struct ipw_network *net);
+int ipwireless_ppp_unit_number(struct ipw_network *net);
+
+int ipwireless_dump_network_state(char *p, size_t limit,
+                                 struct ipw_network *net);
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/setup_protocol.h b/drivers/char/pcmcia/ipwireless/setup_protocol.h
new file mode 100644 (file)
index 0000000..9d6bcc7
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_SETUP_PROTOCOL_H_
+#define _IPWIRELESS_CS_SETUP_PROTOCOL_H_
+
+/* Version of the setup protocol and transport protocols */
+#define TL_SETUP_VERSION               1
+
+#define TL_SETUP_VERSION_QRY_TMO       1000
+#define TL_SETUP_MAX_VERSION_QRY       30
+
+/* Message numbers 0-9 are obsoleted and must not be reused! */
+#define TL_SETUP_SIGNO_GET_VERSION_QRY 10
+#define TL_SETUP_SIGNO_GET_VERSION_RSP 11
+#define TL_SETUP_SIGNO_CONFIG_MSG      12
+#define TL_SETUP_SIGNO_CONFIG_DONE_MSG 13
+#define TL_SETUP_SIGNO_OPEN_MSG                14
+#define TL_SETUP_SIGNO_CLOSE_MSG       15
+
+#define TL_SETUP_SIGNO_INFO_MSG     20
+#define TL_SETUP_SIGNO_INFO_MSG_ACK 21
+
+#define TL_SETUP_SIGNO_REBOOT_MSG      22
+#define TL_SETUP_SIGNO_REBOOT_MSG_ACK  23
+
+/* Synchronous start-messages */
+struct tl_setup_get_version_qry {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_GET_VERSION_QRY */
+} __attribute__ ((__packed__));
+
+struct tl_setup_get_version_rsp {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_GET_VERSION_RSP */
+       unsigned char version;          /* TL_SETUP_VERSION */
+} __attribute__ ((__packed__));
+
+struct tl_setup_config_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CONFIG_MSG */
+       unsigned char port_no;
+       unsigned char prio_data;
+       unsigned char prio_ctrl;
+} __attribute__ ((__packed__));
+
+struct tl_setup_config_done_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */
+} __attribute__ ((__packed__));
+
+/* Asyncronous messages */
+struct tl_setup_open_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_OPEN_MSG */
+       unsigned char port_no;
+} __attribute__ ((__packed__));
+
+struct tl_setup_close_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CLOSE_MSG */
+       unsigned char port_no;
+} __attribute__ ((__packed__));
+
+/* Driver type  - for use in tl_setup_info_msg.driver_type */
+#define COMM_DRIVER     0
+#define NDISWAN_DRIVER  1
+#define NDISWAN_DRIVER_MAJOR_VERSION  2
+#define NDISWAN_DRIVER_MINOR_VERSION  0
+
+/*
+ * It should not matter when this message comes over as we just store the
+ * results and send the ACK.
+ */
+struct tl_setup_info_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_INFO_MSG */
+       unsigned char driver_type;
+       unsigned char major_version;
+       unsigned char minor_version;
+} __attribute__ ((__packed__));
+
+struct tl_setup_info_msgAck {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_INFO_MSG_ACK */
+} __attribute__ ((__packed__));
+
+struct TlSetupRebootMsgAck {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_REBOOT_MSG_ACK */
+} __attribute__ ((__packed__));
+
+/* Define a union of all the msgs that the driver can receive from the card.*/
+union ipw_setup_rx_msg {
+       unsigned char sig_no;
+       struct tl_setup_get_version_rsp version_rsp_msg;
+       struct tl_setup_open_msg open_msg;
+       struct tl_setup_close_msg close_msg;
+       struct tl_setup_info_msg InfoMsg;
+       struct tl_setup_info_msgAck info_msg_ack;
+} __attribute__ ((__packed__));
+
+#endif                         /* _IPWIRELESS_CS_SETUP_PROTOCOL_H_ */
diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
new file mode 100644 (file)
index 0000000..42f3815
--- /dev/null
@@ -0,0 +1,688 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/ppp_defs.h>
+#include <linux/if.h>
+#include <linux/if_ppp.h>
+#include <linux/sched.h>
+#include <linux/serial.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/uaccess.h>
+#include <linux/version.h>
+
+#include "tty.h"
+#include "network.h"
+#include "hardware.h"
+#include "main.h"
+
+#define IPWIRELESS_PCMCIA_START        (0)
+#define IPWIRELESS_PCMCIA_MINORS       (24)
+#define IPWIRELESS_PCMCIA_MINOR_RANGE  (8)
+
+#define TTYTYPE_MODEM    (0)
+#define TTYTYPE_MONITOR  (1)
+#define TTYTYPE_RAS_RAW  (2)
+
+struct ipw_tty {
+       int index;
+       struct ipw_hardware *hardware;
+       unsigned int channel_idx;
+       unsigned int secondary_channel_idx;
+       int tty_type;
+       struct ipw_network *network;
+       struct tty_struct *linux_tty;
+       int open_count;
+       unsigned int control_lines;
+       struct mutex ipw_tty_mutex;
+       int tx_bytes_queued;
+       int closing;
+};
+
+static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
+
+static struct tty_driver *ipw_tty_driver;
+
+static char *tty_type_name(int tty_type)
+{
+       static char *channel_names[] = {
+               "modem",
+               "monitor",
+               "RAS-raw"
+       };
+
+       return channel_names[tty_type];
+}
+
+static void report_registering(struct ipw_tty *tty)
+{
+       char *iftype = tty_type_name(tty->tty_type);
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": registering %s device ttyIPWp%d\n", iftype, tty->index);
+}
+
+static void report_deregistering(struct ipw_tty *tty)
+{
+       char *iftype = tty_type_name(tty->tty_type);
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": deregistering %s device ttyIPWp%d\n", iftype,
+              tty->index);
+}
+
+static struct ipw_tty *get_tty(int minor)
+{
+       if (minor < ipw_tty_driver->minor_start
+                       || minor >= ipw_tty_driver->minor_start +
+                       IPWIRELESS_PCMCIA_MINORS)
+               return NULL;
+       else {
+               int minor_offset = minor - ipw_tty_driver->minor_start;
+
+               /*
+                * The 'ras_raw' channel is only available when 'loopback' mode
+                * is enabled.
+                * Number of minor starts with 16 (_RANGE * _RAS_RAW).
+                */
+               if (!ipwireless_loopback &&
+                               minor_offset >=
+                                IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
+                       return NULL;
+
+               return ttys[minor_offset];
+       }
+}
+
+static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
+{
+       int minor = linux_tty->index;
+       struct ipw_tty *tty = get_tty(minor);
+
+       if (!tty)
+               return -ENODEV;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+
+       if (tty->closing) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return -ENODEV;
+       }
+       if (tty->open_count == 0)
+               tty->tx_bytes_queued = 0;
+
+       tty->open_count++;
+
+       tty->linux_tty = linux_tty;
+       linux_tty->driver_data = tty;
+       linux_tty->low_latency = 1;
+
+       if (tty->tty_type == TTYTYPE_MODEM)
+               ipwireless_ppp_open(tty->network);
+
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       return 0;
+}
+
+static void do_ipw_close(struct ipw_tty *tty)
+{
+       tty->open_count--;
+
+       if (tty->open_count == 0) {
+               struct tty_struct *linux_tty = tty->linux_tty;
+
+               if (linux_tty != NULL) {
+                       tty->linux_tty = NULL;
+                       linux_tty->driver_data = NULL;
+
+                       if (tty->tty_type == TTYTYPE_MODEM)
+                               ipwireless_ppp_close(tty->network);
+               }
+       }
+}
+
+static void ipw_hangup(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       if (tty->open_count == 0) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+
+       do_ipw_close(tty);
+
+       mutex_unlock(&tty->ipw_tty_mutex);
+}
+
+static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
+{
+       ipw_hangup(linux_tty);
+}
+
+/* Take data received from hardware, and send it out the tty */
+void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
+                       unsigned int length)
+{
+       struct tty_struct *linux_tty;
+       int work = 0;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       linux_tty = tty->linux_tty;
+       if (linux_tty == NULL) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+
+       if (!tty->open_count) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       work = tty_insert_flip_string(linux_tty, data, length);
+
+       if (work != length)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                               ": %d chars not inserted to flip buffer!\n",
+                               length - work);
+
+       /*
+        * This may sleep if ->low_latency is set
+        */
+       if (work)
+               tty_flip_buffer_push(linux_tty);
+}
+
+static void ipw_write_packet_sent_callback(void *callback_data,
+                                          unsigned int packet_length)
+{
+       struct ipw_tty *tty = callback_data;
+
+       /*
+        * Packet has been sent, so we subtract the number of bytes from our
+        * tally of outstanding TX bytes.
+        */
+       tty->tx_bytes_queued -= packet_length;
+}
+
+static int ipw_write(struct tty_struct *linux_tty,
+                    const unsigned char *buf, int count)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+       int room, ret;
+
+       if (!tty)
+               return -ENODEV;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       if (!tty->open_count) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return -EINVAL;
+       }
+
+       room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
+       if (room < 0)
+               room = 0;
+       /* Don't allow caller to write any more than we have room for */
+       if (count > room)
+               count = room;
+
+       if (count == 0) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return 0;
+       }
+
+       ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
+                              (unsigned char *) buf, count,
+                              ipw_write_packet_sent_callback, tty);
+       if (ret == -1) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return 0;
+       }
+
+       tty->tx_bytes_queued += count;
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       return count;
+}
+
+static int ipw_write_room(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+       int room;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
+       if (room < 0)
+               room = 0;
+
+       return room;
+}
+
+static int ipwireless_get_serial_info(struct ipw_tty *tty,
+                                     struct serial_struct __user *retinfo)
+{
+       struct serial_struct tmp;
+
+       if (!retinfo)
+               return (-EFAULT);
+
+       memset(&tmp, 0, sizeof(tmp));
+       tmp.type = PORT_UNKNOWN;
+       tmp.line = tty->index;
+       tmp.port = 0;
+       tmp.irq = 0;
+       tmp.flags = 0;
+       tmp.baud_base = 115200;
+       tmp.close_delay = 0;
+       tmp.closing_wait = 0;
+       tmp.custom_divisor = 0;
+       tmp.hub6 = 0;
+       if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
+               return -EFAULT;
+
+       return 0;
+}
+
+static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return tty->tx_bytes_queued;
+}
+
+static int get_control_lines(struct ipw_tty *tty)
+{
+       unsigned int my = tty->control_lines;
+       unsigned int out = 0;
+
+       if (my & IPW_CONTROL_LINE_RTS)
+               out |= TIOCM_RTS;
+       if (my & IPW_CONTROL_LINE_DTR)
+               out |= TIOCM_DTR;
+       if (my & IPW_CONTROL_LINE_CTS)
+               out |= TIOCM_CTS;
+       if (my & IPW_CONTROL_LINE_DSR)
+               out |= TIOCM_DSR;
+       if (my & IPW_CONTROL_LINE_DCD)
+               out |= TIOCM_CD;
+
+       return out;
+}
+
+static int set_control_lines(struct ipw_tty *tty, unsigned int set,
+                            unsigned int clear)
+{
+       int ret;
+
+       if (set & TIOCM_RTS) {
+               ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
+               if (ret)
+                       return ret;
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_RTS(tty->hardware,
+                                         tty->secondary_channel_idx, 1);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (set & TIOCM_DTR) {
+               ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
+               if (ret)
+                       return ret;
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_DTR(tty->hardware,
+                                         tty->secondary_channel_idx, 1);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (clear & TIOCM_RTS) {
+               ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_RTS(tty->hardware,
+                                         tty->secondary_channel_idx, 0);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (clear & TIOCM_DTR) {
+               ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_DTR(tty->hardware,
+                                         tty->secondary_channel_idx, 0);
+                       if (ret)
+                               return ret;
+               }
+       }
+       return 0;
+}
+
+static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return get_control_lines(tty);
+}
+
+static int
+ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
+            unsigned int set, unsigned int clear)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return set_control_lines(tty, set, clear);
+}
+
+static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
+                    unsigned int cmd, unsigned long arg)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       switch (cmd) {
+       case TIOCGSERIAL:
+               return ipwireless_get_serial_info(tty, (void __user *) arg);
+
+       case TIOCSSERIAL:
+               return 0;       /* Keeps the PCMCIA scripts happy. */
+       }
+
+       if (tty->tty_type == TTYTYPE_MODEM) {
+               switch (cmd) {
+               case PPPIOCGCHAN:
+                       {
+                               int chan = ipwireless_ppp_channel_index(
+                                                       tty->network);
+
+                               if (chan < 0)
+                                       return -ENODEV;
+                               if (put_user(chan, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+
+               case PPPIOCGUNIT:
+                       {
+                               int unit = ipwireless_ppp_unit_number(
+                                               tty->network);
+
+                               if (unit < 0)
+                                       return -ENODEV;
+                               if (put_user(unit, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+
+               case TCGETS:
+               case TCGETA:
+                       return n_tty_ioctl(linux_tty, file, cmd, arg);
+
+               case TCFLSH:
+                       return n_tty_ioctl(linux_tty, file, cmd, arg);
+
+               case FIONREAD:
+                       {
+                               int val = 0;
+
+                               if (put_user(val, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+               }
+       }
+
+       return -ENOIOCTLCMD;
+}
+
+static int add_tty(dev_node_t *nodesp, int j,
+                   struct ipw_hardware *hardware,
+                   struct ipw_network *network, int channel_idx,
+                   int secondary_channel_idx, int tty_type)
+{
+       ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
+       if (!ttys[j])
+               return -ENOMEM;
+       ttys[j]->index = j;
+       ttys[j]->hardware = hardware;
+       ttys[j]->channel_idx = channel_idx;
+       ttys[j]->secondary_channel_idx = secondary_channel_idx;
+       ttys[j]->network = network;
+       ttys[j]->tty_type = tty_type;
+       mutex_init(&ttys[j]->ipw_tty_mutex);
+
+       tty_register_device(ipw_tty_driver, j, NULL);
+       ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
+
+       if (secondary_channel_idx != -1)
+               ipwireless_associate_network_tty(network,
+                                                secondary_channel_idx,
+                                                ttys[j]);
+       if (nodesp != NULL) {
+               sprintf(nodesp->dev_name, "ttyIPWp%d", j);
+               nodesp->major = ipw_tty_driver->major;
+               nodesp->minor = j + ipw_tty_driver->minor_start;
+       }
+       if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
+               report_registering(ttys[j]);
+       return 0;
+}
+
+struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
+                                     struct ipw_network *network,
+                                     dev_node_t *nodes)
+{
+       int i, j;
+
+       for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
+               int allfree = 1;
+
+               for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
+                               j += IPWIRELESS_PCMCIA_MINOR_RANGE)
+                       if (ttys[j] != NULL) {
+                               allfree = 0;
+                               break;
+                       }
+
+               if (allfree) {
+                       j = i;
+
+                       if (add_tty(&nodes[0], j, hardware, network,
+                                       IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
+                                       TTYTYPE_MODEM))
+                               return NULL;
+
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE;
+                       if (add_tty(&nodes[1], j, hardware, network,
+                                       IPW_CHANNEL_DIALLER, -1,
+                                       TTYTYPE_MONITOR))
+                               return NULL;
+
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE;
+                       if (add_tty(NULL, j, hardware, network,
+                                       IPW_CHANNEL_RAS, -1,
+                                       TTYTYPE_RAS_RAW))
+                               return NULL;
+
+                       nodes[0].next = &nodes[1];
+                       nodes[1].next = NULL;
+
+                       return ttys[i];
+               }
+       }
+       return NULL;
+}
+
+/*
+ * Must be called before ipwireless_network_free().
+ */
+void ipwireless_tty_free(struct ipw_tty *tty)
+{
+       int j;
+       struct ipw_network *network = ttys[tty->index]->network;
+
+       for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
+               struct ipw_tty *ttyj = ttys[j];
+
+               if (ttyj) {
+                       mutex_lock(&ttyj->ipw_tty_mutex);
+                       if (get_tty(j + ipw_tty_driver->minor_start) == ttyj)
+                               report_deregistering(ttyj);
+                       ttyj->closing = 1;
+                       if (ttyj->linux_tty != NULL) {
+                               mutex_unlock(&ttyj->ipw_tty_mutex);
+                               tty_hangup(ttyj->linux_tty);
+                               /* Wait till the tty_hangup has completed */
+                               flush_scheduled_work();
+                               mutex_lock(&ttyj->ipw_tty_mutex);
+                       }
+                       while (ttyj->open_count)
+                               do_ipw_close(ttyj);
+                       ipwireless_disassociate_network_ttys(network,
+                                                            ttyj->channel_idx);
+                       tty_unregister_device(ipw_tty_driver, j);
+                       ttys[j] = NULL;
+                       mutex_unlock(&ttyj->ipw_tty_mutex);
+                       kfree(ttyj);
+               }
+       }
+}
+
+static struct tty_operations tty_ops = {
+       .open = ipw_open,
+       .close = ipw_close,
+       .hangup = ipw_hangup,
+       .write = ipw_write,
+       .write_room = ipw_write_room,
+       .ioctl = ipw_ioctl,
+       .chars_in_buffer = ipw_chars_in_buffer,
+       .tiocmget = ipw_tiocmget,
+       .tiocmset = ipw_tiocmset,
+};
+
+int ipwireless_tty_init(void)
+{
+       int result;
+
+       ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
+       if (!ipw_tty_driver)
+               return -ENOMEM;
+
+       ipw_tty_driver->owner = THIS_MODULE;
+       ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
+       ipw_tty_driver->name = "ttyIPWp";
+       ipw_tty_driver->major = 0;
+       ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
+       ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+       ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
+       ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+       ipw_tty_driver->init_termios = tty_std_termios;
+       ipw_tty_driver->init_termios.c_cflag =
+           B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       ipw_tty_driver->init_termios.c_ispeed = 9600;
+       ipw_tty_driver->init_termios.c_ospeed = 9600;
+       tty_set_operations(ipw_tty_driver, &tty_ops);
+       result = tty_register_driver(ipw_tty_driver);
+       if (result) {
+               printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                      ": failed to register tty driver\n");
+               put_tty_driver(ipw_tty_driver);
+               return result;
+       }
+
+       return 0;
+}
+
+void ipwireless_tty_release(void)
+{
+       int ret;
+
+       ret = tty_unregister_driver(ipw_tty_driver);
+       put_tty_driver(ipw_tty_driver);
+       if (ret != 0)
+               printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                       ": tty_unregister_driver failed with code %d\n", ret);
+}
+
+int ipwireless_tty_is_modem(struct ipw_tty *tty)
+{
+       return tty->tty_type == TTYTYPE_MODEM;
+}
+
+void
+ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
+                                         unsigned int channel_idx,
+                                         unsigned int control_lines,
+                                         unsigned int changed_mask)
+{
+       unsigned int old_control_lines = tty->control_lines;
+
+       tty->control_lines = (tty->control_lines & ~changed_mask)
+               | (control_lines & changed_mask);
+
+       /*
+        * If DCD is de-asserted, we close the tty so pppd can tell that we
+        * have gone offline.
+        */
+       if ((old_control_lines & IPW_CONTROL_LINE_DCD)
+                       && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
+                       && tty->linux_tty) {
+               tty_hangup(tty->linux_tty);
+       }
+}
+
diff --git a/drivers/char/pcmcia/ipwireless/tty.h b/drivers/char/pcmcia/ipwireless/tty.h
new file mode 100644 (file)
index 0000000..b0deb91
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_TTY_H_
+#define _IPWIRELESS_CS_TTY_H_
+
+#include <linux/types.h>
+#include <linux/sched.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/ds.h>
+
+struct ipw_tty;
+struct ipw_network;
+struct ipw_hardware;
+
+int ipwireless_tty_init(void);
+void ipwireless_tty_release(void);
+
+struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hw,
+                                     struct ipw_network *net,
+                                     dev_node_t *nodes);
+void ipwireless_tty_free(struct ipw_tty *tty);
+void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
+                            unsigned int length);
+int ipwireless_tty_is_modem(struct ipw_tty *tty);
+void ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
+                                              unsigned int channel_idx,
+                                              unsigned int control_lines,
+                                              unsigned int changed_mask);
+
+#endif
index e0bade732376555214e04831d7a27b45a3f3ee89..1412d7bcdbd195f7cfb0d0c46f63ddd772a1c5f1 100644 (file)
@@ -43,18 +43,12 @@ static char * __init dmi_string(const struct dmi_header *dm, u8 s)
  *     We have to be cautious here. We have seen BIOSes with DMI pointers
  *     pointing to completely the wrong place for example
  */
-static int __init dmi_table(u32 base, int len, int num,
-                           void (*decode)(const struct dmi_header *))
+static void dmi_table(u8 *buf, int len, int num,
+                     void (*decode)(const struct dmi_header *))
 {
-       u8 *buf, *data;
+       u8 *data = buf;
        int i = 0;
 
-       buf = dmi_ioremap(base, len);
-       if (buf == NULL)
-               return -1;
-
-       data = buf;
-
        /*
         *      Stop when we see all the items the table claimed to have
         *      OR we run off the end of the table (also happens)
@@ -75,7 +69,23 @@ static int __init dmi_table(u32 base, int len, int num,
                data += 2;
                i++;
        }
-       dmi_iounmap(buf, len);
+}
+
+static u32 dmi_base;
+static u16 dmi_len;
+static u16 dmi_num;
+
+static int __init dmi_walk_early(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       buf = dmi_ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       dmi_iounmap(buf, dmi_len);
        return 0;
 }
 
@@ -291,9 +301,9 @@ static int __init dmi_present(const char __iomem *p)
 
        memcpy_fromio(buf, p, 15);
        if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
-               u16 num = (buf[13] << 8) | buf[12];
-               u16 len = (buf[7] << 8) | buf[6];
-               u32 base = (buf[11] << 24) | (buf[10] << 16) |
+               dmi_num = (buf[13] << 8) | buf[12];
+               dmi_len = (buf[7] << 8) | buf[6];
+               dmi_base = (buf[11] << 24) | (buf[10] << 16) |
                        (buf[9] << 8) | buf[8];
 
                /*
@@ -305,7 +315,7 @@ static int __init dmi_present(const char __iomem *p)
                               buf[14] >> 4, buf[14] & 0xF);
                else
                        printk(KERN_INFO "DMI present.\n");
-               if (dmi_table(base,len, num, dmi_decode) == 0)
+               if (dmi_walk_early(dmi_decode) == 0)
                        return 0;
        }
        return 1;
@@ -489,3 +499,27 @@ int dmi_get_year(int field)
 
        return year;
 }
+
+/**
+ *     dmi_walk - Walk the DMI table and get called back for every record
+ *     @decode: Callback function
+ *
+ *     Returns -1 when the DMI table can't be reached, 0 on success.
+ */
+int dmi_walk(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       if (!dmi_available)
+               return -1;
+
+       buf = ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       iounmap(buf);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dmi_walk);
index a0445bea9f75ade0411a2949fe0ff43f1ad75b32..410ffe4e9d80ad0f155244d03ebc19eb66feb3f9 100644 (file)
@@ -433,12 +433,12 @@ config SENSORS_LM85
          will be called lm85.
 
 config SENSORS_LM87
-       tristate "National Semiconductor LM87"
+       tristate "National Semiconductor LM87 and compatibles"
        depends on I2C
        select HWMON_VID
        help
          If you say yes here you get support for National Semiconductor LM87
-         sensor chips.
+         and Analog Devices ADM1024 sensor chips.
 
          This driver can also be built as a module.  If so, the module
          will be called lm87.
@@ -588,6 +588,16 @@ config SENSORS_SMSC47B397
          This driver can also be built as a module.  If so, the module
          will be called smsc47b397.
 
+config SENSORS_ADS7828
+       tristate "Texas Instruments ADS7828"
+       depends on I2C
+       help
+         If you say yes here you get support for Texas Instruments ADS7828
+         12-bit 8-channel ADC device.
+
+         This driver can also be built as a module.  If so, the module
+         will be called ads7828.
+
 config SENSORS_THMC50
        tristate "Texas Instruments THMC50 / Analog Devices ADM1022"
        depends on I2C && EXPERIMENTAL
@@ -631,13 +641,13 @@ config SENSORS_VT8231
          will be called vt8231.
 
 config SENSORS_W83781D
-       tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
+       tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F"
        depends on I2C
        select HWMON_VID
        help
          If you say yes here you get support for the Winbond W8378x series
-         of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
-         and the similar Asus AS99127F.
+         of sensor chips: the W83781D, W83782D and W83783S, and the similar
+         Asus AS99127F.
 
          This driver can also be built as a module.  If so, the module
          will be called w83781d.
@@ -683,6 +693,16 @@ config SENSORS_W83L785TS
          This driver can also be built as a module.  If so, the module
          will be called w83l785ts.
 
+config SENSORS_W83L786NG
+       tristate "Winbond W83L786NG, W83L786NR"
+       depends on I2C && EXPERIMENTAL
+       help
+         If you say yes here you get support for the Winbond W83L786NG
+         and W83L786NR sensor chips.
+
+         This driver can also be built as a module.  If so, the module
+         will be called w83l786ng.
+
 config SENSORS_W83627HF
        tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
        select HWMON_VID
index 55595f6e1aa632a8ecb05eb1306540905ac5a729..824161337f1c8ea128d733bd11b72e9ff42f90f9 100644 (file)
@@ -22,6 +22,7 @@ obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
 obj-$(CONFIG_SENSORS_ADM1029)  += adm1029.o
 obj-$(CONFIG_SENSORS_ADM1031)  += adm1031.o
 obj-$(CONFIG_SENSORS_ADM9240)  += adm9240.o
+obj-$(CONFIG_SENSORS_ADS7828)  += ads7828.o
 obj-$(CONFIG_SENSORS_ADT7470)  += adt7470.o
 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
 obj-$(CONFIG_SENSORS_AMS)      += ams/
@@ -68,6 +69,7 @@ obj-$(CONFIG_SENSORS_VT1211)  += vt1211.o
 obj-$(CONFIG_SENSORS_VT8231)   += vt8231.o
 obj-$(CONFIG_SENSORS_W83627EHF)        += w83627ehf.o
 obj-$(CONFIG_SENSORS_W83L785TS)        += w83l785ts.o
+obj-$(CONFIG_SENSORS_W83L786NG)        += w83l786ng.o
 
 ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
index d9f04ce903273e7b214eac1659f0086186550d7e..ed33fddc4dee5689e8fae75e7b339692e9fcf6a1 100644 (file)
@@ -528,6 +528,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
                { "AUX1 Fan",           33, 2, 60, 1, 0 },
                { "AUX2 Fan",           35, 2, 60, 1, 0 },
                { "AUX3 Fan",           36, 2, 60, 1, 0 },
+               { "AUX4 Fan",           37, 2, 60, 1, 0 },
                { NULL, 0, 0, 0, 0, 0 } }
        },
        { 0x001B, "unknown", {
index ebdc6d7db2318c295a84deca0db123b04091bd11..b96be772e498c82528657ae7ea969fb2c8268da5 100644 (file)
@@ -115,7 +115,6 @@ static struct i2c_driver adm1021_driver = {
        .driver = {
                .name   = "adm1021",
        },
-       .id             = I2C_DRIVERID_ADM1021,
        .attach_adapter = adm1021_attach_adapter,
        .detach_client  = adm1021_detach_client,
 };
index 041ecb0bdf484d08b4accbfe26e8df8050a95f4d..e96c3725203d80c6841e9b3012d41bca14d2adbc 100644 (file)
@@ -51,6 +51,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
@@ -74,7 +75,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
  */
 
 #define ADM1025_REG_MAN_ID             0x3E
-#define ADM1025_REG_CHIP_ID            0x3F
+#define ADM1025_REG_CHIP_ID            0x3F
 #define ADM1025_REG_CONFIG             0x40
 #define ADM1025_REG_STATUS1            0x41
 #define ADM1025_REG_STATUS2            0x42
@@ -92,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
  * The ADM1025 uses signed 8-bit values for temperatures.
  */
 
-static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
+static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
 
 #define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
 #define IN_TO_REG(val,scale)   ((val) <= 0 ? 0 : \
@@ -122,7 +123,6 @@ static struct i2c_driver adm1025_driver = {
        .driver = {
                .name   = "adm1025",
        },
-       .id             = I2C_DRIVERID_ADM1025,
        .attach_adapter = adm1025_attach_adapter,
        .detach_client  = adm1025_detach_client,
 };
@@ -153,86 +153,96 @@ struct adm1025_data {
  * Sysfs stuff
  */
 
-#define show_in(offset) \
-static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
-                      in_scale[offset])); \
-} \
-static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
-                      in_scale[offset])); \
-} \
-static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
-                      in_scale[offset])); \
-} \
-static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
-show_in(0);
-show_in(1);
-show_in(2);
-show_in(3);
-show_in(4);
-show_in(5);
-
-#define show_temp(offset) \
-static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
-} \
-static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
-} \
-static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
-}\
-static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL);
-show_temp(1);
-show_temp(2);
+static ssize_t
+show_in(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_temp(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
+}
+
+static ssize_t
+show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
+}
+
+static ssize_t
+show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
+}
+
+static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_min[index] = IN_TO_REG(val, in_scale[index]);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
+                                 data->in_min[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_max[index] = IN_TO_REG(val, in_scale[index]);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
+                                 data->in_max[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
 
 #define set_in(offset) \
-static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
-                                 data->in_min[offset]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
-                                 data->in_max[offset]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
-       show_in##offset##_min, set_in##offset##_min); \
-static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
-       show_in##offset##_max, set_in##offset##_max);
+static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
+       show_in, NULL, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
+       show_in_min, set_in_min, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
+       show_in_max, set_in_max, offset)
 set_in(0);
 set_in(1);
 set_in(2);
@@ -240,65 +250,91 @@ set_in(3);
 set_in(4);
 set_in(5);
 
+static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_min[index] = TEMP_TO_REG(val);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
+                                 data->temp_min[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_max[index] = TEMP_TO_REG(val);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
+                                 data->temp_max[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
 #define set_temp(offset) \
-static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->temp_min[offset-1] = TEMP_TO_REG(val); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
-                                 data->temp_min[offset-1]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->temp_max[offset-1] = TEMP_TO_REG(val); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
-                                 data->temp_max[offset-1]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_min, set_temp##offset##_min); \
-static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_max, set_temp##offset##_max);
+static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
+       show_temp, NULL, offset - 1); \
+static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
+       show_temp_min, set_temp_min, offset - 1); \
+static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
+       show_temp_max, set_temp_max, offset - 1)
 set_temp(1);
 set_temp(2);
 
-static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = adm1025_update_device(dev);
        return sprintf(buf, "%u\n", data->alarms);
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
-static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
+
+static ssize_t
+show_vid(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = adm1025_update_device(dev);
        return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
 }
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
-static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%u\n", data->vrm);
 }
-static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct adm1025_data *data = i2c_get_clientdata(client);
+       struct adm1025_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
@@ -316,27 +352,35 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
 }
 
 static struct attribute *adm1025_attributes[] = {
-       &dev_attr_in0_input.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in2_input.attr,
-       &dev_attr_in3_input.attr,
-       &dev_attr_in5_input.attr,
-       &dev_attr_in0_min.attr,
-       &dev_attr_in1_min.attr,
-       &dev_attr_in2_min.attr,
-       &dev_attr_in3_min.attr,
-       &dev_attr_in5_min.attr,
-       &dev_attr_in0_max.attr,
-       &dev_attr_in1_max.attr,
-       &dev_attr_in2_max.attr,
-       &dev_attr_in3_max.attr,
-       &dev_attr_in5_max.attr,
-       &dev_attr_temp1_input.attr,
-       &dev_attr_temp2_input.attr,
-       &dev_attr_temp1_min.attr,
-       &dev_attr_temp2_min.attr,
-       &dev_attr_temp1_max.attr,
-       &dev_attr_temp2_max.attr,
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_fault.dev_attr.attr,
        &dev_attr_alarms.attr,
        &dev_attr_cpu0_vid.attr,
        &dev_attr_vrm.attr,
@@ -347,15 +391,16 @@ static const struct attribute_group adm1025_group = {
        .attrs = adm1025_attributes,
 };
 
-static struct attribute *adm1025_attributes_opt[] = {
-       &dev_attr_in4_input.attr,
-       &dev_attr_in4_min.attr,
-       &dev_attr_in4_max.attr,
+static struct attribute *adm1025_attributes_in4[] = {
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
        NULL
 };
 
-static const struct attribute_group adm1025_group_opt = {
-       .attrs = adm1025_attributes_opt,
+static const struct attribute_group adm1025_group_in4 = {
+       .attrs = adm1025_attributes_in4,
 };
 
 /*
@@ -364,7 +409,7 @@ static const struct attribute_group adm1025_group_opt = {
  */
 static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
 {
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct adm1025_data *data;
        int err = 0;
        const char *name = "";
@@ -378,14 +423,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       /* The common I2C client data is placed right before the
-          ADM1025-specific data. */
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &adm1025_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &adm1025_driver;
 
        /*
         * Now we do the remaining detection. A negative kind means that
@@ -397,12 +439,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
         * requested, so both the detection and the identification steps
         * are skipped.
         */
-       config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG);
+       config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
        if (kind < 0) { /* detection */
                if ((config & 0x80) != 0x00
-                || (i2c_smbus_read_byte_data(new_client,
+                || (i2c_smbus_read_byte_data(client,
                     ADM1025_REG_STATUS1) & 0xC0) != 0x00
-                || (i2c_smbus_read_byte_data(new_client,
+                || (i2c_smbus_read_byte_data(client,
                     ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
                        dev_dbg(&adapter->dev,
                                "ADM1025 detection failed at 0x%02x.\n",
@@ -414,11 +456,9 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        if (kind <= 0) { /* identification */
                u8 man_id, chip_id;
 
-               man_id = i2c_smbus_read_byte_data(new_client,
-                        ADM1025_REG_MAN_ID);
-               chip_id = i2c_smbus_read_byte_data(new_client,
-                         ADM1025_REG_CHIP_ID);
-               
+               man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
+               chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
+
                if (man_id == 0x41) { /* Analog Devices */
                        if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
                                kind = adm1025;
@@ -446,33 +486,28 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* We can fill in the remaining client fields */
-       strlcpy(new_client->name, name, I2C_NAME_SIZE);
-       data->valid = 0;
+       strlcpy(client->name, name, I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exit_free;
 
        /* Initialize the ADM1025 chip */
-       adm1025_init_client(new_client);
+       adm1025_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
                goto exit_detach;
 
        /* Pin 11 is either in4 (+12V) or VID4 */
        if (!(config & 0x20)) {
-               if ((err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_input))
-                || (err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_min))
-                || (err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_max)))
+               if ((err = sysfs_create_group(&client->dev.kobj,
+                                             &adm1025_group_in4)))
                        goto exit_remove;
        }
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exit_remove;
@@ -481,10 +516,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 exit_remove:
-       sysfs_remove_group(&new_client->dev.kobj, &adm1025_group);
-       sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
 exit_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -540,7 +575,7 @@ static int adm1025_detach_client(struct i2c_client *client)
 
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &adm1025_group);
-       sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
 
        if ((err = i2c_detach_client(client)))
                return err;
index 3e63c148677095dc38ce5e67dab90355a40fda8d..8002f68240c4e47c1dc2d7492fbbfb38d6f7752c 100644 (file)
@@ -40,8 +40,8 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
 /* Insmod parameters */
 I2C_CLIENT_INSMOD_1(adm1026);
 
-static int gpio_input[17]  = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-                               -1, -1, -1, -1, -1, -1, -1, -1 }; 
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+                               -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -49,46 +49,49 @@ static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
 static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
-module_param_array(gpio_input,int,NULL,0);
-MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
-module_param_array(gpio_output,int,NULL,0);
-MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_input, int, NULL, 0);
+MODULE_PARM_DESC(gpio_input, "List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output, int, NULL, 0);
+MODULE_PARM_DESC(gpio_output, "List of GPIO pins (0-16) to program as "
        "outputs");
-module_param_array(gpio_inverted,int,NULL,0);
-MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_inverted, int, NULL, 0);
+MODULE_PARM_DESC(gpio_inverted, "List of GPIO pins (0-16) to program as "
        "inverted");
-module_param_array(gpio_normal,int,NULL,0);
-MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_normal, int, NULL, 0);
+MODULE_PARM_DESC(gpio_normal, "List of GPIO pins (0-16) to program as "
        "normal/non-inverted");
-module_param_array(gpio_fan,int,NULL,0);
-MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+module_param_array(gpio_fan, int, NULL, 0);
+MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
 
 /* Many ADM1026 constants specified below */
 
 /* The ADM1026 registers */
-#define ADM1026_REG_CONFIG1  0x00
-#define CFG1_MONITOR     0x01
-#define CFG1_INT_ENABLE  0x02
-#define CFG1_INT_CLEAR   0x04
-#define CFG1_AIN8_9      0x08
-#define CFG1_THERM_HOT   0x10
-#define CFG1_DAC_AFC     0x20
-#define CFG1_PWM_AFC     0x40
-#define CFG1_RESET       0x80
-#define ADM1026_REG_CONFIG2  0x01
+#define ADM1026_REG_CONFIG1    0x00
+#define CFG1_MONITOR           0x01
+#define CFG1_INT_ENABLE                0x02
+#define CFG1_INT_CLEAR         0x04
+#define CFG1_AIN8_9            0x08
+#define CFG1_THERM_HOT         0x10
+#define CFG1_DAC_AFC           0x20
+#define CFG1_PWM_AFC           0x40
+#define CFG1_RESET             0x80
+
+#define ADM1026_REG_CONFIG2    0x01
 /* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
-#define ADM1026_REG_CONFIG3  0x07
-#define CFG3_GPIO16_ENABLE  0x01
-#define CFG3_CI_CLEAR  0x02
-#define CFG3_VREF_250  0x04
-#define CFG3_GPIO16_DIR  0x40
-#define CFG3_GPIO16_POL  0x80
-#define ADM1026_REG_E2CONFIG  0x13
-#define E2CFG_READ  0x01
-#define E2CFG_WRITE  0x02
-#define E2CFG_ERASE  0x04
-#define E2CFG_ROM  0x08
-#define E2CFG_CLK_EXT  0x80
+
+#define ADM1026_REG_CONFIG3    0x07
+#define CFG3_GPIO16_ENABLE     0x01
+#define CFG3_CI_CLEAR          0x02
+#define CFG3_VREF_250          0x04
+#define CFG3_GPIO16_DIR                0x40
+#define CFG3_GPIO16_POL                0x80
+
+#define ADM1026_REG_E2CONFIG   0x13
+#define E2CFG_READ             0x01
+#define E2CFG_WRITE            0x02
+#define E2CFG_ERASE            0x04
+#define E2CFG_ROM              0x08
+#define E2CFG_CLK_EXT          0x80
 
 /* There are 10 general analog inputs and 7 dedicated inputs
  * They are:
@@ -129,48 +132,48 @@ static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
 static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
 static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
 
-#define ADM1026_REG_FAN(nr) (0x38 + (nr))
-#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
-#define ADM1026_REG_FAN_DIV_0_3 0x02
-#define ADM1026_REG_FAN_DIV_4_7 0x03
+#define ADM1026_REG_FAN(nr)            (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr)                (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3                0x02
+#define ADM1026_REG_FAN_DIV_4_7                0x03
 
-#define ADM1026_REG_DAC  0x04
-#define ADM1026_REG_PWM  0x05
+#define ADM1026_REG_DAC                        0x04
+#define ADM1026_REG_PWM                        0x05
 
-#define ADM1026_REG_GPIO_CFG_0_3 0x08
-#define ADM1026_REG_GPIO_CFG_4_7 0x09
-#define ADM1026_REG_GPIO_CFG_8_11 0x0a
-#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+#define ADM1026_REG_GPIO_CFG_0_3       0x08
+#define ADM1026_REG_GPIO_CFG_4_7       0x09
+#define ADM1026_REG_GPIO_CFG_8_11      0x0a
+#define ADM1026_REG_GPIO_CFG_12_15     0x0b
 /* CFG_16 in REG_CFG3 */
-#define ADM1026_REG_GPIO_STATUS_0_7 0x24
-#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+#define ADM1026_REG_GPIO_STATUS_0_7    0x24
+#define ADM1026_REG_GPIO_STATUS_8_15   0x25
 /* STATUS_16 in REG_STATUS4 */
-#define ADM1026_REG_GPIO_MASK_0_7 0x1c
-#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+#define ADM1026_REG_GPIO_MASK_0_7      0x1c
+#define ADM1026_REG_GPIO_MASK_8_15     0x1d
 /* MASK_16 in REG_MASK4 */
 
-#define ADM1026_REG_COMPANY 0x16
-#define ADM1026_REG_VERSTEP 0x17
+#define ADM1026_REG_COMPANY            0x16
+#define ADM1026_REG_VERSTEP            0x17
 /* These are the recognized values for the above regs */
-#define ADM1026_COMPANY_ANALOG_DEV 0x41
-#define ADM1026_VERSTEP_GENERIC 0x40
-#define ADM1026_VERSTEP_ADM1026 0x44
+#define ADM1026_COMPANY_ANALOG_DEV     0x41
+#define ADM1026_VERSTEP_GENERIC                0x40
+#define ADM1026_VERSTEP_ADM1026                0x44
 
-#define ADM1026_REG_MASK1 0x18
-#define ADM1026_REG_MASK2 0x19
-#define ADM1026_REG_MASK3 0x1a
-#define ADM1026_REG_MASK4 0x1b
+#define ADM1026_REG_MASK1              0x18
+#define ADM1026_REG_MASK2              0x19
+#define ADM1026_REG_MASK3              0x1a
+#define ADM1026_REG_MASK4              0x1b
 
-#define ADM1026_REG_STATUS1 0x20
-#define ADM1026_REG_STATUS2 0x21
-#define ADM1026_REG_STATUS3 0x22
-#define ADM1026_REG_STATUS4 0x23
+#define ADM1026_REG_STATUS1            0x20
+#define ADM1026_REG_STATUS2            0x21
+#define ADM1026_REG_STATUS3            0x22
+#define ADM1026_REG_STATUS4            0x23
 
 #define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
-#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
-#define ADM1026_PWM_MAX 255
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX                        255
 
-/* Conversions. Rounding and limit checking is only done on the TO_REG 
+/* Conversions. Rounding and limit checking is only done on the TO_REG
  * variants. Note that you should be a bit careful with which arguments
  * these macros are called: arguments may be evaluated more than once.
  */
@@ -186,52 +189,49 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
  * The values in this table are based on Table II, page 15 of the
  *    datasheet.
  */
-static int adm1026_scaling[] = {  /* .001 Volts */
-               2250, 2250, 2250, 2250, 2250, 2250, 
-               1875, 1875, 1875, 1875, 3000, 3330, 
+static int adm1026_scaling[] = { /* .001 Volts */
+               2250, 2250, 2250, 2250, 2250, 2250,
+               1875, 1875, 1875, 1875, 3000, 3330,
                3330, 4995, 2250, 12000, 13875
        };
 #define NEG12_OFFSET  16000
-#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
-#define INS_TO_REG(n,val)  (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
-       0,255))
-#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n, val)  (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\
+       0, 255))
+#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
 
 /* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
  *   and we assume a 2 pulse-per-rev fan tach signal
  *      22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
  */
-#define FAN_TO_REG(val,div)  ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
-       (div)),1,254)) 
-#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
-       (div)))
+#define FAN_TO_REG(val, div)  ((val) <= 0 ? 0xff : \
+                               SENSORS_LIMIT(1350000/((val)*(div)), 1, 254))
+#define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \
+                               1350000/((val)*(div)))
 #define DIV_FROM_REG(val) (1<<(val))
-#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
 
 /* Temperature is reported in 1 degC increments */
 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-       -127,127))
+       -127, 127))
 #define TEMP_FROM_REG(val) ((val) * 1000)
 #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-       -127,127))
+       -127, 127))
 #define OFFSET_FROM_REG(val) ((val) * 1000)
 
-#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
 #define PWM_FROM_REG(val) (val)
 
 #define PWM_MIN_TO_REG(val) ((val) & 0xf0)
 #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
 
-/* Analog output is a voltage, and scaled to millivolts.  The datasheet 
- *   indicates that the DAC could be used to drive the fans, but in our 
+/* Analog output is a voltage, and scaled to millivolts.  The datasheet
+ *   indicates that the DAC could be used to drive the fans, but in our
  *   example board (Arima HDAMA) it isn't connected to the fans at all.
  */
-#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255)) 
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255))
 #define DAC_FROM_REG(val) (((val)*2500)/255)
 
-/* Typically used with systems using a v9.1 VRM spec ? */
-#define ADM1026_INIT_VRM  91
-
 /* Chip sampling rates
  *
  * Some sensors are not updated more frequently than once per second
@@ -243,8 +243,8 @@ static int adm1026_scaling[] = {  /* .001 Volts */
  *    So, we keep the config data up to date in the cache
  *    when it is written and only sample it once every 5 *minutes*
  */
-#define ADM1026_DATA_INTERVAL  (1 * HZ)
-#define ADM1026_CONFIG_INTERVAL  (5 * 60 * HZ)
+#define ADM1026_DATA_INTERVAL          (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL                (5 * 60 * HZ)
 
 /* We allow for multiple chips in a single system.
  *
@@ -261,37 +261,36 @@ struct pwm_data {
 struct adm1026_data {
        struct i2c_client client;
        struct device *hwmon_dev;
-       enum chips type;
 
        struct mutex update_lock;
        int valid;              /* !=0 if following fields are valid */
        unsigned long last_reading;     /* In jiffies */
        unsigned long last_config;      /* In jiffies */
 
-       u8 in[17];              /* Register value */
-       u8 in_max[17];          /* Register value */
-       u8 in_min[17];          /* Register value */
-       s8 temp[3];             /* Register value */
-       s8 temp_min[3];         /* Register value */
-       s8 temp_max[3];         /* Register value */
-       s8 temp_tmin[3];        /* Register value */
-       s8 temp_crit[3];        /* Register value */
-       s8 temp_offset[3];      /* Register value */
-       u8 fan[8];              /* Register value */
-       u8 fan_min[8];          /* Register value */
-       u8 fan_div[8];          /* Decoded value */
-       struct pwm_data pwm1;   /* Pwm control values */
-       int vid;                /* Decoded value */
-       u8 vrm;                 /* VRM version */
+       u8 in[17];              /* Register value */
+       u8 in_max[17];          /* Register value */
+       u8 in_min[17];          /* Register value */
+       s8 temp[3];             /* Register value */
+       s8 temp_min[3];         /* Register value */
+       s8 temp_max[3];         /* Register value */
+       s8 temp_tmin[3];        /* Register value */
+       s8 temp_crit[3];        /* Register value */
+       s8 temp_offset[3];      /* Register value */
+       u8 fan[8];              /* Register value */
+       u8 fan_min[8];          /* Register value */
+       u8 fan_div[8];          /* Decoded value */
+       struct pwm_data pwm1;   /* Pwm control values */
+       int vid;                /* Decoded value */
+       u8 vrm;                 /* VRM version */
        u8 analog_out;          /* Register value (DAC) */
-       long alarms;            /* Register encoding, combined */
-       long alarm_mask;        /* Register encoding, combined */
-       long gpio;              /* Register encoding, combined */
-       long gpio_mask;         /* Register encoding, combined */
-       u8 gpio_config[17];     /* Decoded value */
-       u8 config1;             /* Register value */
-       u8 config2;             /* Register value */
-       u8 config3;             /* Register value */
+       long alarms;            /* Register encoding, combined */
+       long alarm_mask;        /* Register encoding, combined */
+       long gpio;              /* Register encoding, combined */
+       long gpio_mask;         /* Register encoding, combined */
+       u8 gpio_config[17];     /* Decoded value */
+       u8 config1;             /* Register value */
+       u8 config2;             /* Register value */
+       u8 config3;             /* Register value */
 };
 
 static int adm1026_attach_adapter(struct i2c_adapter *adapter);
@@ -301,7 +300,7 @@ static int adm1026_detach_client(struct i2c_client *client);
 static int adm1026_read_value(struct i2c_client *client, u8 reg);
 static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
 static void adm1026_print_gpio(struct i2c_client *client);
-static void adm1026_fixup_gpio(struct i2c_client *client); 
+static void adm1026_fixup_gpio(struct i2c_client *client);
 static struct adm1026_data *adm1026_update_device(struct device *dev);
 static void adm1026_init_client(struct i2c_client *client);
 
@@ -311,7 +310,7 @@ static struct i2c_driver adm1026_driver = {
                .name   = "adm1026",
        },
        .attach_adapter = adm1026_attach_adapter,
-       .detach_client  = adm1026_detach_client,
+       .detach_client  = adm1026_detach_client,
 };
 
 static int adm1026_attach_adapter(struct i2c_adapter *adapter)
@@ -355,7 +354,7 @@ static void adm1026_init_client(struct i2c_client *client)
        int value, i;
        struct adm1026_data *data = i2c_get_clientdata(client);
 
-        dev_dbg(&client->dev, "Initializing device\n");
+       dev_dbg(&client->dev, "Initializing device\n");
        /* Read chip config */
        data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
        data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
@@ -384,7 +383,6 @@ static void adm1026_init_client(struct i2c_client *client)
                        "and temp limits enabled.\n");
        }
 
-       value = data->config3;
        if (data->config3 & CFG3_GPIO16_ENABLE) {
                dev_dbg(&client->dev, "GPIO16 enabled.  THERM "
                        "pin disabled.\n");
@@ -426,10 +424,10 @@ static void adm1026_init_client(struct i2c_client *client)
         *   configured, we don't want to mess with them.
         *   If they weren't, the default is 100% PWM, no
         *   control and will suffice until 'sensors -s'
-        *   can be run by the user.  We DO set the default 
+        *   can be run by the user.  We DO set the default
         *   value for pwm1.auto_pwm_min to its maximum
         *   so that enabling automatic pwm fan control
-        *   without first setting a value for pwm1.auto_pwm_min 
+        *   without first setting a value for pwm1.auto_pwm_min
         *   will not result in potentially dangerous fan speed decrease.
         */
        data->pwm1.auto_pwm_min=255;
@@ -453,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client)
 static void adm1026_print_gpio(struct i2c_client *client)
 {
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int  i;
+       int i;
 
        dev_dbg(&client->dev, "GPIO config is:");
        for (i = 0;i <= 7;++i) {
@@ -477,7 +475,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
                        data->gpio_config[16] & 0x02 ? "" : "!",
                        data->gpio_config[16] & 0x01 ? "OUT" : "IN");
        } else {
-               /* GPIO16 is THERM  */
+               /* GPIO16 is THERM */
                dev_dbg(&client->dev, "\tTHERM\n");
        }
 }
@@ -485,8 +483,8 @@ static void adm1026_print_gpio(struct i2c_client *client)
 static void adm1026_fixup_gpio(struct i2c_client *client)
 {
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int  i;
-       int  value;
+       int i;
+       int value;
 
        /* Make the changes requested. */
        /* We may need to unlock/stop monitoring or soft-reset the
@@ -516,14 +514,14 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
                }
        }
 
-       /* Inverted  */
+       /* Inverted */
        for (i = 0;i <= 16;++i) {
                if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
                        data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
                }
        }
 
-       /* Normal overrides inverted  */
+       /* Normal overrides inverted */
        for (i = 0;i <= 16;++i) {
                if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
                        data->gpio_config[gpio_normal[i]] |= 0x02;
@@ -569,7 +567,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
        if (!data->valid
            || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
                /* Things that change quickly */
-               dev_dbg(&client->dev,"Reading sensor values\n");
+               dev_dbg(&client->dev, "Reading sensor values\n");
                for (i = 0;i <= 16;++i) {
                        data->in[i] =
                            adm1026_read_value(client, ADM1026_REG_IN[i]);
@@ -582,18 +580,18 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
 
                for (i = 0;i <= 2;++i) {
                        /* NOTE: temp[] is s8 and we assume 2's complement
-                        *   "conversion" in the assignment   */
+                        *   "conversion" in the assignment */
                        data->temp[i] =
                            adm1026_read_value(client, ADM1026_REG_TEMP[i]);
                }
 
-               data->pwm1.pwm = adm1026_read_value(client, 
+               data->pwm1.pwm = adm1026_read_value(client,
                        ADM1026_REG_PWM);
-               data->analog_out = adm1026_read_value(client, 
+               data->analog_out = adm1026_read_value(client,
                        ADM1026_REG_DAC);
                /* GPIO16 is MSbit of alarms, move it to gpio */
                alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
-               gpio = alarms & 0x80 ? 0x0100 : 0;  /* GPIO16 */
+               gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
                alarms &= 0x7f;
                alarms <<= 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
@@ -604,24 +602,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                data->alarms = alarms;
 
                /* Read the GPIO values */
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_STATUS_8_15);
                gpio <<= 8;
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_STATUS_0_7);
                data->gpio = gpio;
 
                data->last_reading = jiffies;
-       };  /* last_reading */
+       }; /* last_reading */
 
        if (!data->valid ||
            time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
                /* Things that don't change often */
                dev_dbg(&client->dev, "Reading config values\n");
                for (i = 0;i <= 16;++i) {
-                       data->in_min[i] = adm1026_read_value(client, 
+                       data->in_min[i] = adm1026_read_value(client,
                                ADM1026_REG_IN_MIN[i]);
-                       data->in_max[i] = adm1026_read_value(client, 
+                       data->in_max[i] = adm1026_read_value(client,
                                ADM1026_REG_IN_MAX[i]);
                }
 
@@ -629,32 +627,32 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                        | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
                        << 8);
                for (i = 0;i <= 7;++i) {
-                       data->fan_min[i] = adm1026_read_value(client, 
+                       data->fan_min[i] = adm1026_read_value(client,
                                ADM1026_REG_FAN_MIN(i));
                        data->fan_div[i] = DIV_FROM_REG(value & 0x03);
                        value >>= 2;
                }
 
                for (i = 0; i <= 2; ++i) {
-                       /* NOTE: temp_xxx[] are s8 and we assume 2's 
+                       /* NOTE: temp_xxx[] are s8 and we assume 2's
                         *    complement "conversion" in the assignment
                         */
-                       data->temp_min[i] = adm1026_read_value(client, 
+                       data->temp_min[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_MIN[i]);
-                       data->temp_max[i] = adm1026_read_value(client, 
+                       data->temp_max[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_MAX[i]);
-                       data->temp_tmin[i] = adm1026_read_value(client, 
+                       data->temp_tmin[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_TMIN[i]);
-                       data->temp_crit[i] = adm1026_read_value(client, 
+                       data->temp_crit[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_THERM[i]);
-                       data->temp_offset[i] = adm1026_read_value(client, 
+                       data->temp_offset[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_OFFSET[i]);
                }
 
                /* Read the STATUS/alarm masks */
-               alarms  = adm1026_read_value(client, ADM1026_REG_MASK4);
-               gpio    = alarms & 0x80 ? 0x0100 : 0;  /* GPIO16 */
-               alarms  = (alarms & 0x7f) << 8;
+               alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+               gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+               alarms = (alarms & 0x7f) << 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
                alarms <<= 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
@@ -663,24 +661,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                data->alarm_mask = alarms;
 
                /* Read the GPIO values */
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_MASK_8_15);
                gpio <<= 8;
                gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
                data->gpio_mask = gpio;
 
                /* Read various values from CONFIG1 */
-               data->config1 = adm1026_read_value(client, 
+               data->config1 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG1);
                if (data->config1 & CFG1_PWM_AFC) {
                        data->pwm1.enable = 2;
-                       data->pwm1.auto_pwm_min = 
+                       data->pwm1.auto_pwm_min =
                                PWM_MIN_FROM_REG(data->pwm1.pwm);
                }
                /* Read the GPIO config */
-               data->config2 = adm1026_read_value(client, 
+               data->config2 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG2);
-               data->config3 = adm1026_read_value(client, 
+               data->config3 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG3);
                data->gpio_config[16] = (data->config3 >> 6) & 0x03;
 
@@ -695,7 +693,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                }
 
                data->last_config = jiffies;
-       };  /* last_config */
+       }; /* last_config */
 
        dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
        data->vid = (data->gpio >> 11) & 0x1f;
@@ -710,15 +708,15 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in[nr]));
 }
 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
                char *buf)
 {
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
-       struct adm1026_data *data = adm1026_update_device(dev); 
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+       struct adm1026_data *data = adm1026_update_device(dev);
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
 }
 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -733,7 +731,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
        data->in_min[nr] = INS_TO_REG(nr, val);
        adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
        mutex_unlock(&data->update_lock);
-       return count; 
+       return count;
 }
 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -741,7 +739,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
 }
 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -788,13 +786,13 @@ in_reg(15);
 static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
                NEG12_OFFSET);
 }
 static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct adm1026_data *data = adm1026_update_device(dev); 
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+       struct adm1026_data *data = adm1026_update_device(dev);
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
                - NEG12_OFFSET);
 }
 static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -807,12 +805,12 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c
        data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
        adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
        mutex_unlock(&data->update_lock);
-       return count; 
+       return count;
 }
 static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
                        - NEG12_OFFSET);
 }
 static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -843,7 +841,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
                data->fan_div[nr]));
 }
 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -852,7 +850,7 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
                data->fan_div[nr]));
 }
 static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
@@ -872,10 +870,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-#define fan_offset(offset)                                                     \
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL,        \
-               offset - 1);                                                    \
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,                \
+#define fan_offset(offset)                                             \
+static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL,        \
+               offset - 1);                                            \
+static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,                \
                show_fan_min, set_fan_min, offset - 1);
 
 fan_offset(1);
@@ -892,8 +890,8 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int    new_min;
-       int    new_div = data->fan_div[fan];
+       int new_min;
+       int new_div = data->fan_div[fan];
 
        /* 0 and 0xff are special.  Don't adjust them */
        if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
@@ -913,7 +911,7 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", data->fan_div[nr]);
+       return sprintf(buf, "%d\n", data->fan_div[nr]);
 }
 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -922,10 +920,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int    val,orig_div,new_div,shift;
+       int val, orig_div, new_div, shift;
 
        val = simple_strtol(buf, NULL, 10);
-       new_div = DIV_TO_REG(val); 
+       new_div = DIV_TO_REG(val);
        if (new_div == 0) {
                return -EINVAL;
        }
@@ -946,14 +944,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        }
 
        if (data->fan_div[nr] != orig_div) {
-               fixup_fan_min(dev,nr,orig_div);
+               fixup_fan_min(dev, nr, orig_div);
        }
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-#define fan_offset_div(offset)                                          \
-static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,         \
+#define fan_offset_div(offset)                                         \
+static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,                \
                show_fan_div, set_fan_div, offset - 1);
 
 fan_offset_div(1);
@@ -972,7 +970,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
 }
 static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -980,7 +978,7 @@ static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
 }
 static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1004,7 +1002,7 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
 }
 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1024,7 +1022,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
 }
 
 #define temp_reg(offset)                                               \
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp,    \
+static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp,    \
                NULL, offset - 1);                                      \
 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR,       \
                show_temp_min, set_temp_min, offset - 1);               \
@@ -1042,7 +1040,7 @@ static ssize_t show_temp_offset(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
 }
 static ssize_t set_temp_offset(struct device *dev,
                struct device_attribute *attr, const char *buf,
@@ -1076,7 +1074,7 @@ static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(
                ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
 }
 static ssize_t show_temp_auto_point2_temp(struct device *dev,
@@ -1085,7 +1083,7 @@ static ssize_t show_temp_auto_point2_temp(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
                ADM1026_FAN_CONTROL_TEMP_RANGE));
 }
 static ssize_t show_temp_auto_point1_temp(struct device *dev,
@@ -1094,7 +1092,7 @@ static ssize_t show_temp_auto_point1_temp(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
 }
 static ssize_t set_temp_auto_point1_temp(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
@@ -1113,13 +1111,13 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
        return count;
 }
 
-#define temp_auto_point(offset)                                                        \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR,  \
-               show_temp_auto_point1_temp, set_temp_auto_point1_temp,          \
-               offset - 1);                                                    \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO,       \
-               show_temp_auto_point1_temp_hyst, NULL, offset - 1);             \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO,            \
+#define temp_auto_point(offset)                                                \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp,             \
+               S_IRUGO | S_IWUSR, show_temp_auto_point1_temp,          \
+               set_temp_auto_point1_temp, offset - 1);                 \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO,\
+               show_temp_auto_point1_temp_hyst, NULL, offset - 1);     \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO,    \
                show_temp_auto_point2_temp, NULL, offset - 1);
 
 temp_auto_point(1);
@@ -1130,7 +1128,7 @@ static ssize_t show_temp_crit_enable(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+       return sprintf(buf, "%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
 }
 static ssize_t set_temp_crit_enable(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
@@ -1142,7 +1140,7 @@ static ssize_t set_temp_crit_enable(struct device *dev,
        if ((val == 1) || (val==0)) {
                mutex_lock(&data->update_lock);
                data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
-               adm1026_write_value(client, ADM1026_REG_CONFIG1, 
+               adm1026_write_value(client, ADM1026_REG_CONFIG1,
                        data->config1);
                mutex_unlock(&data->update_lock);
        }
@@ -1163,7 +1161,7 @@ static ssize_t show_temp_crit(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
 }
 static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1193,7 +1191,7 @@ temp_crit_reg(3);
 static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+       return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
 }
 static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1209,26 +1207,25 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a
        return count;
 }
 
-static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, 
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
        set_analog_out_reg);
 
 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+       return sprintf(buf, "%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
 }
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
 
 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = dev_get_drvdata(dev);
-       return sprintf(buf,"%d\n", data->vrm);
+       return sprintf(buf, "%d\n", data->vrm);
 }
 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct adm1026_data *data = i2c_get_clientdata(client);
+       struct adm1026_data *data = dev_get_drvdata(dev);
 
        data->vrm = simple_strtol(buf, NULL, 10);
        return count;
@@ -1239,15 +1236,52 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
 static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf, "%ld\n", (long) (data->alarms));
+       return sprintf(buf, "%ld\n", data->alarms);
 }
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       struct adm1026_data *data = adm1026_update_device(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%ld\n", (data->alarms >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(in15_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(in16_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 19);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 20);
+static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 21);
+static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 22);
+static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL, 23);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
+static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
+
 static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->alarm_mask);
+       return sprintf(buf, "%ld\n", data->alarm_mask);
 }
 static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1283,7 +1317,7 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
 static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->gpio);
+       return sprintf(buf, "%ld\n", data->gpio);
 }
 static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1291,16 +1325,16 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
        int val = simple_strtol(buf, NULL, 10);
-       long   gpio;
+       long gpio;
 
        mutex_lock(&data->update_lock);
        data->gpio = val & 0x1ffff;
        gpio = data->gpio;
-       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7, gpio & 0xff);
        gpio >>= 8;
-       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15, gpio & 0xff);
        gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
-       adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_STATUS4, gpio & 0xff);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -1311,7 +1345,7 @@ static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
 static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->gpio_mask);
+       return sprintf(buf, "%ld\n", data->gpio_mask);
 }
 static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1319,16 +1353,16 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
        int val = simple_strtol(buf, NULL, 10);
-       long   mask;
+       long mask;
 
        mutex_lock(&data->update_lock);
        data->gpio_mask = val & 0x1ffff;
        mask = data->gpio_mask;
-       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7, mask & 0xff);
        mask >>= 8;
-       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15, mask & 0xff);
        mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
-       adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_MASK1, mask & 0xff);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -1338,7 +1372,7 @@ static DEVICE_ATTR(gpio_mask