]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'doc-subdirs' of git://git.kernel.org/pub/scm/linux/kernel/git/rdunlap...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Nov 2008 19:51:03 +0000 (11:51 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Nov 2008 19:51:03 +0000 (11:51 -0800)
* 'doc-subdirs' of git://git.kernel.org/pub/scm/linux/kernel/git/rdunlap/linux-docs:
  Create/use more directory structure in the Documentation/ tree.

169 files changed:
Documentation/00-INDEX
Documentation/ABI/testing/sysfs-c2port [new file with mode: 0644]
Documentation/c2port.txt [new file with mode: 0644]
Documentation/cgroups/freezer-subsystem.txt
Documentation/filesystems/xip.txt
Documentation/hwmon/adt7462 [new file with mode: 0644]
Documentation/hwmon/lis3lv02d [new file with mode: 0644]
Documentation/ics932s401 [new file with mode: 0644]
Documentation/printk-formats.txt [new file with mode: 0644]
Documentation/w1/masters/omap-hdq [new file with mode: 0644]
MAINTAINERS
arch/arm/include/asm/dma-mapping.h
arch/arm/include/asm/hardware/iop3xx-adma.h
arch/arm/include/asm/hardware/iop_adma.h
arch/arm/include/asm/mach/map.h
arch/arm/mach-clps711x/include/mach/hardware.h
arch/arm/mach-clps7500/core.c
arch/arm/mach-clps7500/include/mach/hardware.h
arch/arm/mach-h720x/include/mach/boards.h
arch/arm/mach-integrator/include/mach/platform.h
arch/arm/mach-iop13xx/include/mach/adma.h
arch/arm/mach-realview/clock.c
arch/arm/mach-realview/include/mach/platform.h
arch/arm/mach-versatile/clock.c
arch/arm/mach-versatile/include/mach/platform.h
arch/arm/mm/cache-feroceon-l2.c
arch/arm/mm/mmu.c
arch/arm/plat-iop/setup.c
arch/m68k/kernel/ints.c
arch/parisc/include/asm/smp.h
arch/s390/kernel/entry.S
arch/s390/kernel/entry64.S
arch/s390/kernel/process.c
arch/s390/kernel/setup.c
arch/s390/kernel/sys_s390.c
arch/s390/kernel/topology.c
arch/x86/include/asm/iommu.h
arch/x86/kernel/early-quirks.c
drivers/ata/libata-sff.c
drivers/block/ub.c
drivers/char/ipmi/ipmi_msghandler.c
drivers/char/ipmi/ipmi_si_intf.c
drivers/dma/dmaengine.c
drivers/dma/dmatest.c
drivers/dma/iop-adma.c
drivers/edac/i5000_edac.c
drivers/gpio/Kconfig
drivers/gpio/Makefile
drivers/gpio/xilinx_gpio.c [new file with mode: 0644]
drivers/hwmon/Kconfig
drivers/hwmon/Makefile
drivers/hwmon/adt7462.c [new file with mode: 0644]
drivers/hwmon/adt7470.c
drivers/hwmon/adt7473.c
drivers/hwmon/applesmc.c
drivers/hwmon/ibmaem.c
drivers/hwmon/lis3lv02d.c [new file with mode: 0644]
drivers/hwmon/lis3lv02d.h [new file with mode: 0644]
drivers/hwmon/lm85.c
drivers/md/dm-mpath.c
drivers/md/dm-raid1.c
drivers/md/dm-stripe.c
drivers/md/dm.c
drivers/media/video/tvaudio.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/c2port/Kconfig [new file with mode: 0644]
drivers/misc/c2port/Makefile [new file with mode: 0644]
drivers/misc/c2port/c2port-duramar2150.c [new file with mode: 0644]
drivers/misc/c2port/core.c [new file with mode: 0644]
drivers/misc/ics932s401.c [new file with mode: 0644]
drivers/mtd/maps/cdb89712.c
drivers/mtd/maps/h720x-flash.c
drivers/net/bnx2.c
drivers/net/cxgb3/cxgb3_main.c
drivers/net/cxgb3/t3_hw.c
drivers/net/myri10ge/myri10ge.c
drivers/net/niu.c
drivers/net/smc911x.c
drivers/net/usb/asix.c
drivers/net/wireless/hostap/hostap_wlan.h
drivers/net/wireless/rtl8187_dev.c
drivers/pci/pci-acpi.c
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-ds1390.c [new file with mode: 0644]
drivers/rtc/rtc-rx8581.c [new file with mode: 0644]
drivers/rtc/rtc-wm8350.c [new file with mode: 0644]
drivers/s390/block/dasd.c
drivers/s390/char/sclp_cmd.c
drivers/s390/cio/device.c
drivers/s390/kvm/kvm_virtio.c
drivers/s390/scsi/zfcp_aux.c
drivers/s390/scsi/zfcp_ccw.c
drivers/s390/scsi/zfcp_dbf.c
drivers/s390/scsi/zfcp_dbf.h
drivers/s390/scsi/zfcp_erp.c
drivers/s390/scsi/zfcp_fsf.c
drivers/s390/scsi/zfcp_scsi.c
drivers/scsi/dpt_i2o.c
drivers/scsi/megaraid.c
drivers/scsi/megaraid.h
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_init.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/scsi_error.c
drivers/spi/atmel_spi.c
drivers/usb/class/cdc-acm.c
drivers/usb/core/message.c
drivers/usb/core/sysfs.c
drivers/usb/core/urb.c
drivers/usb/gadget/f_acm.c
drivers/usb/host/Kconfig
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-ps3.c
drivers/usb/host/ehci-sched.c
drivers/usb/host/isp1760-if.c
drivers/usb/host/ohci-ps3.c
drivers/usb/host/r8a66597-hcd.c
drivers/usb/misc/sisusbvga/sisusb.c
drivers/usb/misc/vstusb.c
drivers/usb/musb/musb_core.c
drivers/usb/musb/musb_debug.h
drivers/usb/musb/musb_host.c
drivers/usb/musb/musb_host.h
drivers/usb/musb/omap2430.c
drivers/usb/musb/tusb6010.c
drivers/usb/serial/cp2101.c
drivers/usb/serial/option.c
drivers/usb/storage/Kconfig
drivers/usb/storage/unusual_devs.h
drivers/w1/masters/Kconfig
drivers/w1/masters/Makefile
drivers/w1/masters/omap_hdq.c [new file with mode: 0644]
drivers/w1/slaves/Kconfig
drivers/w1/slaves/Makefile
drivers/w1/slaves/w1_bq27000.c [new file with mode: 0644]
drivers/w1/w1.h
drivers/w1/w1_io.c
fs/dlm/lockspace.c
fs/ext3/super.c
fs/namespace.c
include/linux/c2port.h [new file with mode: 0644]
include/linux/hrtimer.h
include/linux/kernel.h
include/linux/mfd/wm8350/rtc.h
include/linux/ratelimit.h
include/linux/slab.h
include/linux/usb.h
include/video/atmel_lcdc.h
init/Kconfig
kernel/cgroup_freezer.c
kernel/exit.c
kernel/fork.c
kernel/hrtimer.c
kernel/kprobes.c
kernel/sched.c
mm/hugetlb.c
mm/mlock.c
mm/page_alloc.c
mm/page_cgroup.c
mm/vmscan.c
net/9p/Kconfig
net/compat.c
net/ipv4/tcp_htcp.c
net/mac80211/mlme.c

index 2f969e2bece110950202394ae14a5ce6914f5db5..2a39aeba1464b8f66ed9cfe1dc7f20d40bbeb15f 100644 (file)
@@ -266,6 +266,8 @@ powerpc/
        - directory with info on using Linux with the PowerPC.
 preempt-locking.txt
        - info on locking under a preemptive kernel.
+printk-formats.txt
+       - how to get printk format specifiers right
 prio_tree.txt
        - info on radix-priority-search-tree use for indexing vmas.
 rbtree.txt
diff --git a/Documentation/ABI/testing/sysfs-c2port b/Documentation/ABI/testing/sysfs-c2port
new file mode 100644 (file)
index 0000000..716cffc
--- /dev/null
@@ -0,0 +1,88 @@
+What:          /sys/class/c2port/
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/ directory will contain files and
+               directories that will provide a unified interface to
+               the C2 port interface.
+
+What:          /sys/class/c2port/c2portX
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/ directory is related to X-th
+               C2 port into the system. Each directory will contain files to
+               manage and control its C2 port.
+
+What:          /sys/class/c2port/c2portX/access
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/access file enable the access
+               to the C2 port from the system. No commands can be sent
+               till this entry is set to 0.
+
+What:          /sys/class/c2port/c2portX/dev_id
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/dev_id file show the device ID
+               of the connected micro.
+
+What:          /sys/class/c2port/c2portX/flash_access
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_access file enable the
+               access to the on-board flash of the connected micro.
+               No commands can be sent till this entry is set to 0.
+
+What:          /sys/class/c2port/c2portX/flash_block_size
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_block_size file show
+               the on-board flash block size of the connected micro.
+
+What:          /sys/class/c2port/c2portX/flash_blocks_num
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_blocks_num file show
+               the on-board flash blocks number of the connected micro.
+
+What:          /sys/class/c2port/c2portX/flash_data
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_data file export
+               the content of the on-board flash of the connected micro.
+
+What:          /sys/class/c2port/c2portX/flash_erase
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_erase file execute
+               the "erase" command on the on-board flash of the connected
+               micro.
+
+What:          /sys/class/c2port/c2portX/flash_erase
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/flash_erase file show the
+               on-board flash size of the connected micro.
+
+What:          /sys/class/c2port/c2portX/reset
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/reset file execute a "reset"
+               command on the connected micro.
+
+What:          /sys/class/c2port/c2portX/rev_id
+Date:          October 2008
+Contact:       Rodolfo Giometti <giometti@linux.it>
+Description:
+               The /sys/class/c2port/c2portX/rev_id file show the revision ID
+               of the connected micro.
diff --git a/Documentation/c2port.txt b/Documentation/c2port.txt
new file mode 100644 (file)
index 0000000..d9bf93e
--- /dev/null
@@ -0,0 +1,90 @@
+                       C2 port support
+                       ---------------
+
+(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+
+
+Overview
+--------
+
+This driver implements the support for Linux of Silicon Labs (Silabs)
+C2 Interface used for in-system programming of micro controllers.
+
+By using this driver you can reprogram the in-system flash without EC2
+or EC3 debug adapter. This solution is also useful in those systems
+where the micro controller is connected via special GPIOs pins.
+
+References
+----------
+
+The C2 Interface main references are at (http://www.silabs.com)
+Silicon Laboratories site], see:
+
+- AN127: FLASH Programming via the C2 Interface at
+http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Small_Form_Factor/en/an127.pdf, and
+
+- C2 Specification at
+http://www.silabs.com/public/documents/tpub_doc/spec/Microcontrollers/en/C2spec.pdf,
+
+however it implements a two wire serial communication protocol (bit
+banging) designed to enable in-system programming, debugging, and
+boundary-scan testing on low pin-count Silicon Labs devices. Currently
+this code supports only flash programming but extensions are easy to
+add.
+
+Using the driver
+----------------
+
+Once the driver is loaded you can use sysfs support to get C2port's
+info or read/write in-system flash.
+
+# ls /sys/class/c2port/c2port0/
+access            flash_block_size  flash_erase       rev_id
+dev_id            flash_blocks_num  flash_size        subsystem/
+flash_access      flash_data        reset             uevent
+
+Initially the C2port access is disabled since you hardware may have
+such lines multiplexed with other devices so, to get access to the
+C2port, you need the command:
+
+# echo 1 > /sys/class/c2port/c2port0/access
+
+after that you should read the device ID and revision ID of the
+connected micro controller:
+
+# cat /sys/class/c2port/c2port0/dev_id
+8
+# cat /sys/class/c2port/c2port0/rev_id
+1
+
+However, for security reasons, the in-system flash access in not
+enabled yet, to do so you need the command:
+
+# echo 1 > /sys/class/c2port/c2port0/flash_access
+
+After that you can read the whole flash:
+
+# cat /sys/class/c2port/c2port0/flash_data > image
+
+erase it:
+
+# echo 1 > /sys/class/c2port/c2port0/flash_erase
+
+and write it:
+
+# cat image > /sys/class/c2port/c2port0/flash_data
+
+after writing you have to reset the device to execute the new code:
+
+# echo 1 > /sys/class/c2port/c2port0/reset
index c50ab58b72ebc26e0b03124f970e4d038f6df39e..41f37fea1276839b80cd4c220af27963f52c6a1d 100644 (file)
@@ -1,4 +1,4 @@
-       The cgroup freezer is useful to batch job management system which start
+The cgroup freezer is useful to batch job management system which start
 and stop sets of tasks in order to schedule the resources of a machine
 according to the desires of a system administrator. This sort of program
 is often used on HPC clusters to schedule access to the cluster as a
@@ -6,7 +6,7 @@ whole. The cgroup freezer uses cgroups to describe the set of tasks to
 be started/stopped by the batch job management system. It also provides
 a means to start and stop the tasks composing the job.
 
-       The cgroup freezer will also be useful for checkpointing running groups
+The cgroup freezer will also be useful for checkpointing running groups
 of tasks. The freezer allows the checkpoint code to obtain a consistent
 image of the tasks by attempting to force the tasks in a cgroup into a
 quiescent state. Once the tasks are quiescent another task can
@@ -16,7 +16,7 @@ recoverable error occur. This also allows the checkpointed tasks to be
 migrated between nodes in a cluster by copying the gathered information
 to another node and restarting the tasks there.
 
-       Sequences of SIGSTOP and SIGCONT are not always sufficient for stopping
+Sequences of SIGSTOP and SIGCONT are not always sufficient for stopping
 and resuming tasks in userspace. Both of these signals are observable
 from within the tasks we wish to freeze. While SIGSTOP cannot be caught,
 blocked, or ignored it can be seen by waiting or ptracing parent tasks.
@@ -37,26 +37,29 @@ demonstrate this problem using nested bash shells:
 
        <at this point 16990 exits and causes 16644 to exit too>
 
-       This happens because bash can observe both signals and choose how it
+This happens because bash can observe both signals and choose how it
 responds to them.
 
-       Another example of a program which catches and responds to these
+Another example of a program which catches and responds to these
 signals is gdb. In fact any program designed to use ptrace is likely to
 have a problem with this method of stopping and resuming tasks.
 
-        In contrast, the cgroup freezer uses the kernel freezer code to
+In contrast, the cgroup freezer uses the kernel freezer code to
 prevent the freeze/unfreeze cycle from becoming visible to the tasks
 being frozen. This allows the bash example above and gdb to run as
 expected.
 
-       The freezer subsystem in the container filesystem defines a file named
+The freezer subsystem in the container filesystem defines a file named
 freezer.state. Writing "FROZEN" to the state file will freeze all tasks in the
 cgroup. Subsequently writing "THAWED" will unfreeze the tasks in the cgroup.
 Reading will return the current state.
 
+Note freezer.state doesn't exist in root cgroup, which means root cgroup
+is non-freezable.
+
 * Examples of usage :
 
-   # mkdir /containers/freezer
+   # mkdir /containers
    # mount -t cgroup -ofreezer freezer  /containers
    # mkdir /containers/0
    # echo $some_pid > /containers/0/tasks
@@ -94,6 +97,6 @@ things happens:
                the freezer.state file
        2) Userspace retries the freezing operation by writing "FROZEN" to
                the freezer.state file (writing "FREEZING" is not legal
-               and returns EIO)
+               and returns EINVAL)
        3) The tasks that blocked the cgroup from entering the "FROZEN"
                state disappear from the cgroup's set of tasks.
index 3cc4010521a019562e68eb070aa83ad78b0e8c4b..0466ee569278e43b2ccf80d444ab3c38d1ad5e44 100644 (file)
@@ -39,10 +39,11 @@ The block device operation is optional, these block devices support it as of
 today:
 - dcssblk: s390 dcss block device driver
 
-An address space operation named get_xip_page is used to retrieve reference
-to a struct page. To address the target page, a reference to an address_space,
-and a sector number is provided. A 3rd argument indicates whether the
-function should allocate blocks if needed.
+An address space operation named get_xip_mem is used to retrieve references
+to a page frame number and a kernel address. To obtain these values a reference
+to an address_space is provided. This function assigns values to the kmem and
+pfn parameters. The third argument indicates whether the function should allocate
+blocks if needed.
 
 This address space operation is mutually exclusive with readpage&writepage that
 do page cache read/write operations.
diff --git a/Documentation/hwmon/adt7462 b/Documentation/hwmon/adt7462
new file mode 100644 (file)
index 0000000..ec660b3
--- /dev/null
@@ -0,0 +1,67 @@
+Kernel driver adt7462
+======================
+
+Supported chips:
+  * Analog Devices ADT7462
+    Prefix: 'adt7462'
+    Addresses scanned: I2C 0x58, 0x5C
+    Datasheet: Publicly available at the Analog Devices website
+
+Author: Darrick J. Wong
+
+Description
+-----------
+
+This driver implements support for the Analog Devices ADT7462 chip family.
+
+This chip is a bit of a beast.  It has 8 counters for measuring fan speed.  It
+can also measure 13 voltages or 4 temperatures, or various combinations of the
+two.  See the chip documentation for more details about the exact set of
+configurations.  This driver does not allow one to configure the chip; that is
+left to the system designer.
+
+A sophisticated control system for the PWM outputs is designed into the ADT7462
+that allows fan speed to be adjusted automatically based on any of the three
+temperature sensors. Each PWM output is individually adjustable and
+programmable. Once configured, the ADT7462 will adjust the PWM outputs in
+response to the measured temperatures without further host intervention.  This
+feature can also be disabled for manual control of the PWM's.
+
+Each of the measured inputs (voltage, temperature, fan speed) has
+corresponding high/low limit values. The ADT7462 will signal an ALARM if
+any measured value exceeds either limit.
+
+The ADT7462 samples all inputs continuously. The driver will not read
+the registers more often than once every other second. Further,
+configuration data is only read once per minute.
+
+Special Features
+----------------
+
+The ADT7462 have a 10-bit ADC and can therefore measure temperatures
+with 0.25 degC resolution.
+
+The Analog Devices datasheet is very detailed and describes a procedure for
+determining an optimal configuration for the automatic PWM control.
+
+The driver will report sensor labels when it is able to determine that
+information from the configuration registers.
+
+Configuration Notes
+-------------------
+
+Besides standard interfaces driver adds the following:
+
+* PWM Control
+
+* pwm#_auto_point1_pwm and temp#_auto_point1_temp and
+* pwm#_auto_point2_pwm and temp#_auto_point2_temp -
+
+point1: Set the pwm speed at a lower temperature bound.
+point2: Set the pwm speed at a higher temperature bound.
+
+The ADT7462 will scale the pwm between the lower and higher pwm speed when
+the temperature is between the two temperature boundaries.  PWM values range
+from 0 (off) to 255 (full speed).  Fan speed will be set to maximum when the
+temperature sensor associated with the PWM control exceeds temp#_max.
+
diff --git a/Documentation/hwmon/lis3lv02d b/Documentation/hwmon/lis3lv02d
new file mode 100644 (file)
index 0000000..65dfb0c
--- /dev/null
@@ -0,0 +1,49 @@
+Kernel driver lis3lv02d
+==================
+
+Supported chips:
+
+  * STMicroelectronics LIS3LV02DL and LIS3LV02DQ
+
+Author:
+        Yan Burman <burman.yan@gmail.com>
+       Eric Piel <eric.piel@tremplin-utc.net>
+
+
+Description
+-----------
+
+This driver provides support for the accelerometer found in various HP laptops
+sporting the feature officially called "HP Mobile Data Protection System 3D" or
+"HP 3D DriveGuard". It detect automatically laptops with this sensor. Known models
+(for now the HP 2133, nc6420, nc2510, nc8510, nc84x0, nw9440 and nx9420) will
+have their axis automatically oriented on standard way (eg: you can directly
+play neverball).  The accelerometer data is readable via
+/sys/devices/platform/lis3lv02d.
+
+Sysfs attributes under /sys/devices/platform/lis3lv02d/:
+position - 3D position that the accelerometer reports. Format: "(x,y,z)"
+calibrate - read: values (x, y, z) that are used as the base for input class device operation.
+            write: forces the base to be recalibrated with the current position.
+rate - reports the sampling rate of the accelerometer device in HZ
+
+This driver also provides an absolute input class device, allowing
+the laptop to act as a pinball machine-esque joystick.
+
+Axes orientation
+----------------
+
+For better compatibility between the various laptops. The values reported by
+the accelerometer are converted into a "standard" organisation of the axes
+(aka "can play neverball out of the box"):
+ * When the laptop is horizontal the position reported is about 0 for X and Y
+and a positive value for Z
+ * If the left side is elevated, X increases (becomes positive)
+ * If the front side (where the touchpad is) is elevated, Y decreases (becomes negative)
+ * If the laptop is put upside-down, Z becomes negative
+
+If your laptop model is not recognized (cf "dmesg"), you can send an email to the
+authors to add it to the database.  When reporting a new laptop, please include
+the output of "dmidecode" plus the value of /sys/devices/platform/lis3lv02d/position
+in these four cases.
+
diff --git a/Documentation/ics932s401 b/Documentation/ics932s401
new file mode 100644 (file)
index 0000000..07a739f
--- /dev/null
@@ -0,0 +1,31 @@
+Kernel driver ics932s401
+======================
+
+Supported chips:
+  * IDT ICS932S401
+    Prefix: 'ics932s401'
+    Addresses scanned: I2C 0x69
+    Datasheet: Publically available at the IDT website
+
+Author: Darrick J. Wong
+
+Description
+-----------
+
+This driver implements support for the IDT ICS932S401 chip family.
+
+This chip has 4 clock outputs--a base clock for the CPU (which is likely
+multiplied to get the real CPU clock), a system clock, a PCI clock, a USB
+clock, and a reference clock.  The driver reports selected and actual
+frequency.  If spread spectrum mode is enabled, the driver also reports by what
+percent the clock signal is being spread, which should be between 0 and -0.5%.
+All frequencies are reported in KHz.
+
+The ICS932S401 monitors all inputs continuously. The driver will not read
+the registers more often than once every other second.
+
+Special Features
+----------------
+
+The clocks could be reprogrammed to increase system speed.  I will not help you
+do this, as you risk damaging your system!
diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
new file mode 100644 (file)
index 0000000..1b5a5dd
--- /dev/null
@@ -0,0 +1,35 @@
+If variable is of Type,                use printk format specifier:
+---------------------------------------------------------
+               int                     %d or %x
+               unsigned int            %u or %x
+               long                    %ld or %lx
+               unsigned long           %lu or %lx
+               long long               %lld or %llx
+               unsigned long long      %llu or %llx
+               size_t                  %zu or %zx
+               ssize_t                 %zd or %zx
+
+Raw pointer value SHOULD be printed with %p.
+
+u64 SHOULD be printed with %llu/%llx, (unsigned long long):
+
+       printk("%llu", (unsigned long long)u64_var);
+
+s64 SHOULD be printed with %lld/%llx, (long long):
+
+       printk("%lld", (long long)s64_var);
+
+If <type> is dependent on a config option for its size (e.g., sector_t,
+blkcnt_t, phys_addr_t, resource_size_t) or is architecture-dependent
+for its size (e.g., tcflag_t), use a format specifier of its largest
+possible type and explicitly cast to it.  Example:
+
+       printk("test: sector number/total blocks: %llu/%llu\n",
+               (unsigned long long)sector, (unsigned long long)blockcount);
+
+Reminder: sizeof() result is of type size_t.
+
+Thank you for your cooperation and attention.
+
+
+By Randy Dunlap <rdunlap@xenotime.net>
diff --git a/Documentation/w1/masters/omap-hdq b/Documentation/w1/masters/omap-hdq
new file mode 100644 (file)
index 0000000..ca722e0
--- /dev/null
@@ -0,0 +1,46 @@
+Kernel driver for omap HDQ/1-wire module.
+========================================
+
+Supported chips:
+================
+       HDQ/1-wire controller on the TI OMAP 2430/3430 platforms.
+
+A useful link about HDQ basics:
+===============================
+http://focus.ti.com/lit/an/slua408/slua408.pdf
+
+Description:
+============
+The HDQ/1-Wire module of TI OMAP2430/3430 platforms implement the hardware
+protocol of the master functions of the Benchmark HDQ and the Dallas
+Semiconductor 1-Wire protocols. These protocols use a single wire for
+communication between the master (HDQ/1-Wire controller) and the slave
+(HDQ/1-Wire external compliant device).
+
+A typical application of the HDQ/1-Wire module is the communication with battery
+monitor (gas gauge) integrated circuits.
+
+The controller supports operation in both HDQ and 1-wire mode. The essential
+difference between the HDQ and 1-wire mode is how the slave device responds to
+initialization pulse.In HDQ mode, the firmware does not require the host to
+create an initialization pulse to the slave.However, the slave can be reset by
+using an initialization pulse (also referred to as a break pulse).The slave
+does not respond with a presence pulse as it does in the 1-Wire protocol.
+
+Remarks:
+========
+The driver (drivers/w1/masters/omap_hdq.c) supports the HDQ mode of the
+controller. In this mode, as we can not read the ID which obeys the W1
+spec(family:id:crc), a module parameter can be passed to the driver which will
+be used to calculate the CRC and pass back an appropriate slave ID to the W1
+core.
+
+By default the master driver and the BQ slave i/f
+driver(drivers/w1/slaves/w1_bq27000.c) sets the ID to 1.
+Please note to load both the modules with a different ID if required, but note
+that the ID used should be same for both master and slave driver loading.
+
+e.g:
+insmod omap_hdq.ko W1_ID=2
+inamod w1_bq27000.ko F_ID=2
+
index 272d04e95faa4bb161a7a4e9779cf1858a91fd70..8e0777fae3ce36da962c7f60eb697c2fe1e4bb4f 100644 (file)
@@ -2703,6 +2703,11 @@ P:       Arnaldo Carvalho de Melo
 M:     acme@ghostprotocols.net
 S:     Maintained
 
+LIS3LV02D ACCELEROMETER DRIVER
+P:     Eric Piel
+M:     eric.piel@tremplin-utc.net
+S:     Maintained
+
 LM83 HARDWARE MONITOR DRIVER
 P:     Jean Delvare
 M:     khali@linux-fr.org
index 1cb8602dd9d5f5b0a29c56b3c8ac80c35f874e85..4ed149cbb32a401c26a6d91f062aa25151d994bf 100644 (file)
@@ -256,8 +256,17 @@ int dmabounce_sync_for_cpu(struct device *, dma_addr_t, unsigned long,
 int dmabounce_sync_for_device(struct device *, dma_addr_t, unsigned long,
                size_t, enum dma_data_direction);
 #else
-#define dmabounce_sync_for_cpu(dev,dma,off,sz,dir)     (1)
-#define dmabounce_sync_for_device(dev,dma,off,sz,dir)  (1)
+static inline int dmabounce_sync_for_cpu(struct device *d, dma_addr_t addr,
+       unsigned long offset, size_t size, enum dma_data_direction dir)
+{
+       return 1;
+}
+
+static inline int dmabounce_sync_for_device(struct device *d, dma_addr_t addr,
+       unsigned long offset, size_t size, enum dma_data_direction dir)
+{
+       return 1;
+}
 
 
 /**
index 87bff09633aac50bdcffcdc0aae2891000cda161..83e6ba338e2c4c9c13c6e05cd0aadeea5ce461fc 100644 (file)
@@ -730,7 +730,8 @@ static inline void iop_desc_set_next_desc(struct iop_adma_desc_slot *desc,
 {
        /* hw_desc->next_desc is the same location for all channels */
        union iop3xx_desc hw_desc = { .ptr = desc->hw_desc, };
-       BUG_ON(hw_desc.dma->next_desc);
+
+       iop_paranoia(hw_desc.dma->next_desc);
        hw_desc.dma->next_desc = next_desc_addr;
 }
 
@@ -760,7 +761,7 @@ static inline int iop_desc_get_zero_result(struct iop_adma_desc_slot *desc)
        struct iop3xx_desc_aau *hw_desc = desc->hw_desc;
        struct iop3xx_aau_desc_ctrl desc_ctrl = hw_desc->desc_ctrl_field;
 
-       BUG_ON(!(desc_ctrl.tx_complete && desc_ctrl.zero_result_en));
+       iop_paranoia(!(desc_ctrl.tx_complete && desc_ctrl.zero_result_en));
        return desc_ctrl.zero_result_err;
 }
 
index cb7e3611bcba748352d4227c19104e46fc47d08e..385c6e8cbbd214357e798270ccac8845cb672cec 100644 (file)
 
 #define IOP_ADMA_SLOT_SIZE 32
 #define IOP_ADMA_THRESHOLD 4
+#ifdef DEBUG
+#define IOP_PARANOIA 1
+#else
+#define IOP_PARANOIA 0
+#endif
+#define iop_paranoia(x) BUG_ON(IOP_PARANOIA && (x))
 
 /**
  * struct iop_adma_device - internal representation of an ADMA device
index cb1139ac19432f555b32ccc188b12f838f1ee9d4..39d949b63e80bc0cb23a59b086a2bb24711493ef 100644 (file)
@@ -19,12 +19,13 @@ struct map_desc {
 };
 
 /* types 0-3 are defined in asm/io.h */
-#define MT_CACHECLEAN          4
-#define MT_MINICLEAN           5
-#define MT_LOW_VECTORS         6
-#define MT_HIGH_VECTORS                7
-#define MT_MEMORY              8
-#define MT_ROM                 9
+#define MT_UNCACHED            4
+#define MT_CACHECLEAN          5
+#define MT_MINICLEAN           6
+#define MT_LOW_VECTORS         7
+#define MT_HIGH_VECTORS                8
+#define MT_MEMORY              9
+#define MT_ROM                 10
 
 #ifdef CONFIG_MMU
 extern void iotable_init(struct map_desc *, int);
index 4c3e101b96c9582fcaf6473a5824fa9e10705f56..b3ebe9e4871fe938585e5cad55eb7390424d25b3 100644 (file)
 #include <asm/hardware/ep7212.h>
 #include <asm/hardware/cs89712.h>
 
-/* dynamic ioremap() areas */
-#define FLASH_START      0x00000000
-#define FLASH_SIZE       0x800000
-#define FLASH_WIDTH      4
-
-#define SRAM_START       0x60000000
-#define SRAM_SIZE        0xc000
-#define SRAM_WIDTH       4
-
-#define BOOTROM_START    0x70000000
-#define BOOTROM_SIZE     0x80
-#define BOOTROM_WIDTH    4
-
-
 /* static cdb89712_map_io() areas */
 #define REGISTER_START   0x80000000
 #define REGISTER_SIZE    0x4000
 #define CEIVA_FLASH_SIZE        0x100000
 #define CEIVA_FLASH_WIDTH       2
 
-#define SRAM_START       0x60000000
-#define SRAM_SIZE        0xc000
-#define SRAM_WIDTH       4
-
-#define BOOTROM_START    0x70000000
-#define BOOTROM_SIZE     0x80
-#define BOOTROM_WIDTH    4
-
 /*
  * SED1355 LCD controller
  */
index c3a33b8a5aacc8406d3bcb7279e824cc7500513f..7e247c04d41c471312ff10161654ecc35b441c46 100644 (file)
@@ -275,9 +275,9 @@ static struct map_desc cl7500_io_desc[] __initdata = {
                .length         = ISA_SIZE,
                .type           = MT_DEVICE
        }, {    /* Flash        */
-               .virtual        = FLASH_BASE,
-               .pfn            = __phys_to_pfn(FLASH_START),
-               .length         = FLASH_SIZE,
+               .virtual        = CLPS7500_FLASH_BASE,
+               .pfn            = __phys_to_pfn(CLPS7500_FLASH_START),
+               .length         = CLPS7500_FLASH_SIZE,
                .type           = MT_DEVICE
        }, {    /* LED          */
                .virtual        = LED_BASE,
index d66578a3371c9f0a972a8266497e37519446875e..a6ad1d44badfd44e1fe140297517259652e3c63a 100644 (file)
@@ -39,9 +39,9 @@
 #define ISA_SIZE               0x00010000
 #define ISA_BASE               0xe1000000
 
-#define FLASH_START            0x01000000      /* XXX */
-#define FLASH_SIZE             0x01000000
-#define FLASH_BASE             0xe2000000
+#define CLPS7500_FLASH_START   0x01000000      /* XXX */
+#define CLPS7500_FLASH_SIZE    0x01000000
+#define CLPS7500_FLASH_BASE    0xe2000000
 
 #define LED_START              0x0302B000
 #define LED_SIZE               0x00001000
index 079b279e1242f8f681c0a0d7995cbe3d4cd1602c..38b8e0d61fbfc93f5d3b6cc89b8211bca0dae5c4 100644 (file)
@@ -19,9 +19,9 @@
 #ifdef CONFIG_ARCH_H7202
 
 /* FLASH */
-#define FLASH_VIRT             0xd0000000
-#define FLASH_PHYS             0x00000000
-#define FLASH_SIZE             0x02000000
+#define H720X_FLASH_VIRT       0xd0000000
+#define H720X_FLASH_PHYS       0x00000000
+#define H720X_FLASH_SIZE       0x02000000
 
 /* onboard LAN controller */
 # define ETH0_PHYS             0x08000000
index 028b87839c0f64b3ef421ee488b9e4c149d75899..e00a2624f269922d579cee9d154acb2d4852bfa9 100644 (file)
  */
 #define uHAL_MEMORY_SIZE                INTEGRATOR_SSRAM_SIZE
 
-/*
- *  Application Flash
- *
- */
-#define FLASH_BASE                      INTEGRATOR_FLASH_BASE
-#define FLASH_SIZE                      INTEGRATOR_FLASH_SIZE
-#define FLASH_END                       (FLASH_BASE + FLASH_SIZE - 1)
-#define FLASH_BLOCK_SIZE                SZ_128K
-
-/*
- *  Boot Flash
- *
- */
-#define EPROM_BASE                      INTEGRATOR_BOOT_ROM_HI
-#define EPROM_SIZE                      INTEGRATOR_BOOT_ROM_SIZE
-#define EPROM_END                       (EPROM_BASE + EPROM_SIZE - 1)
-
 /*
  *  Clean base - dummy
  *
  */
-#define CLEAN_BASE                      EPROM_BASE
+#define CLEAN_BASE                      INTEGRATOR_BOOT_ROM_HI
 
 /*
  *  Timer definitions
index 60019c8e6465f420be5d958ca7dd7432f4bc205d..5722e86f2174a93aa4b91975f2c2b608a5b4a1af 100644 (file)
@@ -404,7 +404,8 @@ static inline void iop_desc_set_next_desc(struct iop_adma_desc_slot *desc,
                                        u32 next_desc_addr)
 {
        struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
-       BUG_ON(hw_desc->next_desc);
+
+       iop_paranoia(hw_desc->next_desc);
        hw_desc->next_desc = next_desc_addr;
 }
 
index 3e706c57833aebc16a39e0f61a1fa1356e4ed730..3347c4236a60bd6cb2b34cbadc09d0d966614ebf 100644 (file)
@@ -104,7 +104,7 @@ static struct clk uart_clk = {
 
 static struct clk mmci_clk = {
        .name   = "MCLK",
-       .rate   = 33000000,
+       .rate   = 24000000,
 };
 
 int clk_register(struct clk *clk)
index 4034b54950c26d9d811856aceb9d77f5802c113e..793a3a3327121152072645828237c9d3f17c9e8d 100644 (file)
 #define REALVIEW_INTREG_OFFSET         0x8     /* Interrupt control */
 #define REALVIEW_DECODE_OFFSET         0xC     /* Fitted logic modules */
 
-/* 
- *  Application Flash
- * 
- */
-#define FLASH_BASE                      REALVIEW_FLASH_BASE
-#define FLASH_SIZE                      REALVIEW_FLASH_SIZE
-#define FLASH_END                       (FLASH_BASE + FLASH_SIZE - 1)
-#define FLASH_BLOCK_SIZE                SZ_128K
-
-/* 
- *  Boot Flash
- * 
- */
-#define EPROM_BASE                      REALVIEW_BOOT_ROM_HI
-#define EPROM_SIZE                      REALVIEW_BOOT_ROM_SIZE
-#define EPROM_END                       (EPROM_BASE + EPROM_SIZE - 1)
-
 /* 
  *  Clean base - dummy
  * 
  */
-#define CLEAN_BASE                      EPROM_BASE
+#define CLEAN_BASE                      REALVIEW_BOOT_ROM_HI
 
 /*
  * System controller bit assignment
index 9336508ec0b2b1311bbf6c0ceda0fdaa40d8910d..58937f1fb38ce7b4d805f86771d1ccdac9383457 100644 (file)
@@ -105,7 +105,7 @@ static struct clk uart_clk = {
 
 static struct clk mmci_clk = {
        .name   = "MCLK",
-       .rate   = 33000000,
+       .rate   = 24000000,
 };
 
 int clk_register(struct clk *clk)
index 27cbe6a3f2208f5abf4e4f33ce024b8c1498023e..f91ba930ca8a45221b8cb60074ec9bd186731eab 100644 (file)
 #define SIC_INTMASK_PCI1                (1 << SIC_INT_PCI1)
 #define SIC_INTMASK_PCI2                (1 << SIC_INT_PCI2)
 #define SIC_INTMASK_PCI3                (1 << SIC_INT_PCI3)
-/* 
- *  Application Flash
- * 
- */
-#define FLASH_BASE                      VERSATILE_FLASH_BASE
-#define FLASH_SIZE                      VERSATILE_FLASH_SIZE
-#define FLASH_END                       (FLASH_BASE + FLASH_SIZE - 1)
-#define FLASH_BLOCK_SIZE                SZ_128K
-
-/* 
- *  Boot Flash
- * 
- */
-#define EPROM_BASE                      VERSATILE_BOOT_ROM_HI
-#define EPROM_SIZE                      VERSATILE_BOOT_ROM_SIZE
-#define EPROM_END                       (EPROM_BASE + EPROM_SIZE - 1)
 
 /* 
  *  Clean base - dummy
  * 
  */
-#define CLEAN_BASE                      EPROM_BASE
+#define CLEAN_BASE                      VERSATILE_BOOT_ROM_HI
 
 /*
  * System controller bit assignment
index 13cdae8b0d44192107bdb0c626b9e6a3162d8b93..80cd207cbaea14c282e368fe08791d1ebcf09b2c 100644 (file)
@@ -150,7 +150,7 @@ static void feroceon_l2_inv_range(unsigned long start, unsigned long end)
        /*
         * Clean and invalidate partial last cache line.
         */
-       if (end & (CACHE_LINE_SIZE - 1)) {
+       if (start < end && end & (CACHE_LINE_SIZE - 1)) {
                l2_clean_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
                end &= ~(CACHE_LINE_SIZE - 1);
        }
@@ -158,7 +158,7 @@ static void feroceon_l2_inv_range(unsigned long start, unsigned long end)
        /*
         * Invalidate all full cache lines between 'start' and 'end'.
         */
-       while (start != end) {
+       while (start < end) {
                unsigned long range_end = calc_range_end(start, end);
                l2_inv_pa_range(start, range_end - CACHE_LINE_SIZE);
                start = range_end;
index e63db11f16a808fc0de3b73ea841ad2797ca597b..7f36c825718d37e6f424c57d8e81e2547692a0e4 100644 (file)
@@ -208,6 +208,12 @@ static struct mem_type mem_types[] = {
                .prot_sect      = PROT_SECT_DEVICE,
                .domain         = DOMAIN_IO,
        },
+       [MT_UNCACHED] = {
+               .prot_pte       = PROT_PTE_DEVICE,
+               .prot_l1        = PMD_TYPE_TABLE,
+               .prot_sect      = PMD_TYPE_SECT | PMD_SECT_XN,
+               .domain         = DOMAIN_IO,
+       },
        [MT_CACHECLEAN] = {
                .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
                .domain    = DOMAIN_KERNEL,
index 4689db638e95216ebcf1008767e6f8acbcddb4e4..9e573e78176a65d4bfdb93ae19235f5e39d4ca2b 100644 (file)
 #include <asm/hardware/iop3xx.h>
 
 /*
- * Standard IO mapping for all IOP3xx based systems
+ * Standard IO mapping for all IOP3xx based systems.  Note that
+ * the IOP3xx OCCDR must be mapped uncached and unbuffered.
  */
 static struct map_desc iop3xx_std_desc[] __initdata = {
         {      /* mem mapped registers */
                .virtual        = IOP3XX_PERIPHERAL_VIRT_BASE,
                .pfn            = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
                .length         = IOP3XX_PERIPHERAL_SIZE,
-               .type           = MT_DEVICE,
+               .type           = MT_UNCACHED,
         }, {   /* PCI IO space */
                .virtual        = IOP3XX_PCI_LOWER_IO_VA,
                .pfn            = __phys_to_pfn(IOP3XX_PCI_LOWER_IO_PA),
index 7e8a0d394e6184cbf63a5fb257befa4082ce0148..761ee0440c996a29d4fe784f56571e2cab3358ee 100644 (file)
@@ -133,7 +133,7 @@ void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
 {
        int i;
 
-       BUG_ON(IRQ_USER + cnt >= NR_IRQS);
+       BUG_ON(IRQ_USER + cnt > NR_IRQS);
        m68k_first_user_vec = vec;
        for (i = 0; i < cnt; i++)
                irq_controller[IRQ_USER + i] = &user_irq_controller;
index 398cdbaf4e540f6e6bccffdb84a7fbc8a88e5e98..409e698f436117bd2a18468f8a26ead3cf400d16 100644 (file)
@@ -44,8 +44,6 @@ extern void arch_send_call_function_ipi(cpumask_t mask);
  
 #define PROC_CHANGE_PENALTY    15              /* Schedule penalty */
 
-extern unsigned long cpu_present_mask;
-
 #define raw_smp_processor_id() (current_thread_info()->cpu)
 
 #else /* CONFIG_SMP */
index ed500ef799b795a21f322ae0d8e818b8bd926a36..08844fc24a2e7b8f042364e7e0bf44a0ca4bbb3c 100644 (file)
@@ -61,22 +61,25 @@ STACK_SIZE  = 1 << STACK_SHIFT
 
 #ifdef CONFIG_TRACE_IRQFLAGS
        .macro  TRACE_IRQS_ON
-       l       %r1,BASED(.Ltrace_irq_on)
+       basr    %r2,%r0
+       l       %r1,BASED(.Ltrace_irq_on_caller)
        basr    %r14,%r1
        .endm
 
        .macro  TRACE_IRQS_OFF
-       l       %r1,BASED(.Ltrace_irq_off)
+       basr    %r2,%r0
+       l       %r1,BASED(.Ltrace_irq_off_caller)
        basr    %r14,%r1
        .endm
 
        .macro  TRACE_IRQS_CHECK
+       basr    %r2,%r0
        tm      SP_PSW(%r15),0x03       # irqs enabled?
        jz      0f
-       l       %r1,BASED(.Ltrace_irq_on)
+       l       %r1,BASED(.Ltrace_irq_on_caller)
        basr    %r14,%r1
        j       1f
-0:     l       %r1,BASED(.Ltrace_irq_off)
+0:     l       %r1,BASED(.Ltrace_irq_off_caller)
        basr    %r14,%r1
 1:
        .endm
@@ -1113,9 +1116,12 @@ cleanup_io_leave_insn:
 .Lschedtail:   .long   schedule_tail
 .Lsysc_table:  .long   sys_call_table
 #ifdef CONFIG_TRACE_IRQFLAGS
-.Ltrace_irq_on: .long  trace_hardirqs_on
-.Ltrace_irq_off:
-               .long   trace_hardirqs_off
+.Ltrace_irq_on_caller:
+               .long   trace_hardirqs_on_caller
+.Ltrace_irq_off_caller:
+               .long   trace_hardirqs_off_caller
+#endif
+#ifdef CONFIG_LOCKDEP
 .Llockdep_sys_exit:
                .long   lockdep_sys_exit
 #endif
index d7ce150453f2865bfa4c9e99f53c03cda198442d..41aca06682aa19e294ac54160500da46594cb97a 100644 (file)
@@ -61,19 +61,22 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 
 #ifdef CONFIG_TRACE_IRQFLAGS
        .macro  TRACE_IRQS_ON
-        brasl  %r14,trace_hardirqs_on
+        basr   %r2,%r0
+        brasl  %r14,trace_hardirqs_on_caller
        .endm
 
        .macro  TRACE_IRQS_OFF
-        brasl  %r14,trace_hardirqs_off
+        basr   %r2,%r0
+        brasl  %r14,trace_hardirqs_off_caller
        .endm
 
        .macro TRACE_IRQS_CHECK
+       basr    %r2,%r0
        tm      SP_PSW(%r15),0x03       # irqs enabled?
        jz      0f
-       brasl   %r14,trace_hardirqs_on
+       brasl   %r14,trace_hardirqs_on_caller
        j       1f
-0:     brasl   %r14,trace_hardirqs_off
+0:     brasl   %r14,trace_hardirqs_off_caller
 1:
        .endm
 #else
index 3e2c05cb6a8733683c57d2935536ee936cc52059..04f8c67a610180413788684390d64bc613b8ca30 100644 (file)
@@ -136,9 +136,12 @@ static void default_idle(void)
                return;
        }
        trace_hardirqs_on();
+       /* Don't trace preempt off for idle. */
+       stop_critical_timings();
        /* Wait for external, I/O or machine check interrupt. */
        __load_psw_mask(psw_kernel_bits | PSW_MASK_WAIT |
                        PSW_MASK_IO | PSW_MASK_EXT);
+       start_critical_timings();
 }
 
 void cpu_idle(void)
index 62122bad1e3316f2112ae66c22e51859c7214b52..400b040df7fa05b1028bb9a9744e002957b29f5b 100644 (file)
@@ -604,13 +604,13 @@ setup_memory(void)
                if (memory_chunk[i].type != CHUNK_READ_WRITE)
                        continue;
                start_chunk = PFN_DOWN(memory_chunk[i].addr);
-               end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
+               end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
                end_chunk = min(end_chunk, end_pfn);
                if (start_chunk >= end_chunk)
                        continue;
                add_active_range(0, start_chunk, end_chunk);
                pfn = max(start_chunk, start_pfn);
-               for (; pfn <= end_chunk; pfn++)
+               for (; pfn < end_chunk; pfn++)
                        page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
        }
 
index 5fdb799062b7abfa1471488fd2582660cd56b08a..4fe952e557ac3bf683bb9535ff89b553035aad25 100644 (file)
@@ -198,7 +198,7 @@ asmlinkage long s390x_newuname(struct new_utsname __user *name)
 {
        int ret = sys_newuname(name);
 
-       if (current->personality == PER_LINUX32 && !ret) {
+       if (personality(current->personality) == PER_LINUX32 && !ret) {
                ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
                if (ret) ret = -EFAULT;
        }
index 632b13e100538704758cea2eebd75c6cfdc15bf7..a947899dcba1d55f56f8e00af05ab738293df6a3 100644 (file)
@@ -65,18 +65,21 @@ static int machine_has_topology_irq;
 static struct timer_list topology_timer;
 static void set_topology_timer(void);
 static DECLARE_WORK(topology_work, topology_work_fn);
+/* topology_lock protects the core linked list */
+static DEFINE_SPINLOCK(topology_lock);
 
 cpumask_t cpu_core_map[NR_CPUS];
 
 cpumask_t cpu_coregroup_map(unsigned int cpu)
 {
        struct core_info *core = &core_info;
+       unsigned long flags;
        cpumask_t mask;
 
        cpus_clear(mask);
        if (!machine_has_topology)
                return cpu_present_map;
-       mutex_lock(&smp_cpu_state_mutex);
+       spin_lock_irqsave(&topology_lock, flags);
        while (core) {
                if (cpu_isset(cpu, core->mask)) {
                        mask = core->mask;
@@ -84,7 +87,7 @@ cpumask_t cpu_coregroup_map(unsigned int cpu)
                }
                core = core->next;
        }
-       mutex_unlock(&smp_cpu_state_mutex);
+       spin_unlock_irqrestore(&topology_lock, flags);
        if (cpus_empty(mask))
                mask = cpumask_of_cpu(cpu);
        return mask;
@@ -133,7 +136,7 @@ static void tl_to_cores(struct tl_info *info)
        union tl_entry *tle, *end;
        struct core_info *core = &core_info;
 
-       mutex_lock(&smp_cpu_state_mutex);
+       spin_lock_irq(&topology_lock);
        clear_cores();
        tle = info->tle;
        end = (union tl_entry *)((unsigned long)info + info->length);
@@ -157,7 +160,7 @@ static void tl_to_cores(struct tl_info *info)
                }
                tle = next_tle(tle);
        }
-       mutex_unlock(&smp_cpu_state_mutex);
+       spin_unlock_irq(&topology_lock);
 }
 
 static void topology_update_polarization_simple(void)
index e4a552d44465b88b0f422a5cb51fcfba23598751..0b500c5b6446e6690846fe9d13a0a5483bef2f20 100644 (file)
@@ -6,7 +6,6 @@ extern void no_iommu_init(void);
 extern struct dma_mapping_ops nommu_dma_ops;
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
-extern int dmar_disabled;
 
 extern unsigned long iommu_nr_pages(unsigned long addr, unsigned long len);
 
index 3ce029ffaa55b2085ef4de993b427f86a3cdfdb7..1b894b72c0f5df35a1d489def584086ebb2affe5 100644 (file)
@@ -188,20 +188,6 @@ static void __init ati_bugs_contd(int num, int slot, int func)
 }
 #endif
 
-#ifdef CONFIG_DMAR
-static void __init intel_g33_dmar(int num, int slot, int func)
-{
-       struct acpi_table_header *dmar_tbl;
-       acpi_status status;
-
-       status = acpi_get_table(ACPI_SIG_DMAR, 0, &dmar_tbl);
-       if (ACPI_SUCCESS(status)) {
-               printk(KERN_INFO "BIOS BUG: DMAR advertised on Intel G31/G33 chipset -- ignoring\n");
-               dmar_disabled = 1;
-       }
-}
-#endif
-
 #define QFLAG_APPLY_ONCE       0x1
 #define QFLAG_APPLIED          0x2
 #define QFLAG_DONE             (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
@@ -225,10 +211,6 @@ static struct chipset early_qrk[] __initdata = {
          PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
        { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
          PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
-#ifdef CONFIG_DMAR
-       { PCI_VENDOR_ID_INTEL, 0x29c0,
-         PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, intel_g33_dmar },
-#endif
        {}
 };
 
index 4b47394863279606dc7427d79789bdc8c8485d99..9033d164c4ece13f876777fd7fbb549e4c27456b 100644 (file)
@@ -1227,10 +1227,19 @@ fsm_start:
                        /* ATA PIO protocol */
                        if (unlikely((status & ATA_DRQ) == 0)) {
                                /* handle BSY=0, DRQ=0 as error */
-                               if (likely(status & (ATA_ERR | ATA_DF)))
+                               if (likely(status & (ATA_ERR | ATA_DF))) {
                                        /* device stops HSM for abort/error */
                                        qc->err_mask |= AC_ERR_DEV;
-                               else {
+
+                                       /* If diagnostic failed and this is
+                                        * IDENTIFY, it's likely a phantom
+                                        * device.  Mark hint.
+                                        */
+                                       if (qc->dev->horkage &
+                                           ATA_HORKAGE_DIAGNOSTIC)
+                                               qc->err_mask |=
+                                                       AC_ERR_NODEV_HINT;
+                               } else {
                                        /* HSM violation. Let EH handle this.
                                         * Phantom devices also trigger this
                                         * condition.  Mark hint.
index fccac18d311121d01f28ca4ce819886f79cf300f..048d71d244d7335d3e719e916632ef1a71079465 100644 (file)
@@ -1546,8 +1546,6 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
 
 /*
  * Reset management
- * XXX Move usb_reset_device to khubd. Hogging kevent is not a good thing.
- * XXX Make usb_sync_reset asynchronous.
  */
 
 static void ub_reset_enter(struct ub_dev *sc, int try)
@@ -1632,6 +1630,22 @@ static void ub_reset_task(struct work_struct *work)
        spin_unlock_irqrestore(sc->lock, flags);
 }
 
+/*
+ * XXX Reset brackets are too much hassle to implement, so just stub them
+ * in order to prevent forced unbinding (which deadlocks solid when our
+ * ->disconnect method waits for the reset to complete and this kills keventd).
+ *
+ * XXX Tell Alan to move usb_unlock_device inside of usb_reset_device,
+ * or else the post_reset is invoked, and restats I/O on a locked device.
+ */
+static int ub_pre_reset(struct usb_interface *iface) {
+       return 0;
+}
+
+static int ub_post_reset(struct usb_interface *iface) {
+       return 0;
+}
+
 /*
  * This is called from a process context.
  */
@@ -2446,6 +2460,8 @@ static struct usb_driver ub_driver = {
        .probe =        ub_probe,
        .disconnect =   ub_disconnect,
        .id_table =     ub_usb_ids,
+       .pre_reset =    ub_pre_reset,
+       .post_reset =   ub_post_reset,
 };
 
 static int __init ub_init(void)
index 8a59aaa21be5c79e337802eba20cc0e5ac860f67..7a88dfd4427b136c6e034b06d4f6e6e3a416cd39 100644 (file)
@@ -422,9 +422,11 @@ struct ipmi_smi {
 /**
  * The driver model view of the IPMI messaging driver.
  */
-static struct device_driver ipmidriver = {
-       .name = "ipmi",
-       .bus = &platform_bus_type
+static struct platform_driver ipmidriver = {
+       .driver = {
+               .name = "ipmi",
+               .bus = &platform_bus_type
+       }
 };
 static DEFINE_MUTEX(ipmidriver_mutex);
 
@@ -2384,9 +2386,9 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
         * representing the interfaced BMC already
         */
        if (bmc->guid_set)
-               old_bmc = ipmi_find_bmc_guid(&ipmidriver, bmc->guid);
+               old_bmc = ipmi_find_bmc_guid(&ipmidriver.driver, bmc->guid);
        else
-               old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver,
+               old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.driver,
                                                    bmc->id.product_id,
                                                    bmc->id.device_id);
 
@@ -2416,7 +2418,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
                snprintf(name, sizeof(name),
                         "ipmi_bmc.%4.4x", bmc->id.product_id);
 
-               while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
+               while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver,
                                                 bmc->id.product_id,
                                                 bmc->id.device_id)) {
                        if (!warn_printed) {
@@ -2446,7 +2448,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
                               " Unable to allocate platform device\n");
                        return -ENOMEM;
                }
-               bmc->dev->dev.driver = &ipmidriver;
+               bmc->dev->dev.driver = &ipmidriver.driver;
                dev_set_drvdata(&bmc->dev->dev, bmc);
                kref_init(&bmc->refcount);
 
@@ -4247,7 +4249,7 @@ static int ipmi_init_msghandler(void)
        if (initialized)
                return 0;
 
-       rv = driver_register(&ipmidriver);
+       rv = driver_register(&ipmidriver.driver);
        if (rv) {
                printk(KERN_ERR PFX "Could not register IPMI driver\n");
                return rv;
@@ -4308,7 +4310,7 @@ static __exit void cleanup_ipmi(void)
        remove_proc_entry(proc_ipmi_root->name, NULL);
 #endif /* CONFIG_PROC_FS */
 
-       driver_unregister(&ipmidriver);
+       driver_unregister(&ipmidriver.driver);
 
        initialized = 0;
 
index 3123bf57ad91365039b9b227dc8fb3182a944c06..3000135f2ead3bcd98cd505b7fa89f11d0d2ab5e 100644 (file)
@@ -114,9 +114,11 @@ static char *si_to_str[] = { "kcs", "smic", "bt" };
 
 #define DEVICE_NAME "ipmi_si"
 
-static struct device_driver ipmi_driver = {
-       .name = DEVICE_NAME,
-       .bus = &platform_bus_type
+static struct platform_driver ipmi_driver = {
+       .driver = {
+               .name = DEVICE_NAME,
+               .bus = &platform_bus_type
+       }
 };
 
 
@@ -2868,7 +2870,7 @@ static int try_smi_init(struct smi_info *new_smi)
                        goto out_err;
                }
                new_smi->dev = &new_smi->pdev->dev;
-               new_smi->dev->driver = &ipmi_driver;
+               new_smi->dev->driver = &ipmi_driver.driver;
 
                rv = platform_device_add(new_smi->pdev);
                if (rv) {
@@ -2983,7 +2985,7 @@ static __devinit int init_ipmi_si(void)
        initialized = 1;
 
        /* Register the device drivers. */
-       rv = driver_register(&ipmi_driver);
+       rv = driver_register(&ipmi_driver.driver);
        if (rv) {
                printk(KERN_ERR
                       "init_ipmi_si: Unable to register driver: %d\n",
@@ -3052,7 +3054,7 @@ static __devinit int init_ipmi_si(void)
 #ifdef CONFIG_PPC_OF
                of_unregister_platform_driver(&ipmi_of_platform_driver);
 #endif
-               driver_unregister(&ipmi_driver);
+               driver_unregister(&ipmi_driver.driver);
                printk(KERN_WARNING
                       "ipmi_si: Unable to find any System Interface(s)\n");
                return -ENODEV;
@@ -3151,7 +3153,7 @@ static __exit void cleanup_ipmi_si(void)
                cleanup_one_si(e);
        mutex_unlock(&smi_infos_lock);
 
-       driver_unregister(&ipmi_driver);
+       driver_unregister(&ipmi_driver.driver);
 }
 module_exit(cleanup_ipmi_si);
 
index dc003a3a787d545207fed8be6e81bb4aacd970c1..5317e08221ecb2a34e699c77bac4f72a505f59e6 100644 (file)
@@ -399,8 +399,8 @@ int dma_async_device_register(struct dma_device *device)
                chan->chan_id = chancnt++;
                chan->dev.class = &dma_devclass;
                chan->dev.parent = device->dev;
-               snprintf(chan->dev.bus_id, BUS_ID_SIZE, "dma%dchan%d",
-                        device->dev_id, chan->chan_id);
+               dev_set_name(&chan->dev, "dma%dchan%d",
+                            device->dev_id, chan->chan_id);
 
                rc = device_register(&chan->dev);
                if (rc) {
index d1e381e35a9e1887e79667d3df734d3dd37ad5b9..ed9636bfb54af0e1805ed3ab4dc039b59e434213 100644 (file)
@@ -20,11 +20,11 @@ static unsigned int test_buf_size = 16384;
 module_param(test_buf_size, uint, S_IRUGO);
 MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer");
 
-static char test_channel[BUS_ID_SIZE];
+static char test_channel[20];
 module_param_string(channel, test_channel, sizeof(test_channel), S_IRUGO);
 MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
 
-static char test_device[BUS_ID_SIZE];
+static char test_device[20];
 module_param_string(device, test_device, sizeof(test_device), S_IRUGO);
 MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)");
 
@@ -80,14 +80,14 @@ static bool dmatest_match_channel(struct dma_chan *chan)
 {
        if (test_channel[0] == '\0')
                return true;
-       return strcmp(chan->dev.bus_id, test_channel) == 0;
+       return strcmp(dev_name(&chan->dev), test_channel) == 0;
 }
 
 static bool dmatest_match_device(struct dma_device *device)
 {
        if (test_device[0] == '\0')
                return true;
-       return strcmp(device->dev->bus_id, test_device) == 0;
+       return strcmp(dev_name(device->dev), test_device) == 0;
 }
 
 static unsigned long dmatest_random(void)
@@ -332,7 +332,7 @@ static enum dma_state_client dmatest_add_channel(struct dma_chan *chan)
 
        dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
        if (!dtc) {
-               pr_warning("dmatest: No memory for %s\n", chan->dev.bus_id);
+               pr_warning("dmatest: No memory for %s\n", dev_name(&chan->dev));
                return DMA_NAK;
        }
 
@@ -343,16 +343,16 @@ static enum dma_state_client dmatest_add_channel(struct dma_chan *chan)
                thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
                if (!thread) {
                        pr_warning("dmatest: No memory for %s-test%u\n",
-                                       chan->dev.bus_id, i);
+                                  dev_name(&chan->dev), i);
                        break;
                }
                thread->chan = dtc->chan;
                smp_wmb();
                thread->task = kthread_run(dmatest_func, thread, "%s-test%u",
-                               chan->dev.bus_id, i);
+                               dev_name(&chan->dev), i);
                if (IS_ERR(thread->task)) {
                        pr_warning("dmatest: Failed to run thread %s-test%u\n",
-                                       chan->dev.bus_id, i);
+                                       dev_name(&chan->dev), i);
                        kfree(thread);
                        break;
                }
@@ -362,7 +362,7 @@ static enum dma_state_client dmatest_add_channel(struct dma_chan *chan)
                list_add_tail(&thread->node, &dtc->threads);
        }
 
-       pr_info("dmatest: Started %u threads using %s\n", i, chan->dev.bus_id);
+       pr_info("dmatest: Started %u threads using %s\n", i, dev_name(&chan->dev));
 
        list_add_tail(&dtc->node, &dmatest_channels);
        nr_channels++;
@@ -379,7 +379,7 @@ static enum dma_state_client dmatest_remove_channel(struct dma_chan *chan)
                        list_del(&dtc->node);
                        dmatest_cleanup_channel(dtc);
                        pr_debug("dmatest: lost channel %s\n",
-                                       chan->dev.bus_id);
+                                       dev_name(&chan->dev));
                        return DMA_ACK;
                }
        }
@@ -418,7 +418,7 @@ dmatest_event(struct dma_client *client, struct dma_chan *chan,
 
        default:
                pr_info("dmatest: Unhandled event %u (%s)\n",
-                               state, chan->dev.bus_id);
+                               state, dev_name(&chan->dev));
                break;
        }
 
index 71fba82462cb98372568a2f2da6c8c325e1a10d8..c7a9306d951d2c61f622c601ef2d49af422b679e 100644 (file)
@@ -411,6 +411,7 @@ iop_adma_tx_submit(struct dma_async_tx_descriptor *tx)
        int slot_cnt;
        int slots_per_op;
        dma_cookie_t cookie;
+       dma_addr_t next_dma;
 
        grp_start = sw_desc->group_head;
        slot_cnt = grp_start->slot_cnt;
@@ -425,12 +426,12 @@ iop_adma_tx_submit(struct dma_async_tx_descriptor *tx)
                         &old_chain_tail->chain_node);
 
        /* fix up the hardware chain */
-       iop_desc_set_next_desc(old_chain_tail, grp_start->async_tx.phys);
+       next_dma = grp_start->async_tx.phys;
+       iop_desc_set_next_desc(old_chain_tail, next_dma);
+       BUG_ON(iop_desc_get_next_desc(old_chain_tail) != next_dma); /* flush */
 
-       /* 1/ don't add pre-chained descriptors
-        * 2/ dummy read to flush next_desc write
-        */
-       BUG_ON(iop_desc_get_next_desc(sw_desc));
+       /* check for pre-chained descriptors */
+       iop_paranoia(iop_desc_get_next_desc(sw_desc));
 
        /* increment the pending count by the number of slots
         * memcpy operations have a 1:1 (slot:operation) relation
index f0d9b415db50741bc18f73614be3e7730623b411..d335086f4a265c98cec4300ce2dc5e16d3137e35 100644 (file)
@@ -1381,6 +1381,7 @@ static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
        if (mci == NULL)
                return -ENOMEM;
 
+       kobject_get(&mci->edac_mci_kobj);
        debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
 
        mci->dev = &pdev->dev;  /* record ptr  to the generic device */
@@ -1453,6 +1454,7 @@ fail1:
        i5000_put_devices(mci);
 
 fail0:
+       kobject_put(&mci->edac_mci_kobj);
        edac_mc_free(mci);
        return -ENODEV;
 }
@@ -1498,7 +1500,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
 
        /* retrieve references to resources, and free those resources */
        i5000_put_devices(mci);
-
+       kobject_put(&mci->edac_mci_kobj);
        edac_mc_free(mci);
 }
 
index 7f2ee27fe76be15a947db4f5fdf1f7690cbe4caa..48f49d93d249d8155fbdc1973310fab28319e6f3 100644 (file)
@@ -65,6 +65,14 @@ config GPIO_SYSFS
 
 # put expanders in the right section, in alphabetical order
 
+comment "Memory mapped GPIO expanders:"
+
+config GPIO_XILINX
+       bool "Xilinx GPIO support"
+       depends on PPC_OF
+       help
+         Say yes here to support the Xilinx FPGA GPIO device
+
 comment "I2C GPIO expanders:"
 
 config GPIO_MAX732X
index 6aafdeb9ad03c04a4e932c33c7ff3d7f53954cd4..49ac64e515e6690a02fc96a33fa879a6cf0135d1 100644 (file)
@@ -10,4 +10,5 @@ obj-$(CONFIG_GPIO_MCP23S08)   += mcp23s08.o
 obj-$(CONFIG_GPIO_PCA953X)     += pca953x.o
 obj-$(CONFIG_GPIO_PCF857X)     += pcf857x.o
 obj-$(CONFIG_GPIO_TWL4030)     += twl4030-gpio.o
+obj-$(CONFIG_GPIO_XILINX)      += xilinx_gpio.o
 obj-$(CONFIG_GPIO_BT8XX)       += bt8xxgpio.o
diff --git a/drivers/gpio/xilinx_gpio.c b/drivers/gpio/xilinx_gpio.c
new file mode 100644 (file)
index 0000000..3c1177a
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * Xilinx gpio driver
+ *
+ * Copyright 2008 Xilinx, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_gpio.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+
+/* Register Offset Definitions */
+#define XGPIO_DATA_OFFSET   (0x0)      /* Data register  */
+#define XGPIO_TRI_OFFSET    (0x4)      /* I/O direction register  */
+
+struct xgpio_instance {
+       struct of_mm_gpio_chip mmchip;
+       u32 gpio_state;         /* GPIO state shadow register */
+       u32 gpio_dir;           /* GPIO direction shadow register */
+       spinlock_t gpio_lock;   /* Lock used for synchronization */
+};
+
+/**
+ * xgpio_get - Read the specified signal of the GPIO device.
+ * @gc:     Pointer to gpio_chip device structure.
+ * @gpio:   GPIO signal number.
+ *
+ * This function reads the specified signal of the GPIO device. It returns 0 if
+ * the signal clear, 1 if signal is set or negative value on error.
+ */
+static int xgpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+
+       return (in_be32(mm_gc->regs + XGPIO_DATA_OFFSET) >> gpio) & 1;
+}
+
+/**
+ * xgpio_set - Write the specified signal of the GPIO device.
+ * @gc:     Pointer to gpio_chip device structure.
+ * @gpio:   GPIO signal number.
+ * @val:    Value to be written to specified signal.
+ *
+ * This function writes the specified value in to the specified signal of the
+ * GPIO device.
+ */
+static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+       unsigned long flags;
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct xgpio_instance *chip =
+           container_of(mm_gc, struct xgpio_instance, mmchip);
+
+       spin_lock_irqsave(&chip->gpio_lock, flags);
+
+       /* Write to GPIO signal and set its direction to output */
+       if (val)
+               chip->gpio_state |= 1 << gpio;
+       else
+               chip->gpio_state &= ~(1 << gpio);
+       out_be32(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state);
+
+       spin_unlock_irqrestore(&chip->gpio_lock, flags);
+}
+
+/**
+ * xgpio_dir_in - Set the direction of the specified GPIO signal as input.
+ * @gc:     Pointer to gpio_chip device structure.
+ * @gpio:   GPIO signal number.
+ *
+ * This function sets the direction of specified GPIO signal as input.
+ * It returns 0 if direction of GPIO signals is set as input otherwise it
+ * returns negative error value.
+ */
+static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
+{
+       unsigned long flags;
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct xgpio_instance *chip =
+           container_of(mm_gc, struct xgpio_instance, mmchip);
+
+       spin_lock_irqsave(&chip->gpio_lock, flags);
+
+       /* Set the GPIO bit in shadow register and set direction as input */
+       chip->gpio_dir |= (1 << gpio);
+       out_be32(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir);
+
+       spin_unlock_irqrestore(&chip->gpio_lock, flags);
+
+       return 0;
+}
+
+/**
+ * xgpio_dir_out - Set the direction of the specified GPIO signal as output.
+ * @gc:     Pointer to gpio_chip device structure.
+ * @gpio:   GPIO signal number.
+ * @val:    Value to be written to specified signal.
+ *
+ * This function sets the direction of specified GPIO signal as output. If all
+ * GPIO signals of GPIO chip is configured as input then it returns
+ * error otherwise it returns 0.
+ */
+static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+       unsigned long flags;
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct xgpio_instance *chip =
+           container_of(mm_gc, struct xgpio_instance, mmchip);
+
+       spin_lock_irqsave(&chip->gpio_lock, flags);
+
+       /* Write state of GPIO signal */
+       if (val)
+               chip->gpio_state |= 1 << gpio;
+       else
+               chip->gpio_state &= ~(1 << gpio);
+       out_be32(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state);
+
+       /* Clear the GPIO bit in shadow register and set direction as output */
+       chip->gpio_dir &= (~(1 << gpio));
+       out_be32(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir);
+
+       spin_unlock_irqrestore(&chip->gpio_lock, flags);
+
+       return 0;
+}
+
+/**
+ * xgpio_save_regs - Set initial values of GPIO pins
+ * @mm_gc: pointer to memory mapped GPIO chip structure
+ */
+static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)
+{
+       struct xgpio_instance *chip =
+           container_of(mm_gc, struct xgpio_instance, mmchip);
+
+       out_be32(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state);
+       out_be32(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir);
+}
+
+/**
+ * xgpio_of_probe - Probe method for the GPIO device.
+ * @np: pointer to device tree node
+ *
+ * This function probes the GPIO device in the device tree. It initializes the
+ * driver data structure. It returns 0, if the driver is bound to the GPIO
+ * device, or a negative value if there is an error.
+ */
+static int __devinit xgpio_of_probe(struct device_node *np)
+{
+       struct xgpio_instance *chip;
+       struct of_gpio_chip *ofchip;
+       int status = 0;
+       const u32 *tree_info;
+
+       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+       if (!chip)
+               return -ENOMEM;
+       ofchip = &chip->mmchip.of_gc;
+
+       /* Update GPIO state shadow register with default value */
+       tree_info = of_get_property(np, "xlnx,dout-default", NULL);
+       if (tree_info)
+               chip->gpio_state = *tree_info;
+
+       /* Update GPIO direction shadow register with default value */
+       chip->gpio_dir = 0xFFFFFFFF; /* By default, all pins are inputs */
+       tree_info = of_get_property(np, "xlnx,tri-default", NULL);
+       if (tree_info)
+               chip->gpio_dir = *tree_info;
+
+       /* Check device node and parent device node for device width */
+       ofchip->gc.ngpio = 32; /* By default assume full GPIO controller */
+       tree_info = of_get_property(np, "xlnx,gpio-width", NULL);
+       if (!tree_info)
+               tree_info = of_get_property(np->parent,
+                                           "xlnx,gpio-width", NULL);
+       if (tree_info)
+               ofchip->gc.ngpio = *tree_info;
+
+       spin_lock_init(&chip->gpio_lock);
+
+       ofchip->gpio_cells = 2;
+       ofchip->gc.direction_input = xgpio_dir_in;
+       ofchip->gc.direction_output = xgpio_dir_out;
+       ofchip->gc.get = xgpio_get;
+       ofchip->gc.set = xgpio_set;
+
+       chip->mmchip.save_regs = xgpio_save_regs;
+
+       /* Call the OF gpio helper to setup and register the GPIO device */
+       status = of_mm_gpiochip_add(np, &chip->mmchip);
+       if (status) {
+               kfree(chip);
+               pr_err("%s: error in probe function with status %d\n",
+                      np->full_name, status);
+               return status;
+       }
+       pr_info("XGpio: %s: registered\n", np->full_name);
+       return 0;
+}
+
+static struct of_device_id xgpio_of_match[] __devinitdata = {
+       { .compatible = "xlnx,xps-gpio-1.00.a", },
+       { /* end of list */ },
+};
+
+static int __init xgpio_init(void)
+{
+       struct device_node *np;
+
+       for_each_matching_node(np, xgpio_of_match)
+               xgpio_of_probe(np);
+
+       return 0;
+}
+
+/* Make sure we get initialized before anyone else tries to use us */
+subsys_initcall(xgpio_init);
+/* No exit call at the moment as we cannot unregister of GPIO chips */
+
+MODULE_AUTHOR("Xilinx, Inc.");
+MODULE_DESCRIPTION("Xilinx GPIO driver");
+MODULE_LICENSE("GPL");
index 6de1e0ffd391efe9669fcae51df41beeb9a39407..c709e821f04bf6cd4c93db2fd6451be818fb7840 100644 (file)
@@ -159,6 +159,16 @@ config SENSORS_ADM9240
          This driver can also be built as a module.  If so, the module
          will be called adm9240.
 
+config SENSORS_ADT7462
+       tristate "Analog Devices ADT7462"
+       depends on I2C && EXPERIMENTAL
+       help
+         If you say yes here you get support for the Analog Devices
+         ADT7462 temperature monitoring chips.
+
+         This driver can also be built as a module. If so, the module
+         will be called adt7462.
+
 config SENSORS_ADT7470
        tristate "Analog Devices ADT7470"
        depends on I2C && EXPERIMENTAL
@@ -825,6 +835,25 @@ config SENSORS_HDAPS
          Say Y here if you have an applicable laptop and want to experience
          the awesome power of hdaps.
 
+config SENSORS_LIS3LV02D
+       tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer"
+       depends on ACPI && INPUT
+       default n
+       help
+         This driver provides support for the LIS3LV02Dx accelerometer. In
+         particular, it can be found in a number of HP laptops, which have the
+         "Mobile Data Protection System 3D" or "3D DriveGuard" feature. On such
+         systems the driver should load automatically (via ACPI). The
+         accelerometer might also be found in other systems, connected via SPI
+         or I2C.  The accelerometer data is readable via
+         /sys/devices/platform/lis3lv02d.
+
+         This driver also provides an absolute input class device, allowing
+         the laptop to act as a pinball machine-esque joystick.
+
+         This driver can also be built as a module.  If so, the module
+         will be called lis3lv02d.
+
 config SENSORS_APPLESMC
        tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
        depends on INPUT && X86
index 042d5a78622e4614a397983b147109ff4e01ab20..58fc5be5355d29ec0ea686813fbc1dc651b0e232 100644 (file)
@@ -25,6 +25,7 @@ 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_ADT7462)  += adt7462.o
 obj-$(CONFIG_SENSORS_ADT7470)  += adt7470.o
 obj-$(CONFIG_SENSORS_ADT7473)  += adt7473.o
 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
@@ -48,6 +49,7 @@ obj-$(CONFIG_SENSORS_IBMAEM)  += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
 obj-$(CONFIG_SENSORS_IT87)     += it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
+obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o
 obj-$(CONFIG_SENSORS_LM63)     += lm63.o
 obj-$(CONFIG_SENSORS_LM70)     += lm70.o
 obj-$(CONFIG_SENSORS_LM75)     += lm75.o
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
new file mode 100644 (file)
index 0000000..66107b4
--- /dev/null
@@ -0,0 +1,2002 @@
+/*
+ * A hwmon driver for the Analog Devices ADT7462
+ * Copyright (C) 2008 IBM
+ *
+ * Author: Darrick J. Wong <djwong@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+#include <linux/log2.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
+
+/* Insmod parameters */
+I2C_CLIENT_INSMOD_1(adt7462);
+
+/* ADT7462 registers */
+#define ADT7462_REG_DEVICE                     0x3D
+#define ADT7462_REG_VENDOR                     0x3E
+#define ADT7462_REG_REVISION                   0x3F
+
+#define ADT7462_REG_MIN_TEMP_BASE_ADDR         0x44
+#define ADT7462_REG_MIN_TEMP_MAX_ADDR          0x47
+#define ADT7462_REG_MAX_TEMP_BASE_ADDR         0x48
+#define ADT7462_REG_MAX_TEMP_MAX_ADDR          0x4B
+#define ADT7462_REG_TEMP_BASE_ADDR             0x88
+#define ADT7462_REG_TEMP_MAX_ADDR              0x8F
+
+#define ADT7462_REG_FAN_BASE_ADDR              0x98
+#define ADT7462_REG_FAN_MAX_ADDR               0x9F
+#define ADT7462_REG_FAN2_BASE_ADDR             0xA2
+#define ADT7462_REG_FAN2_MAX_ADDR              0xA9
+#define ADT7462_REG_FAN_ENABLE                 0x07
+#define ADT7462_REG_FAN_MIN_BASE_ADDR          0x78
+#define ADT7462_REG_FAN_MIN_MAX_ADDR           0x7F
+
+#define ADT7462_REG_CFG2                       0x02
+#define                ADT7462_FSPD_MASK               0x20
+
+#define ADT7462_REG_PWM_BASE_ADDR              0xAA
+#define ADT7462_REG_PWM_MAX_ADDR               0xAD
+#define        ADT7462_REG_PWM_MIN_BASE_ADDR           0x28
+#define ADT7462_REG_PWM_MIN_MAX_ADDR           0x2B
+#define ADT7462_REG_PWM_MAX                    0x2C
+#define ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR     0x5C
+#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR      0x5F
+#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR   0x60
+#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR    0x63
+#define        ADT7462_PWM_HYST_MASK           0x0F
+#define        ADT7462_PWM_RANGE_MASK          0xF0
+#define                ADT7462_PWM_RANGE_SHIFT         4
+#define ADT7462_REG_PWM_CFG_BASE_ADDR          0x21
+#define ADT7462_REG_PWM_CFG_MAX_ADDR           0x24
+#define                ADT7462_PWM_CHANNEL_MASK        0xE0
+#define                ADT7462_PWM_CHANNEL_SHIFT       5
+
+#define ADT7462_REG_PIN_CFG_BASE_ADDR          0x10
+#define ADT7462_REG_PIN_CFG_MAX_ADDR           0x13
+#define                ADT7462_PIN7_INPUT              0x01    /* cfg0 */
+#define                ADT7462_DIODE3_INPUT            0x20
+#define                ADT7462_DIODE1_INPUT            0x40
+#define                ADT7462_VID_INPUT               0x80
+#define                ADT7462_PIN22_INPUT             0x04    /* cfg1 */
+#define                ADT7462_PIN21_INPUT             0x08
+#define                ADT7462_PIN19_INPUT             0x10
+#define                ADT7462_PIN15_INPUT             0x20
+#define                ADT7462_PIN13_INPUT             0x40
+#define                ADT7462_PIN8_INPUT              0x80
+#define        ADT7462_PIN23_MASK              0x03
+#define                ADT7462_PIN23_SHIFT             0
+#define                ADT7462_PIN26_MASK              0x0C    /* cfg2 */
+#define                ADT7462_PIN26_SHIFT             2
+#define                ADT7462_PIN25_MASK              0x30
+#define                ADT7462_PIN25_SHIFT             4
+#define                ADT7462_PIN24_MASK              0xC0
+#define                ADT7462_PIN24_SHIFT             6
+#define                ADT7462_PIN26_VOLT_INPUT        0x08
+#define                ADT7462_PIN25_VOLT_INPUT        0x20
+#define                ADT7462_PIN28_SHIFT             6       /* cfg3 */
+#define                ADT7462_PIN28_VOLT              0x5
+
+#define ADT7462_REG_ALARM1                     0xB8
+#define        ADT7462_LT_ALARM                0x02
+#define                ADT7462_R1T_ALARM               0x04
+#define                ADT7462_R2T_ALARM               0x08
+#define                ADT7462_R3T_ALARM               0x10
+#define ADT7462_REG_ALARM2                     0xBB
+#define                ADT7462_V0_ALARM                0x01
+#define                ADT7462_V1_ALARM                0x02
+#define                ADT7462_V2_ALARM                0x04
+#define                ADT7462_V3_ALARM                0x08
+#define                ADT7462_V4_ALARM                0x10
+#define                ADT7462_V5_ALARM                0x20
+#define                ADT7462_V6_ALARM                0x40
+#define                ADT7462_V7_ALARM                0x80
+#define ADT7462_REG_ALARM3                     0xBC
+#define                ADT7462_V8_ALARM                0x08
+#define                ADT7462_V9_ALARM                0x10
+#define                ADT7462_V10_ALARM               0x20
+#define                ADT7462_V11_ALARM               0x40
+#define                ADT7462_V12_ALARM               0x80
+#define ADT7462_REG_ALARM4                     0xBD
+#define                ADT7462_F0_ALARM                0x01
+#define                ADT7462_F1_ALARM                0x02
+#define                ADT7462_F2_ALARM                0x04
+#define                ADT7462_F3_ALARM                0x08
+#define                ADT7462_F4_ALARM                0x10
+#define                ADT7462_F5_ALARM                0x20
+#define                ADT7462_F6_ALARM                0x40
+#define                ADT7462_F7_ALARM                0x80
+#define ADT7462_ALARM1                         0x0000
+#define ADT7462_ALARM2                         0x0100
+#define ADT7462_ALARM3                         0x0200
+#define ADT7462_ALARM4                         0x0300
+#define ADT7462_ALARM_REG_SHIFT                        8
+#define ADT7462_ALARM_FLAG_MASK                        0x0F
+
+#define ADT7462_TEMP_COUNT             4
+#define ADT7462_TEMP_REG(x)            (ADT7462_REG_TEMP_BASE_ADDR + (x * 2))
+#define ADT7462_TEMP_MIN_REG(x)        (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x))
+#define ADT7462_TEMP_MAX_REG(x)        (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x))
+#define TEMP_FRAC_OFFSET               6
+
+#define ADT7462_FAN_COUNT              8
+#define ADT7462_REG_FAN_MIN(x)         (ADT7462_REG_FAN_MIN_BASE_ADDR + (x))
+
+#define ADT7462_PWM_COUNT              4
+#define ADT7462_REG_PWM(x)             (ADT7462_REG_PWM_BASE_ADDR + (x))
+#define ADT7462_REG_PWM_MIN(x)         (ADT7462_REG_PWM_MIN_BASE_ADDR + (x))
+#define ADT7462_REG_PWM_TMIN(x)                \
+       (ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
+#define ADT7462_REG_PWM_TRANGE(x)      \
+       (ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR + (x))
+
+#define ADT7462_PIN_CFG_REG_COUNT      4
+#define ADT7462_REG_PIN_CFG(x)         (ADT7462_REG_PIN_CFG_BASE_ADDR + (x))
+#define ADT7462_REG_PWM_CFG(x)         (ADT7462_REG_PWM_CFG_BASE_ADDR + (x))
+
+#define ADT7462_ALARM_REG_COUNT                4
+
+/*
+ * The chip can measure 13 different voltage sources:
+ *
+ * 1. +12V1 (pin 7)
+ * 2. Vccp1/+2.5V/+1.8V/+1.5V (pin 23)
+ * 3. +12V3 (pin 22)
+ * 4. +5V (pin 21)
+ * 5. +1.25V/+0.9V (pin 19)
+ * 6. +2.5V/+1.8V (pin 15)
+ * 7. +3.3v (pin 13)
+ * 8. +12V2 (pin 8)
+ * 9. Vbatt/FSB_Vtt (pin 26)
+ * A. +3.3V/+1.2V1 (pin 25)
+ * B. Vccp2/+2.5V/+1.8V/+1.5V (pin 24)
+ * C. +1.5V ICH (only if BOTH pin 28/29 are set to +1.5V)
+ * D. +1.5V 3GPIO (only if BOTH pin 28/29 are set to +1.5V)
+ *
+ * Each of these 13 has a factor to convert raw to voltage.  Even better,
+ * the pins can be connected to other sensors (tach/gpio/hot/etc), which
+ * makes the bookkeeping tricky.
+ *
+ * Some, but not all, of these voltages have low/high limits.
+ */
+#define ADT7462_VOLT_COUNT     12
+
+#define ADT7462_VENDOR         0x41
+#define ADT7462_DEVICE         0x62
+/* datasheet only mentions a revision 4 */
+#define ADT7462_REVISION       0x04
+
+/* How often do we reread sensors values? (In jiffies) */
+#define SENSOR_REFRESH_INTERVAL        (2 * HZ)
+
+/* How often do we reread sensor limit values? (In jiffies) */
+#define LIMIT_REFRESH_INTERVAL (60 * HZ)
+
+/* datasheet says to divide this number by the fan reading to get fan rpm */
+#define FAN_PERIOD_TO_RPM(x)   ((90000 * 60) / (x))
+#define FAN_RPM_TO_PERIOD      FAN_PERIOD_TO_RPM
+#define FAN_PERIOD_INVALID     65535
+#define FAN_DATA_VALID(x)      ((x) && (x) != FAN_PERIOD_INVALID)
+
+#define MASK_AND_SHIFT(value, prefix)  \
+       (((value) & prefix##_MASK) >> prefix##_SHIFT)
+
+#define ROUND_DIV(x, divisor)  (((x) + ((divisor) / 2)) / (divisor))
+
+struct adt7462_data {
+       struct device           *hwmon_dev;
+       struct attribute_group  attrs;
+       struct mutex            lock;
+       char                    sensors_valid;
+       char                    limits_valid;
+       unsigned long           sensors_last_updated;   /* In jiffies */
+       unsigned long           limits_last_updated;    /* In jiffies */
+
+       u8                      temp[ADT7462_TEMP_COUNT];
+                               /* bits 6-7 are quarter pieces of temp */
+       u8                      temp_frac[ADT7462_TEMP_COUNT];
+       u8                      temp_min[ADT7462_TEMP_COUNT];
+       u8                      temp_max[ADT7462_TEMP_COUNT];
+       u16                     fan[ADT7462_FAN_COUNT];
+       u8                      fan_enabled;
+       u8                      fan_min[ADT7462_FAN_COUNT];
+       u8                      cfg2;
+       u8                      pwm[ADT7462_PWM_COUNT];
+       u8                      pin_cfg[ADT7462_PIN_CFG_REG_COUNT];
+       u8                      voltages[ADT7462_VOLT_COUNT];
+       u8                      volt_max[ADT7462_VOLT_COUNT];
+       u8                      volt_min[ADT7462_VOLT_COUNT];
+       u8                      pwm_min[ADT7462_PWM_COUNT];
+       u8                      pwm_tmin[ADT7462_PWM_COUNT];
+       u8                      pwm_trange[ADT7462_PWM_COUNT];
+       u8                      pwm_max;        /* only one per chip */
+       u8                      pwm_cfg[ADT7462_PWM_COUNT];
+       u8                      alarms[ADT7462_ALARM_REG_COUNT];
+};
+
+static int adt7462_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id);
+static int adt7462_detect(struct i2c_client *client, int kind,
+                         struct i2c_board_info *info);
+static int adt7462_remove(struct i2c_client *client);
+
+static const struct i2c_device_id adt7462_id[] = {
+       { "adt7462", adt7462 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, adt7462_id);
+
+static struct i2c_driver adt7462_driver = {
+       .class          = I2C_CLASS_HWMON,
+       .driver = {
+               .name   = "adt7462",
+       },
+       .probe          = adt7462_probe,
+       .remove         = adt7462_remove,
+       .id_table       = adt7462_id,
+       .detect         = adt7462_detect,
+       .address_data   = &addr_data,
+};
+
+/*
+ * 16-bit registers on the ADT7462 are low-byte first.  The data sheet says
+ * that the low byte must be read before the high byte.
+ */
+static inline int adt7462_read_word_data(struct i2c_client *client, u8 reg)
+{
+       u16 foo;
+       foo = i2c_smbus_read_byte_data(client, reg);
+       foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
+       return foo;
+}
+
+/* For some reason these registers are not contiguous. */
+static int ADT7462_REG_FAN(int fan)
+{
+       if (fan < 4)
+               return ADT7462_REG_FAN_BASE_ADDR + (2 * fan);
+       return ADT7462_REG_FAN2_BASE_ADDR + (2 * (fan - 4));
+}
+
+/* Voltage registers are scattered everywhere */
+static int ADT7462_REG_VOLT_MAX(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
+                       return 0x7C;
+               break;
+       case 1:
+               return 0x69;
+       case 2:
+               if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
+                       return 0x7F;
+               break;
+       case 3:
+               if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
+                       return 0x7E;
+               break;
+       case 4:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
+                       return 0x4B;
+               break;
+       case 5:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
+                       return 0x49;
+               break;
+       case 6:
+               if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
+                       return 0x68;
+               break;
+       case 7:
+               if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
+                       return 0x7D;
+               break;
+       case 8:
+               if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
+                       return 0x6C;
+               break;
+       case 9:
+               if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
+                       return 0x6B;
+               break;
+       case 10:
+               return 0x6A;
+       case 11:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x50;
+               break;
+       case 12:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x4C;
+               break;
+       }
+       return -ENODEV;
+}
+
+static int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
+                       return 0x6D;
+               break;
+       case 1:
+               return 0x72;
+       case 2:
+               if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
+                       return 0x6F;
+               break;
+       case 3:
+               if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
+                       return 0x71;
+               break;
+       case 4:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
+                       return 0x47;
+               break;
+       case 5:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
+                       return 0x45;
+               break;
+       case 6:
+               if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
+                       return 0x70;
+               break;
+       case 7:
+               if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
+                       return 0x6E;
+               break;
+       case 8:
+               if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
+                       return 0x75;
+               break;
+       case 9:
+               if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
+                       return 0x74;
+               break;
+       case 10:
+               return 0x73;
+       case 11:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x76;
+               break;
+       case 12:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x77;
+               break;
+       }
+       return -ENODEV;
+}
+
+static int ADT7462_REG_VOLT(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
+                       return 0xA3;
+               break;
+       case 1:
+               return 0x90;
+       case 2:
+               if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
+                       return 0xA9;
+               break;
+       case 3:
+               if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
+                       return 0xA7;
+               break;
+       case 4:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
+                       return 0x8F;
+               break;
+       case 5:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
+                       return 0x8B;
+               break;
+       case 6:
+               if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
+                       return 0x96;
+               break;
+       case 7:
+               if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
+                       return 0xA5;
+               break;
+       case 8:
+               if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
+                       return 0x93;
+               break;
+       case 9:
+               if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
+                       return 0x92;
+               break;
+       case 10:
+               return 0x91;
+       case 11:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x94;
+               break;
+       case 12:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 0x95;
+               break;
+       }
+       return -ENODEV;
+}
+
+/* Provide labels for sysfs */
+static const char *voltage_label(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
+                       return "+12V1";
+               break;
+       case 1:
+               switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
+               case 0:
+                       return "Vccp1";
+               case 1:
+                       return "+2.5V";
+               case 2:
+                       return "+1.8V";
+               case 3:
+                       return "+1.5V";
+               }
+       case 2:
+               if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
+                       return "+12V3";
+               break;
+       case 3:
+               if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
+                       return "+5V";
+               break;
+       case 4:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
+                       if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
+                               return "+0.9V";
+                       return "+1.25V";
+               }
+               break;
+       case 5:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
+                       if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
+                               return "+1.8V";
+                       return "+2.5V";
+               }
+               break;
+       case 6:
+               if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
+                       return "+3.3V";
+               break;
+       case 7:
+               if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
+                       return "+12V2";
+               break;
+       case 8:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
+               case 0:
+                       return "Vbatt";
+               case 1:
+                       return "FSB_Vtt";
+               }
+               break;
+       case 9:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
+               case 0:
+                       return "+3.3V";
+               case 1:
+                       return "+1.2V1";
+               }
+               break;
+       case 10:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
+               case 0:
+                       return "Vccp2";
+               case 1:
+                       return "+2.5V";
+               case 2:
+                       return "+1.8V";
+               case 3:
+                       return "+1.5";
+               }
+       case 11:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return "+1.5V ICH";
+               break;
+       case 12:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return "+1.5V 3GPIO";
+               break;
+       }
+       return "N/A";
+}
+
+/* Multipliers are actually in uV, not mV. */
+static int voltage_multiplier(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
+                       return 62500;
+               break;
+       case 1:
+               switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
+               case 0:
+                       if (data->pin_cfg[0] & ADT7462_VID_INPUT)
+                               return 12500;
+                       return 6250;
+               case 1:
+                       return 13000;
+               case 2:
+                       return 9400;
+               case 3:
+                       return 7800;
+               }
+       case 2:
+               if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
+                       return 62500;
+               break;
+       case 3:
+               if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
+                       return 26000;
+               break;
+       case 4:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
+                       if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
+                               return 4690;
+                       return 6500;
+               }
+               break;
+       case 5:
+               if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
+                       if (data->pin_cfg[1] & ADT7462_PIN15_INPUT)
+                               return 9400;
+                       return 13000;
+               }
+               break;
+       case 6:
+               if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
+                       return 17200;
+               break;
+       case 7:
+               if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
+                       return 62500;
+               break;
+       case 8:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
+               case 0:
+                       return 15600;
+               case 1:
+                       return 6250;
+               }
+               break;
+       case 9:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
+               case 0:
+                       return 17200;
+               case 1:
+                       return 6250;
+               }
+               break;
+       case 10:
+               switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
+               case 0:
+                       return 6250;
+               case 1:
+                       return 13000;
+               case 2:
+                       return 9400;
+               case 3:
+                       return 7800;
+               }
+       case 11:
+       case 12:
+               if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
+                                       ADT7462_PIN28_VOLT &&
+                   !(data->pin_cfg[0] & ADT7462_VID_INPUT))
+                       return 7800;
+       }
+       return 0;
+}
+
+static int temp_enabled(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+       case 2:
+               return 1;
+       case 1:
+               if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
+                       return 1;
+               break;
+       case 3:
+               if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
+                       return 1;
+               break;
+       }
+       return 0;
+}
+
+static const char *temp_label(struct adt7462_data *data, int which)
+{
+       switch (which) {
+       case 0:
+               return "local";
+       case 1:
+               if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
+                       return "remote1";
+               break;
+       case 2:
+               return "remote2";
+       case 3:
+               if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
+                       return "remote3";
+               break;
+       }
+       return "N/A";
+}
+
+/* Map Trange register values to mC */
+#define NUM_TRANGE_VALUES      16
+static const int trange_values[NUM_TRANGE_VALUES] = {
+       2000,
+       2500,
+       3300,
+       4000,
+       5000,
+       6700,
+       8000,
+       10000,
+       13300,
+       16000,
+       20000,
+       26700,
+       32000,
+       40000,
+       53300,
+       80000
+};
+
+static int find_trange_value(int trange)
+{
+       int i;
+
+       for (i = 0; i < NUM_TRANGE_VALUES; i++)
+               if (trange_values[i] == trange)
+                       return i;
+
+       return -ENODEV;
+}
+
+static struct adt7462_data *adt7462_update_device(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       unsigned long local_jiffies = jiffies;
+       int i;
+
+       mutex_lock(&data->lock);
+       if (time_before(local_jiffies, data->sensors_last_updated +
+               SENSOR_REFRESH_INTERVAL)
+               && data->sensors_valid)
+               goto no_sensor_update;
+
+       for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
+               /*
+                * Reading the fractional register locks the integral
+                * register until both have been read.
+                */
+               data->temp_frac[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_TEMP_REG(i));
+               data->temp[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_TEMP_REG(i) + 1);
+       }
+
+       for (i = 0; i < ADT7462_FAN_COUNT; i++)
+               data->fan[i] = adt7462_read_word_data(client,
+                                               ADT7462_REG_FAN(i));
+
+       data->fan_enabled = i2c_smbus_read_byte_data(client,
+                                       ADT7462_REG_FAN_ENABLE);
+
+       for (i = 0; i < ADT7462_PWM_COUNT; i++)
+               data->pwm[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_PWM(i));
+
+       for (i = 0; i < ADT7462_PIN_CFG_REG_COUNT; i++)
+               data->pin_cfg[i] = i2c_smbus_read_byte_data(client,
+                               ADT7462_REG_PIN_CFG(i));
+
+       for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
+               int reg = ADT7462_REG_VOLT(data, i);
+               if (!reg)
+                       data->voltages[i] = 0;
+               else
+                       data->voltages[i] = i2c_smbus_read_byte_data(client,
+                                                                    reg);
+       }
+
+       data->alarms[0] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM1);
+       data->alarms[1] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM2);
+       data->alarms[2] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM3);
+       data->alarms[3] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM4);
+
+       data->sensors_last_updated = local_jiffies;
+       data->sensors_valid = 1;
+
+no_sensor_update:
+       if (time_before(local_jiffies, data->limits_last_updated +
+               LIMIT_REFRESH_INTERVAL)
+               && data->limits_valid)
+               goto out;
+
+       for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
+               data->temp_min[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_TEMP_MIN_REG(i));
+               data->temp_max[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_TEMP_MAX_REG(i));
+       }
+
+       for (i = 0; i < ADT7462_FAN_COUNT; i++)
+               data->fan_min[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_FAN_MIN(i));
+
+       for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
+               int reg = ADT7462_REG_VOLT_MAX(data, i);
+               data->volt_max[i] =
+                       (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
+
+               reg = ADT7462_REG_VOLT_MIN(data, i);
+               data->volt_min[i] =
+                       (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
+       }
+
+       for (i = 0; i < ADT7462_PWM_COUNT; i++) {
+               data->pwm_min[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_PWM_MIN(i));
+               data->pwm_tmin[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_PWM_TMIN(i));
+               data->pwm_trange[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_PWM_TRANGE(i));
+               data->pwm_cfg[i] = i2c_smbus_read_byte_data(client,
+                                               ADT7462_REG_PWM_CFG(i));
+       }
+
+       data->pwm_max = i2c_smbus_read_byte_data(client, ADT7462_REG_PWM_MAX);
+
+       data->cfg2 = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
+
+       data->limits_last_updated = local_jiffies;
+       data->limits_valid = 1;
+
+out:
+       mutex_unlock(&data->lock);
+       return data;
+}
+
+static ssize_t show_temp_min(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       if (!temp_enabled(data, attr->index))
+               return sprintf(buf, "0\n");
+
+       return sprintf(buf, "%d\n", 1000 * (data->temp_min[attr->index] - 64));
+}
+
+static ssize_t set_temp_min(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000) + 64;
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->temp_min[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_TEMP_MIN_REG(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_temp_max(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       if (!temp_enabled(data, attr->index))
+               return sprintf(buf, "0\n");
+
+       return sprintf(buf, "%d\n", 1000 * (data->temp_max[attr->index] - 64));
+}
+
+static ssize_t set_temp_max(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000) + 64;
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->temp_max[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_TEMP_MAX_REG(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
+                        char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       u8 frac = data->temp_frac[attr->index] >> TEMP_FRAC_OFFSET;
+
+       if (!temp_enabled(data, attr->index))
+               return sprintf(buf, "0\n");
+
+       return sprintf(buf, "%d\n", 1000 * (data->temp[attr->index] - 64) +
+                                    250 * frac);
+}
+
+static ssize_t show_temp_label(struct device *dev,
+                              struct device_attribute *devattr,
+                              char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       return sprintf(buf, "%s\n", temp_label(data, attr->index));
+}
+
+static ssize_t show_volt_max(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int x = voltage_multiplier(data, attr->index);
+
+       x *= data->volt_max[attr->index];
+       x /= 1000; /* convert from uV to mV */
+
+       return sprintf(buf, "%d\n", x);
+}
+
+static ssize_t set_volt_max(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       int x = voltage_multiplier(data, attr->index);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp) || !x)
+               return -EINVAL;
+
+       temp *= 1000; /* convert mV to uV */
+       temp = ROUND_DIV(temp, x);
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->volt_max[attr->index] = temp;
+       i2c_smbus_write_byte_data(client,
+                                 ADT7462_REG_VOLT_MAX(data, attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_volt_min(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int x = voltage_multiplier(data, attr->index);
+
+       x *= data->volt_min[attr->index];
+       x /= 1000; /* convert from uV to mV */
+
+       return sprintf(buf, "%d\n", x);
+}
+
+static ssize_t set_volt_min(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       int x = voltage_multiplier(data, attr->index);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp) || !x)
+               return -EINVAL;
+
+       temp *= 1000; /* convert mV to uV */
+       temp = ROUND_DIV(temp, x);
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->volt_min[attr->index] = temp;
+       i2c_smbus_write_byte_data(client,
+                                 ADT7462_REG_VOLT_MIN(data, attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_voltage(struct device *dev,
+                           struct device_attribute *devattr,
+                           char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int x = voltage_multiplier(data, attr->index);
+
+       x *= data->voltages[attr->index];
+       x /= 1000; /* convert from uV to mV */
+
+       return sprintf(buf, "%d\n", x);
+}
+
+static ssize_t show_voltage_label(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       return sprintf(buf, "%s\n", voltage_label(data, attr->index));
+}
+
+static ssize_t show_alarm(struct device *dev,
+                         struct device_attribute *devattr,
+                         char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int reg = attr->index >> ADT7462_ALARM_REG_SHIFT;
+       int mask = attr->index & ADT7462_ALARM_FLAG_MASK;
+
+       if (data->alarms[reg] & mask)
+               return sprintf(buf, "1\n");
+       else
+               return sprintf(buf, "0\n");
+}
+
+static int fan_enabled(struct adt7462_data *data, int fan)
+{
+       return data->fan_enabled & (1 << fan);
+}
+
+static ssize_t show_fan_min(struct device *dev,
+                           struct device_attribute *devattr,
+                           char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       u16 temp;
+
+       /* Only the MSB of the min fan period is stored... */
+       temp = data->fan_min[attr->index];
+       temp <<= 8;
+
+       if (!fan_enabled(data, attr->index) ||
+           !FAN_DATA_VALID(temp))
+               return sprintf(buf, "0\n");
+
+       return sprintf(buf, "%d\n", FAN_PERIOD_TO_RPM(temp));
+}
+
+static ssize_t set_fan_min(struct device *dev,
+                          struct device_attribute *devattr,
+                          const char *buf, size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp) || !temp ||
+           !fan_enabled(data, attr->index))
+               return -EINVAL;
+
+       temp = FAN_RPM_TO_PERIOD(temp);
+       temp >>= 8;
+       temp = SENSORS_LIMIT(temp, 1, 255);
+
+       mutex_lock(&data->lock);
+       data->fan_min[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_FAN_MIN(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
+                       char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       if (!fan_enabled(data, attr->index) ||
+           !FAN_DATA_VALID(data->fan[attr->index]))
+               return sprintf(buf, "0\n");
+
+       return sprintf(buf, "%d\n",
+                      FAN_PERIOD_TO_RPM(data->fan[attr->index]));
+}
+
+static ssize_t show_force_pwm_max(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", (data->cfg2 & ADT7462_FSPD_MASK ? 1 : 0));
+}
+
+static ssize_t set_force_pwm_max(struct device *dev,
+                                struct device_attribute *devattr,
+                                const char *buf,
+                                size_t count)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+       u8 reg;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       mutex_lock(&data->lock);
+       reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
+       if (temp)
+               reg |= ADT7462_FSPD_MASK;
+       else
+               reg &= ~ADT7462_FSPD_MASK;
+       data->cfg2 = reg;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_CFG2, reg);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
+                       char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", data->pwm[attr->index]);
+}
+
+static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
+                       const char *buf, size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->pwm[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM(attr->index), temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_max(struct device *dev,
+                           struct device_attribute *devattr,
+                           char *buf)
+{
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", data->pwm_max);
+}
+
+static ssize_t set_pwm_max(struct device *dev,
+                          struct device_attribute *devattr,
+                          const char *buf,
+                          size_t count)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->pwm_max = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MAX, temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_min(struct device *dev,
+                           struct device_attribute *devattr,
+                           char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
+}
+
+static ssize_t set_pwm_min(struct device *dev,
+                          struct device_attribute *devattr,
+                          const char *buf,
+                          size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->pwm_min[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MIN(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_hyst(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", 1000 *
+                     (data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK));
+}
+
+static ssize_t set_pwm_hyst(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
+       temp = SENSORS_LIMIT(temp, 0, 15);
+
+       /* package things up */
+       temp &= ADT7462_PWM_HYST_MASK;
+       temp |= data->pwm_trange[attr->index] & ADT7462_PWM_RANGE_MASK;
+
+       mutex_lock(&data->lock);
+       data->pwm_trange[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_tmax(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+
+       /* tmax = tmin + trange */
+       int trange = trange_values[data->pwm_trange[attr->index] >>
+                                  ADT7462_PWM_RANGE_SHIFT];
+       int tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
+
+       return sprintf(buf, "%d\n", tmin + trange);
+}
+
+static ssize_t set_pwm_tmax(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       int temp;
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       int tmin, trange_value;
+       long trange;
+
+       if (strict_strtol(buf, 10, &trange))
+               return -EINVAL;
+
+       /* trange = tmax - tmin */
+       tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
+       trange_value = find_trange_value(trange - tmin);
+
+       if (trange_value < 0)
+               return -EINVAL;
+
+       temp = trange_value << ADT7462_PWM_RANGE_SHIFT;
+       temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK;
+
+       mutex_lock(&data->lock);
+       data->pwm_trange[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_tmin(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       return sprintf(buf, "%d\n", 1000 * (data->pwm_tmin[attr->index] - 64));
+}
+
+static ssize_t set_pwm_tmin(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000) + 64;
+       temp = SENSORS_LIMIT(temp, 0, 255);
+
+       mutex_lock(&data->lock);
+       data->pwm_tmin[attr->index] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TMIN(attr->index),
+                                 temp);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
+static ssize_t show_pwm_auto(struct device *dev,
+                            struct device_attribute *devattr,
+                            char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int cfg = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
+
+       switch (cfg) {
+       case 4: /* off */
+               return sprintf(buf, "0\n");
+       case 7: /* manual */
+               return sprintf(buf, "1\n");
+       default: /* automatic */
+               return sprintf(buf, "2\n");
+       }
+}
+
+static void set_pwm_channel(struct i2c_client *client,
+                           struct adt7462_data *data,
+                           int which,
+                           int value)
+{
+       int temp = data->pwm_cfg[which] & ~ADT7462_PWM_CHANNEL_MASK;
+       temp |= value << ADT7462_PWM_CHANNEL_SHIFT;
+
+       mutex_lock(&data->lock);
+       data->pwm_cfg[which] = temp;
+       i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_CFG(which), temp);
+       mutex_unlock(&data->lock);
+}
+
+static ssize_t set_pwm_auto(struct device *dev,
+                           struct device_attribute *devattr,
+                           const char *buf,
+                           size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       switch (temp) {
+       case 0: /* off */
+               set_pwm_channel(client, data, attr->index, 4);
+               return count;
+       case 1: /* manual */
+               set_pwm_channel(client, data, attr->index, 7);
+               return count;
+       default:
+               return -EINVAL;
+       }
+}
+
+static ssize_t show_pwm_auto_temp(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7462_data *data = adt7462_update_device(dev);
+       int channel = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
+
+       switch (channel) {
+       case 0: /* temp[1234] only */
+       case 1:
+       case 2:
+       case 3:
+               return sprintf(buf, "%d\n", (1 << channel));
+       case 5: /* temp1 & temp4  */
+               return sprintf(buf, "9\n");
+       case 6:
+               return sprintf(buf, "15\n");
+       default:
+               return sprintf(buf, "0\n");
+       }
+}
+
+static int cvt_auto_temp(int input)
+{
+       if (input == 0xF)
+               return 6;
+       if (input == 0x9)
+               return 5;
+       if (input < 1 || !is_power_of_2(input))
+               return -EINVAL;
+       return ilog2(input);
+}
+
+static ssize_t set_pwm_auto_temp(struct device *dev,
+                                struct device_attribute *devattr,
+                                const char *buf,
+                                size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adt7462_data *data = i2c_get_clientdata(client);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = cvt_auto_temp(temp);
+       if (temp < 0)
+               return temp;
+
+       set_pwm_channel(client, data, attr->index, temp);
+
+       return count;
+}
+
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
+                   set_temp_max, 0);
+static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
+                   set_temp_max, 1);
+static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
+                   set_temp_max, 2);
+static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,
+                   set_temp_max, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
+                   set_temp_min, 0);
+static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
+                   set_temp_min, 1);
+static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
+                   set_temp_min, 2);
+static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min,
+                   set_temp_min, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM1 | ADT7462_LT_ALARM);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM1 | ADT7462_R1T_ALARM);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM1 | ADT7462_R2T_ALARM);
+static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM1 | ADT7462_R3T_ALARM);
+
+static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 0);
+static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 1);
+static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 2);
+static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 3);
+static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 4);
+static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 5);
+static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 6);
+static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 7);
+static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 8);
+static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 9);
+static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 10);
+static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 11);
+static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, show_volt_max,
+                   set_volt_max, 12);
+
+static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 0);
+static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 1);
+static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 2);
+static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 3);
+static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 4);
+static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 5);
+static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 6);
+static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 7);
+static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 8);
+static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 9);
+static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 10);
+static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 11);
+static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, show_volt_min,
+                   set_volt_min, 12);
+
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 0);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 1);
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 2);
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 3);
+static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 4);
+static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 5);
+static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 6);
+static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL, 7);
+static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_voltage, NULL, 8);
+static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_voltage, NULL, 9);
+static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_voltage, NULL, 10);
+static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_voltage, NULL, 11);
+static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_voltage, NULL, 12);
+
+static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, show_voltage_label, NULL, 0);
+static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, show_voltage_label, NULL, 1);
+static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_voltage_label, NULL, 2);
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_voltage_label, NULL, 3);
+static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_voltage_label, NULL, 4);
+static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_voltage_label, NULL, 5);
+static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_voltage_label, NULL, 6);
+static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_voltage_label, NULL, 7);
+static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_voltage_label, NULL, 8);
+static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, show_voltage_label, NULL, 9);
+static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, show_voltage_label, NULL, 10);
+static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, show_voltage_label, NULL, 11);
+static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, show_voltage_label, NULL, 12);
+
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V0_ALARM);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V7_ALARM);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V2_ALARM);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V6_ALARM);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V5_ALARM);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V4_ALARM);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V3_ALARM);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM2 | ADT7462_V1_ALARM);
+static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM3 | ADT7462_V10_ALARM);
+static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM3 | ADT7462_V9_ALARM);
+static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM3 | ADT7462_V8_ALARM);
+static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM3 | ADT7462_V11_ALARM);
+static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM3 | ADT7462_V12_ALARM);
+
+static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 0);
+static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 1);
+static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 2);
+static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 3);
+static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 4);
+static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 5);
+static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 6);
+static SENSOR_DEVICE_ATTR(fan8_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   set_fan_min, 7);
+
+static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
+static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
+static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 5);
+static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan, NULL, 7);
+
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F0_ALARM);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F1_ALARM);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F2_ALARM);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F3_ALARM);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F4_ALARM);
+static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F5_ALARM);
+static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F6_ALARM);
+static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7462_ALARM4 | ADT7462_F7_ALARM);
+
+static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
+                   show_force_pwm_max, set_force_pwm_max, 0);
+
+static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
+static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
+static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
+static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
+
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_min, set_pwm_min, 0);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_min, set_pwm_min, 1);
+static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_min, set_pwm_min, 2);
+static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_min, set_pwm_min, 3);
+
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_max, set_pwm_max, 0);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_max, set_pwm_max, 1);
+static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_max, set_pwm_max, 2);
+static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
+                   show_pwm_max, set_pwm_max, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_auto_point1_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 0);
+static SENSOR_DEVICE_ATTR(temp2_auto_point1_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 1);
+static SENSOR_DEVICE_ATTR(temp3_auto_point1_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 2);
+static SENSOR_DEVICE_ATTR(temp4_auto_point1_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_auto_point2_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 0);
+static SENSOR_DEVICE_ATTR(temp2_auto_point2_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 1);
+static SENSOR_DEVICE_ATTR(temp3_auto_point2_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 2);
+static SENSOR_DEVICE_ATTR(temp4_auto_point2_hyst, S_IWUSR | S_IRUGO,
+                   show_pwm_hyst, set_pwm_hyst, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmin, set_pwm_tmin, 0);
+static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmin, set_pwm_tmin, 1);
+static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmin, set_pwm_tmin, 2);
+static SENSOR_DEVICE_ATTR(temp4_auto_point1_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmin, set_pwm_tmin, 3);
+
+static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmax, set_pwm_tmax, 0);
+static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmax, set_pwm_tmax, 1);
+static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmax, set_pwm_tmax, 2);
+static SENSOR_DEVICE_ATTR(temp4_auto_point2_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_tmax, set_pwm_tmax, 3);
+
+static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
+                   set_pwm_auto, 0);
+static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
+                   set_pwm_auto, 1);
+static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
+                   set_pwm_auto, 2);
+static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
+                   set_pwm_auto, 3);
+
+static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_auto_temp, set_pwm_auto_temp, 0);
+static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_auto_temp, set_pwm_auto_temp, 1);
+static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_auto_temp, set_pwm_auto_temp, 2);
+static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
+                   show_pwm_auto_temp, set_pwm_auto_temp, 3);
+
+static struct attribute *adt7462_attr[] =
+{
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp4_max.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp4_min.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp4_input.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_label.dev_attr.attr,
+       &sensor_dev_attr_temp2_label.dev_attr.attr,
+       &sensor_dev_attr_temp3_label.dev_attr.attr,
+       &sensor_dev_attr_temp4_label.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp4_alarm.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_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in6_max.dev_attr.attr,
+       &sensor_dev_attr_in7_max.dev_attr.attr,
+       &sensor_dev_attr_in8_max.dev_attr.attr,
+       &sensor_dev_attr_in9_max.dev_attr.attr,
+       &sensor_dev_attr_in10_max.dev_attr.attr,
+       &sensor_dev_attr_in11_max.dev_attr.attr,
+       &sensor_dev_attr_in12_max.dev_attr.attr,
+       &sensor_dev_attr_in13_max.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_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in6_min.dev_attr.attr,
+       &sensor_dev_attr_in7_min.dev_attr.attr,
+       &sensor_dev_attr_in8_min.dev_attr.attr,
+       &sensor_dev_attr_in9_min.dev_attr.attr,
+       &sensor_dev_attr_in10_min.dev_attr.attr,
+       &sensor_dev_attr_in11_min.dev_attr.attr,
+       &sensor_dev_attr_in12_min.dev_attr.attr,
+       &sensor_dev_attr_in13_min.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_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in6_input.dev_attr.attr,
+       &sensor_dev_attr_in7_input.dev_attr.attr,
+       &sensor_dev_attr_in8_input.dev_attr.attr,
+       &sensor_dev_attr_in9_input.dev_attr.attr,
+       &sensor_dev_attr_in10_input.dev_attr.attr,
+       &sensor_dev_attr_in11_input.dev_attr.attr,
+       &sensor_dev_attr_in12_input.dev_attr.attr,
+       &sensor_dev_attr_in13_input.dev_attr.attr,
+
+       &sensor_dev_attr_in1_label.dev_attr.attr,
+       &sensor_dev_attr_in2_label.dev_attr.attr,
+       &sensor_dev_attr_in3_label.dev_attr.attr,
+       &sensor_dev_attr_in4_label.dev_attr.attr,
+       &sensor_dev_attr_in5_label.dev_attr.attr,
+       &sensor_dev_attr_in6_label.dev_attr.attr,
+       &sensor_dev_attr_in7_label.dev_attr.attr,
+       &sensor_dev_attr_in8_label.dev_attr.attr,
+       &sensor_dev_attr_in9_label.dev_attr.attr,
+       &sensor_dev_attr_in10_label.dev_attr.attr,
+       &sensor_dev_attr_in11_label.dev_attr.attr,
+       &sensor_dev_attr_in12_label.dev_attr.attr,
+       &sensor_dev_attr_in13_label.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_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_in6_alarm.dev_attr.attr,
+       &sensor_dev_attr_in7_alarm.dev_attr.attr,
+       &sensor_dev_attr_in8_alarm.dev_attr.attr,
+       &sensor_dev_attr_in9_alarm.dev_attr.attr,
+       &sensor_dev_attr_in10_alarm.dev_attr.attr,
+       &sensor_dev_attr_in11_alarm.dev_attr.attr,
+       &sensor_dev_attr_in12_alarm.dev_attr.attr,
+       &sensor_dev_attr_in13_alarm.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan3_min.dev_attr.attr,
+       &sensor_dev_attr_fan4_min.dev_attr.attr,
+       &sensor_dev_attr_fan5_min.dev_attr.attr,
+       &sensor_dev_attr_fan6_min.dev_attr.attr,
+       &sensor_dev_attr_fan7_min.dev_attr.attr,
+       &sensor_dev_attr_fan8_min.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan3_input.dev_attr.attr,
+       &sensor_dev_attr_fan4_input.dev_attr.attr,
+       &sensor_dev_attr_fan5_input.dev_attr.attr,
+       &sensor_dev_attr_fan6_input.dev_attr.attr,
+       &sensor_dev_attr_fan7_input.dev_attr.attr,
+       &sensor_dev_attr_fan8_input.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan5_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan6_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan7_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan8_alarm.dev_attr.attr,
+
+       &sensor_dev_attr_force_pwm_max.dev_attr.attr,
+       &sensor_dev_attr_pwm1.dev_attr.attr,
+       &sensor_dev_attr_pwm2.dev_attr.attr,
+       &sensor_dev_attr_pwm3.dev_attr.attr,
+       &sensor_dev_attr_pwm4.dev_attr.attr,
+
+       &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr,
+
+       &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_auto_point1_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp2_auto_point1_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp4_auto_point1_hyst.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_auto_point2_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp2_auto_point2_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point2_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp4_auto_point2_hyst.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp4_auto_point1_temp.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_temp4_auto_point2_temp.dev_attr.attr,
+
+       &sensor_dev_attr_pwm1_enable.dev_attr.attr,
+       &sensor_dev_attr_pwm2_enable.dev_attr.attr,
+       &sensor_dev_attr_pwm3_enable.dev_attr.attr,
+       &sensor_dev_attr_pwm4_enable.dev_attr.attr,
+
+       &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
+       NULL
+};
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int adt7462_detect(struct i2c_client *client, int kind,
+                         struct i2c_board_info *info)
+{
+       struct i2c_adapter *adapter = client->adapter;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+               return -ENODEV;
+
+       if (kind <= 0) {
+               int vendor, device, revision;
+
+               vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
+               if (vendor != ADT7462_VENDOR)
+                       return -ENODEV;
+
+               device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE);
+               if (device != ADT7462_DEVICE)
+                       return -ENODEV;
+
+               revision = i2c_smbus_read_byte_data(client,
+                                                   ADT7462_REG_REVISION);
+               if (revision != ADT7462_REVISION)
+                       return -ENODEV;
+       } else
+               dev_dbg(&adapter->dev, "detection forced\n");
+
+       strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
+
+       return 0;
+}
+
+static int adt7462_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct adt7462_data *data;
+       int err;
+
+       data = kzalloc(sizeof(struct adt7462_data), GFP_KERNEL);
+       if (!data) {
+               err = -ENOMEM;
+               goto exit;
+       }
+
+       i2c_set_clientdata(client, data);
+       mutex_init(&data->lock);
+
+       dev_info(&client->dev, "%s chip found\n", client->name);
+
+       /* Register sysfs hooks */
+       data->attrs.attrs = adt7462_attr;
+       err = sysfs_create_group(&client->dev.kobj, &data->attrs);
+       if (err)
+               goto exit_free;
+
+       data->hwmon_dev = hwmon_device_register(&client->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto exit_remove;
+       }
+
+       return 0;
+
+exit_remove:
+       sysfs_remove_group(&client->dev.kobj, &data->attrs);
+exit_free:
+       kfree(data);
+exit:
+       return err;
+}
+
+static int adt7462_remove(struct i2c_client *client)
+{
+       struct adt7462_data *data = i2c_get_clientdata(client);
+
+       hwmon_device_unregister(data->hwmon_dev);
+       sysfs_remove_group(&client->dev.kobj, &data->attrs);
+       kfree(data);
+       return 0;
+}
+
+static int __init adt7462_init(void)
+{
+       return i2c_add_driver(&adt7462_driver);
+}
+
+static void __exit adt7462_exit(void)
+{
+       i2c_del_driver(&adt7462_driver);
+}
+
+MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
+MODULE_DESCRIPTION("ADT7462 driver");
+MODULE_LICENSE("GPL");
+
+module_init(adt7462_init);
+module_exit(adt7462_exit);
index d368d8f845e1148d83a55da797d11a5758067b0b..1311a595147e17a136fbe5dbe1b81ebaa635acfe 100644 (file)
@@ -137,6 +137,8 @@ I2C_CLIENT_INSMOD_1(adt7470);
 #define FAN_PERIOD_INVALID     65535
 #define FAN_DATA_VALID(x)      ((x) && (x) != FAN_PERIOD_INVALID)
 
+#define ROUND_DIV(x, divisor)  (((x) + ((divisor) / 2)) / (divisor))
+
 struct adt7470_data {
        struct device           *hwmon_dev;
        struct attribute_group  attrs;
@@ -353,7 +355,13 @@ static ssize_t set_temp_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->temp_min[attr->index] = temp;
@@ -381,7 +389,13 @@ static ssize_t set_temp_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->temp_max[attr->index] = temp;
@@ -430,11 +444,13 @@ static ssize_t set_fan_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
 
-       if (!temp)
+       if (strict_strtol(buf, 10, &temp) || !temp)
                return -EINVAL;
+
        temp = FAN_RPM_TO_PERIOD(temp);
+       temp = SENSORS_LIMIT(temp, 1, 65534);
 
        mutex_lock(&data->lock);
        data->fan_max[attr->index] = temp;
@@ -465,11 +481,13 @@ static ssize_t set_fan_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
 
-       if (!temp)
+       if (strict_strtol(buf, 10, &temp) || !temp)
                return -EINVAL;
+
        temp = FAN_RPM_TO_PERIOD(temp);
+       temp = SENSORS_LIMIT(temp, 1, 65534);
 
        mutex_lock(&data->lock);
        data->fan_min[attr->index] = temp;
@@ -507,9 +525,12 @@ static ssize_t set_force_pwm_max(struct device *dev,
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
        u8 reg;
 
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
        mutex_lock(&data->lock);
        data->force_pwm_max = temp;
        reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
@@ -537,7 +558,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm[attr->index] = temp;
@@ -564,7 +590,12 @@ static ssize_t set_pwm_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm_max[attr->index] = temp;
@@ -592,7 +623,12 @@ static ssize_t set_pwm_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm_min[attr->index] = temp;
@@ -630,7 +666,13 @@ static ssize_t set_pwm_tmin(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm_tmin[attr->index] = temp;
@@ -658,11 +700,14 @@ static ssize_t set_pwm_auto(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
        int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index);
        int pwm_auto_reg_mask;
+       long temp;
        u8 reg;
 
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
        if (attr->index % 2)
                pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
        else
@@ -716,10 +761,14 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7470_data *data = i2c_get_clientdata(client);
-       int temp = cvt_auto_temp(simple_strtol(buf, NULL, 10));
        int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index);
+       long temp;
        u8 reg;
 
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = cvt_auto_temp(temp);
        if (temp < 0)
                return temp;
 
index b9a8ea30c99c822542682017fc40a4c83e99b4f7..18aa30866a6c53deccb0dc5eeda470dd9b5efd1d 100644 (file)
@@ -129,6 +129,8 @@ I2C_CLIENT_INSMOD_1(adt7473);
 #define FAN_PERIOD_INVALID     65535
 #define FAN_DATA_VALID(x)      ((x) && (x) != FAN_PERIOD_INVALID)
 
+#define ROUND_DIV(x, divisor)  (((x) + ((divisor) / 2)) / (divisor))
+
 struct adt7473_data {
        struct device           *hwmon_dev;
        struct attribute_group  attrs;
@@ -357,7 +359,12 @@ static ssize_t set_volt_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int volt = encode_volt(attr->index, simple_strtol(buf, NULL, 10));
+       long volt;
+
+       if (strict_strtol(buf, 10, &volt))
+               return -EINVAL;
+
+       volt = encode_volt(attr->index, volt);
 
        mutex_lock(&data->lock);
        data->volt_min[attr->index] = volt;
@@ -386,7 +393,12 @@ static ssize_t set_volt_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int volt = encode_volt(attr->index, simple_strtol(buf, NULL, 10));
+       long volt;
+
+       if (strict_strtol(buf, 10, &volt))
+               return -EINVAL;
+
+       volt = encode_volt(attr->index, volt);
 
        mutex_lock(&data->lock);
        data->volt_max[attr->index] = volt;
@@ -419,7 +431,8 @@ static int decode_temp(u8 twos_complement, u8 raw)
 
 static u8 encode_temp(u8 twos_complement, int cooked)
 {
-       return twos_complement ? cooked & 0xFF : cooked + 64;
+       u8 ret = twos_complement ? cooked & 0xFF : cooked + 64;
+       return SENSORS_LIMIT(ret, 0, 255);
 }
 
 static ssize_t show_temp_min(struct device *dev,
@@ -441,7 +454,12 @@ static ssize_t set_temp_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
        temp = encode_temp(data->temp_twos_complement, temp);
 
        mutex_lock(&data->lock);
@@ -472,7 +490,12 @@ static ssize_t set_temp_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
        temp = encode_temp(data->temp_twos_complement, temp);
 
        mutex_lock(&data->lock);
@@ -515,11 +538,13 @@ static ssize_t set_fan_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
 
-       if (!temp)
+       if (strict_strtol(buf, 10, &temp) || !temp)
                return -EINVAL;
+
        temp = FAN_RPM_TO_PERIOD(temp);
+       temp = SENSORS_LIMIT(temp, 1, 65534);
 
        mutex_lock(&data->lock);
        data->fan_min[attr->index] = temp;
@@ -558,7 +583,10 @@ static ssize_t set_max_duty_at_crit(struct device *dev,
        u8 reg;
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
 
        mutex_lock(&data->lock);
        data->max_duty_at_overheat = !!temp;
@@ -587,7 +615,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm[attr->index] = temp;
@@ -614,7 +647,12 @@ static ssize_t set_pwm_max(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm_max[attr->index] = temp;
@@ -642,7 +680,12 @@ static ssize_t set_pwm_min(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = SENSORS_LIMIT(temp, 0, 255);
 
        mutex_lock(&data->lock);
        data->pwm_min[attr->index] = temp;
@@ -672,7 +715,12 @@ static ssize_t set_temp_tmax(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
        temp = encode_temp(data->temp_twos_complement, temp);
 
        mutex_lock(&data->lock);
@@ -703,7 +751,12 @@ static ssize_t set_temp_tmin(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10) / 1000;
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
+
+       temp = ROUND_DIV(temp, 1000);
        temp = encode_temp(data->temp_twos_complement, temp);
 
        mutex_lock(&data->lock);
@@ -741,7 +794,10 @@ static ssize_t set_pwm_enable(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
 
        switch (temp) {
        case 0:
@@ -805,7 +861,10 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7473_data *data = i2c_get_clientdata(client);
-       int temp = simple_strtol(buf, NULL, 10);
+       long temp;
+
+       if (strict_strtol(buf, 10, &temp))
+               return -EINVAL;
 
        switch (temp) {
        case 1:
index be3285912cb76b65a7d69375215614f4fc898ee2..488e45cd43d7ab4edb17fd17f6a98ce7bfd1bcf3 100644 (file)
@@ -1280,7 +1280,7 @@ static __initdata struct dmi_match_data applesmc_dmi_data[] = {
        { .accelerometer = 0, .light = 0, .temperature_set = 4 },
 /* iMac: temperature set 5 */
        { .accelerometer = 0, .light = 0, .temperature_set = 5 },
-/* MacBook3: accelerometer and temperature set 6 */
+/* MacBook3, MacBook4: accelerometer and temperature set 6 */
        { .accelerometer = 1, .light = 0, .temperature_set = 6 },
 /* MacBook Air: accelerometer, backlight and temperature set 7 */
        { .accelerometer = 1, .light = 1, .temperature_set = 7 },
@@ -1329,6 +1329,10 @@ static __initdata struct dmi_system_id applesmc_whitelist[] = {
          DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
          DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") },
                &applesmc_dmi_data[6]},
+       { applesmc_dmi_match, "Apple MacBook 4", {
+         DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
+         DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4") },
+               &applesmc_dmi_data[6]},
        { applesmc_dmi_match, "Apple MacBook 5", {
          DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
          DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") },
index 7b0ed5dea399d9fe9a5e385385a216d559d9e326..fe74609a7feb5f706ab907c5d69be9881c5bc731 100644 (file)
 static DEFINE_IDR(aem_idr);
 static DEFINE_SPINLOCK(aem_idr_lock);
 
-static struct device_driver aem_driver = {
-       .name = DRVNAME,
-       .bus = &platform_bus_type,
+static struct platform_driver aem_driver = {
+       .driver = {
+               .name = DRVNAME,
+               .bus = &platform_bus_type,
+       }
 };
 
 struct aem_ipmi_data {
@@ -583,7 +585,7 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
        data->pdev = platform_device_alloc(DRVNAME, data->id);
        if (!data->pdev)
                goto dev_err;
-       data->pdev->dev.driver = &aem_driver;
+       data->pdev->dev.driver = &aem_driver.driver;
 
        res = platform_device_add(data->pdev);
        if (res)
@@ -716,7 +718,7 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
        data->pdev = platform_device_alloc(DRVNAME, data->id);
        if (!data->pdev)
                goto dev_err;
-       data->pdev->dev.driver = &aem_driver;
+       data->pdev->dev.driver = &aem_driver.driver;
 
        res = platform_device_add(data->pdev);
        if (res)
@@ -1085,7 +1087,7 @@ static int __init aem_init(void)
 {
        int res;
 
-       res = driver_register(&aem_driver);
+       res = driver_register(&aem_driver.driver);
        if (res) {
                printk(KERN_ERR "Can't register aem driver\n");
                return res;
@@ -1097,7 +1099,7 @@ static int __init aem_init(void)
        return 0;
 
 ipmi_reg_err:
-       driver_unregister(&aem_driver);
+       driver_unregister(&aem_driver.driver);
        return res;
 
 }
@@ -1107,7 +1109,7 @@ static void __exit aem_exit(void)
        struct aem_data *p1, *next1;
 
        ipmi_smi_watcher_unregister(&driver_data.bmc_events);
-       driver_unregister(&aem_driver);
+       driver_unregister(&aem_driver.driver);
        list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list)
                aem_delete(p1);
 }
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
new file mode 100644 (file)
index 0000000..752b5c4
--- /dev/null
@@ -0,0 +1,582 @@
+/*
+ *  lis3lv02d.c - ST LIS3LV02DL accelerometer driver
+ *
+ *  Copyright (C) 2007-2008 Yan Burman
+ *  Copyright (C) 2008 Eric Piel
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/dmi.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/kthread.h>
+#include <linux/semaphore.h>
+#include <linux/delay.h>
+#include <linux/wait.h>
+#include <linux/poll.h>
+#include <linux/freezer.h>
+#include <linux/version.h>
+#include <linux/uaccess.h>
+#include <acpi/acpi_drivers.h>
+#include <asm/atomic.h>
+#include "lis3lv02d.h"
+
+#define DRIVER_NAME     "lis3lv02d"
+#define ACPI_MDPS_CLASS "accelerometer"
+
+/* joystick device poll interval in milliseconds */
+#define MDPS_POLL_INTERVAL 50
+/*
+ * The sensor can also generate interrupts (DRDY) but it's pretty pointless
+ * because their are generated even if the data do not change. So it's better
+ * to keep the interrupt for the free-fall event. The values are updated at
+ * 40Hz (at the lowest frequency), but as it can be pretty time consuming on
+ * some low processor, we poll the sensor only at 20Hz... enough for the
+ * joystick.
+ */
+
+/* Maximum value our axis may get for the input device (signed 12 bits) */
+#define MDPS_MAX_VAL 2048
+
+struct axis_conversion {
+       s8      x;
+       s8      y;
+       s8      z;
+};
+
+struct acpi_lis3lv02d {
+       struct acpi_device      *device;   /* The ACPI device */
+       struct input_dev        *idev;     /* input device */
+       struct task_struct      *kthread;  /* kthread for input */
+       struct mutex            lock;
+       struct platform_device  *pdev;     /* platform device */
+       atomic_t                count;     /* interrupt count after last read */
+       int                     xcalib;    /* calibrated null value for x */
+       int                     ycalib;    /* calibrated null value for y */
+       int                     zcalib;    /* calibrated null value for z */
+       unsigned char           is_on;     /* whether the device is on or off */
+       unsigned char           usage;     /* usage counter */
+       struct axis_conversion  ac;        /* hw -> logical axis */
+};
+
+static struct acpi_lis3lv02d adev;
+
+static int lis3lv02d_remove_fs(void);
+static int lis3lv02d_add_fs(struct acpi_device *device);
+
+/* For automatic insertion of the module */
+static struct acpi_device_id lis3lv02d_device_ids[] = {
+       {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
+       {"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids);
+
+/**
+ * lis3lv02d_acpi_init - ACPI _INI method: initialize the device.
+ * @handle: the handle of the device
+ *
+ * Returns AE_OK on success.
+ */
+static inline acpi_status lis3lv02d_acpi_init(acpi_handle handle)
+{
+       return acpi_evaluate_object(handle, METHOD_NAME__INI, NULL, NULL);
+}
+
+/**
+ * lis3lv02d_acpi_read - ACPI ALRD method: read a register
+ * @handle: the handle of the device
+ * @reg:    the register to read
+ * @ret:    result of the operation
+ *
+ * Returns AE_OK on success.
+ */
+static acpi_status lis3lv02d_acpi_read(acpi_handle handle, int reg, u8 *ret)
+{
+       union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+       struct acpi_object_list args = { 1, &arg0 };
+       unsigned long long lret;
+       acpi_status status;
+
+       arg0.integer.value = reg;
+
+       status = acpi_evaluate_integer(handle, "ALRD", &args, &lret);
+       *ret = lret;
+       return status;
+}
+
+/**
+ * lis3lv02d_acpi_write - ACPI ALWR method: write to a register
+ * @handle: the handle of the device
+ * @reg:    the register to write to
+ * @val:    the value to write
+ *
+ * Returns AE_OK on success.
+ */
+static acpi_status lis3lv02d_acpi_write(acpi_handle handle, int reg, u8 val)
+{
+       unsigned long long ret; /* Not used when writting */
+       union acpi_object in_obj[2];
+       struct acpi_object_list args = { 2, in_obj };
+
+       in_obj[0].type          = ACPI_TYPE_INTEGER;
+       in_obj[0].integer.value = reg;
+       in_obj[1].type          = ACPI_TYPE_INTEGER;
+       in_obj[1].integer.value = val;
+
+       return acpi_evaluate_integer(handle, "ALWR", &args, &ret);
+}
+
+static s16 lis3lv02d_read_16(acpi_handle handle, int reg)
+{
+       u8 lo, hi;
+
+       lis3lv02d_acpi_read(handle, reg, &lo);
+       lis3lv02d_acpi_read(handle, reg + 1, &hi);
+       /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */
+       return (s16)((hi << 8) | lo);
+}
+
+/**
+ * lis3lv02d_get_axis - For the given axis, give the value converted
+ * @axis:      1,2,3 - can also be negative
+ * @hw_values: raw values returned by the hardware
+ *
+ * Returns the converted value.
+ */
+static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
+{
+       if (axis > 0)
+               return hw_values[axis - 1];
+       else
+               return -hw_values[-axis - 1];
+}
+
+/**
+ * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer
+ * @handle: the handle to the device
+ * @x:      where to store the X axis value
+ * @y:      where to store the Y axis value
+ * @z:      where to store the Z axis value
+ *
+ * Note that 40Hz input device can eat up about 10% CPU at 800MHZ
+ */
+static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z)
+{
+       int position[3];
+
+       position[0] = lis3lv02d_read_16(handle, OUTX_L);
+       position[1] = lis3lv02d_read_16(handle, OUTY_L);
+       position[2] = lis3lv02d_read_16(handle, OUTZ_L);
+
+       *x = lis3lv02d_get_axis(adev.ac.x, position);
+       *y = lis3lv02d_get_axis(adev.ac.y, position);
+       *z = lis3lv02d_get_axis(adev.ac.z, position);
+}
+
+static inline void lis3lv02d_poweroff(acpi_handle handle)
+{
+       adev.is_on = 0;
+       /* disable X,Y,Z axis and power down */
+       lis3lv02d_acpi_write(handle, CTRL_REG1, 0x00);
+}
+
+static void lis3lv02d_poweron(acpi_handle handle)
+{
+       u8 val;
+
+       adev.is_on = 1;
+       lis3lv02d_acpi_init(handle);
+       lis3lv02d_acpi_write(handle, FF_WU_CFG, 0);
+       /*
+        * BDU: LSB and MSB values are not updated until both have been read.
+        *      So the value read will always be correct.
+        * IEN: Interrupt for free-fall and DD, not for data-ready.
+        */
+       lis3lv02d_acpi_read(handle, CTRL_REG2, &val);
+       val |= CTRL2_BDU | CTRL2_IEN;
+       lis3lv02d_acpi_write(handle, CTRL_REG2, val);
+}
+
+#ifdef CONFIG_PM
+static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state)
+{
+       /* make sure the device is off when we suspend */
+       lis3lv02d_poweroff(device->handle);
+       return 0;
+}
+
+static int lis3lv02d_resume(struct acpi_device *device)
+{
+       /* put back the device in the right state (ACPI might turn it on) */
+       mutex_lock(&adev.lock);
+       if (adev.usage > 0)
+               lis3lv02d_poweron(device->handle);
+       else
+               lis3lv02d_poweroff(device->handle);
+       mutex_unlock(&adev.lock);
+       return 0;
+}
+#else
+#define lis3lv02d_suspend NULL
+#define lis3lv02d_resume NULL
+#endif
+
+
+/*
+ * To be called before starting to use the device. It makes sure that the
+ * device will always be on until a call to lis3lv02d_decrease_use(). Not to be
+ * used from interrupt context.
+ */
+static void lis3lv02d_increase_use(struct acpi_lis3lv02d *dev)
+{
+       mutex_lock(&dev->lock);
+       dev->usage++;
+       if (dev->usage == 1) {
+               if (!dev->is_on)
+                       lis3lv02d_poweron(dev->device->handle);
+       }
+       mutex_unlock(&dev->lock);
+}
+
+/*
+ * To be called whenever a usage of the device is stopped.
+ * It will make sure to turn off the device when there is not usage.
+ */
+static void lis3lv02d_decrease_use(struct acpi_lis3lv02d *dev)
+{
+       mutex_lock(&dev->lock);
+       dev->usage--;
+       if (dev->usage == 0)
+               lis3lv02d_poweroff(dev->device->handle);
+       mutex_unlock(&dev->lock);
+}
+
+/**
+ * lis3lv02d_joystick_kthread - Kthread polling function
+ * @data: unused - here to conform to threadfn prototype
+ */
+static int lis3lv02d_joystick_kthread(void *data)
+{
+       int x, y, z;
+
+       while (!kthread_should_stop()) {
+               lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z);
+               input_report_abs(adev.idev, ABS_X, x - adev.xcalib);
+               input_report_abs(adev.idev, ABS_Y, y - adev.ycalib);
+               input_report_abs(adev.idev, ABS_Z, z - adev.zcalib);
+
+               input_sync(adev.idev);
+
+               try_to_freeze();
+               msleep_interruptible(MDPS_POLL_INTERVAL);
+       }
+
+       return 0;
+}
+
+static int lis3lv02d_joystick_open(struct input_dev *input)
+{
+       lis3lv02d_increase_use(&adev);
+       adev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d");
+       if (IS_ERR(adev.kthread)) {
+               lis3lv02d_decrease_use(&adev);
+               return PTR_ERR(adev.kthread);
+       }
+
+       return 0;
+}
+
+static void lis3lv02d_joystick_close(struct input_dev *input)
+{
+       kthread_stop(adev.kthread);
+       lis3lv02d_decrease_use(&adev);
+}
+
+
+static inline void lis3lv02d_calibrate_joystick(void)
+{
+       lis3lv02d_get_xyz(adev.device->handle, &adev.xcalib, &adev.ycalib, &adev.zcalib);
+}
+
+static int lis3lv02d_joystick_enable(void)
+{
+       int err;
+
+       if (adev.idev)
+               return -EINVAL;
+
+       adev.idev = input_allocate_device();
+       if (!adev.idev)
+               return -ENOMEM;
+
+       lis3lv02d_calibrate_joystick();
+
+       adev.idev->name       = "ST LIS3LV02DL Accelerometer";
+       adev.idev->phys       = DRIVER_NAME "/input0";
+       adev.idev->id.bustype = BUS_HOST;
+       adev.idev->id.vendor  = 0;
+       adev.idev->dev.parent = &adev.pdev->dev;
+       adev.idev->open       = lis3lv02d_joystick_open;
+       adev.idev->close      = lis3lv02d_joystick_close;
+
+       set_bit(EV_ABS, adev.idev->evbit);
+       input_set_abs_params(adev.idev, ABS_X, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);
+       input_set_abs_params(adev.idev, ABS_Y, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);
+       input_set_abs_params(adev.idev, ABS_Z, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);
+
+       err = input_register_device(adev.idev);
+       if (err) {
+               input_free_device(adev.idev);
+               adev.idev = NULL;
+       }
+
+       return err;
+}
+
+static void lis3lv02d_joystick_disable(void)
+{
+       if (!adev.idev)
+               return;
+
+       input_unregister_device(adev.idev);
+       adev.idev = NULL;
+}
+
+
+/*
+ * Initialise the accelerometer and the various subsystems.
+ * Should be rather independant of the bus system.
+ */
+static int lis3lv02d_init_device(struct acpi_lis3lv02d *dev)
+{
+       mutex_init(&dev->lock);
+       lis3lv02d_add_fs(dev->device);
+       lis3lv02d_increase_use(dev);
+
+       if (lis3lv02d_joystick_enable())
+               printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");
+
+       lis3lv02d_decrease_use(dev);
+       return 0;
+}
+
+static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
+{
+       adev.ac = *((struct axis_conversion *)dmi->driver_data);
+       printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident);
+
+       return 1;
+}
+
+/* Represents, for each axis seen by userspace, the corresponding hw axis (+1).
+ * If the value is negative, the opposite of the hw value is used. */
+static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3};
+static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3};
+static struct axis_conversion lis3lv02d_axis_x_inverted = {-1, 2, 3};
+static struct axis_conversion lis3lv02d_axis_z_inverted = {1, 2, -3};
+static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3};
+static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3};
+
+#define AXIS_DMI_MATCH(_ident, _name, _axis) {         \
+       .ident = _ident,                                \
+       .callback = lis3lv02d_dmi_matched,              \
+       .matches = {                                    \
+               DMI_MATCH(DMI_PRODUCT_NAME, _name)      \
+       },                                              \
+       .driver_data = &lis3lv02d_axis_##_axis          \
+}
+static struct dmi_system_id lis3lv02d_dmi_ids[] = {
+       /* product names are truncated to match all kinds of a same model */
+       AXIS_DMI_MATCH("NC64x0", "HP Compaq nc64", x_inverted),
+       AXIS_DMI_MATCH("NC84x0", "HP Compaq nc84", z_inverted),
+       AXIS_DMI_MATCH("NX9420", "HP Compaq nx9420", x_inverted),
+       AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted),
+       AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted),
+       AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted),
+       AXIS_DMI_MATCH("HP2133", "HP 2133", xy_rotated_left),
+       { NULL, }
+/* Laptop models without axis info (yet):
+ * "NC651xx" "HP Compaq 651"
+ * "NC671xx" "HP Compaq 671"
+ * "NC6910" "HP Compaq 6910"
+ * HP Compaq 8710x Notebook PC / Mobile Workstation
+ * "NC2400" "HP Compaq nc2400"
+ * "NX74x0" "HP Compaq nx74"
+ * "NX6325" "HP Compaq nx6325"
+ * "NC4400" "HP Compaq nc4400"
+ */
+};
+
+static int lis3lv02d_add(struct acpi_device *device)
+{
+       u8 val;
+
+       if (!device)
+               return -EINVAL;
+
+       adev.device = device;
+       strcpy(acpi_device_name(device), DRIVER_NAME);
+       strcpy(acpi_device_class(device), ACPI_MDPS_CLASS);
+       device->driver_data = &adev;
+
+       lis3lv02d_acpi_read(device->handle, WHO_AM_I, &val);
+       if ((val != LIS3LV02DL_ID) && (val != LIS302DL_ID)) {
+               printk(KERN_ERR DRIVER_NAME
+                               ": Accelerometer chip not LIS3LV02D{L,Q}\n");
+       }
+
+       /* If possible use a "standard" axes order */
+       if (dmi_check_system(lis3lv02d_dmi_ids) == 0) {
+               printk(KERN_INFO DRIVER_NAME ": laptop model unknown, "
+                                "using default axes configuration\n");
+               adev.ac = lis3lv02d_axis_normal;
+       }
+
+       return lis3lv02d_init_device(&adev);
+}
+
+static int lis3lv02d_remove(struct acpi_device *device, int type)
+{
+       if (!device)
+               return -EINVAL;
+
+       lis3lv02d_joystick_disable();
+       lis3lv02d_poweroff(device->handle);
+
+       return lis3lv02d_remove_fs();
+}
+
+
+/* Sysfs stuff */
+static ssize_t lis3lv02d_position_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       int x, y, z;
+
+       lis3lv02d_increase_use(&adev);
+       lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z);
+       lis3lv02d_decrease_use(&adev);
+       return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
+}
+
+static ssize_t lis3lv02d_calibrate_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "(%d,%d,%d)\n", adev.xcalib, adev.ycalib, adev.zcalib);
+}
+
+static ssize_t lis3lv02d_calibrate_store(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       lis3lv02d_increase_use(&adev);
+       lis3lv02d_calibrate_joystick();
+       lis3lv02d_decrease_use(&adev);
+       return count;
+}
+
+/* conversion btw sampling rate and the register values */
+static int lis3lv02dl_df_val[4] = {40, 160, 640, 2560};
+static ssize_t lis3lv02d_rate_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       u8 ctrl;
+       int val;
+
+       lis3lv02d_increase_use(&adev);
+       lis3lv02d_acpi_read(adev.device->handle, CTRL_REG1, &ctrl);
+       lis3lv02d_decrease_use(&adev);
+       val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4;
+       return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]);
+}
+
+static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
+static DEVICE_ATTR(calibrate, S_IRUGO|S_IWUSR, lis3lv02d_calibrate_show,
+       lis3lv02d_calibrate_store);
+static DEVICE_ATTR(rate, S_IRUGO, lis3lv02d_rate_show, NULL);
+
+static struct attribute *lis3lv02d_attributes[] = {
+       &dev_attr_position.attr,
+       &dev_attr_calibrate.attr,
+       &dev_attr_rate.attr,
+       NULL
+};
+
+static struct attribute_group lis3lv02d_attribute_group = {
+       .attrs = lis3lv02d_attributes
+};
+
+static int lis3lv02d_add_fs(struct acpi_device *device)
+{
+       adev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+       if (IS_ERR(adev.pdev))
+               return PTR_ERR(adev.pdev);
+
+       return sysfs_create_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group);
+}
+
+static int lis3lv02d_remove_fs(void)
+{
+       sysfs_remove_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group);
+       platform_device_unregister(adev.pdev);
+       return 0;
+}
+
+/* For the HP MDPS aka 3D Driveguard */
+static struct acpi_driver lis3lv02d_driver = {
+       .name  = DRIVER_NAME,
+       .class = ACPI_MDPS_CLASS,
+       .ids   = lis3lv02d_device_ids,
+       .ops = {
+               .add     = lis3lv02d_add,
+               .remove  = lis3lv02d_remove,
+               .suspend = lis3lv02d_suspend,
+               .resume  = lis3lv02d_resume,
+       }
+};
+
+static int __init lis3lv02d_init_module(void)
+{
+       int ret;
+
+       if (acpi_disabled)
+               return -ENODEV;
+
+       ret = acpi_bus_register_driver(&lis3lv02d_driver);
+       if (ret < 0)
+               return ret;
+
+       printk(KERN_INFO DRIVER_NAME " driver loaded.\n");
+
+       return 0;
+}
+
+static void __exit lis3lv02d_exit_module(void)
+{
+       acpi_bus_unregister_driver(&lis3lv02d_driver);
+}
+
+MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");
+MODULE_AUTHOR("Yan Burman and Eric Piel");
+MODULE_LICENSE("GPL");
+
+module_init(lis3lv02d_init_module);
+module_exit(lis3lv02d_exit_module);
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
new file mode 100644 (file)
index 0000000..330cfc6
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ *  lis3lv02d.h - ST LIS3LV02DL accelerometer driver
+ *
+ *  Copyright (C) 2007-2008 Yan Burman
+ *  Copyright (C) 2008 Eric Piel
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * The actual chip is STMicroelectronics LIS3LV02DL or LIS3LV02DQ that seems to
+ * be connected via SPI. There exists also several similar chips (such as LIS302DL or
+ * LIS3L02DQ) but not in the HP laptops and they have slightly different registers.
+ * They can also be connected via I²C.
+ */
+
+#define LIS3LV02DL_ID  0x3A /* Also the LIS3LV02DQ */
+#define LIS302DL_ID    0x3B /* Also the LIS202DL! */
+
+enum lis3lv02d_reg {
+       WHO_AM_I        = 0x0F,
+       OFFSET_X        = 0x16,
+       OFFSET_Y        = 0x17,
+       OFFSET_Z        = 0x18,
+       GAIN_X          = 0x19,
+       GAIN_Y          = 0x1A,
+       GAIN_Z          = 0x1B,
+       CTRL_REG1       = 0x20,
+       CTRL_REG2       = 0x21,
+       CTRL_REG3       = 0x22,
+       HP_FILTER_RESET = 0x23,
+       STATUS_REG      = 0x27,
+       OUTX_L          = 0x28,
+       OUTX_H          = 0x29,
+       OUTY_L          = 0x2A,
+       OUTY_H          = 0x2B,
+       OUTZ_L          = 0x2C,
+       OUTZ_H          = 0x2D,
+       FF_WU_CFG       = 0x30,
+       FF_WU_SRC       = 0x31,
+       FF_WU_ACK       = 0x32,
+       FF_WU_THS_L     = 0x34,
+       FF_WU_THS_H     = 0x35,
+       FF_WU_DURATION  = 0x36,
+       DD_CFG          = 0x38,
+       DD_SRC          = 0x39,
+       DD_ACK          = 0x3A,
+       DD_THSI_L       = 0x3C,
+       DD_THSI_H       = 0x3D,
+       DD_THSE_L       = 0x3E,
+       DD_THSE_H       = 0x3F,
+};
+
+enum lis3lv02d_ctrl1 {
+       CTRL1_Xen       = 0x01,
+       CTRL1_Yen       = 0x02,
+       CTRL1_Zen       = 0x04,
+       CTRL1_ST        = 0x08,
+       CTRL1_DF0       = 0x10,
+       CTRL1_DF1       = 0x20,
+       CTRL1_PD0       = 0x40,
+       CTRL1_PD1       = 0x80,
+};
+enum lis3lv02d_ctrl2 {
+       CTRL2_DAS       = 0x01,
+       CTRL2_SIM       = 0x02,
+       CTRL2_DRDY      = 0x04,
+       CTRL2_IEN       = 0x08,
+       CTRL2_BOOT      = 0x10,
+       CTRL2_BLE       = 0x20,
+       CTRL2_BDU       = 0x40, /* Block Data Update */
+       CTRL2_FS        = 0x80, /* Full Scale selection */
+};
+
+
+enum lis3lv02d_ctrl3 {
+       CTRL3_CFS0      = 0x01,
+       CTRL3_CFS1      = 0x02,
+       CTRL3_FDS       = 0x10,
+       CTRL3_HPFF      = 0x20,
+       CTRL3_HPDD      = 0x40,
+       CTRL3_ECK       = 0x80,
+};
+
+enum lis3lv02d_status_reg {
+       STATUS_XDA      = 0x01,
+       STATUS_YDA      = 0x02,
+       STATUS_ZDA      = 0x04,
+       STATUS_XYZDA    = 0x08,
+       STATUS_XOR      = 0x10,
+       STATUS_YOR      = 0x20,
+       STATUS_ZOR      = 0x40,
+       STATUS_XYZOR    = 0x80,
+};
+
+enum lis3lv02d_ff_wu_cfg {
+       FF_WU_CFG_XLIE  = 0x01,
+       FF_WU_CFG_XHIE  = 0x02,
+       FF_WU_CFG_YLIE  = 0x04,
+       FF_WU_CFG_YHIE  = 0x08,
+       FF_WU_CFG_ZLIE  = 0x10,
+       FF_WU_CFG_ZHIE  = 0x20,
+       FF_WU_CFG_LIR   = 0x40,
+       FF_WU_CFG_AOI   = 0x80,
+};
+
+enum lis3lv02d_ff_wu_src {
+       FF_WU_SRC_XL    = 0x01,
+       FF_WU_SRC_XH    = 0x02,
+       FF_WU_SRC_YL    = 0x04,
+       FF_WU_SRC_YH    = 0x08,
+       FF_WU_SRC_ZL    = 0x10,
+       FF_WU_SRC_ZH    = 0x20,
+       FF_WU_SRC_IA    = 0x40,
+};
+
+enum lis3lv02d_dd_cfg {
+       DD_CFG_XLIE     = 0x01,
+       DD_CFG_XHIE     = 0x02,
+       DD_CFG_YLIE     = 0x04,
+       DD_CFG_YHIE     = 0x08,
+       DD_CFG_ZLIE     = 0x10,
+       DD_CFG_ZHIE     = 0x20,
+       DD_CFG_LIR      = 0x40,
+       DD_CFG_IEND     = 0x80,
+};
+
+enum lis3lv02d_dd_src {
+       DD_SRC_XL       = 0x01,
+       DD_SRC_XH       = 0x02,
+       DD_SRC_YL       = 0x04,
+       DD_SRC_YH       = 0x08,
+       DD_SRC_ZL       = 0x10,
+       DD_SRC_ZH       = 0x20,
+       DD_SRC_IA       = 0x40,
+};
+
index 3ff0285396fa1dd764a17e207ed6f266cfcb43e0..cfc1ee90f5a39d1934c686a5100a185457c2b8a6 100644 (file)
@@ -39,7 +39,8 @@
 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
 
 /* Insmod parameters */
-I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
+I2C_CLIENT_INSMOD_7(lm85b, lm85c, adm1027, adt7463, adt7468, emc6d100,
+                   emc6d102);
 
 /* The LM85 registers */
 
@@ -59,6 +60,12 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
 
 #define        LM85_REG_COMPANY                0x3e
 #define        LM85_REG_VERSTEP                0x3f
+
+#define        ADT7468_REG_CFG5                0x7c
+#define                ADT7468_OFF64           0x01
+#define        IS_ADT7468_OFF64(data)          \
+       ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
+
 /* These are the recognized values for the above regs */
 #define        LM85_COMPANY_NATIONAL           0x01
 #define        LM85_COMPANY_ANALOG_DEV         0x41
@@ -70,6 +77,8 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
 #define        LM85_VERSTEP_ADM1027            0x60
 #define        LM85_VERSTEP_ADT7463            0x62
 #define        LM85_VERSTEP_ADT7463C           0x6A
+#define        LM85_VERSTEP_ADT7468_1          0x71
+#define        LM85_VERSTEP_ADT7468_2          0x72
 #define        LM85_VERSTEP_EMC6D100_A0        0x60
 #define        LM85_VERSTEP_EMC6D100_A1        0x61
 #define        LM85_VERSTEP_EMC6D102           0x65
@@ -306,6 +315,7 @@ struct lm85_data {
        u8 vid;                 /* Register value */
        u8 vrm;                 /* VRM version */
        u32 alarms;             /* Register encoding, combined */
+       u8 cfg5;                /* Config Register 5 on ADT7468 */
        struct lm85_autofan autofan[3];
        struct lm85_zone zone[3];
 };
@@ -685,6 +695,9 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
        struct lm85_data *data = i2c_get_clientdata(client);
        long val = simple_strtol(buf, NULL, 10);
 
+       if (IS_ADT7468_OFF64(data))
+               val += 64;
+
        mutex_lock(&data->update_lock);
        data->temp_min[nr] = TEMP_TO_REG(val);
        lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
@@ -708,6 +721,9 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
        struct lm85_data *data = i2c_get_clientdata(client);
        long val = simple_strtol(buf, NULL, 10);
 
+       if (IS_ADT7468_OFF64(data))
+               val += 64;
+
        mutex_lock(&data->update_lock);
        data->temp_max[nr] = TEMP_TO_REG(val);
        lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
@@ -1163,6 +1179,10 @@ static int lm85_detect(struct i2c_client *client, int kind,
                        case LM85_VERSTEP_ADT7463C:
                                kind = adt7463;
                                break;
+                       case LM85_VERSTEP_ADT7468_1:
+                       case LM85_VERSTEP_ADT7468_2:
+                               kind = adt7468;
+                               break;
                        }
                } else if (company == LM85_COMPANY_SMSC) {
                        switch (verstep) {
@@ -1195,6 +1215,9 @@ static int lm85_detect(struct i2c_client *client, int kind,
        case adt7463:
                type_name = "adt7463";
                break;
+       case adt7468:
+               type_name = "adt7468";
+               break;
        case emc6d100:
                type_name = "emc6d100";
                break;
@@ -1246,10 +1269,11 @@ static int lm85_probe(struct i2c_client *client,
        if (err)
                goto err_kfree;
 
-       /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
+       /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
           as a sixth digital VID input rather than an analog input. */
        data->vid = lm85_read_value(client, LM85_REG_VID);
-       if (!(data->type == adt7463 && (data->vid & 0x80)))
+       if (!((data->type == adt7463 || data->type == adt7468) &&
+           (data->vid & 0x80)))
                if ((err = sysfs_create_group(&client->dev.kobj,
                                        &lm85_group_in4)))
                        goto err_remove_files;
@@ -1357,7 +1381,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                 * There are 2 additional resolution bits per channel and we
                 * have room for 4, so we shift them to the left.
                 */
-               if (data->type == adm1027 || data->type == adt7463) {
+               if (data->type == adm1027 || data->type == adt7463 ||
+                   data->type == adt7468) {
                        int ext1 = lm85_read_value(client,
                                                   ADM1027_REG_EXTEND_ADC1);
                        int ext2 =  lm85_read_value(client,
@@ -1382,16 +1407,23 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                            lm85_read_value(client, LM85_REG_FAN(i));
                }
 
-               if (!(data->type == adt7463 && (data->vid & 0x80))) {
+               if (!((data->type == adt7463 || data->type == adt7468) &&
+                   (data->vid & 0x80))) {
                        data->in[4] = lm85_read_value(client,
                                      LM85_REG_IN(4));
                }
 
+               if (data->type == adt7468)
+                       data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
+
                for (i = 0; i <= 2; ++i) {
                        data->temp[i] =
                            lm85_read_value(client, LM85_REG_TEMP(i));
                        data->pwm[i] =
                            lm85_read_value(client, LM85_REG_PWM(i));
+
+                       if (IS_ADT7468_OFF64(data))
+                               data->temp[i] -= 64;
                }
 
                data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
@@ -1446,7 +1478,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                            lm85_read_value(client, LM85_REG_FAN_MIN(i));
                }
 
-               if (!(data->type == adt7463 && (data->vid & 0x80))) {
+               if (!((data->type == adt7463 || data->type == adt7468) &&
+                   (data->vid & 0x80))) {
                        data->in_min[4] = lm85_read_value(client,
                                          LM85_REG_IN_MIN(4));
                        data->in_max[4] = lm85_read_value(client,
@@ -1481,6 +1514,13 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                            lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
                        data->zone[i].critical =
                            lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
+
+                       if (IS_ADT7468_OFF64(data)) {
+                               data->temp_min[i] -= 64;
+                               data->temp_max[i] -= 64;
+                               data->zone[i].limit -= 64;
+                               data->zone[i].critical -= 64;
+                       }
                }
 
                i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
index 4840733cd9032c48a1253a8fae8ebdea2d4c09cd..3d7f4923cd133a2216115bb18d6fb177eb93ffd1 100644 (file)
@@ -441,13 +441,13 @@ static void process_queued_ios(struct work_struct *work)
                __choose_pgpath(m);
 
        pgpath = m->current_pgpath;
-       m->pgpath_to_activate = m->current_pgpath;
 
        if ((pgpath && !m->queue_io) ||
            (!pgpath && !m->queue_if_no_path))
                must_queue = 0;
 
-       if (m->pg_init_required && !m->pg_init_in_progress) {
+       if (m->pg_init_required && !m->pg_init_in_progress && pgpath) {
+               m->pgpath_to_activate = pgpath;
                m->pg_init_count++;
                m->pg_init_required = 0;
                m->pg_init_in_progress = 1;
@@ -708,6 +708,10 @@ static int parse_hw_handler(struct arg_set *as, struct multipath *m)
                m->hw_handler_name = NULL;
                return -EINVAL;
        }
+
+       if (hw_argc > 1)
+               DMWARN("Ignoring user-specified arguments for "
+                      "hardware handler \"%s\"", m->hw_handler_name);
        consume(as, hw_argc - 1);
 
        return 0;
index 9d7b53ed75b228e05bc865571afdd424da92f483..ec43f9fa4b2acaffed0bf45f79edc5a115f36804 100644 (file)
@@ -1032,6 +1032,7 @@ static void mirror_dtr(struct dm_target *ti)
 
        del_timer_sync(&ms->timer);
        flush_workqueue(ms->kmirrord_wq);
+       flush_scheduled_work();
        dm_kcopyd_client_destroy(ms->kcopyd_client);
        destroy_workqueue(ms->kmirrord_wq);
        free_context(ms, ti, ms->nr_mirrors);
index a2d068dbe9e2669dc25290a09e8918b4b5c2f28f..9e4ef88d421e499dfb05e1697593bcbf82fefe38 100644 (file)
@@ -320,8 +320,10 @@ int __init dm_stripe_init(void)
        int r;
 
        r = dm_register_target(&stripe_target);
-       if (r < 0)
+       if (r < 0) {
                DMWARN("target registration failed");
+               return r;
+       }
 
        kstriped = create_singlethread_workqueue("kstriped");
        if (!kstriped) {
index 6963ad1484082bf5d0f8009c60aa1db18eb980c1..c99e4728ff4162ed16c4a7ec99fdc0c27c8cb35f 100644 (file)
@@ -375,7 +375,7 @@ static void start_io_acct(struct dm_io *io)
        dm_disk(md)->part0.in_flight = atomic_inc_return(&md->pending);
 }
 
-static int end_io_acct(struct dm_io *io)
+static void end_io_acct(struct dm_io *io)
 {
        struct mapped_device *md = io->md;
        struct bio *bio = io->bio;
@@ -391,7 +391,9 @@ static int end_io_acct(struct dm_io *io)
        dm_disk(md)->part0.in_flight = pending =
                atomic_dec_return(&md->pending);
 
-       return !pending;
+       /* nudge anyone waiting on suspend queue */
+       if (!pending)
+               wake_up(&md->wait);
 }
 
 /*
@@ -499,9 +501,7 @@ static void dec_pending(struct dm_io *io, int error)
                        spin_unlock_irqrestore(&io->md->pushback_lock, flags);
                }
 
-               if (end_io_acct(io))
-                       /* nudge anyone waiting on suspend queue */
-                       wake_up(&io->md->wait);
+               end_io_acct(io);
 
                if (io->error != DM_ENDIO_REQUEUE) {
                        blk_add_trace_bio(io->md->queue, io->bio,
@@ -937,16 +937,24 @@ static void dm_unplug_all(struct request_queue *q)
 
 static int dm_any_congested(void *congested_data, int bdi_bits)
 {
-       int r;
-       struct mapped_device *md = (struct mapped_device *) congested_data;
-       struct dm_table *map = dm_get_table(md);
+       int r = bdi_bits;
+       struct mapped_device *md = congested_data;
+       struct dm_table *map;
 
-       if (!map || test_bit(DMF_BLOCK_IO, &md->flags))
-               r = bdi_bits;
-       else
-               r = dm_table_any_congested(map, bdi_bits);
+       atomic_inc(&md->pending);
+
+       if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
+               map = dm_get_table(md);
+               if (map) {
+                       r = dm_table_any_congested(map, bdi_bits);
+                       dm_table_put(map);
+               }
+       }
+
+       if (!atomic_dec_return(&md->pending))
+               /* nudge anyone waiting on suspend queue */
+               wake_up(&md->wait);
 
-       dm_table_put(map);
        return r;
 }
 
index b59e47272abfc292493e65bf66a0d2fbdda56f62..3720f0e03a16906efd339b0eefb89b5454499abf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * experimental driver for simple i2c audio chips.
+ * Driver for simple i2c audio chips.
  *
  * Copyright (c) 2000 Gerd Knorr
  * based on code by:
@@ -7,6 +7,10 @@
  *   Steve VanDeBogart (vandebo@uclink.berkeley.edu)
  *   Greg Alexander (galexand@acm.org)
  *
+ * Copyright(c) 2005-2008 Mauro Carvalho Chehab
+ *     - Some cleanups, code fixes, etc
+ *     - Convert it to V4L2 API
+ *
  * This code is placed under the terms of the GNU General Public License
  *
  * OPTIONS:
@@ -30,6 +34,7 @@
 
 #include <media/tvaudio.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-chip-ident.h>
 #include <media/v4l2-i2c-drv-legacy.h>
 
@@ -58,7 +63,6 @@ typedef int  (*checkit)(struct CHIPSTATE*);
 typedef int  (*initialize)(struct CHIPSTATE*);
 typedef int  (*getmode)(struct CHIPSTATE*);
 typedef void (*setmode)(struct CHIPSTATE*, int mode);
-typedef void (*checkmode)(struct CHIPSTATE*);
 
 /* i2c command */
 typedef struct AUDIOCMD {
@@ -79,6 +83,7 @@ struct CHIPDESC {
 #define CHIP_HAS_VOLUME      1
 #define CHIP_HAS_BASSTREBLE  2
 #define CHIP_HAS_INPUTSEL    4
+#define CHIP_NEED_CHECKMODE  8
 
        /* various i2c command sequences */
        audiocmd   init;
@@ -96,23 +101,20 @@ struct CHIPDESC {
        getmode  getmode;
        setmode  setmode;
 
-       /* check / autoswitch audio after channel switches */
-       checkmode  checkmode;
-
        /* input switch register + values for v4l inputs */
        int  inputreg;
        int  inputmap[4];
        int  inputmute;
        int  inputmask;
 };
-static struct CHIPDESC chiplist[];
 
 /* current state of the chip */
 struct CHIPSTATE {
        struct i2c_client *c;
 
-       /* index into CHIPDESC array */
-       int type;
+       /* chip-specific description - should point to
+          an entry at CHIPDESC table */
+       struct CHIPDESC *desc;
 
        /* shadow register set */
        audiocmd   shadow;
@@ -152,7 +154,7 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
 {
        unsigned char buffer[2];
 
-       if (-1 == subaddr) {
+       if (subaddr < 0) {
                v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n",
                        chip->c->name, val);
                chip->shadow.bytes[1] = val;
@@ -163,6 +165,13 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
                        return -1;
                }
        } else {
+               if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
+                       v4l_info(chip->c,
+                               "Tried to access a non-existent register: %d\n",
+                               subaddr);
+                       return -EINVAL;
+               }
+
                v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n",
                        chip->c->name, subaddr, val);
                chip->shadow.bytes[subaddr+1] = val;
@@ -177,12 +186,20 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
        return 0;
 }
 
-static int chip_write_masked(struct CHIPSTATE *chip, int subaddr, int val, int mask)
+static int chip_write_masked(struct CHIPSTATE *chip,
+                            int subaddr, int val, int mask)
 {
        if (mask != 0) {
-               if (-1 == subaddr) {
+               if (subaddr < 0) {
                        val = (chip->shadow.bytes[1] & ~mask) | (val & mask);
                } else {
+                       if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
+                               v4l_info(chip->c,
+                                       "Tried to access a non-existent register: %d\n",
+                                       subaddr);
+                               return -EINVAL;
+                       }
+
                        val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask);
                }
        }
@@ -228,6 +245,15 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
        if (0 == cmd->count)
                return 0;
 
+       if (cmd->count + cmd->bytes[0] - 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
+               v4l_info(chip->c,
+                        "Tried to access a non-existent register range: %d to %d\n",
+                        cmd->bytes[0] + 1, cmd->bytes[0] + cmd->count - 1);
+               return -EINVAL;
+       }
+
+       /* FIXME: it seems that the shadow bytes are wrong bellow !*/
+
        /* update our shadow register set; print bytes if (debug > 0) */
        v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:",
                chip->c->name, name,cmd->bytes[0]);
@@ -263,7 +289,8 @@ static void chip_thread_wake(unsigned long data)
 static int chip_thread(void *data)
 {
        struct CHIPSTATE *chip = data;
-       struct CHIPDESC  *desc = chiplist + chip->type;
+       struct CHIPDESC  *desc = chip->desc;
+       int mode;
 
        v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name);
        set_freezable();
@@ -282,7 +309,26 @@ static int chip_thread(void *data)
                        continue;
 
                /* have a look what's going on */
-               desc->checkmode(chip);
+               mode = desc->getmode(chip);
+               if (mode == chip->prevmode)
+                       continue;
+
+               /* chip detected a new audio mode - set it */
+               v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n",
+                       chip->c->name);
+
+               chip->prevmode = mode;
+
+               if (mode & V4L2_TUNER_MODE_STEREO)
+                       desc->setmode(chip, V4L2_TUNER_MODE_STEREO);
+               if (mode & V4L2_TUNER_MODE_LANG1_LANG2)
+                       desc->setmode(chip, V4L2_TUNER_MODE_STEREO);
+               else if (mode & V4L2_TUNER_MODE_LANG1)
+                       desc->setmode(chip, V4L2_TUNER_MODE_LANG1);
+               else if (mode & V4L2_TUNER_MODE_LANG2)
+                       desc->setmode(chip, V4L2_TUNER_MODE_LANG2);
+               else
+                       desc->setmode(chip, V4L2_TUNER_MODE_MONO);
 
                /* schedule next check */
                mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
@@ -292,29 +338,6 @@ static int chip_thread(void *data)
        return 0;
 }
 
-static void generic_checkmode(struct CHIPSTATE *chip)
-{
-       struct CHIPDESC  *desc = chiplist + chip->type;
-       int mode = desc->getmode(chip);
-
-       if (mode == chip->prevmode)
-       return;
-
-       v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n", chip->c->name);
-       chip->prevmode = mode;
-
-       if (mode & V4L2_TUNER_MODE_STEREO)
-               desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
-       if (mode & V4L2_TUNER_MODE_LANG1_LANG2)
-               desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
-       else if (mode & V4L2_TUNER_MODE_LANG1)
-               desc->setmode(chip,V4L2_TUNER_MODE_LANG1);
-       else if (mode & V4L2_TUNER_MODE_LANG2)
-               desc->setmode(chip,V4L2_TUNER_MODE_LANG2);
-       else
-               desc->setmode(chip,V4L2_TUNER_MODE_MONO);
-}
-
 /* ---------------------------------------------------------------------- */
 /* audio chip descriptions - defines+functions for tda9840                */
 
@@ -777,7 +800,7 @@ static struct tda9874a_MODES {
        char *name;
        audiocmd cmd;
 } tda9874a_modelist[9] = {
-  {    "A2, B/G",
+  {    "A2, B/G", /* default */
        { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x77,0xA0,0x00, 0x00,0x00 }} },
   {    "A2, M (Korea)",
        { 9, { TDA9874A_C1FRA, 0x5D,0xC0,0x00, 0x62,0x6A,0xAA, 0x20,0x22 }} },
@@ -791,7 +814,7 @@ static struct tda9874a_MODES {
        { 9, { TDA9874A_C1FRA, 0x7D,0x00,0x00, 0x88,0x8A,0xAA, 0x08,0x33 }} },
   {    "NICAM, B/G",
        { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x79,0xEA,0xAA, 0x08,0x33 }} },
-  {    "NICAM, D/K", /* default */
+  {    "NICAM, D/K",
        { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x08,0x33 }} },
   {    "NICAM, L",
        { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x09,0x33 }} }
@@ -981,7 +1004,7 @@ static int tda9874a_initialize(struct CHIPSTATE *chip)
 {
        if (tda9874a_SIF > 2)
                tda9874a_SIF = 1;
-       if (tda9874a_STD > 8)
+       if (tda9874a_STD >= ARRAY_SIZE(tda9874a_modelist))
                tda9874a_STD = 0;
        if(tda9874a_AMSEL > 1)
                tda9874a_AMSEL = 0;
@@ -1089,7 +1112,7 @@ static int tda8425_shift12(int val) { return (val >> 12) | 0xf0; }
 
 static int tda8425_initialize(struct CHIPSTATE *chip)
 {
-       struct CHIPDESC *desc = chiplist + chip->type;
+       struct CHIPDESC *desc = chip->desc;
        int inputmap[4] = { /* tuner    */ TDA8425_S1_CH2, /* radio  */ TDA8425_S1_CH1,
                            /* extern   */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF};
 
@@ -1259,27 +1282,28 @@ static struct CHIPDESC chiplist[] = {
                .addr_lo    = I2C_ADDR_TDA9840 >> 1,
                .addr_hi    = I2C_ADDR_TDA9840 >> 1,
                .registers  = 5,
+               .flags      = CHIP_NEED_CHECKMODE,
 
+               /* callbacks */
                .checkit    = tda9840_checkit,
                .getmode    = tda9840_getmode,
                .setmode    = tda9840_setmode,
-               .checkmode  = generic_checkmode,
 
                .init       = { 2, { TDA9840_TEST, TDA9840_TEST_INT1SN
                                /* ,TDA9840_SW, TDA9840_MONO */} }
        },
        {
                .name       = "tda9873h",
-               .checkit    = tda9873_checkit,
                .insmodopt  = &tda9873,
                .addr_lo    = I2C_ADDR_TDA985x_L >> 1,
                .addr_hi    = I2C_ADDR_TDA985x_H >> 1,
                .registers  = 3,
-               .flags      = CHIP_HAS_INPUTSEL,
+               .flags      = CHIP_HAS_INPUTSEL | CHIP_NEED_CHECKMODE,
 
+               /* callbacks */
+               .checkit    = tda9873_checkit,
                .getmode    = tda9873_getmode,
                .setmode    = tda9873_setmode,
-               .checkmode  = generic_checkmode,
 
                .init       = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } },
                .inputreg   = TDA9873_SW,
@@ -1290,15 +1314,16 @@ static struct CHIPDESC chiplist[] = {
        },
        {
                .name       = "tda9874h/a",
-               .checkit    = tda9874a_checkit,
-               .initialize = tda9874a_initialize,
                .insmodopt  = &tda9874a,
                .addr_lo    = I2C_ADDR_TDA9874 >> 1,
                .addr_hi    = I2C_ADDR_TDA9874 >> 1,
+               .flags      = CHIP_NEED_CHECKMODE,
 
+               /* callbacks */
+               .initialize = tda9874a_initialize,
+               .checkit    = tda9874a_checkit,
                .getmode    = tda9874a_getmode,
                .setmode    = tda9874a_setmode,
-               .checkmode  = generic_checkmode,
        },
        {
                .name       = "tda9850",
@@ -1324,10 +1349,11 @@ static struct CHIPDESC chiplist[] = {
                .rightreg   = TDA9855_VR,
                .bassreg    = TDA9855_BA,
                .treblereg  = TDA9855_TR,
+
+               /* callbacks */
                .volfunc    = tda9855_volume,
                .bassfunc   = tda9855_bass,
                .treblefunc = tda9855_treble,
-
                .getmode    = tda985x_getmode,
                .setmode    = tda985x_setmode,
 
@@ -1348,6 +1374,8 @@ static struct CHIPDESC chiplist[] = {
                .rightreg   = TEA6300_VL,
                .bassreg    = TEA6300_BA,
                .treblereg  = TEA6300_TR,
+
+               /* callbacks */
                .volfunc    = tea6300_shift10,
                .bassfunc   = tea6300_shift12,
                .treblefunc = tea6300_shift12,
@@ -1358,7 +1386,6 @@ static struct CHIPDESC chiplist[] = {
        },
        {
                .name       = "tea6320",
-               .initialize = tea6320_initialize,
                .insmodopt  = &tea6320,
                .addr_lo    = I2C_ADDR_TEA6300 >> 1,
                .addr_hi    = I2C_ADDR_TEA6300 >> 1,
@@ -1369,6 +1396,9 @@ static struct CHIPDESC chiplist[] = {
                .rightreg   = TEA6320_V,
                .bassreg    = TEA6320_BA,
                .treblereg  = TEA6320_TR,
+
+               /* callbacks */
+               .initialize = tea6320_initialize,
                .volfunc    = tea6320_volume,
                .bassfunc   = tea6320_shift11,
                .treblefunc = tea6320_shift11,
@@ -1401,16 +1431,18 @@ static struct CHIPDESC chiplist[] = {
                .rightreg   = TDA8425_VR,
                .bassreg    = TDA8425_BA,
                .treblereg  = TDA8425_TR,
+
+               /* callbacks */
+               .initialize = tda8425_initialize,
                .volfunc    = tda8425_shift10,
                .bassfunc   = tda8425_shift12,
                .treblefunc = tda8425_shift12,
+               .setmode    = tda8425_setmode,
 
                .inputreg   = TDA8425_S1,
                .inputmap   = { TDA8425_S1_CH1, TDA8425_S1_CH1, TDA8425_S1_CH1 },
                .inputmute  = TDA8425_S1_OFF,
 
-               .setmode    = tda8425_setmode,
-               .initialize = tda8425_initialize,
        },
        {
                .name       = "pic16c54 (PV951)",
@@ -1434,10 +1466,11 @@ static struct CHIPDESC chiplist[] = {
                .addr_lo    = I2C_ADDR_TDA9840 >> 1,
                .addr_hi    = I2C_ADDR_TDA9840 >> 1,
                .registers  = 2,
+               .flags      = CHIP_NEED_CHECKMODE,
 
+               /* callbacks */
                .getmode    = ta8874z_getmode,
                .setmode    = ta8874z_setmode,
-               .checkmode  = generic_checkmode,
 
                .init       = {2, { TA8874Z_MONO_SET, TA8874Z_SEPARATION_DEFAULT}},
        },
@@ -1481,6 +1514,7 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
        }
        if (desc->name == NULL) {
                v4l_dbg(1, debug, client, "no matching chip description found\n");
+               kfree(chip);
                return -EIO;
        }
        v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name);
@@ -1494,7 +1528,7 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
        /* fill required data structures */
        if (!id)
                strlcpy(client->name, desc->name, I2C_NAME_SIZE);
-       chip->type = desc-chiplist;
+       chip->desc = desc;
        chip->shadow.count = desc->registers+1;
        chip->prevmode = -1;
        chip->audmode = V4L2_TUNER_MODE_LANG1;
@@ -1506,20 +1540,49 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
                chip_cmd(chip,"init",&desc->init);
 
        if (desc->flags & CHIP_HAS_VOLUME) {
-               chip->left   = desc->leftinit   ? desc->leftinit   : 65535;
-               chip->right  = desc->rightinit  ? desc->rightinit  : 65535;
-               chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
-               chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
+               if (!desc->volfunc) {
+                       /* This shouldn't be happen. Warn user, but keep working
+                          without volume controls
+                        */
+                       v4l_info(chip->c, "volume callback undefined!\n");
+                       desc->flags &= ~CHIP_HAS_VOLUME;
+               } else {
+                       chip->left  = desc->leftinit  ? desc->leftinit  : 65535;
+                       chip->right = desc->rightinit ? desc->rightinit : 65535;
+                       chip_write(chip, desc->leftreg,
+                                  desc->volfunc(chip->left));
+                       chip_write(chip, desc->rightreg,
+                                  desc->volfunc(chip->right));
+               }
        }
        if (desc->flags & CHIP_HAS_BASSTREBLE) {
-               chip->treble = desc->trebleinit ? desc->trebleinit : 32768;
-               chip->bass   = desc->bassinit   ? desc->bassinit   : 32768;
-               chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
-               chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
+               if (!desc->bassfunc || !desc->treblefunc) {
+                       /* This shouldn't be happen. Warn user, but keep working
+                          without bass/treble controls
+                        */
+                       v4l_info(chip->c, "bass/treble callbacks undefined!\n");
+                       desc->flags &= ~CHIP_HAS_BASSTREBLE;
+               } else {
+                       chip->treble = desc->trebleinit ?
+                                               desc->trebleinit : 32768;
+                       chip->bass   = desc->bassinit   ?
+                                               desc->bassinit   : 32768;
+                       chip_write(chip, desc->bassreg,
+                                  desc->bassfunc(chip->bass));
+                       chip_write(chip, desc->treblereg,
+                                  desc->treblefunc(chip->treble));
+               }
        }
 
        chip->thread = NULL;
-       if (desc->checkmode) {
+       if (desc->flags & CHIP_NEED_CHECKMODE) {
+               if (!desc->getmode || !desc->setmode) {
+                       /* This shouldn't be happen. Warn user, but keep working
+                          without kthread
+                        */
+                       v4l_info(chip->c, "set/get mode callbacks undefined!\n");
+                       return 0;
+               }
                /* start async thread */
                init_timer(&chip->wt);
                chip->wt.function = chip_thread_wake;
@@ -1552,7 +1615,7 @@ static int chip_remove(struct i2c_client *client)
 static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
                            struct v4l2_control *ctrl)
 {
-       struct CHIPDESC *desc = chiplist + chip->type;
+       struct CHIPDESC *desc = chip->desc;
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -1576,13 +1639,13 @@ static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
                return 0;
        }
        case V4L2_CID_AUDIO_BASS:
-               if (desc->flags & CHIP_HAS_BASSTREBLE)
+               if (!(desc->flags & CHIP_HAS_BASSTREBLE))
                        break;
                ctrl->value = chip->bass;
                return 0;
        case V4L2_CID_AUDIO_TREBLE:
-               if (desc->flags & CHIP_HAS_BASSTREBLE)
-                       return -EINVAL;
+               if (!(desc->flags & CHIP_HAS_BASSTREBLE))
+                       break;
                ctrl->value = chip->treble;
                return 0;
        }
@@ -1592,7 +1655,7 @@ static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
 static int tvaudio_set_ctrl(struct CHIPSTATE *chip,
                            struct v4l2_control *ctrl)
 {
-       struct CHIPDESC *desc = chiplist + chip->type;
+       struct CHIPDESC *desc = chip->desc;
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -1642,16 +1705,15 @@ static int tvaudio_set_ctrl(struct CHIPSTATE *chip,
                return 0;
        }
        case V4L2_CID_AUDIO_BASS:
-               if (desc->flags & CHIP_HAS_BASSTREBLE)
+               if (!(desc->flags & CHIP_HAS_BASSTREBLE))
                        break;
                chip->bass = ctrl->value;
                chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
 
                return 0;
        case V4L2_CID_AUDIO_TREBLE:
-               if (desc->flags & CHIP_HAS_BASSTREBLE)
-                       return -EINVAL;
-
+               if (!(desc->flags & CHIP_HAS_BASSTREBLE))
+                       break;
                chip->treble = ctrl->value;
                chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
 
@@ -1668,9 +1730,12 @@ static int chip_command(struct i2c_client *client,
                        unsigned int cmd, void *arg)
 {
        struct CHIPSTATE *chip = i2c_get_clientdata(client);
-       struct CHIPDESC  *desc = chiplist + chip->type;
+       struct CHIPDESC  *desc = chip->desc;
 
-       v4l_dbg(1, debug, chip->c, "%s: chip_command 0x%x\n", chip->c->name, cmd);
+       if (debug > 0) {
+               v4l_i2c_print_ioctl(chip->c, cmd);
+               printk("\n");
+       }
 
        switch (cmd) {
        case AUDC_SET_RADIO:
@@ -1695,7 +1760,7 @@ static int chip_command(struct i2c_client *client,
                                break;
                        case V4L2_CID_AUDIO_BASS:
                        case V4L2_CID_AUDIO_TREBLE:
-                               if (desc->flags & CHIP_HAS_BASSTREBLE)
+                               if (!(desc->flags & CHIP_HAS_BASSTREBLE))
                                        return -EINVAL;
                                break;
                        default:
@@ -1792,12 +1857,20 @@ static int chip_command(struct i2c_client *client,
                break;
        case VIDIOC_S_FREQUENCY:
                chip->mode = 0; /* automatic */
-               if (desc->checkmode && desc->setmode) {
+
+               /* For chips that provide getmode and setmode, and doesn't
+                  automatically follows the stereo carrier, a kthread is
+                  created to set the audio standard. In this case, when then
+                  the video channel is changed, tvaudio starts on MONO mode.
+                  After waiting for 2 seconds, the kernel thread is called,
+                  to follow whatever audio standard is pointed by the
+                  audio carrier.
+                */
+               if (chip->thread) {
                        desc->setmode(chip,V4L2_TUNER_MODE_MONO);
                        if (chip->prevmode != V4L2_TUNER_MODE_MONO)
                                chip->prevmode = -1; /* reset previous mode */
                        mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
-                       /* the thread will call checkmode() later */
                }
                break;
 
@@ -1836,9 +1909,3 @@ static struct v4l2_i2c_driver_data v4l2_i2c_data = {
        .legacy_probe = chip_legacy_probe,
        .id_table = chip_id,
 };
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
index 4494ad27cbf135b0156032d7224b989fe02b0723..fee7304102af8158ca3882bccb854f0f6fcb2bbe 100644 (file)
@@ -227,6 +227,16 @@ config HP_WMI
          To compile this driver as a module, choose M here: the module will
          be called hp-wmi.
 
+config ICS932S401
+       tristate "Integrated Circuits ICS932S401"
+       depends on I2C && EXPERIMENTAL
+       help
+         If you say yes here you get support for the Integrated Circuits
+         ICS932S401 clock control chips.
+
+         This driver can also be built as a module. If so, the module
+         will be called ics932s401.
+
 config MSI_LAPTOP
         tristate "MSI Laptop Extras"
         depends on X86
@@ -488,4 +498,6 @@ config SGI_GRU_DEBUG
        This option enables addition debugging code for the SGI GRU driver. If
        you are unsure, say N.
 
+source "drivers/misc/c2port/Kconfig"
+
 endif # MISC_DEVICES
index 909e2468cdc974be5e4ffc7c3e85affc6f6129c6..817f7f5ab3bd2c21476033c195dbba93bf58d05b 100644 (file)
@@ -14,6 +14,7 @@ obj-$(CONFIG_ATMEL_PWM)               += atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)                += atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)      += atmel_tclib.o
 obj-$(CONFIG_HP_WMI)           += hp-wmi.o
+obj-$(CONFIG_ICS932S401)       += ics932s401.o
 obj-$(CONFIG_TC1100_WMI)       += tc1100-wmi.o
 obj-$(CONFIG_LKDTM)            += lkdtm.o
 obj-$(CONFIG_TIFM_CORE)        += tifm_core.o
@@ -31,3 +32,4 @@ obj-$(CONFIG_KGDB_TESTS)      += kgdbts.o
 obj-$(CONFIG_SGI_XP)           += sgi-xp/
 obj-$(CONFIG_SGI_GRU)          += sgi-gru/
 obj-$(CONFIG_HP_ILO)           += hpilo.o
+obj-$(CONFIG_C2PORT)           += c2port/
diff --git a/drivers/misc/c2port/Kconfig b/drivers/misc/c2port/Kconfig
new file mode 100644 (file)
index 0000000..e46af9a
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# C2 port devices
+#
+
+menuconfig C2PORT
+       tristate "Silicon Labs C2 port support (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       default no
+       help
+         This option enables support for Silicon Labs C2 port used to
+         program Silicon micro controller chips (and other 8051 compatible).
+
+         If your board have no such micro controllers you don't need this
+         interface at all.
+
+         To compile this driver as a module, choose M here: the module will
+         be called c2port_core. Note that you also need a client module
+         usually called c2port-*.
+
+         If you are not sure, say N here.
+
+if C2PORT
+
+config C2PORT_DURAMAR_2150
+       tristate "C2 port support for Eurotech's Duramar 2150 (EXPERIMENTAL)"
+       depends on X86 && C2PORT
+       default no
+       help
+         This option enables C2 support for the Eurotech's Duramar 2150
+         on board micro controller.
+
+         To compile this driver as a module, choose M here: the module will
+         be called c2port-duramar2150.
+
+endif # C2PORT
diff --git a/drivers/misc/c2port/Makefile b/drivers/misc/c2port/Makefile
new file mode 100644 (file)
index 0000000..3b2cf43
--- /dev/null
@@ -0,0 +1,3 @@
+obj-$(CONFIG_C2PORT)           += core.o
+
+obj-$(CONFIG_C2PORT_DURAMAR_2150)      += c2port-duramar2150.o
diff --git a/drivers/misc/c2port/c2port-duramar2150.c b/drivers/misc/c2port/c2port-duramar2150.c
new file mode 100644 (file)
index 0000000..338dcc1
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ *  Silicon Labs C2 port Linux support for Eurotech Duramar 2150
+ *
+ *  Copyright (c) 2008 Rodolfo Giometti <giometti@linux.it>
+ *  Copyright (c) 2008 Eurotech S.p.A. <info@eurotech.it>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation
+ */
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/c2port.h>
+
+#define DATA_PORT      0x325
+#define DIR_PORT       0x326
+#define    C2D            (1 << 0)
+#define    C2CK                   (1 << 1)
+
+static DEFINE_MUTEX(update_lock);
+
+/*
+ * C2 port operations
+ */
+
+static void duramar2150_c2port_access(struct c2port_device *dev, int status)
+{
+       u8 v;
+
+       mutex_lock(&update_lock);
+
+       v = inb(DIR_PORT);
+
+       /* 0 = input, 1 = output */
+       if (status)
+               outb(v | (C2D | C2CK), DIR_PORT);
+       else
+               /* When access is "off" is important that both lines are set
+                * as inputs or hi-impedence */
+               outb(v & ~(C2D | C2CK), DIR_PORT);
+
+       mutex_unlock(&update_lock);
+}
+
+static void duramar2150_c2port_c2d_dir(struct c2port_device *dev, int dir)
+{
+       u8 v;
+
+       mutex_lock(&update_lock);
+
+       v = inb(DIR_PORT);
+
+       if (dir)
+               outb(v & ~C2D, DIR_PORT);
+       else
+               outb(v | C2D, DIR_PORT);
+
+       mutex_unlock(&update_lock);
+}
+
+static int duramar2150_c2port_c2d_get(struct c2port_device *dev)
+{
+       return inb(DATA_PORT) & C2D;
+}
+
+static void duramar2150_c2port_c2d_set(struct c2port_device *dev, int status)
+{
+       u8 v;
+
+       mutex_lock(&update_lock);
+
+       v = inb(DATA_PORT);
+
+       if (status)
+               outb(v | C2D, DATA_PORT);
+       else
+               outb(v & ~C2D, DATA_PORT);
+
+       mutex_unlock(&update_lock);
+}
+
+static void duramar2150_c2port_c2ck_set(struct c2port_device *dev, int status)
+{
+       u8 v;
+
+       mutex_lock(&update_lock);
+
+       v = inb(DATA_PORT);
+
+       if (status)
+               outb(v | C2CK, DATA_PORT);
+       else
+               outb(v & ~C2CK, DATA_PORT);
+
+       mutex_unlock(&update_lock);
+}
+
+static struct c2port_ops duramar2150_c2port_ops = {
+       .block_size     = 512,  /* bytes */
+       .blocks_num     = 30,   /* total flash size: 15360 bytes */
+
+       .access         = duramar2150_c2port_access,
+       .c2d_dir        = duramar2150_c2port_c2d_dir,
+       .c2d_get        = duramar2150_c2port_c2d_get,
+       .c2d_set        = duramar2150_c2port_c2d_set,
+       .c2ck_set       = duramar2150_c2port_c2ck_set,
+};
+
+static struct c2port_device *duramar2150_c2port_dev;
+
+/*
+ * Module stuff
+ */
+
+static int __init duramar2150_c2port_init(void)
+{
+       struct resource *res;
+       int ret = 0;
+
+       res = request_region(0x325, 2, "c2port");
+       if (!res)
+               return -EBUSY;
+
+       duramar2150_c2port_dev = c2port_device_register("uc",
+                                       &duramar2150_c2port_ops, NULL);
+       if (!duramar2150_c2port_dev) {
+               ret = -ENODEV;
+               goto free_region;
+       }
+
+       return 0;
+
+free_region:
+       release_region(0x325, 2);
+       return ret;
+}
+
+static void __exit duramar2150_c2port_exit(void)
+{
+       /* Setup the GPIOs as input by default (access = 0) */
+       duramar2150_c2port_access(duramar2150_c2port_dev, 0);
+
+       c2port_device_unregister(duramar2150_c2port_dev);
+
+       release_region(0x325, 2);
+}
+
+module_init(duramar2150_c2port_init);
+module_exit(duramar2150_c2port_exit);
+
+MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
+MODULE_DESCRIPTION("Silicon Labs C2 port Linux support for Duramar 2150");
+MODULE_LICENSE("GPL");
diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
new file mode 100644 (file)
index 0000000..0207dd5
--- /dev/null
@@ -0,0 +1,1003 @@
+/*
+ *  Silicon Labs C2 port core Linux support
+ *
+ *  Copyright (c) 2007 Rodolfo Giometti <giometti@linux.it>
+ *  Copyright (c) 2007 Eurotech S.p.A. <info@eurotech.it>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/delay.h>
+#include <linux/idr.h>
+#include <linux/sched.h>
+
+#include <linux/c2port.h>
+
+#define DRIVER_NAME             "c2port"
+#define DRIVER_VERSION          "0.51.0"
+
+static DEFINE_SPINLOCK(c2port_idr_lock);
+static DEFINE_IDR(c2port_idr);
+
+/*
+ * Local variables
+ */
+
+static struct class *c2port_class;
+
+/*
+ * C2 registers & commands defines
+ */
+
+/* C2 registers */
+#define C2PORT_DEVICEID                0x00
+#define C2PORT_REVID           0x01
+#define C2PORT_FPCTL           0x02
+#define C2PORT_FPDAT           0xB4
+
+/* C2 interface commands */
+#define C2PORT_GET_VERSION     0x01
+#define C2PORT_DEVICE_ERASE    0x03
+#define C2PORT_BLOCK_READ      0x06
+#define C2PORT_BLOCK_WRITE     0x07
+#define C2PORT_PAGE_ERASE      0x08
+
+/* C2 status return codes */
+#define C2PORT_INVALID_COMMAND 0x00
+#define C2PORT_COMMAND_FAILED  0x02
+#define C2PORT_COMMAND_OK      0x0d
+
+/*
+ * C2 port low level signal managements
+ */
+
+static void c2port_reset(struct c2port_device *dev)
+{
+       struct c2port_ops *ops = dev->ops;
+
+       /* To reset the device we have to keep clock line low for at least
+        * 20us.
+        */
+       local_irq_disable();
+       ops->c2ck_set(dev, 0);
+       udelay(25);
+       ops->c2ck_set(dev, 1);
+       local_irq_enable();
+
+       udelay(1);
+}
+
+static void c2port_strobe_ck(struct c2port_device *dev)
+{
+       struct c2port_ops *ops = dev->ops;
+
+       /* During hi-low-hi transition we disable local IRQs to avoid
+        * interructions since C2 port specification says that it must be
+        * shorter than 5us, otherwise the microcontroller may consider
+        * it as a reset signal!
+        */
+       local_irq_disable();
+       ops->c2ck_set(dev, 0);
+       udelay(1);
+       ops->c2ck_set(dev, 1);
+       local_irq_enable();
+
+       udelay(1);
+}
+
+/*
+ * C2 port basic functions
+ */
+
+static void c2port_write_ar(struct c2port_device *dev, u8 addr)
+{
+       struct c2port_ops *ops = dev->ops;
+       int i;
+
+       /* START field */
+       c2port_strobe_ck(dev);
+
+       /* INS field (11b, LSB first) */
+       ops->c2d_dir(dev, 0);
+       ops->c2d_set(dev, 1);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 1);
+       c2port_strobe_ck(dev);
+
+       /* ADDRESS field */
+       for (i = 0; i < 8; i++) {
+               ops->c2d_set(dev, addr & 0x01);
+               c2port_strobe_ck(dev);
+
+               addr >>= 1;
+       }
+
+       /* STOP field */
+       ops->c2d_dir(dev, 1);
+       c2port_strobe_ck(dev);
+}
+
+static int c2port_read_ar(struct c2port_device *dev, u8 *addr)
+{
+       struct c2port_ops *ops = dev->ops;
+       int i;
+
+       /* START field */
+       c2port_strobe_ck(dev);
+
+       /* INS field (10b, LSB first) */
+       ops->c2d_dir(dev, 0);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 1);
+       c2port_strobe_ck(dev);
+
+       /* ADDRESS field */
+       ops->c2d_dir(dev, 1);
+       *addr = 0;
+       for (i = 0; i < 8; i++) {
+               *addr >>= 1;    /* shift in 8-bit ADDRESS field LSB first */
+
+               c2port_strobe_ck(dev);
+               if (ops->c2d_get(dev))
+                       *addr |= 0x80;
+       }
+
+       /* STOP field */
+       c2port_strobe_ck(dev);
+
+       return 0;
+}
+
+static int c2port_write_dr(struct c2port_device *dev, u8 data)
+{
+       struct c2port_ops *ops = dev->ops;
+       int timeout, i;
+
+       /* START field */
+       c2port_strobe_ck(dev);
+
+       /* INS field (01b, LSB first) */
+       ops->c2d_dir(dev, 0);
+       ops->c2d_set(dev, 1);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+
+       /* LENGTH field (00b, LSB first -> 1 byte) */
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+
+       /* DATA field */
+       for (i = 0; i < 8; i++) {
+               ops->c2d_set(dev, data & 0x01);
+               c2port_strobe_ck(dev);
+
+               data >>= 1;
+       }
+
+       /* WAIT field */
+       ops->c2d_dir(dev, 1);
+       timeout = 20;
+       do {
+               c2port_strobe_ck(dev);
+               if (ops->c2d_get(dev))
+                       break;
+
+               udelay(1);
+       } while (--timeout > 0);
+       if (timeout == 0)
+               return -EIO;
+
+       /* STOP field */
+       c2port_strobe_ck(dev);
+
+       return 0;
+}
+
+static int c2port_read_dr(struct c2port_device *dev, u8 *data)
+{
+       struct c2port_ops *ops = dev->ops;
+       int timeout, i;
+
+       /* START field */
+       c2port_strobe_ck(dev);
+
+       /* INS field (00b, LSB first) */
+       ops->c2d_dir(dev, 0);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+
+       /* LENGTH field (00b, LSB first -> 1 byte) */
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+       ops->c2d_set(dev, 0);
+       c2port_strobe_ck(dev);
+
+       /* WAIT field */
+       ops->c2d_dir(dev, 1);
+       timeout = 20;
+       do {
+               c2port_strobe_ck(dev);
+               if (ops->c2d_get(dev))
+                       break;
+
+               udelay(1);
+       } while (--timeout > 0);
+       if (timeout == 0)
+               return -EIO;
+
+       /* DATA field */
+       *data = 0;
+       for (i = 0; i < 8; i++) {
+               *data >>= 1;    /* shift in 8-bit DATA field LSB first */
+
+               c2port_strobe_ck(dev);
+               if (ops->c2d_get(dev))
+                       *data |= 0x80;
+       }
+
+       /* STOP field */
+       c2port_strobe_ck(dev);
+
+       return 0;
+}
+
+static int c2port_poll_in_busy(struct c2port_device *dev)
+{
+       u8 addr;
+       int ret, timeout = 20;
+
+       do {
+               ret = (c2port_read_ar(dev, &addr));
+               if (ret < 0)
+                       return -EIO;
+
+               if (!(addr & 0x02))
+                       break;
+
+               udelay(1);
+       } while (--timeout > 0);
+       if (timeout == 0)
+               return -EIO;
+
+       return 0;
+}
+
+static int c2port_poll_out_ready(struct c2port_device *dev)
+{
+       u8 addr;
+       int ret, timeout = 10000; /* erase flash needs long time... */
+
+       do {
+               ret = (c2port_read_ar(dev, &addr));
+               if (ret < 0)
+                       return -EIO;
+
+               if (addr & 0x01)
+                       break;
+
+               udelay(1);
+       } while (--timeout > 0);
+       if (timeout == 0)
+               return -EIO;
+
+       return 0;
+}
+
+/*
+ * sysfs methods
+ */
+
+static ssize_t c2port_show_name(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%s\n", c2dev->name);
+}
+
+static ssize_t c2port_show_flash_blocks_num(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       struct c2port_ops *ops = c2dev->ops;
+
+       return sprintf(buf, "%d\n", ops->blocks_num);
+}
+
+static ssize_t c2port_show_flash_block_size(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       struct c2port_ops *ops = c2dev->ops;
+
+       return sprintf(buf, "%d\n", ops->block_size);
+}
+
+static ssize_t c2port_show_flash_size(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       struct c2port_ops *ops = c2dev->ops;
+
+       return sprintf(buf, "%d\n", ops->blocks_num * ops->block_size);
+}
+
+static ssize_t c2port_show_access(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%d\n", c2dev->access);
+}
+
+static ssize_t c2port_store_access(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       struct c2port_ops *ops = c2dev->ops;
+       int status, ret;
+
+       ret = sscanf(buf, "%d", &status);
+       if (ret != 1)
+               return -EINVAL;
+
+       mutex_lock(&c2dev->mutex);
+
+       c2dev->access = !!status;
+
+       /* If access is "on" clock should be HIGH _before_ setting the line
+        * as output and data line should be set as INPUT anyway */
+       if (c2dev->access)
+               ops->c2ck_set(c2dev, 1);
+       ops->access(c2dev, c2dev->access);
+       if (c2dev->access)
+               ops->c2d_dir(c2dev, 1);
+
+       mutex_unlock(&c2dev->mutex);
+
+       return count;
+}
+
+static ssize_t c2port_store_reset(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+
+       /* Check the device access status */
+       if (!c2dev->access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+
+       c2port_reset(c2dev);
+       c2dev->flash_access = 0;
+
+       mutex_unlock(&c2dev->mutex);
+
+       return count;
+}
+
+static ssize_t __c2port_show_dev_id(struct c2port_device *dev, char *buf)
+{
+       u8 data;
+       int ret;
+
+       /* Select DEVICEID register for C2 data register accesses */
+       c2port_write_ar(dev, C2PORT_DEVICEID);
+
+       /* Read and return the device ID register */
+       ret = c2port_read_dr(dev, &data);
+       if (ret < 0)
+               return ret;
+
+       return sprintf(buf, "%d\n", data);
+}
+
+static ssize_t c2port_show_dev_id(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       ssize_t ret;
+
+       /* Check the device access status */
+       if (!c2dev->access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_show_dev_id(c2dev, buf);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0)
+               dev_err(dev, "cannot read from %s\n", c2dev->name);
+
+       return ret;
+}
+
+static ssize_t __c2port_show_rev_id(struct c2port_device *dev, char *buf)
+{
+       u8 data;
+       int ret;
+
+       /* Select REVID register for C2 data register accesses */
+       c2port_write_ar(dev, C2PORT_REVID);
+
+       /* Read and return the revision ID register */
+       ret = c2port_read_dr(dev, &data);
+       if (ret < 0)
+               return ret;
+
+       return sprintf(buf, "%d\n", data);
+}
+
+static ssize_t c2port_show_rev_id(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       ssize_t ret;
+
+       /* Check the device access status */
+       if (!c2dev->access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_show_rev_id(c2dev, buf);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0)
+               dev_err(c2dev->dev, "cannot read from %s\n", c2dev->name);
+
+       return ret;
+}
+
+static ssize_t c2port_show_flash_access(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%d\n", c2dev->flash_access);
+}
+
+static ssize_t __c2port_store_flash_access(struct c2port_device *dev,
+                                               int status)
+{
+       int ret;
+
+       /* Check the device access status */
+       if (!dev->access)
+               return -EBUSY;
+
+       dev->flash_access = !!status;
+
+       /* If flash_access is off we have nothing to do... */
+       if (dev->flash_access == 0)
+               return 0;
+
+       /* Target the C2 flash programming control register for C2 data
+        * register access */
+       c2port_write_ar(dev, C2PORT_FPCTL);
+
+       /* Write the first keycode to enable C2 Flash programming */
+       ret = c2port_write_dr(dev, 0x02);
+       if (ret < 0)
+               return ret;
+
+       /* Write the second keycode to enable C2 Flash programming */
+       ret = c2port_write_dr(dev, 0x01);
+       if (ret < 0)
+               return ret;
+
+       /* Delay for at least 20ms to ensure the target is ready for
+        * C2 flash programming */
+       mdelay(25);
+
+       return 0;
+}
+
+static ssize_t c2port_store_flash_access(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       int status;
+       ssize_t ret;
+
+       ret = sscanf(buf, "%d", &status);
+       if (ret != 1)
+               return -EINVAL;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_store_flash_access(c2dev, status);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0) {
+               dev_err(c2dev->dev, "cannot enable %s flash programming\n",
+                       c2dev->name);
+               return ret;
+       }
+
+       return count;
+}
+
+static ssize_t __c2port_write_flash_erase(struct c2port_device *dev)
+{
+       u8 status;
+       int ret;
+
+       /* Target the C2 flash programming data register for C2 data register
+        * access.
+        */
+       c2port_write_ar(dev, C2PORT_FPDAT);
+
+       /* Send device erase command */
+       c2port_write_dr(dev, C2PORT_DEVICE_ERASE);
+
+       /* Wait for input acknowledge */
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Should check status before starting FLASH access sequence */
+
+       /* Wait for status information */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Read flash programming interface status */
+       ret = c2port_read_dr(dev, &status);
+       if (ret < 0)
+               return ret;
+       if (status != C2PORT_COMMAND_OK)
+               return -EBUSY;
+
+       /* Send a three-byte arming sequence to enable the device erase.
+        * If the sequence is not received correctly, the command will be
+        * ignored.
+        * Sequence is: 0xde, 0xad, 0xa5.
+        */
+       c2port_write_dr(dev, 0xde);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+       c2port_write_dr(dev, 0xad);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+       c2port_write_dr(dev, 0xa5);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static ssize_t c2port_store_flash_erase(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct c2port_device *c2dev = dev_get_drvdata(dev);
+       int ret;
+
+       /* Check the device and flash access status */
+       if (!c2dev->access || !c2dev->flash_access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_write_flash_erase(c2dev);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0) {
+               dev_err(c2dev->dev, "cannot erase %s flash\n", c2dev->name);
+               return ret;
+       }
+
+       return count;
+}
+
+static ssize_t __c2port_read_flash_data(struct c2port_device *dev,
+                               char *buffer, loff_t offset, size_t count)
+{
+       struct c2port_ops *ops = dev->ops;
+       u8 status, nread = 128;
+       int i, ret;
+
+       /* Check for flash end */
+       if (offset >= ops->block_size * ops->blocks_num)
+               return 0;
+
+       if (ops->block_size * ops->blocks_num - offset < nread)
+               nread = ops->block_size * ops->blocks_num - offset;
+       if (count < nread)
+               nread = count;
+       if (nread == 0)
+               return nread;
+
+       /* Target the C2 flash programming data register for C2 data register
+        * access */
+       c2port_write_ar(dev, C2PORT_FPDAT);
+
+       /* Send flash block read command */
+       c2port_write_dr(dev, C2PORT_BLOCK_READ);
+
+       /* Wait for input acknowledge */
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Should check status before starting FLASH access sequence */
+
+       /* Wait for status information */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Read flash programming interface status */
+       ret = c2port_read_dr(dev, &status);
+       if (ret < 0)
+               return ret;
+       if (status != C2PORT_COMMAND_OK)
+               return -EBUSY;
+
+       /* Send address high byte */
+       c2port_write_dr(dev, offset >> 8);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Send address low byte */
+       c2port_write_dr(dev, offset & 0x00ff);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Send address block size */
+       c2port_write_dr(dev, nread);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Should check status before reading FLASH block */
+
+       /* Wait for status information */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Read flash programming interface status */
+       ret = c2port_read_dr(dev, &status);
+       if (ret < 0)
+               return ret;
+       if (status != C2PORT_COMMAND_OK)
+               return -EBUSY;
+
+       /* Read flash block */
+       for (i = 0; i < nread; i++) {
+               ret = c2port_poll_out_ready(dev);
+               if (ret < 0)
+                       return ret;
+
+               ret = c2port_read_dr(dev, buffer+i);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return nread;
+}
+
+static ssize_t c2port_read_flash_data(struct kobject *kobj,
+                               struct bin_attribute *attr,
+                               char *buffer, loff_t offset, size_t count)
+{
+       struct c2port_device *c2dev =
+                       dev_get_drvdata(container_of(kobj,
+                                               struct device, kobj));
+       ssize_t ret;
+
+       /* Check the device and flash access status */
+       if (!c2dev->access || !c2dev->flash_access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_read_flash_data(c2dev, buffer, offset, count);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0)
+               dev_err(c2dev->dev, "cannot read %s flash\n", c2dev->name);
+
+       return ret;
+}
+
+static ssize_t __c2port_write_flash_data(struct c2port_device *dev,
+                               char *buffer, loff_t offset, size_t count)
+{
+       struct c2port_ops *ops = dev->ops;
+       u8 status, nwrite = 128;
+       int i, ret;
+
+       if (nwrite > count)
+               nwrite = count;
+       if (ops->block_size * ops->blocks_num - offset < nwrite)
+               nwrite = ops->block_size * ops->blocks_num - offset;
+
+       /* Check for flash end */
+       if (offset >= ops->block_size * ops->blocks_num)
+               return -EINVAL;
+
+       /* Target the C2 flash programming data register for C2 data register
+        * access */
+       c2port_write_ar(dev, C2PORT_FPDAT);
+
+       /* Send flash block write command */
+       c2port_write_dr(dev, C2PORT_BLOCK_WRITE);
+
+       /* Wait for input acknowledge */
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Should check status before starting FLASH access sequence */
+
+       /* Wait for status information */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Read flash programming interface status */
+       ret = c2port_read_dr(dev, &status);
+       if (ret < 0)
+               return ret;
+       if (status != C2PORT_COMMAND_OK)
+               return -EBUSY;
+
+       /* Send address high byte */
+       c2port_write_dr(dev, offset >> 8);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Send address low byte */
+       c2port_write_dr(dev, offset & 0x00ff);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Send address block size */
+       c2port_write_dr(dev, nwrite);
+       ret = c2port_poll_in_busy(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Should check status before writing FLASH block */
+
+       /* Wait for status information */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       /* Read flash programming interface status */
+       ret = c2port_read_dr(dev, &status);
+       if (ret < 0)
+               return ret;
+       if (status != C2PORT_COMMAND_OK)
+               return -EBUSY;
+
+       /* Write flash block */
+       for (i = 0; i < nwrite; i++) {
+               ret = c2port_write_dr(dev, *(buffer+i));
+               if (ret < 0)
+                       return ret;
+
+               ret = c2port_poll_in_busy(dev);
+               if (ret < 0)
+                       return ret;
+
+       }
+
+       /* Wait for last flash write to complete */
+       ret = c2port_poll_out_ready(dev);
+       if (ret < 0)
+               return ret;
+
+       return nwrite;
+}
+
+static ssize_t c2port_write_flash_data(struct kobject *kobj,
+                               struct bin_attribute *attr,
+                               char *buffer, loff_t offset, size_t count)
+{
+       struct c2port_device *c2dev =
+                       dev_get_drvdata(container_of(kobj,
+                                               struct device, kobj));
+       int ret;
+
+       /* Check the device access status */
+       if (!c2dev->access || !c2dev->flash_access)
+               return -EBUSY;
+
+       mutex_lock(&c2dev->mutex);
+       ret = __c2port_write_flash_data(c2dev, buffer, offset, count);
+       mutex_unlock(&c2dev->mutex);
+
+       if (ret < 0)
+               dev_err(c2dev->dev, "cannot write %s flash\n", c2dev->name);
+
+       return ret;
+}
+
+/*
+ * Class attributes
+ */
+
+static struct device_attribute c2port_attrs[] = {
+       __ATTR(name, 0444, c2port_show_name, NULL),
+       __ATTR(flash_blocks_num, 0444, c2port_show_flash_blocks_num, NULL),
+       __ATTR(flash_block_size, 0444, c2port_show_flash_block_size, NULL),
+       __ATTR(flash_size, 0444, c2port_show_flash_size, NULL),
+       __ATTR(access, 0644, c2port_show_access, c2port_store_access),
+       __ATTR(reset, 0200, NULL, c2port_store_reset),
+       __ATTR(dev_id, 0444, c2port_show_dev_id, NULL),
+       __ATTR(rev_id, 0444, c2port_show_rev_id, NULL),
+
+       __ATTR(flash_access, 0644, c2port_show_flash_access,
+                                       c2port_store_flash_access),
+       __ATTR(flash_erase, 0200, NULL, c2port_store_flash_erase),
+       __ATTR_NULL,
+};
+
+static struct bin_attribute c2port_bin_attrs = {
+       .attr   = {
+               .name   = "flash_data",
+               .mode   = 0644
+       },
+       .read   = c2port_read_flash_data,
+       .write  = c2port_write_flash_data,
+       /* .size is computed at run-time */
+};
+
+/*
+ * Exported functions
+ */
+
+struct c2port_device *c2port_device_register(char *name,
+                                       struct c2port_ops *ops, void *devdata)
+{
+       struct c2port_device *c2dev;
+       int id, ret;
+
+       if (unlikely(!ops) || unlikely(!ops->access) || \
+               unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \
+               unlikely(!ops->c2d_get) || unlikely(!ops->c2d_set))
+               return ERR_PTR(-EINVAL);
+
+       c2dev = kmalloc(sizeof(struct c2port_device), GFP_KERNEL);
+       if (unlikely(!c2dev))
+               return ERR_PTR(-ENOMEM);
+
+       ret = idr_pre_get(&c2port_idr, GFP_KERNEL);
+       if (!ret) {
+               ret = -ENOMEM;
+               goto error_idr_get_new;
+       }
+
+       spin_lock_irq(&c2port_idr_lock);
+       ret = idr_get_new(&c2port_idr, c2dev, &id);
+       spin_unlock_irq(&c2port_idr_lock);
+
+       if (ret < 0)
+               goto error_idr_get_new;
+       c2dev->id = id;
+
+       c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
+                                       "c2port%d", id);
+       if (unlikely(!c2dev->dev)) {
+               ret = -ENOMEM;
+               goto error_device_create;
+       }
+       dev_set_drvdata(c2dev->dev, c2dev);
+
+       strncpy(c2dev->name, name, C2PORT_NAME_LEN);
+       c2dev->ops = ops;
+       mutex_init(&c2dev->mutex);
+
+       /* Create binary file */
+       c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
+       ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
+       if (unlikely(ret))
+               goto error_device_create_bin_file;
+
+       /* By default C2 port access is off */
+       c2dev->access = c2dev->flash_access = 0;
+       ops->access(c2dev, 0);
+
+       dev_info(c2dev->dev, "C2 port %s added\n", name);
+       dev_info(c2dev->dev, "%s flash has %d blocks x %d bytes "
+                               "(%d bytes total)\n",
+                               name, ops->blocks_num, ops->block_size,
+                               ops->blocks_num * ops->block_size);
+
+       return c2dev;
+
+error_device_create_bin_file:
+       device_destroy(c2port_class, 0);
+
+error_device_create:
+       spin_lock_irq(&c2port_idr_lock);
+       idr_remove(&c2port_idr, id);
+       spin_unlock_irq(&c2port_idr_lock);
+
+error_idr_get_new:
+       kfree(c2dev);
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL(c2port_device_register);
+
+void c2port_device_unregister(struct c2port_device *c2dev)
+{
+       if (!c2dev)
+               return;
+
+       dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name);
+
+       device_remove_bin_file(c2dev->dev, &c2port_bin_attrs);
+       spin_lock_irq(&c2port_idr_lock);
+       idr_remove(&c2port_idr, c2dev->id);
+       spin_unlock_irq(&c2port_idr_lock);
+
+       device_destroy(c2port_class, c2dev->id);
+
+       kfree(c2dev);
+}
+EXPORT_SYMBOL(c2port_device_unregister);
+
+/*
+ * Module stuff
+ */
+
+static int __init c2port_init(void)
+{
+       printk(KERN_INFO "Silicon Labs C2 port support v. " DRIVER_VERSION
+               " - (C) 2007 Rodolfo Giometti\n");
+
+       c2port_class = class_create(THIS_MODULE, "c2port");
+       if (!c2port_class) {
+               printk(KERN_ERR "c2port: failed to allocate class\n");
+               return -ENOMEM;
+       }
+       c2port_class->dev_attrs = c2port_attrs;
+
+       return 0;
+}
+
+static void __exit c2port_exit(void)
+{
+       class_destroy(c2port_class);
+}
+
+module_init(c2port_init);
+module_exit(c2port_exit);
+
+MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
+MODULE_DESCRIPTION("Silicon Labs C2 port support v. " DRIVER_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c
new file mode 100644 (file)
index 0000000..6e43ab4
--- /dev/null
@@ -0,0 +1,515 @@
+/*
+ * A driver for the Integrated Circuits ICS932S401
+ * Copyright (C) 2008 IBM
+ *
+ * Author: Darrick J. Wong <djwong@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+#include <linux/log2.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x69, I2C_CLIENT_END };
+
+/* Insmod parameters */
+I2C_CLIENT_INSMOD_1(ics932s401);
+
+/* ICS932S401 registers */
+#define ICS932S401_REG_CFG2                    0x01
+#define        ICS932S401_CFG1_SPREAD          0x01
+#define ICS932S401_REG_CFG7                    0x06
+#define                ICS932S401_FS_MASK              0x07
+#define        ICS932S401_REG_VENDOR_REV               0x07
+#define                ICS932S401_VENDOR               1
+#define                ICS932S401_VENDOR_MASK          0x0F
+#define                ICS932S401_REV                  4
+#define                ICS932S401_REV_SHIFT            4
+#define ICS932S401_REG_DEVICE                  0x09
+#define                ICS932S401_DEVICE               11
+#define        ICS932S401_REG_CTRL                     0x0A
+#define                ICS932S401_MN_ENABLED           0x80
+#define                ICS932S401_CPU_ALT              0x04
+#define                ICS932S401_SRC_ALT              0x08
+#define ICS932S401_REG_CPU_M_CTRL              0x0B
+#define                ICS932S401_M_MASK               0x3F
+#define        ICS932S401_REG_CPU_N_CTRL               0x0C
+#define        ICS932S401_REG_CPU_SPREAD1              0x0D
+#define ICS932S401_REG_CPU_SPREAD2             0x0E
+#define                ICS932S401_SPREAD_MASK          0x7FFF
+#define ICS932S401_REG_SRC_M_CTRL              0x0F
+#define ICS932S401_REG_SRC_N_CTRL              0x10
+#define        ICS932S401_REG_SRC_SPREAD1              0x11
+#define ICS932S401_REG_SRC_SPREAD2             0x12
+#define ICS932S401_REG_CPU_DIVISOR             0x13
+#define        ICS932S401_CPU_DIVISOR_SHIFT    4
+#define ICS932S401_REG_PCISRC_DIVISOR          0x14
+#define                ICS932S401_SRC_DIVISOR_MASK     0x0F
+#define                ICS932S401_PCI_DIVISOR_SHIFT    4
+
+/* Base clock is 14.318MHz */
+#define BASE_CLOCK                             14318
+
+#define NUM_REGS                               21
+#define NUM_MIRRORED_REGS                      15
+
+static int regs_to_copy[NUM_MIRRORED_REGS] = {
+       ICS932S401_REG_CFG2,
+       ICS932S401_REG_CFG7,
+       ICS932S401_REG_VENDOR_REV,
+       ICS932S401_REG_DEVICE,
+       ICS932S401_REG_CTRL,
+       ICS932S401_REG_CPU_M_CTRL,
+       ICS932S401_REG_CPU_N_CTRL,
+       ICS932S401_REG_CPU_SPREAD1,
+       ICS932S401_REG_CPU_SPREAD2,
+       ICS932S401_REG_SRC_M_CTRL,
+       ICS932S401_REG_SRC_N_CTRL,
+       ICS932S401_REG_SRC_SPREAD1,
+       ICS932S401_REG_SRC_SPREAD2,
+       ICS932S401_REG_CPU_DIVISOR,
+       ICS932S401_REG_PCISRC_DIVISOR,
+};
+
+/* How often do we reread sensors values? (In jiffies) */
+#define SENSOR_REFRESH_INTERVAL        (2 * HZ)
+
+/* How often do we reread sensor limit values? (In jiffies) */
+#define LIMIT_REFRESH_INTERVAL (60 * HZ)
+
+struct ics932s401_data {
+       struct attribute_group  attrs;
+       struct mutex            lock;
+       char                    sensors_valid;
+       unsigned long           sensors_last_updated;   /* In jiffies */
+
+       u8                      regs[NUM_REGS];
+};
+
+static int ics932s401_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id);
+static int ics932s401_detect(struct i2c_client *client, int kind,
+                         struct i2c_board_info *info);
+static int ics932s401_remove(struct i2c_client *client);
+
+static const struct i2c_device_id ics932s401_id[] = {
+       { "ics932s401", ics932s401 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, ics932s401_id);
+
+static struct i2c_driver ics932s401_driver = {
+       .class          = I2C_CLASS_HWMON,
+       .driver = {
+               .name   = "ics932s401",
+       },
+       .probe          = ics932s401_probe,
+       .remove         = ics932s401_remove,
+       .id_table       = ics932s401_id,
+       .detect         = ics932s401_detect,
+       .address_data   = &addr_data,
+};
+
+static struct ics932s401_data *ics932s401_update_device(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct ics932s401_data *data = i2c_get_clientdata(client);
+       unsigned long local_jiffies = jiffies;
+       int i, temp;
+
+       mutex_lock(&data->lock);
+       if (time_before(local_jiffies, data->sensors_last_updated +
+               SENSOR_REFRESH_INTERVAL)
+               && data->sensors_valid)
+               goto out;
+
+       /*
+        * Each register must be read as a word and then right shifted 8 bits.
+        * Not really sure why this is; setting the "byte count programming"
+        * register to 1 does not fix this problem.
+        */
+       for (i = 0; i < NUM_MIRRORED_REGS; i++) {
+               temp = i2c_smbus_read_word_data(client, regs_to_copy[i]);
+               data->regs[regs_to_copy[i]] = temp >> 8;
+       }
+
+       data->sensors_last_updated = local_jiffies;
+       data->sensors_valid = 1;
+
+out:
+       mutex_unlock(&data->lock);
+       return data;
+}
+
+static ssize_t show_spread_enabled(struct device *dev,
+                                  struct device_attribute *devattr,
+                                  char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+
+       if (data->regs[ICS932S401_REG_CFG2] & ICS932S401_CFG1_SPREAD)
+               return sprintf(buf, "1\n");
+
+       return sprintf(buf, "0\n");
+}
+
+/* bit to cpu khz map */
+static const int fs_speeds[] = {
+       266666,
+       133333,
+       200000,
+       166666,
+       333333,
+       100000,
+       400000,
+       0,
+};
+
+/* clock divisor map */
+static const int divisors[] = {2, 3, 5, 15, 4, 6, 10, 30, 8, 12, 20, 60, 16,
+                              24, 40, 120};
+
+/* Calculate CPU frequency from the M/N registers. */
+static int calculate_cpu_freq(struct ics932s401_data *data)
+{
+       int m, n, freq;
+
+       m = data->regs[ICS932S401_REG_CPU_M_CTRL] & ICS932S401_M_MASK;
+       n = data->regs[ICS932S401_REG_CPU_N_CTRL];
+
+       /* Pull in bits 8 & 9 from the M register */
+       n |= ((int)data->regs[ICS932S401_REG_CPU_M_CTRL] & 0x80) << 1;
+       n |= ((int)data->regs[ICS932S401_REG_CPU_M_CTRL] & 0x40) << 3;
+
+       freq = BASE_CLOCK * (n + 8) / (m + 2);
+       freq /= divisors[data->regs[ICS932S401_REG_CPU_DIVISOR] >>
+                        ICS932S401_CPU_DIVISOR_SHIFT];
+
+       return freq;
+}
+
+static ssize_t show_cpu_clock(struct device *dev,
+                             struct device_attribute *devattr,
+                             char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+
+       return sprintf(buf, "%d\n", calculate_cpu_freq(data));
+}
+
+static ssize_t show_cpu_clock_sel(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+       int freq;
+
+       if (data->regs[ICS932S401_REG_CTRL] & ICS932S401_MN_ENABLED)
+               freq = calculate_cpu_freq(data);
+       else {
+               /* Freq is neatly wrapped up for us */
+               int fid = data->regs[ICS932S401_REG_CFG7] & ICS932S401_FS_MASK;
+               freq = fs_speeds[fid];
+               if (data->regs[ICS932S401_REG_CTRL] & ICS932S401_CPU_ALT) {
+                       switch (freq) {
+                       case 166666:
+                               freq = 160000;
+                               break;
+                       case 333333:
+                               freq = 320000;
+                               break;
+                       }
+               }
+       }
+
+       return sprintf(buf, "%d\n", freq);
+}
+
+/* Calculate SRC frequency from the M/N registers. */
+static int calculate_src_freq(struct ics932s401_data *data)
+{
+       int m, n, freq;
+
+       m = data->regs[ICS932S401_REG_SRC_M_CTRL] & ICS932S401_M_MASK;
+       n = data->regs[ICS932S401_REG_SRC_N_CTRL];
+
+       /* Pull in bits 8 & 9 from the M register */
+       n |= ((int)data->regs[ICS932S401_REG_SRC_M_CTRL] & 0x80) << 1;
+       n |= ((int)data->regs[ICS932S401_REG_SRC_M_CTRL] & 0x40) << 3;
+
+       freq = BASE_CLOCK * (n + 8) / (m + 2);
+       freq /= divisors[data->regs[ICS932S401_REG_PCISRC_DIVISOR] &
+                        ICS932S401_SRC_DIVISOR_MASK];
+
+       return freq;
+}
+
+static ssize_t show_src_clock(struct device *dev,
+                             struct device_attribute *devattr,
+                             char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+
+       return sprintf(buf, "%d\n", calculate_src_freq(data));
+}
+
+static ssize_t show_src_clock_sel(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+       int freq;
+
+       if (data->regs[ICS932S401_REG_CTRL] & ICS932S401_MN_ENABLED)
+               freq = calculate_src_freq(data);
+       else
+               /* Freq is neatly wrapped up for us */
+               if (data->regs[ICS932S401_REG_CTRL] & ICS932S401_CPU_ALT &&
+                   data->regs[ICS932S401_REG_CTRL] & ICS932S401_SRC_ALT)
+                       freq = 96000;
+               else
+                       freq = 100000;
+
+       return sprintf(buf, "%d\n", freq);
+}
+
+/* Calculate PCI frequency from the SRC M/N registers. */
+static int calculate_pci_freq(struct ics932s401_data *data)
+{
+       int m, n, freq;
+
+       m = data->regs[ICS932S401_REG_SRC_M_CTRL] & ICS932S401_M_MASK;
+       n = data->regs[ICS932S401_REG_SRC_N_CTRL];
+
+       /* Pull in bits 8 & 9 from the M register */
+       n |= ((int)data->regs[ICS932S401_REG_SRC_M_CTRL] & 0x80) << 1;
+       n |= ((int)data->regs[ICS932S401_REG_SRC_M_CTRL] & 0x40) << 3;
+
+       freq = BASE_CLOCK * (n + 8) / (m + 2);
+       freq /= divisors[data->regs[ICS932S401_REG_PCISRC_DIVISOR] >>
+                        ICS932S401_PCI_DIVISOR_SHIFT];
+
+       return freq;
+}
+
+static ssize_t show_pci_clock(struct device *dev,
+                             struct device_attribute *devattr,
+                             char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+
+       return sprintf(buf, "%d\n", calculate_pci_freq(data));
+}
+
+static ssize_t show_pci_clock_sel(struct device *dev,
+                                 struct device_attribute *devattr,
+                                 char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+       int freq;
+
+       if (data->regs[ICS932S401_REG_CTRL] & ICS932S401_MN_ENABLED)
+               freq = calculate_pci_freq(data);
+       else
+               freq = 33333;
+
+       return sprintf(buf, "%d\n", freq);
+}
+
+static ssize_t show_value(struct device *dev,
+                         struct device_attribute *devattr,
+                         char *buf);
+
+static ssize_t show_spread(struct device *dev,
+                          struct device_attribute *devattr,
+                          char *buf);
+
+static DEVICE_ATTR(spread_enabled, S_IRUGO, show_spread_enabled, NULL);
+static DEVICE_ATTR(cpu_clock_selection, S_IRUGO, show_cpu_clock_sel, NULL);
+static DEVICE_ATTR(cpu_clock, S_IRUGO, show_cpu_clock, NULL);
+static DEVICE_ATTR(src_clock_selection, S_IRUGO, show_src_clock_sel, NULL);
+static DEVICE_ATTR(src_clock, S_IRUGO, show_src_clock, NULL);
+static DEVICE_ATTR(pci_clock_selection, S_IRUGO, show_pci_clock_sel, NULL);
+static DEVICE_ATTR(pci_clock, S_IRUGO, show_pci_clock, NULL);
+static DEVICE_ATTR(usb_clock, S_IRUGO, show_value, NULL);
+static DEVICE_ATTR(ref_clock, S_IRUGO, show_value, NULL);
+static DEVICE_ATTR(cpu_spread, S_IRUGO, show_spread, NULL);
+static DEVICE_ATTR(src_spread, S_IRUGO, show_spread, NULL);
+
+static struct attribute *ics932s401_attr[] =
+{
+       &dev_attr_spread_enabled.attr,
+       &dev_attr_cpu_clock_selection.attr,
+       &dev_attr_cpu_clock.attr,
+       &dev_attr_src_clock_selection.attr,
+       &dev_attr_src_clock.attr,
+       &dev_attr_pci_clock_selection.attr,
+       &dev_attr_pci_clock.attr,
+       &dev_attr_usb_clock.attr,
+       &dev_attr_ref_clock.attr,
+       &dev_attr_cpu_spread.attr,
+       &dev_attr_src_spread.attr,
+       NULL
+};
+
+static ssize_t show_value(struct device *dev,
+                         struct device_attribute *devattr,
+                         char *buf)
+{
+       int x;
+
+       if (devattr == &dev_attr_usb_clock)
+               x = 48000;
+       else if (devattr == &dev_attr_ref_clock)
+               x = BASE_CLOCK;
+       else
+               BUG();
+
+       return sprintf(buf, "%d\n", x);
+}
+
+static ssize_t show_spread(struct device *dev,
+                          struct device_attribute *devattr,
+                          char *buf)
+{
+       struct ics932s401_data *data = ics932s401_update_device(dev);
+       int reg;
+       unsigned long val;
+
+       if (!(data->regs[ICS932S401_REG_CFG2] & ICS932S401_CFG1_SPREAD))
+               return sprintf(buf, "0%%\n");
+
+       if (devattr == &dev_attr_src_spread)
+               reg = ICS932S401_REG_SRC_SPREAD1;
+       else if (devattr == &dev_attr_cpu_spread)
+               reg = ICS932S401_REG_CPU_SPREAD1;
+       else
+               BUG();
+
+       val = data->regs[reg] | (data->regs[reg + 1] << 8);
+       val &= ICS932S401_SPREAD_MASK;
+
+       /* Scale 0..2^14 to -0.5. */
+       val = 500000 * val / 16384;
+       return sprintf(buf, "-0.%lu%%\n", val);
+}
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int ics932s401_detect(struct i2c_client *client, int kind,
+                         struct i2c_board_info *info)
+{
+       struct i2c_adapter *adapter = client->adapter;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+               return -ENODEV;
+
+       if (kind <= 0) {
+               int vendor, device, revision;
+
+               vendor = i2c_smbus_read_word_data(client,
+                                                 ICS932S401_REG_VENDOR_REV);
+               vendor >>= 8;
+               revision = vendor >> ICS932S401_REV_SHIFT;
+               vendor &= ICS932S401_VENDOR_MASK;
+               if (vendor != ICS932S401_VENDOR)
+                       return -ENODEV;
+
+               device = i2c_smbus_read_word_data(client,
+                                                 ICS932S401_REG_DEVICE);
+               device >>= 8;
+               if (device != ICS932S401_DEVICE)
+                       return -ENODEV;
+
+               if (revision != ICS932S401_REV)
+                       dev_info(&adapter->dev, "Unknown revision %d\n",
+                                revision);
+       } else
+               dev_dbg(&adapter->dev, "detection forced\n");
+
+       strlcpy(info->type, "ics932s401", I2C_NAME_SIZE);
+
+       return 0;
+}
+
+static int ics932s401_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct ics932s401_data *data;
+       int err;
+
+       data = kzalloc(sizeof(struct ics932s401_data), GFP_KERNEL);
+       if (!data) {
+               err = -ENOMEM;
+               goto exit;
+       }
+
+       i2c_set_clientdata(client, data);
+       mutex_init(&data->lock);
+
+       dev_info(&client->dev, "%s chip found\n", client->name);
+
+       /* Register sysfs hooks */
+       data->attrs.attrs = ics932s401_attr;
+       err = sysfs_create_group(&client->dev.kobj, &data->attrs);
+       if (err)
+               goto exit_free;
+
+       return 0;
+
+exit_free:
+       kfree(data);
+exit:
+       return err;
+}
+
+static int ics932s401_remove(struct i2c_client *client)
+{
+       struct ics932s401_data *data = i2c_get_clientdata(client);
+
+       sysfs_remove_group(&client->dev.kobj, &data->attrs);
+       kfree(data);
+       return 0;
+}
+
+static int __init ics932s401_init(void)
+{
+       return i2c_add_driver(&ics932s401_driver);
+}
+
+static void __exit ics932s401_exit(void)
+{
+       i2c_del_driver(&ics932s401_driver);
+}
+
+MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
+MODULE_DESCRIPTION("ICS932S401 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ics932s401_init);
+module_exit(ics932s401_exit);
+
+/* IBM IntelliStation Z30 */
+MODULE_ALIAS("dmi:bvnIBM:*:rn9228:*");
+MODULE_ALIAS("dmi:bvnIBM:*:rn9232:*");
+
+/* IBM x3650/x3550 */
+MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3650*");
+MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3550*");
index e5059aa3c724b189613db3ab6a61255a91d2f3be..8d92d8db9a98c0a3c5625ce74fd27a4268070ba4 100644 (file)
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
 
-
+/* dynamic ioremap() areas */
+#define FLASH_START      0x00000000
+#define FLASH_SIZE       0x800000
+#define FLASH_WIDTH      4
+
+#define SRAM_START       0x60000000
+#define SRAM_SIZE        0xc000
+#define SRAM_WIDTH       4
+
+#define BOOTROM_START    0x70000000
+#define BOOTROM_SIZE     0x80
+#define BOOTROM_WIDTH    4
 
 
 static struct mtd_info *flash_mtd;
index 35fef655ccc4c8e5cbfe55eae84f6aead0456b32..3b959fad1c4ec082bfd7310f789e673de214ac47 100644 (file)
@@ -24,8 +24,8 @@ static struct mtd_info *mymtd;
 static struct map_info h720x_map = {
        .name =         "H720X",
        .bankwidth =    4,
-       .size =         FLASH_SIZE,
-       .phys =         FLASH_PHYS,
+       .size =         H720X_FLASH_SIZE,
+       .phys =         H720X_FLASH_PHYS,
 };
 
 static struct mtd_partition h720x_partitions[] = {
@@ -70,7 +70,7 @@ int __init h720x_mtd_init(void)
 
        char    *part_type = NULL;
 
-       h720x_map.virt = ioremap(FLASH_PHYS, FLASH_SIZE);
+       h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size);
 
        if (!h720x_map.virt) {
                printk(KERN_ERR "H720x-MTD: ioremap failed\n");
index 430d430bce29e8f3f6f03a37753579c140ff2e8e..d07e3f1489510642c0cde8b41b96875fdc115c92 100644 (file)
@@ -7204,10 +7204,13 @@ static void
 poll_bnx2(struct net_device *dev)
 {
        struct bnx2 *bp = netdev_priv(dev);
+       int i;
 
-       disable_irq(bp->pdev->irq);
-       bnx2_interrupt(bp->pdev->irq, dev);
-       enable_irq(bp->pdev->irq);
+       for (i = 0; i < bp->irq_nvecs; i++) {
+               disable_irq(bp->irq_tbl[i].vector);
+               bnx2_interrupt(bp->irq_tbl[i].vector, &bp->bnx2_napi[i]);
+               enable_irq(bp->irq_tbl[i].vector);
+       }
 }
 #endif
 
index 5e663ccda4d4473f675cdf887ab507131b1bfb90..2c341f83d3270e8d32a42d24e1a472fffd945599 100644 (file)
@@ -2701,7 +2701,7 @@ static void set_nqsets(struct adapter *adap)
        int hwports = adap->params.nports;
        int nqsets = SGE_QSETS;
 
-       if (adap->params.rev > 0) {
+       if (adap->params.rev > 0 && adap->flags & USING_MSIX) {
                if (hwports == 2 &&
                    (hwports * nqsets > SGE_QSETS ||
                     num_cpus >= nqsets / hwports))
index 968f64be3743acb165dbe40013e5d2a4dd60ee42..9a0898b0dbcef2e8d214046c3ac9137de1ccfb23 100644 (file)
@@ -572,7 +572,7 @@ struct t3_vpd {
        u32 pad;                /* for multiple-of-4 sizing and alignment */
 };
 
-#define EEPROM_MAX_POLL   4
+#define EEPROM_MAX_POLL   40
 #define EEPROM_STAT_ADDR  0x4000
 #define VPD_BASE          0xc00
 
@@ -3690,6 +3690,12 @@ int t3_prep_adapter(struct adapter *adapter, const struct adapter_info *ai,
                        ;
 
                pti = &port_types[adapter->params.vpd.port_type[j]];
+               if (!pti->phy_prep) {
+                       CH_ALERT(adapter, "Invalid port type index %d\n",
+                                adapter->params.vpd.port_type[j]);
+                       return -EINVAL;
+               }
+
                ret = pti->phy_prep(&p->phy, adapter, ai->phy_base_addr + j,
                                    ai->mdio_ops);
                if (ret)
index a5f428bcc0ebb28011efb551534584e768c4a6e9..b3786709730811c2b6467cabda06c55d2203ddb1 100644 (file)
@@ -75,7 +75,7 @@
 #include "myri10ge_mcp.h"
 #include "myri10ge_mcp_gen_header.h"
 
-#define MYRI10GE_VERSION_STR "1.4.3-1.375"
+#define MYRI10GE_VERSION_STR "1.4.3-1.378"
 
 MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
 MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -1393,6 +1393,7 @@ myri10ge_tx_done(struct myri10ge_slice_state *ss, int mcp_index)
                if (tx->req == tx->done) {
                        tx->queue_active = 0;
                        put_be32(htonl(1), tx->send_stop);
+                       mb();
                        mmiowb();
                }
                __netif_tx_unlock(dev_queue);
@@ -2865,6 +2866,7 @@ again:
        if ((mgp->dev->real_num_tx_queues > 1) && tx->queue_active == 0) {
                tx->queue_active = 1;
                put_be32(htonl(1), tx->send_go);
+               mb();
                mmiowb();
        }
        tx->pkt_start++;
index 9acb5d70a3ae310c4ac179469a7d5f18ae721b32..d8463b1c3df3fe97c459feff6843de56425b028a 100644 (file)
@@ -51,8 +51,7 @@ MODULE_VERSION(DRV_MODULE_VERSION);
 #ifndef readq
 static u64 readq(void __iomem *reg)
 {
-       return (((u64)readl(reg + 0x4UL) << 32) |
-               (u64)readl(reg));
+       return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
 }
 
 static void writeq(u64 val, void __iomem *reg)
index 5051554ff05b06f6c90c0a7f2ed006b96e3fafc0..1f26ab0e7986533386a821870c30290222c387ba 100644 (file)
@@ -2050,7 +2050,9 @@ err_out:
  */
 static int smc911x_drv_probe(struct platform_device *pdev)
 {
+#ifdef SMC_DYNAMIC_BUS_CONFIG
        struct smc911x_platdata *pd = pdev->dev.platform_data;
+#endif
        struct net_device *ndev;
        struct resource *res;
        struct smc911x_local *lp;
@@ -2182,9 +2184,9 @@ static int smc911x_drv_resume(struct platform_device *dev)
 
                if (netif_running(ndev)) {
                        smc911x_reset(ndev);
-                       smc911x_enable(ndev);
                        if (lp->phy_type != 0)
                                smc911x_phy_configure(&lp->phy_configure);
+                       smc911x_enable(ndev);
                        netif_device_attach(ndev);
                }
        }
index 37ecf845edfe9b91c5a6aee4ef514ad713e541ea..e12cdb4543b406f543e6e363dd43dcef20918db7 100644 (file)
@@ -1444,6 +1444,10 @@ static const struct usb_device_id        products [] = {
        // Apple USB Ethernet Adapter
        USB_DEVICE(0x05ac, 0x1402),
        .driver_info = (unsigned long) &ax88772_info,
+}, {
+       // Cables-to-Go USB Ethernet Adapter
+       USB_DEVICE(0x0b95, 0x772a),
+       .driver_info = (unsigned long) &ax88772_info,
 },
        { },            // END
 };
index ffdf4876121b60829dd9634f1fcc45f7d06fc24b..a68f97c3935947a59990d188f7d95d05b19c600c 100644 (file)
@@ -918,9 +918,12 @@ struct hostap_interface {
 
 /*
  * TX meta data - stored in skb->cb buffer, so this must not be increased over
- * the 40-byte limit
+ * the 48-byte limit.
+ * THE PADDING THIS STARTS WITH IS A HORRIBLE HACK THAT SHOULD NOT LIVE
+ * TO SEE THE DAY.
  */
 struct hostap_skb_tx_data {
+       unsigned int __padding_for_default_qdiscs;
        u32 magic; /* HOSTAP_SKB_TX_DATA_MAGIC */
        u8 rate; /* transmit rate */
 #define HOSTAP_TX_FLAGS_WDS BIT(0)
index 431e3c78bf27668b00d87fc06120a7f909ae5090..69eb0132593b72cc2a5d995788a28d2744fcecce 100644 (file)
@@ -48,6 +48,9 @@ static struct usb_device_id rtl8187_table[] __devinitdata = {
        {USB_DEVICE(0x03f0, 0xca02), .driver_info = DEVICE_RTL8187},
        /* Sitecom */
        {USB_DEVICE(0x0df6, 0x000d), .driver_info = DEVICE_RTL8187},
+       {USB_DEVICE(0x0df6, 0x0028), .driver_info = DEVICE_RTL8187B},
+       /* Abocom */
+       {USB_DEVICE(0x13d1, 0xabe6), .driver_info = DEVICE_RTL8187},
        {}
 };
 
index b3a63edb69012bd443f4caebffdaddf12103b86a..ae5ec76dca77a636bf5b1f1a6cf4c52b03b8d9c8 100644 (file)
@@ -63,7 +63,7 @@ static acpi_status acpi_run_osc(acpi_handle handle,
        union acpi_object in_params[4];
        struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
        union acpi_object *out_obj;
-       u32 osc_dw0, flags = osc_args->capbuf[OSC_QUERY_TYPE];
+       u32 errors, flags = osc_args->capbuf[OSC_QUERY_TYPE];
 
        /* Setting up input parameters */
        input.count = 4;
@@ -92,15 +92,16 @@ static acpi_status acpi_run_osc(acpi_handle handle,
                status = AE_TYPE;
                goto out_kfree;
        }
-       osc_dw0 = *((u32 *)out_obj->buffer.pointer);
-       if (osc_dw0) {
-               if (osc_dw0 & OSC_REQUEST_ERROR)
+       /* Need to ignore the bit0 in result code */
+       errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
+       if (errors) {
+               if (errors & OSC_REQUEST_ERROR)
                        printk(KERN_DEBUG "_OSC request fails\n"); 
-               if (osc_dw0 & OSC_INVALID_UUID_ERROR)
+               if (errors & OSC_INVALID_UUID_ERROR)
                        printk(KERN_DEBUG "_OSC invalid UUID\n"); 
-               if (osc_dw0 & OSC_INVALID_REVISION_ERROR)
+               if (errors & OSC_INVALID_REVISION_ERROR)
                        printk(KERN_DEBUG "_OSC invalid revision\n"); 
-               if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) {
+               if (errors & OSC_CAPABILITIES_MASK_ERROR) {
                        if (flags & OSC_QUERY_ENABLE)
                                goto out_success;
                        printk(KERN_DEBUG "_OSC FW not grant req. control\n");
index 8abbb2020af9c0d6b238d16cf81c4277de31dc3d..123092d8a98484aebde61d7c60cc77639e95c351 100644 (file)
@@ -277,6 +277,14 @@ config RTC_DRV_FM3130
          This driver can also be built as a module. If so the module
          will be called rtc-fm3130.
 
+config RTC_DRV_RX8581
+       tristate "Epson RX-8581"
+       help
+         If you say yes here you will get support for the Epson RX-8581.
+
+         This driver can also be built as a module. If so the module
+         will be called rtc-rx8581.
+
 endif # I2C
 
 comment "SPI RTC drivers"
@@ -302,6 +310,17 @@ config RTC_DRV_DS1305
          This driver can also be built as a module. If so, the module
          will be called rtc-ds1305.
 
+config RTC_DRV_DS1390
+       tristate "Dallas/Maxim DS1390/93/94"
+       help
+         If you say yes here you get support for the DS1390/93/94 chips.
+
+         This driver only supports the RTC feature, and not other chip
+         features such as alarms and trickle charging.
+
+         This driver can also be built as a module. If so, the module
+         will be called rtc-ds1390.
+
 config RTC_DRV_MAX6902
        tristate "Maxim MAX6902"
        help
@@ -468,6 +487,16 @@ config RTC_DRV_V3020
          This driver can also be built as a module. If so, the module
          will be called rtc-v3020.
 
+config RTC_DRV_WM8350
+       tristate "Wolfson Microelectronics WM8350 RTC"
+       depends on MFD_WM8350
+       help
+         If you say yes here you will get support for the RTC subsystem
+         of the Wolfson Microelectronics WM8350.
+
+         This driver can also be built as a module. If so, the module
+         will be called "rtc-wm8350".
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_OMAP
index e9e8474cc8fea8fb11ff77f31df46e30d8c7dbba..6e79c912bf9ee1b44d30baafabe2ef424fb14f3b 100644 (file)
@@ -28,6 +28,7 @@ obj-$(CONFIG_RTC_DRV_DS1302)  += rtc-ds1302.o
 obj-$(CONFIG_RTC_DRV_DS1305)   += rtc-ds1305.o
 obj-$(CONFIG_RTC_DRV_DS1307)   += rtc-ds1307.o
 obj-$(CONFIG_RTC_DRV_DS1374)   += rtc-ds1374.o
+obj-$(CONFIG_RTC_DRV_DS1390)   += rtc-ds1390.o
 obj-$(CONFIG_RTC_DRV_DS1511)   += rtc-ds1511.o
 obj-$(CONFIG_RTC_DRV_DS1553)   += rtc-ds1553.o
 obj-$(CONFIG_RTC_DRV_DS1672)   += rtc-ds1672.o
@@ -57,6 +58,7 @@ obj-$(CONFIG_RTC_DRV_R9701)   += rtc-r9701.o
 obj-$(CONFIG_RTC_DRV_RS5C313)  += rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)  += rtc-rs5c348.o
 obj-$(CONFIG_RTC_DRV_RS5C372)  += rtc-rs5c372.o
+obj-$(CONFIG_RTC_DRV_RX8581)   += rtc-rx8581.o
 obj-$(CONFIG_RTC_DRV_S35390A)  += rtc-s35390a.o
 obj-$(CONFIG_RTC_DRV_S3C)      += rtc-s3c.o
 obj-$(CONFIG_RTC_DRV_SA1100)   += rtc-sa1100.o
@@ -66,4 +68,5 @@ obj-$(CONFIG_RTC_DRV_TEST)    += rtc-test.o
 obj-$(CONFIG_RTC_DRV_TWL4030)  += rtc-twl4030.o
 obj-$(CONFIG_RTC_DRV_V3020)    += rtc-v3020.o
 obj-$(CONFIG_RTC_DRV_VR41XX)   += rtc-vr41xx.o
+obj-$(CONFIG_RTC_DRV_WM8350)   += rtc-wm8350.o
 obj-$(CONFIG_RTC_DRV_X1205)    += rtc-x1205.o
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
new file mode 100644 (file)
index 0000000..599e976
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * rtc-ds1390.c -- driver for DS1390/93/94
+ *
+ * Copyright (C) 2008 Mercury IMC Ltd
+ * Written by Mark Jackson <mpfj@mimc.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * NOTE : Currently this driver only supports the bare minimum for read
+ * and write the RTC.  The extra features provided by the chip family
+ * (alarms, trickle charger, different control registers) are unavailable.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/spi/spi.h>
+#include <linux/bcd.h>
+
+#define DS1390_REG_100THS              0x00
+#define DS1390_REG_SECONDS             0x01
+#define DS1390_REG_MINUTES             0x02
+#define DS1390_REG_HOURS               0x03
+#define DS1390_REG_DAY                 0x04
+#define DS1390_REG_DATE                        0x05
+#define DS1390_REG_MONTH_CENT          0x06
+#define DS1390_REG_YEAR                        0x07
+
+#define DS1390_REG_ALARM_100THS                0x08
+#define DS1390_REG_ALARM_SECONDS       0x09
+#define DS1390_REG_ALARM_MINUTES       0x0A
+#define DS1390_REG_ALARM_HOURS         0x0B
+#define DS1390_REG_ALARM_DAY_DATE      0x0C
+
+#define DS1390_REG_CONTROL             0x0D
+#define DS1390_REG_STATUS              0x0E
+#define DS1390_REG_TRICKLE             0x0F
+
+struct ds1390 {
+       struct rtc_device *rtc;
+       u8 txrx_buf[9]; /* cmd + 8 registers */
+};
+
+static void ds1390_set_reg(struct device *dev, unsigned char address,
+                               unsigned char data)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct ds1390 *chip = dev_get_drvdata(dev);
+
+       /* Set MSB to indicate write */
+       chip->txrx_buf[0] = address | 0x80;
+       chip->txrx_buf[1] = data;
+
+       /* do the i/o */
+       spi_write_then_read(spi, chip->txrx_buf, 2, NULL, 0);
+}
+
+static int ds1390_get_reg(struct device *dev, unsigned char address,
+                               unsigned char *data)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct ds1390 *chip = dev_get_drvdata(dev);
+       int status;
+
+       if (!data)
+               return -EINVAL;
+
+       /* Clear MSB to indicate read */
+       chip->txrx_buf[0] = address & 0x7f;
+       /* do the i/o */
+       status = spi_write_then_read(spi, chip->txrx_buf, 1, chip->txrx_buf, 1);
+       if (status != 0)
+               return status;
+
+       *data = chip->txrx_buf[1];
+
+       return 0;
+}
+
+static int ds1390_get_datetime(struct device *dev, struct rtc_time *dt)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct ds1390 *chip = dev_get_drvdata(dev);
+       int status;
+
+       /* build the message */
+       chip->txrx_buf[0] = DS1390_REG_SECONDS;
+
+       /* do the i/o */
+       status = spi_write_then_read(spi, chip->txrx_buf, 1, chip->txrx_buf, 8);
+       if (status != 0)
+               return status;
+
+       /* The chip sends data in this order:
+        * Seconds, Minutes, Hours, Day, Date, Month / Century, Year */
+       dt->tm_sec      = bcd2bin(chip->txrx_buf[0]);
+       dt->tm_min      = bcd2bin(chip->txrx_buf[1]);
+       dt->tm_hour     = bcd2bin(chip->txrx_buf[2]);
+       dt->tm_wday     = bcd2bin(chip->txrx_buf[3]);
+       dt->tm_mday     = bcd2bin(chip->txrx_buf[4]);
+       /* mask off century bit */
+       dt->tm_mon      = bcd2bin(chip->txrx_buf[5] & 0x7f) - 1;
+       /* adjust for century bit */
+       dt->tm_year = bcd2bin(chip->txrx_buf[6]) + ((chip->txrx_buf[5] & 0x80) ? 100 : 0);
+
+       return rtc_valid_tm(dt);
+}
+
+static int ds1390_set_datetime(struct device *dev, struct rtc_time *dt)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct ds1390 *chip = dev_get_drvdata(dev);
+
+       /* build the message */
+       chip->txrx_buf[0] = DS1390_REG_SECONDS | 0x80;
+       chip->txrx_buf[1] = bin2bcd(dt->tm_sec);
+       chip->txrx_buf[2] = bin2bcd(dt->tm_min);
+       chip->txrx_buf[3] = bin2bcd(dt->tm_hour);
+       chip->txrx_buf[4] = bin2bcd(dt->tm_wday);
+       chip->txrx_buf[5] = bin2bcd(dt->tm_mday);
+       chip->txrx_buf[6] = bin2bcd(dt->tm_mon + 1) |
+                               ((dt->tm_year > 99) ? 0x80 : 0x00);
+       chip->txrx_buf[7] = bin2bcd(dt->tm_year % 100);
+
+       /* do the i/o */
+       return spi_write_then_read(spi, chip->txrx_buf, 8, NULL, 0);
+}
+
+static int ds1390_read_time(struct device *dev, struct rtc_time *tm)
+{
+       return ds1390_get_datetime(dev, tm);
+}
+
+static int ds1390_set_time(struct device *dev, struct rtc_time *tm)
+{
+       return ds1390_set_datetime(dev, tm);
+}
+
+static const struct rtc_class_ops ds1390_rtc_ops = {
+       .read_time      = ds1390_read_time,
+       .set_time       = ds1390_set_time,
+};
+
+static int __devinit ds1390_probe(struct spi_device *spi)
+{
+       struct rtc_device *rtc;
+       unsigned char tmp;
+       struct ds1390 *chip;
+       int res;
+
+       printk(KERN_DEBUG "DS1390 SPI RTC driver\n");
+
+       rtc = rtc_device_register("ds1390",
+                               &spi->dev, &ds1390_rtc_ops, THIS_MODULE);
+       if (IS_ERR(rtc)) {
+               printk(KERN_ALERT "RTC : unable to register device\n");
+               return PTR_ERR(rtc);
+       }
+
+       spi->mode = SPI_MODE_3;
+       spi->bits_per_word = 8;
+       spi_setup(spi);
+
+       chip = kzalloc(sizeof *chip, GFP_KERNEL);
+       if (!chip) {
+               printk(KERN_ALERT "RTC : unable to allocate device memory\n");
+               rtc_device_unregister(rtc);
+               return -ENOMEM;
+       }
+       chip->rtc = rtc;
+       dev_set_drvdata(&spi->dev, chip);
+
+       res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp);
+       if (res) {
+               printk(KERN_ALERT "RTC : unable to read device\n");
+               rtc_device_unregister(rtc);
+               return res;
+       }
+
+       return 0;
+}
+
+static int __devexit ds1390_remove(struct spi_device *spi)
+{
+       struct ds1390 *chip = platform_get_drvdata(spi);
+       struct rtc_device *rtc = chip->rtc;
+
+       if (rtc)
+               rtc_device_unregister(rtc);
+
+       kfree(chip);
+
+       return 0;
+}
+
+static struct spi_driver ds1390_driver = {
+       .driver = {
+               .name   = "rtc-ds1390",
+               .owner  = THIS_MODULE,
+       },
+       .probe  = ds1390_probe,
+       .remove = __devexit_p(ds1390_remove),
+};
+
+static __init int ds1390_init(void)
+{
+       return spi_register_driver(&ds1390_driver);
+}
+module_init(ds1390_init);
+
+static __exit void ds1390_exit(void)
+{
+       spi_unregister_driver(&ds1390_driver);
+}
+module_exit(ds1390_exit);
+
+MODULE_DESCRIPTION("DS1390/93/94 SPI RTC driver");
+MODULE_AUTHOR("Mark Jackson <mpfj@mimc.co.uk>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
new file mode 100644 (file)
index 0000000..c9522f3
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * An I2C driver for the Epson RX8581 RTC
+ *
+ * Author: Martyn Welch <martyn.welch@gefanuc.com>
+ * Copyright 2008 GE Fanuc Intelligent Platforms Embedded Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Based on: rtc-pcf8563.c (An I2C driver for the Philips PCF8563 RTC)
+ * Copyright 2005-06 Tower Technologies
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/bcd.h>
+#include <linux/rtc.h>
+#include <linux/log2.h>
+
+#define DRV_VERSION "0.1"
+
+#define RX8581_REG_SC          0x00 /* Second in BCD */
+#define RX8581_REG_MN          0x01 /* Minute in BCD */
+#define RX8581_REG_HR          0x02 /* Hour in BCD */
+#define RX8581_REG_DW          0x03 /* Day of Week */
+#define RX8581_REG_DM          0x04 /* Day of Month in BCD */
+#define RX8581_REG_MO          0x05 /* Month in BCD */
+#define RX8581_REG_YR          0x06 /* Year in BCD */
+#define RX8581_REG_RAM         0x07 /* RAM */
+#define RX8581_REG_AMN         0x08 /* Alarm Min in BCD*/
+#define RX8581_REG_AHR         0x09 /* Alarm Hour in BCD */
+#define RX8581_REG_ADM         0x0A
+#define RX8581_REG_ADW         0x0A
+#define RX8581_REG_TMR0                0x0B
+#define RX8581_REG_TMR1                0x0C
+#define RX8581_REG_EXT         0x0D /* Extension Register */
+#define RX8581_REG_FLAG                0x0E /* Flag Register */
+#define RX8581_REG_CTRL                0x0F /* Control Register */
+
+
+/* Flag Register bit definitions */
+#define RX8581_FLAG_UF         0x20 /* Update */
+#define RX8581_FLAG_TF         0x10 /* Timer */
+#define RX8581_FLAG_AF         0x08 /* Alarm */
+#define RX8581_FLAG_VLF                0x02 /* Voltage Low */
+
+/* Control Register bit definitions */
+#define RX8581_CTRL_UIE                0x20 /* Update Interrupt Enable */
+#define RX8581_CTRL_TIE                0x10 /* Timer Interrupt Enable */
+#define RX8581_CTRL_AIE                0x08 /* Alarm Interrupt Enable */
+#define RX8581_CTRL_STOP       0x02 /* STOP bit */
+#define RX8581_CTRL_RESET      0x01 /* RESET bit */
+
+static struct i2c_driver rx8581_driver;
+
+/*
+ * In the routines that deal directly with the rx8581 hardware, we use
+ * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
+ */
+static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm)
+{
+       unsigned char date[7];
+       int data, err;
+
+       /* First we ensure that the "update flag" is not set, we read the
+        * time and date then re-read the "update flag". If the update flag
+        * has been set, we know that the time has changed during the read so
+        * we repeat the whole process again.
+        */
+       data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG);
+       if (data < 0) {
+               dev_err(&client->dev, "Unable to read device flags\n");
+               return -EIO;
+       }
+
+       do {
+               /* If update flag set, clear it */
+               if (data & RX8581_FLAG_UF) {
+                       err = i2c_smbus_write_byte_data(client,
+                               RX8581_REG_FLAG, (data & ~RX8581_FLAG_UF));
+                       if (err != 0) {
+                               dev_err(&client->dev, "Unable to write device "
+                                       "flags\n");
+                               return -EIO;
+                       }
+               }
+
+               /* Now read time and date */
+               err = i2c_smbus_read_i2c_block_data(client, RX8581_REG_SC,
+                       7, date);
+               if (err < 0) {
+                       dev_err(&client->dev, "Unable to read date\n");
+                       return -EIO;
+               }
+
+               /* Check flag register */
+               data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG);
+               if (data < 0) {
+                       dev_err(&client->dev, "Unable to read device flags\n");
+                       return -EIO;
+               }
+       } while (data & RX8581_FLAG_UF);
+
+       if (data & RX8581_FLAG_VLF)
+               dev_info(&client->dev,
+                       "low voltage detected, date/time is not reliable.\n");
+
+       dev_dbg(&client->dev,
+               "%s: raw data is sec=%02x, min=%02x, hr=%02x, "
+               "wday=%02x, mday=%02x, mon=%02x, year=%02x\n",
+               __func__,
+               date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
+
+       tm->tm_sec = bcd2bin(date[RX8581_REG_SC] & 0x7F);
+       tm->tm_min = bcd2bin(date[RX8581_REG_MN] & 0x7F);
+       tm->tm_hour = bcd2bin(date[RX8581_REG_HR] & 0x3F); /* rtc hr 0-23 */
+       tm->tm_wday = ilog2(date[RX8581_REG_DW] & 0x7F);
+       tm->tm_mday = bcd2bin(date[RX8581_REG_DM] & 0x3F);
+       tm->tm_mon = bcd2bin(date[RX8581_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
+       tm->tm_year = bcd2bin(date[RX8581_REG_YR]);
+       if (tm->tm_year < 70)
+               tm->tm_year += 100;     /* assume we are in 1970...2069 */
+
+
+       dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
+               "mday=%d, mon=%d, year=%d, wday=%d\n",
+               __func__,
+               tm->tm_sec, tm->tm_min, tm->tm_hour,
+               tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
+
+       err = rtc_valid_tm(tm);
+       if (err < 0)
+               dev_err(&client->dev, "retrieved date/time is not valid.\n");
+
+       return err;
+}
+
+static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
+{
+       int data, err;
+       unsigned char buf[7];
+
+       dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
+               "mday=%d, mon=%d, year=%d, wday=%d\n",
+               __func__,
+               tm->tm_sec, tm->tm_min, tm->tm_hour,
+               tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
+
+       /* hours, minutes and seconds */
+       buf[RX8581_REG_SC] = bin2bcd(tm->tm_sec);
+       buf[RX8581_REG_MN] = bin2bcd(tm->tm_min);
+       buf[RX8581_REG_HR] = bin2bcd(tm->tm_hour);
+
+       buf[RX8581_REG_DM] = bin2bcd(tm->tm_mday);
+
+       /* month, 1 - 12 */
+       buf[RX8581_REG_MO] = bin2bcd(tm->tm_mon + 1);
+
+       /* year and century */
+       buf[RX8581_REG_YR] = bin2bcd(tm->tm_year % 100);
+       buf[RX8581_REG_DW] = (0x1 << tm->tm_wday);
+
+       /* Stop the clock */
+       data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL);
+       if (data < 0) {
+               dev_err(&client->dev, "Unable to read control register\n");
+               return -EIO;
+       }
+
+       err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG,
+               (data | RX8581_CTRL_STOP));
+       if (err < 0) {
+               dev_err(&client->dev, "Unable to write control register\n");
+               return -EIO;
+       }
+
+       /* write register's data */
+       err = i2c_smbus_write_i2c_block_data(client, RX8581_REG_SC, 7, buf);
+       if (err < 0) {
+               dev_err(&client->dev, "Unable to write to date registers\n");
+               return -EIO;
+       }
+
+       /* Restart the clock */
+       data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL);
+       if (data < 0) {
+               dev_err(&client->dev, "Unable to read control register\n");
+               return -EIO;
+       }
+
+       err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG,
+               (data | ~(RX8581_CTRL_STOP)));
+       if (err != 0) {
+               dev_err(&client->dev, "Unable to write control register\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static int rx8581_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+       return rx8581_get_datetime(to_i2c_client(dev), tm);
+}
+
+static int rx8581_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+       return rx8581_set_datetime(to_i2c_client(dev), tm);
+}
+
+static const struct rtc_class_ops rx8581_rtc_ops = {
+       .read_time      = rx8581_rtc_read_time,
+       .set_time       = rx8581_rtc_set_time,
+};
+
+static int __devinit rx8581_probe(struct i2c_client *client,
+                               const struct i2c_device_id *id)
+{
+       struct rtc_device *rtc;
+
+       dev_dbg(&client->dev, "%s\n", __func__);
+
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+               return -ENODEV;
+
+       dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
+
+       rtc = rtc_device_register(rx8581_driver.driver.name,
+                               &client->dev, &rx8581_rtc_ops, THIS_MODULE);
+
+       if (IS_ERR(rtc))
+               return PTR_ERR(rtc);
+
+       i2c_set_clientdata(client, rtc);
+
+       return 0;
+}
+
+static int __devexit rx8581_remove(struct i2c_client *client)
+{
+       struct rtc_device *rtc = i2c_get_clientdata(client);
+
+       rtc_device_unregister(rtc);
+
+       return 0;
+}
+
+static const struct i2c_device_id rx8581_id[] = {
+       { "rx8581", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, rx8581_id);
+
+static struct i2c_driver rx8581_driver = {
+       .driver         = {
+               .name   = "rtc-rx8581",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = rx8581_probe,
+       .remove         = __devexit_p(rx8581_remove),
+       .id_table       = rx8581_id,
+};
+
+static int __init rx8581_init(void)
+{
+       return i2c_add_driver(&rx8581_driver);
+}
+
+static void __exit rx8581_exit(void)
+{
+       i2c_del_driver(&rx8581_driver);
+}
+
+MODULE_AUTHOR("Martyn Welch <martyn.welch@gefanuc.com>");
+MODULE_DESCRIPTION("Epson RX-8581 RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
+
+module_init(rx8581_init);
+module_exit(rx8581_exit);
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
new file mode 100644 (file)
index 0000000..5c5e3aa
--- /dev/null
@@ -0,0 +1,514 @@
+/*
+ *     Real Time Clock driver for Wolfson Microelectronics WM8350
+ *
+ *     Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ *  Author: Liam Girdwood
+ *          linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/time.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/interrupt.h>
+#include <linux/ioctl.h>
+#include <linux/completion.h>
+#include <linux/mfd/wm8350/rtc.h>
+#include <linux/mfd/wm8350/core.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+
+#define WM8350_SET_ALM_RETRIES 5
+#define WM8350_SET_TIME_RETRIES        5
+#define WM8350_GET_TIME_RETRIES        5
+
+#define to_wm8350_from_rtc_dev(d) container_of(d, struct wm8350, rtc.pdev.dev)
+
+/*
+ * Read current time and date in RTC
+ */
+static int wm8350_rtc_readtime(struct device *dev, struct rtc_time *tm)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+       u16 time1[4], time2[4];
+       int retries = WM8350_GET_TIME_RETRIES, ret;
+
+       /*
+        * Read the time twice and compare.
+        * If time1 == time2, then time is valid else retry.
+        */
+       do {
+               ret = wm8350_block_read(wm8350, WM8350_RTC_SECONDS_MINUTES,
+                                       4, time1);
+               if (ret < 0)
+                       return ret;
+               ret = wm8350_block_read(wm8350, WM8350_RTC_SECONDS_MINUTES,
+                                       4, time2);
+               if (ret < 0)
+                       return ret;
+
+               if (memcmp(time1, time2, sizeof(time1)) == 0) {
+                       tm->tm_sec = time1[0] & WM8350_RTC_SECS_MASK;
+
+                       tm->tm_min = (time1[0] & WM8350_RTC_MINS_MASK)
+                           >> WM8350_RTC_MINS_SHIFT;
+
+                       tm->tm_hour = time1[1] & WM8350_RTC_HRS_MASK;
+
+                       tm->tm_wday = ((time1[1] >> WM8350_RTC_DAY_SHIFT)
+                                      & 0x7) - 1;
+
+                       tm->tm_mon = ((time1[2] & WM8350_RTC_MTH_MASK)
+                                     >> WM8350_RTC_MTH_SHIFT) - 1;
+
+                       tm->tm_mday = (time1[2] & WM8350_RTC_DATE_MASK);
+
+                       tm->tm_year = ((time1[3] & WM8350_RTC_YHUNDREDS_MASK)
+                                      >> WM8350_RTC_YHUNDREDS_SHIFT) * 100;
+                       tm->tm_year += time1[3] & WM8350_RTC_YUNITS_MASK;
+
+                       tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon,
+                                                   tm->tm_year);
+                       tm->tm_year -= 1900;
+
+                       dev_dbg(dev, "Read (%d left): %04x %04x %04x %04x\n",
+                               retries,
+                               time1[0], time1[1], time1[2], time1[3]);
+
+                       return 0;
+               }
+       } while (retries--);
+
+       dev_err(dev, "timed out reading RTC time\n");
+       return -EIO;
+}
+
+/*
+ * Set current time and date in RTC
+ */
+static int wm8350_rtc_settime(struct device *dev, struct rtc_time *tm)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+       u16 time[4];
+       u16 rtc_ctrl;
+       int ret, retries = WM8350_SET_TIME_RETRIES;
+
+       time[0] = tm->tm_sec;
+       time[0] |= tm->tm_min << WM8350_RTC_MINS_SHIFT;
+       time[1] = tm->tm_hour;
+       time[1] |= (tm->tm_wday + 1) << WM8350_RTC_DAY_SHIFT;
+       time[2] = tm->tm_mday;
+       time[2] |= (tm->tm_mon + 1) << WM8350_RTC_MTH_SHIFT;
+       time[3] = ((tm->tm_year + 1900) / 100) << WM8350_RTC_YHUNDREDS_SHIFT;
+       time[3] |= (tm->tm_year + 1900) % 100;
+
+       dev_dbg(dev, "Setting: %04x %04x %04x %04x\n",
+               time[0], time[1], time[2], time[3]);
+
+       /* Set RTC_SET to stop the clock */
+       ret = wm8350_set_bits(wm8350, WM8350_RTC_TIME_CONTROL, WM8350_RTC_SET);
+       if (ret < 0)
+               return ret;
+
+       /* Wait until confirmation of stopping */
+       do {
+               rtc_ctrl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);
+               schedule_timeout_uninterruptible(msecs_to_jiffies(1));
+       } while (retries-- && !(rtc_ctrl & WM8350_RTC_STS));
+
+       if (!retries) {
+               dev_err(dev, "timed out on set confirmation\n");
+               return -EIO;
+       }
+
+       /* Write time to RTC */
+       ret = wm8350_block_write(wm8350, WM8350_RTC_SECONDS_MINUTES, 4, time);
+       if (ret < 0)
+               return ret;
+
+       /* Clear RTC_SET to start the clock */
+       ret = wm8350_clear_bits(wm8350, WM8350_RTC_TIME_CONTROL,
+                               WM8350_RTC_SET);
+       return ret;
+}
+
+/*
+ * Read alarm time and date in RTC
+ */
+static int wm8350_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+       struct rtc_time *tm = &alrm->time;
+       u16 time[4];
+       int ret;
+
+       ret = wm8350_block_read(wm8350, WM8350_ALARM_SECONDS_MINUTES, 4, time);
+       if (ret < 0)
+               return ret;
+
+       tm->tm_sec = time[0] & WM8350_RTC_ALMSECS_MASK;
+       if (tm->tm_sec == WM8350_RTC_ALMSECS_MASK)
+               tm->tm_sec = -1;
+
+       tm->tm_min = time[0] & WM8350_RTC_ALMMINS_MASK;
+       if (tm->tm_min == WM8350_RTC_ALMMINS_MASK)
+               tm->tm_min = -1;
+       else
+               tm->tm_min >>= WM8350_RTC_ALMMINS_SHIFT;
+
+       tm->tm_hour = time[1] & WM8350_RTC_ALMHRS_MASK;
+       if (tm->tm_hour == WM8350_RTC_ALMHRS_MASK)
+               tm->tm_hour = -1;
+
+       tm->tm_wday = ((time[1] >> WM8350_RTC_ALMDAY_SHIFT) & 0x7) - 1;
+       if (tm->tm_wday > 7)
+               tm->tm_wday = -1;
+
+       tm->tm_mon = time[2] & WM8350_RTC_ALMMTH_MASK;
+       if (tm->tm_mon == WM8350_RTC_ALMMTH_MASK)
+               tm->tm_mon = -1;
+       else
+               tm->tm_mon = (tm->tm_mon >> WM8350_RTC_ALMMTH_SHIFT) - 1;
+
+       tm->tm_mday = (time[2] & WM8350_RTC_ALMDATE_MASK);
+       if (tm->tm_mday == WM8350_RTC_ALMDATE_MASK)
+               tm->tm_mday = -1;
+
+       tm->tm_year = -1;
+
+       alrm->enabled = !(time[3] & WM8350_RTC_ALMSTS);
+
+       return 0;
+}
+
+static int wm8350_rtc_stop_alarm(struct wm8350 *wm8350)
+{
+       int retries = WM8350_SET_ALM_RETRIES;
+       u16 rtc_ctrl;
+       int ret;
+
+       /* Set RTC_SET to stop the clock */
+       ret = wm8350_set_bits(wm8350, WM8350_RTC_TIME_CONTROL,
+                             WM8350_RTC_ALMSET);
+       if (ret < 0)
+               return ret;
+
+       /* Wait until confirmation of stopping */
+       do {
+               rtc_ctrl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);
+               schedule_timeout_uninterruptible(msecs_to_jiffies(1));
+       } while (retries-- && !(rtc_ctrl & WM8350_RTC_ALMSTS));
+
+       if (!(rtc_ctrl & WM8350_RTC_ALMSTS))
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+static int wm8350_rtc_start_alarm(struct wm8350 *wm8350)
+{
+       int ret;
+       int retries = WM8350_SET_ALM_RETRIES;
+       u16 rtc_ctrl;
+
+       ret = wm8350_clear_bits(wm8350, WM8350_RTC_TIME_CONTROL,
+                               WM8350_RTC_ALMSET);
+       if (ret < 0)
+               return ret;
+
+       /* Wait until confirmation */
+       do {
+               rtc_ctrl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);
+               schedule_timeout_uninterruptible(msecs_to_jiffies(1));
+       } while (retries-- && rtc_ctrl & WM8350_RTC_ALMSTS);
+
+       if (rtc_ctrl & WM8350_RTC_ALMSTS)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+static int wm8350_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+       struct rtc_time *tm = &alrm->time;
+       u16 time[3];
+       int ret;
+
+       memset(time, 0, sizeof(time));
+
+       if (tm->tm_sec != -1)
+               time[0] |= tm->tm_sec;
+       else
+               time[0] |= WM8350_RTC_ALMSECS_MASK;
+
+       if (tm->tm_min != -1)
+               time[0] |= tm->tm_min << WM8350_RTC_ALMMINS_SHIFT;
+       else
+               time[0] |= WM8350_RTC_ALMMINS_MASK;
+
+       if (tm->tm_hour != -1)
+               time[1] |= tm->tm_hour;
+       else
+               time[1] |= WM8350_RTC_ALMHRS_MASK;
+
+       if (tm->tm_wday != -1)
+               time[1] |= (tm->tm_wday + 1) << WM8350_RTC_ALMDAY_SHIFT;
+       else
+               time[1] |= WM8350_RTC_ALMDAY_MASK;
+
+       if (tm->tm_mday != -1)
+               time[2] |= tm->tm_mday;
+       else
+               time[2] |= WM8350_RTC_ALMDATE_MASK;
+
+       if (tm->tm_mon != -1)
+               time[2] |= (tm->tm_mon + 1) << WM8350_RTC_ALMMTH_SHIFT;
+       else
+               time[2] |= WM8350_RTC_ALMMTH_MASK;
+
+       ret = wm8350_rtc_stop_alarm(wm8350);
+       if (ret < 0)
+               return ret;
+
+       /* Write time to RTC */
+       ret = wm8350_block_write(wm8350, WM8350_ALARM_SECONDS_MINUTES,
+                                3, time);
+       if (ret < 0)
+               return ret;
+
+       if (alrm->enabled)
+               ret = wm8350_rtc_start_alarm(wm8350);
+
+       return ret;
+}
+
+/*
+ * Handle commands from user-space
+ */
+static int wm8350_rtc_ioctl(struct device *dev, unsigned int cmd,
+                           unsigned long arg)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+
+       switch (cmd) {
+       case RTC_AIE_OFF:
+               return wm8350_rtc_stop_alarm(wm8350);
+       case RTC_AIE_ON:
+               return wm8350_rtc_start_alarm(wm8350);
+
+       case RTC_UIE_OFF:
+               wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
+               break;
+       case RTC_UIE_ON:
+               wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_SEC);
+               break;
+
+       default:
+               return -ENOIOCTLCMD;
+       }
+
+       return 0;
+}
+
+static void wm8350_rtc_alarm_handler(struct wm8350 *wm8350, int irq,
+                                    void *data)
+{
+       struct rtc_device *rtc = wm8350->rtc.rtc;
+       int ret;
+
+       rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF);
+
+       /* Make it one shot */
+       ret = wm8350_set_bits(wm8350, WM8350_RTC_TIME_CONTROL,
+                             WM8350_RTC_ALMSET);
+       if (ret != 0) {
+               dev_err(&(wm8350->rtc.pdev->dev),
+                       "Failed to disable alarm: %d\n", ret);
+       }
+}
+
+static void wm8350_rtc_update_handler(struct wm8350 *wm8350, int irq,
+                                     void *data)
+{
+       struct rtc_device *rtc = wm8350->rtc.rtc;
+
+       rtc_update_irq(rtc, 1, RTC_IRQF | RTC_UF);
+}
+
+static const struct rtc_class_ops wm8350_rtc_ops = {
+       .ioctl = wm8350_rtc_ioctl,
+       .read_time = wm8350_rtc_readtime,
+       .set_time = wm8350_rtc_settime,
+       .read_alarm = wm8350_rtc_readalarm,
+       .set_alarm = wm8350_rtc_setalarm,
+};
+
+#ifdef CONFIG_PM
+static int wm8350_rtc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
+       int ret = 0;
+       u16 reg;
+
+       reg = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);
+
+       if (device_may_wakeup(&wm8350->rtc.pdev->dev) &&
+           reg & WM8350_RTC_ALMSTS) {
+               ret = wm8350_rtc_stop_alarm(wm8350);
+               if (ret != 0)
+                       dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n",
+                               ret);
+       }
+
+       return ret;
+}
+
+static int wm8350_rtc_resume(struct platform_device *pdev)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
+       int ret;
+
+       if (wm8350->rtc.alarm_enabled) {
+               ret = wm8350_rtc_start_alarm(wm8350);
+               if (ret != 0)
+                       dev_err(&pdev->dev,
+                               "Failed to restart RTC alarm: %d\n", ret);
+       }
+
+       return 0;
+}
+
+#else
+#define wm8350_rtc_suspend NULL
+#define wm8350_rtc_resume NULL
+#endif
+
+static int wm8350_rtc_probe(struct platform_device *pdev)
+{
+       struct wm8350 *wm8350 = platform_get_drvdata(pdev);
+       struct wm8350_rtc *wm_rtc = &wm8350->rtc;
+       int ret = 0;
+       u16 timectl, power5;
+
+       timectl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL);
+       if (timectl & WM8350_RTC_BCD) {
+               dev_err(&pdev->dev, "RTC BCD mode not supported\n");
+               return -EINVAL;
+       }
+       if (timectl & WM8350_RTC_12HR) {
+               dev_err(&pdev->dev, "RTC 12 hour mode not supported\n");
+               return -EINVAL;
+       }
+
+       /* enable the RTC if it's not already enabled */
+       power5 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5);
+       if (!(power5 &  WM8350_RTC_TICK_ENA)) {
+               dev_info(wm8350->dev, "Starting RTC\n");
+
+               wm8350_reg_unlock(wm8350);
+
+               ret = wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5,
+                                     WM8350_RTC_TICK_ENA);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "failed to enable RTC: %d\n", ret);
+                       return ret;
+               }
+
+               wm8350_reg_lock(wm8350);
+       }
+
+       if (timectl & WM8350_RTC_STS) {
+               int retries;
+
+               ret = wm8350_clear_bits(wm8350, WM8350_RTC_TIME_CONTROL,
+                                       WM8350_RTC_SET);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "failed to start: %d\n", ret);
+                       return ret;
+               }
+
+               retries = WM8350_SET_TIME_RETRIES;
+               do {
+                       timectl = wm8350_reg_read(wm8350,
+                                                 WM8350_RTC_TIME_CONTROL);
+               } while (timectl & WM8350_RTC_STS && retries--);
+
+               if (retries == 0) {
+                       dev_err(&pdev->dev, "failed to start: timeout\n");
+                       return -ENODEV;
+               }
+       }
+
+       device_init_wakeup(&pdev->dev, 1);
+
+       wm_rtc->rtc = rtc_device_register("wm8350", &pdev->dev,
+                                         &wm8350_rtc_ops, THIS_MODULE);
+       if (IS_ERR(wm_rtc->rtc)) {
+               ret = PTR_ERR(wm_rtc->rtc);
+               dev_err(&pdev->dev, "failed to register RTC: %d\n", ret);
+               return ret;
+       }
+
+       wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
+       wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_PER);
+
+       wm8350_register_irq(wm8350, WM8350_IRQ_RTC_SEC,
+                           wm8350_rtc_update_handler, NULL);
+
+       wm8350_register_irq(wm8350, WM8350_IRQ_RTC_ALM,
+                           wm8350_rtc_alarm_handler, NULL);
+       wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_ALM);
+
+       return 0;
+}
+
+static int __devexit wm8350_rtc_remove(struct platform_device *pdev)
+{
+       struct wm8350 *wm8350 = platform_get_drvdata(pdev);
+       struct wm8350_rtc *wm_rtc = &wm8350->rtc;
+
+       wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
+
+       wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC);
+       wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM);
+
+       rtc_device_unregister(wm_rtc->rtc);
+
+       return 0;
+}
+
+static struct platform_driver wm8350_rtc_driver = {
+       .probe = wm8350_rtc_probe,
+       .remove = __devexit_p(wm8350_rtc_remove),
+       .suspend = wm8350_rtc_suspend,
+       .resume = wm8350_rtc_resume,
+       .driver = {
+               .name = "wm8350-rtc",
+       },
+};
+
+static int __init wm8350_rtc_init(void)
+{
+       return platform_driver_register(&wm8350_rtc_driver);
+}
+module_init(wm8350_rtc_init);
+
+static void __exit wm8350_rtc_exit(void)
+{
+       platform_driver_unregister(&wm8350_rtc_driver);
+}
+module_exit(wm8350_rtc_exit);
+
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
+MODULE_DESCRIPTION("RTC driver for the WM8350");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:wm8350-rtc");
index 4b76fca64a6f1bf5538c8babc8595b15a234aa8e..363bd1303d217aa4904ea088549e8f0bb9f23618 100644 (file)
@@ -1746,6 +1746,11 @@ restart:
                        goto restart;
                }
 
+               /* log sense for fatal error */
+               if (cqr->status == DASD_CQR_FAILED) {
+                       dasd_log_sense(cqr, &cqr->irb);
+               }
+
                /* First of all call extended error reporting. */
                if (dasd_eer_enabled(base) &&
                    cqr->status == DASD_CQR_FAILED) {
index eb5f1b8bc57fd0546c94067a5b57364f3db1addf..ec9c0bcf66eeefd8ee9029675cc193d0af328b0f 100644 (file)
@@ -324,6 +324,9 @@ static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
        case 0x0120:
                break;
        default:
+               pr_warning("assign storage failed (cmd=0x%08x, "
+                          "response=0x%04x, rn=0x%04x)\n", cmd,
+                          sccb->header.response_code, rn);
                rc = -EIO;
                break;
        }
index 4e78c82194b47520c271be8617ac5202644d395c..4e4008325e281edc58f11b3a211506b3f8bac35a 100644 (file)
@@ -874,11 +874,15 @@ void ccw_device_move_to_orphanage(struct work_struct *work)
        replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
        if (replacing_cdev) {
                sch_attach_disconnected_device(sch, replacing_cdev);
+               /* Release reference from get_disc_ccwdev_by_dev_id() */
+               put_device(&cdev->dev);
                return;
        }
        replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
        if (replacing_cdev) {
                sch_attach_orphaned_device(sch, replacing_cdev);
+               /* Release reference from get_orphaned_ccwdev_by_dev_id() */
+               put_device(&cdev->dev);
                return;
        }
        sch_create_and_recog_new_device(sch);
index ff4a6931bb8e680b4f429577fc81e481df4cd786..3d442444c618ccb431d7e4d6b6e1b5bc4f16924b 100644 (file)
@@ -322,13 +322,13 @@ static int __init kvm_devices_init(void)
                return rc;
        }
 
-       rc = vmem_add_mapping(PFN_PHYS(max_pfn), PAGE_SIZE);
+       rc = vmem_add_mapping(real_memory_size, PAGE_SIZE);
        if (rc) {
                s390_root_dev_unregister(kvm_root);
                return rc;
        }
 
-       kvm_devices = (void *) PFN_PHYS(max_pfn);
+       kvm_devices = (void *) real_memory_size;
 
        ctl_set_bit(0, 9);
        register_external_interrupt(0x2603, kvm_extint_handler);
index 3b56220fb900291df60b56284191b6e66119a02d..3d4e3e3f3fc07c873846d75b56d6e338c54475ce 100644 (file)
@@ -610,7 +610,8 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
        atomic_set_mask(status | ZFCP_STATUS_COMMON_REMOVE, &port->status);
        atomic_set(&port->refcount, 0);
 
-       dev_set_name(&port->sysfs_device, "0x%016llx", wwpn);
+       dev_set_name(&port->sysfs_device, "0x%016llx",
+                    (unsigned long long)wwpn);
        port->sysfs_device.parent = &adapter->ccw_device->dev;
 
        port->sysfs_device.release = zfcp_sysfs_port_release;
index b04038c74786b32456ded58505b96efd7f4c1756..951a8d409d1d5faa787a058d3f3542f13c9852c6 100644 (file)
@@ -116,7 +116,9 @@ static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
        zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
                                NULL);
        zfcp_erp_wait(adapter);
-       goto out;
+       up(&zfcp_data.config_sema);
+       flush_work(&adapter->scan_work);
+       return 0;
 
  out_scsi_register:
        zfcp_erp_thread_kill(adapter);
index 060f5f2352ecb590b74e8667bb703fb1c0e62bc1..31012d58cfb760fb457862bfd596da12f8532310 100644 (file)
@@ -30,7 +30,7 @@ static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
                dump->offset = offset;
                dump->size = min(from_len - offset, room);
                memcpy(dump->data, from + offset, dump->size);
-               debug_event(dbf, level, dump, dump->size);
+               debug_event(dbf, level, dump, dump->size + sizeof(*dump));
        }
 }
 
@@ -108,7 +108,7 @@ static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
                             t.tv_sec, t.tv_nsec);
                zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
        } else  {
-               zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
+               zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
                              dump->total_size);
                if ((dump->offset + dump->size) == dump->total_size)
                        p += sprintf(p, "\n");
@@ -366,6 +366,7 @@ static void zfcp_hba_dbf_view_response(char **p,
                        break;
                zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
                zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
+               p += sprintf(*p, "\n");
                break;
 
        case FSF_QTCB_OPEN_PORT_WITH_DID:
@@ -465,7 +466,8 @@ static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
        else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
                zfcp_hba_dbf_view_berr(&p, &r->u.berr);
 
-       p += sprintf(p, "\n");
+       if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
+               p += sprintf(p, "\n");
        return p - out_buf;
 }
 
@@ -880,6 +882,7 @@ void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
        struct ct_hdr *hdr = sg_virt(ct->req);
        struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
        struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
+       int level = 3;
        unsigned long flags;
 
        spin_lock_irqsave(&adapter->san_dbf_lock, flags);
@@ -896,9 +899,10 @@ void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
        oct->options = hdr->options;
        oct->max_res_size = hdr->max_res_size;
        oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
-                      ZFCP_DBF_CT_PAYLOAD);
-       memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
-       debug_event(adapter->san_dbf, 3, r, sizeof(*r));
+                      ZFCP_DBF_SAN_MAX_PAYLOAD);
+       debug_event(adapter->san_dbf, level, r, sizeof(*r));
+       zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
+                        (void *)hdr + sizeof(struct ct_hdr), oct->len);
        spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
 }
 
@@ -914,6 +918,7 @@ void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
        struct ct_hdr *hdr = sg_virt(ct->resp);
        struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
        struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
+       int level = 3;
        unsigned long flags;
 
        spin_lock_irqsave(&adapter->san_dbf_lock, flags);
@@ -929,9 +934,10 @@ void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
        rct->expl = hdr->reason_code_expl;
        rct->vendor_unique = hdr->vendor_unique;
        rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
-                      ZFCP_DBF_CT_PAYLOAD);
-       memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
-       debug_event(adapter->san_dbf, 3, r, sizeof(*r));
+                      ZFCP_DBF_SAN_MAX_PAYLOAD);
+       debug_event(adapter->san_dbf, level, r, sizeof(*r));
+       zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
+                        (void *)hdr + sizeof(struct ct_hdr), rct->len);
        spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
 }
 
@@ -954,7 +960,7 @@ static void zfcp_san_dbf_event_els(const char *tag, int level,
        rec->u.els.ls_code = ls_code;
        debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
        zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
-                        buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
+                        buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
        spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
 }
 
@@ -1008,8 +1014,6 @@ static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
                                    char *out_buf, const char *in_buf)
 {
        struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
-       char *buffer = NULL;
-       int buflen = 0, total = 0;
        char *p = out_buf;
 
        if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
@@ -1029,9 +1033,6 @@ static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
                zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
                zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
                zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
-               total = ct->len;
-               buffer = ct->payload;
-               buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
        } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
                struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
                zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
@@ -1039,23 +1040,12 @@ static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
                zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
                zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
                zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
-               total = ct->len;
-               buffer = ct->payload;
-               buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
        } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
                   strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
                   strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
                struct zfcp_san_dbf_record_els *els = &r->u.els;
                zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
-               total = els->len;
-               buffer = els->payload;
-               buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
        }
-
-       zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
-       if (buflen == total)
-               p += sprintf(p, "\n");
-
        return p - out_buf;
 }
 
index e8f450801fea7f1cd351b7dad1049d02f82ab238..5d6b2dff855bb44e46d7fa6c65f93791b0bf1dfa 100644 (file)
@@ -163,8 +163,6 @@ struct zfcp_san_dbf_record_ct_request {
        u8 options;
        u16 max_res_size;
        u32 len;
-#define ZFCP_DBF_CT_PAYLOAD    24
-       u8 payload[ZFCP_DBF_CT_PAYLOAD];
 } __attribute__ ((packed));
 
 struct zfcp_san_dbf_record_ct_response {
@@ -174,15 +172,11 @@ struct zfcp_san_dbf_record_ct_response {
        u8 expl;
        u8 vendor_unique;
        u32 len;
-       u8 payload[ZFCP_DBF_CT_PAYLOAD];
 } __attribute__ ((packed));
 
 struct zfcp_san_dbf_record_els {
        u8 ls_code;
        u32 len;
-#define ZFCP_DBF_ELS_PAYLOAD   32
-#define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
-       u8 payload[ZFCP_DBF_ELS_PAYLOAD];
 } __attribute__ ((packed));
 
 struct zfcp_san_dbf_record {
@@ -196,6 +190,8 @@ struct zfcp_san_dbf_record {
                struct zfcp_san_dbf_record_ct_response ct_resp;
                struct zfcp_san_dbf_record_els els;
        } u;
+#define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
+       u8 payload[32];
 } __attribute__ ((packed));
 
 struct zfcp_scsi_dbf_record {
index 9040f738ff333f47fd243486c311380f0ea00ebe..35364f64da7ff27ce7c740f3bde2a121df3d8556 100644 (file)
@@ -472,6 +472,7 @@ static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
                                   ZFCP_STATUS_ERP_TIMEDOUT)) {
                        act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
                        zfcp_rec_dbf_event_action(142, act);
+                       act->fsf_req->erp_action = NULL;
                }
                if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
                        zfcp_rec_dbf_event_action(143, act);
index 5ae1d497e5ed21f9061d36331a5a75ee63934b76..d024442ee128d9ee04ec44c5fe6b43e9ec099959 100644 (file)
@@ -683,6 +683,7 @@ static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
        if (!req)
                return NULL;
        memset(req, 0, sizeof(*req));
+       req->pool = pool;
        return req;
 }
 
@@ -769,28 +770,24 @@ static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
 {
        struct zfcp_adapter *adapter = req->adapter;
-       struct zfcp_qdio_queue *req_q = &adapter->req_q;
+       unsigned long flags;
        int idx;
 
        /* put allocated FSF request into hash table */
-       spin_lock(&adapter->req_list_lock);
+       spin_lock_irqsave(&adapter->req_list_lock, flags);
        idx = zfcp_reqlist_hash(req->req_id);
        list_add_tail(&req->list, &adapter->req_list[idx]);
-       spin_unlock(&adapter->req_list_lock);
+       spin_unlock_irqrestore(&adapter->req_list_lock, flags);
 
-       req->qdio_outb_usage = atomic_read(&req_q->count);
+       req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
        req->issued = get_clock();
        if (zfcp_qdio_send(req)) {
-               /* Queues are down..... */
                del_timer(&req->timer);
-               spin_lock(&adapter->req_list_lock);
-               zfcp_reqlist_remove(adapter, req);
-               spin_unlock(&adapter->req_list_lock);
-               /* undo changes in request queue made for this request */
-               atomic_add(req->sbal_number, &req_q->count);
-               req_q->first -= req->sbal_number;
-               req_q->first += QDIO_MAX_BUFFERS_PER_Q;
-               req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
+               spin_lock_irqsave(&adapter->req_list_lock, flags);
+               /* lookup request again, list might have changed */
+               if (zfcp_reqlist_find_safe(adapter, req))
+                       zfcp_reqlist_remove(adapter, req);
+               spin_unlock_irqrestore(&adapter->req_list_lock, flags);
                zfcp_erp_adapter_reopen(adapter, 0, 116, req);
                return -EIO;
        }
index ca8f85f3dad439f515e25b8e5b049a0edd3701ee..e46fd3e9f68fb85ff3dc9899e454772b5bb33a39 100644 (file)
@@ -24,14 +24,10 @@ char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
 static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
 {
        struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
-       WARN_ON(!unit);
-       if (unit) {
-               atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
-               sdpnt->hostdata = NULL;
-               unit->device = NULL;
-               zfcp_erp_unit_failed(unit, 12, NULL);
-               zfcp_unit_put(unit);
-       }
+       atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
+       unit->device = NULL;
+       zfcp_erp_unit_failed(unit, 12, NULL);
+       zfcp_unit_put(unit);
 }
 
 static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
index 8aba4fdfb5222b40d93a8e231fd1b69858ddecdc..6194ed5d02c4e694bc2bfbe3faf9a56860a2ade5 100644 (file)
@@ -2445,7 +2445,7 @@ static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
        hba_status = detailed_status >> 8;
 
        // calculate resid for sg 
-       scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+5));
+       scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+20));
 
        pHba = (adpt_hba*) cmd->device->host->hostdata[0];
 
@@ -2456,7 +2456,7 @@ static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
                case I2O_SCSI_DSC_SUCCESS:
                        cmd->result = (DID_OK << 16);
                        // handle underflow
-                       if(readl(reply+5) < cmd->underflow ) {
+                       if (readl(reply+20) < cmd->underflow) {
                                cmd->result = (DID_ERROR <<16);
                                printk(KERN_WARNING"%s: SCSI CMD underflow\n",pHba->name);
                        }
index 28c9da7d4a5c5f0aad97c0a41f964c8994c4d228..7dc62deb4087cead7dfeed562cc3e9bc4a5c9011 100644 (file)
@@ -4402,6 +4402,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru)
        scb_t   *scb;
        int     rval;
 
+       scmd = scsi_allocate_command(GFP_KERNEL);
+       if (!scmd)
+               return -ENOMEM;
+
        /*
         * The internal commands share one command id and hence are
         * serialized. This is so because we want to reserve maximum number of
@@ -4412,12 +4416,11 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru)
        scb = &adapter->int_scb;
        memset(scb, 0, sizeof(scb_t));
 
-       scmd = &adapter->int_scmd;
-       memset(scmd, 0, sizeof(Scsi_Cmnd));
-
        sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
        scmd->device = sdev;
 
+       memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
+       scmd->cmnd = adapter->int_cdb;
        scmd->device->host = adapter->host;
        scmd->host_scribble = (void *)scb;
        scmd->cmnd[0] = MEGA_INTERNAL_CMD;
@@ -4456,6 +4459,8 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru)
 
        mutex_unlock(&adapter->int_mtx);
 
+       scsi_free_command(GFP_KERNEL, scmd);
+
        return rval;
 }
 
index ee70bd4ae4badc0f2f7a82eb0a523d5702c796f4..795201fa0b487d1a23113f38534666d90d23ec49 100644 (file)
@@ -888,8 +888,8 @@ typedef struct {
 
        u8      sglen;  /* f/w supported scatter-gather list length */
 
+       unsigned char int_cdb[MAX_COMMAND_SIZE];
        scb_t                   int_scb;
-       Scsi_Cmnd               int_scmd;
        struct mutex            int_mtx;        /* To synchronize the internal
                                                commands */
        struct completion       int_waitq;      /* wait queue for internal
index f25f41a499e5ed7be7ebd3dc109d4d4b14c9494a..b97194096d8e6a285f55389360bf92691c6cf471 100644 (file)
@@ -2547,7 +2547,6 @@ typedef struct scsi_qla_host {
        uint8_t         fcode_revision[16];
        uint32_t        fw_revision[4];
 
-       uint16_t        fdt_odd_index;
        uint32_t        fdt_wrt_disable;
        uint32_t        fdt_erase_cmd;
        uint32_t        fdt_block_size;
index a470f2d3270d205ad35ee26519a25e9d37f90252..4218f20f5ed5256b35a61862a73424e7c581d712 100644 (file)
@@ -140,7 +140,6 @@ int
 qla2100_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t w;
-       uint32_t d;
        unsigned long flags;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
 
@@ -151,10 +150,7 @@ qla2100_pci_config(scsi_qla_host_t *ha)
        w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
        pci_write_config_word(ha->pdev, PCI_COMMAND, w);
 
-       /* Reset expansion ROM address decode enable */
-       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
-       d &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
+       pci_disable_rom(ha->pdev);
 
        /* Get PCI bus information. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -174,7 +170,6 @@ int
 qla2300_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t        w;
-       uint32_t        d;
        unsigned long   flags = 0;
        uint32_t        cnt;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
@@ -236,10 +231,7 @@ qla2300_pci_config(scsi_qla_host_t *ha)
 
        pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
 
-       /* Reset expansion ROM address decode enable */
-       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
-       d &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
+       pci_disable_rom(ha->pdev);
 
        /* Get PCI bus information. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -259,7 +251,6 @@ int
 qla24xx_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t w;
-       uint32_t d;
        unsigned long flags = 0;
        struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
 
@@ -281,10 +272,7 @@ qla24xx_pci_config(scsi_qla_host_t *ha)
        if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
                pcie_set_readrq(ha->pdev, 2048);
 
-       /* Reset expansion ROM address decode enable */
-       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
-       d &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
+       pci_disable_rom(ha->pdev);
 
        ha->chip_revision = ha->pdev->revision;
 
@@ -306,7 +294,6 @@ int
 qla25xx_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t w;
-       uint32_t d;
 
        pci_set_master(ha->pdev);
        pci_try_set_mwi(ha->pdev);
@@ -320,10 +307,7 @@ qla25xx_pci_config(scsi_qla_host_t *ha)
        if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
                pcie_set_readrq(ha->pdev, 2048);
 
-       /* Reset expansion ROM address decode enable */
-       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
-       d &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
+       pci_disable_rom(ha->pdev);
 
        ha->chip_revision = ha->pdev->revision;
 
@@ -980,7 +964,6 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
                                    &ha->fw_minor_version,
                                    &ha->fw_subminor_version,
                                    &ha->fw_attributes, &ha->fw_memory_size);
-                               qla2x00_resize_request_q(ha);
                                ha->flags.npiv_supported = 0;
                                if ((IS_QLA24XX(ha) || IS_QLA25XX(ha) ||
                                     IS_QLA84XX(ha)) &&
@@ -992,6 +975,7 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
                                                ha->max_npiv_vports =
                                                    MIN_MULTI_ID_FABRIC - 1;
                                }
+                               qla2x00_resize_request_q(ha);
 
                                if (ql2xallocfwdump)
                                        qla2x00_alloc_fw_dump(ha);
index 36bc6851e23dd2b13cfbbe98a6a14eac5faf0c07..3402746ec128a54115ac1880acbba27b7da6541f 100644 (file)
@@ -1964,7 +1964,7 @@ qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
                        *cur_iocb_cnt = mcp->mb[7];
                if (orig_iocb_cnt)
                        *orig_iocb_cnt = mcp->mb[10];
-               if (max_npiv_vports)
+               if (ha->flags.npiv_supported && max_npiv_vports)
                        *max_npiv_vports = mcp->mb[11];
        }
 
index 21dd182ad512214c7646299a1af4ad4f2e9d9e88..35567203ef611bc730df2fde134c036b6e124107 100644 (file)
@@ -728,6 +728,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
                if (ha->isp_ops->abort_command(ha, sp)) {
                        DEBUG2(printk("%s(%ld): abort_command "
                            "mbx failed.\n", __func__, ha->host_no));
+                       ret = FAILED;
                } else {
                        DEBUG3(printk("%s(%ld): abort_command "
                            "mbx success.\n", __func__, ha->host_no));
index 90a13211717f7d367a89c3b7f0b74fc5dd0f113c..e4af678eb2d62ca071f6d04a2461074d611d089a 100644 (file)
@@ -722,6 +722,7 @@ done:
 static void
 qla2xxx_get_fdt_info(scsi_qla_host_t *ha)
 {
+#define FLASH_BLK_SIZE_4K      0x1000
 #define FLASH_BLK_SIZE_32K     0x8000
 #define FLASH_BLK_SIZE_64K     0x10000
        const char *loc, *locations[] = { "MID", "FDT" };
@@ -755,7 +756,6 @@ qla2xxx_get_fdt_info(scsi_qla_host_t *ha)
        loc = locations[1];
        mid = le16_to_cpu(fdt->man_id);
        fid = le16_to_cpu(fdt->id);
-       ha->fdt_odd_index = mid == 0x1f;
        ha->fdt_wrt_disable = fdt->wrt_disable_bits;
        ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0300 | fdt->erase_cmd);
        ha->fdt_block_size = le32_to_cpu(fdt->block_size);
@@ -788,8 +788,7 @@ no_flash_data:
                ha->fdt_block_size = FLASH_BLK_SIZE_64K;
                break;
        case 0x1f: /* Atmel 26DF081A. */
-               ha->fdt_odd_index = 1;
-               ha->fdt_block_size = FLASH_BLK_SIZE_64K;
+               ha->fdt_block_size = FLASH_BLK_SIZE_4K;
                ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0320);
                ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0339);
                ha->fdt_protect_sec_cmd = flash_conf_to_access_addr(0x0336);
@@ -801,9 +800,9 @@ no_flash_data:
        }
 done:
        DEBUG2(qla_printk(KERN_DEBUG, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
-           "pro=%x upro=%x idx=%d wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
+           "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
            ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
-           ha->fdt_unprotect_sec_cmd, ha->fdt_odd_index, ha->fdt_wrt_disable,
+           ha->fdt_unprotect_sec_cmd, ha->fdt_wrt_disable,
            ha->fdt_block_size));
 }
 
@@ -987,13 +986,9 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
        qla24xx_unprotect_flash(ha);
 
        for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
-               if (ha->fdt_odd_index) {
-                       findex = faddr << 2;
-                       fdata = findex & sec_mask;
-               } else {
-                       findex = faddr;
-                       fdata = (findex & sec_mask) << 2;
-               }
+
+               findex = faddr;
+               fdata = (findex & sec_mask) << 2;
 
                /* Are we at the beginning of a sector? */
                if ((findex & rest_addr) == 0) {
index be5e299df528e22eed62f8ac25d03c01a11630d7..eea6720adf1693c8521851f57e8b15bb1b87880b 100644 (file)
@@ -7,7 +7,7 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION      "8.02.01-k8"
+#define QLA2XXX_VERSION      "8.02.01-k9"
 
 #define QLA_DRIVER_MAJOR_VER   8
 #define QLA_DRIVER_MINOR_VER   2
index 94ed262bdf0c7731040c0112d955ded856fe96e4..386361778ebb32d859c6770971329f46d55ae23e 100644 (file)
@@ -1340,9 +1340,10 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
                 * LLD/transport was disrupted during processing of the IO.
                 * The transport class is now blocked/blocking,
                 * and the transport will decide what to do with the IO
-                * based on its timers and recovery capablilities.
+                * based on its timers and recovery capablilities if
+                * there are enough retries.
                 */
-               return ADD_TO_MLQUEUE;
+               goto maybe_retry;
        case DID_TRANSPORT_FAILFAST:
                /*
                 * The transport decided to failfast the IO (most likely
index 02f9320f3efcf25000393284e7823f9089d0b7f3..8abae4ad0fa528565427ec050555142924dc7b99 100644 (file)
@@ -766,6 +766,7 @@ static int __init atmel_spi_probe(struct platform_device *pdev)
        /* Initialize the hardware */
        clk_enable(clk);
        spi_writel(as, CR, SPI_BIT(SWRST));
+       spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
        spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
        spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
        spi_writel(as, CR, SPI_BIT(SPIEN));
@@ -782,6 +783,7 @@ static int __init atmel_spi_probe(struct platform_device *pdev)
 
 out_reset_hw:
        spi_writel(as, CR, SPI_BIT(SWRST));
+       spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
        clk_disable(clk);
        free_irq(irq, master);
 out_unmap_regs:
@@ -805,6 +807,7 @@ static int __exit atmel_spi_remove(struct platform_device *pdev)
        spin_lock_irq(&as->lock);
        as->stopping = 1;
        spi_writel(as, CR, SPI_BIT(SWRST));
+       spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
        spi_readl(as, SR);
        spin_unlock_irq(&as->lock);
 
index 20104443081ad1fc260d4ba74f17a0c9828eca69..d50a99f70aee8d33941e5445f62bef41778093d3 100644 (file)
@@ -158,16 +158,12 @@ static int acm_wb_is_avail(struct acm *acm)
 }
 
 /*
- * Finish write.
+ * Finish write. Caller must hold acm->write_lock
  */
 static void acm_write_done(struct acm *acm, struct acm_wb *wb)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&acm->write_lock, flags);
        wb->use = 0;
        acm->transmitting--;
-       spin_unlock_irqrestore(&acm->write_lock, flags);
 }
 
 /*
@@ -482,6 +478,7 @@ static void acm_write_bulk(struct urb *urb)
 {
        struct acm_wb *wb = urb->context;
        struct acm *acm = wb->instance;
+       unsigned long flags;
 
        if (verbose || urb->status
                        || (urb->actual_length != urb->transfer_buffer_length))
@@ -490,7 +487,9 @@ static void acm_write_bulk(struct urb *urb)
                        urb->transfer_buffer_length,
                        urb->status);
 
+       spin_lock_irqsave(&acm->write_lock, flags);
        acm_write_done(acm, wb);
+       spin_unlock_irqrestore(&acm->write_lock, flags);
        if (ACM_READY(acm))
                schedule_work(&acm->work);
        else
index 887738577b2838df3e02f93c05a9fe32a48b0606..6d1048faf08e1679597af0fadd6a5849d3afd299 100644 (file)
@@ -1091,6 +1091,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
                                continue;
                        dev_dbg(&dev->dev, "unregistering interface %s\n",
                                dev_name(&interface->dev));
+                       interface->unregistering = 1;
                        usb_remove_sysfs_intf_files(interface);
                        device_del(&interface->dev);
                }
index f66fba11fbd53f2eeaf5a5ebc17a9d8251c526db..4fb65fdc9dc36bb51eb25059789886fbd1dfe857 100644 (file)
@@ -840,7 +840,7 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
        struct usb_host_interface *alt = intf->cur_altsetting;
        int retval;
 
-       if (intf->sysfs_files_created)
+       if (intf->sysfs_files_created || intf->unregistering)
                return 0;
 
        /* The interface string may be present in some altsettings
index 4342bd9c3bb610d9582217aae0bc524378a28a7f..1f68af9db3f7d6bed13bcab914eb238b638b5bee 100644 (file)
@@ -85,8 +85,8 @@ EXPORT_SYMBOL_GPL(usb_alloc_urb);
  * Must be called when a user of a urb is finished with it.  When the last user
  * of the urb calls this function, the memory of the urb is freed.
  *
- * Note: The transfer buffer associated with the urb is not freed, that must be
- * done elsewhere.
+ * Note: The transfer buffer associated with the urb is not freed unless the
+ * URB_FREE_BUFFER transfer flag is set.
  */
 void usb_free_urb(struct urb *urb)
 {
index 5ee1590b8e9cf2739e629804193aa8fa053954cf..c1d34df0b157c45f533b03b794bd14a929055f70 100644 (file)
@@ -463,7 +463,11 @@ static int acm_cdc_notify(struct f_acm *acm, u8 type, u16 value,
        notify->wLength = cpu_to_le16(length);
        memcpy(buf, data, length);
 
+       /* ep_queue() can complete immediately if it fills the fifo... */
+       spin_unlock(&acm->lock);
        status = usb_ep_queue(ep, req, GFP_ATOMIC);
+       spin_lock(&acm->lock);
+
        if (status < 0) {
                ERROR(acm->port.func.config->cdev,
                                "acm ttyGS%d can't notify serial state, %d\n",
index 56f592dc0b3626139f4e9b34dd191af967f30bf0..f3a75a929e0aa26dcdbaee0c75c0cfa10403f8bf 100644 (file)
@@ -110,29 +110,18 @@ config USB_ISP116X_HCD
 
 config USB_ISP1760_HCD
        tristate "ISP 1760 HCD support"
-       depends on USB && EXPERIMENTAL
+       depends on USB && EXPERIMENTAL && (PCI || PPC_OF)
        ---help---
          The ISP1760 chip is a USB 2.0 host controller.
 
          This driver does not support isochronous transfers or OTG.
+         This USB controller is usually attached to a non-DMA-Master
+         capable bus. NXP's eval kit brings this chip on PCI card
+         where the chip itself is behind a PLB to simulate such
+         a bus.
 
          To compile this driver as a module, choose M here: the
-         module will be called isp1760-hcd.
-
-config USB_ISP1760_PCI
-       bool "Support for the PCI bus"
-       depends on USB_ISP1760_HCD && PCI
-       ---help---
-         Enables support for the device present on the PCI bus.
-         This should only be required if you happen to have the eval kit from
-         NXP and you are going to test it.
-
-config USB_ISP1760_OF
-       bool "Support for the OF platform bus"
-       depends on USB_ISP1760_HCD && PPC_OF
-       ---help---
-         Enables support for the device present on the PowerPC
-         OpenFirmware platform bus.
+         module will be called isp1760.
 
 config USB_OHCI_HCD
        tristate "OHCI HCD support"
index 15a803b206b8ea72c4774ba6edb504a0fd5e964c..4725d15d096f559fc833d0e0f6323bcff4aa7631 100644 (file)
@@ -643,7 +643,7 @@ static int ehci_run (struct usb_hcd *hcd)
 static irqreturn_t ehci_irq (struct usb_hcd *hcd)
 {
        struct ehci_hcd         *ehci = hcd_to_ehci (hcd);
-       u32                     status, pcd_status = 0, cmd;
+       u32                     status, masked_status, pcd_status = 0, cmd;
        int                     bh;
 
        spin_lock (&ehci->lock);
@@ -656,14 +656,14 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
                goto dead;
        }
 
-       status &= INTR_MASK;
-       if (!status) {                  /* irq sharing? */
+       masked_status = status & INTR_MASK;
+       if (!masked_status) {           /* irq sharing? */
                spin_unlock(&ehci->lock);
                return IRQ_NONE;
        }
 
        /* clear (just) interrupts */
-       ehci_writel(ehci, status, &ehci->regs->status);
+       ehci_writel(ehci, masked_status, &ehci->regs->status);
        cmd = ehci_readl(ehci, &ehci->regs->command);
        bh = 0;
 
@@ -734,18 +734,17 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
 
        /* PCI errors [4.15.2.4] */
        if (unlikely ((status & STS_FATAL) != 0)) {
+               ehci_err(ehci, "fatal error\n");
                dbg_cmd(ehci, "fatal", cmd);
                dbg_status(ehci, "fatal", status);
-               if (status & STS_HALT) {
-                       ehci_err (ehci, "fatal error\n");
+               ehci_halt(ehci);
 dead:
-                       ehci_reset (ehci);
-                       ehci_writel(ehci, 0, &ehci->regs->configured_flag);
-                       /* generic layer kills/unlinks all urbs, then
-                        * uses ehci_stop to clean up the rest
-                        */
-                       bh = 1;
-               }
+               ehci_reset(ehci);
+               ehci_writel(ehci, 0, &ehci->regs->configured_flag);
+               /* generic layer kills/unlinks all urbs, then
+                * uses ehci_stop to clean up the rest
+                */
+               bh = 1;
        }
 
        if (bh)
index 0eba894bcb017aa0706f5e60224149e76338d99a..9c9da35abc6c010c6929a1e515fc4179ef898111 100644 (file)
@@ -205,6 +205,7 @@ static int ps3_ehci_remove(struct ps3_system_bus_device *dev)
 
        tmp = hcd->irq;
 
+       ehci_shutdown(hcd);
        usb_remove_hcd(hcd);
 
        ps3_system_bus_set_driver_data(dev, NULL);
index 4a0c5a78b2ed74358055e800d5181b1a1e2cb1c7..a081ee65bde6d933f3f2000c67028d461ece27c7 100644 (file)
@@ -918,7 +918,7 @@ iso_stream_init (
                 */
                stream->usecs = HS_USECS_ISO (maxp);
                bandwidth = stream->usecs * 8;
-               bandwidth /= 1 << (interval - 1);
+               bandwidth /= interval;
 
        } else {
                u32             addr;
@@ -951,7 +951,7 @@ iso_stream_init (
                } else
                        stream->raw_mask = smask_out [hs_transfers - 1];
                bandwidth = stream->usecs + stream->c_usecs;
-               bandwidth /= 1 << (interval + 2);
+               bandwidth /= interval << 3;
 
                /* stream->splits gets created from raw_mask later */
                stream->address = cpu_to_hc32(ehci, addr);
index af849f596135324bf727ac667f7f2d4cbc7d9920..b87ca7cf4b378f4ee0c6ee7ed403e629d79a38ea 100644 (file)
 #include "../core/hcd.h"
 #include "isp1760-hcd.h"
 
-#ifdef CONFIG_USB_ISP1760_OF
+#ifdef CONFIG_PPC_OF
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #endif
 
-#ifdef CONFIG_USB_ISP1760_PCI
+#ifdef CONFIG_PCI
 #include <linux/pci.h>
 #endif
 
-#ifdef CONFIG_USB_ISP1760_OF
+#ifdef CONFIG_PPC_OF
 static int of_isp1760_probe(struct of_device *dev,
                const struct of_device_id *match)
 {
@@ -128,7 +128,7 @@ static struct of_platform_driver isp1760_of_driver = {
 };
 #endif
 
-#ifdef CONFIG_USB_ISP1760_PCI
+#ifdef CONFIG_PCI
 static u32 nxp_pci_io_base;
 static u32 iolength;
 static u32 pci_mem_phy0;
@@ -288,28 +288,28 @@ static struct pci_driver isp1761_pci_driver = {
 
 static int __init isp1760_init(void)
 {
-       int ret = -ENODEV;
+       int ret;
 
        init_kmem_once();
 
-#ifdef CONFIG_USB_ISP1760_OF
+#ifdef CONFIG_PPC_OF
        ret = of_register_platform_driver(&isp1760_of_driver);
        if (ret) {
                deinit_kmem_cache();
                return ret;
        }
 #endif
-#ifdef CONFIG_USB_ISP1760_PCI
+#ifdef CONFIG_PCI
        ret = pci_register_driver(&isp1761_pci_driver);
        if (ret)
                goto unreg_of;
 #endif
        return ret;
 
-#ifdef CONFIG_USB_ISP1760_PCI
+#ifdef CONFIG_PCI
 unreg_of:
 #endif
-#ifdef CONFIG_USB_ISP1760_OF
+#ifdef CONFIG_PPC_OF
        of_unregister_platform_driver(&isp1760_of_driver);
 #endif
        deinit_kmem_cache();
@@ -319,10 +319,10 @@ module_init(isp1760_init);
 
 static void __exit isp1760_exit(void)
 {
-#ifdef CONFIG_USB_ISP1760_OF
+#ifdef CONFIG_PPC_OF
        of_unregister_platform_driver(&isp1760_of_driver);
 #endif
-#ifdef CONFIG_USB_ISP1760_PCI
+#ifdef CONFIG_PCI
        pci_unregister_driver(&isp1761_pci_driver);
 #endif
        deinit_kmem_cache();
index 2089d8a46c4bbedb0cd140dc5db4d0cee4cab908..3c1a3b5f89f19fb19dde0962b8b4e6a2e704b9e4 100644 (file)
@@ -192,7 +192,7 @@ fail_start:
        return result;
 }
 
-static int ps3_ohci_remove (struct ps3_system_bus_device *dev)
+static int ps3_ohci_remove(struct ps3_system_bus_device *dev)
 {
        unsigned int tmp;
        struct usb_hcd *hcd =
@@ -205,6 +205,7 @@ static int ps3_ohci_remove (struct ps3_system_bus_device *dev)
 
        tmp = hcd->irq;
 
+       ohci_shutdown(hcd);
        usb_remove_hcd(hcd);
 
        ps3_system_bus_set_driver_data(dev, NULL);
index c18d8790c4107c032eb0e34b94be345683828d8d..2376f24f3c83dc964f03286a66a88ab195434179 100644 (file)
@@ -1763,11 +1763,12 @@ static void r8a66597_timer(unsigned long _r8a66597)
 {
        struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
        unsigned long flags;
+       int port;
 
        spin_lock_irqsave(&r8a66597->lock, flags);
 
-       r8a66597_root_hub_control(r8a66597, 0);
-       r8a66597_root_hub_control(r8a66597, 1);
+       for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
+               r8a66597_root_hub_control(r8a66597, port);
 
        spin_unlock_irqrestore(&r8a66597->lock, flags);
 }
index 69c34a58e2054a7c49d225164a3f1a7ead20cf5a..b4ec716de7dadc12b766e445822edbc4f35f537a 100644 (file)
@@ -3270,6 +3270,7 @@ static struct usb_device_id sisusb_table [] = {
        { USB_DEVICE(0x0711, 0x0900) },
        { USB_DEVICE(0x0711, 0x0901) },
        { USB_DEVICE(0x0711, 0x0902) },
+       { USB_DEVICE(0x0711, 0x0903) },
        { USB_DEVICE(0x0711, 0x0918) },
        { USB_DEVICE(0x182d, 0x021c) },
        { USB_DEVICE(0x182d, 0x0269) },
index 8648470c81caa3a4e516445255a00b9101373c25..63dff9ba73c5d074bcd87ba13fcd4188dce81960 100644 (file)
@@ -620,7 +620,7 @@ static long vstusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                __func__);
                        retval = -EFAULT;
                } else {
-                       dev_dbg(&dev->dev, "%s: recv %d bytes from pipe %d\n",
+                       dev_dbg(&dev->dev, "%s: recv %zd bytes from pipe %d\n",
                                __func__, usb_data.count, usb_data.pipe);
                }
 
index 4a35745b30be6992ff775cfd118c02750a2eef52..5280dba9b1fb7e0a94f6dc1b379b28fc5c7d831b 100644 (file)
 
 
 
-unsigned debug;
-module_param(debug, uint, S_IRUGO | S_IWUSR);
+unsigned musb_debug;
+module_param(musb_debug, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
 
 #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
@@ -2248,7 +2248,7 @@ static int __init musb_init(void)
                "host"
 #endif
                ", debug=%d\n",
-               musb_driver_name, debug);
+               musb_driver_name, musb_debug);
        return platform_driver_probe(&musb_driver, musb_probe);
 }
 
index 4d2794441b153ac6c2f745b99f06c245cb56bbe5..9fc1db44c72c13844e73148112bbe8055c65ef3f 100644 (file)
                                __func__, __LINE__ , ## args); \
        } } while (0)
 
-extern unsigned debug;
+extern unsigned musb_debug;
 
 static inline int _dbg_level(unsigned l)
 {
-       return debug >= l;
+       return musb_debug >= l;
 }
 
 #define DBG(level, fmt, args...) xprintk(level, KERN_DEBUG, fmt, ## args)
index 3133990f04ec868fcb0809cd233535f3fc562ff2..e45e70bcc5e2ea1c79610ad7f754a8029e922ccd 100644 (file)
@@ -378,6 +378,19 @@ musb_giveback(struct musb_qh *qh, struct urb *urb, int status)
 
                switch (qh->type) {
 
+               case USB_ENDPOINT_XFER_CONTROL:
+               case USB_ENDPOINT_XFER_BULK:
+                       /* fifo policy for these lists, except that NAKing
+                        * should rotate a qh to the end (for fairness).
+                        */
+                       if (qh->mux == 1) {
+                               head = qh->ring.prev;
+                               list_del(&qh->ring);
+                               kfree(qh);
+                               qh = first_qh(head);
+                               break;
+                       }
+
                case USB_ENDPOINT_XFER_ISOC:
                case USB_ENDPOINT_XFER_INT:
                        /* this is where periodic bandwidth should be
@@ -388,17 +401,6 @@ musb_giveback(struct musb_qh *qh, struct urb *urb, int status)
                        kfree(qh);
                        qh = NULL;
                        break;
-
-               case USB_ENDPOINT_XFER_CONTROL:
-               case USB_ENDPOINT_XFER_BULK:
-                       /* fifo policy for these lists, except that NAKing
-                        * should rotate a qh to the end (for fairness).
-                        */
-                       head = qh->ring.prev;
-                       list_del(&qh->ring);
-                       kfree(qh);
-                       qh = first_qh(head);
-                       break;
                }
        }
        return qh;
@@ -1507,10 +1509,29 @@ void musb_host_rx(struct musb *musb, u8 epnum)
                musb_writew(hw_ep->regs, MUSB_RXCSR, val);
 
 #ifdef CONFIG_USB_INVENTRA_DMA
+               if (usb_pipeisoc(pipe)) {
+                       struct usb_iso_packet_descriptor *d;
+
+                       d = urb->iso_frame_desc + qh->iso_idx;
+                       d->actual_length = xfer_len;
+
+                       /* even if there was an error, we did the dma
+                        * for iso_frame_desc->length
+                        */
+                       if (d->status != EILSEQ && d->status != -EOVERFLOW)
+                               d->status = 0;
+
+                       if (++qh->iso_idx >= urb->number_of_packets)
+                               done = true;
+                       else
+                               done = false;
+
+               } else  {
                /* done if urb buffer is full or short packet is recd */
                done = (urb->actual_length + xfer_len >=
                                urb->transfer_buffer_length
                        || dma->actual_len < qh->maxpacket);
+               }
 
                /* send IN token for next packet, without AUTOREQ */
                if (!done) {
@@ -1547,7 +1568,8 @@ void musb_host_rx(struct musb *musb, u8 epnum)
                if (dma) {
                        struct dma_controller   *c;
                        u16                     rx_count;
-                       int                     ret;
+                       int                     ret, length;
+                       dma_addr_t              buf;
 
                        rx_count = musb_readw(epio, MUSB_RXCOUNT);
 
@@ -1560,6 +1582,35 @@ void musb_host_rx(struct musb *musb, u8 epnum)
 
                        c = musb->dma_controller;
 
+                       if (usb_pipeisoc(pipe)) {
+                               int status = 0;
+                               struct usb_iso_packet_descriptor *d;
+
+                               d = urb->iso_frame_desc + qh->iso_idx;
+
+                               if (iso_err) {
+                                       status = -EILSEQ;
+                                       urb->error_count++;
+                               }
+                               if (rx_count > d->length) {
+                                       if (status == 0) {
+                                               status = -EOVERFLOW;
+                                               urb->error_count++;
+                                       }
+                                       DBG(2, "** OVERFLOW %d into %d\n",\
+                                           rx_count, d->length);
+
+                                       length = d->length;
+                               } else
+                                       length = rx_count;
+                               d->status = status;
+                               buf = urb->transfer_dma + d->offset;
+                       } else {
+                               length = rx_count;
+                               buf = urb->transfer_dma +
+                                               urb->actual_length;
+                       }
+
                        dma->desired_mode = 0;
 #ifdef USE_MODE1
                        /* because of the issue below, mode 1 will
@@ -1571,6 +1622,12 @@ void musb_host_rx(struct musb *musb, u8 epnum)
                                                urb->actual_length)
                                        > qh->maxpacket)
                                dma->desired_mode = 1;
+                       if (rx_count < hw_ep->max_packet_sz_rx) {
+                               length = rx_count;
+                               dma->bDesiredMode = 0;
+                       } else {
+                               length = urb->transfer_buffer_length;
+                       }
 #endif
 
 /* Disadvantage of using mode 1:
@@ -1608,12 +1665,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
                         */
                        ret = c->channel_program(
                                dma, qh->maxpacket,
-                               dma->desired_mode,
-                               urb->transfer_dma
-                                       + urb->actual_length,
-                               (dma->desired_mode == 0)
-                                       ? rx_count
-                                       : urb->transfer_buffer_length);
+                               dma->desired_mode, buf, length);
 
                        if (!ret) {
                                c->channel_release(dma);
@@ -1631,19 +1683,6 @@ void musb_host_rx(struct musb *musb, u8 epnum)
                }
        }
 
-       if (dma && usb_pipeisoc(pipe)) {
-               struct usb_iso_packet_descriptor        *d;
-               int                                     iso_stat = status;
-
-               d = urb->iso_frame_desc + qh->iso_idx;
-               d->actual_length += xfer_len;
-               if (iso_err) {
-                       iso_stat = -EILSEQ;
-                       urb->error_count++;
-               }
-               d->status = iso_stat;
-       }
-
 finish:
        urb->actual_length += xfer_len;
        qh->offset += xfer_len;
@@ -1671,22 +1710,9 @@ static int musb_schedule(
        struct list_head        *head = NULL;
 
        /* use fixed hardware for control and bulk */
-       switch (qh->type) {
-       case USB_ENDPOINT_XFER_CONTROL:
+       if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
                head = &musb->control;
                hw_ep = musb->control_ep;
-               break;
-       case USB_ENDPOINT_XFER_BULK:
-               hw_ep = musb->bulk_ep;
-               if (is_in)
-                       head = &musb->in_bulk;
-               else
-                       head = &musb->out_bulk;
-               break;
-       }
-       if (head) {
-               idle = list_empty(head);
-               list_add_tail(&qh->ring, head);
                goto success;
        }
 
@@ -1725,19 +1751,34 @@ static int musb_schedule(
                else
                        diff = hw_ep->max_packet_sz_tx - qh->maxpacket;
 
-               if (diff > 0 && best_diff > diff) {
+               if (diff >= 0 && best_diff > diff) {
                        best_diff = diff;
                        best_end = epnum;
                }
        }
-       if (best_end < 0)
+       /* use bulk reserved ep1 if no other ep is free */
+       if (best_end > 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
+               hw_ep = musb->bulk_ep;
+               if (is_in)
+                       head = &musb->in_bulk;
+               else
+                       head = &musb->out_bulk;
+               goto success;
+       } else if (best_end < 0) {
                return -ENOSPC;
+       }
 
        idle = 1;
+       qh->mux = 0;
        hw_ep = musb->endpoints + best_end;
        musb->periodic[best_end] = qh;
        DBG(4, "qh %p periodic slot %d\n", qh, best_end);
 success:
+       if (head) {
+               idle = list_empty(head);
+               list_add_tail(&qh->ring, head);
+               qh->mux = 1;
+       }
        qh->hw_ep = hw_ep;
        qh->hep->hcpriv = qh;
        if (idle)
@@ -2015,11 +2056,13 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                        sched = &musb->control;
                        break;
                case USB_ENDPOINT_XFER_BULK:
-                       if (usb_pipein(urb->pipe))
-                               sched = &musb->in_bulk;
-                       else
-                               sched = &musb->out_bulk;
-                       break;
+                       if (qh->mux == 1) {
+                               if (usb_pipein(urb->pipe))
+                                       sched = &musb->in_bulk;
+                               else
+                                       sched = &musb->out_bulk;
+                               break;
+                       }
                default:
                        /* REVISIT when we get a schedule tree, periodic
                         * transfers won't always be at the head of a
@@ -2067,11 +2110,13 @@ musb_h_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
                sched = &musb->control;
                break;
        case USB_ENDPOINT_XFER_BULK:
-               if (is_in)
-                       sched = &musb->in_bulk;
-               else
-                       sched = &musb->out_bulk;
-               break;
+               if (qh->mux == 1) {
+                       if (is_in)
+                               sched = &musb->in_bulk;
+                       else
+                               sched = &musb->out_bulk;
+                       break;
+               }
        default:
                /* REVISIT when we get a schedule tree, periodic transfers
                 * won't always be at the head of a singleton queue...
index 77bcdb9d5b32d93c1fd77433bce4821d9ab9c4bd..0b7fbcd21963ebcc23435d168a061bed741ff612 100644 (file)
@@ -53,6 +53,7 @@ struct musb_qh {
 
        struct list_head        ring;           /* of musb_qh */
        /* struct musb_qh               *next; */       /* for periodic tree */
+       u8                      mux;            /* qh multiplexed to hw_ep */
 
        unsigned                offset;         /* in urb->transfer_buffer */
        unsigned                segsize;        /* current xfer fragment */
index 9d2dcb121c5e95cc7e6ba81a5cdfa59ae07637ae..ce6c162920f7bfcb5bef980b2438aeba4661d12b 100644 (file)
@@ -53,7 +53,9 @@ static void musb_do_idle(unsigned long _musb)
 {
        struct musb     *musb = (void *)_musb;
        unsigned long   flags;
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
        u8      power;
+#endif
        u8      devctl;
 
        devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
index b73b036f3d7770c01822e0885635a5fa3879aeae..ee8fca92a4ac4cd0ec58b157941bf8017ecff331 100644 (file)
@@ -605,7 +605,7 @@ void musb_platform_set_mode(struct musb *musb, u8 musb_mode)
 
        if (musb->board_mode != MUSB_OTG) {
                ERR("Changing mode currently only supported in OTG mode\n");
-               return;
+               return -EINVAL;
        }
 
        otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
index 8008d0bc80ad3732a05b4fa82b04b06f3fb334fc..9035d7256b03570a63203994d0fc031ea59e0a22 100644 (file)
@@ -67,6 +67,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
        { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
        { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
+       { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */
        { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
        { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */
        { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
@@ -85,6 +86,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
        { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */
        { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
+       { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
        { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
        { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
        { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
index bd07eaa300b967f792ffd2923af3385b8784cf3b..6fa1ec441b618d12575adf9bec5ee67a327fde6f 100644 (file)
@@ -160,6 +160,11 @@ static int  option_send_setup(struct tty_struct *tty, struct usb_serial_port *po
 
 #define NOVATELWIRELESS_VENDOR_ID              0x1410
 
+/* YISO PRODUCTS */
+
+#define YISO_VENDOR_ID                         0x0EAB
+#define YISO_PRODUCT_U893                      0xC893
+
 /* MERLIN EVDO PRODUCTS */
 #define NOVATELWIRELESS_PRODUCT_V640           0x1100
 #define NOVATELWIRELESS_PRODUCT_V620           0x1110
@@ -408,6 +413,7 @@ static struct usb_device_id option_ids[] = {
        { USB_DEVICE(AXESSTEL_VENDOR_ID, AXESSTEL_PRODUCT_MV110H) },
        { USB_DEVICE(ONDA_VENDOR_ID, ONDA_PRODUCT_MSA501HS) },
        { USB_DEVICE(ONDA_VENDOR_ID, ONDA_PRODUCT_ET502HS) },
+       { USB_DEVICE(YISO_VENDOR_ID, YISO_PRODUCT_U893) },
        { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_1) },
        { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_2) },
        { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_1004) },
index 3d9249632ae12e7051174817241ef37ea6f2cd4c..c68b738900bdbb9b6c8f6c95d536a69d7cada937 100644 (file)
@@ -2,8 +2,8 @@
 # USB Storage driver configuration
 #
 
-comment "NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'"
-comment "may also be needed; see USB_STORAGE Help for more information"
+comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed;"
+comment "see USB_STORAGE Help for more information"
        depends on USB
 
 config USB_STORAGE
index fb9e20e624c1477f909c6ec4825dc7e6d22ebe50..d4e5fc86e43c679eee20ee64e5334cfd2eceda66 100644 (file)
@@ -253,6 +253,14 @@ UNUSUAL_DEV(  0x0421, 0x006a, 0x0000, 0x0591,
        US_SC_DEVICE, US_PR_DEVICE, NULL,
        US_FL_FIX_CAPACITY ),
 
+/* Submitted by Ricky Wong Yung Fei <evilbladewarrior@gmail.com> */
+/* Nokia 7610 Supernova - Too many sectors reported in usb storage mode */
+UNUSUAL_DEV(  0x0421, 0x00f5, 0x0000, 0x0470,
+       "Nokia",
+       "7610 Supernova",
+       US_SC_DEVICE, US_PR_DEVICE, NULL,
+       US_FL_FIX_CAPACITY ),
+
 /* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
 UNUSUAL_DEV(  0x0424, 0x0fdc, 0x0210, 0x0210,
                "SMSC",
@@ -418,6 +426,13 @@ UNUSUAL_DEV(  0x04b0, 0x0417, 0x0100, 0x0100,
                US_SC_DEVICE, US_PR_DEVICE, NULL,
                US_FL_FIX_CAPACITY),
 
+/* Reported by paul ready <lxtwin@homecall.co.uk> */
+UNUSUAL_DEV(  0x04b0, 0x0419, 0x0100, 0x0200,
+               "NIKON",
+               "NIKON DSC D300",
+               US_SC_DEVICE, US_PR_DEVICE, NULL,
+               US_FL_FIX_CAPACITY),
+
 /* Reported by Doug Maxey (dwm@austin.ibm.com) */
 UNUSUAL_DEV(  0x04b3, 0x4001, 0x0110, 0x0110,
                "IBM",
@@ -1258,6 +1273,13 @@ UNUSUAL_DEV( 0x0839, 0x000a, 0x0001, 0x0001,
                US_SC_DEVICE, US_PR_DEVICE, NULL,
                US_FL_FIX_INQUIRY),
 
+/* Reported by Luciano Rocha <luciano@eurotux.com> */
+UNUSUAL_DEV( 0x0840, 0x0082, 0x0001, 0x0001,
+               "Argosy",
+               "Storage",
+               US_SC_DEVICE, US_PR_DEVICE, NULL,
+               US_FL_FIX_CAPACITY),
+
 /* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>.
  * Flag will support Bulk devices which use a standards-violating 32-byte
  * Command Block Wrapper. Here, the "DC2MEGA" cameras (several brands) with
index c4493091c655d109dd008983183048b02c2a304e..a14d5b6e4c7c280b831f9f87ea33ace10f8fc571 100644 (file)
@@ -52,5 +52,12 @@ config W1_MASTER_GPIO
          This support is also available as a module.  If so, the module
          will be called w1-gpio.ko.
 
+config HDQ_MASTER_OMAP
+       tristate "OMAP HDQ driver"
+       depends on ARCH_OMAP2430 || ARCH_OMAP34XX
+       help
+         Say Y here if you want support for the 1-wire or HDQ Interface
+         on an OMAP processor.
+
 endmenu
 
index 1420b5bbdda81f930379dfac9e776af216af7557..bc4714a75f3a0358ebcc7c51a78025dab7e1d594 100644 (file)
@@ -7,3 +7,4 @@ obj-$(CONFIG_W1_MASTER_DS2490)          += ds2490.o
 obj-$(CONFIG_W1_MASTER_DS2482)         += ds2482.o
 obj-$(CONFIG_W1_MASTER_DS1WM)          += ds1wm.o
 obj-$(CONFIG_W1_MASTER_GPIO)           += w1-gpio.o
+obj-$(CONFIG_HDQ_MASTER_OMAP)          += omap_hdq.o
diff --git a/drivers/w1/masters/omap_hdq.c b/drivers/w1/masters/omap_hdq.c
new file mode 100644 (file)
index 0000000..1295625
--- /dev/null
@@ -0,0 +1,725 @@
+/*
+ * drivers/w1/masters/omap_hdq.c
+ *
+ * Copyright (C) 2007 Texas Instruments, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <asm/irq.h>
+#include <mach/hardware.h>
+
+#include "../w1.h"
+#include "../w1_int.h"
+
+#define        MOD_NAME        "OMAP_HDQ:"
+
+#define OMAP_HDQ_REVISION                      0x00
+#define OMAP_HDQ_TX_DATA                       0x04
+#define OMAP_HDQ_RX_DATA                       0x08
+#define OMAP_HDQ_CTRL_STATUS                   0x0c
+#define OMAP_HDQ_CTRL_STATUS_INTERRUPTMASK     (1<<6)
+#define OMAP_HDQ_CTRL_STATUS_CLOCKENABLE       (1<<5)
+#define OMAP_HDQ_CTRL_STATUS_GO                        (1<<4)
+#define OMAP_HDQ_CTRL_STATUS_INITIALIZATION    (1<<2)
+#define OMAP_HDQ_CTRL_STATUS_DIR               (1<<1)
+#define OMAP_HDQ_CTRL_STATUS_MODE              (1<<0)
+#define OMAP_HDQ_INT_STATUS                    0x10
+#define OMAP_HDQ_INT_STATUS_TXCOMPLETE         (1<<2)
+#define OMAP_HDQ_INT_STATUS_RXCOMPLETE         (1<<1)
+#define OMAP_HDQ_INT_STATUS_TIMEOUT            (1<<0)
+#define OMAP_HDQ_SYSCONFIG                     0x14
+#define OMAP_HDQ_SYSCONFIG_SOFTRESET           (1<<1)
+#define OMAP_HDQ_SYSCONFIG_AUTOIDLE            (1<<0)
+#define OMAP_HDQ_SYSSTATUS                     0x18
+#define OMAP_HDQ_SYSSTATUS_RESETDONE           (1<<0)
+
+#define OMAP_HDQ_FLAG_CLEAR                    0
+#define OMAP_HDQ_FLAG_SET                      1
+#define OMAP_HDQ_TIMEOUT                       (HZ/5)
+
+#define OMAP_HDQ_MAX_USER                      4
+
+static DECLARE_WAIT_QUEUE_HEAD(hdq_wait_queue);
+static int w1_id;
+
+struct hdq_data {
+       struct device           *dev;
+       void __iomem            *hdq_base;
+       /* lock status update */
+       struct  mutex           hdq_mutex;
+       int                     hdq_usecount;
+       struct  clk             *hdq_ick;
+       struct  clk             *hdq_fck;
+       u8                      hdq_irqstatus;
+       /* device lock */
+       spinlock_t              hdq_spinlock;
+       /*
+        * Used to control the call to omap_hdq_get and omap_hdq_put.
+        * HDQ Protocol: Write the CMD|REG_address first, followed by
+        * the data wrire or read.
+        */
+       int                     init_trans;
+};
+
+static int __init omap_hdq_probe(struct platform_device *pdev);
+static int omap_hdq_remove(struct platform_device *pdev);
+
+static struct platform_driver omap_hdq_driver = {
+       .probe =        omap_hdq_probe,
+       .remove =       omap_hdq_remove,
+       .driver =       {
+               .name = "omap_hdq",
+       },
+};
+
+static u8 omap_w1_read_byte(void *_hdq);
+static void omap_w1_write_byte(void *_hdq, u8 byte);
+static u8 omap_w1_reset_bus(void *_hdq);
+static void omap_w1_search_bus(void *_hdq, u8 search_type,
+       w1_slave_found_callback slave_found);
+
+
+static struct w1_bus_master omap_w1_master = {
+       .read_byte      = omap_w1_read_byte,
+       .write_byte     = omap_w1_write_byte,
+       .reset_bus      = omap_w1_reset_bus,
+       .search         = omap_w1_search_bus,
+};
+
+/* HDQ register I/O routines */
+static inline u8 hdq_reg_in(struct hdq_data *hdq_data, u32 offset)
+{
+       return __raw_readb(hdq_data->hdq_base + offset);
+}
+
+static inline void hdq_reg_out(struct hdq_data *hdq_data, u32 offset, u8 val)
+{
+       __raw_writeb(val, hdq_data->hdq_base + offset);
+}
+
+static inline u8 hdq_reg_merge(struct hdq_data *hdq_data, u32 offset,
+                       u8 val, u8 mask)
+{
+       u8 new_val = (__raw_readb(hdq_data->hdq_base + offset) & ~mask)
+                       | (val & mask);
+       __raw_writeb(new_val, hdq_data->hdq_base + offset);
+
+       return new_val;
+}
+
+/*
+ * Wait for one or more bits in flag change.
+ * HDQ_FLAG_SET: wait until any bit in the flag is set.
+ * HDQ_FLAG_CLEAR: wait until all bits in the flag are cleared.
+ * return 0 on success and -ETIMEDOUT in the case of timeout.
+ */
+static int hdq_wait_for_flag(struct hdq_data *hdq_data, u32 offset,
+               u8 flag, u8 flag_set, u8 *status)
+{
+       int ret = 0;
+       unsigned long timeout = jiffies + OMAP_HDQ_TIMEOUT;
+
+       if (flag_set == OMAP_HDQ_FLAG_CLEAR) {
+               /* wait for the flag clear */
+               while (((*status = hdq_reg_in(hdq_data, offset)) & flag)
+                       && time_before(jiffies, timeout)) {
+                       schedule_timeout_uninterruptible(1);
+               }
+               if (*status & flag)
+                       ret = -ETIMEDOUT;
+       } else if (flag_set == OMAP_HDQ_FLAG_SET) {
+               /* wait for the flag set */
+               while (!((*status = hdq_reg_in(hdq_data, offset)) & flag)
+                       && time_before(jiffies, timeout)) {
+                       schedule_timeout_uninterruptible(1);
+               }
+               if (!(*status & flag))
+                       ret = -ETIMEDOUT;
+       } else
+               return -EINVAL;
+
+       return ret;
+}
+
+/* write out a byte and fill *status with HDQ_INT_STATUS */
+static int hdq_write_byte(struct hdq_data *hdq_data, u8 val, u8 *status)
+{
+       int ret;
+       u8 tmp_status;
+       unsigned long irqflags;
+
+       *status = 0;
+
+       spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags);
+       /* clear interrupt flags via a dummy read */
+       hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS);
+       /* ISR loads it with new INT_STATUS */
+       hdq_data->hdq_irqstatus = 0;
+       spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags);
+
+       hdq_reg_out(hdq_data, OMAP_HDQ_TX_DATA, val);
+
+       /* set the GO bit */
+       hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, OMAP_HDQ_CTRL_STATUS_GO,
+               OMAP_HDQ_CTRL_STATUS_DIR | OMAP_HDQ_CTRL_STATUS_GO);
+       /* wait for the TXCOMPLETE bit */
+       ret = wait_event_timeout(hdq_wait_queue,
+               hdq_data->hdq_irqstatus, OMAP_HDQ_TIMEOUT);
+       if (ret == 0) {
+               dev_dbg(hdq_data->dev, "TX wait elapsed\n");
+               goto out;
+       }
+
+       *status = hdq_data->hdq_irqstatus;
+       /* check irqstatus */
+       if (!(*status & OMAP_HDQ_INT_STATUS_TXCOMPLETE)) {
+               dev_dbg(hdq_data->dev, "timeout waiting for"
+                       "TXCOMPLETE/RXCOMPLETE, %x", *status);
+               ret = -ETIMEDOUT;
+               goto out;
+       }
+
+       /* wait for the GO bit return to zero */
+       ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS,
+                       OMAP_HDQ_CTRL_STATUS_GO,
+                       OMAP_HDQ_FLAG_CLEAR, &tmp_status);
+       if (ret) {
+               dev_dbg(hdq_data->dev, "timeout waiting GO bit"
+                       "return to zero, %x", tmp_status);
+       }
+
+out:
+       return ret;
+}
+
+/* HDQ Interrupt service routine */
+static irqreturn_t hdq_isr(int irq, void *_hdq)
+{
+       struct hdq_data *hdq_data = _hdq;
+       unsigned long irqflags;
+
+       spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags);
+       hdq_data->hdq_irqstatus = hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS);
+       spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags);
+       dev_dbg(hdq_data->dev, "hdq_isr: %x", hdq_data->hdq_irqstatus);
+
+       if (hdq_data->hdq_irqstatus &
+               (OMAP_HDQ_INT_STATUS_TXCOMPLETE | OMAP_HDQ_INT_STATUS_RXCOMPLETE
+               | OMAP_HDQ_INT_STATUS_TIMEOUT)) {
+               /* wake up sleeping process */
+               wake_up(&hdq_wait_queue);
+       }
+
+       return IRQ_HANDLED;
+}
+
+/* HDQ Mode: always return success */
+static u8 omap_w1_reset_bus(void *_hdq)
+{
+       return 0;
+}
+
+/* W1 search callback function */
+static void omap_w1_search_bus(void *_hdq, u8 search_type,
+       w1_slave_found_callback slave_found)
+{
+       u64 module_id, rn_le, cs, id;
+
+       if (w1_id)
+               module_id = w1_id;
+       else
+               module_id = 0x1;
+
+       rn_le = cpu_to_le64(module_id);
+       /*
+        * HDQ might not obey truly the 1-wire spec.
+        * So calculate CRC based on module parameter.
+        */
+       cs = w1_calc_crc8((u8 *)&rn_le, 7);
+       id = (cs << 56) | module_id;
+
+       slave_found(_hdq, id);
+}
+
+static int _omap_hdq_reset(struct hdq_data *hdq_data)
+{
+       int ret;
+       u8 tmp_status;
+
+       hdq_reg_out(hdq_data, OMAP_HDQ_SYSCONFIG, OMAP_HDQ_SYSCONFIG_SOFTRESET);
+       /*
+        * Select HDQ mode & enable clocks.
+        * It is observed that INT flags can't be cleared via a read and GO/INIT
+        * won't return to zero if interrupt is disabled. So we always enable
+        * interrupt.
+        */
+       hdq_reg_out(hdq_data, OMAP_HDQ_CTRL_STATUS,
+               OMAP_HDQ_CTRL_STATUS_CLOCKENABLE |
+               OMAP_HDQ_CTRL_STATUS_INTERRUPTMASK);
+
+       /* wait for reset to complete */
+       ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_SYSSTATUS,
+               OMAP_HDQ_SYSSTATUS_RESETDONE, OMAP_HDQ_FLAG_SET, &tmp_status);
+       if (ret)
+               dev_dbg(hdq_data->dev, "timeout waiting HDQ reset, %x",
+                               tmp_status);
+       else {
+               hdq_reg_out(hdq_data, OMAP_HDQ_CTRL_STATUS,
+                       OMAP_HDQ_CTRL_STATUS_CLOCKENABLE |
+                       OMAP_HDQ_CTRL_STATUS_INTERRUPTMASK);
+               hdq_reg_out(hdq_data, OMAP_HDQ_SYSCONFIG,
+                       OMAP_HDQ_SYSCONFIG_AUTOIDLE);
+       }
+
+       return ret;
+}
+
+/* Issue break pulse to the device */
+static int omap_hdq_break(struct hdq_data *hdq_data)
+{
+       int ret = 0;
+       u8 tmp_status;
+       unsigned long irqflags;
+
+       ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+       if (ret < 0) {
+               dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
+               ret = -EINTR;
+               goto rtn;
+       }
+
+       spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags);
+       /* clear interrupt flags via a dummy read */
+       hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS);
+       /* ISR loads it with new INT_STATUS */
+       hdq_data->hdq_irqstatus = 0;
+       spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags);
+
+       /* set the INIT and GO bit */
+       hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS,
+               OMAP_HDQ_CTRL_STATUS_INITIALIZATION | OMAP_HDQ_CTRL_STATUS_GO,
+               OMAP_HDQ_CTRL_STATUS_DIR | OMAP_HDQ_CTRL_STATUS_INITIALIZATION |
+               OMAP_HDQ_CTRL_STATUS_GO);
+
+       /* wait for the TIMEOUT bit */
+       ret = wait_event_timeout(hdq_wait_queue,
+               hdq_data->hdq_irqstatus, OMAP_HDQ_TIMEOUT);
+       if (ret == 0) {
+               dev_dbg(hdq_data->dev, "break wait elapsed\n");
+               ret = -EINTR;
+               goto out;
+       }
+
+       tmp_status = hdq_data->hdq_irqstatus;
+       /* check irqstatus */
+       if (!(tmp_status & OMAP_HDQ_INT_STATUS_TIMEOUT)) {
+               dev_dbg(hdq_data->dev, "timeout waiting for TIMEOUT, %x",
+                               tmp_status);
+               ret = -ETIMEDOUT;
+               goto out;
+       }
+       /*
+        * wait for both INIT and GO bits rerurn to zero.
+        * zero wait time expected for interrupt mode.
+        */
+       ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS,
+                       OMAP_HDQ_CTRL_STATUS_INITIALIZATION |
+                       OMAP_HDQ_CTRL_STATUS_GO, OMAP_HDQ_FLAG_CLEAR,
+                       &tmp_status);
+       if (ret)
+               dev_dbg(hdq_data->dev, "timeout waiting INIT&GO bits"
+                       "return to zero, %x", tmp_status);
+
+out:
+       mutex_unlock(&hdq_data->hdq_mutex);
+rtn:
+       return ret;
+}
+
+static int hdq_read_byte(struct hdq_data *hdq_data, u8 *val)
+{
+       int ret = 0;
+       u8 status;
+       unsigned long timeout = jiffies + OMAP_HDQ_TIMEOUT;
+
+       ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+       if (ret < 0) {
+               ret = -EINTR;
+               goto rtn;
+       }
+
+       if (!hdq_data->hdq_usecount) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (!(hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_RXCOMPLETE)) {
+               hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS,
+                       OMAP_HDQ_CTRL_STATUS_DIR | OMAP_HDQ_CTRL_STATUS_GO,
+                       OMAP_HDQ_CTRL_STATUS_DIR | OMAP_HDQ_CTRL_STATUS_GO);
+               /*
+                * The RX comes immediately after TX. It
+                * triggers another interrupt before we
+                * sleep. So we have to wait for RXCOMPLETE bit.
+                */
+               while (!(hdq_data->hdq_irqstatus
+                       & OMAP_HDQ_INT_STATUS_RXCOMPLETE)
+                       && time_before(jiffies, timeout)) {
+                       schedule_timeout_uninterruptible(1);
+               }
+               hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, 0,
+                       OMAP_HDQ_CTRL_STATUS_DIR);
+               status = hdq_data->hdq_irqstatus;
+               /* check irqstatus */
+               if (!(status & OMAP_HDQ_INT_STATUS_RXCOMPLETE)) {
+                       dev_dbg(hdq_data->dev, "timeout waiting for"
+                               "RXCOMPLETE, %x", status);
+                       ret = -ETIMEDOUT;
+                       goto out;
+               }
+       }
+       /* the data is ready. Read it in! */
+       *val = hdq_reg_in(hdq_data, OMAP_HDQ_RX_DATA);
+out:
+       mutex_unlock(&hdq_data->hdq_mutex);
+rtn:
+       return 0;
+
+}
+
+/* Enable clocks and set the controller to HDQ mode */
+static int omap_hdq_get(struct hdq_data *hdq_data)
+{
+       int ret = 0;
+
+       ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+       if (ret < 0) {
+               ret = -EINTR;
+               goto rtn;
+       }
+
+       if (OMAP_HDQ_MAX_USER == hdq_data->hdq_usecount) {
+               dev_dbg(hdq_data->dev, "attempt to exceed the max use count");
+               ret = -EINVAL;
+               goto out;
+       } else {
+               hdq_data->hdq_usecount++;
+               try_module_get(THIS_MODULE);
+               if (1 == hdq_data->hdq_usecount) {
+                       if (clk_enable(hdq_data->hdq_ick)) {
+                               dev_dbg(hdq_data->dev, "Can not enable ick\n");
+                               ret = -ENODEV;
+                               goto clk_err;
+                       }
+                       if (clk_enable(hdq_data->hdq_fck)) {
+                               dev_dbg(hdq_data->dev, "Can not enable fck\n");
+                               clk_disable(hdq_data->hdq_ick);
+                               ret = -ENODEV;
+                               goto clk_err;
+                       }
+
+                       /* make sure HDQ is out of reset */
+                       if (!(hdq_reg_in(hdq_data, OMAP_HDQ_SYSSTATUS) &
+                               OMAP_HDQ_SYSSTATUS_RESETDONE)) {
+                               ret = _omap_hdq_reset(hdq_data);
+                               if (ret)
+                                       /* back up the count */
+                                       hdq_data->hdq_usecount--;
+                       } else {
+                               /* select HDQ mode & enable clocks */
+                               hdq_reg_out(hdq_data, OMAP_HDQ_CTRL_STATUS,
+                                       OMAP_HDQ_CTRL_STATUS_CLOCKENABLE |
+                                       OMAP_HDQ_CTRL_STATUS_INTERRUPTMASK);
+                               hdq_reg_out(hdq_data, OMAP_HDQ_SYSCONFIG,
+                                       OMAP_HDQ_SYSCONFIG_AUTOIDLE);
+                               hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS);
+                       }
+               }
+       }
+
+clk_err:
+       clk_put(hdq_data->hdq_ick);
+       clk_put(hdq_data->hdq_fck);
+out:
+       mutex_unlock(&hdq_data->hdq_mutex);
+rtn:
+       return ret;
+}
+
+/* Disable clocks to the module */
+static int omap_hdq_put(struct hdq_data *hdq_data)
+{
+       int ret = 0;
+
+       ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+       if (ret < 0)
+               return -EINTR;
+
+       if (0 == hdq_data->hdq_usecount) {
+               dev_dbg(hdq_data->dev, "attempt to decrement use count"
+                       "when it is zero");
+               ret = -EINVAL;
+       } else {
+               hdq_data->hdq_usecount--;
+               module_put(THIS_MODULE);
+               if (0 == hdq_data->hdq_usecount) {
+                       clk_disable(hdq_data->hdq_ick);
+                       clk_disable(hdq_data->hdq_fck);
+               }
+       }
+       mutex_unlock(&hdq_data->hdq_mutex);
+
+       return ret;
+}
+
+/* Read a byte of data from the device */
+static u8 omap_w1_read_byte(void *_hdq)
+{
+       struct hdq_data *hdq_data = _hdq;
+       u8 val = 0;
+       int ret;
+
+       ret = hdq_read_byte(hdq_data, &val);
+       if (ret) {
+               ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+               if (ret < 0) {
+                       dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
+                       return -EINTR;
+               }
+               hdq_data->init_trans = 0;
+               mutex_unlock(&hdq_data->hdq_mutex);
+               omap_hdq_put(hdq_data);
+               return -1;
+       }
+
+       /* Write followed by a read, release the module */
+       if (hdq_data->init_trans) {
+               ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+               if (ret < 0) {
+                       dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
+                       return -EINTR;
+               }
+               hdq_data->init_trans = 0;
+               mutex_unlock(&hdq_data->hdq_mutex);
+               omap_hdq_put(hdq_data);
+       }
+
+       return val;
+}
+
+/* Write a byte of data to the device */
+static void omap_w1_write_byte(void *_hdq, u8 byte)
+{
+       struct hdq_data *hdq_data = _hdq;
+       int ret;
+       u8 status;
+
+       /* First write to initialize the transfer */
+       if (hdq_data->init_trans == 0)
+               omap_hdq_get(hdq_data);
+
+       ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+       if (ret < 0) {
+               dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
+               return;
+       }
+       hdq_data->init_trans++;
+       mutex_unlock(&hdq_data->hdq_mutex);
+
+       ret = hdq_write_byte(hdq_data, byte, &status);
+       if (ret == 0) {
+               dev_dbg(hdq_data->dev, "TX failure:Ctrl status %x\n", status);
+               return;
+       }
+
+       /* Second write, data transfered. Release the module */
+       if (hdq_data->init_trans > 1) {
+               omap_hdq_put(hdq_data);
+               ret = mutex_lock_interruptible(&hdq_data->hdq_mutex);
+               if (ret < 0) {
+                       dev_dbg(hdq_data->dev, "Could not acquire mutex\n");
+                       return;
+               }
+               hdq_data->init_trans = 0;
+               mutex_unlock(&hdq_data->hdq_mutex);
+       }
+
+       return;
+}
+
+static int __init omap_hdq_probe(struct platform_device *pdev)
+{
+       struct hdq_data *hdq_data;
+       struct resource *res;
+       int ret, irq;
+       u8 rev;
+
+       hdq_data = kmalloc(sizeof(*hdq_data), GFP_KERNEL);
+       if (!hdq_data) {
+               dev_dbg(&pdev->dev, "unable to allocate memory\n");
+               ret = -ENOMEM;
+               goto err_kmalloc;
+       }
+
+       hdq_data->dev = &pdev->dev;
+       platform_set_drvdata(pdev, hdq_data);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_dbg(&pdev->dev, "unable to get resource\n");
+               ret = -ENXIO;
+               goto err_resource;
+       }
+
+       hdq_data->hdq_base = ioremap(res->start, SZ_4K);
+       if (!hdq_data->hdq_base) {
+               dev_dbg(&pdev->dev, "ioremap failed\n");
+               ret = -EINVAL;
+               goto err_ioremap;
+       }
+
+       /* get interface & functional clock objects */
+       hdq_data->hdq_ick = clk_get(&pdev->dev, "hdq_ick");
+       hdq_data->hdq_fck = clk_get(&pdev->dev, "hdq_fck");
+
+       if (IS_ERR(hdq_data->hdq_ick) || IS_ERR(hdq_data->hdq_fck)) {
+               dev_dbg(&pdev->dev, "Can't get HDQ clock objects\n");
+               if (IS_ERR(hdq_data->hdq_ick)) {
+                       ret = PTR_ERR(hdq_data->hdq_ick);
+                       goto err_clk;
+               }
+               if (IS_ERR(hdq_data->hdq_fck)) {
+                       ret = PTR_ERR(hdq_data->hdq_fck);
+                       clk_put(hdq_data->hdq_ick);
+                       goto err_clk;
+               }
+       }
+
+       hdq_data->hdq_usecount = 0;
+       mutex_init(&hdq_data->hdq_mutex);
+
+       if (clk_enable(hdq_data->hdq_ick)) {
+               dev_dbg(&pdev->dev, "Can not enable ick\n");
+               ret = -ENODEV;
+               goto err_intfclk;
+       }
+
+       if (clk_enable(hdq_data->hdq_fck)) {
+               dev_dbg(&pdev->dev, "Can not enable fck\n");
+               ret = -ENODEV;
+               goto err_fnclk;
+       }
+
+       rev = hdq_reg_in(hdq_data, OMAP_HDQ_REVISION);
+       dev_info(&pdev->dev, "OMAP HDQ Hardware Rev %c.%c. Driver in %s mode\n",
+               (rev >> 4) + '0', (rev & 0x0f) + '0', "Interrupt");
+
+       spin_lock_init(&hdq_data->hdq_spinlock);
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               ret = -ENXIO;
+               goto err_irq;
+       }
+
+       ret = request_irq(irq, hdq_isr, IRQF_DISABLED, "omap_hdq", hdq_data);
+       if (ret < 0) {
+               dev_dbg(&pdev->dev, "could not request irq\n");
+               goto err_irq;
+       }
+
+       omap_hdq_break(hdq_data);
+
+       /* don't clock the HDQ until it is needed */
+       clk_disable(hdq_data->hdq_ick);
+       clk_disable(hdq_data->hdq_fck);
+
+       omap_w1_master.data = hdq_data;
+
+       ret = w1_add_master_device(&omap_w1_master);
+       if (ret) {
+               dev_dbg(&pdev->dev, "Failure in registering w1 master\n");
+               goto err_w1;
+       }
+
+       return 0;
+
+err_w1:
+err_irq:
+       clk_disable(hdq_data->hdq_fck);
+
+err_fnclk:
+       clk_disable(hdq_data->hdq_ick);
+
+err_intfclk:
+       clk_put(hdq_data->hdq_ick);
+       clk_put(hdq_data->hdq_fck);
+
+err_clk:
+       iounmap(hdq_data->hdq_base);
+
+err_ioremap:
+err_resource:
+       platform_set_drvdata(pdev, NULL);
+       kfree(hdq_data);
+
+err_kmalloc:
+       return ret;
+
+}
+
+static int omap_hdq_remove(struct platform_device *pdev)
+{
+       struct hdq_data *hdq_data = platform_get_drvdata(pdev);
+
+       mutex_lock(&hdq_data->hdq_mutex);
+
+       if (hdq_data->hdq_usecount) {
+               dev_dbg(&pdev->dev, "removed when use count is not zero\n");
+               return -EBUSY;
+       }
+
+       mutex_unlock(&hdq_data->hdq_mutex);
+
+       /* remove module dependency */
+       clk_put(hdq_data->hdq_ick);
+       clk_put(hdq_data->hdq_fck);
+       free_irq(INT_24XX_HDQ_IRQ, hdq_data);
+       platform_set_drvdata(pdev, NULL);
+       iounmap(hdq_data->hdq_base);
+       kfree(hdq_data);
+
+       return 0;
+}
+
+static int __init
+omap_hdq_init(void)
+{
+       return platform_driver_register(&omap_hdq_driver);
+}
+module_init(omap_hdq_init);
+
+static void __exit
+omap_hdq_exit(void)
+{
+       platform_driver_unregister(&omap_hdq_driver);
+}
+module_exit(omap_hdq_exit);
+
+module_param(w1_id, int, S_IRUSR);
+MODULE_PARM_DESC(w1_id, "1-wire id for the slave detection");
+
+MODULE_AUTHOR("Texas Instruments");
+MODULE_DESCRIPTION("HDQ driver Library");
+MODULE_LICENSE("GPL");
index 3df29a122f84c559d6ca1dcc104725028f18a9a7..8d0b1fb1e52edb6eeb57f98887e399d8a4c4b7af 100644 (file)
@@ -44,4 +44,11 @@ config W1_SLAVE_DS2760
 
          If you are unsure, say N.
 
+config W1_SLAVE_BQ27000
+       tristate "BQ27000 slave support"
+       depends on W1
+       help
+         Say Y here if you want to use a hdq
+         bq27000 slave support.
+
 endmenu
index a8eb7524df1db2c0c4db0dbe8a4097d9f65fcff6..990f400b6d22dc82563a382f6c0b7defd09820a6 100644 (file)
@@ -6,4 +6,4 @@ obj-$(CONFIG_W1_SLAVE_THERM)    += w1_therm.o
 obj-$(CONFIG_W1_SLAVE_SMEM)    += w1_smem.o
 obj-$(CONFIG_W1_SLAVE_DS2433)  += w1_ds2433.o
 obj-$(CONFIG_W1_SLAVE_DS2760)  += w1_ds2760.o
-
+obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o
diff --git a/drivers/w1/slaves/w1_bq27000.c b/drivers/w1/slaves/w1_bq27000.c
new file mode 100644 (file)
index 0000000..8f4c91f
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * drivers/w1/slaves/w1_bq27000.c
+ *
+ * Copyright (C) 2007 Texas Instruments, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <linux/mutex.h>
+
+#include "../w1.h"
+#include "../w1_int.h"
+#include "../w1_family.h"
+
+#define HDQ_CMD_READ   (0)
+#define HDQ_CMD_WRITE  (1<<7)
+
+static int F_ID;
+
+void w1_bq27000_write(struct device *dev, u8 buf, u8 reg)
+{
+       struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
+
+       if (!dev) {
+               pr_info("Could not obtain slave dev ptr\n");
+               return;
+       }
+
+       w1_write_8(sl->master, HDQ_CMD_WRITE | reg);
+       w1_write_8(sl->master, buf);
+}
+EXPORT_SYMBOL(w1_bq27000_write);
+
+int w1_bq27000_read(struct device *dev, u8 reg)
+{
+       u8 val;
+       struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
+
+       if (!dev)
+               return 0;
+
+       w1_write_8(sl->master, HDQ_CMD_READ | reg);
+       val = w1_read_8(sl->master);
+
+       return val;
+}
+EXPORT_SYMBOL(w1_bq27000_read);
+
+static int w1_bq27000_add_slave(struct w1_slave *sl)
+{
+       int ret;
+       int id = 1;
+       struct platform_device *pdev;
+
+       pdev = platform_device_alloc("bq27000-battery", id);
+       if (!pdev) {
+               ret = -ENOMEM;
+               return ret;
+       }
+       pdev->dev.parent = &sl->dev;
+
+       ret = platform_device_add(pdev);
+       if (ret)
+               goto pdev_add_failed;
+
+       dev_set_drvdata(&sl->dev, pdev);
+
+       goto success;
+
+pdev_add_failed:
+       platform_device_unregister(pdev);
+success:
+       return ret;
+}
+
+static void w1_bq27000_remove_slave(struct w1_slave *sl)
+{
+       struct platform_device *pdev = dev_get_drvdata(&sl->dev);
+
+       platform_device_unregister(pdev);
+}
+
+static struct w1_family_ops w1_bq27000_fops = {
+       .add_slave      = w1_bq27000_add_slave,
+       .remove_slave   = w1_bq27000_remove_slave,
+};
+
+static struct w1_family w1_bq27000_family = {
+       .fid = 1,
+       .fops = &w1_bq27000_fops,
+};
+
+static int __init w1_bq27000_init(void)
+{
+       if (F_ID)
+               w1_bq27000_family.fid = F_ID;
+
+       return w1_register_family(&w1_bq27000_family);
+}
+
+static void __exit w1_bq27000_exit(void)
+{
+       w1_unregister_family(&w1_bq27000_family);
+}
+
+
+module_init(w1_bq27000_init);
+module_exit(w1_bq27000_exit);
+
+module_param(F_ID, int, S_IRUSR);
+MODULE_PARM_DESC(F_ID, "1-wire slave FID for BQ device");
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Texas Instruments Ltd");
+MODULE_DESCRIPTION("HDQ/1-wire slave driver bq27000 battery monitor chip");
index cdaa6fffbfc73c2c6bd6be3eefdd2a600ca3f82e..97304bd83ec9674105bc837a4e9ecea6ba373cfd 100644 (file)
@@ -206,6 +206,7 @@ void w1_slave_detach(struct w1_slave *sl);
 
 u8 w1_triplet(struct w1_master *dev, int bdir);
 void w1_write_8(struct w1_master *, u8);
+u8 w1_read_8(struct w1_master *);
 int w1_reset_bus(struct w1_master *);
 u8 w1_calc_crc8(u8 *, int);
 void w1_write_block(struct w1_master *, const u8 *, int);
index f4f82f1f486ebdd2c70c9ff80c5fdb4e99f03fe2..0d15b0eaf79a7b5a56eb50bb00efc1a9571280e6 100644 (file)
@@ -217,7 +217,7 @@ u8 w1_triplet(struct w1_master *dev, int bdir)
  * @param dev     the master device
  * @return        the byte read
  */
-static u8 w1_read_8(struct w1_master * dev)
+u8 w1_read_8(struct w1_master *dev)
 {
        int i;
        u8 res = 0;
@@ -230,6 +230,7 @@ static u8 w1_read_8(struct w1_master * dev)
 
        return res;
 }
+EXPORT_SYMBOL_GPL(w1_read_8);
 
 /**
  * Writes a series of bytes.
index d910501de6d2ca9d4fc8ed1a1cda8d9a1aca1519..8d86b7960f0df7527fed5494230676b137b4f63b 100644 (file)
@@ -812,7 +812,7 @@ int dlm_release_lockspace(void *lockspace, int force)
        error = release_lockspace(ls, force);
        if (!error)
                ls_count--;
-       else if (!ls_count)
+       if (!ls_count)
                threads_stop();
        mutex_unlock(&ls_lock);
 
index 5dec6d1356c4b07477bb40f68305c0d9de89258b..f6c94f232ec1e8fee05e47dfcc54b234c82e7cf0 100644 (file)
@@ -2375,12 +2375,9 @@ int ext3_force_commit(struct super_block *sb)
 /*
  * Ext3 always journals updates to the superblock itself, so we don't
  * have to propagate any other updates to the superblock on disk at this
- * point.  Just start an async writeback to get the buffers on their way
- * to the disk.
- *
- * This implicitly triggers the writebehind on sync().
+ * point.  (We can probably nuke this function altogether, and remove
+ * any mention to sb->s_dirt in all of fs/ext3; eventual cleanup...)
  */
-
 static void ext3_write_super (struct super_block * sb)
 {
        if (mutex_trylock(&sb->s_lock) != 0)
index cce46702d33c98f6d9e1669ac10f4d6c23be82c2..65b3dc844c879c059c004425487672eff21b5682 100644 (file)
@@ -1815,8 +1815,8 @@ static void shrink_submounts(struct vfsmount *mnt, struct list_head *umounts)
                while (!list_empty(&graveyard)) {
                        m = list_first_entry(&graveyard, struct vfsmount,
                                                mnt_expire);
-                       touch_mnt_namespace(mnt->mnt_ns);
-                       umount_tree(mnt, 1, umounts);
+                       touch_mnt_namespace(m->mnt_ns);
+                       umount_tree(m, 1, umounts);
                }
        }
 }
diff --git a/include/linux/c2port.h b/include/linux/c2port.h
new file mode 100644 (file)
index 0000000..7b5a238
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Silicon Labs C2 port Linux support
+ *
+ *  Copyright (c) 2007 Rodolfo Giometti <giometti@linux.it>
+ *  Copyright (c) 2007 Eurotech S.p.A. <info@eurotech.it>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation
+ */
+
+#include <linux/device.h>
+
+#define C2PORT_NAME_LEN                        32
+
+/*
+ * C2 port basic structs
+ */
+
+/* Main struct */
+struct c2port_ops;
+struct c2port_device {
+       unsigned int access:1;
+       unsigned int flash_access:1;
+
+       int id;
+       char name[C2PORT_NAME_LEN];
+       struct c2port_ops *ops;
+       struct mutex mutex;             /* prevent races during read/write */
+
+       struct device *dev;
+
+       void *private_data;
+};
+
+/* Basic operations */
+struct c2port_ops {
+       /* Flash layout */
+       unsigned short block_size;      /* flash block size in bytes */
+       unsigned short blocks_num;      /* flash blocks number */
+
+       /* Enable or disable the access to C2 port */
+       void (*access)(struct c2port_device *dev, int status);
+
+       /* Set C2D data line as input/output */
+       void (*c2d_dir)(struct c2port_device *dev, int dir);
+
+       /* Read/write C2D data line */
+       int (*c2d_get)(struct c2port_device *dev);
+       void (*c2d_set)(struct c2port_device *dev, int status);
+
+       /* Write C2CK clock line */
+       void (*c2ck_set)(struct c2port_device *dev, int status);
+};
+
+/*
+ * Exported functions
+ */
+
+#define to_class_dev(obj) container_of((obj), struct class_device, kobj)
+#define to_c2port_device(obj) container_of((obj), struct c2port_device, class)
+
+extern struct c2port_device *c2port_device_register(char *name,
+                                       struct c2port_ops *ops, void *devdata);
+extern void c2port_device_unregister(struct c2port_device *dev);
index 07e510a3b00a89e78c2f48b591208b19dac6ef4e..3eba43878dcb2da2e6d4ad6a8b029ed13e3f8e6a 100644 (file)
@@ -46,9 +46,6 @@ enum hrtimer_restart {
  * hrtimer callback modes:
  *
  *     HRTIMER_CB_SOFTIRQ:             Callback must run in softirq context
- *     HRTIMER_CB_IRQSAFE:             Callback may run in hardirq context
- *     HRTIMER_CB_IRQSAFE_NO_RESTART:  Callback may run in hardirq context and
- *                                     does not restart the timer
  *     HRTIMER_CB_IRQSAFE_PERCPU:      Callback must run in hardirq context
  *                                     Special mode for tick emulation and
  *                                     scheduler timer. Such timers are per
@@ -61,8 +58,6 @@ enum hrtimer_restart {
  */
 enum hrtimer_cb_mode {
        HRTIMER_CB_SOFTIRQ,
-       HRTIMER_CB_IRQSAFE,
-       HRTIMER_CB_IRQSAFE_NO_RESTART,
        HRTIMER_CB_IRQSAFE_PERCPU,
        HRTIMER_CB_IRQSAFE_UNLOCKED,
 };
index fba141d3ca0783303c661f39fb2c503ba418dc56..dc7e0d0a6474448aba71b4c32d2045afc44e240e 100644 (file)
@@ -318,32 +318,36 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
        return buf;
 }
 
-#define pr_emerg(fmt, arg...) \
-       printk(KERN_EMERG fmt, ##arg)
-#define pr_alert(fmt, arg...) \
-       printk(KERN_ALERT fmt, ##arg)
-#define pr_crit(fmt, arg...) \
-       printk(KERN_CRIT fmt, ##arg)
-#define pr_err(fmt, arg...) \
-       printk(KERN_ERR fmt, ##arg)
-#define pr_warning(fmt, arg...) \
-       printk(KERN_WARNING fmt, ##arg)
-#define pr_notice(fmt, arg...) \
-       printk(KERN_NOTICE fmt, ##arg)
-#define pr_info(fmt, arg...) \
-       printk(KERN_INFO fmt, ##arg)
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+#define pr_emerg(fmt, ...) \
+        printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert(fmt, ...) \
+        printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit(fmt, ...) \
+        printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err(fmt, ...) \
+        printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning(fmt, ...) \
+        printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice(fmt, ...) \
+        printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info(fmt, ...) \
+        printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
 
 /* If you are writing a driver, please use dev_dbg instead */
 #if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
 #define pr_debug(fmt, ...) do { \
-       dynamic_pr_debug(fmt, ##__VA_ARGS__); \
+       dynamic_pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
        } while (0)
 #elif defined(DEBUG)
-#define pr_debug(fmt, arg...) \
-       printk(KERN_DEBUG fmt, ##arg)
+#define pr_debug(fmt, ...) \
+       printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
 #else
-#define pr_debug(fmt, arg...) \
-       ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
+#define pr_debug(fmt, ...) \
+       ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
 #endif
 
 /*
index dfda69e9f4409ca973385dc1cb7d1123fb21194c..24add2bef6c9240a30023e82766059bc8b31f81d 100644 (file)
 
 struct wm8350_rtc {
        struct platform_device *pdev;
+       struct rtc_device *rtc;
+       int alarm_enabled;      /* used over suspend/resume */
 };
 
 #endif
index 18a5b9ba9d40180b53273d75556bb529eafb8dd0..00044b856453f45bf886ddc3b237ac3744323ac3 100644 (file)
@@ -17,11 +17,4 @@ struct ratelimit_state {
                struct ratelimit_state name = {interval, burst,}
 
 extern int __ratelimit(struct ratelimit_state *rs);
-
-static inline int ratelimit(void)
-{
-       static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
-                                       DEFAULT_RATELIMIT_BURST);
-       return __ratelimit(&rs);
-}
 #endif
index ba965c84ae0695b175da712a0951b6c3e0530b5c..000da12b5cf03650ad90db9be142d803930fb62e 100644 (file)
 #define SLAB_CACHE_DMA         0x00004000UL    /* Use GFP_DMA memory */
 #define SLAB_STORE_USER                0x00010000UL    /* DEBUG: Store the last owner for bug hunting */
 #define SLAB_PANIC             0x00040000UL    /* Panic if kmem_cache_create() fails */
+/*
+ * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
+ *
+ * This delays freeing the SLAB page by a grace period, it does _NOT_
+ * delay object freeing. This means that if you do kmem_cache_free()
+ * that memory location is free to be reused at any time. Thus it may
+ * be possible to see another object there in the same RCU grace period.
+ *
+ * This feature only ensures the memory location backing the object
+ * stays valid, the trick to using this is relying on an independent
+ * object validation pass. Something like:
+ *
+ *  rcu_read_lock()
+ * again:
+ *  obj = lockless_lookup(key);
+ *  if (obj) {
+ *    if (!try_get_ref(obj)) // might fail for free objects
+ *      goto again;
+ *
+ *    if (obj->key != key) { // not the object we expected
+ *      put_ref(obj);
+ *      goto again;
+ *    }
+ *  }
+ *  rcu_read_unlock();
+ *
+ * See also the comment on struct slab_rcu in mm/slab.c.
+ */
 #define SLAB_DESTROY_BY_RCU    0x00080000UL    /* Defer freeing slabs to RCU */
 #define SLAB_MEM_SPREAD                0x00100000UL    /* Spread some memory over cpuset */
 #define SLAB_TRACE             0x00200000UL    /* Trace allocations and frees */
index 8fa973bede5e1930d8b96317b9fbc99305a4d66b..f72aa51f7bcdc3fdb3d728c452cdd12f2d3d9baf 100644 (file)
@@ -108,6 +108,7 @@ enum usb_interface_condition {
  *     (in probe()), bound to a driver, or unbinding (in disconnect())
  * @is_active: flag set when the interface is bound and not suspended.
  * @sysfs_files_created: sysfs attributes exist
+ * @unregistering: flag set when the interface is being unregistered
  * @needs_remote_wakeup: flag set when the driver requires remote-wakeup
  *     capability during autosuspend.
  * @needs_altsetting0: flag set when a set-interface request for altsetting 0
@@ -163,6 +164,7 @@ struct usb_interface {
        enum usb_interface_condition condition;         /* state of binding */
        unsigned is_active:1;           /* the interface is not suspended */
        unsigned sysfs_files_created:1; /* the sysfs attributes exist */
+       unsigned unregistering:1;       /* unregistration is in progress */
        unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
        unsigned needs_altsetting0:1;   /* switch to altsetting 0 is pending */
        unsigned needs_binding:1;       /* needs delayed unbind/rebind */
index 6ad87f48599284c809371c533f287b748268097f..0c864db1a4662a5e1c89f902830e5cf4a7f91efc 100644 (file)
@@ -38,7 +38,7 @@ struct atmel_lcdfb_info {
        spinlock_t              lock;
        struct fb_info          *info;
        void __iomem            *mmio;
-       unsigned long           irq_base;
+       int                     irq_base;
        struct work_struct      task;
 
        unsigned int            guard_time;
index 86b00c53fadeb833d054fab64d13fb9a0e8d6fde..226da2733c1e7f8a885d8db735f11605136fa103 100644 (file)
@@ -771,8 +771,7 @@ config SLAB
        help
          The regular slab allocator that is established and known to work
          well in all environments. It organizes cache hot objects in
-         per cpu and per node queues. SLAB is the default choice for
-         a slab allocator.
+         per cpu and per node queues.
 
 config SLUB
        bool "SLUB (Unqueued Allocator)"
@@ -781,7 +780,8 @@ config SLUB
           instead of managing queues of cached objects (SLAB approach).
           Per cpu caching is realized using slabs of objects instead
           of queues of objects. SLUB can use memory efficiently
-          and has enhanced diagnostics.
+          and has enhanced diagnostics. SLUB is the default choice for
+          a slab allocator.
 
 config SLOB
        depends on EMBEDDED
index 7fa476f01d05568ac42541391f935b23b4145c80..fb249e2bcada880a19105488c7fdde33e9483126 100644 (file)
@@ -184,9 +184,20 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
 {
        struct freezer *freezer;
 
-       task_lock(task);
+       /*
+        * No lock is needed, since the task isn't on tasklist yet,
+        * so it can't be moved to another cgroup, which means the
+        * freezer won't be removed and will be valid during this
+        * function call.
+        */
        freezer = task_freezer(task);
-       task_unlock(task);
+
+       /*
+        * The root cgroup is non-freezable, so we can skip the
+        * following check.
+        */
+       if (!freezer->css.cgroup->parent)
+               return;
 
        spin_lock_irq(&freezer->lock);
        BUG_ON(freezer->state == CGROUP_FROZEN);
@@ -331,7 +342,7 @@ static int freezer_write(struct cgroup *cgroup,
        else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0)
                goal_state = CGROUP_FROZEN;
        else
-               return -EIO;
+               return -EINVAL;
 
        if (!cgroup_lock_live_group(cgroup))
                return -ENODEV;
@@ -350,6 +361,8 @@ static struct cftype files[] = {
 
 static int freezer_populate(struct cgroup_subsys *ss, struct cgroup *cgroup)
 {
+       if (!cgroup->parent)
+               return 0;
        return cgroup_add_files(cgroup, ss, files, ARRAY_SIZE(files));
 }
 
index ae2b92be5faec1efa73beefb63304a22d030fc16..2d8be7ebb0f73499f894a1828fd827f0217290f1 100644 (file)
@@ -40,7 +40,6 @@
 #include <linux/cn_proc.h>
 #include <linux/mutex.h>
 #include <linux/futex.h>
-#include <linux/compat.h>
 #include <linux/pipe_fs_i.h>
 #include <linux/audit.h> /* for audit_free() */
 #include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
                exit_itimers(tsk->signal);
        }
        acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
-       if (unlikely(tsk->robust_list))
-               exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
-       if (unlikely(tsk->compat_robust_list))
-               compat_exit_robust_list(tsk);
-#endif
-#endif
        if (group_dead)
                tty_audit_exit();
        if (unlikely(tsk->audit_context))
index f6083561dfe0a9f8d2a13138f7332bc358a51653..2a372a0e206fa2de99dbfdd594f86f6eb927bf40 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/jiffies.h>
 #include <linux/tracehook.h>
 #include <linux/futex.h>
+#include <linux/compat.h>
 #include <linux/task_io_accounting_ops.h>
 #include <linux/rcupdate.h>
 #include <linux/ptrace.h>
@@ -519,6 +520,16 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
 {
        struct completion *vfork_done = tsk->vfork_done;
 
+       /* Get rid of any futexes when releasing the mm */
+#ifdef CONFIG_FUTEX
+       if (unlikely(tsk->robust_list))
+               exit_robust_list(tsk);
+#ifdef CONFIG_COMPAT
+       if (unlikely(tsk->compat_robust_list))
+               compat_exit_robust_list(tsk);
+#endif
+#endif
+
        /* Get rid of any cached register state */
        deactivate_mm(tsk, mm);
 
index 95d3949f2ae51135b181906f632b8de7f5e3f8e7..47e63349d1b2d262be2d8be568af8d3d93de3333 100644 (file)
@@ -664,14 +664,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
 
                /* Timer is expired, act upon the callback mode */
                switch(timer->cb_mode) {
-               case HRTIMER_CB_IRQSAFE_NO_RESTART:
-                       debug_hrtimer_deactivate(timer);
-                       /*
-                        * We can call the callback from here. No restart
-                        * happens, so no danger of recursion
-                        */
-                       BUG_ON(timer->function(timer) != HRTIMER_NORESTART);
-                       return 1;
                case HRTIMER_CB_IRQSAFE_PERCPU:
                case HRTIMER_CB_IRQSAFE_UNLOCKED:
                        /*
@@ -683,7 +675,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
                         */
                        debug_hrtimer_deactivate(timer);
                        return 1;
-               case HRTIMER_CB_IRQSAFE:
                case HRTIMER_CB_SOFTIRQ:
                        /*
                         * Move everything else into the softirq pending list !
index 8b57a2597f21fda9c9602e27028753f1f7325234..9f8a3f25259a9da4c8535bab07014b07da79a643 100644 (file)
@@ -72,7 +72,7 @@ static bool kprobe_enabled;
 DEFINE_MUTEX(kprobe_mutex);            /* Protects kprobe_table */
 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
 static struct {
-       spinlock_t lock ____cacheline_aligned;
+       spinlock_t lock ____cacheline_aligned_in_smp;
 } kretprobe_table_locks[KPROBE_TABLE_SIZE];
 
 static spinlock_t *kretprobe_table_lock_ptr(unsigned long hash)
@@ -613,30 +613,37 @@ static int __kprobes __register_kprobe(struct kprobe *p,
                return -EINVAL;
        p->addr = addr;
 
-       if (!kernel_text_address((unsigned long) p->addr) ||
-           in_kprobes_functions((unsigned long) p->addr))
+       preempt_disable();
+       if (!__kernel_text_address((unsigned long) p->addr) ||
+           in_kprobes_functions((unsigned long) p->addr)) {
+               preempt_enable();
                return -EINVAL;
+       }
 
        p->mod_refcounted = 0;
 
        /*
         * Check if are we probing a module.
         */
-       probed_mod = module_text_address((unsigned long) p->addr);
+       probed_mod = __module_text_address((unsigned long) p->addr);
        if (probed_mod) {
-               struct module *calling_mod = module_text_address(called_from);
+               struct module *calling_mod;
+               calling_mod = __module_text_address(called_from);
                /*
                 * We must allow modules to probe themself and in this case
                 * avoid incrementing the module refcount, so as to allow
                 * unloading of self probing modules.
                 */
                if (calling_mod && calling_mod != probed_mod) {
-                       if (unlikely(!try_module_get(probed_mod)))
+                       if (unlikely(!try_module_get(probed_mod))) {
+                               preempt_enable();
                                return -EINVAL;
+                       }
                        p->mod_refcounted = 1;
                } else
                        probed_mod = NULL;
        }
+       preempt_enable();
 
        p->nmissed = 0;
        INIT_LIST_HEAD(&p->list);
@@ -718,6 +725,10 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p)
        struct kprobe *old_p;
 
        if (p->mod_refcounted) {
+               /*
+                * Since we've already incremented refcount,
+                * we don't need to disable preemption.
+                */
                mod = module_text_address((unsigned long)p->addr);
                if (mod)
                        module_put(mod);
index 50a21f964679ec42eee299cab7f7f86edc26a408..c94baf2969e7b7e663050f31805986688ce106d0 100644 (file)
@@ -1456,6 +1456,8 @@ static unsigned long cpu_avg_load_per_task(int cpu)
 
        if (rq->nr_running)
                rq->avg_load_per_task = rq->load.weight / rq->nr_running;
+       else
+               rq->avg_load_per_task = 0;
 
        return rq->avg_load_per_task;
 }
@@ -5868,6 +5870,8 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
        struct rq *rq = cpu_rq(cpu);
        unsigned long flags;
 
+       spin_lock_irqsave(&rq->lock, flags);
+
        __sched_fork(idle);
        idle->se.exec_start = sched_clock();
 
@@ -5875,7 +5879,6 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
        idle->cpus_allowed = cpumask_of_cpu(cpu);
        __set_task_cpu(idle, cpu);
 
-       spin_lock_irqsave(&rq->lock, flags);
        rq->curr = rq->idle = idle;
 #if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
        idle->oncpu = 1;
index d143ab67be444119b6240c5f8461a72fe2fc9647..6058b53dcb8905bc33bc25371083b47167de7596 100644 (file)
@@ -1796,6 +1796,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
 static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
                                struct page *page, unsigned long address)
 {
+       struct hstate *h = hstate_vma(vma);
        struct vm_area_struct *iter_vma;
        struct address_space *mapping;
        struct prio_tree_iter iter;
@@ -1805,7 +1806,7 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
         * vm_pgoff is in PAGE_SIZE units, hence the different calculation
         * from page cache lookup which is in HPAGE_SIZE units.
         */
-       address = address & huge_page_mask(hstate_vma(vma));
+       address = address & huge_page_mask(h);
        pgoff = ((address - vma->vm_start) >> PAGE_SHIFT)
                + (vma->vm_pgoff >> PAGE_SHIFT);
        mapping = (struct address_space *)page_private(page);
@@ -1824,7 +1825,7 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
                 */
                if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER))
                        unmap_hugepage_range(iter_vma,
-                               address, address + HPAGE_SIZE,
+                               address, address + huge_page_size(h),
                                page);
        }
 
index 008ea70b7afa9a2baed56cdc9b6b43ef0b05a6ff..a6da2aee940af0873f46bd1b88b24a36242979b3 100644 (file)
@@ -66,14 +66,10 @@ void __clear_page_mlock(struct page *page)
                putback_lru_page(page);
        } else {
                /*
-                * Page not on the LRU yet.  Flush all pagevecs and retry.
+                * We lost the race. the page already moved to evictable list.
                 */
-               lru_add_drain_all();
-               if (!isolate_lru_page(page))
-                       putback_lru_page(page);
-               else if (PageUnevictable(page))
+               if (PageUnevictable(page))
                        count_vm_event(UNEVICTABLE_PGSTRANDED);
-
        }
 }
 
@@ -187,8 +183,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
        if (vma->vm_flags & VM_WRITE)
                gup_flags |= GUP_FLAGS_WRITE;
 
-       lru_add_drain_all();    /* push cached pages to LRU */
-
        while (nr_pages > 0) {
                int i;
 
@@ -251,8 +245,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
                ret = 0;
        }
 
-       lru_add_drain_all();    /* to update stats */
-
        return ret;     /* count entire vma as locked_vm */
 }
 
@@ -546,6 +538,8 @@ asmlinkage long sys_mlock(unsigned long start, size_t len)
        if (!can_do_mlock())
                return -EPERM;
 
+       lru_add_drain_all();    /* flush pagevec */
+
        down_write(&current->mm->mmap_sem);
        len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
        start &= PAGE_MASK;
@@ -612,6 +606,8 @@ asmlinkage long sys_mlockall(int flags)
        if (!can_do_mlock())
                goto out;
 
+       lru_add_drain_all();    /* flush pagevec */
+
        down_write(&current->mm->mmap_sem);
 
        lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
index 54069e64e3a8a4b0c9a0450aba08b7f0fa21c5f9..d8ac01474563954fed58a1f87e2249c99827c430 100644 (file)
@@ -1561,6 +1561,10 @@ nofail_alloc:
 
        /* We now go into synchronous reclaim */
        cpuset_memory_pressure_bump();
+       /*
+        * The task's cpuset might have expanded its set of allowable nodes
+        */
+       cpuset_update_task_memory_state();
        p->flags |= PF_MEMALLOC;
        reclaim_state.reclaimed_slab = 0;
        p->reclaim_state = &reclaim_state;
index f59d797dc5a9b28ddcb3eae0f0aeeb4bc6e6daad..1223d927904d196d652911e222bc4a50140c627b 100644 (file)
@@ -165,7 +165,7 @@ int online_page_cgroup(unsigned long start_pfn,
        unsigned long start, end, pfn;
        int fail = 0;
 
-       start = start_pfn & (PAGES_PER_SECTION - 1);
+       start = start_pfn & ~(PAGES_PER_SECTION - 1);
        end = ALIGN(start_pfn + nr_pages, PAGES_PER_SECTION);
 
        for (pfn = start; !fail && pfn < end; pfn += PAGES_PER_SECTION) {
@@ -188,7 +188,7 @@ int offline_page_cgroup(unsigned long start_pfn,
 {
        unsigned long start, end, pfn;
 
-       start = start_pfn & (PAGES_PER_SECTION - 1);
+       start = start_pfn & ~(PAGES_PER_SECTION - 1);
        end = ALIGN(start_pfn + nr_pages, PAGES_PER_SECTION);
 
        for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION)
index 3b5860294bb6654a7b6765a327cef83a9952a29d..c141b3e780719d314a5010f702190d8a9c56c23b 100644 (file)
@@ -2368,39 +2368,6 @@ int page_evictable(struct page *page, struct vm_area_struct *vma)
        return 1;
 }
 
-static void show_page_path(struct page *page)
-{
-       char buf[256];
-       if (page_is_file_cache(page)) {
-               struct address_space *mapping = page->mapping;
-               struct dentry *dentry;
-               pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
-
-               spin_lock(&mapping->i_mmap_lock);
-               dentry = d_find_alias(mapping->host);
-               printk(KERN_INFO "rescued: %s %lu\n",
-                      dentry_path(dentry, buf, 256), pgoff);
-               spin_unlock(&mapping->i_mmap_lock);
-       } else {
-#if defined(CONFIG_MM_OWNER) && defined(CONFIG_MMU)
-               struct anon_vma *anon_vma;
-               struct vm_area_struct *vma;
-
-               anon_vma = page_lock_anon_vma(page);
-               if (!anon_vma)
-                       return;
-
-               list_for_each_entry(vma, &anon_vma->head, anon_vma_node) {
-                       printk(KERN_INFO "rescued: anon %s\n",
-                              vma->vm_mm->owner->comm);
-                       break;
-               }
-               page_unlock_anon_vma(anon_vma);
-#endif
-       }
-}
-
-
 /**
  * check_move_unevictable_page - check page for evictability and move to appropriate zone lru list
  * @page: page to check evictability and move to appropriate lru list
@@ -2421,8 +2388,6 @@ retry:
        if (page_evictable(page, NULL)) {
                enum lru_list l = LRU_INACTIVE_ANON + page_is_file_cache(page);
 
-               show_page_path(page);
-
                __dec_zone_state(zone, NR_UNEVICTABLE);
                list_move(&page->lru, &zone->lru[l].list);
                __inc_zone_state(zone, NR_INACTIVE_ANON + l);
index c42c0c400bf9a36176ceedcac6a94083016e5b8d..0663f99e977a8af81e1c149d3b193b6b94acb520 100644 (file)
@@ -13,22 +13,24 @@ menuconfig NET_9P
 
          If unsure, say N.
 
+if NET_9P
+
 config NET_9P_VIRTIO
-       depends on NET_9P && EXPERIMENTAL && VIRTIO
+       depends on EXPERIMENTAL && VIRTIO
        tristate "9P Virtio Transport (Experimental)"
        help
          This builds support for a transports between
          guest partitions and a host partition.
 
 config NET_9P_RDMA
-       depends on NET_9P && INFINIBAND && EXPERIMENTAL
+       depends on INET && INFINIBAND && EXPERIMENTAL
        tristate "9P RDMA Transport (Experimental)"
        help
-         This builds support for a RDMA transport.
+         This builds support for an RDMA transport.
 
 config NET_9P_DEBUG
        bool "Debug information"
-       depends on NET_9P
        help
          Say Y if you want the 9P subsystem to log debug information.
 
+endif
index 67fb6a3834a3a538221b347c309842cda1816521..6ce1a1cadcc02417a30667d0f6d9ce92bf9416a0 100644 (file)
@@ -226,14 +226,14 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
                return 0; /* XXX: return error? check spec. */
        }
 
-       if (level == SOL_SOCKET && type == SO_TIMESTAMP) {
+       if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
                struct timeval *tv = (struct timeval *)data;
                ctv.tv_sec = tv->tv_sec;
                ctv.tv_usec = tv->tv_usec;
                data = &ctv;
                len = sizeof(ctv);
        }
-       if (level == SOL_SOCKET && type == SO_TIMESTAMPNS) {
+       if (level == SOL_SOCKET && type == SCM_TIMESTAMPNS) {
                struct timespec *ts = (struct timespec *)data;
                cts.tv_sec = ts->tv_sec;
                cts.tv_nsec = ts->tv_nsec;
index af99776146ffc14a4f85cb08ceaaea619d7b8a90..937549b8a9212fa6289964bde303367e2f462d74 100644 (file)
@@ -69,9 +69,12 @@ static u32 htcp_cwnd_undo(struct sock *sk)
        const struct tcp_sock *tp = tcp_sk(sk);
        struct htcp *ca = inet_csk_ca(sk);
 
-       ca->last_cong = ca->undo_last_cong;
-       ca->maxRTT = ca->undo_maxRTT;
-       ca->old_maxB = ca->undo_old_maxB;
+       if (ca->undo_last_cong) {
+               ca->last_cong = ca->undo_last_cong;
+               ca->maxRTT = ca->undo_maxRTT;
+               ca->old_maxB = ca->undo_old_maxB;
+               ca->undo_last_cong = 0;
+       }
 
        return max(tp->snd_cwnd, (tp->snd_ssthresh << 7) / ca->beta);
 }
@@ -268,7 +271,10 @@ static void htcp_state(struct sock *sk, u8 new_state)
        case TCP_CA_Open:
                {
                        struct htcp *ca = inet_csk_ca(sk);
-                       ca->last_cong = jiffies;
+                       if (ca->undo_last_cong) {
+                               ca->last_cong = jiffies;
+                               ca->undo_last_cong = 0;
+                       }
                }
                break;
        case TCP_CA_CWR:
index 87665d7bb4f9aa0bad666295914edca3dfefa701..14d165f0df75ff90e1ec9648b4454245cdbcd153 100644 (file)
@@ -2570,14 +2570,14 @@ void ieee80211_notify_mac(struct ieee80211_hw *hw,
 
        switch (notif_type) {
        case IEEE80211_NOTIFY_RE_ASSOC:
-               rcu_read_lock();
-               list_for_each_entry_rcu(sdata, &local->interfaces, list) {
+               rtnl_lock();
+               list_for_each_entry(sdata, &local->interfaces, list) {
                        if (sdata->vif.type != NL80211_IFTYPE_STATION)
                                continue;
 
                        ieee80211_sta_req_auth(sdata, &sdata->u.sta);
                }
-               rcu_read_unlock();
+               rtnl_unlock();
                break;
        }
 }