aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-devices-mmc21
-rw-r--r--Documentation/devicetree/bindings/open-pic.txt98
-rw-r--r--Documentation/feature-removal-schedule.txt19
-rw-r--r--Documentation/i2c/busses/i2c-i8013
-rw-r--r--Documentation/i2c/instantiating-devices2
-rw-r--r--Documentation/i2c/upgrading-clients18
-rw-r--r--Documentation/video4linux/Zoran2
-rw-r--r--Makefile7
-rw-r--r--arch/arm/boot/compressed/Makefile4
-rw-r--r--arch/arm/mach-mxs/include/mach/mmc.h18
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c8
-rw-r--r--arch/arm/plat-mxc/include/mach/esdhc.h12
-rw-r--r--arch/arm/vfp/Makefile4
-rw-r--r--arch/blackfin/Kconfig42
-rw-r--r--arch/blackfin/configs/BF518F-EZBRD_defconfig1
-rw-r--r--arch/blackfin/configs/BF526-EZBRD_defconfig1
-rw-r--r--arch/blackfin/configs/BF527-EZKIT-V2_defconfig1
-rw-r--r--arch/blackfin/configs/BF527-EZKIT_defconfig1
-rw-r--r--arch/blackfin/configs/BF533-EZKIT_defconfig1
-rw-r--r--arch/blackfin/configs/BF533-STAMP_defconfig1
-rw-r--r--arch/blackfin/configs/BF537-STAMP_defconfig1
-rw-r--r--arch/blackfin/configs/BF538-EZKIT_defconfig1
-rw-r--r--arch/blackfin/configs/BF548-EZKIT_defconfig1
-rw-r--r--arch/blackfin/configs/BF561-EZKIT-SMP_defconfig1
-rw-r--r--arch/blackfin/configs/BF561-EZKIT_defconfig1
-rw-r--r--arch/blackfin/include/asm/def_LPBlackfin.h16
-rw-r--r--arch/blackfin/include/asm/dpmc.h3
-rw-r--r--arch/blackfin/include/asm/ipipe.h95
-rw-r--r--arch/blackfin/include/asm/ipipe_base.h11
-rw-r--r--arch/blackfin/include/asm/irqflags.h87
-rw-r--r--arch/blackfin/include/asm/smp.h9
-rw-r--r--arch/blackfin/include/asm/unistd.h5
-rw-r--r--arch/blackfin/kernel/bfin_dma_5xx.c32
-rw-r--r--arch/blackfin/kernel/ipipe.c84
-rw-r--r--arch/blackfin/kernel/irqchip.c10
-rw-r--r--arch/blackfin/kernel/kgdb.c4
-rw-r--r--arch/blackfin/kernel/setup.c37
-rw-r--r--arch/blackfin/kernel/vmlinux.lds.S3
-rw-r--r--arch/blackfin/mach-bf518/include/mach/defBF512.h19
-rw-r--r--arch/blackfin/mach-bf527/include/mach/defBF522.h19
-rw-r--r--arch/blackfin/mach-bf533/boards/ip0x.c2
-rw-r--r--arch/blackfin/mach-bf537/boards/cm_bf537e.c2
-rw-r--r--arch/blackfin/mach-bf537/boards/cm_bf537u.c2
-rw-r--r--arch/blackfin/mach-bf537/boards/dnp5370.c20
-rw-r--r--arch/blackfin/mach-bf537/boards/tcm_bf537.c2
-rw-r--r--arch/blackfin/mach-bf537/include/mach/defBF534.h18
-rw-r--r--arch/blackfin/mach-bf548/Kconfig59
-rw-r--r--arch/blackfin/mach-bf548/boards/ezkit.c55
-rw-r--r--arch/blackfin/mach-bf548/include/mach/defBF544.h18
-rw-r--r--arch/blackfin/mach-bf548/include/mach/defBF547.h19
-rw-r--r--arch/blackfin/mach-bf548/include/mach/dma.h28
-rw-r--r--arch/blackfin/mach-bf548/include/mach/irq.h4
-rw-r--r--arch/blackfin/mach-bf561/boards/cm_bf561.c2
-rw-r--r--arch/blackfin/mach-bf561/hotplug.c21
-rw-r--r--arch/blackfin/mach-bf561/secondary.S35
-rw-r--r--arch/blackfin/mach-bf561/smp.c15
-rw-r--r--arch/blackfin/mach-common/arch_checks.c2
-rw-r--r--arch/blackfin/mach-common/cache.S38
-rw-r--r--arch/blackfin/mach-common/cpufreq.c8
-rw-r--r--arch/blackfin/mach-common/dpmc.c50
-rw-r--r--arch/blackfin/mach-common/entry.S14
-rw-r--r--arch/blackfin/mach-common/head.S110
-rw-r--r--arch/blackfin/mach-common/interrupt.S6
-rw-r--r--arch/blackfin/mach-common/ints-priority.c236
-rw-r--r--arch/blackfin/mach-common/smp.c28
-rw-r--r--arch/h8300/boot/compressed/Makefile2
-rw-r--r--arch/ia64/kvm/Makefile4
-rw-r--r--arch/ia64/sn/kernel/Makefile2
-rw-r--r--arch/ia64/sn/kernel/sn2/Makefile2
-rw-r--r--arch/ia64/sn/pci/Makefile2
-rw-r--r--arch/ia64/sn/pci/pcibr/Makefile2
-rw-r--r--arch/ia64/uv/kernel/Makefile2
-rw-r--r--arch/microblaze/kernel/cpu/Makefile2
-rw-r--r--arch/mips/Makefile4
-rw-r--r--arch/mips/bcm63xx/boards/Makefile2
-rw-r--r--arch/mips/fw/arc/Makefile2
-rw-r--r--arch/mips/jz4740/Makefile2
-rw-r--r--arch/mips/oprofile/Makefile2
-rw-r--r--arch/mips/pmc-sierra/yosemite/Makefile2
-rw-r--r--arch/mips/powertv/Makefile2
-rw-r--r--arch/mips/powertv/asic/Makefile2
-rw-r--r--arch/mips/powertv/pci/Makefile2
-rw-r--r--arch/mn10300/Kconfig18
-rw-r--r--arch/mn10300/include/asm/intctl-regs.h5
-rw-r--r--arch/mn10300/kernel/Makefile5
-rw-r--r--arch/mn10300/kernel/cevt-mn10300.c11
-rw-r--r--arch/mn10300/kernel/csrc-mn10300.c3
-rw-r--r--arch/mn10300/kernel/internal.h10
-rw-r--r--arch/mn10300/kernel/irq.c91
-rw-r--r--arch/mn10300/kernel/mn10300-serial.c16
-rw-r--r--arch/mn10300/kernel/smp.c30
-rw-r--r--arch/mn10300/kernel/time.c82
-rw-r--r--arch/mn10300/unit-asb2364/include/unit/fpga-regs.h2
-rw-r--r--arch/mn10300/unit-asb2364/include/unit/serial.h24
-rw-r--r--arch/mn10300/unit-asb2364/irq-fpga.c37
-rw-r--r--arch/mn10300/unit-asb2364/unit-init.c44
-rw-r--r--arch/powerpc/include/asm/mpic.h4
-rw-r--r--arch/powerpc/include/asm/ptrace.h2
-rw-r--r--arch/powerpc/kernel/pci_dn.c7
-rw-r--r--arch/powerpc/kernel/ptrace.c15
-rw-r--r--arch/powerpc/sysdev/mpic.c85
-rw-r--r--arch/s390/boot/Makefile2
-rw-r--r--arch/s390/kvm/Makefile2
-rw-r--r--arch/s390/math-emu/Makefile2
-rw-r--r--arch/tile/lib/atomic_32.c12
-rw-r--r--arch/um/sys-ppc/Makefile10
-rw-r--r--arch/xtensa/boot/Makefile2
-rw-r--r--arch/xtensa/boot/lib/Makefile2
-rw-r--r--drivers/char/mwave/Makefile4
-rw-r--r--drivers/char/mwave/README2
-rw-r--r--drivers/dma/Makefile8
-rw-r--r--drivers/hid/hid-apple.c6
-rw-r--r--drivers/hid/hid-core.c6
-rw-r--r--drivers/hid/hid-ids.h3
-rw-r--r--drivers/hid/hid-input.c4
-rw-r--r--drivers/hwmon/Makefile4
-rw-r--r--drivers/i2c/Makefile1
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-i801.c4
-rw-r--r--drivers/i2c/i2c-boardinfo.c2
-rw-r--r--drivers/i2c/i2c-core.c28
-rw-r--r--drivers/i2c/i2c-dev.c60
-rw-r--r--drivers/ide/Makefile2
-rw-r--r--drivers/ieee802154/Makefile2
-rw-r--r--drivers/input/Kconfig10
-rw-r--r--drivers/input/Makefile2
-rw-r--r--drivers/input/evdev.c10
-rw-r--r--drivers/input/input-polldev.c4
-rw-r--r--drivers/input/input.c55
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/lm8323.c15
-rw-r--r--drivers/input/keyboard/max7359_keypad.c17
-rw-r--r--drivers/input/keyboard/mcs_touchkey.c57
-rw-r--r--drivers/input/keyboard/omap4-keypad.c74
-rw-r--r--drivers/input/keyboard/qt1070.c276
-rw-r--r--drivers/input/keyboard/tc3589x-keypad.c22
-rw-r--r--drivers/input/keyboard/tca6416-keypad.c28
-rw-r--r--drivers/input/misc/Kconfig13
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/ad714x-i2c.c17
-rw-r--r--drivers/input/misc/ad714x-spi.c17
-rw-r--r--drivers/input/misc/adxl34x-i2c.c16
-rw-r--r--drivers/input/misc/adxl34x-spi.c20
-rw-r--r--drivers/input/misc/ati_remote2.c4
-rw-r--r--drivers/input/misc/uinput.c48
-rw-r--r--drivers/input/misc/xen-kbdfront.c (renamed from drivers/input/xen-kbdfront.c)83
-rw-r--r--drivers/input/mouse/bcm5974.c28
-rw-r--r--drivers/input/mouse/synaptics_i2c.c16
-rw-r--r--drivers/input/sparse-keymap.c4
-rw-r--r--drivers/input/tablet/wacom_sys.c12
-rw-r--r--drivers/input/tablet/wacom_wac.c247
-rw-r--r--drivers/input/tablet/wacom_wac.h6
-rw-r--r--drivers/input/touchscreen/Kconfig45
-rw-r--r--drivers/input/touchscreen/Makefile4
-rw-r--r--drivers/input/touchscreen/ad7877.c19
-rw-r--r--drivers/input/touchscreen/ad7879-spi.c17
-rw-r--r--drivers/input/touchscreen/ads7846.c16
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c1211
-rw-r--r--drivers/input/touchscreen/qt602240_ts.c1406
-rw-r--r--drivers/input/touchscreen/tsc2005.c756
-rw-r--r--drivers/input/touchscreen/wm831x-ts.c368
-rw-r--r--drivers/isdn/hisax/Makefile2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c109
-rw-r--r--drivers/media/rc/rc-main.c4
-rw-r--r--drivers/memstick/Makefile4
-rw-r--r--drivers/memstick/core/Makefile4
-rw-r--r--drivers/memstick/host/Makefile4
-rw-r--r--drivers/message/fusion/Makefile2
-rw-r--r--drivers/misc/cb710/Makefile4
-rw-r--r--drivers/misc/sgi-gru/Makefile4
-rw-r--r--drivers/mmc/card/Kconfig3
-rw-r--r--drivers/mmc/card/block.c1
-rw-r--r--drivers/mmc/card/mmc_test.c271
-rw-r--r--drivers/mmc/core/Makefile3
-rw-r--r--drivers/mmc/core/core.c26
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/host.c5
-rw-r--r--drivers/mmc/core/mmc.c86
-rw-r--r--drivers/mmc/core/quirks.c84
-rw-r--r--drivers/mmc/core/sd.c1
-rw-r--r--drivers/mmc/core/sdio.c9
-rw-r--r--drivers/mmc/host/Kconfig11
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/atmel-mci.c19
-rw-r--r--drivers/mmc/host/cb710-mmc.c2
-rw-r--r--drivers/mmc/host/dw_mmc.c83
-rw-r--r--drivers/mmc/host/dw_mmc.h2
-rw-r--r--drivers/mmc/host/msm_sdcc.c8
-rw-r--r--drivers/mmc/host/mxcmmc.c181
-rw-r--r--drivers/mmc/host/mxs-mmc.c874
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c134
-rw-r--r--drivers/mmc/host/sdhci-esdhc.h1
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c3
-rw-r--r--drivers/mmc/host/sdhci-pci.c12
-rw-r--r--drivers/mmc/host/sdhci-s3c.c3
-rw-r--r--drivers/mmc/host/sdhci-tegra.c6
-rw-r--r--drivers/mmc/host/sh_mmcif.c62
-rw-r--r--drivers/mmc/host/tmio_mmc.c96
-rw-r--r--drivers/mmc/host/via-sdmmc.c3
-rw-r--r--drivers/net/caif/Makefile4
-rw-r--r--drivers/net/r8169.c4
-rw-r--r--drivers/net/skfp/Makefile2
-rw-r--r--drivers/net/wan/lmc/Makefile2
-rw-r--r--drivers/net/wireless/hostap/hostap_config.h4
-rw-r--r--drivers/net/wireless/zd1211rw/Makefile4
-rw-r--r--drivers/pps/clients/Makefile4
-rw-r--r--drivers/rapidio/Makefile4
-rw-r--r--drivers/rapidio/switches/Makefile4
-rw-r--r--drivers/rtc/Makefile4
-rw-r--r--drivers/scsi/aacraid/Makefile2
-rw-r--r--drivers/scsi/aic94xx/Makefile4
-rw-r--r--drivers/scsi/libsas/Makefile2
-rw-r--r--drivers/scsi/lpfc/Makefile6
-rw-r--r--drivers/scsi/mvsas/Makefile4
-rw-r--r--drivers/scsi/pcmcia/Makefile2
-rw-r--r--drivers/usb/core/driver.c15
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/core/usb.h3
-rw-r--r--drivers/video/intelfb/Makefile5
-rw-r--r--fs/affs/Makefile2
-rw-r--r--fs/coda/Makefile2
-rw-r--r--fs/gfs2/Makefile2
-rw-r--r--fs/jfs/Makefile2
-rw-r--r--fs/ncpfs/Makefile2
-rw-r--r--fs/nilfs2/alloc.c12
-rw-r--r--fs/nilfs2/bmap.c12
-rw-r--r--fs/nilfs2/bmap.h3
-rw-r--r--fs/nilfs2/btree.c6
-rw-r--r--fs/nilfs2/dir.c5
-rw-r--r--fs/nilfs2/direct.c4
-rw-r--r--fs/nilfs2/file.c4
-rw-r--r--fs/nilfs2/inode.c83
-rw-r--r--fs/nilfs2/ioctl.c115
-rw-r--r--fs/nilfs2/mdt.h2
-rw-r--r--fs/nilfs2/namei.c2
-rw-r--r--fs/nilfs2/nilfs.h33
-rw-r--r--fs/nilfs2/recovery.c32
-rw-r--r--fs/nilfs2/sb.h85
-rw-r--r--fs/nilfs2/segment.c258
-rw-r--r--fs/nilfs2/segment.h14
-rw-r--r--fs/nilfs2/super.c214
-rw-r--r--fs/nilfs2/the_nilfs.c44
-rw-r--r--fs/nilfs2/the_nilfs.h51
-rw-r--r--fs/ntfs/Makefile19
-rw-r--r--fs/ocfs2/Makefile4
-rw-r--r--fs/ocfs2/dlm/Makefile2
-rw-r--r--fs/ocfs2/dlmfs/Makefile2
-rw-r--r--fs/reiserfs/Makefile4
-rw-r--r--fs/xfs/Makefile7
-rw-r--r--include/asm-generic/unistd.h4
-rw-r--r--include/linux/i2c-id.h37
-rw-r--r--include/linux/i2c.h18
-rw-r--r--include/linux/i2c/atmel_mxt_ts.h (renamed from include/linux/i2c/qt602240_ts.h)34
-rw-r--r--include/linux/i2c/mcs.h1
-rw-r--r--include/linux/input-polldev.h4
-rw-r--r--include/linux/input.h12
-rw-r--r--include/linux/magic.h1
-rw-r--r--include/linux/mfd/wm831x/pdata.h3
-rw-r--r--include/linux/mmc/card.h6
-rw-r--r--include/linux/mmc/core.h1
-rw-r--r--include/linux/mmc/dw_mmc.h15
-rw-r--r--include/linux/mmc/mmc.h3
-rw-r--r--include/linux/nilfs2_fs.h32
-rw-r--r--include/linux/spi/tsc2005.h41
-rw-r--r--kernel/gcov/Makefile2
-rw-r--r--kernel/power/Makefile3
-rwxr-xr-xscripts/extract-ikconfig9
-rw-r--r--scripts/package/Makefile5
-rw-r--r--scripts/package/buildtar4
-rwxr-xr-xscripts/setlocalversion14
-rwxr-xr-xscripts/tags.sh9
272 files changed, 6951 insertions, 3699 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-mmc b/Documentation/ABI/testing/sysfs-devices-mmc
new file mode 100644
index 000000000000..5a50ab655843
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-mmc
@@ -0,0 +1,21 @@
1What: /sys/devices/.../mmc_host/mmcX/mmcX:XXXX/enhanced_area_offset
2Date: January 2011
3Contact: Chuanxiao Dong <chuanxiao.dong@intel.com>
4Description:
5 Enhanced area is a new feature defined in eMMC4.4 standard.
6 eMMC4.4 or later card can support such feature. This kind of
7 area can help to improve the card performance. If the feature
8 is enabled, this attribute will indicate the start address of
9 enhanced data area. If not, this attribute will be -EINVAL.
10 Unit Byte. Format decimal.
11
12What: /sys/devices/.../mmc_host/mmcX/mmcX:XXXX/enhanced_area_size
13Date: January 2011
14Contact: Chuanxiao Dong <chuanxiao.dong@intel.com>
15Description:
16 Enhanced area is a new feature defined in eMMC4.4 standard.
17 eMMC4.4 or later card can support such feature. This kind of
18 area can help to improve the card performance. If the feature
19 is enabled, this attribute will indicate the size of enhanced
20 data area. If not, this attribute will be -EINVAL.
21 Unit KByte. Format decimal.
diff --git a/Documentation/devicetree/bindings/open-pic.txt b/Documentation/devicetree/bindings/open-pic.txt
new file mode 100644
index 000000000000..909a902dff85
--- /dev/null
+++ b/Documentation/devicetree/bindings/open-pic.txt
@@ -0,0 +1,98 @@
1* Open PIC Binding
2
3This binding specifies what properties must be available in the device tree
4representation of an Open PIC compliant interrupt controller. This binding is
5based on the binding defined for Open PIC in [1] and is a superset of that
6binding.
7
8Required properties:
9
10 NOTE: Many of these descriptions were paraphrased here from [1] to aid
11 readability.
12
13 - compatible: Specifies the compatibility list for the PIC. The type
14 shall be <string> and the value shall include "open-pic".
15
16 - reg: Specifies the base physical address(s) and size(s) of this
17 PIC's addressable register space. The type shall be <prop-encoded-array>.
18
19 - interrupt-controller: The presence of this property identifies the node
20 as an Open PIC. No property value shall be defined.
21
22 - #interrupt-cells: Specifies the number of cells needed to encode an
23 interrupt source. The type shall be a <u32> and the value shall be 2.
24
25 - #address-cells: Specifies the number of cells needed to encode an
26 address. The type shall be <u32> and the value shall be 0. As such,
27 'interrupt-map' nodes do not have to specify a parent unit address.
28
29Optional properties:
30
31 - pic-no-reset: The presence of this property indicates that the PIC
32 shall not be reset during runtime initialization. No property value shall
33 be defined. The presence of this property also mandates that any
34 initialization related to interrupt sources shall be limited to sources
35 explicitly referenced in the device tree.
36
37* Interrupt Specifier Definition
38
39 Interrupt specifiers consists of 2 cells encoded as
40 follows:
41
42 - <1st-cell>: The interrupt-number that identifies the interrupt source.
43
44 - <2nd-cell>: The level-sense information, encoded as follows:
45 0 = low-to-high edge triggered
46 1 = active low level-sensitive
47 2 = active high level-sensitive
48 3 = high-to-low edge triggered
49
50* Examples
51
52Example 1:
53
54 /*
55 * An Open PIC interrupt controller
56 */
57 mpic: pic@40000 {
58 // This is an interrupt controller node.
59 interrupt-controller;
60
61 // No address cells so that 'interrupt-map' nodes which reference
62 // this Open PIC node do not need a parent address specifier.
63 #address-cells = <0>;
64
65 // Two cells to encode interrupt sources.
66 #interrupt-cells = <2>;
67
68 // Offset address of 0x40000 and size of 0x40000.
69 reg = <0x40000 0x40000>;
70
71 // Compatible with Open PIC.
72 compatible = "open-pic";
73
74 // The PIC shall not be reset.
75 pic-no-reset;
76 };
77
78Example 2:
79
80 /*
81 * An interrupt generating device that is wired to an Open PIC.
82 */
83 serial0: serial@4500 {
84 // Interrupt source '42' that is active high level-sensitive.
85 // Note that there are only two cells as specified in the interrupt
86 // parent's '#interrupt-cells' property.
87 interrupts = <42 2>;
88
89 // The interrupt controller that this device is wired to.
90 interrupt-parent = <&mpic>;
91 };
92
93* References
94
95[1] Power.org (TM) Standard for Embedded Power Architecture (TM) Platform
96 Requirements (ePAPR), Version 1.0, July 2008.
97 (http://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf)
98
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index f487c6918d78..895330940f5d 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -585,16 +585,6 @@ Who: NeilBrown <neilb@suse.de>
585 585
586---------------------------- 586----------------------------
587 587
588What: i2c_adapter.id
589When: June 2011
590Why: This field is deprecated. I2C device drivers shouldn't change their
591 behavior based on the underlying I2C adapter. Instead, the I2C
592 adapter driver should instantiate the I2C devices and provide the
593 needed platform-specific information.
594Who: Jean Delvare <khali@linux-fr.org>
595
596----------------------------
597
598What: cancel_rearming_delayed_work[queue]() 588What: cancel_rearming_delayed_work[queue]()
599When: 2.6.39 589When: 2.6.39
600 590
@@ -645,3 +635,12 @@ Who: Florian Westphal <fw@strlen.de>
645Files: include/linux/netfilter_ipv4/ipt_addrtype.h 635Files: include/linux/netfilter_ipv4/ipt_addrtype.h
646 636
647---------------------------- 637----------------------------
638
639What: i2c_driver.attach_adapter
640 i2c_driver.detach_adapter
641When: September 2011
642Why: These legacy callbacks should no longer be used as i2c-core offers
643 a variety of preferable alternative ways to instantiate I2C devices.
644Who: Jean Delvare <khali@linux-fr.org>
645
646----------------------------
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index 93fe76e56522..6df69765ccb7 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -16,8 +16,9 @@ Supported adapters:
16 * Intel EP80579 (Tolapai) 16 * Intel EP80579 (Tolapai)
17 * Intel 82801JI (ICH10) 17 * Intel 82801JI (ICH10)
18 * Intel 5/3400 Series (PCH) 18 * Intel 5/3400 Series (PCH)
19 * Intel Cougar Point (PCH) 19 * Intel 6 Series (PCH)
20 * Intel Patsburg (PCH) 20 * Intel Patsburg (PCH)
21 * Intel DH89xxCC (PCH)
21 Datasheets: Publicly available at the Intel website 22 Datasheets: Publicly available at the Intel website
22 23
23On Intel Patsburg and later chipsets, both the normal host SMBus controller 24On Intel Patsburg and later chipsets, both the normal host SMBus controller
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices
index 87da405a8597..9edb75d8c9b9 100644
--- a/Documentation/i2c/instantiating-devices
+++ b/Documentation/i2c/instantiating-devices
@@ -100,7 +100,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
100 (...) 100 (...)
101 i2c_adap = i2c_get_adapter(2); 101 i2c_adap = i2c_get_adapter(2);
102 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 102 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
103 strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); 103 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
104 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 104 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
105 normal_i2c, NULL); 105 normal_i2c, NULL);
106 i2c_put_adapter(i2c_adap); 106 i2c_put_adapter(i2c_adap);
diff --git a/Documentation/i2c/upgrading-clients b/Documentation/i2c/upgrading-clients
index 9a45f9bb6a25..d6991625c407 100644
--- a/Documentation/i2c/upgrading-clients
+++ b/Documentation/i2c/upgrading-clients
@@ -61,7 +61,7 @@ static int example_attach(struct i2c_adapter *adap, int addr, int kind)
61 return 0; 61 return 0;
62} 62}
63 63
64static int __devexit example_detach(struct i2c_client *client) 64static int example_detach(struct i2c_client *client)
65{ 65{
66 struct example_state *state = i2c_get_clientdata(client); 66 struct example_state *state = i2c_get_clientdata(client);
67 67
@@ -81,7 +81,7 @@ static struct i2c_driver example_driver = {
81 .name = "example", 81 .name = "example",
82 }, 82 },
83 .attach_adapter = example_attach_adapter, 83 .attach_adapter = example_attach_adapter,
84 .detach_client = __devexit_p(example_detach), 84 .detach_client = example_detach,
85 .suspend = example_suspend, 85 .suspend = example_suspend,
86 .resume = example_resume, 86 .resume = example_resume,
87}; 87};
@@ -93,7 +93,7 @@ Updating the client
93The new style binding model will check against a list of supported 93The new style binding model will check against a list of supported
94devices and their associated address supplied by the code registering 94devices and their associated address supplied by the code registering
95the busses. This means that the driver .attach_adapter and 95the busses. This means that the driver .attach_adapter and
96.detach_adapter methods can be removed, along with the addr_data, 96.detach_client methods can be removed, along with the addr_data,
97as follows: 97as follows:
98 98
99- static struct i2c_driver example_driver; 99- static struct i2c_driver example_driver;
@@ -110,14 +110,14 @@ as follows:
110 110
111 static struct i2c_driver example_driver = { 111 static struct i2c_driver example_driver = {
112- .attach_adapter = example_attach_adapter, 112- .attach_adapter = example_attach_adapter,
113- .detach_client = __devexit_p(example_detach), 113- .detach_client = example_detach,
114 } 114 }
115 115
116Add the probe and remove methods to the i2c_driver, as so: 116Add the probe and remove methods to the i2c_driver, as so:
117 117
118 static struct i2c_driver example_driver = { 118 static struct i2c_driver example_driver = {
119+ .probe = example_probe, 119+ .probe = example_probe,
120+ .remove = __devexit_p(example_remove), 120+ .remove = example_remove,
121 } 121 }
122 122
123Change the example_attach method to accept the new parameters 123Change the example_attach method to accept the new parameters
@@ -199,8 +199,8 @@ to delete the i2c_detach_client call. It is possible that you
199can also remove the ret variable as it is not not needed for 199can also remove the ret variable as it is not not needed for
200any of the core functions. 200any of the core functions.
201 201
202- static int __devexit example_detach(struct i2c_client *client) 202- static int example_detach(struct i2c_client *client)
203+ static int __devexit example_remove(struct i2c_client *client) 203+ static int example_remove(struct i2c_client *client)
204{ 204{
205 struct example_state *state = i2c_get_clientdata(client); 205 struct example_state *state = i2c_get_clientdata(client);
206 206
@@ -253,7 +253,7 @@ static int example_probe(struct i2c_client *client,
253 return 0; 253 return 0;
254} 254}
255 255
256static int __devexit example_remove(struct i2c_client *client) 256static int example_remove(struct i2c_client *client)
257{ 257{
258 struct example_state *state = i2c_get_clientdata(client); 258 struct example_state *state = i2c_get_clientdata(client);
259 259
@@ -275,7 +275,7 @@ static struct i2c_driver example_driver = {
275 }, 275 },
276 .id_table = example_idtable, 276 .id_table = example_idtable,
277 .probe = example_probe, 277 .probe = example_probe,
278 .remove = __devexit_p(example_remove), 278 .remove = example_remove,
279 .suspend = example_suspend, 279 .suspend = example_suspend,
280 .resume = example_resume, 280 .resume = example_resume,
281}; 281};
diff --git a/Documentation/video4linux/Zoran b/Documentation/video4linux/Zoran
index 699b60e070d2..c40e3bab08fa 100644
--- a/Documentation/video4linux/Zoran
+++ b/Documentation/video4linux/Zoran
@@ -130,7 +130,7 @@ Card number: 4
130 130
131Note: No module for the mse3000 is available yet 131Note: No module for the mse3000 is available yet
132Note: No module for the vpx3224 is available yet 132Note: No module for the vpx3224 is available yet
133Note: use encoder=X or decoder=X for non-default i2c chips (see i2c-id.h) 133Note: use encoder=X or decoder=X for non-default i2c chips
134 134
135=========================== 135===========================
136 136
diff --git a/Makefile b/Makefile
index 92b8bed3059e..9193f94ddf83 100644
--- a/Makefile
+++ b/Makefile
@@ -421,7 +421,7 @@ endif
421# of make so .config is not included in this case either (for *config). 421# of make so .config is not included in this case either (for *config).
422 422
423no-dot-config-targets := clean mrproper distclean \ 423no-dot-config-targets := clean mrproper distclean \
424 cscope TAGS tags help %docs check% coccicheck \ 424 cscope gtags TAGS tags help %docs check% coccicheck \
425 include/linux/version.h headers_% \ 425 include/linux/version.h headers_% \
426 kernelversion %src-pkg 426 kernelversion %src-pkg
427 427
@@ -1135,7 +1135,7 @@ CLEAN_FILES += vmlinux System.map \
1135MRPROPER_DIRS += include/config usr/include include/generated 1135MRPROPER_DIRS += include/config usr/include include/generated
1136MRPROPER_FILES += .config .config.old .version .old_version \ 1136MRPROPER_FILES += .config .config.old .version .old_version \
1137 include/linux/version.h \ 1137 include/linux/version.h \
1138 Module.symvers tags TAGS cscope* 1138 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
1139 1139
1140# clean - Delete most, but leave enough to build external modules 1140# clean - Delete most, but leave enough to build external modules
1141# 1141#
@@ -1222,6 +1222,7 @@ help:
1222 @echo ' modules_prepare - Set up for building external modules' 1222 @echo ' modules_prepare - Set up for building external modules'
1223 @echo ' tags/TAGS - Generate tags file for editors' 1223 @echo ' tags/TAGS - Generate tags file for editors'
1224 @echo ' cscope - Generate cscope index' 1224 @echo ' cscope - Generate cscope index'
1225 @echo ' gtags - Generate GNU GLOBAL index'
1225 @echo ' kernelrelease - Output the release version string' 1226 @echo ' kernelrelease - Output the release version string'
1226 @echo ' kernelversion - Output the version stored in Makefile' 1227 @echo ' kernelversion - Output the version stored in Makefile'
1227 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 1228 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
@@ -1380,7 +1381,7 @@ clean: $(clean-dirs)
1380quiet_cmd_tags = GEN $@ 1381quiet_cmd_tags = GEN $@
1381 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ 1382 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
1382 1383
1383tags TAGS cscope: FORCE 1384tags TAGS cscope gtags: FORCE
1384 $(call cmd,tags) 1385 $(call cmd,tags)
1385 1386
1386# Scripts to check various things for consistency 1387# Scripts to check various things for consistency
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index f9f77c65dff3..8ebbb511c783 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -95,8 +95,8 @@ ORIG_CFLAGS := $(KBUILD_CFLAGS)
95KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS)) 95KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
96endif 96endif
97 97
98EXTRA_CFLAGS := -fpic -fno-builtin 98ccflags-y := -fpic -fno-builtin
99EXTRA_AFLAGS := -Wa,-march=all 99asflags-y := -Wa,-march=all
100 100
101# Provide size of uncompressed kernel to the decompressor via a linker symbol. 101# Provide size of uncompressed kernel to the decompressor via a linker symbol.
102LDFLAGS_vmlinux = --defsym _image_size=$(shell stat -c "%s" $(obj)/../Image) 102LDFLAGS_vmlinux = --defsym _image_size=$(shell stat -c "%s" $(obj)/../Image)
diff --git a/arch/arm/mach-mxs/include/mach/mmc.h b/arch/arm/mach-mxs/include/mach/mmc.h
new file mode 100644
index 000000000000..211547a05564
--- /dev/null
+++ b/arch/arm/mach-mxs/include/mach/mmc.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#ifndef __MACH_MXS_MMC_H__
10#define __MACH_MXS_MMC_H__
11
12struct mxs_mmc_platform_data {
13 int wp_gpio; /* write protect pin */
14 unsigned int flags;
15#define SLOTF_4_BIT_CAPABLE (1 << 0)
16#define SLOTF_8_BIT_CAPABLE (1 << 1)
17};
18#endif /* __MACH_MXS_MMC_H__ */
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index 243291722c66..31d5aa769753 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -15,7 +15,7 @@
15#include <linux/fb.h> 15#include <linux/fb.h>
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/i2c-gpio.h> 17#include <linux/i2c-gpio.h>
18#include <linux/i2c/qt602240_ts.h> 18#include <linux/i2c/atmel_mxt_ts.h>
19#include <linux/mfd/max8998.h> 19#include <linux/mfd/max8998.h>
20#include <linux/mfd/wm8994/pdata.h> 20#include <linux/mfd/wm8994/pdata.h>
21#include <linux/regulator/fixed.h> 21#include <linux/regulator/fixed.h>
@@ -25,6 +25,7 @@
25#include <linux/gpio_keys.h> 25#include <linux/gpio_keys.h>
26#include <linux/input.h> 26#include <linux/input.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/interrupt.h>
28 29
29#include <asm/mach/arch.h> 30#include <asm/mach/arch.h>
30#include <asm/mach/map.h> 31#include <asm/mach/map.h>
@@ -225,7 +226,7 @@ static void __init goni_radio_init(void)
225} 226}
226 227
227/* TSP */ 228/* TSP */
228static struct qt602240_platform_data qt602240_platform_data = { 229static struct mxt_platform_data qt602240_platform_data = {
229 .x_line = 17, 230 .x_line = 17,
230 .y_line = 11, 231 .y_line = 11,
231 .x_size = 800, 232 .x_size = 800,
@@ -233,7 +234,8 @@ static struct qt602240_platform_data qt602240_platform_data = {
233 .blen = 0x21, 234 .blen = 0x21,
234 .threshold = 0x28, 235 .threshold = 0x28,
235 .voltage = 2800000, /* 2.8V */ 236 .voltage = 2800000, /* 2.8V */
236 .orient = QT602240_DIAGONAL, 237 .orient = MXT_DIAGONAL,
238 .irqflags = IRQF_TRIGGER_FALLING,
237}; 239};
238 240
239static struct s3c2410_platform_i2c i2c2_data __initdata = { 241static struct s3c2410_platform_i2c i2c2_data __initdata = {
diff --git a/arch/arm/plat-mxc/include/mach/esdhc.h b/arch/arm/plat-mxc/include/mach/esdhc.h
index a48a9aaa56b1..86003f411755 100644
--- a/arch/arm/plat-mxc/include/mach/esdhc.h
+++ b/arch/arm/plat-mxc/include/mach/esdhc.h
@@ -10,7 +10,17 @@
10#ifndef __ASM_ARCH_IMX_ESDHC_H 10#ifndef __ASM_ARCH_IMX_ESDHC_H
11#define __ASM_ARCH_IMX_ESDHC_H 11#define __ASM_ARCH_IMX_ESDHC_H
12 12
13/**
14 * struct esdhc_platform_data - optional platform data for esdhc on i.MX
15 *
16 * strongly recommended for i.MX25/35, not needed for other variants
17 *
18 * @wp_gpio: gpio for write_protect (-EINVAL if unused)
19 * @cd_gpio: gpio for card_detect interrupt (-EINVAL if unused)
20 */
21
13struct esdhc_platform_data { 22struct esdhc_platform_data {
14 unsigned int wp_gpio; /* write protect pin */ 23 unsigned int wp_gpio;
24 unsigned int cd_gpio;
15}; 25};
16#endif /* __ASM_ARCH_IMX_ESDHC_H */ 26#endif /* __ASM_ARCH_IMX_ESDHC_H */
diff --git a/arch/arm/vfp/Makefile b/arch/arm/vfp/Makefile
index 39f6d8e1af73..6de73aab0195 100644
--- a/arch/arm/vfp/Makefile
+++ b/arch/arm/vfp/Makefile
@@ -4,8 +4,8 @@
4# Copyright (C) 2001 ARM Limited 4# Copyright (C) 2001 ARM Limited
5# 5#
6 6
7# EXTRA_CFLAGS := -DDEBUG 7# ccflags-y := -DDEBUG
8# EXTRA_AFLAGS := -DDEBUG 8# asflags-y := -DDEBUG
9 9
10KBUILD_AFLAGS :=$(KBUILD_AFLAGS:-msoft-float=-Wa,-mfpu=softvfp+vfp) 10KBUILD_AFLAGS :=$(KBUILD_AFLAGS:-msoft-float=-Wa,-mfpu=softvfp+vfp)
11LDFLAGS +=--no-warn-mismatch 11LDFLAGS +=--no-warn-mismatch
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index c09577ddc3c5..01615d4f57d6 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -33,6 +33,7 @@ config BLACKFIN
33 select HAVE_GENERIC_HARDIRQS 33 select HAVE_GENERIC_HARDIRQS
34 select GENERIC_IRQ_PROBE 34 select GENERIC_IRQ_PROBE
35 select IRQ_PER_CPU if SMP 35 select IRQ_PER_CPU if SMP
36 select GENERIC_HARDIRQS_NO_DEPRECATED
36 37
37config GENERIC_CSUM 38config GENERIC_CSUM
38 def_bool y 39 def_bool y
@@ -690,13 +691,13 @@ endmenu
690 691
691 692
692menu "Blackfin Kernel Optimizations" 693menu "Blackfin Kernel Optimizations"
693 depends on !SMP
694 694
695comment "Memory Optimizations" 695comment "Memory Optimizations"
696 696
697config I_ENTRY_L1 697config I_ENTRY_L1
698 bool "Locate interrupt entry code in L1 Memory" 698 bool "Locate interrupt entry code in L1 Memory"
699 default y 699 default y
700 depends on !SMP
700 help 701 help
701 If enabled, interrupt entry code (STORE/RESTORE CONTEXT) is linked 702 If enabled, interrupt entry code (STORE/RESTORE CONTEXT) is linked
702 into L1 instruction memory. (less latency) 703 into L1 instruction memory. (less latency)
@@ -704,6 +705,7 @@ config I_ENTRY_L1
704config EXCPT_IRQ_SYSC_L1 705config EXCPT_IRQ_SYSC_L1
705 bool "Locate entire ASM lowlevel exception / interrupt - Syscall and CPLB handler code in L1 Memory" 706 bool "Locate entire ASM lowlevel exception / interrupt - Syscall and CPLB handler code in L1 Memory"
706 default y 707 default y
708 depends on !SMP
707 help 709 help
708 If enabled, the entire ASM lowlevel exception and interrupt entry code 710 If enabled, the entire ASM lowlevel exception and interrupt entry code
709 (STORE/RESTORE CONTEXT) is linked into L1 instruction memory. 711 (STORE/RESTORE CONTEXT) is linked into L1 instruction memory.
@@ -712,6 +714,7 @@ config EXCPT_IRQ_SYSC_L1
712config DO_IRQ_L1 714config DO_IRQ_L1
713 bool "Locate frequently called do_irq dispatcher function in L1 Memory" 715 bool "Locate frequently called do_irq dispatcher function in L1 Memory"
714 default y 716 default y
717 depends on !SMP
715 help 718 help
716 If enabled, the frequently called do_irq dispatcher function is linked 719 If enabled, the frequently called do_irq dispatcher function is linked
717 into L1 instruction memory. (less latency) 720 into L1 instruction memory. (less latency)
@@ -719,6 +722,7 @@ config DO_IRQ_L1
719config CORE_TIMER_IRQ_L1 722config CORE_TIMER_IRQ_L1
720 bool "Locate frequently called timer_interrupt() function in L1 Memory" 723 bool "Locate frequently called timer_interrupt() function in L1 Memory"
721 default y 724 default y
725 depends on !SMP
722 help 726 help
723 If enabled, the frequently called timer_interrupt() function is linked 727 If enabled, the frequently called timer_interrupt() function is linked
724 into L1 instruction memory. (less latency) 728 into L1 instruction memory. (less latency)
@@ -726,6 +730,7 @@ config CORE_TIMER_IRQ_L1
726config IDLE_L1 730config IDLE_L1
727 bool "Locate frequently idle function in L1 Memory" 731 bool "Locate frequently idle function in L1 Memory"
728 default y 732 default y
733 depends on !SMP
729 help 734 help
730 If enabled, the frequently called idle function is linked 735 If enabled, the frequently called idle function is linked
731 into L1 instruction memory. (less latency) 736 into L1 instruction memory. (less latency)
@@ -733,6 +738,7 @@ config IDLE_L1
733config SCHEDULE_L1 738config SCHEDULE_L1
734 bool "Locate kernel schedule function in L1 Memory" 739 bool "Locate kernel schedule function in L1 Memory"
735 default y 740 default y
741 depends on !SMP
736 help 742 help
737 If enabled, the frequently called kernel schedule is linked 743 If enabled, the frequently called kernel schedule is linked
738 into L1 instruction memory. (less latency) 744 into L1 instruction memory. (less latency)
@@ -740,6 +746,7 @@ config SCHEDULE_L1
740config ARITHMETIC_OPS_L1 746config ARITHMETIC_OPS_L1
741 bool "Locate kernel owned arithmetic functions in L1 Memory" 747 bool "Locate kernel owned arithmetic functions in L1 Memory"
742 default y 748 default y
749 depends on !SMP
743 help 750 help
744 If enabled, arithmetic functions are linked 751 If enabled, arithmetic functions are linked
745 into L1 instruction memory. (less latency) 752 into L1 instruction memory. (less latency)
@@ -747,6 +754,7 @@ config ARITHMETIC_OPS_L1
747config ACCESS_OK_L1 754config ACCESS_OK_L1
748 bool "Locate access_ok function in L1 Memory" 755 bool "Locate access_ok function in L1 Memory"
749 default y 756 default y
757 depends on !SMP
750 help 758 help
751 If enabled, the access_ok function is linked 759 If enabled, the access_ok function is linked
752 into L1 instruction memory. (less latency) 760 into L1 instruction memory. (less latency)
@@ -754,6 +762,7 @@ config ACCESS_OK_L1
754config MEMSET_L1 762config MEMSET_L1
755 bool "Locate memset function in L1 Memory" 763 bool "Locate memset function in L1 Memory"
756 default y 764 default y
765 depends on !SMP
757 help 766 help
758 If enabled, the memset function is linked 767 If enabled, the memset function is linked
759 into L1 instruction memory. (less latency) 768 into L1 instruction memory. (less latency)
@@ -761,6 +770,7 @@ config MEMSET_L1
761config MEMCPY_L1 770config MEMCPY_L1
762 bool "Locate memcpy function in L1 Memory" 771 bool "Locate memcpy function in L1 Memory"
763 default y 772 default y
773 depends on !SMP
764 help 774 help
765 If enabled, the memcpy function is linked 775 If enabled, the memcpy function is linked
766 into L1 instruction memory. (less latency) 776 into L1 instruction memory. (less latency)
@@ -768,6 +778,7 @@ config MEMCPY_L1
768config STRCMP_L1 778config STRCMP_L1
769 bool "locate strcmp function in L1 Memory" 779 bool "locate strcmp function in L1 Memory"
770 default y 780 default y
781 depends on !SMP
771 help 782 help
772 If enabled, the strcmp function is linked 783 If enabled, the strcmp function is linked
773 into L1 instruction memory (less latency). 784 into L1 instruction memory (less latency).
@@ -775,6 +786,7 @@ config STRCMP_L1
775config STRNCMP_L1 786config STRNCMP_L1
776 bool "locate strncmp function in L1 Memory" 787 bool "locate strncmp function in L1 Memory"
777 default y 788 default y
789 depends on !SMP
778 help 790 help
779 If enabled, the strncmp function is linked 791 If enabled, the strncmp function is linked
780 into L1 instruction memory (less latency). 792 into L1 instruction memory (less latency).
@@ -782,6 +794,7 @@ config STRNCMP_L1
782config STRCPY_L1 794config STRCPY_L1
783 bool "locate strcpy function in L1 Memory" 795 bool "locate strcpy function in L1 Memory"
784 default y 796 default y
797 depends on !SMP
785 help 798 help
786 If enabled, the strcpy function is linked 799 If enabled, the strcpy function is linked
787 into L1 instruction memory (less latency). 800 into L1 instruction memory (less latency).
@@ -789,6 +802,7 @@ config STRCPY_L1
789config STRNCPY_L1 802config STRNCPY_L1
790 bool "locate strncpy function in L1 Memory" 803 bool "locate strncpy function in L1 Memory"
791 default y 804 default y
805 depends on !SMP
792 help 806 help
793 If enabled, the strncpy function is linked 807 If enabled, the strncpy function is linked
794 into L1 instruction memory (less latency). 808 into L1 instruction memory (less latency).
@@ -796,6 +810,7 @@ config STRNCPY_L1
796config SYS_BFIN_SPINLOCK_L1 810config SYS_BFIN_SPINLOCK_L1
797 bool "Locate sys_bfin_spinlock function in L1 Memory" 811 bool "Locate sys_bfin_spinlock function in L1 Memory"
798 default y 812 default y
813 depends on !SMP
799 help 814 help
800 If enabled, sys_bfin_spinlock function is linked 815 If enabled, sys_bfin_spinlock function is linked
801 into L1 instruction memory. (less latency) 816 into L1 instruction memory. (less latency)
@@ -803,6 +818,7 @@ config SYS_BFIN_SPINLOCK_L1
803config IP_CHECKSUM_L1 818config IP_CHECKSUM_L1
804 bool "Locate IP Checksum function in L1 Memory" 819 bool "Locate IP Checksum function in L1 Memory"
805 default n 820 default n
821 depends on !SMP
806 help 822 help
807 If enabled, the IP Checksum function is linked 823 If enabled, the IP Checksum function is linked
808 into L1 instruction memory. (less latency) 824 into L1 instruction memory. (less latency)
@@ -811,7 +827,7 @@ config CACHELINE_ALIGNED_L1
811 bool "Locate cacheline_aligned data to L1 Data Memory" 827 bool "Locate cacheline_aligned data to L1 Data Memory"
812 default y if !BF54x 828 default y if !BF54x
813 default n if BF54x 829 default n if BF54x
814 depends on !BF531 830 depends on !SMP && !BF531
815 help 831 help
816 If enabled, cacheline_aligned data is linked 832 If enabled, cacheline_aligned data is linked
817 into L1 data memory. (less latency) 833 into L1 data memory. (less latency)
@@ -819,7 +835,7 @@ config CACHELINE_ALIGNED_L1
819config SYSCALL_TAB_L1 835config SYSCALL_TAB_L1
820 bool "Locate Syscall Table L1 Data Memory" 836 bool "Locate Syscall Table L1 Data Memory"
821 default n 837 default n
822 depends on !BF531 838 depends on !SMP && !BF531
823 help 839 help
824 If enabled, the Syscall LUT is linked 840 If enabled, the Syscall LUT is linked
825 into L1 data memory. (less latency) 841 into L1 data memory. (less latency)
@@ -827,16 +843,16 @@ config SYSCALL_TAB_L1
827config CPLB_SWITCH_TAB_L1 843config CPLB_SWITCH_TAB_L1
828 bool "Locate CPLB Switch Tables L1 Data Memory" 844 bool "Locate CPLB Switch Tables L1 Data Memory"
829 default n 845 default n
830 depends on !BF531 846 depends on !SMP && !BF531
831 help 847 help
832 If enabled, the CPLB Switch Tables are linked 848 If enabled, the CPLB Switch Tables are linked
833 into L1 data memory. (less latency) 849 into L1 data memory. (less latency)
834 850
835config CACHE_FLUSH_L1 851config ICACHE_FLUSH_L1
836 bool "Locate cache flush funcs in L1 Inst Memory" 852 bool "Locate icache flush funcs in L1 Inst Memory"
837 default y 853 default y
838 help 854 help
839 If enabled, the Blackfin cache flushing functions are linked 855 If enabled, the Blackfin icache flushing functions are linked
840 into L1 instruction memory. 856 into L1 instruction memory.
841 857
842 Note that this might be required to address anomalies, but 858 Note that this might be required to address anomalies, but
@@ -844,9 +860,18 @@ config CACHE_FLUSH_L1
844 If you are using a processor affected by an anomaly, the build 860 If you are using a processor affected by an anomaly, the build
845 system will double check for you and prevent it. 861 system will double check for you and prevent it.
846 862
863config DCACHE_FLUSH_L1
864 bool "Locate dcache flush funcs in L1 Inst Memory"
865 default y
866 depends on !SMP
867 help
868 If enabled, the Blackfin dcache flushing functions are linked
869 into L1 instruction memory.
870
847config APP_STACK_L1 871config APP_STACK_L1
848 bool "Support locating application stack in L1 Scratch Memory" 872 bool "Support locating application stack in L1 Scratch Memory"
849 default y 873 default y
874 depends on !SMP
850 help 875 help
851 If enabled the application stack can be located in L1 876 If enabled the application stack can be located in L1
852 scratch memory (less latency). 877 scratch memory (less latency).
@@ -856,7 +881,7 @@ config APP_STACK_L1
856config EXCEPTION_L1_SCRATCH 881config EXCEPTION_L1_SCRATCH
857 bool "Locate exception stack in L1 Scratch Memory" 882 bool "Locate exception stack in L1 Scratch Memory"
858 default n 883 default n
859 depends on !APP_STACK_L1 884 depends on !SMP && !APP_STACK_L1
860 help 885 help
861 Whenever an exception occurs, use the L1 Scratch memory for 886 Whenever an exception occurs, use the L1 Scratch memory for
862 stack storage. You cannot place the stacks of FLAT binaries 887 stack storage. You cannot place the stacks of FLAT binaries
@@ -868,6 +893,7 @@ comment "Speed Optimizations"
868config BFIN_INS_LOWOVERHEAD 893config BFIN_INS_LOWOVERHEAD
869 bool "ins[bwl] low overhead, higher interrupt latency" 894 bool "ins[bwl] low overhead, higher interrupt latency"
870 default y 895 default y
896 depends on !SMP
871 help 897 help
872 Reads on the Blackfin are speculative. In Blackfin terms, this means 898 Reads on the Blackfin are speculative. In Blackfin terms, this means
873 they can be interrupted at any time (even after they have been issued 899 they can be interrupted at any time (even after they have been issued
diff --git a/arch/blackfin/configs/BF518F-EZBRD_defconfig b/arch/blackfin/configs/BF518F-EZBRD_defconfig
index db8d38a12a9a..5edcb58d6f73 100644
--- a/arch/blackfin/configs/BF518F-EZBRD_defconfig
+++ b/arch/blackfin/configs/BF518F-EZBRD_defconfig
@@ -115,6 +115,7 @@ CONFIG_DEBUG_DOUBLEFAULT=y
115CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 115CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
116CONFIG_EARLY_PRINTK=y 116CONFIG_EARLY_PRINTK=y
117CONFIG_CPLB_INFO=y 117CONFIG_CPLB_INFO=y
118CONFIG_BFIN_PSEUDODBG_INSNS=y
118CONFIG_CRYPTO=y 119CONFIG_CRYPTO=y
119# CONFIG_CRYPTO_ANSI_CPRNG is not set 120# CONFIG_CRYPTO_ANSI_CPRNG is not set
120CONFIG_CRC_CCITT=m 121CONFIG_CRC_CCITT=m
diff --git a/arch/blackfin/configs/BF526-EZBRD_defconfig b/arch/blackfin/configs/BF526-EZBRD_defconfig
index 3e50d7857c27..2e549572d4f5 100644
--- a/arch/blackfin/configs/BF526-EZBRD_defconfig
+++ b/arch/blackfin/configs/BF526-EZBRD_defconfig
@@ -153,6 +153,7 @@ CONFIG_DEBUG_DOUBLEFAULT=y
153CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 153CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
154CONFIG_EARLY_PRINTK=y 154CONFIG_EARLY_PRINTK=y
155CONFIG_CPLB_INFO=y 155CONFIG_CPLB_INFO=y
156CONFIG_BFIN_PSEUDODBG_INSNS=y
156CONFIG_CRYPTO=y 157CONFIG_CRYPTO=y
157# CONFIG_CRYPTO_ANSI_CPRNG is not set 158# CONFIG_CRYPTO_ANSI_CPRNG is not set
158CONFIG_CRC_CCITT=m 159CONFIG_CRC_CCITT=m
diff --git a/arch/blackfin/configs/BF527-EZKIT-V2_defconfig b/arch/blackfin/configs/BF527-EZKIT-V2_defconfig
index 023ff0df2692..95cf2ba9de17 100644
--- a/arch/blackfin/configs/BF527-EZKIT-V2_defconfig
+++ b/arch/blackfin/configs/BF527-EZKIT-V2_defconfig
@@ -183,5 +183,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
183CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 183CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
184CONFIG_EARLY_PRINTK=y 184CONFIG_EARLY_PRINTK=y
185CONFIG_CPLB_INFO=y 185CONFIG_CPLB_INFO=y
186CONFIG_BFIN_PSEUDODBG_INSNS=y
186CONFIG_CRYPTO=y 187CONFIG_CRYPTO=y
187# CONFIG_CRYPTO_ANSI_CPRNG is not set 188# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF527-EZKIT_defconfig b/arch/blackfin/configs/BF527-EZKIT_defconfig
index 4e5a121b3c56..8be8e33fac52 100644
--- a/arch/blackfin/configs/BF527-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF527-EZKIT_defconfig
@@ -175,5 +175,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
175CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 175CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
176CONFIG_EARLY_PRINTK=y 176CONFIG_EARLY_PRINTK=y
177CONFIG_CPLB_INFO=y 177CONFIG_CPLB_INFO=y
178CONFIG_BFIN_PSEUDODBG_INSNS=y
178CONFIG_CRYPTO=y 179CONFIG_CRYPTO=y
179# CONFIG_CRYPTO_ANSI_CPRNG is not set 180# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF533-EZKIT_defconfig b/arch/blackfin/configs/BF533-EZKIT_defconfig
index 9f8fc84e4ac9..a7eb54bf3089 100644
--- a/arch/blackfin/configs/BF533-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF533-EZKIT_defconfig
@@ -108,5 +108,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
108CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 108CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
109CONFIG_EARLY_PRINTK=y 109CONFIG_EARLY_PRINTK=y
110CONFIG_CPLB_INFO=y 110CONFIG_CPLB_INFO=y
111CONFIG_BFIN_PSEUDODBG_INSNS=y
111CONFIG_CRYPTO=y 112CONFIG_CRYPTO=y
112# CONFIG_CRYPTO_ANSI_CPRNG is not set 113# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF533-STAMP_defconfig b/arch/blackfin/configs/BF533-STAMP_defconfig
index ccc432b722a0..0aafde6c8c2d 100644
--- a/arch/blackfin/configs/BF533-STAMP_defconfig
+++ b/arch/blackfin/configs/BF533-STAMP_defconfig
@@ -122,5 +122,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
122CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 122CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
123CONFIG_EARLY_PRINTK=y 123CONFIG_EARLY_PRINTK=y
124CONFIG_CPLB_INFO=y 124CONFIG_CPLB_INFO=y
125CONFIG_BFIN_PSEUDODBG_INSNS=y
125CONFIG_CRYPTO=y 126CONFIG_CRYPTO=y
126# CONFIG_CRYPTO_ANSI_CPRNG is not set 127# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF537-STAMP_defconfig b/arch/blackfin/configs/BF537-STAMP_defconfig
index 566695472a84..c9077fb58135 100644
--- a/arch/blackfin/configs/BF537-STAMP_defconfig
+++ b/arch/blackfin/configs/BF537-STAMP_defconfig
@@ -133,5 +133,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
133CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 133CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
134CONFIG_EARLY_PRINTK=y 134CONFIG_EARLY_PRINTK=y
135CONFIG_CPLB_INFO=y 135CONFIG_CPLB_INFO=y
136CONFIG_BFIN_PSEUDODBG_INSNS=y
136CONFIG_CRYPTO=y 137CONFIG_CRYPTO=y
137# CONFIG_CRYPTO_ANSI_CPRNG is not set 138# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF538-EZKIT_defconfig b/arch/blackfin/configs/BF538-EZKIT_defconfig
index ac22124ccb6c..6883803e6ca8 100644
--- a/arch/blackfin/configs/BF538-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF538-EZKIT_defconfig
@@ -131,5 +131,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
131CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 131CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
132CONFIG_EARLY_PRINTK=y 132CONFIG_EARLY_PRINTK=y
133CONFIG_CPLB_INFO=y 133CONFIG_CPLB_INFO=y
134CONFIG_BFIN_PSEUDODBG_INSNS=y
134CONFIG_CRYPTO=y 135CONFIG_CRYPTO=y
135# CONFIG_CRYPTO_ANSI_CPRNG is not set 136# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF548-EZKIT_defconfig b/arch/blackfin/configs/BF548-EZKIT_defconfig
index 944404b6ff08..56151b5dbc44 100644
--- a/arch/blackfin/configs/BF548-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF548-EZKIT_defconfig
@@ -205,5 +205,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
205CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 205CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
206CONFIG_EARLY_PRINTK=y 206CONFIG_EARLY_PRINTK=y
207CONFIG_CPLB_INFO=y 207CONFIG_CPLB_INFO=y
208CONFIG_BFIN_PSEUDODBG_INSNS=y
208CONFIG_CRYPTO=y 209CONFIG_CRYPTO=y
209# CONFIG_CRYPTO_ANSI_CPRNG is not set 210# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF561-EZKIT-SMP_defconfig b/arch/blackfin/configs/BF561-EZKIT-SMP_defconfig
index 7e67ba31e991..f5ed34e12e0c 100644
--- a/arch/blackfin/configs/BF561-EZKIT-SMP_defconfig
+++ b/arch/blackfin/configs/BF561-EZKIT-SMP_defconfig
@@ -109,5 +109,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
109CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 109CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
110CONFIG_EARLY_PRINTK=y 110CONFIG_EARLY_PRINTK=y
111CONFIG_CPLB_INFO=y 111CONFIG_CPLB_INFO=y
112CONFIG_BFIN_PSEUDODBG_INSNS=y
112CONFIG_CRYPTO=y 113CONFIG_CRYPTO=y
113# CONFIG_CRYPTO_ANSI_CPRNG is not set 114# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/configs/BF561-EZKIT_defconfig b/arch/blackfin/configs/BF561-EZKIT_defconfig
index 141e5933e1aa..1c0a82a10591 100644
--- a/arch/blackfin/configs/BF561-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF561-EZKIT_defconfig
@@ -111,5 +111,6 @@ CONFIG_DEBUG_DOUBLEFAULT=y
111CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y 111CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE=y
112CONFIG_EARLY_PRINTK=y 112CONFIG_EARLY_PRINTK=y
113CONFIG_CPLB_INFO=y 113CONFIG_CPLB_INFO=y
114CONFIG_BFIN_PSEUDODBG_INSNS=y
114CONFIG_CRYPTO=y 115CONFIG_CRYPTO=y
115# CONFIG_CRYPTO_ANSI_CPRNG is not set 116# CONFIG_CRYPTO_ANSI_CPRNG is not set
diff --git a/arch/blackfin/include/asm/def_LPBlackfin.h b/arch/blackfin/include/asm/def_LPBlackfin.h
index e3f0f4c49819..7600fe0696af 100644
--- a/arch/blackfin/include/asm/def_LPBlackfin.h
+++ b/arch/blackfin/include/asm/def_LPBlackfin.h
@@ -58,14 +58,26 @@
58 ({ BUG(); 0; }); \ 58 ({ BUG(); 0; }); \
59}) 59})
60#define bfin_write(addr, val) \ 60#define bfin_write(addr, val) \
61({ \ 61do { \
62 switch (sizeof(*(addr))) { \ 62 switch (sizeof(*(addr))) { \
63 case 1: bfin_write8(addr, val); break; \ 63 case 1: bfin_write8(addr, val); break; \
64 case 2: bfin_write16(addr, val); break; \ 64 case 2: bfin_write16(addr, val); break; \
65 case 4: bfin_write32(addr, val); break; \ 65 case 4: bfin_write32(addr, val); break; \
66 default: BUG(); \ 66 default: BUG(); \
67 } \ 67 } \
68}) 68} while (0)
69
70#define bfin_write_or(addr, bits) \
71do { \
72 void *__addr = (void *)(addr); \
73 bfin_write(__addr, bfin_read(__addr) | (bits)); \
74} while (0)
75
76#define bfin_write_and(addr, bits) \
77do { \
78 void *__addr = (void *)(addr); \
79 bfin_write(__addr, bfin_read(__addr) & (bits)); \
80} while (0)
69 81
70#endif /* __ASSEMBLY__ */ 82#endif /* __ASSEMBLY__ */
71 83
diff --git a/arch/blackfin/include/asm/dpmc.h b/arch/blackfin/include/asm/dpmc.h
index 3047120cfcff..edf2a2ad5183 100644
--- a/arch/blackfin/include/asm/dpmc.h
+++ b/arch/blackfin/include/asm/dpmc.h
@@ -125,6 +125,9 @@ void unset_dram_srfs(void);
125 125
126#define VRPAIR(vlev, freq) (((vlev) << 16) | ((freq) >> 16)) 126#define VRPAIR(vlev, freq) (((vlev) << 16) | ((freq) >> 16))
127 127
128#ifdef CONFIG_CPU_FREQ
129#define CPUFREQ_CPU 0
130#endif
128struct bfin_dpmc_platform_data { 131struct bfin_dpmc_platform_data {
129 const unsigned int *tuple_tab; 132 const unsigned int *tuple_tab;
130 unsigned short tabsize; 133 unsigned short tabsize;
diff --git a/arch/blackfin/include/asm/ipipe.h b/arch/blackfin/include/asm/ipipe.h
index 40f94a704c02..9e0cc0e2534f 100644
--- a/arch/blackfin/include/asm/ipipe.h
+++ b/arch/blackfin/include/asm/ipipe.h
@@ -34,11 +34,12 @@
34#include <asm/bitops.h> 34#include <asm/bitops.h>
35#include <asm/atomic.h> 35#include <asm/atomic.h>
36#include <asm/traps.h> 36#include <asm/traps.h>
37#include <asm/bitsperlong.h>
37 38
38#define IPIPE_ARCH_STRING "1.12-00" 39#define IPIPE_ARCH_STRING "1.16-01"
39#define IPIPE_MAJOR_NUMBER 1 40#define IPIPE_MAJOR_NUMBER 1
40#define IPIPE_MINOR_NUMBER 12 41#define IPIPE_MINOR_NUMBER 16
41#define IPIPE_PATCH_NUMBER 0 42#define IPIPE_PATCH_NUMBER 1
42 43
43#ifdef CONFIG_SMP 44#ifdef CONFIG_SMP
44#error "I-pipe/blackfin: SMP not implemented" 45#error "I-pipe/blackfin: SMP not implemented"
@@ -55,25 +56,19 @@ do { \
55#define task_hijacked(p) \ 56#define task_hijacked(p) \
56 ({ \ 57 ({ \
57 int __x__ = __ipipe_root_domain_p; \ 58 int __x__ = __ipipe_root_domain_p; \
58 __clear_bit(IPIPE_SYNC_FLAG, &ipipe_root_cpudom_var(status)); \
59 if (__x__) \ 59 if (__x__) \
60 hard_local_irq_enable(); \ 60 hard_local_irq_enable(); \
61 !__x__; \ 61 !__x__; \
62 }) 62 })
63 63
64struct ipipe_domain; 64struct ipipe_domain;
65 65
66struct ipipe_sysinfo { 66struct ipipe_sysinfo {
67 67 int sys_nr_cpus; /* Number of CPUs on board */
68 int ncpus; /* Number of CPUs on board */ 68 int sys_hrtimer_irq; /* hrtimer device IRQ */
69 u64 cpufreq; /* CPU frequency (in Hz) */ 69 u64 sys_hrtimer_freq; /* hrtimer device frequency */
70 70 u64 sys_hrclock_freq; /* hrclock device frequency */
71 /* Arch-dependent block */ 71 u64 sys_cpu_freq; /* CPU frequency (Hz) */
72
73 struct {
74 unsigned tmirq; /* Timer tick IRQ */
75 u64 tmfreq; /* Timer frequency */
76 } archdep;
77}; 72};
78 73
79#define ipipe_read_tsc(t) \ 74#define ipipe_read_tsc(t) \
@@ -115,9 +110,19 @@ void __ipipe_enable_irqdesc(struct ipipe_domain *ipd,
115void __ipipe_disable_irqdesc(struct ipipe_domain *ipd, 110void __ipipe_disable_irqdesc(struct ipipe_domain *ipd,
116 unsigned irq); 111 unsigned irq);
117 112
118#define __ipipe_enable_irq(irq) (irq_desc[irq].chip->unmask(irq)) 113#define __ipipe_enable_irq(irq) \
114 do { \
115 struct irq_desc *desc = irq_to_desc(irq); \
116 struct irq_chip *chip = get_irq_desc_chip(desc); \
117 chip->irq_unmask(&desc->irq_data); \
118 } while (0)
119 119
120#define __ipipe_disable_irq(irq) (irq_desc[irq].chip->mask(irq)) 120#define __ipipe_disable_irq(irq) \
121 do { \
122 struct irq_desc *desc = irq_to_desc(irq); \
123 struct irq_chip *chip = get_irq_desc_chip(desc); \
124 chip->irq_mask(&desc->irq_data); \
125 } while (0)
121 126
122static inline int __ipipe_check_tickdev(const char *devname) 127static inline int __ipipe_check_tickdev(const char *devname)
123{ 128{
@@ -128,12 +133,11 @@ void __ipipe_enable_pipeline(void);
128 133
129#define __ipipe_hook_critical_ipi(ipd) do { } while (0) 134#define __ipipe_hook_critical_ipi(ipd) do { } while (0)
130 135
131#define __ipipe_sync_pipeline ___ipipe_sync_pipeline 136void ___ipipe_sync_pipeline(void);
132void ___ipipe_sync_pipeline(unsigned long syncmask);
133 137
134void __ipipe_handle_irq(unsigned irq, struct pt_regs *regs); 138void __ipipe_handle_irq(unsigned irq, struct pt_regs *regs);
135 139
136int __ipipe_get_irq_priority(unsigned irq); 140int __ipipe_get_irq_priority(unsigned int irq);
137 141
138void __ipipe_serial_debug(const char *fmt, ...); 142void __ipipe_serial_debug(const char *fmt, ...);
139 143
@@ -152,7 +156,10 @@ static inline unsigned long __ipipe_ffnz(unsigned long ul)
152 return ffs(ul) - 1; 156 return ffs(ul) - 1;
153} 157}
154 158
155#define __ipipe_run_irqtail() /* Must be a macro */ \ 159#define __ipipe_do_root_xirq(ipd, irq) \
160 ((ipd)->irqs[irq].handler(irq, &__raw_get_cpu_var(__ipipe_tick_regs)))
161
162#define __ipipe_run_irqtail(irq) /* Must be a macro */ \
156 do { \ 163 do { \
157 unsigned long __pending; \ 164 unsigned long __pending; \
158 CSYNC(); \ 165 CSYNC(); \
@@ -164,42 +171,8 @@ static inline unsigned long __ipipe_ffnz(unsigned long ul)
164 } \ 171 } \
165 } while (0) 172 } while (0)
166 173
167#define __ipipe_run_isr(ipd, irq) \
168 do { \
169 if (!__ipipe_pipeline_head_p(ipd)) \
170 hard_local_irq_enable(); \
171 if (ipd == ipipe_root_domain) { \
172 if (unlikely(ipipe_virtual_irq_p(irq))) { \
173 irq_enter(); \
174 ipd->irqs[irq].handler(irq, ipd->irqs[irq].cookie); \
175 irq_exit(); \
176 } else \
177 ipd->irqs[irq].handler(irq, &__raw_get_cpu_var(__ipipe_tick_regs)); \
178 } else { \
179 __clear_bit(IPIPE_SYNC_FLAG, &ipipe_cpudom_var(ipd, status)); \
180 ipd->irqs[irq].handler(irq, ipd->irqs[irq].cookie); \
181 /* Attempt to exit the outer interrupt level before \
182 * starting the deferred IRQ processing. */ \
183 __ipipe_run_irqtail(); \
184 __set_bit(IPIPE_SYNC_FLAG, &ipipe_cpudom_var(ipd, status)); \
185 } \
186 hard_local_irq_disable(); \
187 } while (0)
188
189#define __ipipe_syscall_watched_p(p, sc) \ 174#define __ipipe_syscall_watched_p(p, sc) \
190 (((p)->flags & PF_EVNOTIFY) || (unsigned long)sc >= NR_syscalls) 175 (ipipe_notifier_enabled_p(p) || (unsigned long)sc >= NR_syscalls)
191
192void ipipe_init_irq_threads(void);
193
194int ipipe_start_irq_thread(unsigned irq, struct irq_desc *desc);
195
196#ifdef CONFIG_TICKSOURCE_CORETMR
197#define IRQ_SYSTMR IRQ_CORETMR
198#define IRQ_PRIOTMR IRQ_CORETMR
199#else
200#define IRQ_SYSTMR IRQ_TIMER0
201#define IRQ_PRIOTMR CONFIG_IRQ_TIMER0
202#endif
203 176
204#ifdef CONFIG_BF561 177#ifdef CONFIG_BF561
205#define bfin_write_TIMER_DISABLE(val) bfin_write_TMRS8_DISABLE(val) 178#define bfin_write_TIMER_DISABLE(val) bfin_write_TMRS8_DISABLE(val)
@@ -219,11 +192,11 @@ int ipipe_start_irq_thread(unsigned irq, struct irq_desc *desc);
219 192
220#define task_hijacked(p) 0 193#define task_hijacked(p) 0
221#define ipipe_trap_notify(t, r) 0 194#define ipipe_trap_notify(t, r) 0
195#define __ipipe_root_tick_p(regs) 1
222 196
223#define ipipe_init_irq_threads() do { } while (0) 197#endif /* !CONFIG_IPIPE */
224#define ipipe_start_irq_thread(irq, desc) 0
225 198
226#ifndef CONFIG_TICKSOURCE_GPTMR0 199#ifdef CONFIG_TICKSOURCE_CORETMR
227#define IRQ_SYSTMR IRQ_CORETMR 200#define IRQ_SYSTMR IRQ_CORETMR
228#define IRQ_PRIOTMR IRQ_CORETMR 201#define IRQ_PRIOTMR IRQ_CORETMR
229#else 202#else
@@ -231,10 +204,6 @@ int ipipe_start_irq_thread(unsigned irq, struct irq_desc *desc);
231#define IRQ_PRIOTMR CONFIG_IRQ_TIMER0 204#define IRQ_PRIOTMR CONFIG_IRQ_TIMER0
232#endif 205#endif
233 206
234#define __ipipe_root_tick_p(regs) 1
235
236#endif /* !CONFIG_IPIPE */
237
238#define ipipe_update_tick_evtdev(evtdev) do { } while (0) 207#define ipipe_update_tick_evtdev(evtdev) do { } while (0)
239 208
240#endif /* !__ASM_BLACKFIN_IPIPE_H */ 209#endif /* !__ASM_BLACKFIN_IPIPE_H */
diff --git a/arch/blackfin/include/asm/ipipe_base.h b/arch/blackfin/include/asm/ipipe_base.h
index 00409201d9ed..84a4ffd36747 100644
--- a/arch/blackfin/include/asm/ipipe_base.h
+++ b/arch/blackfin/include/asm/ipipe_base.h
@@ -24,8 +24,10 @@
24 24
25#ifdef CONFIG_IPIPE 25#ifdef CONFIG_IPIPE
26 26
27#include <asm/bitsperlong.h>
28#include <mach/irq.h>
29
27#define IPIPE_NR_XIRQS NR_IRQS 30#define IPIPE_NR_XIRQS NR_IRQS
28#define IPIPE_IRQ_ISHIFT 5 /* 2^5 for 32bits arch. */
29 31
30/* Blackfin-specific, per-cpu pipeline status */ 32/* Blackfin-specific, per-cpu pipeline status */
31#define IPIPE_SYNCDEFER_FLAG 15 33#define IPIPE_SYNCDEFER_FLAG 15
@@ -42,11 +44,14 @@
42#define IPIPE_EVENT_INIT (IPIPE_FIRST_EVENT + 4) 44#define IPIPE_EVENT_INIT (IPIPE_FIRST_EVENT + 4)
43#define IPIPE_EVENT_EXIT (IPIPE_FIRST_EVENT + 5) 45#define IPIPE_EVENT_EXIT (IPIPE_FIRST_EVENT + 5)
44#define IPIPE_EVENT_CLEANUP (IPIPE_FIRST_EVENT + 6) 46#define IPIPE_EVENT_CLEANUP (IPIPE_FIRST_EVENT + 6)
45#define IPIPE_LAST_EVENT IPIPE_EVENT_CLEANUP 47#define IPIPE_EVENT_RETURN (IPIPE_FIRST_EVENT + 7)
48#define IPIPE_LAST_EVENT IPIPE_EVENT_RETURN
46#define IPIPE_NR_EVENTS (IPIPE_LAST_EVENT + 1) 49#define IPIPE_NR_EVENTS (IPIPE_LAST_EVENT + 1)
47 50
48#define IPIPE_TIMER_IRQ IRQ_CORETMR 51#define IPIPE_TIMER_IRQ IRQ_CORETMR
49 52
53#define __IPIPE_FEATURE_SYSINFO_V2 1
54
50#ifndef __ASSEMBLY__ 55#ifndef __ASSEMBLY__
51 56
52extern unsigned long __ipipe_root_status; /* Alias to ipipe_root_cpudom_var(status) */ 57extern unsigned long __ipipe_root_status; /* Alias to ipipe_root_cpudom_var(status) */
@@ -63,6 +68,8 @@ void __ipipe_unlock_root(void);
63 68
64#endif /* !__ASSEMBLY__ */ 69#endif /* !__ASSEMBLY__ */
65 70
71#define __IPIPE_FEATURE_SYSINFO_V2 1
72
66#endif /* CONFIG_IPIPE */ 73#endif /* CONFIG_IPIPE */
67 74
68#endif /* !__ASM_BLACKFIN_IPIPE_BASE_H */ 75#endif /* !__ASM_BLACKFIN_IPIPE_BASE_H */
diff --git a/arch/blackfin/include/asm/irqflags.h b/arch/blackfin/include/asm/irqflags.h
index 3365cb97f539..b4bbb75a9e15 100644
--- a/arch/blackfin/include/asm/irqflags.h
+++ b/arch/blackfin/include/asm/irqflags.h
@@ -89,15 +89,33 @@ static inline void __hard_local_irq_restore(unsigned long flags)
89#ifdef CONFIG_IPIPE 89#ifdef CONFIG_IPIPE
90 90
91#include <linux/compiler.h> 91#include <linux/compiler.h>
92#include <linux/ipipe_base.h>
93#include <linux/ipipe_trace.h> 92#include <linux/ipipe_trace.h>
93/*
94 * Way too many inter-deps between low-level headers in this port, so
95 * we redeclare the required bits we cannot pick from
96 * <asm/ipipe_base.h> to prevent circular dependencies.
97 */
98void __ipipe_stall_root(void);
99void __ipipe_unstall_root(void);
100unsigned long __ipipe_test_root(void);
101unsigned long __ipipe_test_and_stall_root(void);
102void __ipipe_restore_root(unsigned long flags);
103
104#ifdef CONFIG_IPIPE_DEBUG_CONTEXT
105struct ipipe_domain;
106extern struct ipipe_domain ipipe_root;
107void ipipe_check_context(struct ipipe_domain *ipd);
108#define __check_irqop_context(ipd) ipipe_check_context(&ipipe_root)
109#else /* !CONFIG_IPIPE_DEBUG_CONTEXT */
110#define __check_irqop_context(ipd) do { } while (0)
111#endif /* !CONFIG_IPIPE_DEBUG_CONTEXT */
94 112
95/* 113/*
96 * Interrupt pipe interface to linux/irqflags.h. 114 * Interrupt pipe interface to linux/irqflags.h.
97 */ 115 */
98static inline void arch_local_irq_disable(void) 116static inline void arch_local_irq_disable(void)
99{ 117{
100 ipipe_check_context(ipipe_root_domain); 118 __check_irqop_context();
101 __ipipe_stall_root(); 119 __ipipe_stall_root();
102 barrier(); 120 barrier();
103} 121}
@@ -105,7 +123,7 @@ static inline void arch_local_irq_disable(void)
105static inline void arch_local_irq_enable(void) 123static inline void arch_local_irq_enable(void)
106{ 124{
107 barrier(); 125 barrier();
108 ipipe_check_context(ipipe_root_domain); 126 __check_irqop_context();
109 __ipipe_unstall_root(); 127 __ipipe_unstall_root();
110} 128}
111 129
@@ -119,16 +137,21 @@ static inline int arch_irqs_disabled_flags(unsigned long flags)
119 return flags == bfin_no_irqs; 137 return flags == bfin_no_irqs;
120} 138}
121 139
122static inline void arch_local_irq_save_ptr(unsigned long *_flags) 140static inline unsigned long arch_local_irq_save(void)
123{ 141{
124 x = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags; 142 unsigned long flags;
143
144 __check_irqop_context();
145 flags = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags;
125 barrier(); 146 barrier();
147
148 return flags;
126} 149}
127 150
128static inline unsigned long arch_local_irq_save(void) 151static inline void arch_local_irq_restore(unsigned long flags)
129{ 152{
130 ipipe_check_context(ipipe_root_domain); 153 __check_irqop_context();
131 return __hard_local_irq_save(); 154 __ipipe_restore_root(flags == bfin_no_irqs);
132} 155}
133 156
134static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real) 157static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
@@ -192,7 +215,10 @@ static inline void hard_local_irq_restore(unsigned long flags)
192# define hard_local_irq_restore(flags) __hard_local_irq_restore(flags) 215# define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
193#endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */ 216#endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
194 217
195#else /* CONFIG_IPIPE */ 218#define hard_local_irq_save_cond() hard_local_irq_save()
219#define hard_local_irq_restore_cond(flags) hard_local_irq_restore(flags)
220
221#else /* !CONFIG_IPIPE */
196 222
197/* 223/*
198 * Direct interface to linux/irqflags.h. 224 * Direct interface to linux/irqflags.h.
@@ -212,7 +238,48 @@ static inline void hard_local_irq_restore(unsigned long flags)
212#define hard_local_irq_restore(flags) __hard_local_irq_restore(flags) 238#define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
213#define hard_local_irq_enable() __hard_local_irq_enable() 239#define hard_local_irq_enable() __hard_local_irq_enable()
214#define hard_local_irq_disable() __hard_local_irq_disable() 240#define hard_local_irq_disable() __hard_local_irq_disable()
215 241#define hard_local_irq_save_cond() hard_local_save_flags()
242#define hard_local_irq_restore_cond(flags) do { (void)(flags); } while (0)
216 243
217#endif /* !CONFIG_IPIPE */ 244#endif /* !CONFIG_IPIPE */
245
246#ifdef CONFIG_SMP
247#define hard_local_irq_save_smp() hard_local_irq_save()
248#define hard_local_irq_restore_smp(flags) hard_local_irq_restore(flags)
249#else
250#define hard_local_irq_save_smp() hard_local_save_flags()
251#define hard_local_irq_restore_smp(flags) do { (void)(flags); } while (0)
252#endif
253
254/*
255 * Remap the arch-neutral IRQ state manipulation macros to the
256 * blackfin-specific hard_local_irq_* API.
257 */
258#define local_irq_save_hw(flags) \
259 do { \
260 (flags) = hard_local_irq_save(); \
261 } while (0)
262#define local_irq_restore_hw(flags) \
263 do { \
264 hard_local_irq_restore(flags); \
265 } while (0)
266#define local_irq_disable_hw() \
267 do { \
268 hard_local_irq_disable(); \
269 } while (0)
270#define local_irq_enable_hw() \
271 do { \
272 hard_local_irq_enable(); \
273 } while (0)
274#define local_irq_save_hw_notrace(flags) \
275 do { \
276 (flags) = __hard_local_irq_save(); \
277 } while (0)
278#define local_irq_restore_hw_notrace(flags) \
279 do { \
280 __hard_local_irq_restore(flags); \
281 } while (0)
282
283#define irqs_disabled_hw() hard_irqs_disabled()
284
218#endif 285#endif
diff --git a/arch/blackfin/include/asm/smp.h b/arch/blackfin/include/asm/smp.h
index f5b537967116..af6c0aa79bae 100644
--- a/arch/blackfin/include/asm/smp.h
+++ b/arch/blackfin/include/asm/smp.h
@@ -17,7 +17,12 @@
17 17
18#define raw_smp_processor_id() blackfin_core_id() 18#define raw_smp_processor_id() blackfin_core_id()
19 19
20extern char coreb_trampoline_start, coreb_trampoline_end; 20extern void bfin_relocate_coreb_l1_mem(void);
21
22#if defined(CONFIG_SMP) && defined(CONFIG_ICACHE_FLUSH_L1)
23asmlinkage void blackfin_icache_flush_range_l1(unsigned long *ptr);
24extern unsigned long blackfin_iflush_l1_entry[NR_CPUS];
25#endif
21 26
22struct corelock_slot { 27struct corelock_slot {
23 int lock; 28 int lock;
@@ -34,7 +39,7 @@ extern unsigned long dcache_invld_count[NR_CPUS];
34void smp_icache_flush_range_others(unsigned long start, 39void smp_icache_flush_range_others(unsigned long start,
35 unsigned long end); 40 unsigned long end);
36#ifdef CONFIG_HOTPLUG_CPU 41#ifdef CONFIG_HOTPLUG_CPU
37void coreb_sleep(u32 sic_iwr0, u32 sic_iwr1, u32 sic_iwr2); 42void coreb_die(void);
38void cpu_die(void); 43void cpu_die(void);
39void platform_cpu_die(void); 44void platform_cpu_die(void);
40int __cpu_disable(void); 45int __cpu_disable(void);
diff --git a/arch/blackfin/include/asm/unistd.h b/arch/blackfin/include/asm/unistd.h
index 928ae975b87e..c97497dd0d19 100644
--- a/arch/blackfin/include/asm/unistd.h
+++ b/arch/blackfin/include/asm/unistd.h
@@ -393,8 +393,11 @@
393#define __NR_fanotify_mark 372 393#define __NR_fanotify_mark 372
394#define __NR_prlimit64 373 394#define __NR_prlimit64 373
395#define __NR_cacheflush 374 395#define __NR_cacheflush 374
396#define __NR_name_to_handle_at 375
397#define __NR_open_by_handle_at 376
398#define __NR_clock_adjtime 377
396 399
397#define __NR_syscall 375 400#define __NR_syscall 378
398#define NR_syscalls __NR_syscall 401#define NR_syscalls __NR_syscall
399 402
400/* Old optional stuff no one actually uses */ 403/* Old optional stuff no one actually uses */
diff --git a/arch/blackfin/kernel/bfin_dma_5xx.c b/arch/blackfin/kernel/bfin_dma_5xx.c
index 1e485dfdc9f2..6ce8dce753c9 100644
--- a/arch/blackfin/kernel/bfin_dma_5xx.c
+++ b/arch/blackfin/kernel/bfin_dma_5xx.c
@@ -84,6 +84,24 @@ static int __init proc_dma_init(void)
84late_initcall(proc_dma_init); 84late_initcall(proc_dma_init);
85#endif 85#endif
86 86
87static void set_dma_peripheral_map(unsigned int channel, const char *device_id)
88{
89#ifdef CONFIG_BF54x
90 unsigned int per_map;
91
92 switch (channel) {
93 case CH_UART2_RX: per_map = 0xC << 12; break;
94 case CH_UART2_TX: per_map = 0xD << 12; break;
95 case CH_UART3_RX: per_map = 0xE << 12; break;
96 case CH_UART3_TX: per_map = 0xF << 12; break;
97 default: return;
98 }
99
100 if (strncmp(device_id, "BFIN_UART", 9) == 0)
101 dma_ch[channel].regs->peripheral_map = per_map;
102#endif
103}
104
87/** 105/**
88 * request_dma - request a DMA channel 106 * request_dma - request a DMA channel
89 * 107 *
@@ -111,19 +129,7 @@ int request_dma(unsigned int channel, const char *device_id)
111 return -EBUSY; 129 return -EBUSY;
112 } 130 }
113 131
114#ifdef CONFIG_BF54x 132 set_dma_peripheral_map(channel, device_id);
115 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
116 unsigned int per_map;
117 per_map = dma_ch[channel].regs->peripheral_map & 0xFFF;
118 if (strncmp(device_id, "BFIN_UART", 9) == 0)
119 dma_ch[channel].regs->peripheral_map = per_map |
120 ((channel - CH_UART2_RX + 0xC)<<12);
121 else
122 dma_ch[channel].regs->peripheral_map = per_map |
123 ((channel - CH_UART2_RX + 0x6)<<12);
124 }
125#endif
126
127 dma_ch[channel].device_id = device_id; 133 dma_ch[channel].device_id = device_id;
128 dma_ch[channel].irq = 0; 134 dma_ch[channel].irq = 0;
129 135
diff --git a/arch/blackfin/kernel/ipipe.c b/arch/blackfin/kernel/ipipe.c
index 3b1da4aff2a1..f37019c847c9 100644
--- a/arch/blackfin/kernel/ipipe.c
+++ b/arch/blackfin/kernel/ipipe.c
@@ -154,7 +154,7 @@ void __ipipe_handle_irq(unsigned irq, struct pt_regs *regs)
154 * pending for it. 154 * pending for it.
155 */ 155 */
156 if (test_bit(IPIPE_AHEAD_FLAG, &this_domain->flags) && 156 if (test_bit(IPIPE_AHEAD_FLAG, &this_domain->flags) &&
157 ipipe_head_cpudom_var(irqpend_himask) == 0) 157 !__ipipe_ipending_p(ipipe_head_cpudom_ptr()))
158 goto out; 158 goto out;
159 159
160 __ipipe_walk_pipeline(head); 160 __ipipe_walk_pipeline(head);
@@ -185,25 +185,21 @@ void __ipipe_disable_irqdesc(struct ipipe_domain *ipd, unsigned irq)
185} 185}
186EXPORT_SYMBOL(__ipipe_disable_irqdesc); 186EXPORT_SYMBOL(__ipipe_disable_irqdesc);
187 187
188int __ipipe_syscall_root(struct pt_regs *regs) 188asmlinkage int __ipipe_syscall_root(struct pt_regs *regs)
189{ 189{
190 struct ipipe_percpu_domain_data *p; 190 struct ipipe_percpu_domain_data *p;
191 unsigned long flags; 191 void (*hook)(void);
192 int ret; 192 int ret;
193 193
194 WARN_ON_ONCE(irqs_disabled_hw());
195
194 /* 196 /*
195 * We need to run the IRQ tail hook whenever we don't 197 * We need to run the IRQ tail hook each time we intercept a
196 * propagate a syscall to higher domains, because we know that 198 * syscall, because we know that important operations might be
197 * important operations might be pending there (e.g. Xenomai 199 * pending there (e.g. Xenomai deferred rescheduling).
198 * deferred rescheduling).
199 */ 200 */
200 201 hook = (__typeof__(hook))__ipipe_irq_tail_hook;
201 if (regs->orig_p0 < NR_syscalls) { 202 hook();
202 void (*hook)(void) = (void (*)(void))__ipipe_irq_tail_hook;
203 hook();
204 if ((current->flags & PF_EVNOTIFY) == 0)
205 return 0;
206 }
207 203
208 /* 204 /*
209 * This routine either returns: 205 * This routine either returns:
@@ -214,51 +210,47 @@ int __ipipe_syscall_root(struct pt_regs *regs)
214 * tail work has to be performed (for handling signals etc). 210 * tail work has to be performed (for handling signals etc).
215 */ 211 */
216 212
217 if (!__ipipe_event_monitored_p(IPIPE_EVENT_SYSCALL)) 213 if (!__ipipe_syscall_watched_p(current, regs->orig_p0) ||
214 !__ipipe_event_monitored_p(IPIPE_EVENT_SYSCALL))
218 return 0; 215 return 0;
219 216
220 ret = __ipipe_dispatch_event(IPIPE_EVENT_SYSCALL, regs); 217 ret = __ipipe_dispatch_event(IPIPE_EVENT_SYSCALL, regs);
221 218
222 flags = hard_local_irq_save(); 219 hard_local_irq_disable();
223 220
224 if (!__ipipe_root_domain_p) { 221 /*
225 hard_local_irq_restore(flags); 222 * This is the end of the syscall path, so we may
226 return 1; 223 * safely assume a valid Linux task stack here.
224 */
225 if (current->ipipe_flags & PF_EVTRET) {
226 current->ipipe_flags &= ~PF_EVTRET;
227 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
227 } 228 }
228 229
229 p = ipipe_root_cpudom_ptr(); 230 if (!__ipipe_root_domain_p)
230 if ((p->irqpend_himask & IPIPE_IRQMASK_VIRT) != 0) 231 ret = -1;
231 __ipipe_sync_pipeline(IPIPE_IRQMASK_VIRT); 232 else {
233 p = ipipe_root_cpudom_ptr();
234 if (__ipipe_ipending_p(p))
235 __ipipe_sync_pipeline();
236 }
232 237
233 hard_local_irq_restore(flags); 238 hard_local_irq_enable();
234 239
235 return -ret; 240 return -ret;
236} 241}
237 242
238unsigned long ipipe_critical_enter(void (*syncfn) (void))
239{
240 unsigned long flags;
241
242 flags = hard_local_irq_save();
243
244 return flags;
245}
246
247void ipipe_critical_exit(unsigned long flags)
248{
249 hard_local_irq_restore(flags);
250}
251
252static void __ipipe_no_irqtail(void) 243static void __ipipe_no_irqtail(void)
253{ 244{
254} 245}
255 246
256int ipipe_get_sysinfo(struct ipipe_sysinfo *info) 247int ipipe_get_sysinfo(struct ipipe_sysinfo *info)
257{ 248{
258 info->ncpus = num_online_cpus(); 249 info->sys_nr_cpus = num_online_cpus();
259 info->cpufreq = ipipe_cpu_freq(); 250 info->sys_cpu_freq = ipipe_cpu_freq();
260 info->archdep.tmirq = IPIPE_TIMER_IRQ; 251 info->sys_hrtimer_irq = IPIPE_TIMER_IRQ;
261 info->archdep.tmfreq = info->cpufreq; 252 info->sys_hrtimer_freq = __ipipe_core_clock;
253 info->sys_hrclock_freq = __ipipe_core_clock;
262 254
263 return 0; 255 return 0;
264} 256}
@@ -289,6 +281,7 @@ int ipipe_trigger_irq(unsigned irq)
289asmlinkage void __ipipe_sync_root(void) 281asmlinkage void __ipipe_sync_root(void)
290{ 282{
291 void (*irq_tail_hook)(void) = (void (*)(void))__ipipe_irq_tail_hook; 283 void (*irq_tail_hook)(void) = (void (*)(void))__ipipe_irq_tail_hook;
284 struct ipipe_percpu_domain_data *p;
292 unsigned long flags; 285 unsigned long flags;
293 286
294 BUG_ON(irqs_disabled()); 287 BUG_ON(irqs_disabled());
@@ -300,19 +293,20 @@ asmlinkage void __ipipe_sync_root(void)
300 293
301 clear_thread_flag(TIF_IRQ_SYNC); 294 clear_thread_flag(TIF_IRQ_SYNC);
302 295
303 if (ipipe_root_cpudom_var(irqpend_himask) != 0) 296 p = ipipe_root_cpudom_ptr();
304 __ipipe_sync_pipeline(IPIPE_IRQMASK_ANY); 297 if (__ipipe_ipending_p(p))
298 __ipipe_sync_pipeline();
305 299
306 hard_local_irq_restore(flags); 300 hard_local_irq_restore(flags);
307} 301}
308 302
309void ___ipipe_sync_pipeline(unsigned long syncmask) 303void ___ipipe_sync_pipeline(void)
310{ 304{
311 if (__ipipe_root_domain_p && 305 if (__ipipe_root_domain_p &&
312 test_bit(IPIPE_SYNCDEFER_FLAG, &ipipe_root_cpudom_var(status))) 306 test_bit(IPIPE_SYNCDEFER_FLAG, &ipipe_root_cpudom_var(status)))
313 return; 307 return;
314 308
315 __ipipe_sync_stage(syncmask); 309 __ipipe_sync_stage();
316} 310}
317 311
318void __ipipe_disable_root_irqs_hw(void) 312void __ipipe_disable_root_irqs_hw(void)
diff --git a/arch/blackfin/kernel/irqchip.c b/arch/blackfin/kernel/irqchip.c
index 64cff54a8a58..8f079392aff0 100644
--- a/arch/blackfin/kernel/irqchip.c
+++ b/arch/blackfin/kernel/irqchip.c
@@ -39,21 +39,23 @@ int show_interrupts(struct seq_file *p, void *v)
39 unsigned long flags; 39 unsigned long flags;
40 40
41 if (i < NR_IRQS) { 41 if (i < NR_IRQS) {
42 raw_spin_lock_irqsave(&irq_desc[i].lock, flags); 42 struct irq_desc *desc = irq_to_desc(i);
43 action = irq_desc[i].action; 43
44 raw_spin_lock_irqsave(&desc->lock, flags);
45 action = desc->action;
44 if (!action) 46 if (!action)
45 goto skip; 47 goto skip;
46 seq_printf(p, "%3d: ", i); 48 seq_printf(p, "%3d: ", i);
47 for_each_online_cpu(j) 49 for_each_online_cpu(j)
48 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); 50 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
49 seq_printf(p, " %8s", irq_desc[i].chip->name); 51 seq_printf(p, " %8s", get_irq_desc_chip(desc)->name);
50 seq_printf(p, " %s", action->name); 52 seq_printf(p, " %s", action->name);
51 for (action = action->next; action; action = action->next) 53 for (action = action->next; action; action = action->next)
52 seq_printf(p, " %s", action->name); 54 seq_printf(p, " %s", action->name);
53 55
54 seq_putc(p, '\n'); 56 seq_putc(p, '\n');
55 skip: 57 skip:
56 raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags); 58 raw_spin_unlock_irqrestore(&desc->lock, flags);
57 } else if (i == NR_IRQS) { 59 } else if (i == NR_IRQS) {
58 seq_printf(p, "NMI: "); 60 seq_printf(p, "NMI: ");
59 for_each_online_cpu(j) 61 for_each_online_cpu(j)
diff --git a/arch/blackfin/kernel/kgdb.c b/arch/blackfin/kernel/kgdb.c
index eb92592fd80c..b8cfe34989e4 100644
--- a/arch/blackfin/kernel/kgdb.c
+++ b/arch/blackfin/kernel/kgdb.c
@@ -422,11 +422,7 @@ int kgdb_arch_handle_exception(int vector, int signo,
422 422
423struct kgdb_arch arch_kgdb_ops = { 423struct kgdb_arch arch_kgdb_ops = {
424 .gdb_bpt_instr = {0xa1}, 424 .gdb_bpt_instr = {0xa1},
425#ifdef CONFIG_SMP
426 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
427#else
428 .flags = KGDB_HW_BREAKPOINT, 425 .flags = KGDB_HW_BREAKPOINT,
429#endif
430 .set_hw_breakpoint = bfin_set_hw_break, 426 .set_hw_breakpoint = bfin_set_hw_break,
431 .remove_hw_breakpoint = bfin_remove_hw_break, 427 .remove_hw_breakpoint = bfin_remove_hw_break,
432 .disable_hw_break = bfin_disable_hw_debug, 428 .disable_hw_break = bfin_disable_hw_debug,
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c
index ac71dc15cbdb..805c6132c779 100644
--- a/arch/blackfin/kernel/setup.c
+++ b/arch/blackfin/kernel/setup.c
@@ -215,11 +215,48 @@ void __init bfin_relocate_l1_mem(void)
215 215
216 early_dma_memcpy_done(); 216 early_dma_memcpy_done();
217 217
218#if defined(CONFIG_SMP) && defined(CONFIG_ICACHE_FLUSH_L1)
219 blackfin_iflush_l1_entry[0] = (unsigned long)blackfin_icache_flush_range_l1;
220#endif
221
218 /* if necessary, copy L2 text/data to L2 SRAM */ 222 /* if necessary, copy L2 text/data to L2 SRAM */
219 if (L2_LENGTH && l2_len) 223 if (L2_LENGTH && l2_len)
220 memcpy(_stext_l2, _l2_lma, l2_len); 224 memcpy(_stext_l2, _l2_lma, l2_len);
221} 225}
222 226
227#ifdef CONFIG_SMP
228void __init bfin_relocate_coreb_l1_mem(void)
229{
230 unsigned long text_l1_len = (unsigned long)_text_l1_len;
231 unsigned long data_l1_len = (unsigned long)_data_l1_len;
232 unsigned long data_b_l1_len = (unsigned long)_data_b_l1_len;
233
234 blackfin_dma_early_init();
235
236 /* if necessary, copy L1 text to L1 instruction SRAM */
237 if (L1_CODE_LENGTH && text_l1_len)
238 early_dma_memcpy((void *)COREB_L1_CODE_START, _text_l1_lma,
239 text_l1_len);
240
241 /* if necessary, copy L1 data to L1 data bank A SRAM */
242 if (L1_DATA_A_LENGTH && data_l1_len)
243 early_dma_memcpy((void *)COREB_L1_DATA_A_START, _data_l1_lma,
244 data_l1_len);
245
246 /* if necessary, copy L1 data B to L1 data bank B SRAM */
247 if (L1_DATA_B_LENGTH && data_b_l1_len)
248 early_dma_memcpy((void *)COREB_L1_DATA_B_START, _data_b_l1_lma,
249 data_b_l1_len);
250
251 early_dma_memcpy_done();
252
253#ifdef CONFIG_ICACHE_FLUSH_L1
254 blackfin_iflush_l1_entry[1] = (unsigned long)blackfin_icache_flush_range_l1 -
255 (unsigned long)_stext_l1 + COREB_L1_CODE_START;
256#endif
257}
258#endif
259
223#ifdef CONFIG_ROMKERNEL 260#ifdef CONFIG_ROMKERNEL
224void __init bfin_relocate_xip_data(void) 261void __init bfin_relocate_xip_data(void)
225{ 262{
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index c40d07f708e8..854fa49f1c3e 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -136,7 +136,7 @@ SECTIONS
136 136
137 . = ALIGN(16); 137 . = ALIGN(16);
138 INIT_DATA_SECTION(16) 138 INIT_DATA_SECTION(16)
139 PERCPU(32, 4) 139 PERCPU(32, PAGE_SIZE)
140 140
141 .exit.data : 141 .exit.data :
142 { 142 {
@@ -176,6 +176,7 @@ SECTIONS
176 { 176 {
177 . = ALIGN(4); 177 . = ALIGN(4);
178 __stext_l1 = .; 178 __stext_l1 = .;
179 *(.l1.text.head)
179 *(.l1.text) 180 *(.l1.text)
180#ifdef CONFIG_SCHEDULE_L1 181#ifdef CONFIG_SCHEDULE_L1
181 SCHED_TEXT 182 SCHED_TEXT
diff --git a/arch/blackfin/mach-bf518/include/mach/defBF512.h b/arch/blackfin/mach-bf518/include/mach/defBF512.h
index 27285823fb25..cb1172f50757 100644
--- a/arch/blackfin/mach-bf518/include/mach/defBF512.h
+++ b/arch/blackfin/mach-bf518/include/mach/defBF512.h
@@ -1201,25 +1201,6 @@
1201#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */ 1201#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */
1202#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */ 1202#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */
1203 1203
1204
1205/* ****************** HANDSHAKE DMA (HDMA) MASKS *********************/
1206/* HDMAx_CTL Masks */
1207#define HMDMAEN 0x0001 /* Enable Handshake DMA 0/1 */
1208#define REP 0x0002 /* HDMA Request Polarity */
1209#define UTE 0x0004 /* Urgency Threshold Enable */
1210#define OIE 0x0010 /* Overflow Interrupt Enable */
1211#define BDIE 0x0020 /* Block Done Interrupt Enable */
1212#define MBDI 0x0040 /* Mask Block Done IRQ If Pending ECNT */
1213#define DRQ 0x0300 /* HDMA Request Type */
1214#define DRQ_NONE 0x0000 /* No Request */
1215#define DRQ_SINGLE 0x0100 /* Channels Request Single */
1216#define DRQ_MULTI 0x0200 /* Channels Request Multi (Default) */
1217#define DRQ_URGENT 0x0300 /* Channels Request Multi Urgent */
1218#define RBC 0x1000 /* Reload BCNT With IBCNT */
1219#define PS 0x2000 /* HDMA Pin Status */
1220#define OI 0x4000 /* Overflow Interrupt Generated */
1221#define BDI 0x8000 /* Block Done Interrupt Generated */
1222
1223/* entry addresses of the user-callable Boot ROM functions */ 1204/* entry addresses of the user-callable Boot ROM functions */
1224 1205
1225#define _BOOTROM_RESET 0xEF000000 1206#define _BOOTROM_RESET 0xEF000000
diff --git a/arch/blackfin/mach-bf527/include/mach/defBF522.h b/arch/blackfin/mach-bf527/include/mach/defBF522.h
index 89f5420ee6cd..84ef11e52644 100644
--- a/arch/blackfin/mach-bf527/include/mach/defBF522.h
+++ b/arch/blackfin/mach-bf527/include/mach/defBF522.h
@@ -1204,25 +1204,6 @@
1204#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */ 1204#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */
1205#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */ 1205#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */
1206 1206
1207
1208/* ****************** HANDSHAKE DMA (HDMA) MASKS *********************/
1209/* HDMAx_CTL Masks */
1210#define HMDMAEN 0x0001 /* Enable Handshake DMA 0/1 */
1211#define REP 0x0002 /* HDMA Request Polarity */
1212#define UTE 0x0004 /* Urgency Threshold Enable */
1213#define OIE 0x0010 /* Overflow Interrupt Enable */
1214#define BDIE 0x0020 /* Block Done Interrupt Enable */
1215#define MBDI 0x0040 /* Mask Block Done IRQ If Pending ECNT */
1216#define DRQ 0x0300 /* HDMA Request Type */
1217#define DRQ_NONE 0x0000 /* No Request */
1218#define DRQ_SINGLE 0x0100 /* Channels Request Single */
1219#define DRQ_MULTI 0x0200 /* Channels Request Multi (Default) */
1220#define DRQ_URGENT 0x0300 /* Channels Request Multi Urgent */
1221#define RBC 0x1000 /* Reload BCNT With IBCNT */
1222#define PS 0x2000 /* HDMA Pin Status */
1223#define OI 0x4000 /* Overflow Interrupt Generated */
1224#define BDI 0x8000 /* Block Done Interrupt Generated */
1225
1226/* entry addresses of the user-callable Boot ROM functions */ 1207/* entry addresses of the user-callable Boot ROM functions */
1227 1208
1228#define _BOOTROM_RESET 0xEF000000 1209#define _BOOTROM_RESET 0xEF000000
diff --git a/arch/blackfin/mach-bf533/boards/ip0x.c b/arch/blackfin/mach-bf533/boards/ip0x.c
index f869a3711480..a377d8afea03 100644
--- a/arch/blackfin/mach-bf533/boards/ip0x.c
+++ b/arch/blackfin/mach-bf533/boards/ip0x.c
@@ -289,8 +289,6 @@ static struct platform_device *ip0x_devices[] __initdata = {
289 289
290static int __init ip0x_init(void) 290static int __init ip0x_init(void)
291{ 291{
292 int i;
293
294 printk(KERN_INFO "%s(): registering device resources\n", __func__); 292 printk(KERN_INFO "%s(): registering device resources\n", __func__);
295 platform_add_devices(ip0x_devices, ARRAY_SIZE(ip0x_devices)); 293 platform_add_devices(ip0x_devices, ARRAY_SIZE(ip0x_devices));
296 294
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537e.c b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
index 2c776e188a94..d582b810e7a7 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537e.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
@@ -775,7 +775,7 @@ static int __init cm_bf537e_init(void)
775#endif 775#endif
776 776
777#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 777#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
778 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN; 778 irq_set_status_flags(PATA_INT, IRQ_NOAUTOEN);
779#endif 779#endif
780 return 0; 780 return 0;
781} 781}
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537u.c b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
index 085661175ec7..cbb8098604c5 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537u.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
@@ -740,7 +740,7 @@ static int __init cm_bf537u_init(void)
740#endif 740#endif
741 741
742#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 742#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
743 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN; 743 irq_set_status_flags(PATA_INT, IRQ_NOAUTOEN);
744#endif 744#endif
745 return 0; 745 return 0;
746} 746}
diff --git a/arch/blackfin/mach-bf537/boards/dnp5370.c b/arch/blackfin/mach-bf537/boards/dnp5370.c
index e1e9ea02ad89..6b4ff4605bff 100644
--- a/arch/blackfin/mach-bf537/boards/dnp5370.c
+++ b/arch/blackfin/mach-bf537/boards/dnp5370.c
@@ -128,30 +128,11 @@ static struct platform_device asmb_flash_device = {
128 128
129#if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE) 129#if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
130 130
131#define MMC_SPI_CARD_DETECT_INT IRQ_PF5
132
133static int bfin_mmc_spi_init(struct device *dev,
134 irqreturn_t (*detect_int)(int, void *), void *data)
135{
136 return request_irq(MMC_SPI_CARD_DETECT_INT, detect_int,
137 IRQF_TRIGGER_FALLING, "mmc-spi-detect", data);
138}
139
140static void bfin_mmc_spi_exit(struct device *dev, void *data)
141{
142 free_irq(MMC_SPI_CARD_DETECT_INT, data);
143}
144
145static struct bfin5xx_spi_chip mmc_spi_chip_info = { 131static struct bfin5xx_spi_chip mmc_spi_chip_info = {
146 .enable_dma = 0, /* use no dma transfer with this chip*/ 132 .enable_dma = 0, /* use no dma transfer with this chip*/
147 .bits_per_word = 8, 133 .bits_per_word = 8,
148}; 134};
149 135
150static struct mmc_spi_platform_data bfin_mmc_spi_pdata = {
151 .init = bfin_mmc_spi_init,
152 .exit = bfin_mmc_spi_exit,
153 .detect_delay = 100, /* msecs */
154};
155#endif 136#endif
156 137
157#if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE) 138#if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
@@ -192,7 +173,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
192 .max_speed_hz = 20000000, 173 .max_speed_hz = 20000000,
193 .bus_num = 0, 174 .bus_num = 0,
194 .chip_select = 1, 175 .chip_select = 1,
195 .platform_data = &bfin_mmc_spi_pdata,
196 .controller_data = &mmc_spi_chip_info, 176 .controller_data = &mmc_spi_chip_info,
197 .mode = SPI_MODE_3, 177 .mode = SPI_MODE_3,
198 }, 178 },
diff --git a/arch/blackfin/mach-bf537/boards/tcm_bf537.c b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
index 0761b201abca..164a7e02c022 100644
--- a/arch/blackfin/mach-bf537/boards/tcm_bf537.c
+++ b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
@@ -742,7 +742,7 @@ static int __init tcm_bf537_init(void)
742#endif 742#endif
743 743
744#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 744#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
745 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN; 745 irq_set_status_flags(PATA_INT, IRQ_NOAUTOEN);
746#endif 746#endif
747 return 0; 747 return 0;
748} 748}
diff --git a/arch/blackfin/mach-bf537/include/mach/defBF534.h b/arch/blackfin/mach-bf537/include/mach/defBF534.h
index 725bb35f3aaa..4a031dde173f 100644
--- a/arch/blackfin/mach-bf537/include/mach/defBF534.h
+++ b/arch/blackfin/mach-bf537/include/mach/defBF534.h
@@ -1520,24 +1520,6 @@
1520#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */ 1520#define PGTE_PPI 0x0000 /* Enable PPI D15:13 */
1521#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */ 1521#define PGTE_SPORT 0x0800 /* Enable DT1PRI/TFS1/TSCLK1 */
1522 1522
1523/* ****************** HANDSHAKE DMA (HDMA) MASKS *********************/
1524/* HDMAx_CTL Masks */
1525#define HMDMAEN 0x0001 /* Enable Handshake DMA 0/1 */
1526#define REP 0x0002 /* HDMA Request Polarity */
1527#define UTE 0x0004 /* Urgency Threshold Enable */
1528#define OIE 0x0010 /* Overflow Interrupt Enable */
1529#define BDIE 0x0020 /* Block Done Interrupt Enable */
1530#define MBDI 0x0040 /* Mask Block Done IRQ If Pending ECNT */
1531#define DRQ 0x0300 /* HDMA Request Type */
1532#define DRQ_NONE 0x0000 /* No Request */
1533#define DRQ_SINGLE 0x0100 /* Channels Request Single */
1534#define DRQ_MULTI 0x0200 /* Channels Request Multi (Default) */
1535#define DRQ_URGENT 0x0300 /* Channels Request Multi Urgent */
1536#define RBC 0x1000 /* Reload BCNT With IBCNT */
1537#define PS 0x2000 /* HDMA Pin Status */
1538#define OI 0x4000 /* Overflow Interrupt Generated */
1539#define BDI 0x8000 /* Block Done Interrupt Generated */
1540
1541/* entry addresses of the user-callable Boot ROM functions */ 1523/* entry addresses of the user-callable Boot ROM functions */
1542 1524
1543#define _BOOTROM_RESET 0xEF000000 1525#define _BOOTROM_RESET 0xEF000000
diff --git a/arch/blackfin/mach-bf548/Kconfig b/arch/blackfin/mach-bf548/Kconfig
index 70189a0d1a19..94acb586832e 100644
--- a/arch/blackfin/mach-bf548/Kconfig
+++ b/arch/blackfin/mach-bf548/Kconfig
@@ -42,6 +42,65 @@ config BF548_ATAPI_ALTERNATIVE_PORT
42 async address or GPIO port F and G. Select y to route it 42 async address or GPIO port F and G. Select y to route it
43 to GPIO. 43 to GPIO.
44 44
45choice
46 prompt "UART2 DMA channel selection"
47 depends on SERIAL_BFIN_UART2
48 default UART2_DMA_RX_ON_DMA18
49 help
50 UART2 DMA channel selection
51 RX -> DMA18
52 TX -> DMA19
53 or
54 RX -> DMA13
55 TX -> DMA14
56
57config UART2_DMA_RX_ON_DMA18
58 bool "UART2 DMA RX -> DMA18 TX -> DMA19"
59 help
60 UART2 DMA channel assignment
61 RX -> DMA18
62 TX -> DMA19
63 use SPORT2 default DMA channel
64
65config UART2_DMA_RX_ON_DMA13
66 bool "UART2 DMA RX -> DMA13 TX -> DMA14"
67 help
68 UART2 DMA channel assignment
69 RX -> DMA13
70 TX -> DMA14
71 use EPPI1 EPPI2 default DMA channel
72endchoice
73
74choice
75 prompt "UART3 DMA channel selection"
76 depends on SERIAL_BFIN_UART3
77 default UART3_DMA_RX_ON_DMA20
78 help
79 UART3 DMA channel selection
80 RX -> DMA20
81 TX -> DMA21
82 or
83 RX -> DMA15
84 TX -> DMA16
85
86config UART3_DMA_RX_ON_DMA20
87 bool "UART3 DMA RX -> DMA20 TX -> DMA21"
88 help
89 UART3 DMA channel assignment
90 RX -> DMA20
91 TX -> DMA21
92 use SPORT3 default DMA channel
93
94config UART3_DMA_RX_ON_DMA15
95 bool "UART3 DMA RX -> DMA15 TX -> DMA16"
96 help
97 UART3 DMA channel assignment
98 RX -> DMA15
99 TX -> DMA16
100 use PIXC default DMA channel
101
102endchoice
103
45comment "Interrupt Priority Assignment" 104comment "Interrupt Priority Assignment"
46menu "Priority" 105menu "Priority"
47 106
diff --git a/arch/blackfin/mach-bf548/boards/ezkit.c b/arch/blackfin/mach-bf548/boards/ezkit.c
index ce5a2bb147dc..93e19a54a880 100644
--- a/arch/blackfin/mach-bf548/boards/ezkit.c
+++ b/arch/blackfin/mach-bf548/boards/ezkit.c
@@ -778,11 +778,12 @@ static struct platform_device bfin_sport3_uart_device = {
778#endif 778#endif
779 779
780#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE) 780#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE)
781static unsigned short bfin_can_peripherals[] = { 781
782static unsigned short bfin_can0_peripherals[] = {
782 P_CAN0_RX, P_CAN0_TX, 0 783 P_CAN0_RX, P_CAN0_TX, 0
783}; 784};
784 785
785static struct resource bfin_can_resources[] = { 786static struct resource bfin_can0_resources[] = {
786 { 787 {
787 .start = 0xFFC02A00, 788 .start = 0xFFC02A00,
788 .end = 0xFFC02FFF, 789 .end = 0xFFC02FFF,
@@ -805,14 +806,53 @@ static struct resource bfin_can_resources[] = {
805 }, 806 },
806}; 807};
807 808
808static struct platform_device bfin_can_device = { 809static struct platform_device bfin_can0_device = {
809 .name = "bfin_can", 810 .name = "bfin_can",
810 .num_resources = ARRAY_SIZE(bfin_can_resources), 811 .id = 0,
811 .resource = bfin_can_resources, 812 .num_resources = ARRAY_SIZE(bfin_can0_resources),
813 .resource = bfin_can0_resources,
812 .dev = { 814 .dev = {
813 .platform_data = &bfin_can_peripherals, /* Passed to driver */ 815 .platform_data = &bfin_can0_peripherals, /* Passed to driver */
814 }, 816 },
815}; 817};
818
819static unsigned short bfin_can1_peripherals[] = {
820 P_CAN1_RX, P_CAN1_TX, 0
821};
822
823static struct resource bfin_can1_resources[] = {
824 {
825 .start = 0xFFC03200,
826 .end = 0xFFC037FF,
827 .flags = IORESOURCE_MEM,
828 },
829 {
830 .start = IRQ_CAN1_RX,
831 .end = IRQ_CAN1_RX,
832 .flags = IORESOURCE_IRQ,
833 },
834 {
835 .start = IRQ_CAN1_TX,
836 .end = IRQ_CAN1_TX,
837 .flags = IORESOURCE_IRQ,
838 },
839 {
840 .start = IRQ_CAN1_ERROR,
841 .end = IRQ_CAN1_ERROR,
842 .flags = IORESOURCE_IRQ,
843 },
844};
845
846static struct platform_device bfin_can1_device = {
847 .name = "bfin_can",
848 .id = 1,
849 .num_resources = ARRAY_SIZE(bfin_can1_resources),
850 .resource = bfin_can1_resources,
851 .dev = {
852 .platform_data = &bfin_can1_peripherals, /* Passed to driver */
853 },
854};
855
816#endif 856#endif
817 857
818#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE) 858#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
@@ -1366,7 +1406,8 @@ static struct platform_device *ezkit_devices[] __initdata = {
1366#endif 1406#endif
1367 1407
1368#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE) 1408#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE)
1369 &bfin_can_device, 1409 &bfin_can0_device,
1410 &bfin_can1_device,
1370#endif 1411#endif
1371 1412
1372#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE) 1413#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
diff --git a/arch/blackfin/mach-bf548/include/mach/defBF544.h b/arch/blackfin/mach-bf548/include/mach/defBF544.h
index 642468c1bcb1..bcccab36629c 100644
--- a/arch/blackfin/mach-bf548/include/mach/defBF544.h
+++ b/arch/blackfin/mach-bf548/include/mach/defBF544.h
@@ -657,22 +657,4 @@
657 657
658/* Bit masks for EPPI0 are obtained from common base header for EPPIx (EPPI1 and EPPI2) */ 658/* Bit masks for EPPI0 are obtained from common base header for EPPIx (EPPI1 and EPPI2) */
659 659
660/* Bit masks for HMDMAx_CONTROL */
661
662#define HMDMAEN 0x1 /* Handshake MDMA Enable */
663#define REP 0x2 /* Handshake MDMA Request Polarity */
664#define UTE 0x8 /* Urgency Threshold Enable */
665#define OIE 0x10 /* Overflow Interrupt Enable */
666#define BDIE 0x20 /* Block Done Interrupt Enable */
667#define MBDI 0x40 /* Mask Block Done Interrupt */
668#define DRQ 0x300 /* Handshake MDMA Request Type */
669#define RBC 0x1000 /* Force Reload of BCOUNT */
670#define PS 0x2000 /* Pin Status */
671#define OI 0x4000 /* Overflow Interrupt Generated */
672#define BDI 0x8000 /* Block Done Interrupt Generated */
673
674/* ******************************************* */
675/* MULTI BIT MACRO ENUMERATIONS */
676/* ******************************************* */
677
678#endif /* _DEF_BF544_H */ 660#endif /* _DEF_BF544_H */
diff --git a/arch/blackfin/mach-bf548/include/mach/defBF547.h b/arch/blackfin/mach-bf548/include/mach/defBF547.h
index 2f3337cd311e..1cbba115f96f 100644
--- a/arch/blackfin/mach-bf548/include/mach/defBF547.h
+++ b/arch/blackfin/mach-bf548/include/mach/defBF547.h
@@ -1063,23 +1063,4 @@
1063 1063
1064#define DMA_COUNT_LOW 0xffff /* Lower 16-bits of byte count of DMA transfer for DMA master channel */ 1064#define DMA_COUNT_LOW 0xffff /* Lower 16-bits of byte count of DMA transfer for DMA master channel */
1065 1065
1066/* Bit masks for HMDMAx_CONTROL */
1067
1068#define HMDMAEN 0x1 /* Handshake MDMA Enable */
1069#define REP 0x2 /* Handshake MDMA Request Polarity */
1070#define UTE 0x8 /* Urgency Threshold Enable */
1071#define OIE 0x10 /* Overflow Interrupt Enable */
1072#define BDIE 0x20 /* Block Done Interrupt Enable */
1073#define MBDI 0x40 /* Mask Block Done Interrupt */
1074#define DRQ 0x300 /* Handshake MDMA Request Type */
1075#define RBC 0x1000 /* Force Reload of BCOUNT */
1076#define PS 0x2000 /* Pin Status */
1077#define OI 0x4000 /* Overflow Interrupt Generated */
1078#define BDI 0x8000 /* Block Done Interrupt Generated */
1079
1080/* ******************************************* */
1081/* MULTI BIT MACRO ENUMERATIONS */
1082/* ******************************************* */
1083
1084
1085#endif /* _DEF_BF547_H */ 1066#endif /* _DEF_BF547_H */
diff --git a/arch/blackfin/mach-bf548/include/mach/dma.h b/arch/blackfin/mach-bf548/include/mach/dma.h
index a30d242c7398..1a1091b071fd 100644
--- a/arch/blackfin/mach-bf548/include/mach/dma.h
+++ b/arch/blackfin/mach-bf548/include/mach/dma.h
@@ -27,17 +27,37 @@
27#define CH_PIXC_OVERLAY 16 27#define CH_PIXC_OVERLAY 16
28#define CH_PIXC_OUTPUT 17 28#define CH_PIXC_OUTPUT 17
29#define CH_SPORT2_RX 18 29#define CH_SPORT2_RX 18
30#define CH_UART2_RX 18
31#define CH_SPORT2_TX 19 30#define CH_SPORT2_TX 19
32#define CH_UART2_TX 19
33#define CH_SPORT3_RX 20 31#define CH_SPORT3_RX 20
34#define CH_UART3_RX 20
35#define CH_SPORT3_TX 21 32#define CH_SPORT3_TX 21
36#define CH_UART3_TX 21
37#define CH_SDH 22 33#define CH_SDH 22
38#define CH_NFC 22 34#define CH_NFC 22
39#define CH_SPI2 23 35#define CH_SPI2 23
40 36
37#if defined(CONFIG_UART2_DMA_RX_ON_DMA13)
38#define CH_UART2_RX 13
39#define IRQ_UART2_RX BFIN_IRQ(37) /* UART2 RX USE EPP1 (DMA13) Interrupt */
40#define CH_UART2_TX 14
41#define IRQ_UART2_TX BFIN_IRQ(38) /* UART2 RX USE EPP1 (DMA14) Interrupt */
42#else /* Default USE SPORT2's DMA Channel */
43#define CH_UART2_RX 18
44#define IRQ_UART2_RX BFIN_IRQ(33) /* UART2 RX (DMA18) Interrupt */
45#define CH_UART2_TX 19
46#define IRQ_UART2_TX BFIN_IRQ(34) /* UART2 TX (DMA19) Interrupt */
47#endif
48
49#if defined(CONFIG_UART3_DMA_RX_ON_DMA15)
50#define CH_UART3_RX 15
51#define IRQ_UART3_RX BFIN_IRQ(64) /* UART3 RX USE PIXC IN0 (DMA15) Interrupt */
52#define CH_UART3_TX 16
53#define IRQ_UART3_TX BFIN_IRQ(65) /* UART3 TX USE PIXC IN1 (DMA16) Interrupt */
54#else /* Default USE SPORT3's DMA Channel */
55#define CH_UART3_RX 20
56#define IRQ_UART3_RX BFIN_IRQ(35) /* UART3 RX (DMA20) Interrupt */
57#define CH_UART3_TX 21
58#define IRQ_UART3_TX BFIN_IRQ(36) /* UART3 TX (DMA21) Interrupt */
59#endif
60
41#define CH_MEM_STREAM0_DEST 24 61#define CH_MEM_STREAM0_DEST 24
42#define CH_MEM_STREAM0_SRC 25 62#define CH_MEM_STREAM0_SRC 25
43#define CH_MEM_STREAM1_DEST 26 63#define CH_MEM_STREAM1_DEST 26
diff --git a/arch/blackfin/mach-bf548/include/mach/irq.h b/arch/blackfin/mach-bf548/include/mach/irq.h
index 99fd1b2c53d8..7f87787e7738 100644
--- a/arch/blackfin/mach-bf548/include/mach/irq.h
+++ b/arch/blackfin/mach-bf548/include/mach/irq.h
@@ -74,13 +74,9 @@ Events (highest priority) EMU 0
74#define IRQ_UART2_ERROR BFIN_IRQ(31) /* UART2 Status (Error) Interrupt */ 74#define IRQ_UART2_ERROR BFIN_IRQ(31) /* UART2 Status (Error) Interrupt */
75#define IRQ_CAN0_ERROR BFIN_IRQ(32) /* CAN0 Status (Error) Interrupt */ 75#define IRQ_CAN0_ERROR BFIN_IRQ(32) /* CAN0 Status (Error) Interrupt */
76#define IRQ_SPORT2_RX BFIN_IRQ(33) /* SPORT2 RX (DMA18) Interrupt */ 76#define IRQ_SPORT2_RX BFIN_IRQ(33) /* SPORT2 RX (DMA18) Interrupt */
77#define IRQ_UART2_RX BFIN_IRQ(33) /* UART2 RX (DMA18) Interrupt */
78#define IRQ_SPORT2_TX BFIN_IRQ(34) /* SPORT2 TX (DMA19) Interrupt */ 77#define IRQ_SPORT2_TX BFIN_IRQ(34) /* SPORT2 TX (DMA19) Interrupt */
79#define IRQ_UART2_TX BFIN_IRQ(34) /* UART2 TX (DMA19) Interrupt */
80#define IRQ_SPORT3_RX BFIN_IRQ(35) /* SPORT3 RX (DMA20) Interrupt */ 78#define IRQ_SPORT3_RX BFIN_IRQ(35) /* SPORT3 RX (DMA20) Interrupt */
81#define IRQ_UART3_RX BFIN_IRQ(35) /* UART3 RX (DMA20) Interrupt */
82#define IRQ_SPORT3_TX BFIN_IRQ(36) /* SPORT3 TX (DMA21) Interrupt */ 79#define IRQ_SPORT3_TX BFIN_IRQ(36) /* SPORT3 TX (DMA21) Interrupt */
83#define IRQ_UART3_TX BFIN_IRQ(36) /* UART3 TX (DMA21) Interrupt */
84#define IRQ_EPPI1 BFIN_IRQ(37) /* EPP1 (DMA13) Interrupt */ 80#define IRQ_EPPI1 BFIN_IRQ(37) /* EPP1 (DMA13) Interrupt */
85#define IRQ_EPPI2 BFIN_IRQ(38) /* EPP2 (DMA14) Interrupt */ 81#define IRQ_EPPI2 BFIN_IRQ(38) /* EPP2 (DMA14) Interrupt */
86#define IRQ_SPI1 BFIN_IRQ(39) /* SPI1 (DMA5) Interrupt */ 82#define IRQ_SPI1 BFIN_IRQ(39) /* SPI1 (DMA5) Interrupt */
diff --git a/arch/blackfin/mach-bf561/boards/cm_bf561.c b/arch/blackfin/mach-bf561/boards/cm_bf561.c
index 3b67929d4c0a..87595cd38afe 100644
--- a/arch/blackfin/mach-bf561/boards/cm_bf561.c
+++ b/arch/blackfin/mach-bf561/boards/cm_bf561.c
@@ -541,7 +541,7 @@ static int __init cm_bf561_init(void)
541#endif 541#endif
542 542
543#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 543#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
544 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN; 544 irq_set_status_flags(PATA_INT, IRQ_NOAUTOEN);
545#endif 545#endif
546 return 0; 546 return 0;
547} 547}
diff --git a/arch/blackfin/mach-bf561/hotplug.c b/arch/blackfin/mach-bf561/hotplug.c
index 4cd3b28cd046..42fc085629c7 100644
--- a/arch/blackfin/mach-bf561/hotplug.c
+++ b/arch/blackfin/mach-bf561/hotplug.c
@@ -5,30 +5,27 @@
5 * Licensed under the GPL-2 or later. 5 * Licensed under the GPL-2 or later.
6 */ 6 */
7 7
8#include <linux/smp.h>
8#include <asm/blackfin.h> 9#include <asm/blackfin.h>
9#include <asm/irq.h> 10#include <mach/pll.h>
10#include <asm/smp.h>
11
12#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
13 11
14int hotplug_coreb; 12int hotplug_coreb;
15 13
16void platform_cpu_die(void) 14void platform_cpu_die(void)
17{ 15{
18 unsigned long iwr[2] = {0, 0}; 16 unsigned long iwr;
19 unsigned long bank = SIC_SYSIRQ(IRQ_SUPPLE_0) / 32;
20 unsigned long bit = 1 << (SIC_SYSIRQ(IRQ_SUPPLE_0) % 32);
21
22 hotplug_coreb = 1; 17 hotplug_coreb = 1;
23 18
24 iwr[bank] = bit;
25
26 /* disable core timer */ 19 /* disable core timer */
27 bfin_write_TCNTL(0); 20 bfin_write_TCNTL(0);
28 21
29 /* clear ipi interrupt IRQ_SUPPLE_0 */ 22 /* clear ipi interrupt IRQ_SUPPLE_0 of CoreB */
30 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (10 + 1))); 23 bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (10 + 1)));
31 SSYNC(); 24 SSYNC();
32 25
33 coreb_sleep(iwr[0], iwr[1], 0); 26 /* set CoreB wakeup by ipi0, iwr will be discarded */
27 bfin_iwr_set_sup0(&iwr, &iwr, &iwr);
28 SSYNC();
29
30 coreb_die();
34} 31}
diff --git a/arch/blackfin/mach-bf561/secondary.S b/arch/blackfin/mach-bf561/secondary.S
index 4624eebbf9c4..4c462838f4e1 100644
--- a/arch/blackfin/mach-bf561/secondary.S
+++ b/arch/blackfin/mach-bf561/secondary.S
@@ -13,7 +13,11 @@
13#include <asm/asm-offsets.h> 13#include <asm/asm-offsets.h>
14#include <asm/trace.h> 14#include <asm/trace.h>
15 15
16__INIT 16/*
17 * This code must come first as CoreB is hardcoded (in hardware)
18 * to start at the beginning of its L1 instruction memory.
19 */
20.section .l1.text.head
17 21
18/* Lay the initial stack into the L1 scratch area of Core B */ 22/* Lay the initial stack into the L1 scratch area of Core B */
19#define INITIAL_STACK (COREB_L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12) 23#define INITIAL_STACK (COREB_L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
@@ -160,43 +164,34 @@ ENTRY(_coreb_trampoline_start)
160.LWAIT_HERE: 164.LWAIT_HERE:
161 jump .LWAIT_HERE; 165 jump .LWAIT_HERE;
162ENDPROC(_coreb_trampoline_start) 166ENDPROC(_coreb_trampoline_start)
163ENTRY(_coreb_trampoline_end)
164 167
168#ifdef CONFIG_HOTPLUG_CPU
165.section ".text" 169.section ".text"
166ENTRY(_set_sicb_iwr) 170ENTRY(_coreb_die)
167 P0.H = hi(SICB_IWR0);
168 P0.L = lo(SICB_IWR0);
169 P1.H = hi(SICB_IWR1);
170 P1.L = lo(SICB_IWR1);
171 [P0] = R0;
172 [P1] = R1;
173 SSYNC;
174 RTS;
175ENDPROC(_set_sicb_iwr)
176
177ENTRY(_coreb_sleep)
178 sp.l = lo(INITIAL_STACK); 171 sp.l = lo(INITIAL_STACK);
179 sp.h = hi(INITIAL_STACK); 172 sp.h = hi(INITIAL_STACK);
180 fp = sp; 173 fp = sp;
181 usp = sp; 174 usp = sp;
182 175
183 call _set_sicb_iwr;
184
185 CLI R2; 176 CLI R2;
186 SSYNC; 177 SSYNC;
187 IDLE; 178 IDLE;
188 STI R2; 179 STI R2;
189 180
190 R0 = IWR_DISABLE_ALL; 181 R0 = IWR_DISABLE_ALL;
191 R1 = IWR_DISABLE_ALL; 182 P0.H = hi(SYSMMR_BASE);
192 call _set_sicb_iwr; 183 P0.L = lo(SYSMMR_BASE);
184 [P0 + (SICB_IWR0 - SYSMMR_BASE)] = R0;
185 [P0 + (SICB_IWR1 - SYSMMR_BASE)] = R0;
186 SSYNC;
193 187
194 p0.h = hi(COREB_L1_CODE_START); 188 p0.h = hi(COREB_L1_CODE_START);
195 p0.l = lo(COREB_L1_CODE_START); 189 p0.l = lo(COREB_L1_CODE_START);
196 jump (p0); 190 jump (p0);
197ENDPROC(_coreb_sleep) 191ENDPROC(_coreb_die)
192#endif
198 193
199__CPUINIT 194__INIT
200ENTRY(_coreb_start) 195ENTRY(_coreb_start)
201 [--sp] = reti; 196 [--sp] = reti;
202 197
diff --git a/arch/blackfin/mach-bf561/smp.c b/arch/blackfin/mach-bf561/smp.c
index 1074a7ef81c7..5d68bf613b0b 100644
--- a/arch/blackfin/mach-bf561/smp.c
+++ b/arch/blackfin/mach-bf561/smp.c
@@ -30,18 +30,11 @@ void __init platform_init_cpus(void)
30 30
31void __init platform_prepare_cpus(unsigned int max_cpus) 31void __init platform_prepare_cpus(unsigned int max_cpus)
32{ 32{
33 int len; 33 bfin_relocate_coreb_l1_mem();
34
35 len = &coreb_trampoline_end - &coreb_trampoline_start + 1;
36 BUG_ON(len > L1_CODE_LENGTH);
37
38 dma_memcpy((void *)COREB_L1_CODE_START, &coreb_trampoline_start, len);
39 34
40 /* Both cores ought to be present on a bf561! */ 35 /* Both cores ought to be present on a bf561! */
41 cpu_set(0, cpu_present_map); /* CoreA */ 36 cpu_set(0, cpu_present_map); /* CoreA */
42 cpu_set(1, cpu_present_map); /* CoreB */ 37 cpu_set(1, cpu_present_map); /* CoreB */
43
44 printk(KERN_INFO "CoreB bootstrap code to SRAM %p via DMA.\n", (void *)COREB_L1_CODE_START);
45} 38}
46 39
47int __init setup_profiling_timer(unsigned int multiplier) /* not supported */ 40int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
@@ -161,9 +154,13 @@ void platform_clear_ipi(unsigned int cpu, int irq)
161void __cpuinit bfin_local_timer_setup(void) 154void __cpuinit bfin_local_timer_setup(void)
162{ 155{
163#if defined(CONFIG_TICKSOURCE_CORETMR) 156#if defined(CONFIG_TICKSOURCE_CORETMR)
157 struct irq_chip *chip = get_irq_chip(IRQ_CORETMR);
158 struct irq_desc *desc = irq_to_desc(IRQ_CORETMR);
159
164 bfin_coretmr_init(); 160 bfin_coretmr_init();
165 bfin_coretmr_clockevent_init(); 161 bfin_coretmr_clockevent_init();
166 get_irq_chip(IRQ_CORETMR)->unmask(IRQ_CORETMR); 162
163 chip->irq_unmask(&desc->irq_data);
167#else 164#else
168 /* Power down the core timer, just to play safe. */ 165 /* Power down the core timer, just to play safe. */
169 bfin_write_TCNTL(0); 166 bfin_write_TCNTL(0);
diff --git a/arch/blackfin/mach-common/arch_checks.c b/arch/blackfin/mach-common/arch_checks.c
index bceb98126c21..d8643fdd0fcf 100644
--- a/arch/blackfin/mach-common/arch_checks.c
+++ b/arch/blackfin/mach-common/arch_checks.c
@@ -61,6 +61,6 @@
61# error "Anomaly 05000220 does not allow you to use Write Back cache with L2 or External Memory" 61# error "Anomaly 05000220 does not allow you to use Write Back cache with L2 or External Memory"
62#endif 62#endif
63 63
64#if ANOMALY_05000491 && !defined(CONFIG_CACHE_FLUSH_L1) 64#if ANOMALY_05000491 && !defined(CONFIG_ICACHE_FLUSH_L1)
65# error You need IFLUSH in L1 inst while Anomaly 05000491 applies 65# error You need IFLUSH in L1 inst while Anomaly 05000491 applies
66#endif 66#endif
diff --git a/arch/blackfin/mach-common/cache.S b/arch/blackfin/mach-common/cache.S
index ab4a925a443e..9f4dd35bfd74 100644
--- a/arch/blackfin/mach-common/cache.S
+++ b/arch/blackfin/mach-common/cache.S
@@ -11,12 +11,6 @@
11#include <asm/cache.h> 11#include <asm/cache.h>
12#include <asm/page.h> 12#include <asm/page.h>
13 13
14#ifdef CONFIG_CACHE_FLUSH_L1
15.section .l1.text
16#else
17.text
18#endif
19
20/* 05000443 - IFLUSH cannot be last instruction in hardware loop */ 14/* 05000443 - IFLUSH cannot be last instruction in hardware loop */
21#if ANOMALY_05000443 15#if ANOMALY_05000443
22# define BROK_FLUSH_INST "IFLUSH" 16# define BROK_FLUSH_INST "IFLUSH"
@@ -68,11 +62,43 @@
68 RTS; 62 RTS;
69.endm 63.endm
70 64
65#ifdef CONFIG_ICACHE_FLUSH_L1
66.section .l1.text
67#else
68.text
69#endif
70
71/* Invalidate all instruction cache lines assocoiated with this memory area */ 71/* Invalidate all instruction cache lines assocoiated with this memory area */
72#ifdef CONFIG_SMP
73# define _blackfin_icache_flush_range _blackfin_icache_flush_range_l1
74#endif
72ENTRY(_blackfin_icache_flush_range) 75ENTRY(_blackfin_icache_flush_range)
73 do_flush IFLUSH 76 do_flush IFLUSH
74ENDPROC(_blackfin_icache_flush_range) 77ENDPROC(_blackfin_icache_flush_range)
75 78
79#ifdef CONFIG_SMP
80.text
81# undef _blackfin_icache_flush_range
82ENTRY(_blackfin_icache_flush_range)
83 p0.L = LO(DSPID);
84 p0.H = HI(DSPID);
85 r3 = [p0];
86 r3 = r3.b (z);
87 p2 = r3;
88 p0.L = _blackfin_iflush_l1_entry;
89 p0.H = _blackfin_iflush_l1_entry;
90 p0 = p0 + (p2 << 2);
91 p1 = [p0];
92 jump (p1);
93ENDPROC(_blackfin_icache_flush_range)
94#endif
95
96#ifdef CONFIG_DCACHE_FLUSH_L1
97.section .l1.text
98#else
99.text
100#endif
101
76/* Throw away all D-cached data in specified region without any obligation to 102/* Throw away all D-cached data in specified region without any obligation to
77 * write them back. Since the Blackfin ISA does not have an "invalidate" 103 * write them back. Since the Blackfin ISA does not have an "invalidate"
78 * instruction, we use flush/invalidate. Perhaps as a speed optimization we 104 * instruction, we use flush/invalidate. Perhaps as a speed optimization we
diff --git a/arch/blackfin/mach-common/cpufreq.c b/arch/blackfin/mach-common/cpufreq.c
index f4cf11d362e1..85dc6d69f9c0 100644
--- a/arch/blackfin/mach-common/cpufreq.c
+++ b/arch/blackfin/mach-common/cpufreq.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Blackfin core clock scaling 2 * Blackfin core clock scaling
3 * 3 *
4 * Copyright 2008-2009 Analog Devices Inc. 4 * Copyright 2008-2011 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
@@ -16,10 +16,8 @@
16#include <asm/time.h> 16#include <asm/time.h>
17#include <asm/dpmc.h> 17#include <asm/dpmc.h>
18 18
19#define CPUFREQ_CPU 0
20
21/* this is the table of CCLK frequencies, in Hz */ 19/* this is the table of CCLK frequencies, in Hz */
22/* .index is the entry in the auxillary dpm_state_table[] */ 20/* .index is the entry in the auxiliary dpm_state_table[] */
23static struct cpufreq_frequency_table bfin_freq_table[] = { 21static struct cpufreq_frequency_table bfin_freq_table[] = {
24 { 22 {
25 .frequency = CPUFREQ_TABLE_END, 23 .frequency = CPUFREQ_TABLE_END,
@@ -46,7 +44,7 @@ static struct bfin_dpm_state {
46 44
47#if defined(CONFIG_CYCLES_CLOCKSOURCE) 45#if defined(CONFIG_CYCLES_CLOCKSOURCE)
48/* 46/*
49 * normalized to maximum frequncy offset for CYCLES, 47 * normalized to maximum frequency offset for CYCLES,
50 * used in time-ts cycles clock source, but could be used 48 * used in time-ts cycles clock source, but could be used
51 * somewhere also. 49 * somewhere also.
52 */ 50 */
diff --git a/arch/blackfin/mach-common/dpmc.c b/arch/blackfin/mach-common/dpmc.c
index 02c7efd1bcf4..382099fd5561 100644
--- a/arch/blackfin/mach-common/dpmc.c
+++ b/arch/blackfin/mach-common/dpmc.c
@@ -61,17 +61,63 @@ err_out:
61} 61}
62 62
63#ifdef CONFIG_CPU_FREQ 63#ifdef CONFIG_CPU_FREQ
64# ifdef CONFIG_SMP
65static void bfin_idle_this_cpu(void *info)
66{
67 unsigned long flags = 0;
68 unsigned long iwr0, iwr1, iwr2;
69 unsigned int cpu = smp_processor_id();
70
71 local_irq_save_hw(flags);
72 bfin_iwr_set_sup0(&iwr0, &iwr1, &iwr2);
73
74 platform_clear_ipi(cpu, IRQ_SUPPLE_0);
75 SSYNC();
76 asm("IDLE;");
77 bfin_iwr_restore(iwr0, iwr1, iwr2);
78
79 local_irq_restore_hw(flags);
80}
81
82static void bfin_idle_cpu(void)
83{
84 smp_call_function(bfin_idle_this_cpu, NULL, 0);
85}
86
87static void bfin_wakeup_cpu(void)
88{
89 unsigned int cpu;
90 unsigned int this_cpu = smp_processor_id();
91 cpumask_t mask = cpu_online_map;
92
93 cpu_clear(this_cpu, mask);
94 for_each_cpu_mask(cpu, mask)
95 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_0);
96}
97
98# else
99static void bfin_idle_cpu(void) {}
100static void bfin_wakeup_cpu(void) {}
101# endif
102
64static int 103static int
65vreg_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data) 104vreg_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
66{ 105{
67 struct cpufreq_freqs *freq = data; 106 struct cpufreq_freqs *freq = data;
68 107
108 if (freq->cpu != CPUFREQ_CPU)
109 return 0;
110
69 if (val == CPUFREQ_PRECHANGE && freq->old < freq->new) { 111 if (val == CPUFREQ_PRECHANGE && freq->old < freq->new) {
112 bfin_idle_cpu();
70 bfin_set_vlev(bfin_get_vlev(freq->new)); 113 bfin_set_vlev(bfin_get_vlev(freq->new));
71 udelay(pdata->vr_settling_time); /* Wait until Volatge settled */ 114 udelay(pdata->vr_settling_time); /* Wait until Volatge settled */
72 115 bfin_wakeup_cpu();
73 } else if (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) 116 } else if (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) {
117 bfin_idle_cpu();
74 bfin_set_vlev(bfin_get_vlev(freq->new)); 118 bfin_set_vlev(bfin_get_vlev(freq->new));
119 bfin_wakeup_cpu();
120 }
75 121
76 return 0; 122 return 0;
77} 123}
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index bc08c98d008d..757943f620e7 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -952,8 +952,17 @@ ENDPROC(_evt_up_evt14)
952#ifdef CONFIG_IPIPE 952#ifdef CONFIG_IPIPE
953 953
954_resume_kernel_from_int: 954_resume_kernel_from_int:
955 r1 = LO(~0x8000) (Z);
956 r1 = r0 & r1;
957 r0 = 1;
958 r0 = r1 - r0;
959 r2 = r1 & r0;
960 cc = r2 == 0;
961 /* Sync the root stage only from the outer interrupt level. */
962 if !cc jump .Lnosync;
955 r0.l = ___ipipe_sync_root; 963 r0.l = ___ipipe_sync_root;
956 r0.h = ___ipipe_sync_root; 964 r0.h = ___ipipe_sync_root;
965 [--sp] = reti;
957 [--sp] = rets; 966 [--sp] = rets;
958 [--sp] = ( r7:4, p5:3 ); 967 [--sp] = ( r7:4, p5:3 );
959 SP += -12; 968 SP += -12;
@@ -961,6 +970,8 @@ _resume_kernel_from_int:
961 SP += 12; 970 SP += 12;
962 ( r7:4, p5:3 ) = [sp++]; 971 ( r7:4, p5:3 ) = [sp++];
963 rets = [sp++]; 972 rets = [sp++];
973 reti = [sp++];
974.Lnosync:
964 rts 975 rts
965#elif defined(CONFIG_PREEMPT) 976#elif defined(CONFIG_PREEMPT)
966 977
@@ -1738,6 +1749,9 @@ ENTRY(_sys_call_table)
1738 .long _sys_fanotify_mark 1749 .long _sys_fanotify_mark
1739 .long _sys_prlimit64 1750 .long _sys_prlimit64
1740 .long _sys_cacheflush 1751 .long _sys_cacheflush
1752 .long _sys_name_to_handle_at /* 375 */
1753 .long _sys_open_by_handle_at
1754 .long _sys_clock_adjtime
1741 1755
1742 .rept NR_syscalls-(.-_sys_call_table)/4 1756 .rept NR_syscalls-(.-_sys_call_table)/4
1743 .long _sys_ni_syscall 1757 .long _sys_ni_syscall
diff --git a/arch/blackfin/mach-common/head.S b/arch/blackfin/mach-common/head.S
index 4391621d9048..581e2b0a71ac 100644
--- a/arch/blackfin/mach-common/head.S
+++ b/arch/blackfin/mach-common/head.S
@@ -31,6 +31,7 @@ ENDPROC(__init_clear_bss)
31ENTRY(__start) 31ENTRY(__start)
32 /* R0: argument of command line string, passed from uboot, save it */ 32 /* R0: argument of command line string, passed from uboot, save it */
33 R7 = R0; 33 R7 = R0;
34
34 /* Enable Cycle Counter and Nesting Of Interrupts */ 35 /* Enable Cycle Counter and Nesting Of Interrupts */
35#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES 36#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
36 R0 = SYSCFG_SNEN; 37 R0 = SYSCFG_SNEN;
@@ -38,76 +39,49 @@ ENTRY(__start)
38 R0 = SYSCFG_SNEN | SYSCFG_CCEN; 39 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
39#endif 40#endif
40 SYSCFG = R0; 41 SYSCFG = R0;
41 R0 = 0; 42
42 43 /* Optimization register tricks: keep a base value in the
43 /* Clear Out All the data and pointer Registers */ 44 * reserved P registers so we use the load/store with an
44 R1 = R0; 45 * offset syntax. R0 = [P5 + <constant>];
45 R2 = R0; 46 * P5 - core MMR base
46 R3 = R0; 47 * R6 - 0
47 R4 = R0; 48 */
48 R5 = R0; 49 r6 = 0;
49 R6 = R0; 50 p5.l = 0;
50 51 p5.h = hi(COREMMR_BASE);
51 P0 = R0; 52
52 P1 = R0; 53 /* Zero out registers required by Blackfin ABI */
53 P2 = R0; 54
54 P3 = R0; 55 /* Disable circular buffers */
55 P4 = R0; 56 L0 = r6;
56 P5 = R0; 57 L1 = r6;
57 58 L2 = r6;
58 LC0 = r0; 59 L3 = r6;
59 LC1 = r0; 60
60 L0 = r0; 61 /* Disable hardware loops in case we were started by 'go' */
61 L1 = r0; 62 LC0 = r6;
62 L2 = r0; 63 LC1 = r6;
63 L3 = r0;
64
65 /* Clear Out All the DAG Registers */
66 B0 = r0;
67 B1 = r0;
68 B2 = r0;
69 B3 = r0;
70
71 I0 = r0;
72 I1 = r0;
73 I2 = r0;
74 I3 = r0;
75
76 M0 = r0;
77 M1 = r0;
78 M2 = r0;
79 M3 = r0;
80 64
81 /* 65 /*
82 * Clear ITEST_COMMAND and DTEST_COMMAND registers, 66 * Clear ITEST_COMMAND and DTEST_COMMAND registers,
83 * Leaving these as non-zero can confuse the emulator 67 * Leaving these as non-zero can confuse the emulator
84 */ 68 */
85 p0.L = LO(DTEST_COMMAND); 69 [p5 + (DTEST_COMMAND - COREMMR_BASE)] = r6;
86 p0.H = HI(DTEST_COMMAND); 70 [p5 + (ITEST_COMMAND - COREMMR_BASE)] = r6;
87 [p0] = R0;
88 [p0 + (ITEST_COMMAND - DTEST_COMMAND)] = R0;
89 CSYNC; 71 CSYNC;
90 72
91 trace_buffer_init(p0,r0); 73 trace_buffer_init(p0,r0);
92 P0 = R1;
93 R0 = R1;
94 74
95 /* Turn off the icache */ 75 /* Turn off the icache */
96 p0.l = LO(IMEM_CONTROL); 76 r1 = [p5 + (IMEM_CONTROL - COREMMR_BASE)];
97 p0.h = HI(IMEM_CONTROL); 77 BITCLR (r1, ENICPLB_P);
98 R1 = [p0]; 78 [p5 + (IMEM_CONTROL - COREMMR_BASE)] = r1;
99 R0 = ~ENICPLB;
100 R0 = R0 & R1;
101 [p0] = R0;
102 SSYNC; 79 SSYNC;
103 80
104 /* Turn off the dcache */ 81 /* Turn off the dcache */
105 p0.l = LO(DMEM_CONTROL); 82 r1 = [p5 + (DMEM_CONTROL - COREMMR_BASE)];
106 p0.h = HI(DMEM_CONTROL); 83 BITCLR (r1, ENDCPLB_P);
107 R1 = [p0]; 84 [p5 + (DMEM_CONTROL - COREMMR_BASE)] = r1;
108 R0 = ~ENDCPLB;
109 R0 = R0 & R1;
110 [p0] = R0;
111 SSYNC; 85 SSYNC;
112 86
113 /* in case of double faults, save a few things */ 87 /* in case of double faults, save a few things */
@@ -122,25 +96,25 @@ ENTRY(__start)
122 * below 96 * below
123 */ 97 */
124 GET_PDA(p0, r0); 98 GET_PDA(p0, r0);
125 r6 = [p0 + PDA_DF_RETX]; 99 r5 = [p0 + PDA_DF_RETX];
126 p1.l = _init_saved_retx; 100 p1.l = _init_saved_retx;
127 p1.h = _init_saved_retx; 101 p1.h = _init_saved_retx;
128 [p1] = r6; 102 [p1] = r5;
129 103
130 r6 = [p0 + PDA_DF_DCPLB]; 104 r5 = [p0 + PDA_DF_DCPLB];
131 p1.l = _init_saved_dcplb_fault_addr; 105 p1.l = _init_saved_dcplb_fault_addr;
132 p1.h = _init_saved_dcplb_fault_addr; 106 p1.h = _init_saved_dcplb_fault_addr;
133 [p1] = r6; 107 [p1] = r5;
134 108
135 r6 = [p0 + PDA_DF_ICPLB]; 109 r5 = [p0 + PDA_DF_ICPLB];
136 p1.l = _init_saved_icplb_fault_addr; 110 p1.l = _init_saved_icplb_fault_addr;
137 p1.h = _init_saved_icplb_fault_addr; 111 p1.h = _init_saved_icplb_fault_addr;
138 [p1] = r6; 112 [p1] = r5;
139 113
140 r6 = [p0 + PDA_DF_SEQSTAT]; 114 r5 = [p0 + PDA_DF_SEQSTAT];
141 p1.l = _init_saved_seqstat; 115 p1.l = _init_saved_seqstat;
142 p1.h = _init_saved_seqstat; 116 p1.h = _init_saved_seqstat;
143 [p1] = r6; 117 [p1] = r5;
144#endif 118#endif
145 119
146 /* Initialize stack pointer */ 120 /* Initialize stack pointer */
@@ -155,7 +129,7 @@ ENTRY(__start)
155 sti r0; 129 sti r0;
156#endif 130#endif
157 131
158 r0 = 0 (x); 132 r0 = r6;
159 /* Zero out all of the fun bss regions */ 133 /* Zero out all of the fun bss regions */
160#if L1_DATA_A_LENGTH > 0 134#if L1_DATA_A_LENGTH > 0
161 r1.l = __sbss_l1; 135 r1.l = __sbss_l1;
@@ -210,11 +184,9 @@ ENTRY(__start)
210 184
211 /* EVT15 = _real_start */ 185 /* EVT15 = _real_start */
212 186
213 p0.l = lo(EVT15);
214 p0.h = hi(EVT15);
215 p1.l = _real_start; 187 p1.l = _real_start;
216 p1.h = _real_start; 188 p1.h = _real_start;
217 [p0] = p1; 189 [p5 + (EVT15 - COREMMR_BASE)] = p1;
218 csync; 190 csync;
219 191
220#ifdef CONFIG_EARLY_PRINTK 192#ifdef CONFIG_EARLY_PRINTK
diff --git a/arch/blackfin/mach-common/interrupt.S b/arch/blackfin/mach-common/interrupt.S
index 2df37db3b49b..469ce7282dc8 100644
--- a/arch/blackfin/mach-common/interrupt.S
+++ b/arch/blackfin/mach-common/interrupt.S
@@ -274,16 +274,16 @@ ENDPROC(_evt_system_call)
274 * level to EVT14 to prepare the caller for a normal interrupt 274 * level to EVT14 to prepare the caller for a normal interrupt
275 * return through RTI. 275 * return through RTI.
276 * 276 *
277 * We currently use this facility in two occasions: 277 * We currently use this feature in two occasions:
278 * 278 *
279 * - to branch to __ipipe_irq_tail_hook as requested by a high 279 * - before branching to __ipipe_irq_tail_hook as requested by a high
280 * priority domain after the pipeline delivered an interrupt, 280 * priority domain after the pipeline delivered an interrupt,
281 * e.g. such as Xenomai, in order to start its rescheduling 281 * e.g. such as Xenomai, in order to start its rescheduling
282 * procedure, since we may not switch tasks when IRQ levels are 282 * procedure, since we may not switch tasks when IRQ levels are
283 * nested on the Blackfin, so we have to fake an interrupt return 283 * nested on the Blackfin, so we have to fake an interrupt return
284 * so that we may reschedule immediately. 284 * so that we may reschedule immediately.
285 * 285 *
286 * - to branch to sync_root_irqs, in order to play any interrupt 286 * - before branching to __ipipe_sync_root(), in order to play any interrupt
287 * pending for the root domain (i.e. the Linux kernel). This lowers 287 * pending for the root domain (i.e. the Linux kernel). This lowers
288 * the core priority level enough so that Linux IRQ handlers may 288 * the core priority level enough so that Linux IRQ handlers may
289 * never delay interrupts handled by high priority domains; we defer 289 * never delay interrupts handled by high priority domains; we defer
diff --git a/arch/blackfin/mach-common/ints-priority.c b/arch/blackfin/mach-common/ints-priority.c
index a604f19d8dc3..6cd52395a999 100644
--- a/arch/blackfin/mach-common/ints-priority.c
+++ b/arch/blackfin/mach-common/ints-priority.c
@@ -15,6 +15,7 @@
15#include <linux/kernel_stat.h> 15#include <linux/kernel_stat.h>
16#include <linux/seq_file.h> 16#include <linux/seq_file.h>
17#include <linux/irq.h> 17#include <linux/irq.h>
18#include <linux/sched.h>
18#ifdef CONFIG_IPIPE 19#ifdef CONFIG_IPIPE
19#include <linux/ipipe.h> 20#include <linux/ipipe.h>
20#endif 21#endif
@@ -124,21 +125,21 @@ static void __init search_IAR(void)
124 * This is for core internal IRQs 125 * This is for core internal IRQs
125 */ 126 */
126 127
127static void bfin_ack_noop(unsigned int irq) 128static void bfin_ack_noop(struct irq_data *d)
128{ 129{
129 /* Dummy function. */ 130 /* Dummy function. */
130} 131}
131 132
132static void bfin_core_mask_irq(unsigned int irq) 133static void bfin_core_mask_irq(struct irq_data *d)
133{ 134{
134 bfin_irq_flags &= ~(1 << irq); 135 bfin_irq_flags &= ~(1 << d->irq);
135 if (!hard_irqs_disabled()) 136 if (!hard_irqs_disabled())
136 hard_local_irq_enable(); 137 hard_local_irq_enable();
137} 138}
138 139
139static void bfin_core_unmask_irq(unsigned int irq) 140static void bfin_core_unmask_irq(struct irq_data *d)
140{ 141{
141 bfin_irq_flags |= 1 << irq; 142 bfin_irq_flags |= 1 << d->irq;
142 /* 143 /*
143 * If interrupts are enabled, IMASK must contain the same value 144 * If interrupts are enabled, IMASK must contain the same value
144 * as bfin_irq_flags. Make sure that invariant holds. If interrupts 145 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
@@ -176,6 +177,11 @@ static void bfin_internal_mask_irq(unsigned int irq)
176 hard_local_irq_restore(flags); 177 hard_local_irq_restore(flags);
177} 178}
178 179
180static void bfin_internal_mask_irq_chip(struct irq_data *d)
181{
182 bfin_internal_mask_irq(d->irq);
183}
184
179#ifdef CONFIG_SMP 185#ifdef CONFIG_SMP
180static void bfin_internal_unmask_irq_affinity(unsigned int irq, 186static void bfin_internal_unmask_irq_affinity(unsigned int irq,
181 const struct cpumask *affinity) 187 const struct cpumask *affinity)
@@ -211,19 +217,24 @@ static void bfin_internal_unmask_irq(unsigned int irq)
211} 217}
212 218
213#ifdef CONFIG_SMP 219#ifdef CONFIG_SMP
214static void bfin_internal_unmask_irq(unsigned int irq) 220static void bfin_internal_unmask_irq_chip(struct irq_data *d)
215{ 221{
216 struct irq_desc *desc = irq_to_desc(irq); 222 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
217 bfin_internal_unmask_irq_affinity(irq, desc->affinity);
218} 223}
219 224
220static int bfin_internal_set_affinity(unsigned int irq, const struct cpumask *mask) 225static int bfin_internal_set_affinity(struct irq_data *d,
226 const struct cpumask *mask, bool force)
221{ 227{
222 bfin_internal_mask_irq(irq); 228 bfin_internal_mask_irq(d->irq);
223 bfin_internal_unmask_irq_affinity(irq, mask); 229 bfin_internal_unmask_irq_affinity(d->irq, mask);
224 230
225 return 0; 231 return 0;
226} 232}
233#else
234static void bfin_internal_unmask_irq_chip(struct irq_data *d)
235{
236 bfin_internal_unmask_irq(d->irq);
237}
227#endif 238#endif
228 239
229#ifdef CONFIG_PM 240#ifdef CONFIG_PM
@@ -279,28 +290,33 @@ int bfin_internal_set_wake(unsigned int irq, unsigned int state)
279 290
280 return 0; 291 return 0;
281} 292}
293
294static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
295{
296 return bfin_internal_set_wake(d->irq, state);
297}
282#endif 298#endif
283 299
284static struct irq_chip bfin_core_irqchip = { 300static struct irq_chip bfin_core_irqchip = {
285 .name = "CORE", 301 .name = "CORE",
286 .ack = bfin_ack_noop, 302 .irq_ack = bfin_ack_noop,
287 .mask = bfin_core_mask_irq, 303 .irq_mask = bfin_core_mask_irq,
288 .unmask = bfin_core_unmask_irq, 304 .irq_unmask = bfin_core_unmask_irq,
289}; 305};
290 306
291static struct irq_chip bfin_internal_irqchip = { 307static struct irq_chip bfin_internal_irqchip = {
292 .name = "INTN", 308 .name = "INTN",
293 .ack = bfin_ack_noop, 309 .irq_ack = bfin_ack_noop,
294 .mask = bfin_internal_mask_irq, 310 .irq_mask = bfin_internal_mask_irq_chip,
295 .unmask = bfin_internal_unmask_irq, 311 .irq_unmask = bfin_internal_unmask_irq_chip,
296 .mask_ack = bfin_internal_mask_irq, 312 .irq_mask_ack = bfin_internal_mask_irq_chip,
297 .disable = bfin_internal_mask_irq, 313 .irq_disable = bfin_internal_mask_irq_chip,
298 .enable = bfin_internal_unmask_irq, 314 .irq_enable = bfin_internal_unmask_irq_chip,
299#ifdef CONFIG_SMP 315#ifdef CONFIG_SMP
300 .set_affinity = bfin_internal_set_affinity, 316 .irq_set_affinity = bfin_internal_set_affinity,
301#endif 317#endif
302#ifdef CONFIG_PM 318#ifdef CONFIG_PM
303 .set_wake = bfin_internal_set_wake, 319 .irq_set_wake = bfin_internal_set_wake_chip,
304#endif 320#endif
305}; 321};
306 322
@@ -312,33 +328,32 @@ static void bfin_handle_irq(unsigned irq)
312 __ipipe_handle_irq(irq, &regs); 328 __ipipe_handle_irq(irq, &regs);
313 ipipe_trace_irq_exit(irq); 329 ipipe_trace_irq_exit(irq);
314#else /* !CONFIG_IPIPE */ 330#else /* !CONFIG_IPIPE */
315 struct irq_desc *desc = irq_desc + irq; 331 generic_handle_irq(irq);
316 desc->handle_irq(irq, desc);
317#endif /* !CONFIG_IPIPE */ 332#endif /* !CONFIG_IPIPE */
318} 333}
319 334
320#ifdef BF537_GENERIC_ERROR_INT_DEMUX 335#ifdef BF537_GENERIC_ERROR_INT_DEMUX
321static int error_int_mask; 336static int error_int_mask;
322 337
323static void bfin_generic_error_mask_irq(unsigned int irq) 338static void bfin_generic_error_mask_irq(struct irq_data *d)
324{ 339{
325 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR)); 340 error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
326 if (!error_int_mask) 341 if (!error_int_mask)
327 bfin_internal_mask_irq(IRQ_GENERIC_ERROR); 342 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
328} 343}
329 344
330static void bfin_generic_error_unmask_irq(unsigned int irq) 345static void bfin_generic_error_unmask_irq(struct irq_data *d)
331{ 346{
332 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR); 347 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
333 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR); 348 error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
334} 349}
335 350
336static struct irq_chip bfin_generic_error_irqchip = { 351static struct irq_chip bfin_generic_error_irqchip = {
337 .name = "ERROR", 352 .name = "ERROR",
338 .ack = bfin_ack_noop, 353 .irq_ack = bfin_ack_noop,
339 .mask_ack = bfin_generic_error_mask_irq, 354 .irq_mask_ack = bfin_generic_error_mask_irq,
340 .mask = bfin_generic_error_mask_irq, 355 .irq_mask = bfin_generic_error_mask_irq,
341 .unmask = bfin_generic_error_unmask_irq, 356 .irq_unmask = bfin_generic_error_unmask_irq,
342}; 357};
343 358
344static void bfin_demux_error_irq(unsigned int int_err_irq, 359static void bfin_demux_error_irq(unsigned int int_err_irq,
@@ -448,8 +463,10 @@ static void bfin_mac_status_ack_irq(unsigned int irq)
448 } 463 }
449} 464}
450 465
451static void bfin_mac_status_mask_irq(unsigned int irq) 466static void bfin_mac_status_mask_irq(struct irq_data *d)
452{ 467{
468 unsigned int irq = d->irq;
469
453 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT)); 470 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
454#ifdef BF537_GENERIC_ERROR_INT_DEMUX 471#ifdef BF537_GENERIC_ERROR_INT_DEMUX
455 switch (irq) { 472 switch (irq) {
@@ -466,8 +483,10 @@ static void bfin_mac_status_mask_irq(unsigned int irq)
466 bfin_mac_status_ack_irq(irq); 483 bfin_mac_status_ack_irq(irq);
467} 484}
468 485
469static void bfin_mac_status_unmask_irq(unsigned int irq) 486static void bfin_mac_status_unmask_irq(struct irq_data *d)
470{ 487{
488 unsigned int irq = d->irq;
489
471#ifdef BF537_GENERIC_ERROR_INT_DEMUX 490#ifdef BF537_GENERIC_ERROR_INT_DEMUX
472 switch (irq) { 491 switch (irq) {
473 case IRQ_MAC_PHYINT: 492 case IRQ_MAC_PHYINT:
@@ -484,7 +503,7 @@ static void bfin_mac_status_unmask_irq(unsigned int irq)
484} 503}
485 504
486#ifdef CONFIG_PM 505#ifdef CONFIG_PM
487int bfin_mac_status_set_wake(unsigned int irq, unsigned int state) 506int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
488{ 507{
489#ifdef BF537_GENERIC_ERROR_INT_DEMUX 508#ifdef BF537_GENERIC_ERROR_INT_DEMUX
490 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state); 509 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
@@ -496,12 +515,12 @@ int bfin_mac_status_set_wake(unsigned int irq, unsigned int state)
496 515
497static struct irq_chip bfin_mac_status_irqchip = { 516static struct irq_chip bfin_mac_status_irqchip = {
498 .name = "MACST", 517 .name = "MACST",
499 .ack = bfin_ack_noop, 518 .irq_ack = bfin_ack_noop,
500 .mask_ack = bfin_mac_status_mask_irq, 519 .irq_mask_ack = bfin_mac_status_mask_irq,
501 .mask = bfin_mac_status_mask_irq, 520 .irq_mask = bfin_mac_status_mask_irq,
502 .unmask = bfin_mac_status_unmask_irq, 521 .irq_unmask = bfin_mac_status_unmask_irq,
503#ifdef CONFIG_PM 522#ifdef CONFIG_PM
504 .set_wake = bfin_mac_status_set_wake, 523 .irq_set_wake = bfin_mac_status_set_wake,
505#endif 524#endif
506}; 525};
507 526
@@ -538,13 +557,9 @@ static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
538static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle) 557static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
539{ 558{
540#ifdef CONFIG_IPIPE 559#ifdef CONFIG_IPIPE
541 _set_irq_handler(irq, handle_level_irq); 560 handle = handle_level_irq;
542#else
543 struct irq_desc *desc = irq_desc + irq;
544 /* May not call generic set_irq_handler() due to spinlock
545 recursion. */
546 desc->handle_irq = handle;
547#endif 561#endif
562 __set_irq_handler_unlocked(irq, handle);
548} 563}
549 564
550static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS); 565static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
@@ -552,17 +567,18 @@ extern void bfin_gpio_irq_prepare(unsigned gpio);
552 567
553#if !defined(CONFIG_BF54x) 568#if !defined(CONFIG_BF54x)
554 569
555static void bfin_gpio_ack_irq(unsigned int irq) 570static void bfin_gpio_ack_irq(struct irq_data *d)
556{ 571{
557 /* AFAIK ack_irq in case mask_ack is provided 572 /* AFAIK ack_irq in case mask_ack is provided
558 * get's only called for edge sense irqs 573 * get's only called for edge sense irqs
559 */ 574 */
560 set_gpio_data(irq_to_gpio(irq), 0); 575 set_gpio_data(irq_to_gpio(d->irq), 0);
561} 576}
562 577
563static void bfin_gpio_mask_ack_irq(unsigned int irq) 578static void bfin_gpio_mask_ack_irq(struct irq_data *d)
564{ 579{
565 struct irq_desc *desc = irq_desc + irq; 580 unsigned int irq = d->irq;
581 struct irq_desc *desc = irq_to_desc(irq);
566 u32 gpionr = irq_to_gpio(irq); 582 u32 gpionr = irq_to_gpio(irq);
567 583
568 if (desc->handle_irq == handle_edge_irq) 584 if (desc->handle_irq == handle_edge_irq)
@@ -571,39 +587,40 @@ static void bfin_gpio_mask_ack_irq(unsigned int irq)
571 set_gpio_maska(gpionr, 0); 587 set_gpio_maska(gpionr, 0);
572} 588}
573 589
574static void bfin_gpio_mask_irq(unsigned int irq) 590static void bfin_gpio_mask_irq(struct irq_data *d)
575{ 591{
576 set_gpio_maska(irq_to_gpio(irq), 0); 592 set_gpio_maska(irq_to_gpio(d->irq), 0);
577} 593}
578 594
579static void bfin_gpio_unmask_irq(unsigned int irq) 595static void bfin_gpio_unmask_irq(struct irq_data *d)
580{ 596{
581 set_gpio_maska(irq_to_gpio(irq), 1); 597 set_gpio_maska(irq_to_gpio(d->irq), 1);
582} 598}
583 599
584static unsigned int bfin_gpio_irq_startup(unsigned int irq) 600static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
585{ 601{
586 u32 gpionr = irq_to_gpio(irq); 602 u32 gpionr = irq_to_gpio(d->irq);
587 603
588 if (__test_and_set_bit(gpionr, gpio_enabled)) 604 if (__test_and_set_bit(gpionr, gpio_enabled))
589 bfin_gpio_irq_prepare(gpionr); 605 bfin_gpio_irq_prepare(gpionr);
590 606
591 bfin_gpio_unmask_irq(irq); 607 bfin_gpio_unmask_irq(d);
592 608
593 return 0; 609 return 0;
594} 610}
595 611
596static void bfin_gpio_irq_shutdown(unsigned int irq) 612static void bfin_gpio_irq_shutdown(struct irq_data *d)
597{ 613{
598 u32 gpionr = irq_to_gpio(irq); 614 u32 gpionr = irq_to_gpio(d->irq);
599 615
600 bfin_gpio_mask_irq(irq); 616 bfin_gpio_mask_irq(d);
601 __clear_bit(gpionr, gpio_enabled); 617 __clear_bit(gpionr, gpio_enabled);
602 bfin_gpio_irq_free(gpionr); 618 bfin_gpio_irq_free(gpionr);
603} 619}
604 620
605static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) 621static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
606{ 622{
623 unsigned int irq = d->irq;
607 int ret; 624 int ret;
608 char buf[16]; 625 char buf[16];
609 u32 gpionr = irq_to_gpio(irq); 626 u32 gpionr = irq_to_gpio(irq);
@@ -664,9 +681,9 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
664} 681}
665 682
666#ifdef CONFIG_PM 683#ifdef CONFIG_PM
667int bfin_gpio_set_wake(unsigned int irq, unsigned int state) 684int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
668{ 685{
669 return gpio_pm_wakeup_ctrl(irq_to_gpio(irq), state); 686 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
670} 687}
671#endif 688#endif
672 689
@@ -818,10 +835,10 @@ void init_pint_lut(void)
818 } 835 }
819} 836}
820 837
821static void bfin_gpio_ack_irq(unsigned int irq) 838static void bfin_gpio_ack_irq(struct irq_data *d)
822{ 839{
823 struct irq_desc *desc = irq_desc + irq; 840 struct irq_desc *desc = irq_to_desc(d->irq);
824 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 841 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
825 u32 pintbit = PINT_BIT(pint_val); 842 u32 pintbit = PINT_BIT(pint_val);
826 u32 bank = PINT_2_BANK(pint_val); 843 u32 bank = PINT_2_BANK(pint_val);
827 844
@@ -835,10 +852,10 @@ static void bfin_gpio_ack_irq(unsigned int irq)
835 852
836} 853}
837 854
838static void bfin_gpio_mask_ack_irq(unsigned int irq) 855static void bfin_gpio_mask_ack_irq(struct irq_data *d)
839{ 856{
840 struct irq_desc *desc = irq_desc + irq; 857 struct irq_desc *desc = irq_to_desc(d->irq);
841 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 858 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
842 u32 pintbit = PINT_BIT(pint_val); 859 u32 pintbit = PINT_BIT(pint_val);
843 u32 bank = PINT_2_BANK(pint_val); 860 u32 bank = PINT_2_BANK(pint_val);
844 861
@@ -853,24 +870,25 @@ static void bfin_gpio_mask_ack_irq(unsigned int irq)
853 pint[bank]->mask_clear = pintbit; 870 pint[bank]->mask_clear = pintbit;
854} 871}
855 872
856static void bfin_gpio_mask_irq(unsigned int irq) 873static void bfin_gpio_mask_irq(struct irq_data *d)
857{ 874{
858 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 875 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
859 876
860 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val); 877 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
861} 878}
862 879
863static void bfin_gpio_unmask_irq(unsigned int irq) 880static void bfin_gpio_unmask_irq(struct irq_data *d)
864{ 881{
865 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 882 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
866 u32 pintbit = PINT_BIT(pint_val); 883 u32 pintbit = PINT_BIT(pint_val);
867 u32 bank = PINT_2_BANK(pint_val); 884 u32 bank = PINT_2_BANK(pint_val);
868 885
869 pint[bank]->mask_set = pintbit; 886 pint[bank]->mask_set = pintbit;
870} 887}
871 888
872static unsigned int bfin_gpio_irq_startup(unsigned int irq) 889static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
873{ 890{
891 unsigned int irq = d->irq;
874 u32 gpionr = irq_to_gpio(irq); 892 u32 gpionr = irq_to_gpio(irq);
875 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 893 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
876 894
@@ -884,22 +902,23 @@ static unsigned int bfin_gpio_irq_startup(unsigned int irq)
884 if (__test_and_set_bit(gpionr, gpio_enabled)) 902 if (__test_and_set_bit(gpionr, gpio_enabled))
885 bfin_gpio_irq_prepare(gpionr); 903 bfin_gpio_irq_prepare(gpionr);
886 904
887 bfin_gpio_unmask_irq(irq); 905 bfin_gpio_unmask_irq(d);
888 906
889 return 0; 907 return 0;
890} 908}
891 909
892static void bfin_gpio_irq_shutdown(unsigned int irq) 910static void bfin_gpio_irq_shutdown(struct irq_data *d)
893{ 911{
894 u32 gpionr = irq_to_gpio(irq); 912 u32 gpionr = irq_to_gpio(d->irq);
895 913
896 bfin_gpio_mask_irq(irq); 914 bfin_gpio_mask_irq(d);
897 __clear_bit(gpionr, gpio_enabled); 915 __clear_bit(gpionr, gpio_enabled);
898 bfin_gpio_irq_free(gpionr); 916 bfin_gpio_irq_free(gpionr);
899} 917}
900 918
901static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) 919static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
902{ 920{
921 unsigned int irq = d->irq;
903 int ret; 922 int ret;
904 char buf[16]; 923 char buf[16];
905 u32 gpionr = irq_to_gpio(irq); 924 u32 gpionr = irq_to_gpio(irq);
@@ -961,10 +980,10 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
961u32 pint_saved_masks[NR_PINT_SYS_IRQS]; 980u32 pint_saved_masks[NR_PINT_SYS_IRQS];
962u32 pint_wakeup_masks[NR_PINT_SYS_IRQS]; 981u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
963 982
964int bfin_gpio_set_wake(unsigned int irq, unsigned int state) 983int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
965{ 984{
966 u32 pint_irq; 985 u32 pint_irq;
967 u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; 986 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
968 u32 bank = PINT_2_BANK(pint_val); 987 u32 bank = PINT_2_BANK(pint_val);
969 u32 pintbit = PINT_BIT(pint_val); 988 u32 pintbit = PINT_BIT(pint_val);
970 989
@@ -1066,17 +1085,17 @@ static void bfin_demux_gpio_irq(unsigned int inta_irq,
1066 1085
1067static struct irq_chip bfin_gpio_irqchip = { 1086static struct irq_chip bfin_gpio_irqchip = {
1068 .name = "GPIO", 1087 .name = "GPIO",
1069 .ack = bfin_gpio_ack_irq, 1088 .irq_ack = bfin_gpio_ack_irq,
1070 .mask = bfin_gpio_mask_irq, 1089 .irq_mask = bfin_gpio_mask_irq,
1071 .mask_ack = bfin_gpio_mask_ack_irq, 1090 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1072 .unmask = bfin_gpio_unmask_irq, 1091 .irq_unmask = bfin_gpio_unmask_irq,
1073 .disable = bfin_gpio_mask_irq, 1092 .irq_disable = bfin_gpio_mask_irq,
1074 .enable = bfin_gpio_unmask_irq, 1093 .irq_enable = bfin_gpio_unmask_irq,
1075 .set_type = bfin_gpio_irq_type, 1094 .irq_set_type = bfin_gpio_irq_type,
1076 .startup = bfin_gpio_irq_startup, 1095 .irq_startup = bfin_gpio_irq_startup,
1077 .shutdown = bfin_gpio_irq_shutdown, 1096 .irq_shutdown = bfin_gpio_irq_shutdown,
1078#ifdef CONFIG_PM 1097#ifdef CONFIG_PM
1079 .set_wake = bfin_gpio_set_wake, 1098 .irq_set_wake = bfin_gpio_set_wake,
1080#endif 1099#endif
1081}; 1100};
1082 1101
@@ -1373,7 +1392,7 @@ asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1373 struct ipipe_domain *this_domain = __ipipe_current_domain; 1392 struct ipipe_domain *this_domain = __ipipe_current_domain;
1374 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop; 1393 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1375 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst; 1394 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
1376 int irq, s; 1395 int irq, s = 0;
1377 1396
1378 if (likely(vec == EVT_IVTMR_P)) 1397 if (likely(vec == EVT_IVTMR_P))
1379 irq = IRQ_CORETMR; 1398 irq = IRQ_CORETMR;
@@ -1423,6 +1442,21 @@ asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1423 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10; 1442 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
1424 } 1443 }
1425 1444
1445 /*
1446 * We don't want Linux interrupt handlers to run at the
1447 * current core priority level (i.e. < EVT15), since this
1448 * might delay other interrupts handled by a high priority
1449 * domain. Here is what we do instead:
1450 *
1451 * - we raise the SYNCDEFER bit to prevent
1452 * __ipipe_handle_irq() to sync the pipeline for the root
1453 * stage for the incoming interrupt. Upon return, that IRQ is
1454 * pending in the interrupt log.
1455 *
1456 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1457 * that _schedule_and_signal_from_int will eventually sync the
1458 * pipeline from EVT15.
1459 */
1426 if (this_domain == ipipe_root_domain) { 1460 if (this_domain == ipipe_root_domain) {
1427 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status); 1461 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1428 barrier(); 1462 barrier();
@@ -1432,6 +1466,24 @@ asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1432 __ipipe_handle_irq(irq, regs); 1466 __ipipe_handle_irq(irq, regs);
1433 ipipe_trace_irq_exit(irq); 1467 ipipe_trace_irq_exit(irq);
1434 1468
1469 if (user_mode(regs) &&
1470 !ipipe_test_foreign_stack() &&
1471 (current->ipipe_flags & PF_EVTRET) != 0) {
1472 /*
1473 * Testing for user_regs() does NOT fully eliminate
1474 * foreign stack contexts, because of the forged
1475 * interrupt returns we do through
1476 * __ipipe_call_irqtail. In that case, we might have
1477 * preempted a foreign stack context in a high
1478 * priority domain, with a single interrupt level now
1479 * pending after the irqtail unwinding is done. In
1480 * which case user_mode() is now true, and the event
1481 * gets dispatched spuriously.
1482 */
1483 current->ipipe_flags &= ~PF_EVTRET;
1484 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1485 }
1486
1435 if (this_domain == ipipe_root_domain) { 1487 if (this_domain == ipipe_root_domain) {
1436 set_thread_flag(TIF_IRQ_SYNC); 1488 set_thread_flag(TIF_IRQ_SYNC);
1437 if (!s) { 1489 if (!s) {
diff --git a/arch/blackfin/mach-common/smp.c b/arch/blackfin/mach-common/smp.c
index 9f251406a76a..6e17a265c4d3 100644
--- a/arch/blackfin/mach-common/smp.c
+++ b/arch/blackfin/mach-common/smp.c
@@ -40,6 +40,10 @@
40 */ 40 */
41struct corelock_slot corelock __attribute__ ((__section__(".l2.bss"))); 41struct corelock_slot corelock __attribute__ ((__section__(".l2.bss")));
42 42
43#ifdef CONFIG_ICACHE_FLUSH_L1
44unsigned long blackfin_iflush_l1_entry[NR_CPUS];
45#endif
46
43void __cpuinitdata *init_retx_coreb, *init_saved_retx_coreb, 47void __cpuinitdata *init_retx_coreb, *init_saved_retx_coreb,
44 *init_saved_seqstat_coreb, *init_saved_icplb_fault_addr_coreb, 48 *init_saved_seqstat_coreb, *init_saved_icplb_fault_addr_coreb,
45 *init_saved_dcplb_fault_addr_coreb; 49 *init_saved_dcplb_fault_addr_coreb;
@@ -105,10 +109,10 @@ static void ipi_flush_icache(void *info)
105 struct blackfin_flush_data *fdata = info; 109 struct blackfin_flush_data *fdata = info;
106 110
107 /* Invalidate the memory holding the bounds of the flushed region. */ 111 /* Invalidate the memory holding the bounds of the flushed region. */
108 blackfin_dcache_invalidate_range((unsigned long)fdata, 112 invalidate_dcache_range((unsigned long)fdata,
109 (unsigned long)fdata + sizeof(*fdata)); 113 (unsigned long)fdata + sizeof(*fdata));
110 114
111 blackfin_icache_flush_range(fdata->start, fdata->end); 115 flush_icache_range(fdata->start, fdata->end);
112} 116}
113 117
114static void ipi_call_function(unsigned int cpu, struct ipi_message *msg) 118static void ipi_call_function(unsigned int cpu, struct ipi_message *msg)
@@ -244,12 +248,13 @@ int smp_call_function(void (*func)(void *info), void *info, int wait)
244{ 248{
245 cpumask_t callmap; 249 cpumask_t callmap;
246 250
251 preempt_disable();
247 callmap = cpu_online_map; 252 callmap = cpu_online_map;
248 cpu_clear(smp_processor_id(), callmap); 253 cpu_clear(smp_processor_id(), callmap);
249 if (cpus_empty(callmap)) 254 if (!cpus_empty(callmap))
250 return 0; 255 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait);
251 256
252 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait); 257 preempt_enable();
253 258
254 return 0; 259 return 0;
255} 260}
@@ -286,12 +291,13 @@ void smp_send_stop(void)
286{ 291{
287 cpumask_t callmap; 292 cpumask_t callmap;
288 293
294 preempt_disable();
289 callmap = cpu_online_map; 295 callmap = cpu_online_map;
290 cpu_clear(smp_processor_id(), callmap); 296 cpu_clear(smp_processor_id(), callmap);
291 if (cpus_empty(callmap)) 297 if (!cpus_empty(callmap))
292 return; 298 smp_send_message(callmap, BFIN_IPI_CPU_STOP, NULL, NULL, 0);
293 299
294 smp_send_message(callmap, BFIN_IPI_CPU_STOP, NULL, NULL, 0); 300 preempt_enable();
295 301
296 return; 302 return;
297} 303}
@@ -361,8 +367,6 @@ void __cpuinit secondary_start_kernel(void)
361 */ 367 */
362 init_exception_vectors(); 368 init_exception_vectors();
363 369
364 bfin_setup_caches(cpu);
365
366 local_irq_disable(); 370 local_irq_disable();
367 371
368 /* Attach the new idle task to the global mm. */ 372 /* Attach the new idle task to the global mm. */
@@ -381,6 +385,8 @@ void __cpuinit secondary_start_kernel(void)
381 385
382 local_irq_enable(); 386 local_irq_enable();
383 387
388 bfin_setup_caches(cpu);
389
384 /* 390 /*
385 * Calibrate loops per jiffy value. 391 * Calibrate loops per jiffy value.
386 * IRQs need to be enabled here - D-cache can be invalidated 392 * IRQs need to be enabled here - D-cache can be invalidated
diff --git a/arch/h8300/boot/compressed/Makefile b/arch/h8300/boot/compressed/Makefile
index d6189e057ed3..6745cb1ffb4f 100644
--- a/arch/h8300/boot/compressed/Makefile
+++ b/arch/h8300/boot/compressed/Makefile
@@ -5,7 +5,7 @@
5# 5#
6 6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o 7targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
8EXTRA_AFLAGS := -traditional 8asflags-y := -traditional
9 9
10OBJECTS = $(obj)/head.o $(obj)/misc.o 10OBJECTS = $(obj)/head.o $(obj)/misc.o
11 11
diff --git a/arch/ia64/kvm/Makefile b/arch/ia64/kvm/Makefile
index 1089b3e918ac..db3d7c5d1071 100644
--- a/arch/ia64/kvm/Makefile
+++ b/arch/ia64/kvm/Makefile
@@ -45,8 +45,8 @@ FORCE : $(obj)/$(offsets-file)
45# Makefile for Kernel-based Virtual Machine module 45# Makefile for Kernel-based Virtual Machine module
46# 46#
47 47
48EXTRA_CFLAGS += -Ivirt/kvm -Iarch/ia64/kvm/ 48ccflags-y := -Ivirt/kvm -Iarch/ia64/kvm/
49EXTRA_AFLAGS += -Ivirt/kvm -Iarch/ia64/kvm/ 49asflags-y := -Ivirt/kvm -Iarch/ia64/kvm/
50 50
51common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ 51common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
52 coalesced_mmio.o irq_comm.o assigned-dev.o) 52 coalesced_mmio.o irq_comm.o assigned-dev.o)
diff --git a/arch/ia64/sn/kernel/Makefile b/arch/ia64/sn/kernel/Makefile
index 0591038735af..d27df1d45da7 100644
--- a/arch/ia64/sn/kernel/Makefile
+++ b/arch/ia64/sn/kernel/Makefile
@@ -7,7 +7,7 @@
7# Copyright (C) 1999,2001-2006,2008 Silicon Graphics, Inc. All Rights Reserved. 7# Copyright (C) 1999,2001-2006,2008 Silicon Graphics, Inc. All Rights Reserved.
8# 8#
9 9
10EXTRA_CFLAGS += -Iarch/ia64/sn/include 10ccflags-y := -Iarch/ia64/sn/include
11 11
12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \ 12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \
13 huberror.o io_acpi_init.o io_common.o \ 13 huberror.o io_acpi_init.o io_common.o \
diff --git a/arch/ia64/sn/kernel/sn2/Makefile b/arch/ia64/sn/kernel/sn2/Makefile
index 08e6565dc908..3d09108d4277 100644
--- a/arch/ia64/sn/kernel/sn2/Makefile
+++ b/arch/ia64/sn/kernel/sn2/Makefile
@@ -9,7 +9,7 @@
9# sn2 specific kernel files 9# sn2 specific kernel files
10# 10#
11 11
12EXTRA_CFLAGS += -Iarch/ia64/sn/include 12ccflags-y := -Iarch/ia64/sn/include
13 13
14obj-y += cache.o io.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o \ 14obj-y += cache.o io.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o \
15 prominfo_proc.o timer.o timer_interrupt.o sn_hwperf.o 15 prominfo_proc.o timer.o timer_interrupt.o sn_hwperf.o
diff --git a/arch/ia64/sn/pci/Makefile b/arch/ia64/sn/pci/Makefile
index ad4ef34dfe26..df2a90145426 100644
--- a/arch/ia64/sn/pci/Makefile
+++ b/arch/ia64/sn/pci/Makefile
@@ -7,6 +7,6 @@
7# 7#
8# Makefile for the sn pci general routines. 8# Makefile for the sn pci general routines.
9 9
10EXTRA_CFLAGS += -Iarch/ia64/sn/include 10ccflags-y := -Iarch/ia64/sn/include
11 11
12obj-y := pci_dma.o tioca_provider.o tioce_provider.o pcibr/ 12obj-y := pci_dma.o tioca_provider.o tioce_provider.o pcibr/
diff --git a/arch/ia64/sn/pci/pcibr/Makefile b/arch/ia64/sn/pci/pcibr/Makefile
index 01192d3247dd..396bcae36309 100644
--- a/arch/ia64/sn/pci/pcibr/Makefile
+++ b/arch/ia64/sn/pci/pcibr/Makefile
@@ -7,7 +7,7 @@
7# 7#
8# Makefile for the sn2 io routines. 8# Makefile for the sn2 io routines.
9 9
10EXTRA_CFLAGS += -Iarch/ia64/sn/include 10ccflags-y := -Iarch/ia64/sn/include
11 11
12obj-y += pcibr_dma.o pcibr_reg.o \ 12obj-y += pcibr_dma.o pcibr_reg.o \
13 pcibr_ate.o pcibr_provider.o 13 pcibr_ate.o pcibr_provider.o
diff --git a/arch/ia64/uv/kernel/Makefile b/arch/ia64/uv/kernel/Makefile
index 8d92b4684d8e..124e441d383d 100644
--- a/arch/ia64/uv/kernel/Makefile
+++ b/arch/ia64/uv/kernel/Makefile
@@ -7,7 +7,7 @@
7# Copyright (C) 2008 Silicon Graphics, Inc. All Rights Reserved. 7# Copyright (C) 2008 Silicon Graphics, Inc. All Rights Reserved.
8# 8#
9 9
10EXTRA_CFLAGS += -Iarch/ia64/sn/include 10ccflags-y := -Iarch/ia64/sn/include
11 11
12obj-y += setup.o 12obj-y += setup.o
13obj-$(CONFIG_IA64_GENERIC) += machvec.o 13obj-$(CONFIG_IA64_GENERIC) += machvec.o
diff --git a/arch/microblaze/kernel/cpu/Makefile b/arch/microblaze/kernel/cpu/Makefile
index 59cc7bceaf8c..fceed4edea41 100644
--- a/arch/microblaze/kernel/cpu/Makefile
+++ b/arch/microblaze/kernel/cpu/Makefile
@@ -6,7 +6,7 @@ ifdef CONFIG_FUNCTION_TRACER
6CFLAGS_REMOVE_cache.o = -pg 6CFLAGS_REMOVE_cache.o = -pg
7endif 7endif
8 8
9EXTRA_CFLAGS += -DCPU_MAJOR=$(CPU_MAJOR) -DCPU_MINOR=$(CPU_MINOR) \ 9ccflags-y := -DCPU_MAJOR=$(CPU_MAJOR) -DCPU_MINOR=$(CPU_MINOR) \
10 -DCPU_REV=$(CPU_REV) 10 -DCPU_REV=$(CPU_REV)
11 11
12obj-y += cache.o cpuinfo.o cpuinfo-pvr-full.o cpuinfo-static.o mb.o pvr.o 12obj-y += cache.o cpuinfo.o cpuinfo-pvr-full.o cpuinfo-static.o mb.o pvr.o
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 7c1102e41fe2..ac1d5b611a27 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -286,11 +286,11 @@ CLEAN_FILES += vmlinux.32 vmlinux.64
286archprepare: 286archprepare:
287ifdef CONFIG_MIPS32_N32 287ifdef CONFIG_MIPS32_N32
288 @echo ' Checking missing-syscalls for N32' 288 @echo ' Checking missing-syscalls for N32'
289 $(Q)$(MAKE) $(build)=. missing-syscalls EXTRA_CFLAGS="-mabi=n32" 289 $(Q)$(MAKE) $(build)=. missing-syscalls ccflags-y="-mabi=n32"
290endif 290endif
291ifdef CONFIG_MIPS32_O32 291ifdef CONFIG_MIPS32_O32
292 @echo ' Checking missing-syscalls for O32' 292 @echo ' Checking missing-syscalls for O32'
293 $(Q)$(MAKE) $(build)=. missing-syscalls EXTRA_CFLAGS="-mabi=32" 293 $(Q)$(MAKE) $(build)=. missing-syscalls ccflags-y="-mabi=32"
294endif 294endif
295 295
296install: 296install:
diff --git a/arch/mips/bcm63xx/boards/Makefile b/arch/mips/bcm63xx/boards/Makefile
index e5cc86dc1da8..9f64fb414077 100644
--- a/arch/mips/bcm63xx/boards/Makefile
+++ b/arch/mips/bcm63xx/boards/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o 1obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
2 2
3EXTRA_CFLAGS += -Werror 3ccflags-y := -Werror
diff --git a/arch/mips/fw/arc/Makefile b/arch/mips/fw/arc/Makefile
index e0aaad482b0e..5314b37aff2c 100644
--- a/arch/mips/fw/arc/Makefile
+++ b/arch/mips/fw/arc/Makefile
@@ -9,4 +9,4 @@ lib-$(CONFIG_ARC_MEMORY) += memory.o
9lib-$(CONFIG_ARC_CONSOLE) += arc_con.o 9lib-$(CONFIG_ARC_CONSOLE) += arc_con.o
10lib-$(CONFIG_ARC_PROMLIB) += promlib.o 10lib-$(CONFIG_ARC_PROMLIB) += promlib.o
11 11
12EXTRA_CFLAGS += -Werror 12ccflags-y := -Werror
diff --git a/arch/mips/jz4740/Makefile b/arch/mips/jz4740/Makefile
index a604eaeb6c08..a9dff3321251 100644
--- a/arch/mips/jz4740/Makefile
+++ b/arch/mips/jz4740/Makefile
@@ -17,4 +17,4 @@ obj-$(CONFIG_JZ4740_QI_LB60) += board-qi_lb60.o
17 17
18obj-$(CONFIG_PM) += pm.o 18obj-$(CONFIG_PM) += pm.o
19 19
20EXTRA_CFLAGS += -Werror -Wall 20ccflags-y := -Werror -Wall
diff --git a/arch/mips/oprofile/Makefile b/arch/mips/oprofile/Makefile
index 02cc65e52d11..4b9d7044e26c 100644
--- a/arch/mips/oprofile/Makefile
+++ b/arch/mips/oprofile/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS := -Werror 1ccflags-y := -Werror
2 2
3obj-$(CONFIG_OPROFILE) += oprofile.o 3obj-$(CONFIG_OPROFILE) += oprofile.o
4 4
diff --git a/arch/mips/pmc-sierra/yosemite/Makefile b/arch/mips/pmc-sierra/yosemite/Makefile
index b16f95c3df65..02f5fb94ea28 100644
--- a/arch/mips/pmc-sierra/yosemite/Makefile
+++ b/arch/mips/pmc-sierra/yosemite/Makefile
@@ -6,4 +6,4 @@ obj-y += irq.o prom.o py-console.o setup.o
6 6
7obj-$(CONFIG_SMP) += smp.o 7obj-$(CONFIG_SMP) += smp.o
8 8
9EXTRA_CFLAGS += -Werror 9ccflags-y := -Werror
diff --git a/arch/mips/powertv/Makefile b/arch/mips/powertv/Makefile
index baf6e9092a9f..348d2e850ef5 100644
--- a/arch/mips/powertv/Makefile
+++ b/arch/mips/powertv/Makefile
@@ -28,4 +28,4 @@ obj-y += init.o ioremap.o memory.o powertv_setup.o reset.o time.o \
28 28
29obj-$(CONFIG_USB) += powertv-usb.o 29obj-$(CONFIG_USB) += powertv-usb.o
30 30
31EXTRA_CFLAGS += -Wall 31ccflags-y := -Wall
diff --git a/arch/mips/powertv/asic/Makefile b/arch/mips/powertv/asic/Makefile
index f0e95dc0ac97..d810a33182a4 100644
--- a/arch/mips/powertv/asic/Makefile
+++ b/arch/mips/powertv/asic/Makefile
@@ -20,4 +20,4 @@ obj-y += asic-calliope.o asic-cronus.o asic-gaia.o asic-zeus.o \
20 asic_devices.o asic_int.o irq_asic.o prealloc-calliope.o \ 20 asic_devices.o asic_int.o irq_asic.o prealloc-calliope.o \
21 prealloc-cronus.o prealloc-cronuslite.o prealloc-gaia.o prealloc-zeus.o 21 prealloc-cronus.o prealloc-cronuslite.o prealloc-gaia.o prealloc-zeus.o
22 22
23EXTRA_CFLAGS += -Wall -Werror 23ccflags-y := -Wall -Werror
diff --git a/arch/mips/powertv/pci/Makefile b/arch/mips/powertv/pci/Makefile
index f5c62462fc9d..5783201cd2c8 100644
--- a/arch/mips/powertv/pci/Makefile
+++ b/arch/mips/powertv/pci/Makefile
@@ -18,4 +18,4 @@
18 18
19obj-$(CONFIG_PCI) += fixup-powertv.o 19obj-$(CONFIG_PCI) += fixup-powertv.o
20 20
21EXTRA_CFLAGS += -Wall -Werror 21ccflags-y := -Wall -Werror
diff --git a/arch/mn10300/Kconfig b/arch/mn10300/Kconfig
index 243bfa23fd58..10971be43061 100644
--- a/arch/mn10300/Kconfig
+++ b/arch/mn10300/Kconfig
@@ -1,7 +1,8 @@
1config MN10300 1config MN10300
2 def_bool y 2 def_bool y
3 select HAVE_OPROFILE 3 select HAVE_OPROFILE
4 select GENERIC_HARDIRQS 4 select HAVE_GENERIC_HARDIRQS
5 select GENERIC_HARDIRQS_NO_DEPRECATED
5 6
6config AM33_2 7config AM33_2
7 def_bool n 8 def_bool n
@@ -53,21 +54,6 @@ config GENERIC_TIME
53config GENERIC_CLOCKEVENTS 54config GENERIC_CLOCKEVENTS
54 def_bool y 55 def_bool y
55 56
56config GENERIC_CLOCKEVENTS_BUILD
57 def_bool y
58 depends on GENERIC_CLOCKEVENTS
59
60config GENERIC_CLOCKEVENTS_BROADCAST
61 bool
62
63config CEVT_MN10300
64 def_bool y
65 depends on GENERIC_CLOCKEVENTS
66
67config CSRC_MN10300
68 def_bool y
69 depends on GENERIC_TIME
70
71config GENERIC_BUG 57config GENERIC_BUG
72 def_bool y 58 def_bool y
73 59
diff --git a/arch/mn10300/include/asm/intctl-regs.h b/arch/mn10300/include/asm/intctl-regs.h
index 585b708c2bc0..d65bbeebe50a 100644
--- a/arch/mn10300/include/asm/intctl-regs.h
+++ b/arch/mn10300/include/asm/intctl-regs.h
@@ -60,11 +60,6 @@
60 60
61#ifndef __ASSEMBLY__ 61#ifndef __ASSEMBLY__
62extern void set_intr_level(int irq, u16 level); 62extern void set_intr_level(int irq, u16 level);
63extern void mn10300_intc_set_level(unsigned int irq, unsigned int level);
64extern void mn10300_intc_clear(unsigned int irq);
65extern void mn10300_intc_set(unsigned int irq);
66extern void mn10300_intc_enable(unsigned int irq);
67extern void mn10300_intc_disable(unsigned int irq);
68extern void mn10300_set_lateack_irq_type(int irq); 63extern void mn10300_set_lateack_irq_type(int irq);
69#endif 64#endif
70 65
diff --git a/arch/mn10300/kernel/Makefile b/arch/mn10300/kernel/Makefile
index 8f5f1e81baf5..a06a2e10051d 100644
--- a/arch/mn10300/kernel/Makefile
+++ b/arch/mn10300/kernel/Makefile
@@ -8,7 +8,8 @@ fpu-obj-$(CONFIG_FPU) := fpu.o fpu-low.o
8 8
9obj-y := process.o signal.o entry.o traps.o irq.o \ 9obj-y := process.o signal.o entry.o traps.o irq.o \
10 ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \ 10 ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \
11 switch_to.o mn10300_ksyms.o kernel_execve.o $(fpu-obj-y) 11 switch_to.o mn10300_ksyms.o kernel_execve.o $(fpu-obj-y) \
12 csrc-mn10300.o cevt-mn10300.o
12 13
13obj-$(CONFIG_SMP) += smp.o smp-low.o 14obj-$(CONFIG_SMP) += smp.o smp-low.o
14 15
@@ -28,5 +29,3 @@ obj-$(CONFIG_MN10300_RTC) += rtc.o
28obj-$(CONFIG_PROFILE) += profile.o profile-low.o 29obj-$(CONFIG_PROFILE) += profile.o profile-low.o
29obj-$(CONFIG_MODULES) += module.o 30obj-$(CONFIG_MODULES) += module.o
30obj-$(CONFIG_KPROBES) += kprobes.o 31obj-$(CONFIG_KPROBES) += kprobes.o
31obj-$(CONFIG_CSRC_MN10300) += csrc-mn10300.o
32obj-$(CONFIG_CEVT_MN10300) += cevt-mn10300.o
diff --git a/arch/mn10300/kernel/cevt-mn10300.c b/arch/mn10300/kernel/cevt-mn10300.c
index d4cb535bf786..69cae0260786 100644
--- a/arch/mn10300/kernel/cevt-mn10300.c
+++ b/arch/mn10300/kernel/cevt-mn10300.c
@@ -89,9 +89,10 @@ int __init init_clockevents(void)
89 cd->name = "Timestamp"; 89 cd->name = "Timestamp";
90 cd->features = CLOCK_EVT_FEAT_ONESHOT; 90 cd->features = CLOCK_EVT_FEAT_ONESHOT;
91 91
92 /* Calculate the min / max delta */ 92 /* Calculate shift/mult. We want to spawn at least 1 second */
93 clockevent_set_clock(cd, MN10300_JCCLK); 93 clockevents_calc_mult_shift(cd, MN10300_JCCLK, 1);
94 94
95 /* Calculate the min / max delta */
95 cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd); 96 cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd);
96 cd->min_delta_ns = clockevent_delta2ns(100, cd); 97 cd->min_delta_ns = clockevent_delta2ns(100, cd);
97 98
@@ -110,9 +111,9 @@ int __init init_clockevents(void)
110#if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) 111#if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
111 /* setup timer irq affinity so it only runs on this cpu */ 112 /* setup timer irq affinity so it only runs on this cpu */
112 { 113 {
113 struct irq_desc *desc; 114 struct irq_data *data;
114 desc = irq_to_desc(cd->irq); 115 data = irq_get_irq_data(cd->irq);
115 cpumask_copy(desc->affinity, cpumask_of(cpu)); 116 cpumask_copy(data->affinity, cpumask_of(cpu));
116 iact->flags |= IRQF_NOBALANCING; 117 iact->flags |= IRQF_NOBALANCING;
117 } 118 }
118#endif 119#endif
diff --git a/arch/mn10300/kernel/csrc-mn10300.c b/arch/mn10300/kernel/csrc-mn10300.c
index ba2f0c4d6e01..45644cf18c41 100644
--- a/arch/mn10300/kernel/csrc-mn10300.c
+++ b/arch/mn10300/kernel/csrc-mn10300.c
@@ -29,7 +29,6 @@ static struct clocksource clocksource_mn10300 = {
29int __init init_clocksource(void) 29int __init init_clocksource(void)
30{ 30{
31 startup_timestamp_counter(); 31 startup_timestamp_counter();
32 clocksource_set_clock(&clocksource_mn10300, MN10300_TSCCLK); 32 clocksource_register_hz(&clocksource_mn10300, MN10300_TSCCLK);
33 clocksource_register(&clocksource_mn10300);
34 return 0; 33 return 0;
35} 34}
diff --git a/arch/mn10300/kernel/internal.h b/arch/mn10300/kernel/internal.h
index 6a064ab5af07..ea946613f46d 100644
--- a/arch/mn10300/kernel/internal.h
+++ b/arch/mn10300/kernel/internal.h
@@ -33,13 +33,3 @@ extern void mn10300_low_ipi_handler(void);
33 * time.c 33 * time.c
34 */ 34 */
35extern irqreturn_t local_timer_interrupt(void); 35extern irqreturn_t local_timer_interrupt(void);
36
37/*
38 * time.c
39 */
40#ifdef CONFIG_CEVT_MN10300
41extern void clockevent_set_clock(struct clock_event_device *, unsigned int);
42#endif
43#ifdef CONFIG_CSRC_MN10300
44extern void clocksource_set_clock(struct clocksource *, unsigned int);
45#endif
diff --git a/arch/mn10300/kernel/irq.c b/arch/mn10300/kernel/irq.c
index ac11754ecec5..f09fed5e6afc 100644
--- a/arch/mn10300/kernel/irq.c
+++ b/arch/mn10300/kernel/irq.c
@@ -37,8 +37,9 @@ atomic_t irq_err_count;
37/* 37/*
38 * MN10300 interrupt controller operations 38 * MN10300 interrupt controller operations
39 */ 39 */
40static void mn10300_cpupic_ack(unsigned int irq) 40static void mn10300_cpupic_ack(struct irq_data *d)
41{ 41{
42 unsigned int irq = d->irq;
42 unsigned long flags; 43 unsigned long flags;
43 u16 tmp; 44 u16 tmp;
44 45
@@ -61,13 +62,14 @@ static void __mask_and_set_icr(unsigned int irq,
61 arch_local_irq_restore(flags); 62 arch_local_irq_restore(flags);
62} 63}
63 64
64static void mn10300_cpupic_mask(unsigned int irq) 65static void mn10300_cpupic_mask(struct irq_data *d)
65{ 66{
66 __mask_and_set_icr(irq, GxICR_LEVEL, 0); 67 __mask_and_set_icr(d->irq, GxICR_LEVEL, 0);
67} 68}
68 69
69static void mn10300_cpupic_mask_ack(unsigned int irq) 70static void mn10300_cpupic_mask_ack(struct irq_data *d)
70{ 71{
72 unsigned int irq = d->irq;
71#ifdef CONFIG_SMP 73#ifdef CONFIG_SMP
72 unsigned long flags; 74 unsigned long flags;
73 u16 tmp; 75 u16 tmp;
@@ -85,7 +87,7 @@ static void mn10300_cpupic_mask_ack(unsigned int irq)
85 tmp2 = GxICR(irq); 87 tmp2 = GxICR(irq);
86 88
87 irq_affinity_online[irq] = 89 irq_affinity_online[irq] =
88 any_online_cpu(*irq_desc[irq].affinity); 90 any_online_cpu(*d->affinity);
89 CROSS_GxICR(irq, irq_affinity_online[irq]) = 91 CROSS_GxICR(irq, irq_affinity_online[irq]) =
90 (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT; 92 (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
91 tmp = CROSS_GxICR(irq, irq_affinity_online[irq]); 93 tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
@@ -97,13 +99,14 @@ static void mn10300_cpupic_mask_ack(unsigned int irq)
97#endif /* CONFIG_SMP */ 99#endif /* CONFIG_SMP */
98} 100}
99 101
100static void mn10300_cpupic_unmask(unsigned int irq) 102static void mn10300_cpupic_unmask(struct irq_data *d)
101{ 103{
102 __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE); 104 __mask_and_set_icr(d->irq, GxICR_LEVEL, GxICR_ENABLE);
103} 105}
104 106
105static void mn10300_cpupic_unmask_clear(unsigned int irq) 107static void mn10300_cpupic_unmask_clear(struct irq_data *d)
106{ 108{
109 unsigned int irq = d->irq;
107 /* the MN10300 PIC latches its interrupt request bit, even after the 110 /* the MN10300 PIC latches its interrupt request bit, even after the
108 * device has ceased to assert its interrupt line and the interrupt 111 * device has ceased to assert its interrupt line and the interrupt
109 * channel has been disabled in the PIC, so for level-triggered 112 * channel has been disabled in the PIC, so for level-triggered
@@ -121,7 +124,7 @@ static void mn10300_cpupic_unmask_clear(unsigned int irq)
121 } else { 124 } else {
122 tmp = GxICR(irq); 125 tmp = GxICR(irq);
123 126
124 irq_affinity_online[irq] = any_online_cpu(*irq_desc[irq].affinity); 127 irq_affinity_online[irq] = any_online_cpu(*d->affinity);
125 CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT; 128 CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
126 tmp = CROSS_GxICR(irq, irq_affinity_online[irq]); 129 tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
127 } 130 }
@@ -134,7 +137,8 @@ static void mn10300_cpupic_unmask_clear(unsigned int irq)
134 137
135#ifdef CONFIG_SMP 138#ifdef CONFIG_SMP
136static int 139static int
137mn10300_cpupic_setaffinity(unsigned int irq, const struct cpumask *mask) 140mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
141 bool force)
138{ 142{
139 unsigned long flags; 143 unsigned long flags;
140 int err; 144 int err;
@@ -142,7 +146,7 @@ mn10300_cpupic_setaffinity(unsigned int irq, const struct cpumask *mask)
142 flags = arch_local_cli_save(); 146 flags = arch_local_cli_save();
143 147
144 /* check irq no */ 148 /* check irq no */
145 switch (irq) { 149 switch (d->irq) {
146 case TMJCIRQ: 150 case TMJCIRQ:
147 case RESCHEDULE_IPI: 151 case RESCHEDULE_IPI:
148 case CALL_FUNC_SINGLE_IPI: 152 case CALL_FUNC_SINGLE_IPI:
@@ -181,7 +185,7 @@ mn10300_cpupic_setaffinity(unsigned int irq, const struct cpumask *mask)
181 break; 185 break;
182 186
183 default: 187 default:
184 set_bit(irq, irq_affinity_request); 188 set_bit(d->irq, irq_affinity_request);
185 err = 0; 189 err = 0;
186 break; 190 break;
187 } 191 }
@@ -202,15 +206,15 @@ mn10300_cpupic_setaffinity(unsigned int irq, const struct cpumask *mask)
202 * mask_ack() is provided), and mask_ack() just masks. 206 * mask_ack() is provided), and mask_ack() just masks.
203 */ 207 */
204static struct irq_chip mn10300_cpu_pic_level = { 208static struct irq_chip mn10300_cpu_pic_level = {
205 .name = "cpu_l", 209 .name = "cpu_l",
206 .disable = mn10300_cpupic_mask, 210 .irq_disable = mn10300_cpupic_mask,
207 .enable = mn10300_cpupic_unmask_clear, 211 .irq_enable = mn10300_cpupic_unmask_clear,
208 .ack = NULL, 212 .irq_ack = NULL,
209 .mask = mn10300_cpupic_mask, 213 .irq_mask = mn10300_cpupic_mask,
210 .mask_ack = mn10300_cpupic_mask, 214 .irq_mask_ack = mn10300_cpupic_mask,
211 .unmask = mn10300_cpupic_unmask_clear, 215 .irq_unmask = mn10300_cpupic_unmask_clear,
212#ifdef CONFIG_SMP 216#ifdef CONFIG_SMP
213 .set_affinity = mn10300_cpupic_setaffinity, 217 .irq_set_affinity = mn10300_cpupic_setaffinity,
214#endif 218#endif
215}; 219};
216 220
@@ -220,15 +224,15 @@ static struct irq_chip mn10300_cpu_pic_level = {
220 * We use the latch clearing function of the PIC as the 'ACK' function. 224 * We use the latch clearing function of the PIC as the 'ACK' function.
221 */ 225 */
222static struct irq_chip mn10300_cpu_pic_edge = { 226static struct irq_chip mn10300_cpu_pic_edge = {
223 .name = "cpu_e", 227 .name = "cpu_e",
224 .disable = mn10300_cpupic_mask, 228 .irq_disable = mn10300_cpupic_mask,
225 .enable = mn10300_cpupic_unmask, 229 .irq_enable = mn10300_cpupic_unmask,
226 .ack = mn10300_cpupic_ack, 230 .irq_ack = mn10300_cpupic_ack,
227 .mask = mn10300_cpupic_mask, 231 .irq_mask = mn10300_cpupic_mask,
228 .mask_ack = mn10300_cpupic_mask_ack, 232 .irq_mask_ack = mn10300_cpupic_mask_ack,
229 .unmask = mn10300_cpupic_unmask, 233 .irq_unmask = mn10300_cpupic_unmask,
230#ifdef CONFIG_SMP 234#ifdef CONFIG_SMP
231 .set_affinity = mn10300_cpupic_setaffinity, 235 .irq_set_affinity = mn10300_cpupic_setaffinity,
232#endif 236#endif
233}; 237};
234 238
@@ -252,31 +256,6 @@ void set_intr_level(int irq, u16 level)
252 __mask_and_set_icr(irq, GxICR_ENABLE, level); 256 __mask_and_set_icr(irq, GxICR_ENABLE, level);
253} 257}
254 258
255void mn10300_intc_set_level(unsigned int irq, unsigned int level)
256{
257 set_intr_level(irq, NUM2GxICR_LEVEL(level) & GxICR_LEVEL);
258}
259
260void mn10300_intc_clear(unsigned int irq)
261{
262 __mask_and_set_icr(irq, GxICR_LEVEL | GxICR_ENABLE, GxICR_DETECT);
263}
264
265void mn10300_intc_set(unsigned int irq)
266{
267 __mask_and_set_icr(irq, 0, GxICR_REQUEST | GxICR_DETECT);
268}
269
270void mn10300_intc_enable(unsigned int irq)
271{
272 mn10300_cpupic_unmask(irq);
273}
274
275void mn10300_intc_disable(unsigned int irq)
276{
277 mn10300_cpupic_mask(irq);
278}
279
280/* 259/*
281 * mark an interrupt to be ACK'd after interrupt handlers have been run rather 260 * mark an interrupt to be ACK'd after interrupt handlers have been run rather
282 * than before 261 * than before
@@ -296,7 +275,7 @@ void __init init_IRQ(void)
296 int irq; 275 int irq;
297 276
298 for (irq = 0; irq < NR_IRQS; irq++) 277 for (irq = 0; irq < NR_IRQS; irq++)
299 if (irq_desc[irq].chip == &no_irq_chip) 278 if (get_irq_chip(irq) == &no_irq_chip)
300 /* due to the PIC latching interrupt requests, even 279 /* due to the PIC latching interrupt requests, even
301 * when the IRQ is disabled, IRQ_PENDING is superfluous 280 * when the IRQ is disabled, IRQ_PENDING is superfluous
302 * and we can use handle_level_irq() for edge-triggered 281 * and we can use handle_level_irq() for edge-triggered
@@ -384,12 +363,12 @@ int show_interrupts(struct seq_file *p, void *v)
384 363
385 if (i < NR_CPU_IRQS) 364 if (i < NR_CPU_IRQS)
386 seq_printf(p, " %14s.%u", 365 seq_printf(p, " %14s.%u",
387 irq_desc[i].chip->name, 366 irq_desc[i].irq_data.chip->name,
388 (GxICR(i) & GxICR_LEVEL) >> 367 (GxICR(i) & GxICR_LEVEL) >>
389 GxICR_LEVEL_SHIFT); 368 GxICR_LEVEL_SHIFT);
390 else 369 else
391 seq_printf(p, " %14s", 370 seq_printf(p, " %14s",
392 irq_desc[i].chip->name); 371 irq_desc[i].irq_data.chip->name);
393 372
394 seq_printf(p, " %s", action->name); 373 seq_printf(p, " %s", action->name);
395 374
diff --git a/arch/mn10300/kernel/mn10300-serial.c b/arch/mn10300/kernel/mn10300-serial.c
index 996384dba45d..93c53739cfc9 100644
--- a/arch/mn10300/kernel/mn10300-serial.c
+++ b/arch/mn10300/kernel/mn10300-serial.c
@@ -384,17 +384,21 @@ static void mn10300_serial_mask_ack(unsigned int irq)
384 arch_local_irq_restore(flags); 384 arch_local_irq_restore(flags);
385} 385}
386 386
387static void mn10300_serial_nop(unsigned int irq) 387static void mn10300_serial_chip_mask_ack(struct irq_data *d)
388{
389 mn10300_serial_mask_ack(d->irq);
390}
391
392static void mn10300_serial_nop(struct irq_data *d)
388{ 393{
389} 394}
390 395
391static struct irq_chip mn10300_serial_pic = { 396static struct irq_chip mn10300_serial_pic = {
392 .name = "mnserial", 397 .name = "mnserial",
393 .ack = mn10300_serial_mask_ack, 398 .irq_ack = mn10300_serial_chip_mask_ack,
394 .mask = mn10300_serial_mask_ack, 399 .irq_mask = mn10300_serial_chip_mask_ack,
395 .mask_ack = mn10300_serial_mask_ack, 400 .irq_mask_ack = mn10300_serial_chip_mask_ack,
396 .unmask = mn10300_serial_nop, 401 .irq_unmask = mn10300_serial_nop,
397 .end = mn10300_serial_nop,
398}; 402};
399 403
400 404
diff --git a/arch/mn10300/kernel/smp.c b/arch/mn10300/kernel/smp.c
index 0dcd1c686ba8..1ebb79f1650d 100644
--- a/arch/mn10300/kernel/smp.c
+++ b/arch/mn10300/kernel/smp.c
@@ -113,15 +113,17 @@ static void init_ipi(void);
113 */ 113 */
114static void mn10300_ipi_disable(unsigned int irq); 114static void mn10300_ipi_disable(unsigned int irq);
115static void mn10300_ipi_enable(unsigned int irq); 115static void mn10300_ipi_enable(unsigned int irq);
116static void mn10300_ipi_ack(unsigned int irq); 116static void mn10300_ipi_chip_disable(struct irq_data *d);
117static void mn10300_ipi_nop(unsigned int irq); 117static void mn10300_ipi_chip_enable(struct irq_data *d);
118static void mn10300_ipi_ack(struct irq_data *d);
119static void mn10300_ipi_nop(struct irq_data *d);
118 120
119static struct irq_chip mn10300_ipi_type = { 121static struct irq_chip mn10300_ipi_type = {
120 .name = "cpu_ipi", 122 .name = "cpu_ipi",
121 .disable = mn10300_ipi_disable, 123 .irq_disable = mn10300_ipi_chip_disable,
122 .enable = mn10300_ipi_enable, 124 .irq_enable = mn10300_ipi_chip_enable,
123 .ack = mn10300_ipi_ack, 125 .irq_ack = mn10300_ipi_ack,
124 .eoi = mn10300_ipi_nop 126 .irq_eoi = mn10300_ipi_nop
125}; 127};
126 128
127static irqreturn_t smp_reschedule_interrupt(int irq, void *dev_id); 129static irqreturn_t smp_reschedule_interrupt(int irq, void *dev_id);
@@ -236,6 +238,11 @@ static void mn10300_ipi_enable(unsigned int irq)
236 arch_local_irq_restore(flags); 238 arch_local_irq_restore(flags);
237} 239}
238 240
241static void mn10300_ipi_chip_enable(struct irq_data *d)
242{
243 mn10300_ipi_enable(d->irq);
244}
245
239/** 246/**
240 * mn10300_ipi_disable - Disable an IPI 247 * mn10300_ipi_disable - Disable an IPI
241 * @irq: The IPI to be disabled. 248 * @irq: The IPI to be disabled.
@@ -254,6 +261,12 @@ static void mn10300_ipi_disable(unsigned int irq)
254 arch_local_irq_restore(flags); 261 arch_local_irq_restore(flags);
255} 262}
256 263
264static void mn10300_ipi_chip_disable(struct irq_data *d)
265{
266 mn10300_ipi_disable(d->irq);
267}
268
269
257/** 270/**
258 * mn10300_ipi_ack - Acknowledge an IPI interrupt in the PIC 271 * mn10300_ipi_ack - Acknowledge an IPI interrupt in the PIC
259 * @irq: The IPI to be acknowledged. 272 * @irq: The IPI to be acknowledged.
@@ -261,8 +274,9 @@ static void mn10300_ipi_disable(unsigned int irq)
261 * Clear the interrupt detection flag for the IPI on the appropriate interrupt 274 * Clear the interrupt detection flag for the IPI on the appropriate interrupt
262 * channel in the PIC. 275 * channel in the PIC.
263 */ 276 */
264static void mn10300_ipi_ack(unsigned int irq) 277static void mn10300_ipi_ack(struct irq_data *d)
265{ 278{
279 unsigned int irq = d->irq;
266 unsigned long flags; 280 unsigned long flags;
267 u16 tmp; 281 u16 tmp;
268 282
@@ -276,7 +290,7 @@ static void mn10300_ipi_ack(unsigned int irq)
276 * mn10300_ipi_nop - Dummy IPI action 290 * mn10300_ipi_nop - Dummy IPI action
277 * @irq: The IPI to be acted upon. 291 * @irq: The IPI to be acted upon.
278 */ 292 */
279static void mn10300_ipi_nop(unsigned int irq) 293static void mn10300_ipi_nop(struct irq_data *d)
280{ 294{
281} 295}
282 296
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c
index 5b955000626d..67c6416a58f8 100644
--- a/arch/mn10300/kernel/time.c
+++ b/arch/mn10300/kernel/time.c
@@ -93,79 +93,6 @@ irqreturn_t local_timer_interrupt(void)
93 return IRQ_HANDLED; 93 return IRQ_HANDLED;
94} 94}
95 95
96#ifndef CONFIG_GENERIC_TIME
97/*
98 * advance the kernel's time keeping clocks (xtime and jiffies)
99 * - we use Timer 0 & 1 cascaded as a clock to nudge us the next time
100 * there's a need to update
101 */
102static irqreturn_t timer_interrupt(int irq, void *dev_id)
103{
104 unsigned tsc, elapse;
105 irqreturn_t ret;
106
107 while (tsc = get_cycles(),
108 elapse = tsc - mn10300_last_tsc, /* time elapsed since last
109 * tick */
110 elapse > MN10300_TSC_PER_HZ
111 ) {
112 mn10300_last_tsc += MN10300_TSC_PER_HZ;
113
114 /* advance the kernel's time tracking system */
115 xtime_update(1);
116 }
117
118 ret = local_timer_interrupt();
119#ifdef CONFIG_SMP
120 send_IPI_allbutself(LOCAL_TIMER_IPI);
121#endif
122 return ret;
123}
124
125static struct irqaction timer_irq = {
126 .handler = timer_interrupt,
127 .flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER,
128 .name = "timer",
129};
130#endif /* CONFIG_GENERIC_TIME */
131
132#ifdef CONFIG_CSRC_MN10300
133void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
134{
135 u64 temp;
136 u32 shift;
137
138 /* Find a shift value */
139 for (shift = 32; shift > 0; shift--) {
140 temp = (u64) NSEC_PER_SEC << shift;
141 do_div(temp, clock);
142 if ((temp >> 32) == 0)
143 break;
144 }
145 cs->shift = shift;
146 cs->mult = (u32) temp;
147}
148#endif
149
150#if CONFIG_CEVT_MN10300
151void __cpuinit clockevent_set_clock(struct clock_event_device *cd,
152 unsigned int clock)
153{
154 u64 temp;
155 u32 shift;
156
157 /* Find a shift value */
158 for (shift = 32; shift > 0; shift--) {
159 temp = (u64) clock << shift;
160 do_div(temp, NSEC_PER_SEC);
161 if ((temp >> 32) == 0)
162 break;
163 }
164 cd->shift = shift;
165 cd->mult = (u32) temp;
166}
167#endif
168
169/* 96/*
170 * initialise the various timers used by the main part of the kernel 97 * initialise the various timers used by the main part of the kernel
171 */ 98 */
@@ -177,11 +104,7 @@ void __init time_init(void)
177 */ 104 */
178 TMPSCNT |= TMPSCNT_ENABLE; 105 TMPSCNT |= TMPSCNT_ENABLE;
179 106
180#ifdef CONFIG_GENERIC_TIME
181 init_clocksource(); 107 init_clocksource();
182#else
183 startup_timestamp_counter();
184#endif
185 108
186 printk(KERN_INFO 109 printk(KERN_INFO
187 "timestamp counter I/O clock running at %lu.%02lu" 110 "timestamp counter I/O clock running at %lu.%02lu"
@@ -190,12 +113,7 @@ void __init time_init(void)
190 113
191 mn10300_last_tsc = read_timestamp_counter(); 114 mn10300_last_tsc = read_timestamp_counter();
192 115
193#ifdef CONFIG_GENERIC_CLOCKEVENTS
194 init_clockevents(); 116 init_clockevents();
195#else
196 reload_jiffies_counter(MN10300_JC_PER_HZ - 1);
197 setup_jiffies_interrupt(TMJCIRQ, &timer_irq, CONFIG_TIMER_IRQ_LEVEL);
198#endif
199 117
200#ifdef CONFIG_MN10300_WD_TIMER 118#ifdef CONFIG_MN10300_WD_TIMER
201 /* start the watchdog timer */ 119 /* start the watchdog timer */
diff --git a/arch/mn10300/unit-asb2364/include/unit/fpga-regs.h b/arch/mn10300/unit-asb2364/include/unit/fpga-regs.h
index 7cf12054db65..33f100f9b468 100644
--- a/arch/mn10300/unit-asb2364/include/unit/fpga-regs.h
+++ b/arch/mn10300/unit-asb2364/include/unit/fpga-regs.h
@@ -14,7 +14,7 @@
14#define ASB2364_FPGA_REG_RESET_USB __SYSREG(0xa900130c, u16) 14#define ASB2364_FPGA_REG_RESET_USB __SYSREG(0xa900130c, u16)
15#define ASB2364_FPGA_REG_RESET_AV __SYSREG(0xa9001310, u16) 15#define ASB2364_FPGA_REG_RESET_AV __SYSREG(0xa9001310, u16)
16 16
17#define ASB2364_FPGA_REG_IRQ(X) __SYSREG(0xa9001590+((X)*4), u16) 17#define ASB2364_FPGA_REG_IRQ(X) __SYSREG(0xa9001510+((X)*4), u16)
18#define ASB2364_FPGA_REG_IRQ_LAN ASB2364_FPGA_REG_IRQ(0) 18#define ASB2364_FPGA_REG_IRQ_LAN ASB2364_FPGA_REG_IRQ(0)
19#define ASB2364_FPGA_REG_IRQ_UART ASB2364_FPGA_REG_IRQ(1) 19#define ASB2364_FPGA_REG_IRQ_UART ASB2364_FPGA_REG_IRQ(1)
20#define ASB2364_FPGA_REG_IRQ_I2C ASB2364_FPGA_REG_IRQ(2) 20#define ASB2364_FPGA_REG_IRQ_I2C ASB2364_FPGA_REG_IRQ(2)
diff --git a/arch/mn10300/unit-asb2364/include/unit/serial.h b/arch/mn10300/unit-asb2364/include/unit/serial.h
index 7f048bbfdfd7..92f224a97efc 100644
--- a/arch/mn10300/unit-asb2364/include/unit/serial.h
+++ b/arch/mn10300/unit-asb2364/include/unit/serial.h
@@ -59,18 +59,18 @@ static inline void __debug_to_serial(const char *p, int n)
59#define SERIAL_PORT_DFNS /* stolen by gdb-stub */ 59#define SERIAL_PORT_DFNS /* stolen by gdb-stub */
60 60
61#if defined(CONFIG_GDBSTUB_ON_TTYS0) 61#if defined(CONFIG_GDBSTUB_ON_TTYS0)
62#define GDBPORT_SERIAL_RX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX * 4, u8) 62#define GDBPORT_SERIAL_RX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX * 2, u8)
63#define GDBPORT_SERIAL_TX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX * 4, u8) 63#define GDBPORT_SERIAL_TX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX * 2, u8)
64#define GDBPORT_SERIAL_DLL __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 4, u8) 64#define GDBPORT_SERIAL_DLL __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 2, u8)
65#define GDBPORT_SERIAL_DLM __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 4, u8) 65#define GDBPORT_SERIAL_DLM __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 2, u8)
66#define GDBPORT_SERIAL_IER __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 4, u8) 66#define GDBPORT_SERIAL_IER __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 2, u8)
67#define GDBPORT_SERIAL_IIR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 4, u8) 67#define GDBPORT_SERIAL_IIR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 2, u8)
68#define GDBPORT_SERIAL_FCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 4, u8) 68#define GDBPORT_SERIAL_FCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 2, u8)
69#define GDBPORT_SERIAL_LCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 4, u8) 69#define GDBPORT_SERIAL_LCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 2, u8)
70#define GDBPORT_SERIAL_MCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8) 70#define GDBPORT_SERIAL_MCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 2, u8)
71#define GDBPORT_SERIAL_LSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8) 71#define GDBPORT_SERIAL_LSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 2, u8)
72#define GDBPORT_SERIAL_MSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8) 72#define GDBPORT_SERIAL_MSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 2, u8)
73#define GDBPORT_SERIAL_SCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 4, u8) 73#define GDBPORT_SERIAL_SCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 2, u8)
74#define GDBPORT_SERIAL_IRQ SERIAL_IRQ 74#define GDBPORT_SERIAL_IRQ SERIAL_IRQ
75 75
76#elif defined(CONFIG_GDBSTUB_ON_TTYS1) 76#elif defined(CONFIG_GDBSTUB_ON_TTYS1)
diff --git a/arch/mn10300/unit-asb2364/irq-fpga.c b/arch/mn10300/unit-asb2364/irq-fpga.c
index fcf29754e4d1..ee84e62b16ed 100644
--- a/arch/mn10300/unit-asb2364/irq-fpga.c
+++ b/arch/mn10300/unit-asb2364/irq-fpga.c
@@ -17,38 +17,38 @@
17/* 17/*
18 * FPGA PIC operations 18 * FPGA PIC operations
19 */ 19 */
20static void asb2364_fpga_mask(unsigned int irq) 20static void asb2364_fpga_mask(struct irq_data *d)
21{ 21{
22 ASB2364_FPGA_REG_MASK(irq - NR_CPU_IRQS) = 0x0001; 22 ASB2364_FPGA_REG_MASK(d->irq - NR_CPU_IRQS) = 0x0001;
23 SyncExBus(); 23 SyncExBus();
24} 24}
25 25
26static void asb2364_fpga_ack(unsigned int irq) 26static void asb2364_fpga_ack(struct irq_data *d)
27{ 27{
28 ASB2364_FPGA_REG_IRQ(irq - NR_CPU_IRQS) = 0x0001; 28 ASB2364_FPGA_REG_IRQ(d->irq - NR_CPU_IRQS) = 0x0001;
29 SyncExBus(); 29 SyncExBus();
30} 30}
31 31
32static void asb2364_fpga_mask_ack(unsigned int irq) 32static void asb2364_fpga_mask_ack(struct irq_data *d)
33{ 33{
34 ASB2364_FPGA_REG_MASK(irq - NR_CPU_IRQS) = 0x0001; 34 ASB2364_FPGA_REG_MASK(d->irq - NR_CPU_IRQS) = 0x0001;
35 SyncExBus(); 35 SyncExBus();
36 ASB2364_FPGA_REG_IRQ(irq - NR_CPU_IRQS) = 0x0001; 36 ASB2364_FPGA_REG_IRQ(d->irq - NR_CPU_IRQS) = 0x0001;
37 SyncExBus(); 37 SyncExBus();
38} 38}
39 39
40static void asb2364_fpga_unmask(unsigned int irq) 40static void asb2364_fpga_unmask(struct irq_data *d)
41{ 41{
42 ASB2364_FPGA_REG_MASK(irq - NR_CPU_IRQS) = 0x0000; 42 ASB2364_FPGA_REG_MASK(d->irq - NR_CPU_IRQS) = 0x0000;
43 SyncExBus(); 43 SyncExBus();
44} 44}
45 45
46static struct irq_chip asb2364_fpga_pic = { 46static struct irq_chip asb2364_fpga_pic = {
47 .name = "fpga", 47 .name = "fpga",
48 .ack = asb2364_fpga_ack, 48 .irq_ack = asb2364_fpga_ack,
49 .mask = asb2364_fpga_mask, 49 .irq_mask = asb2364_fpga_mask,
50 .mask_ack = asb2364_fpga_mask_ack, 50 .irq_mask_ack = asb2364_fpga_mask_ack,
51 .unmask = asb2364_fpga_unmask, 51 .irq_unmask = asb2364_fpga_unmask,
52}; 52};
53 53
54/* 54/*
@@ -88,6 +88,17 @@ void __init irq_fpga_init(void)
88{ 88{
89 int irq; 89 int irq;
90 90
91 ASB2364_FPGA_REG_MASK_LAN = 0x0001;
92 SyncExBus();
93 ASB2364_FPGA_REG_MASK_UART = 0x0001;
94 SyncExBus();
95 ASB2364_FPGA_REG_MASK_I2C = 0x0001;
96 SyncExBus();
97 ASB2364_FPGA_REG_MASK_USB = 0x0001;
98 SyncExBus();
99 ASB2364_FPGA_REG_MASK_FPGA = 0x0001;
100 SyncExBus();
101
91 for (irq = NR_CPU_IRQS; irq < NR_IRQS; irq++) 102 for (irq = NR_CPU_IRQS; irq < NR_IRQS; irq++)
92 set_irq_chip_and_handler(irq, &asb2364_fpga_pic, handle_level_irq); 103 set_irq_chip_and_handler(irq, &asb2364_fpga_pic, handle_level_irq);
93 104
diff --git a/arch/mn10300/unit-asb2364/unit-init.c b/arch/mn10300/unit-asb2364/unit-init.c
index 11440803db10..6359b41ce7e9 100644
--- a/arch/mn10300/unit-asb2364/unit-init.c
+++ b/arch/mn10300/unit-asb2364/unit-init.c
@@ -20,13 +20,41 @@
20#include <asm/processor.h> 20#include <asm/processor.h>
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <asm/intctl-regs.h> 22#include <asm/intctl-regs.h>
23#include <asm/serial-regs.h>
23#include <unit/fpga-regs.h> 24#include <unit/fpga-regs.h>
25#include <unit/serial.h>
26#include <unit/smsc911x.h>
27
28#define TTYS0_SERIAL_IER __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 2, u8)
29#define LAN_IRQ_CFG __SYSREG(SMSC911X_BASE + 0x54, u32)
30#define LAN_INT_EN __SYSREG(SMSC911X_BASE + 0x5c, u32)
24 31
25/* 32/*
26 * initialise some of the unit hardware before gdbstub is set up 33 * initialise some of the unit hardware before gdbstub is set up
27 */ 34 */
28asmlinkage void __init unit_init(void) 35asmlinkage void __init unit_init(void)
29{ 36{
37 /* Make sure we aren't going to get unexpected interrupts */
38 TTYS0_SERIAL_IER = 0;
39 SC0RXICR = 0;
40 SC0TXICR = 0;
41 SC1RXICR = 0;
42 SC1TXICR = 0;
43 SC2RXICR = 0;
44 SC2TXICR = 0;
45
46 /* Attempt to reset the FPGA attached peripherals */
47 ASB2364_FPGA_REG_RESET_LAN = 0x0000;
48 SyncExBus();
49 ASB2364_FPGA_REG_RESET_UART = 0x0000;
50 SyncExBus();
51 ASB2364_FPGA_REG_RESET_I2C = 0x0000;
52 SyncExBus();
53 ASB2364_FPGA_REG_RESET_USB = 0x0000;
54 SyncExBus();
55 ASB2364_FPGA_REG_RESET_AV = 0x0000;
56 SyncExBus();
57
30 /* set up the external interrupts */ 58 /* set up the external interrupts */
31 59
32 /* XIRQ[0]: NAND RXBY */ 60 /* XIRQ[0]: NAND RXBY */
@@ -56,7 +84,23 @@ asmlinkage void __init unit_init(void)
56 */ 84 */
57asmlinkage void __init unit_setup(void) 85asmlinkage void __init unit_setup(void)
58{ 86{
87 /* Release the reset on the SMSC911X so that it is ready by the time we
88 * need it */
89 ASB2364_FPGA_REG_RESET_LAN = 0x0001;
90 SyncExBus();
91 ASB2364_FPGA_REG_RESET_UART = 0x0001;
92 SyncExBus();
93 ASB2364_FPGA_REG_RESET_I2C = 0x0001;
94 SyncExBus();
95 ASB2364_FPGA_REG_RESET_USB = 0x0001;
96 SyncExBus();
97 ASB2364_FPGA_REG_RESET_AV = 0x0001;
98 SyncExBus();
59 99
100 /* Make sure the ethernet chipset isn't going to give us an interrupt
101 * storm from stuff it was doing pre-reset */
102 LAN_IRQ_CFG = 0;
103 LAN_INT_EN = 0;
60} 104}
61 105
62/* 106/*
diff --git a/arch/powerpc/include/asm/mpic.h b/arch/powerpc/include/asm/mpic.h
index 946ec4947da2..7005ee0b074d 100644
--- a/arch/powerpc/include/asm/mpic.h
+++ b/arch/powerpc/include/asm/mpic.h
@@ -367,6 +367,10 @@ struct mpic
367#define MPIC_SINGLE_DEST_CPU 0x00001000 367#define MPIC_SINGLE_DEST_CPU 0x00001000
368/* Enable CoreInt delivery of interrupts */ 368/* Enable CoreInt delivery of interrupts */
369#define MPIC_ENABLE_COREINT 0x00002000 369#define MPIC_ENABLE_COREINT 0x00002000
370/* Disable resetting of the MPIC.
371 * NOTE: This flag trumps MPIC_WANTS_RESET.
372 */
373#define MPIC_NO_RESET 0x00004000
370 374
371/* MPIC HW modification ID */ 375/* MPIC HW modification ID */
372#define MPIC_REGSET_MASK 0xf0000000 376#define MPIC_REGSET_MASK 0xf0000000
diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
index 0175a676b34b..48223f9b8728 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -125,8 +125,10 @@ extern int ptrace_put_reg(struct task_struct *task, int regno,
125#endif /* ! __powerpc64__ */ 125#endif /* ! __powerpc64__ */
126#define TRAP(regs) ((regs)->trap & ~0xF) 126#define TRAP(regs) ((regs)->trap & ~0xF)
127#ifdef __powerpc64__ 127#ifdef __powerpc64__
128#define NV_REG_POISON 0xdeadbeefdeadbeefUL
128#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1) 129#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
129#else 130#else
131#define NV_REG_POISON 0xdeadbeef
130#define CHECK_FULL_REGS(regs) \ 132#define CHECK_FULL_REGS(regs) \
131do { \ 133do { \
132 if ((regs)->trap & 1) \ 134 if ((regs)->trap & 1) \
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index 29852688ceaa..d225d99fe39d 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -176,11 +176,14 @@ static void *is_devfn_node(struct device_node *dn, void *data)
176 */ 176 */
177struct device_node *fetch_dev_dn(struct pci_dev *dev) 177struct device_node *fetch_dev_dn(struct pci_dev *dev)
178{ 178{
179 struct device_node *orig_dn = dev->dev.of_node; 179 struct pci_controller *phb = dev->sysdata;
180 struct device_node *dn; 180 struct device_node *dn;
181 unsigned long searchval = (dev->bus->number << 8) | dev->devfn; 181 unsigned long searchval = (dev->bus->number << 8) | dev->devfn;
182 182
183 dn = traverse_pci_devices(orig_dn, is_devfn_node, (void *)searchval); 183 if (WARN_ON(!phb))
184 return NULL;
185
186 dn = traverse_pci_devices(phb->dn, is_devfn_node, (void *)searchval);
184 if (dn) 187 if (dn)
185 dev->dev.of_node = dn; 188 dev->dev.of_node = dn;
186 return dn; 189 return dn;
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 906536998291..895b082f1e48 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -229,12 +229,16 @@ static int gpr_get(struct task_struct *target, const struct user_regset *regset,
229 unsigned int pos, unsigned int count, 229 unsigned int pos, unsigned int count,
230 void *kbuf, void __user *ubuf) 230 void *kbuf, void __user *ubuf)
231{ 231{
232 int ret; 232 int i, ret;
233 233
234 if (target->thread.regs == NULL) 234 if (target->thread.regs == NULL)
235 return -EIO; 235 return -EIO;
236 236
237 CHECK_FULL_REGS(target->thread.regs); 237 if (!FULL_REGS(target->thread.regs)) {
238 /* We have a partial register set. Fill 14-31 with bogus values */
239 for (i = 14; i < 32; i++)
240 target->thread.regs->gpr[i] = NV_REG_POISON;
241 }
238 242
239 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 243 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
240 target->thread.regs, 244 target->thread.regs,
@@ -641,11 +645,16 @@ static int gpr32_get(struct task_struct *target,
641 compat_ulong_t *k = kbuf; 645 compat_ulong_t *k = kbuf;
642 compat_ulong_t __user *u = ubuf; 646 compat_ulong_t __user *u = ubuf;
643 compat_ulong_t reg; 647 compat_ulong_t reg;
648 int i;
644 649
645 if (target->thread.regs == NULL) 650 if (target->thread.regs == NULL)
646 return -EIO; 651 return -EIO;
647 652
648 CHECK_FULL_REGS(target->thread.regs); 653 if (!FULL_REGS(target->thread.regs)) {
654 /* We have a partial register set. Fill 14-31 with bogus values */
655 for (i = 14; i < 32; i++)
656 target->thread.regs->gpr[i] = NV_REG_POISON;
657 }
649 658
650 pos /= sizeof(reg); 659 pos /= sizeof(reg);
651 count /= sizeof(reg); 660 count /= sizeof(reg);
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index eb7021815e2d..0f7c6718d261 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -147,6 +147,16 @@ static u32 mpic_infos[][MPIC_IDX_END] = {
147 147
148#endif /* CONFIG_MPIC_WEIRD */ 148#endif /* CONFIG_MPIC_WEIRD */
149 149
150static inline unsigned int mpic_processor_id(struct mpic *mpic)
151{
152 unsigned int cpu = 0;
153
154 if (mpic->flags & MPIC_PRIMARY)
155 cpu = hard_smp_processor_id();
156
157 return cpu;
158}
159
150/* 160/*
151 * Register accessor functions 161 * Register accessor functions
152 */ 162 */
@@ -210,19 +220,14 @@ static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 valu
210 220
211static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg) 221static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
212{ 222{
213 unsigned int cpu = 0; 223 unsigned int cpu = mpic_processor_id(mpic);
214 224
215 if (mpic->flags & MPIC_PRIMARY)
216 cpu = hard_smp_processor_id();
217 return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg); 225 return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
218} 226}
219 227
220static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value) 228static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
221{ 229{
222 unsigned int cpu = 0; 230 unsigned int cpu = mpic_processor_id(mpic);
223
224 if (mpic->flags & MPIC_PRIMARY)
225 cpu = hard_smp_processor_id();
226 231
227 _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value); 232 _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
228} 233}
@@ -913,6 +918,20 @@ void mpic_set_vector(unsigned int virq, unsigned int vector)
913 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri); 918 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
914} 919}
915 920
921void mpic_set_destination(unsigned int virq, unsigned int cpuid)
922{
923 struct mpic *mpic = mpic_from_irq(virq);
924 unsigned int src = mpic_irq_to_hw(virq);
925
926 DBG("mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
927 mpic, virq, src, cpuid);
928
929 if (src >= mpic->irq_count)
930 return;
931
932 mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
933}
934
916static struct irq_chip mpic_irq_chip = { 935static struct irq_chip mpic_irq_chip = {
917 .irq_mask = mpic_mask_irq, 936 .irq_mask = mpic_mask_irq,
918 .irq_unmask = mpic_unmask_irq, 937 .irq_unmask = mpic_unmask_irq,
@@ -993,6 +1012,16 @@ static int mpic_host_map(struct irq_host *h, unsigned int virq,
993 /* Set default irq type */ 1012 /* Set default irq type */
994 set_irq_type(virq, IRQ_TYPE_NONE); 1013 set_irq_type(virq, IRQ_TYPE_NONE);
995 1014
1015 /* If the MPIC was reset, then all vectors have already been
1016 * initialized. Otherwise, a per source lazy initialization
1017 * is done here.
1018 */
1019 if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
1020 mpic_set_vector(virq, hw);
1021 mpic_set_destination(virq, mpic_processor_id(mpic));
1022 mpic_irq_set_priority(virq, 8);
1023 }
1024
996 return 0; 1025 return 0;
997} 1026}
998 1027
@@ -1040,6 +1069,11 @@ static struct irq_host_ops mpic_host_ops = {
1040 .xlate = mpic_host_xlate, 1069 .xlate = mpic_host_xlate,
1041}; 1070};
1042 1071
1072static int mpic_reset_prohibited(struct device_node *node)
1073{
1074 return node && of_get_property(node, "pic-no-reset", NULL);
1075}
1076
1043/* 1077/*
1044 * Exported functions 1078 * Exported functions
1045 */ 1079 */
@@ -1160,7 +1194,15 @@ struct mpic * __init mpic_alloc(struct device_node *node,
1160 mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000); 1194 mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
1161 1195
1162 /* Reset */ 1196 /* Reset */
1163 if (flags & MPIC_WANTS_RESET) { 1197
1198 /* When using a device-node, reset requests are only honored if the MPIC
1199 * is allowed to reset.
1200 */
1201 if (mpic_reset_prohibited(node))
1202 mpic->flags |= MPIC_NO_RESET;
1203
1204 if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
1205 printk(KERN_DEBUG "mpic: Resetting\n");
1164 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0), 1206 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1165 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0)) 1207 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1166 | MPIC_GREG_GCONF_RESET); 1208 | MPIC_GREG_GCONF_RESET);
@@ -1320,22 +1362,21 @@ void __init mpic_init(struct mpic *mpic)
1320 1362
1321 mpic_pasemi_msi_init(mpic); 1363 mpic_pasemi_msi_init(mpic);
1322 1364
1323 if (mpic->flags & MPIC_PRIMARY) 1365 cpu = mpic_processor_id(mpic);
1324 cpu = hard_smp_processor_id();
1325 else
1326 cpu = 0;
1327 1366
1328 for (i = 0; i < mpic->num_sources; i++) { 1367 if (!(mpic->flags & MPIC_NO_RESET)) {
1329 /* start with vector = source number, and masked */ 1368 for (i = 0; i < mpic->num_sources; i++) {
1330 u32 vecpri = MPIC_VECPRI_MASK | i | 1369 /* start with vector = source number, and masked */
1331 (8 << MPIC_VECPRI_PRIORITY_SHIFT); 1370 u32 vecpri = MPIC_VECPRI_MASK | i |
1371 (8 << MPIC_VECPRI_PRIORITY_SHIFT);
1332 1372
1333 /* check if protected */ 1373 /* check if protected */
1334 if (mpic->protected && test_bit(i, mpic->protected)) 1374 if (mpic->protected && test_bit(i, mpic->protected))
1335 continue; 1375 continue;
1336 /* init hw */ 1376 /* init hw */
1337 mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri); 1377 mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
1338 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu); 1378 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
1379 }
1339 } 1380 }
1340 1381
1341 /* Init spurious vector */ 1382 /* Init spurious vector */
diff --git a/arch/s390/boot/Makefile b/arch/s390/boot/Makefile
index 8800cf090694..635d677d3281 100644
--- a/arch/s390/boot/Makefile
+++ b/arch/s390/boot/Makefile
@@ -6,7 +6,7 @@ COMPILE_VERSION := __linux_compile_version_id__`hostname | \
6 tr -c '[0-9A-Za-z]' '_'`__`date | \ 6 tr -c '[0-9A-Za-z]' '_'`__`date | \
7 tr -c '[0-9A-Za-z]' '_'`_t 7 tr -c '[0-9A-Za-z]' '_'`_t
8 8
9EXTRA_CFLAGS := -DCOMPILE_VERSION=$(COMPILE_VERSION) -gstabs -I. 9ccflags-y := -DCOMPILE_VERSION=$(COMPILE_VERSION) -gstabs -I.
10 10
11targets := image 11targets := image
12targets += bzImage 12targets += bzImage
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index e5221ec0b8e3..860d26514c08 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -8,7 +8,7 @@
8 8
9common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o) 9common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o)
10 10
11EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm 11ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
12 12
13kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o sigp.o diag.o 13kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o sigp.o diag.o
14obj-$(CONFIG_KVM) += kvm.o 14obj-$(CONFIG_KVM) += kvm.o
diff --git a/arch/s390/math-emu/Makefile b/arch/s390/math-emu/Makefile
index c84890341052..51d399549f60 100644
--- a/arch/s390/math-emu/Makefile
+++ b/arch/s390/math-emu/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-$(CONFIG_MATHEMU) := math.o 5obj-$(CONFIG_MATHEMU) := math.o
6 6
7EXTRA_CFLAGS := -I$(src) -Iinclude/math-emu -w 7ccflags-y := -I$(src) -Iinclude/math-emu -w
diff --git a/arch/tile/lib/atomic_32.c b/arch/tile/lib/atomic_32.c
index f02040d3614e..46570211df52 100644
--- a/arch/tile/lib/atomic_32.c
+++ b/arch/tile/lib/atomic_32.c
@@ -202,32 +202,32 @@ static inline int *__futex_setup(int __user *v)
202 return __atomic_hashed_lock((int __force *)v); 202 return __atomic_hashed_lock((int __force *)v);
203} 203}
204 204
205struct __get_user futex_set(int __user *v, int i) 205struct __get_user futex_set(u32 __user *v, int i)
206{ 206{
207 return __atomic_xchg((int __force *)v, __futex_setup(v), i); 207 return __atomic_xchg((int __force *)v, __futex_setup(v), i);
208} 208}
209 209
210struct __get_user futex_add(int __user *v, int n) 210struct __get_user futex_add(u32 __user *v, int n)
211{ 211{
212 return __atomic_xchg_add((int __force *)v, __futex_setup(v), n); 212 return __atomic_xchg_add((int __force *)v, __futex_setup(v), n);
213} 213}
214 214
215struct __get_user futex_or(int __user *v, int n) 215struct __get_user futex_or(u32 __user *v, int n)
216{ 216{
217 return __atomic_or((int __force *)v, __futex_setup(v), n); 217 return __atomic_or((int __force *)v, __futex_setup(v), n);
218} 218}
219 219
220struct __get_user futex_andn(int __user *v, int n) 220struct __get_user futex_andn(u32 __user *v, int n)
221{ 221{
222 return __atomic_andn((int __force *)v, __futex_setup(v), n); 222 return __atomic_andn((int __force *)v, __futex_setup(v), n);
223} 223}
224 224
225struct __get_user futex_xor(int __user *v, int n) 225struct __get_user futex_xor(u32 __user *v, int n)
226{ 226{
227 return __atomic_xor((int __force *)v, __futex_setup(v), n); 227 return __atomic_xor((int __force *)v, __futex_setup(v), n);
228} 228}
229 229
230struct __get_user futex_cmpxchg(int __user *v, int o, int n) 230struct __get_user futex_cmpxchg(u32 __user *v, int o, int n)
231{ 231{
232 return __atomic_cmpxchg((int __force *)v, __futex_setup(v), o, n); 232 return __atomic_cmpxchg((int __force *)v, __futex_setup(v), o, n);
233} 233}
diff --git a/arch/um/sys-ppc/Makefile b/arch/um/sys-ppc/Makefile
index b8bc844fd2c4..20d363bd7004 100644
--- a/arch/um/sys-ppc/Makefile
+++ b/arch/um/sys-ppc/Makefile
@@ -6,7 +6,7 @@ OBJ = built-in.o
6OBJS = ptrace.o sigcontext.o checksum.o miscthings.o misc.o \ 6OBJS = ptrace.o sigcontext.o checksum.o miscthings.o misc.o \
7 ptrace_user.o sysrq.o 7 ptrace_user.o sysrq.o
8 8
9EXTRA_AFLAGS := -DCONFIG_PPC32 -I. -I$(srctree)/arch/ppc/kernel 9asflags-y := -DCONFIG_PPC32 -I. -I$(srctree)/arch/ppc/kernel
10 10
11all: $(OBJ) 11all: $(OBJ)
12 12
@@ -15,10 +15,10 @@ $(OBJ): $(OBJS)
15 $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ 15 $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@
16 16
17ptrace_user.o: ptrace_user.c 17ptrace_user.o: ptrace_user.c
18 $(CC) -D__KERNEL__ $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< 18 $(CC) -D__KERNEL__ $(USER_CFLAGS) $(ccflags-y) -c -o $@ $<
19 19
20sigcontext.o: sigcontext.c 20sigcontext.o: sigcontext.c
21 $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< 21 $(CC) $(USER_CFLAGS) $(ccflags-y) -c -o $@ $<
22 22
23checksum.S: 23checksum.S:
24 rm -f $@ 24 rm -f $@
@@ -53,13 +53,13 @@ ppc_defs.h: mk_defs.c ppc_defs.head \
53checksum.o: checksum.S 53checksum.o: checksum.S
54 rm -f asm 54 rm -f asm
55 ln -s $(srctree)/include/asm-ppc asm 55 ln -s $(srctree)/include/asm-ppc asm
56 $(CC) $(EXTRA_AFLAGS) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o 56 $(CC) $(asflags-y) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
57 rm -f asm 57 rm -f asm
58 58
59misc.o: misc.S ppc_defs.h 59misc.o: misc.S ppc_defs.h
60 rm -f asm 60 rm -f asm
61 ln -s $(srctree)/include/asm-ppc asm 61 ln -s $(srctree)/include/asm-ppc asm
62 $(CC) $(EXTRA_AFLAGS) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o 62 $(CC) $(asflags-y) $(KBUILD_AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
63 rm -f asm 63 rm -f asm
64 64
65clean-files := $(OBJS) ppc_defs.h checksum.S mk_defs.c 65clean-files := $(OBJS) ppc_defs.h checksum.S mk_defs.c
diff --git a/arch/xtensa/boot/Makefile b/arch/xtensa/boot/Makefile
index 40aa55b485be..70fd1453e172 100644
--- a/arch/xtensa/boot/Makefile
+++ b/arch/xtensa/boot/Makefile
@@ -14,7 +14,7 @@ HOSTFLAGS += -Iarch/$(ARCH)/boot/include
14 14
15BIG_ENDIAN := $(shell echo -e __XTENSA_EB__ | $(CC) -E - | grep -v "\#") 15BIG_ENDIAN := $(shell echo -e __XTENSA_EB__ | $(CC) -E - | grep -v "\#")
16 16
17export EXTRA_CFLAGS 17export ccflags-y
18export BIG_ENDIAN 18export BIG_ENDIAN
19 19
20subdir-y := lib 20subdir-y := lib
diff --git a/arch/xtensa/boot/lib/Makefile b/arch/xtensa/boot/lib/Makefile
index d3d2aa2d883a..ad8952e8a07f 100644
--- a/arch/xtensa/boot/lib/Makefile
+++ b/arch/xtensa/boot/lib/Makefile
@@ -6,7 +6,7 @@ zlib := inffast.c inflate.c inftrees.c
6 6
7lib-y += $(zlib:.c=.o) zmem.o 7lib-y += $(zlib:.c=.o) zmem.o
8 8
9EXTRA_CFLAGS += -Ilib/zlib_inflate 9ccflags-y := -Ilib/zlib_inflate
10 10
11quiet_cmd_copy_zlib = COPY $@ 11quiet_cmd_copy_zlib = COPY $@
12 cmd_copy_zlib = cat $< > $@ 12 cmd_copy_zlib = cat $< > $@
diff --git a/drivers/char/mwave/Makefile b/drivers/char/mwave/Makefile
index 26b4fce217b6..efa6a82e543d 100644
--- a/drivers/char/mwave/Makefile
+++ b/drivers/char/mwave/Makefile
@@ -9,7 +9,7 @@ obj-$(CONFIG_MWAVE) += mwave.o
9mwave-y := mwavedd.o smapi.o tp3780i.o 3780i.o 9mwave-y := mwavedd.o smapi.o tp3780i.o 3780i.o
10 10
11# To have the mwave driver disable other uarts if necessary 11# To have the mwave driver disable other uarts if necessary
12# EXTRA_CFLAGS += -DMWAVE_FUTZ_WITH_OTHER_DEVICES 12# ccflags-y := -DMWAVE_FUTZ_WITH_OTHER_DEVICES
13 13
14# To compile in lots (~20 KiB) of run-time enablable printk()s for debugging: 14# To compile in lots (~20 KiB) of run-time enablable printk()s for debugging:
15ccflags-y := -DMW_TRACE 15ccflags-y += -DMW_TRACE
diff --git a/drivers/char/mwave/README b/drivers/char/mwave/README
index 480251fc78e2..c2a58f428bc8 100644
--- a/drivers/char/mwave/README
+++ b/drivers/char/mwave/README
@@ -11,7 +11,7 @@ are not saved by the BIOS and so do not persist after unload and reload.
11 0x0008 tp3780i tracing 11 0x0008 tp3780i tracing
12 12
13 Tracing only occurs if the driver has been compiled with the 13 Tracing only occurs if the driver has been compiled with the
14 MW_TRACE macro #defined (i.e. let EXTRA_CFLAGS += -DMW_TRACE 14 MW_TRACE macro #defined (i.e. let ccflags-y := -DMW_TRACE
15 in the Makefile). 15 in the Makefile).
16 16
17 mwave_3780i_irq=5/7/10/11/15 17 mwave_3780i_irq=5/7/10/11/15
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 64b21f5cd740..1be065a62f8c 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -1,9 +1,5 @@
1ifeq ($(CONFIG_DMADEVICES_DEBUG),y) 1ccflags-$(CONFIG_DMADEVICES_DEBUG) := -DDEBUG
2 ccflags-y += -DDEBUG 2ccflags-$(CONFIG_DMADEVICES_VDEBUG) += -DVERBOSE_DEBUG
3endif
4ifeq ($(CONFIG_DMADEVICES_VDEBUG),y)
5 ccflags-y += -DVERBOSE_DEBUG
6endif
7 3
8obj-$(CONFIG_DMA_ENGINE) += dmaengine.o 4obj-$(CONFIG_DMA_ENGINE) += dmaengine.o
9obj-$(CONFIG_NET_DMA) += iovlock.o 5obj-$(CONFIG_NET_DMA) += iovlock.o
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 61aa71233392..b85744fe8464 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -481,6 +481,12 @@ static const struct hid_device_id apple_devices[] = {
481 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 481 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), 482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
483 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 483 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
484 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
485 .driver_data = APPLE_HAS_FN },
486 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
487 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
488 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
489 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
484 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), 490 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
485 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 491 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
486 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), 492 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index c3d66269ed7d..e9687768a335 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1333,6 +1333,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 1334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1336 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 1339 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1337 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 1340 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1338 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1341 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
@@ -1840,6 +1843,9 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
1840 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 1843 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1841 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 1844 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1842 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 1845 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1846 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1847 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1848 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1843 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1849 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1844 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1850 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1845 { } 1851 { }
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index d485894ff4db..65ac53d7aecc 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -103,6 +103,9 @@
103#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 103#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
104#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 104#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
105#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244 105#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
106#define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245
107#define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246
108#define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247
106#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239 109#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
107#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a 110#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
108#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 111#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index cd74203c8178..33dde8724e02 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -900,8 +900,8 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
900 hid->ll_driver->hidinput_input_event; 900 hid->ll_driver->hidinput_input_event;
901 input_dev->open = hidinput_open; 901 input_dev->open = hidinput_open;
902 input_dev->close = hidinput_close; 902 input_dev->close = hidinput_close;
903 input_dev->setkeycode_new = hidinput_setkeycode; 903 input_dev->setkeycode = hidinput_setkeycode;
904 input_dev->getkeycode_new = hidinput_getkeycode; 904 input_dev->getkeycode = hidinput_getkeycode;
905 905
906 input_dev->name = hid->name; 906 input_dev->name = hid->name;
907 input_dev->phys = hid->phys; 907 input_dev->phys = hid->phys;
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index bd0410e4b44f..8a238dec5691 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -122,7 +122,5 @@ obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
122obj-$(CONFIG_SENSORS_MAX34440) += max34440.o 122obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
123obj-$(CONFIG_SENSORS_MAX8688) += max8688.o 123obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
124 124
125ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y) 125ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
126EXTRA_CFLAGS += -DDEBUG
127endif
128 126
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 23ac61e2db39..beee6b2d361d 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_I2C_MUX) += i2c-mux.o
10obj-y += algos/ busses/ muxes/ 10obj-y += algos/ busses/ muxes/
11 11
12ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG 12ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG
13CFLAGS_i2c-core.o := -Wno-deprecated-declarations
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 230601e8853f..ad415e6ec5a1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -98,8 +98,9 @@ config I2C_I801
98 EP80579 (Tolapai) 98 EP80579 (Tolapai)
99 ICH10 99 ICH10
100 5/3400 Series (PCH) 100 5/3400 Series (PCH)
101 Cougar Point (PCH) 101 6 Series (PCH)
102 Patsburg (PCH) 102 Patsburg (PCH)
103 DH89xxCC (PCH)
103 104
104 This driver can also be built as a module. If so, the module 105 This driver can also be built as a module. If so, the module
105 will be called i2c-i801. 106 will be called i2c-i801.
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7979aef7ee7b..ed2e0c5ea37c 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -44,11 +44,12 @@
44 ICH10 0x3a30 32 hard yes yes yes 44 ICH10 0x3a30 32 hard yes yes yes
45 ICH10 0x3a60 32 hard yes yes yes 45 ICH10 0x3a60 32 hard yes yes yes
46 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes 46 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
47 Cougar Point (PCH) 0x1c22 32 hard yes yes yes 47 6 Series (PCH) 0x1c22 32 hard yes yes yes
48 Patsburg (PCH) 0x1d22 32 hard yes yes yes 48 Patsburg (PCH) 0x1d22 32 hard yes yes yes
49 Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes 49 Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
50 Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes 50 Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
51 Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes 51 Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
52 DH89xxCC (PCH) 0x2330 32 hard yes yes yes
52 53
53 Features supported by this driver: 54 Features supported by this driver:
54 Software PEC no 55 Software PEC no
@@ -621,6 +622,7 @@ static const struct pci_device_id i801_ids[] = {
621 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) }, 622 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
622 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) }, 623 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
623 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) }, 624 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
625 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
624 { 0, } 626 { 0, }
625}; 627};
626 628
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c
index 7e6a63b57165..3ca2e012e789 100644
--- a/drivers/i2c/i2c-boardinfo.c
+++ b/drivers/i2c/i2c-boardinfo.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * i2c-boardinfo.h - collect pre-declarations of I2C devices 2 * i2c-boardinfo.c - collect pre-declarations of I2C devices
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 045ba6efea48..e5f76a0372fd 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -797,6 +797,9 @@ static int i2c_do_add_adapter(struct i2c_driver *driver,
797 797
798 /* Let legacy drivers scan this bus for matching devices */ 798 /* Let legacy drivers scan this bus for matching devices */
799 if (driver->attach_adapter) { 799 if (driver->attach_adapter) {
800 dev_warn(&adap->dev, "attach_adapter method is deprecated\n");
801 dev_warn(&adap->dev, "Please use another way to instantiate "
802 "your i2c_client\n");
800 /* We ignore the return code; if it fails, too bad */ 803 /* We ignore the return code; if it fails, too bad */
801 driver->attach_adapter(adap); 804 driver->attach_adapter(adap);
802 } 805 }
@@ -981,6 +984,7 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
981 984
982 if (!driver->detach_adapter) 985 if (!driver->detach_adapter)
983 return 0; 986 return 0;
987 dev_warn(&adapter->dev, "detach_adapter method is deprecated\n");
984 res = driver->detach_adapter(adapter); 988 res = driver->detach_adapter(adapter);
985 if (res) 989 if (res)
986 dev_err(&adapter->dev, "detach_adapter failed (%d) " 990 dev_err(&adapter->dev, "detach_adapter failed (%d) "
@@ -1091,6 +1095,18 @@ EXPORT_SYMBOL(i2c_del_adapter);
1091 1095
1092/* ------------------------------------------------------------------------- */ 1096/* ------------------------------------------------------------------------- */
1093 1097
1098int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *))
1099{
1100 int res;
1101
1102 mutex_lock(&core_lock);
1103 res = bus_for_each_dev(&i2c_bus_type, NULL, data, fn);
1104 mutex_unlock(&core_lock);
1105
1106 return res;
1107}
1108EXPORT_SYMBOL_GPL(i2c_for_each_dev);
1109
1094static int __process_new_driver(struct device *dev, void *data) 1110static int __process_new_driver(struct device *dev, void *data)
1095{ 1111{
1096 if (dev->type != &i2c_adapter_type) 1112 if (dev->type != &i2c_adapter_type)
@@ -1134,9 +1150,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
1134 1150
1135 INIT_LIST_HEAD(&driver->clients); 1151 INIT_LIST_HEAD(&driver->clients);
1136 /* Walk the adapters that are already present */ 1152 /* Walk the adapters that are already present */
1137 mutex_lock(&core_lock); 1153 i2c_for_each_dev(driver, __process_new_driver);
1138 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver);
1139 mutex_unlock(&core_lock);
1140 1154
1141 return 0; 1155 return 0;
1142} 1156}
@@ -1156,9 +1170,7 @@ static int __process_removed_driver(struct device *dev, void *data)
1156 */ 1170 */
1157void i2c_del_driver(struct i2c_driver *driver) 1171void i2c_del_driver(struct i2c_driver *driver)
1158{ 1172{
1159 mutex_lock(&core_lock); 1173 i2c_for_each_dev(driver, __process_removed_driver);
1160 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver);
1161 mutex_unlock(&core_lock);
1162 1174
1163 driver_unregister(&driver->driver); 1175 driver_unregister(&driver->driver);
1164 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 1176 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
@@ -1581,12 +1593,12 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1581} 1593}
1582EXPORT_SYMBOL_GPL(i2c_new_probed_device); 1594EXPORT_SYMBOL_GPL(i2c_new_probed_device);
1583 1595
1584struct i2c_adapter *i2c_get_adapter(int id) 1596struct i2c_adapter *i2c_get_adapter(int nr)
1585{ 1597{
1586 struct i2c_adapter *adapter; 1598 struct i2c_adapter *adapter;
1587 1599
1588 mutex_lock(&core_lock); 1600 mutex_lock(&core_lock);
1589 adapter = idr_find(&i2c_adapter_idr, id); 1601 adapter = idr_find(&i2c_adapter_idr, nr);
1590 if (adapter && !try_module_get(adapter->owner)) 1602 if (adapter && !try_module_get(adapter->owner))
1591 adapter = NULL; 1603 adapter = NULL;
1592 1604
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index cec0f3ba97f8..c90ce50b619f 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -28,6 +28,8 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/device.h>
32#include <linux/notifier.h>
31#include <linux/fs.h> 33#include <linux/fs.h>
32#include <linux/slab.h> 34#include <linux/slab.h>
33#include <linux/init.h> 35#include <linux/init.h>
@@ -37,16 +39,13 @@
37#include <linux/jiffies.h> 39#include <linux/jiffies.h>
38#include <linux/uaccess.h> 40#include <linux/uaccess.h>
39 41
40static struct i2c_driver i2cdev_driver;
41
42/* 42/*
43 * An i2c_dev represents an i2c_adapter ... an I2C or SMBus master, not a 43 * An i2c_dev represents an i2c_adapter ... an I2C or SMBus master, not a
44 * slave (i2c_client) with which messages will be exchanged. It's coupled 44 * slave (i2c_client) with which messages will be exchanged. It's coupled
45 * with a character special file which is accessed by user mode drivers. 45 * with a character special file which is accessed by user mode drivers.
46 * 46 *
47 * The list of i2c_dev structures is parallel to the i2c_adapter lists 47 * The list of i2c_dev structures is parallel to the i2c_adapter lists
48 * maintained by the driver model, and is updated using notifications 48 * maintained by the driver model, and is updated using bus notifications.
49 * delivered to the i2cdev_driver.
50 */ 49 */
51struct i2c_dev { 50struct i2c_dev {
52 struct list_head list; 51 struct list_head list;
@@ -491,7 +490,6 @@ static int i2cdev_open(struct inode *inode, struct file *file)
491 return -ENOMEM; 490 return -ENOMEM;
492 } 491 }
493 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 492 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
494 client->driver = &i2cdev_driver;
495 493
496 client->adapter = adap; 494 client->adapter = adap;
497 file->private_data = client; 495 file->private_data = client;
@@ -522,19 +520,18 @@ static const struct file_operations i2cdev_fops = {
522 520
523/* ------------------------------------------------------------------------- */ 521/* ------------------------------------------------------------------------- */
524 522
525/*
526 * The legacy "i2cdev_driver" is used primarily to get notifications when
527 * I2C adapters are added or removed, so that each one gets an i2c_dev
528 * and is thus made available to userspace driver code.
529 */
530
531static struct class *i2c_dev_class; 523static struct class *i2c_dev_class;
532 524
533static int i2cdev_attach_adapter(struct i2c_adapter *adap) 525static int i2cdev_attach_adapter(struct device *dev, void *dummy)
534{ 526{
527 struct i2c_adapter *adap;
535 struct i2c_dev *i2c_dev; 528 struct i2c_dev *i2c_dev;
536 int res; 529 int res;
537 530
531 if (dev->type != &i2c_adapter_type)
532 return 0;
533 adap = to_i2c_adapter(dev);
534
538 i2c_dev = get_free_i2c_dev(adap); 535 i2c_dev = get_free_i2c_dev(adap);
539 if (IS_ERR(i2c_dev)) 536 if (IS_ERR(i2c_dev))
540 return PTR_ERR(i2c_dev); 537 return PTR_ERR(i2c_dev);
@@ -561,10 +558,15 @@ error:
561 return res; 558 return res;
562} 559}
563 560
564static int i2cdev_detach_adapter(struct i2c_adapter *adap) 561static int i2cdev_detach_adapter(struct device *dev, void *dummy)
565{ 562{
563 struct i2c_adapter *adap;
566 struct i2c_dev *i2c_dev; 564 struct i2c_dev *i2c_dev;
567 565
566 if (dev->type != &i2c_adapter_type)
567 return 0;
568 adap = to_i2c_adapter(dev);
569
568 i2c_dev = i2c_dev_get_by_minor(adap->nr); 570 i2c_dev = i2c_dev_get_by_minor(adap->nr);
569 if (!i2c_dev) /* attach_adapter must have failed */ 571 if (!i2c_dev) /* attach_adapter must have failed */
570 return 0; 572 return 0;
@@ -577,12 +579,23 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
577 return 0; 579 return 0;
578} 580}
579 581
580static struct i2c_driver i2cdev_driver = { 582int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
581 .driver = { 583 void *data)
582 .name = "dev_driver", 584{
583 }, 585 struct device *dev = data;
584 .attach_adapter = i2cdev_attach_adapter, 586
585 .detach_adapter = i2cdev_detach_adapter, 587 switch (action) {
588 case BUS_NOTIFY_ADD_DEVICE:
589 return i2cdev_attach_adapter(dev, NULL);
590 case BUS_NOTIFY_DEL_DEVICE:
591 return i2cdev_detach_adapter(dev, NULL);
592 }
593
594 return 0;
595}
596
597static struct notifier_block i2cdev_notifier = {
598 .notifier_call = i2cdev_notifier_call,
586}; 599};
587 600
588/* ------------------------------------------------------------------------- */ 601/* ------------------------------------------------------------------------- */
@@ -607,10 +620,14 @@ static int __init i2c_dev_init(void)
607 goto out_unreg_chrdev; 620 goto out_unreg_chrdev;
608 } 621 }
609 622
610 res = i2c_add_driver(&i2cdev_driver); 623 /* Keep track of adapters which will be added or removed later */
624 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
611 if (res) 625 if (res)
612 goto out_unreg_class; 626 goto out_unreg_class;
613 627
628 /* Bind to already existing adapters right away */
629 i2c_for_each_dev(NULL, i2cdev_attach_adapter);
630
614 return 0; 631 return 0;
615 632
616out_unreg_class: 633out_unreg_class:
@@ -624,7 +641,8 @@ out:
624 641
625static void __exit i2c_dev_exit(void) 642static void __exit i2c_dev_exit(void)
626{ 643{
627 i2c_del_driver(&i2cdev_driver); 644 bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier);
645 i2c_for_each_dev(NULL, i2cdev_detach_adapter);
628 class_destroy(i2c_dev_class); 646 class_destroy(i2c_dev_class);
629 unregister_chrdev(I2C_MAJOR, "i2c"); 647 unregister_chrdev(I2C_MAJOR, "i2c");
630} 648}
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 81df925f0e8b..7f879b2397b0 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -2,7 +2,7 @@
2# link order is important here 2# link order is important here
3# 3#
4 4
5EXTRA_CFLAGS += -Idrivers/ide 5ccflags-y := -Idrivers/ide
6 6
7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-taskfile.o ide-pm.o ide-park.o ide-sysfs.o ide-devsets.o \ 8 ide-taskfile.o ide-pm.o ide-park.o ide-sysfs.o ide-devsets.o \
diff --git a/drivers/ieee802154/Makefile b/drivers/ieee802154/Makefile
index e0e8e1a184ff..68999137dedf 100644
--- a/drivers/ieee802154/Makefile
+++ b/drivers/ieee802154/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o 1obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o
2 2
3EXTRA_CFLAGS += -DDEBUG -DCONFIG_FFD 3ccflags-y := -DDEBUG -DCONFIG_FFD
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1903c0f5b925..23e82e46656d 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -161,16 +161,6 @@ config INPUT_APMPOWER
161 To compile this driver as a module, choose M here: the 161 To compile this driver as a module, choose M here: the
162 module will be called apm-power. 162 module will be called apm-power.
163 163
164config XEN_KBDDEV_FRONTEND
165 tristate "Xen virtual keyboard and mouse support"
166 depends on XEN_FBDEV_FRONTEND
167 default y
168 select XEN_XENBUS_FRONTEND
169 help
170 This driver implements the front-end of the Xen virtual
171 keyboard and mouse device driver. It communicates with a back-end
172 in another domain.
173
174comment "Input Device Drivers" 164comment "Input Device Drivers"
175 165
176source "drivers/input/keyboard/Kconfig" 166source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 09614ce74961..0c789490e0b3 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -24,5 +24,3 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
24obj-$(CONFIG_INPUT_MISC) += misc/ 24obj-$(CONFIG_INPUT_MISC) += misc/
25 25
26obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o 26obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
27
28obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index c8471a2552e7..7f42d3a454d2 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -321,6 +321,9 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
321 struct input_event event; 321 struct input_event event;
322 int retval; 322 int retval;
323 323
324 if (count < input_event_size())
325 return -EINVAL;
326
324 retval = mutex_lock_interruptible(&evdev->mutex); 327 retval = mutex_lock_interruptible(&evdev->mutex);
325 if (retval) 328 if (retval)
326 return retval; 329 return retval;
@@ -330,17 +333,16 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
330 goto out; 333 goto out;
331 } 334 }
332 335
333 while (retval < count) { 336 do {
334
335 if (input_event_from_user(buffer + retval, &event)) { 337 if (input_event_from_user(buffer + retval, &event)) {
336 retval = -EFAULT; 338 retval = -EFAULT;
337 goto out; 339 goto out;
338 } 340 }
341 retval += input_event_size();
339 342
340 input_inject_event(&evdev->handle, 343 input_inject_event(&evdev->handle,
341 event.type, event.code, event.value); 344 event.type, event.code, event.value);
342 retval += input_event_size(); 345 } while (retval + input_event_size() <= count);
343 }
344 346
345 out: 347 out:
346 mutex_unlock(&evdev->mutex); 348 mutex_unlock(&evdev->mutex);
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index 0559e309bac9..3037842a60d8 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -192,7 +192,7 @@ static struct attribute_group input_polldev_attribute_group = {
192}; 192};
193 193
194/** 194/**
195 * input_allocate_polled_device - allocated memory polled device 195 * input_allocate_polled_device - allocate memory for polled device
196 * 196 *
197 * The function allocates memory for a polled device and also 197 * The function allocates memory for a polled device and also
198 * for an input device associated with this polled device. 198 * for an input device associated with this polled device.
@@ -239,7 +239,7 @@ EXPORT_SYMBOL(input_free_polled_device);
239 * with input layer. The device should be allocated with call to 239 * with input layer. The device should be allocated with call to
240 * input_allocate_polled_device(). Callers should also set up poll() 240 * input_allocate_polled_device(). Callers should also set up poll()
241 * method and set up capabilities (id, name, phys, bits) of the 241 * method and set up capabilities (id, name, phys, bits) of the
242 * corresponing input_dev structure. 242 * corresponding input_dev structure.
243 */ 243 */
244int input_register_polled_device(struct input_polled_dev *dev) 244int input_register_polled_device(struct input_polled_dev *dev)
245{ 245{
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 11905b6a3023..d6e8bd8a851c 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -791,22 +791,9 @@ int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke)
791 int retval; 791 int retval;
792 792
793 spin_lock_irqsave(&dev->event_lock, flags); 793 spin_lock_irqsave(&dev->event_lock, flags);
794 794 retval = dev->getkeycode(dev, ke);
795 if (dev->getkeycode) {
796 /*
797 * Support for legacy drivers, that don't implement the new
798 * ioctls
799 */
800 u32 scancode = ke->index;
801
802 memcpy(ke->scancode, &scancode, sizeof(scancode));
803 ke->len = sizeof(scancode);
804 retval = dev->getkeycode(dev, scancode, &ke->keycode);
805 } else {
806 retval = dev->getkeycode_new(dev, ke);
807 }
808
809 spin_unlock_irqrestore(&dev->event_lock, flags); 795 spin_unlock_irqrestore(&dev->event_lock, flags);
796
810 return retval; 797 return retval;
811} 798}
812EXPORT_SYMBOL(input_get_keycode); 799EXPORT_SYMBOL(input_get_keycode);
@@ -831,35 +818,7 @@ int input_set_keycode(struct input_dev *dev,
831 818
832 spin_lock_irqsave(&dev->event_lock, flags); 819 spin_lock_irqsave(&dev->event_lock, flags);
833 820
834 if (dev->setkeycode) { 821 retval = dev->setkeycode(dev, ke, &old_keycode);
835 /*
836 * Support for legacy drivers, that don't implement the new
837 * ioctls
838 */
839 unsigned int scancode;
840
841 retval = input_scancode_to_scalar(ke, &scancode);
842 if (retval)
843 goto out;
844
845 /*
846 * We need to know the old scancode, in order to generate a
847 * keyup effect, if the set operation happens successfully
848 */
849 if (!dev->getkeycode) {
850 retval = -EINVAL;
851 goto out;
852 }
853
854 retval = dev->getkeycode(dev, scancode, &old_keycode);
855 if (retval)
856 goto out;
857
858 retval = dev->setkeycode(dev, scancode, ke->keycode);
859 } else {
860 retval = dev->setkeycode_new(dev, ke, &old_keycode);
861 }
862
863 if (retval) 822 if (retval)
864 goto out; 823 goto out;
865 824
@@ -1846,11 +1805,11 @@ int input_register_device(struct input_dev *dev)
1846 dev->rep[REP_PERIOD] = 33; 1805 dev->rep[REP_PERIOD] = 33;
1847 } 1806 }
1848 1807
1849 if (!dev->getkeycode && !dev->getkeycode_new) 1808 if (!dev->getkeycode)
1850 dev->getkeycode_new = input_default_getkeycode; 1809 dev->getkeycode = input_default_getkeycode;
1851 1810
1852 if (!dev->setkeycode && !dev->setkeycode_new) 1811 if (!dev->setkeycode)
1853 dev->setkeycode_new = input_default_setkeycode; 1812 dev->setkeycode = input_default_setkeycode;
1854 1813
1855 dev_set_name(&dev->dev, "input%ld", 1814 dev_set_name(&dev->dev, "input%ld",
1856 (unsigned long) atomic_inc_return(&input_no) - 1); 1815 (unsigned long) atomic_inc_return(&input_no) - 1);
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index c7a92028f450..b16bed038f72 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -112,6 +112,16 @@ config KEYBOARD_ATKBD_RDI_KEYCODES
112 right-hand column will be interpreted as the key shown in the 112 right-hand column will be interpreted as the key shown in the
113 left-hand column. 113 left-hand column.
114 114
115config KEYBOARD_QT1070
116 tristate "Atmel AT42QT1070 Touch Sensor Chip"
117 depends on I2C
118 help
119 Say Y here if you want to use Atmel AT42QT1070 QTouch
120 Sensor chip as input device.
121
122 To compile this driver as a module, choose M here:
123 the module will be called qt1070
124
115config KEYBOARD_QT2160 125config KEYBOARD_QT2160
116 tristate "Atmel AT42QT2160 Touch Sensor Chip" 126 tristate "Atmel AT42QT2160 Touch Sensor Chip"
117 depends on I2C && EXPERIMENTAL 127 depends on I2C && EXPERIMENTAL
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 468c627a2844..878e6c20deb0 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o
34obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o 34obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o
35obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o 35obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o
36obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o 36obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
37obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o
37obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 38obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o
38obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o 39obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o
39obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o 40obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index f7c2a166576b..b732870ecc89 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -30,6 +30,7 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/leds.h> 32#include <linux/leds.h>
33#include <linux/pm.h>
33#include <linux/i2c/lm8323.h> 34#include <linux/i2c/lm8323.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35 36
@@ -802,8 +803,9 @@ static int __devexit lm8323_remove(struct i2c_client *client)
802 * We don't need to explicitly suspend the chip, as it already switches off 803 * We don't need to explicitly suspend the chip, as it already switches off
803 * when there's no activity. 804 * when there's no activity.
804 */ 805 */
805static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg) 806static int lm8323_suspend(struct device *dev)
806{ 807{
808 struct i2c_client *client = to_i2c_client(dev);
807 struct lm8323_chip *lm = i2c_get_clientdata(client); 809 struct lm8323_chip *lm = i2c_get_clientdata(client);
808 int i; 810 int i;
809 811
@@ -821,8 +823,9 @@ static int lm8323_suspend(struct i2c_client *client, pm_message_t mesg)
821 return 0; 823 return 0;
822} 824}
823 825
824static int lm8323_resume(struct i2c_client *client) 826static int lm8323_resume(struct device *dev)
825{ 827{
828 struct i2c_client *client = to_i2c_client(dev);
826 struct lm8323_chip *lm = i2c_get_clientdata(client); 829 struct lm8323_chip *lm = i2c_get_clientdata(client);
827 int i; 830 int i;
828 831
@@ -839,11 +842,10 @@ static int lm8323_resume(struct i2c_client *client)
839 842
840 return 0; 843 return 0;
841} 844}
842#else
843#define lm8323_suspend NULL
844#define lm8323_resume NULL
845#endif 845#endif
846 846
847static SIMPLE_DEV_PM_OPS(lm8323_pm_ops, lm8323_suspend, lm8323_resume);
848
847static const struct i2c_device_id lm8323_id[] = { 849static const struct i2c_device_id lm8323_id[] = {
848 { "lm8323", 0 }, 850 { "lm8323", 0 },
849 { } 851 { }
@@ -852,11 +854,10 @@ static const struct i2c_device_id lm8323_id[] = {
852static struct i2c_driver lm8323_i2c_driver = { 854static struct i2c_driver lm8323_i2c_driver = {
853 .driver = { 855 .driver = {
854 .name = "lm8323", 856 .name = "lm8323",
857 .pm = &lm8323_pm_ops,
855 }, 858 },
856 .probe = lm8323_probe, 859 .probe = lm8323_probe,
857 .remove = __devexit_p(lm8323_remove), 860 .remove = __devexit_p(lm8323_remove),
858 .suspend = lm8323_suspend,
859 .resume = lm8323_resume,
860 .id_table = lm8323_id, 861 .id_table = lm8323_id,
861}; 862};
862MODULE_DEVICE_TABLE(i2c, lm8323_id); 863MODULE_DEVICE_TABLE(i2c, lm8323_id);
diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c
index 9091ff5ea808..5afe35ad24d3 100644
--- a/drivers/input/keyboard/max7359_keypad.c
+++ b/drivers/input/keyboard/max7359_keypad.c
@@ -17,6 +17,7 @@
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/pm.h>
20#include <linux/input.h> 21#include <linux/input.h>
21#include <linux/input/matrix_keypad.h> 22#include <linux/input/matrix_keypad.h>
22 23
@@ -271,8 +272,10 @@ static int __devexit max7359_remove(struct i2c_client *client)
271} 272}
272 273
273#ifdef CONFIG_PM 274#ifdef CONFIG_PM
274static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) 275static int max7359_suspend(struct device *dev)
275{ 276{
277 struct i2c_client *client = to_i2c_client(dev);
278
276 max7359_fall_deepsleep(client); 279 max7359_fall_deepsleep(client);
277 280
278 if (device_may_wakeup(&client->dev)) 281 if (device_may_wakeup(&client->dev))
@@ -281,8 +284,10 @@ static int max7359_suspend(struct i2c_client *client, pm_message_t mesg)
281 return 0; 284 return 0;
282} 285}
283 286
284static int max7359_resume(struct i2c_client *client) 287static int max7359_resume(struct device *dev)
285{ 288{
289 struct i2c_client *client = to_i2c_client(dev);
290
286 if (device_may_wakeup(&client->dev)) 291 if (device_may_wakeup(&client->dev))
287 disable_irq_wake(client->irq); 292 disable_irq_wake(client->irq);
288 293
@@ -291,11 +296,10 @@ static int max7359_resume(struct i2c_client *client)
291 296
292 return 0; 297 return 0;
293} 298}
294#else
295#define max7359_suspend NULL
296#define max7359_resume NULL
297#endif 299#endif
298 300
301static SIMPLE_DEV_PM_OPS(max7359_pm, max7359_suspend, max7359_resume);
302
299static const struct i2c_device_id max7359_ids[] = { 303static const struct i2c_device_id max7359_ids[] = {
300 { "max7359", 0 }, 304 { "max7359", 0 },
301 { } 305 { }
@@ -305,11 +309,10 @@ MODULE_DEVICE_TABLE(i2c, max7359_ids);
305static struct i2c_driver max7359_i2c_driver = { 309static struct i2c_driver max7359_i2c_driver = {
306 .driver = { 310 .driver = {
307 .name = "max7359", 311 .name = "max7359",
312 .pm = &max7359_pm,
308 }, 313 },
309 .probe = max7359_probe, 314 .probe = max7359_probe,
310 .remove = __devexit_p(max7359_remove), 315 .remove = __devexit_p(max7359_remove),
311 .suspend = max7359_suspend,
312 .resume = max7359_resume,
313 .id_table = max7359_ids, 316 .id_table = max7359_ids,
314}; 317};
315 318
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 63b849d7e90b..af1aab324a4c 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller 2 * Touchkey driver for MELFAS MCS5000/5080 controller
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: HeungJun Kim <riverful.kim@samsung.com> 5 * Author: HeungJun Kim <riverful.kim@samsung.com>
@@ -19,6 +19,7 @@
19#include <linux/input.h> 19#include <linux/input.h>
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/pm.h>
22 23
23/* MCS5000 Touchkey */ 24/* MCS5000 Touchkey */
24#define MCS5000_TOUCHKEY_STATUS 0x04 25#define MCS5000_TOUCHKEY_STATUS 0x04
@@ -45,6 +46,8 @@ struct mcs_touchkey_chip {
45}; 46};
46 47
47struct mcs_touchkey_data { 48struct mcs_touchkey_data {
49 void (*poweron)(bool);
50
48 struct i2c_client *client; 51 struct i2c_client *client;
49 struct input_dev *input_dev; 52 struct input_dev *input_dev;
50 struct mcs_touchkey_chip chip; 53 struct mcs_touchkey_chip chip;
@@ -169,6 +172,11 @@ static int __devinit mcs_touchkey_probe(struct i2c_client *client,
169 if (pdata->cfg_pin) 172 if (pdata->cfg_pin)
170 pdata->cfg_pin(); 173 pdata->cfg_pin();
171 174
175 if (pdata->poweron) {
176 data->poweron = pdata->poweron;
177 data->poweron(true);
178 }
179
172 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, 180 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
173 IRQF_TRIGGER_FALLING, client->dev.driver->name, data); 181 IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
174 if (error) { 182 if (error) {
@@ -196,12 +204,57 @@ static int __devexit mcs_touchkey_remove(struct i2c_client *client)
196 struct mcs_touchkey_data *data = i2c_get_clientdata(client); 204 struct mcs_touchkey_data *data = i2c_get_clientdata(client);
197 205
198 free_irq(client->irq, data); 206 free_irq(client->irq, data);
207 if (data->poweron)
208 data->poweron(false);
199 input_unregister_device(data->input_dev); 209 input_unregister_device(data->input_dev);
200 kfree(data); 210 kfree(data);
201 211
202 return 0; 212 return 0;
203} 213}
204 214
215static void mcs_touchkey_shutdown(struct i2c_client *client)
216{
217 struct mcs_touchkey_data *data = i2c_get_clientdata(client);
218
219 if (data->poweron)
220 data->poweron(false);
221}
222
223#ifdef CONFIG_PM_SLEEP
224static int mcs_touchkey_suspend(struct device *dev)
225{
226 struct mcs_touchkey_data *data = dev_get_drvdata(dev);
227 struct i2c_client *client = data->client;
228
229 /* Disable the work */
230 disable_irq(client->irq);
231
232 /* Finally turn off the power */
233 if (data->poweron)
234 data->poweron(false);
235
236 return 0;
237}
238
239static int mcs_touchkey_resume(struct device *dev)
240{
241 struct mcs_touchkey_data *data = dev_get_drvdata(dev);
242 struct i2c_client *client = data->client;
243
244 /* Enable the device first */
245 if (data->poweron)
246 data->poweron(true);
247
248 /* Enable irq again */
249 enable_irq(client->irq);
250
251 return 0;
252}
253#endif
254
255static SIMPLE_DEV_PM_OPS(mcs_touchkey_pm_ops,
256 mcs_touchkey_suspend, mcs_touchkey_resume);
257
205static const struct i2c_device_id mcs_touchkey_id[] = { 258static const struct i2c_device_id mcs_touchkey_id[] = {
206 { "mcs5000_touchkey", MCS5000_TOUCHKEY }, 259 { "mcs5000_touchkey", MCS5000_TOUCHKEY },
207 { "mcs5080_touchkey", MCS5080_TOUCHKEY }, 260 { "mcs5080_touchkey", MCS5080_TOUCHKEY },
@@ -213,9 +266,11 @@ static struct i2c_driver mcs_touchkey_driver = {
213 .driver = { 266 .driver = {
214 .name = "mcs_touchkey", 267 .name = "mcs_touchkey",
215 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
269 .pm = &mcs_touchkey_pm_ops,
216 }, 270 },
217 .probe = mcs_touchkey_probe, 271 .probe = mcs_touchkey_probe,
218 .remove = __devexit_p(mcs_touchkey_remove), 272 .remove = __devexit_p(mcs_touchkey_remove),
273 .shutdown = mcs_touchkey_shutdown,
219 .id_table = mcs_touchkey_id, 274 .id_table = mcs_touchkey_id,
220}; 275};
221 276
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index 45bd0977d006..c51a3c4a7feb 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -29,6 +29,7 @@
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/input.h> 30#include <linux/input.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/pm_runtime.h>
32 33
33#include <plat/omap4-keypad.h> 34#include <plat/omap4-keypad.h>
34 35
@@ -80,20 +81,6 @@ struct omap4_keypad {
80 unsigned short keymap[]; 81 unsigned short keymap[];
81}; 82};
82 83
83static void __devinit omap4_keypad_config(struct omap4_keypad *keypad_data)
84{
85 __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
86 keypad_data->base + OMAP4_KBD_CTRL);
87 __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
88 keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
89 __raw_writel(OMAP4_VAL_IRQDISABLE,
90 keypad_data->base + OMAP4_KBD_IRQSTATUS);
91 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
92 keypad_data->base + OMAP4_KBD_IRQENABLE);
93 __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
94 keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
95}
96
97/* Interrupt handler */ 84/* Interrupt handler */
98static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) 85static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
99{ 86{
@@ -144,6 +131,49 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
144 return IRQ_HANDLED; 131 return IRQ_HANDLED;
145} 132}
146 133
134static int omap4_keypad_open(struct input_dev *input)
135{
136 struct omap4_keypad *keypad_data = input_get_drvdata(input);
137
138 pm_runtime_get_sync(input->dev.parent);
139
140 disable_irq(keypad_data->irq);
141
142 __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
143 keypad_data->base + OMAP4_KBD_CTRL);
144 __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
145 keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
146 __raw_writel(OMAP4_VAL_IRQDISABLE,
147 keypad_data->base + OMAP4_KBD_IRQSTATUS);
148 __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
149 keypad_data->base + OMAP4_KBD_IRQENABLE);
150 __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
151 keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
152
153 enable_irq(keypad_data->irq);
154
155 return 0;
156}
157
158static void omap4_keypad_close(struct input_dev *input)
159{
160 struct omap4_keypad *keypad_data = input_get_drvdata(input);
161
162 disable_irq(keypad_data->irq);
163
164 /* Disable interrupts */
165 __raw_writel(OMAP4_VAL_IRQDISABLE,
166 keypad_data->base + OMAP4_KBD_IRQENABLE);
167
168 /* clear pending interrupts */
169 __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
170 keypad_data->base + OMAP4_KBD_IRQSTATUS);
171
172 enable_irq(keypad_data->irq);
173
174 pm_runtime_put_sync(input->dev.parent);
175}
176
147static int __devinit omap4_keypad_probe(struct platform_device *pdev) 177static int __devinit omap4_keypad_probe(struct platform_device *pdev)
148{ 178{
149 const struct omap4_keypad_platform_data *pdata; 179 const struct omap4_keypad_platform_data *pdata;
@@ -225,6 +255,9 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
225 input_dev->id.product = 0x0001; 255 input_dev->id.product = 0x0001;
226 input_dev->id.version = 0x0001; 256 input_dev->id.version = 0x0001;
227 257
258 input_dev->open = omap4_keypad_open;
259 input_dev->close = omap4_keypad_close;
260
228 input_dev->keycode = keypad_data->keymap; 261 input_dev->keycode = keypad_data->keymap;
229 input_dev->keycodesize = sizeof(keypad_data->keymap[0]); 262 input_dev->keycodesize = sizeof(keypad_data->keymap[0]);
230 input_dev->keycodemax = max_keys; 263 input_dev->keycodemax = max_keys;
@@ -239,8 +272,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
239 matrix_keypad_build_keymap(pdata->keymap_data, row_shift, 272 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
240 input_dev->keycode, input_dev->keybit); 273 input_dev->keycode, input_dev->keybit);
241 274
242 omap4_keypad_config(keypad_data);
243
244 error = request_irq(keypad_data->irq, omap4_keypad_interrupt, 275 error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
245 IRQF_TRIGGER_RISING, 276 IRQF_TRIGGER_RISING,
246 "omap4-keypad", keypad_data); 277 "omap4-keypad", keypad_data);
@@ -249,17 +280,19 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
249 goto err_free_input; 280 goto err_free_input;
250 } 281 }
251 282
283 pm_runtime_enable(&pdev->dev);
284
252 error = input_register_device(keypad_data->input); 285 error = input_register_device(keypad_data->input);
253 if (error < 0) { 286 if (error < 0) {
254 dev_err(&pdev->dev, "failed to register input device\n"); 287 dev_err(&pdev->dev, "failed to register input device\n");
255 goto err_free_irq; 288 goto err_pm_disable;
256 } 289 }
257 290
258
259 platform_set_drvdata(pdev, keypad_data); 291 platform_set_drvdata(pdev, keypad_data);
260 return 0; 292 return 0;
261 293
262err_free_irq: 294err_pm_disable:
295 pm_runtime_disable(&pdev->dev);
263 free_irq(keypad_data->irq, keypad_data); 296 free_irq(keypad_data->irq, keypad_data);
264err_free_input: 297err_free_input:
265 input_free_device(input_dev); 298 input_free_device(input_dev);
@@ -278,6 +311,9 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
278 struct resource *res; 311 struct resource *res;
279 312
280 free_irq(keypad_data->irq, keypad_data); 313 free_irq(keypad_data->irq, keypad_data);
314
315 pm_runtime_disable(&pdev->dev);
316
281 input_unregister_device(keypad_data->input); 317 input_unregister_device(keypad_data->input);
282 318
283 iounmap(keypad_data->base); 319 iounmap(keypad_data->base);
diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c
new file mode 100644
index 000000000000..fba8404c7297
--- /dev/null
+++ b/drivers/input/keyboard/qt1070.c
@@ -0,0 +1,276 @@
1/*
2 * Atmel AT42QT1070 QTouch Sensor Controller
3 *
4 * Copyright (C) 2011 Atmel
5 *
6 * Authors: Bo Shen <voice.shen@atmel.com>
7 *
8 * Base on AT42QT2160 driver by:
9 * Raphael Derosso Pereira <raphaelpereira@gmail.com>
10 * Copyright (C) 2009
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/i2c.h>
30#include <linux/input.h>
31#include <linux/slab.h>
32#include <linux/irq.h>
33#include <linux/interrupt.h>
34#include <linux/jiffies.h>
35#include <linux/delay.h>
36
37/* Address for each register */
38#define CHIP_ID 0x00
39#define QT1070_CHIP_ID 0x2E
40
41#define FW_VERSION 0x01
42#define QT1070_FW_VERSION 0x15
43
44#define DET_STATUS 0x02
45
46#define KEY_STATUS 0x03
47
48/* Calibrate */
49#define CALIBRATE_CMD 0x38
50#define QT1070_CAL_TIME 200
51
52/* Reset */
53#define RESET 0x39
54#define QT1070_RESET_TIME 255
55
56/* AT42QT1070 support up to 7 keys */
57static const unsigned short qt1070_key2code[] = {
58 KEY_0, KEY_1, KEY_2, KEY_3,
59 KEY_4, KEY_5, KEY_6,
60};
61
62struct qt1070_data {
63 struct i2c_client *client;
64 struct input_dev *input;
65 unsigned int irq;
66 unsigned short keycodes[ARRAY_SIZE(qt1070_key2code)];
67 u8 last_keys;
68};
69
70static int qt1070_read(struct i2c_client *client, u8 reg)
71{
72 int ret;
73
74 ret = i2c_smbus_read_byte_data(client, reg);
75 if (ret < 0)
76 dev_err(&client->dev,
77 "can not read register, returned %d\n", ret);
78
79 return ret;
80}
81
82static int qt1070_write(struct i2c_client *client, u8 reg, u8 data)
83{
84 int ret;
85
86 ret = i2c_smbus_write_byte_data(client, reg, data);
87 if (ret < 0)
88 dev_err(&client->dev,
89 "can not write register, returned %d\n", ret);
90
91 return ret;
92}
93
94static bool __devinit qt1070_identify(struct i2c_client *client)
95{
96 int id, ver;
97
98 /* Read Chip ID */
99 id = qt1070_read(client, CHIP_ID);
100 if (id != QT1070_CHIP_ID) {
101 dev_err(&client->dev, "ID %d not supported\n", id);
102 return false;
103 }
104
105 /* Read firmware version */
106 ver = qt1070_read(client, FW_VERSION);
107 if (ver < 0) {
108 dev_err(&client->dev, "could not read the firmware version\n");
109 return false;
110 }
111
112 dev_info(&client->dev, "AT42QT1070 firmware version %x\n", ver);
113
114 return true;
115}
116
117static irqreturn_t qt1070_interrupt(int irq, void *dev_id)
118{
119 struct qt1070_data *data = dev_id;
120 struct i2c_client *client = data->client;
121 struct input_dev *input = data->input;
122 int i;
123 u8 new_keys, keyval, mask = 0x01;
124
125 /* Read the detected status register, thus clearing interrupt */
126 qt1070_read(client, DET_STATUS);
127
128 /* Read which key changed */
129 new_keys = qt1070_read(client, KEY_STATUS);
130
131 for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
132 keyval = new_keys & mask;
133 if ((data->last_keys & mask) != keyval)
134 input_report_key(input, data->keycodes[i], keyval);
135 mask <<= 1;
136 }
137 input_sync(input);
138
139 data->last_keys = new_keys;
140 return IRQ_HANDLED;
141}
142
143static int __devinit qt1070_probe(struct i2c_client *client,
144 const struct i2c_device_id *id)
145{
146 struct qt1070_data *data;
147 struct input_dev *input;
148 int i;
149 int err;
150
151 err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE);
152 if (!err) {
153 dev_err(&client->dev, "%s adapter not supported\n",
154 dev_driver_string(&client->adapter->dev));
155 return -ENODEV;
156 }
157
158 if (!client->irq) {
159 dev_err(&client->dev, "please assign the irq to this device\n");
160 return -EINVAL;
161 }
162
163 /* Identify the qt1070 chip */
164 if (!qt1070_identify(client))
165 return -ENODEV;
166
167 data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
168 input = input_allocate_device();
169 if (!data || !input) {
170 dev_err(&client->dev, "insufficient memory\n");
171 err = -ENOMEM;
172 goto err_free_mem;
173 }
174
175 data->client = client;
176 data->input = input;
177 data->irq = client->irq;
178
179 input->name = "AT42QT1070 QTouch Sensor";
180 input->dev.parent = &client->dev;
181 input->id.bustype = BUS_I2C;
182
183 /* Add the keycode */
184 input->keycode = data->keycodes;
185 input->keycodesize = sizeof(data->keycodes[0]);
186 input->keycodemax = ARRAY_SIZE(qt1070_key2code);
187
188 __set_bit(EV_KEY, input->evbit);
189
190 for (i = 0; i < ARRAY_SIZE(qt1070_key2code); i++) {
191 data->keycodes[i] = qt1070_key2code[i];
192 __set_bit(qt1070_key2code[i], input->keybit);
193 }
194
195 /* Calibrate device */
196 qt1070_write(client, CALIBRATE_CMD, 1);
197 msleep(QT1070_CAL_TIME);
198
199 /* Soft reset */
200 qt1070_write(client, RESET, 1);
201 msleep(QT1070_RESET_TIME);
202
203 err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
204 IRQF_TRIGGER_NONE, client->dev.driver->name, data);
205 if (err) {
206 dev_err(&client->dev, "fail to request irq\n");
207 goto err_free_mem;
208 }
209
210 /* Register the input device */
211 err = input_register_device(data->input);
212 if (err) {
213 dev_err(&client->dev, "Failed to register input device\n");
214 goto err_free_irq;
215 }
216
217 i2c_set_clientdata(client, data);
218
219 /* Read to clear the chang line */
220 qt1070_read(client, DET_STATUS);
221
222 return 0;
223
224err_free_irq:
225 free_irq(client->irq, data);
226err_free_mem:
227 input_free_device(input);
228 kfree(data);
229 return err;
230}
231
232static int __devexit qt1070_remove(struct i2c_client *client)
233{
234 struct qt1070_data *data = i2c_get_clientdata(client);
235
236 /* Release IRQ */
237 free_irq(client->irq, data);
238
239 input_unregister_device(data->input);
240 kfree(data);
241
242 i2c_set_clientdata(client, NULL);
243
244 return 0;
245}
246
247static const struct i2c_device_id qt1070_id[] = {
248 { "qt1070", 0 },
249 { },
250};
251
252static struct i2c_driver qt1070_driver = {
253 .driver = {
254 .name = "qt1070",
255 .owner = THIS_MODULE,
256 },
257 .id_table = qt1070_id,
258 .probe = qt1070_probe,
259 .remove = __devexit_p(qt1070_remove),
260};
261
262static int __init qt1070_init(void)
263{
264 return i2c_add_driver(&qt1070_driver);
265}
266module_init(qt1070_init);
267
268static void __exit qt1070_exit(void)
269{
270 i2c_del_driver(&qt1070_driver);
271}
272module_exit(qt1070_exit);
273
274MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
275MODULE_DESCRIPTION("Driver for AT42QT1070 QTouch sensor");
276MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c
index dbbe761778d2..99122f59e988 100644
--- a/drivers/input/keyboard/tc3589x-keypad.c
+++ b/drivers/input/keyboard/tc3589x-keypad.c
@@ -402,7 +402,7 @@ static int __devexit tc3589x_keypad_remove(struct platform_device *pdev)
402 return 0; 402 return 0;
403} 403}
404 404
405#ifdef CONFIG_PM 405#ifdef CONFIG_PM_SLEEP
406static int tc3589x_keypad_suspend(struct device *dev) 406static int tc3589x_keypad_suspend(struct device *dev)
407{ 407{
408 struct platform_device *pdev = to_platform_device(dev); 408 struct platform_device *pdev = to_platform_device(dev);
@@ -439,19 +439,19 @@ static int tc3589x_keypad_resume(struct device *dev)
439 439
440 return 0; 440 return 0;
441} 441}
442
443static const SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops,
444 tc3589x_keypad_suspend, tc3589x_keypad_resume);
445#endif 442#endif
446 443
444static SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops,
445 tc3589x_keypad_suspend, tc3589x_keypad_resume);
446
447static struct platform_driver tc3589x_keypad_driver = { 447static struct platform_driver tc3589x_keypad_driver = {
448 .driver.name = "tc3589x-keypad", 448 .driver = {
449 .driver.owner = THIS_MODULE, 449 .name = "tc3589x-keypad",
450#ifdef CONFIG_PM 450 .owner = THIS_MODULE,
451 .driver.pm = &tc3589x_keypad_dev_pm_ops, 451 .pm = &tc3589x_keypad_dev_pm_ops,
452#endif 452 },
453 .probe = tc3589x_keypad_probe, 453 .probe = tc3589x_keypad_probe,
454 .remove = __devexit_p(tc3589x_keypad_remove), 454 .remove = __devexit_p(tc3589x_keypad_remove),
455}; 455};
456 456
457static int __init tc3589x_keypad_init(void) 457static int __init tc3589x_keypad_init(void)
diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c
index 800fbccf1f0f..3afea3f89718 100644
--- a/drivers/input/keyboard/tca6416-keypad.c
+++ b/drivers/input/keyboard/tca6416-keypad.c
@@ -297,6 +297,7 @@ static int __devinit tca6416_keypad_probe(struct i2c_client *client,
297 } 297 }
298 298
299 i2c_set_clientdata(client, chip); 299 i2c_set_clientdata(client, chip);
300 device_init_wakeup(&client->dev, 1);
300 301
301 return 0; 302 return 0;
302 303
@@ -326,10 +327,37 @@ static int __devexit tca6416_keypad_remove(struct i2c_client *client)
326 return 0; 327 return 0;
327} 328}
328 329
330#ifdef CONFIG_PM_SLEEP
331static int tca6416_keypad_suspend(struct device *dev)
332{
333 struct i2c_client *client = to_i2c_client(dev);
334 struct tca6416_keypad_chip *chip = i2c_get_clientdata(client);
335
336 if (device_may_wakeup(dev))
337 enable_irq_wake(chip->irqnum);
338
339 return 0;
340}
341
342static int tca6416_keypad_resume(struct device *dev)
343{
344 struct i2c_client *client = to_i2c_client(dev);
345 struct tca6416_keypad_chip *chip = i2c_get_clientdata(client);
346
347 if (device_may_wakeup(dev))
348 disable_irq_wake(chip->irqnum);
349
350 return 0;
351}
352#endif
353
354static SIMPLE_DEV_PM_OPS(tca6416_keypad_dev_pm_ops,
355 tca6416_keypad_suspend, tca6416_keypad_resume);
329 356
330static struct i2c_driver tca6416_keypad_driver = { 357static struct i2c_driver tca6416_keypad_driver = {
331 .driver = { 358 .driver = {
332 .name = "tca6416-keypad", 359 .name = "tca6416-keypad",
360 .pm = &tca6416_keypad_dev_pm_ops,
333 }, 361 },
334 .probe = tca6416_keypad_probe, 362 .probe = tca6416_keypad_probe,
335 .remove = __devexit_p(tca6416_keypad_remove), 363 .remove = __devexit_p(tca6416_keypad_remove),
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index b0c6772851a9..f9cf0881b0e3 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -454,4 +454,17 @@ config INPUT_CMA3000_I2C
454 To compile this driver as a module, choose M here: the 454 To compile this driver as a module, choose M here: the
455 module will be called cma3000_d0x_i2c. 455 module will be called cma3000_d0x_i2c.
456 456
457config INPUT_XEN_KBDDEV_FRONTEND
458 tristate "Xen virtual keyboard and mouse support"
459 depends on XEN_FBDEV_FRONTEND
460 default y
461 select XEN_XENBUS_FRONTEND
462 help
463 This driver implements the front-end of the Xen virtual
464 keyboard and mouse device driver. It communicates with a back-end
465 in another domain.
466
467 To compile this driver as a module, choose M here: the
468 module will be called xen-kbdfront.
469
457endif 470endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9b4797112c9a..e3f7984e6274 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -42,5 +42,6 @@ obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
42obj-$(CONFIG_INPUT_UINPUT) += uinput.o 42obj-$(CONFIG_INPUT_UINPUT) += uinput.o
43obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 43obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
44obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 44obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
45obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
45obj-$(CONFIG_INPUT_YEALINK) += yealink.o 46obj-$(CONFIG_INPUT_YEALINK) += yealink.o
46 47
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index 2bef8fa56c94..e21deb1baa8a 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -10,23 +10,23 @@
10#include <linux/i2c.h> 10#include <linux/i2c.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/pm.h>
13#include "ad714x.h" 14#include "ad714x.h"
14 15
15#ifdef CONFIG_PM 16#ifdef CONFIG_PM
16static int ad714x_i2c_suspend(struct i2c_client *client, pm_message_t message) 17static int ad714x_i2c_suspend(struct device *dev)
17{ 18{
18 return ad714x_disable(i2c_get_clientdata(client)); 19 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
19} 20}
20 21
21static int ad714x_i2c_resume(struct i2c_client *client) 22static int ad714x_i2c_resume(struct device *dev)
22{ 23{
23 return ad714x_enable(i2c_get_clientdata(client)); 24 return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev)));
24} 25}
25#else
26# define ad714x_i2c_suspend NULL
27# define ad714x_i2c_resume NULL
28#endif 26#endif
29 27
28static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
29
30static int ad714x_i2c_write(struct device *dev, unsigned short reg, 30static int ad714x_i2c_write(struct device *dev, unsigned short reg,
31 unsigned short data) 31 unsigned short data)
32{ 32{
@@ -114,11 +114,10 @@ MODULE_DEVICE_TABLE(i2c, ad714x_id);
114static struct i2c_driver ad714x_i2c_driver = { 114static struct i2c_driver ad714x_i2c_driver = {
115 .driver = { 115 .driver = {
116 .name = "ad714x_captouch", 116 .name = "ad714x_captouch",
117 .pm = &ad714x_i2c_pm,
117 }, 118 },
118 .probe = ad714x_i2c_probe, 119 .probe = ad714x_i2c_probe,
119 .remove = __devexit_p(ad714x_i2c_remove), 120 .remove = __devexit_p(ad714x_i2c_remove),
120 .suspend = ad714x_i2c_suspend,
121 .resume = ad714x_i2c_resume,
122 .id_table = ad714x_id, 121 .id_table = ad714x_id,
123}; 122};
124 123
diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c
index 7f8dedfd1bfe..4120dd549305 100644
--- a/drivers/input/misc/ad714x-spi.c
+++ b/drivers/input/misc/ad714x-spi.c
@@ -9,6 +9,7 @@
9#include <linux/input.h> /* BUS_I2C */ 9#include <linux/input.h> /* BUS_I2C */
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
12#include <linux/pm.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include "ad714x.h" 14#include "ad714x.h"
14 15
@@ -16,20 +17,19 @@
16#define AD714x_SPI_READ BIT(10) 17#define AD714x_SPI_READ BIT(10)
17 18
18#ifdef CONFIG_PM 19#ifdef CONFIG_PM
19static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) 20static int ad714x_spi_suspend(struct device *dev)
20{ 21{
21 return ad714x_disable(spi_get_drvdata(spi)); 22 return ad714x_disable(spi_get_drvdata(to_spi_device(dev)));
22} 23}
23 24
24static int ad714x_spi_resume(struct spi_device *spi) 25static int ad714x_spi_resume(struct device *dev)
25{ 26{
26 return ad714x_enable(spi_get_drvdata(spi)); 27 return ad714x_enable(spi_get_drvdata(to_spi_device(dev)));
27} 28}
28#else
29# define ad714x_spi_suspend NULL
30# define ad714x_spi_resume NULL
31#endif 29#endif
32 30
31static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume);
32
33static int ad714x_spi_read(struct device *dev, unsigned short reg, 33static int ad714x_spi_read(struct device *dev, unsigned short reg,
34 unsigned short *data) 34 unsigned short *data)
35{ 35{
@@ -79,11 +79,10 @@ static struct spi_driver ad714x_spi_driver = {
79 .driver = { 79 .driver = {
80 .name = "ad714x_captouch", 80 .name = "ad714x_captouch",
81 .owner = THIS_MODULE, 81 .owner = THIS_MODULE,
82 .pm = &ad714x_spi_pm,
82 }, 83 },
83 .probe = ad714x_spi_probe, 84 .probe = ad714x_spi_probe,
84 .remove = __devexit_p(ad714x_spi_remove), 85 .remove = __devexit_p(ad714x_spi_remove),
85 .suspend = ad714x_spi_suspend,
86 .resume = ad714x_spi_resume,
87}; 86};
88 87
89static __init int ad714x_spi_init(void) 88static __init int ad714x_spi_init(void)
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c
index 0779724af7e7..ccacf2bb06a4 100644
--- a/drivers/input/misc/adxl34x-i2c.c
+++ b/drivers/input/misc/adxl34x-i2c.c
@@ -11,6 +11,7 @@
11#include <linux/i2c.h> 11#include <linux/i2c.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/pm.h>
14#include "adxl34x.h" 15#include "adxl34x.h"
15 16
16static int adxl34x_smbus_read(struct device *dev, unsigned char reg) 17static int adxl34x_smbus_read(struct device *dev, unsigned char reg)
@@ -105,8 +106,9 @@ static int __devexit adxl34x_i2c_remove(struct i2c_client *client)
105} 106}
106 107
107#ifdef CONFIG_PM 108#ifdef CONFIG_PM
108static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) 109static int adxl34x_i2c_suspend(struct device *dev)
109{ 110{
111 struct i2c_client *client = to_i2c_client(dev);
110 struct adxl34x *ac = i2c_get_clientdata(client); 112 struct adxl34x *ac = i2c_get_clientdata(client);
111 113
112 adxl34x_suspend(ac); 114 adxl34x_suspend(ac);
@@ -114,19 +116,20 @@ static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message)
114 return 0; 116 return 0;
115} 117}
116 118
117static int adxl34x_i2c_resume(struct i2c_client *client) 119static int adxl34x_i2c_resume(struct device *dev)
118{ 120{
121 struct i2c_client *client = to_i2c_client(dev);
119 struct adxl34x *ac = i2c_get_clientdata(client); 122 struct adxl34x *ac = i2c_get_clientdata(client);
120 123
121 adxl34x_resume(ac); 124 adxl34x_resume(ac);
122 125
123 return 0; 126 return 0;
124} 127}
125#else
126# define adxl34x_i2c_suspend NULL
127# define adxl34x_i2c_resume NULL
128#endif 128#endif
129 129
130static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend,
131 adxl34x_i2c_resume);
132
130static const struct i2c_device_id adxl34x_id[] = { 133static const struct i2c_device_id adxl34x_id[] = {
131 { "adxl34x", 0 }, 134 { "adxl34x", 0 },
132 { } 135 { }
@@ -138,11 +141,10 @@ static struct i2c_driver adxl34x_driver = {
138 .driver = { 141 .driver = {
139 .name = "adxl34x", 142 .name = "adxl34x",
140 .owner = THIS_MODULE, 143 .owner = THIS_MODULE,
144 .pm = &adxl34x_i2c_pm,
141 }, 145 },
142 .probe = adxl34x_i2c_probe, 146 .probe = adxl34x_i2c_probe,
143 .remove = __devexit_p(adxl34x_i2c_remove), 147 .remove = __devexit_p(adxl34x_i2c_remove),
144 .suspend = adxl34x_i2c_suspend,
145 .resume = adxl34x_i2c_resume,
146 .id_table = adxl34x_id, 148 .id_table = adxl34x_id,
147}; 149};
148 150
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c
index 782de9e89828..f29de22fdda0 100644
--- a/drivers/input/misc/adxl34x-spi.c
+++ b/drivers/input/misc/adxl34x-spi.c
@@ -10,6 +10,7 @@
10#include <linux/input.h> /* BUS_SPI */ 10#include <linux/input.h> /* BUS_SPI */
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/spi/spi.h> 12#include <linux/spi/spi.h>
13#include <linux/pm.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include "adxl34x.h" 15#include "adxl34x.h"
15 16
@@ -57,7 +58,7 @@ static int adxl34x_spi_read_block(struct device *dev,
57 return (status < 0) ? status : 0; 58 return (status < 0) ? status : 0;
58} 59}
59 60
60static const struct adxl34x_bus_ops adx134x_spi_bops = { 61static const struct adxl34x_bus_ops adxl34x_spi_bops = {
61 .bustype = BUS_SPI, 62 .bustype = BUS_SPI,
62 .write = adxl34x_spi_write, 63 .write = adxl34x_spi_write,
63 .read = adxl34x_spi_read, 64 .read = adxl34x_spi_read,
@@ -76,7 +77,7 @@ static int __devinit adxl34x_spi_probe(struct spi_device *spi)
76 77
77 ac = adxl34x_probe(&spi->dev, spi->irq, 78 ac = adxl34x_probe(&spi->dev, spi->irq,
78 spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, 79 spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY,
79 &adx134x_spi_bops); 80 &adxl34x_spi_bops);
80 81
81 if (IS_ERR(ac)) 82 if (IS_ERR(ac))
82 return PTR_ERR(ac); 83 return PTR_ERR(ac);
@@ -94,8 +95,9 @@ static int __devexit adxl34x_spi_remove(struct spi_device *spi)
94} 95}
95 96
96#ifdef CONFIG_PM 97#ifdef CONFIG_PM
97static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) 98static int adxl34x_spi_suspend(struct device *dev)
98{ 99{
100 struct spi_device *spi = to_spi_device(dev);
99 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 101 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
100 102
101 adxl34x_suspend(ac); 103 adxl34x_suspend(ac);
@@ -103,29 +105,29 @@ static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message)
103 return 0; 105 return 0;
104} 106}
105 107
106static int adxl34x_spi_resume(struct spi_device *spi) 108static int adxl34x_spi_resume(struct device *dev)
107{ 109{
110 struct spi_device *spi = to_spi_device(dev);
108 struct adxl34x *ac = dev_get_drvdata(&spi->dev); 111 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
109 112
110 adxl34x_resume(ac); 113 adxl34x_resume(ac);
111 114
112 return 0; 115 return 0;
113} 116}
114#else
115# define adxl34x_spi_suspend NULL
116# define adxl34x_spi_resume NULL
117#endif 117#endif
118 118
119static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend,
120 adxl34x_spi_resume);
121
119static struct spi_driver adxl34x_driver = { 122static struct spi_driver adxl34x_driver = {
120 .driver = { 123 .driver = {
121 .name = "adxl34x", 124 .name = "adxl34x",
122 .bus = &spi_bus_type, 125 .bus = &spi_bus_type,
123 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
127 .pm = &adxl34x_spi_pm,
124 }, 128 },
125 .probe = adxl34x_spi_probe, 129 .probe = adxl34x_spi_probe,
126 .remove = __devexit_p(adxl34x_spi_remove), 130 .remove = __devexit_p(adxl34x_spi_remove),
127 .suspend = adxl34x_spi_suspend,
128 .resume = adxl34x_spi_resume,
129}; 131};
130 132
131static int __init adxl34x_spi_init(void) 133static int __init adxl34x_spi_init(void)
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 0b0e9be63542..9ccdb82d869a 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -612,8 +612,8 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
612 idev->open = ati_remote2_open; 612 idev->open = ati_remote2_open;
613 idev->close = ati_remote2_close; 613 idev->close = ati_remote2_close;
614 614
615 idev->getkeycode_new = ati_remote2_getkeycode; 615 idev->getkeycode = ati_remote2_getkeycode;
616 idev->setkeycode_new = ati_remote2_setkeycode; 616 idev->setkeycode = ati_remote2_setkeycode;
617 617
618 idev->name = ar2->name; 618 idev->name = ar2->name;
619 idev->phys = ar2->phys; 619 idev->phys = ar2->phys;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 82542a1c1098..364bdf43a381 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -347,8 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
347{ 347{
348 struct uinput_user_dev *user_dev; 348 struct uinput_user_dev *user_dev;
349 struct input_dev *dev; 349 struct input_dev *dev;
350 char *name; 350 int i;
351 int i, size;
352 int retval; 351 int retval;
353 352
354 if (count != sizeof(struct uinput_user_dev)) 353 if (count != sizeof(struct uinput_user_dev))
@@ -362,30 +361,25 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
362 361
363 dev = udev->dev; 362 dev = udev->dev;
364 363
365 user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); 364 user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev));
366 if (!user_dev) 365 if (IS_ERR(user_dev))
367 return -ENOMEM; 366 return PTR_ERR(user_dev);
368
369 if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) {
370 retval = -EFAULT;
371 goto exit;
372 }
373 367
374 udev->ff_effects_max = user_dev->ff_effects_max; 368 udev->ff_effects_max = user_dev->ff_effects_max;
375 369
376 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 370 /* Ensure name is filled in */
377 if (!size) { 371 if (!user_dev->name[0]) {
378 retval = -EINVAL; 372 retval = -EINVAL;
379 goto exit; 373 goto exit;
380 } 374 }
381 375
382 kfree(dev->name); 376 kfree(dev->name);
383 dev->name = name = kmalloc(size, GFP_KERNEL); 377 dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE,
384 if (!name) { 378 GFP_KERNEL);
379 if (!dev->name) {
385 retval = -ENOMEM; 380 retval = -ENOMEM;
386 goto exit; 381 goto exit;
387 } 382 }
388 strlcpy(name, user_dev->name, size);
389 383
390 dev->id.bustype = user_dev->id.bustype; 384 dev->id.bustype = user_dev->id.bustype;
391 dev->id.vendor = user_dev->id.vendor; 385 dev->id.vendor = user_dev->id.vendor;
@@ -622,7 +616,6 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
622 struct uinput_ff_upload ff_up; 616 struct uinput_ff_upload ff_up;
623 struct uinput_ff_erase ff_erase; 617 struct uinput_ff_erase ff_erase;
624 struct uinput_request *req; 618 struct uinput_request *req;
625 int length;
626 char *phys; 619 char *phys;
627 620
628 retval = mutex_lock_interruptible(&udev->mutex); 621 retval = mutex_lock_interruptible(&udev->mutex);
@@ -689,24 +682,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
689 retval = -EINVAL; 682 retval = -EINVAL;
690 goto out; 683 goto out;
691 } 684 }
692 length = strnlen_user(p, 1024); 685
693 if (length <= 0) { 686 phys = strndup_user(p, 1024);
694 retval = -EFAULT; 687 if (IS_ERR(phys)) {
695 break; 688 retval = PTR_ERR(phys);
689 goto out;
696 } 690 }
691
697 kfree(udev->dev->phys); 692 kfree(udev->dev->phys);
698 udev->dev->phys = phys = kmalloc(length, GFP_KERNEL); 693 udev->dev->phys = phys;
699 if (!phys) {
700 retval = -ENOMEM;
701 break;
702 }
703 if (copy_from_user(phys, p, length)) {
704 udev->dev->phys = NULL;
705 kfree(phys);
706 retval = -EFAULT;
707 break;
708 }
709 phys[length - 1] = '\0';
710 break; 694 break;
711 695
712 case UI_BEGIN_FF_UPLOAD: 696 case UI_BEGIN_FF_UPLOAD:
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 7f85a862ad11..7077f9bf5ead 100644
--- a/drivers/input/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -11,12 +11,6 @@
11 * more details. 11 * more details.
12 */ 12 */
13 13
14/*
15 * TODO:
16 *
17 * Switch to grant tables together with xen-fbfront.c.
18 */
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 15
22#include <linux/kernel.h> 16#include <linux/kernel.h>
@@ -30,6 +24,8 @@
30#include <xen/xen.h> 24#include <xen/xen.h>
31#include <xen/events.h> 25#include <xen/events.h>
32#include <xen/page.h> 26#include <xen/page.h>
27#include <xen/grant_table.h>
28#include <xen/interface/grant_table.h>
33#include <xen/interface/io/fbif.h> 29#include <xen/interface/io/fbif.h>
34#include <xen/interface/io/kbdif.h> 30#include <xen/interface/io/kbdif.h>
35#include <xen/xenbus.h> 31#include <xen/xenbus.h>
@@ -38,6 +34,7 @@ struct xenkbd_info {
38 struct input_dev *kbd; 34 struct input_dev *kbd;
39 struct input_dev *ptr; 35 struct input_dev *ptr;
40 struct xenkbd_page *page; 36 struct xenkbd_page *page;
37 int gref;
41 int irq; 38 int irq;
42 struct xenbus_device *xbdev; 39 struct xenbus_device *xbdev;
43 char phys[32]; 40 char phys[32];
@@ -110,7 +107,7 @@ static irqreturn_t input_handler(int rq, void *dev_id)
110static int __devinit xenkbd_probe(struct xenbus_device *dev, 107static int __devinit xenkbd_probe(struct xenbus_device *dev,
111 const struct xenbus_device_id *id) 108 const struct xenbus_device_id *id)
112{ 109{
113 int ret, i; 110 int ret, i, abs;
114 struct xenkbd_info *info; 111 struct xenkbd_info *info;
115 struct input_dev *kbd, *ptr; 112 struct input_dev *kbd, *ptr;
116 113
@@ -122,12 +119,18 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
122 dev_set_drvdata(&dev->dev, info); 119 dev_set_drvdata(&dev->dev, info);
123 info->xbdev = dev; 120 info->xbdev = dev;
124 info->irq = -1; 121 info->irq = -1;
122 info->gref = -1;
125 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename); 123 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
126 124
127 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); 125 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
128 if (!info->page) 126 if (!info->page)
129 goto error_nomem; 127 goto error_nomem;
130 128
129 if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0)
130 abs = 0;
131 if (abs)
132 xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1");
133
131 /* keyboard */ 134 /* keyboard */
132 kbd = input_allocate_device(); 135 kbd = input_allocate_device();
133 if (!kbd) 136 if (!kbd)
@@ -137,11 +140,12 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
137 kbd->id.bustype = BUS_PCI; 140 kbd->id.bustype = BUS_PCI;
138 kbd->id.vendor = 0x5853; 141 kbd->id.vendor = 0x5853;
139 kbd->id.product = 0xffff; 142 kbd->id.product = 0xffff;
140 kbd->evbit[0] = BIT(EV_KEY); 143
144 __set_bit(EV_KEY, kbd->evbit);
141 for (i = KEY_ESC; i < KEY_UNKNOWN; i++) 145 for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
142 set_bit(i, kbd->keybit); 146 __set_bit(i, kbd->keybit);
143 for (i = KEY_OK; i < KEY_MAX; i++) 147 for (i = KEY_OK; i < KEY_MAX; i++)
144 set_bit(i, kbd->keybit); 148 __set_bit(i, kbd->keybit);
145 149
146 ret = input_register_device(kbd); 150 ret = input_register_device(kbd);
147 if (ret) { 151 if (ret) {
@@ -160,12 +164,20 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
160 ptr->id.bustype = BUS_PCI; 164 ptr->id.bustype = BUS_PCI;
161 ptr->id.vendor = 0x5853; 165 ptr->id.vendor = 0x5853;
162 ptr->id.product = 0xfffe; 166 ptr->id.product = 0xfffe;
163 ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); 167
168 if (abs) {
169 __set_bit(EV_ABS, ptr->evbit);
170 input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
171 input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
172 } else {
173 input_set_capability(ptr, EV_REL, REL_X);
174 input_set_capability(ptr, EV_REL, REL_Y);
175 }
176 input_set_capability(ptr, EV_REL, REL_WHEEL);
177
178 __set_bit(EV_KEY, ptr->evbit);
164 for (i = BTN_LEFT; i <= BTN_TASK; i++) 179 for (i = BTN_LEFT; i <= BTN_TASK; i++)
165 set_bit(i, ptr->keybit); 180 __set_bit(i, ptr->keybit);
166 ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
167 input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
168 input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
169 181
170 ret = input_register_device(ptr); 182 ret = input_register_device(ptr);
171 if (ret) { 183 if (ret) {
@@ -218,15 +230,20 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
218 int ret, evtchn; 230 int ret, evtchn;
219 struct xenbus_transaction xbt; 231 struct xenbus_transaction xbt;
220 232
233 ret = gnttab_grant_foreign_access(dev->otherend_id,
234 virt_to_mfn(info->page), 0);
235 if (ret < 0)
236 return ret;
237 info->gref = ret;
238
221 ret = xenbus_alloc_evtchn(dev, &evtchn); 239 ret = xenbus_alloc_evtchn(dev, &evtchn);
222 if (ret) 240 if (ret)
223 return ret; 241 goto error_grant;
224 ret = bind_evtchn_to_irqhandler(evtchn, input_handler, 242 ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
225 0, dev->devicetype, info); 243 0, dev->devicetype, info);
226 if (ret < 0) { 244 if (ret < 0) {
227 xenbus_free_evtchn(dev, evtchn);
228 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); 245 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
229 return ret; 246 goto error_evtchan;
230 } 247 }
231 info->irq = ret; 248 info->irq = ret;
232 249
@@ -234,12 +251,15 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
234 ret = xenbus_transaction_start(&xbt); 251 ret = xenbus_transaction_start(&xbt);
235 if (ret) { 252 if (ret) {
236 xenbus_dev_fatal(dev, ret, "starting transaction"); 253 xenbus_dev_fatal(dev, ret, "starting transaction");
237 return ret; 254 goto error_irqh;
238 } 255 }
239 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", 256 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
240 virt_to_mfn(info->page)); 257 virt_to_mfn(info->page));
241 if (ret) 258 if (ret)
242 goto error_xenbus; 259 goto error_xenbus;
260 ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
261 if (ret)
262 goto error_xenbus;
243 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", 263 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
244 evtchn); 264 evtchn);
245 if (ret) 265 if (ret)
@@ -249,7 +269,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
249 if (ret == -EAGAIN) 269 if (ret == -EAGAIN)
250 goto again; 270 goto again;
251 xenbus_dev_fatal(dev, ret, "completing transaction"); 271 xenbus_dev_fatal(dev, ret, "completing transaction");
252 return ret; 272 goto error_irqh;
253 } 273 }
254 274
255 xenbus_switch_state(dev, XenbusStateInitialised); 275 xenbus_switch_state(dev, XenbusStateInitialised);
@@ -258,6 +278,14 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
258 error_xenbus: 278 error_xenbus:
259 xenbus_transaction_end(xbt, 1); 279 xenbus_transaction_end(xbt, 1);
260 xenbus_dev_fatal(dev, ret, "writing xenstore"); 280 xenbus_dev_fatal(dev, ret, "writing xenstore");
281 error_irqh:
282 unbind_from_irqhandler(info->irq, info);
283 info->irq = -1;
284 error_evtchan:
285 xenbus_free_evtchn(dev, evtchn);
286 error_grant:
287 gnttab_end_foreign_access_ref(info->gref, 0);
288 info->gref = -1;
261 return ret; 289 return ret;
262} 290}
263 291
@@ -266,13 +294,16 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *info)
266 if (info->irq >= 0) 294 if (info->irq >= 0)
267 unbind_from_irqhandler(info->irq, info); 295 unbind_from_irqhandler(info->irq, info);
268 info->irq = -1; 296 info->irq = -1;
297 if (info->gref >= 0)
298 gnttab_end_foreign_access_ref(info->gref, 0);
299 info->gref = -1;
269} 300}
270 301
271static void xenkbd_backend_changed(struct xenbus_device *dev, 302static void xenkbd_backend_changed(struct xenbus_device *dev,
272 enum xenbus_state backend_state) 303 enum xenbus_state backend_state)
273{ 304{
274 struct xenkbd_info *info = dev_get_drvdata(&dev->dev); 305 struct xenkbd_info *info = dev_get_drvdata(&dev->dev);
275 int ret, val; 306 int val;
276 307
277 switch (backend_state) { 308 switch (backend_state) {
278 case XenbusStateInitialising: 309 case XenbusStateInitialising:
@@ -285,16 +316,6 @@ static void xenkbd_backend_changed(struct xenbus_device *dev,
285 316
286 case XenbusStateInitWait: 317 case XenbusStateInitWait:
287InitWait: 318InitWait:
288 ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
289 "feature-abs-pointer", "%d", &val);
290 if (ret < 0)
291 val = 0;
292 if (val) {
293 ret = xenbus_printf(XBT_NIL, info->xbdev->nodename,
294 "request-abs-pointer", "1");
295 if (ret)
296 pr_warning("can't request abs-pointer\n");
297 }
298 xenbus_switch_state(dev, XenbusStateConnected); 319 xenbus_switch_state(dev, XenbusStateConnected);
299 break; 320 break;
300 321
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index ee82851afe3e..3aead91bacc8 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -63,6 +63,10 @@
63#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 63#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
64#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 64#define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
65#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244 65#define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
66/* Macbook8 (unibody, March 2011) */
67#define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245
68#define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246
69#define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247
66 70
67#define BCM5974_DEVICE(prod) { \ 71#define BCM5974_DEVICE(prod) { \
68 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ 72 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
@@ -96,6 +100,10 @@ static const struct usb_device_id bcm5974_table[] = {
96 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), 100 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
97 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), 101 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
98 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), 102 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
103 /* MacbookPro8 */
104 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
105 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
106 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
99 /* Terminating entry */ 107 /* Terminating entry */
100 {} 108 {}
101}; 109};
@@ -274,6 +282,18 @@ static const struct bcm5974_config bcm5974_config_table[] = {
274 { DIM_X, DIM_X / SN_COORD, -4616, 5112 }, 282 { DIM_X, DIM_X / SN_COORD, -4616, 5112 },
275 { DIM_Y, DIM_Y / SN_COORD, -142, 5234 } 283 { DIM_Y, DIM_Y / SN_COORD, -142, 5234 }
276 }, 284 },
285 {
286 USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI,
287 USB_DEVICE_ID_APPLE_WELLSPRING5_ISO,
288 USB_DEVICE_ID_APPLE_WELLSPRING5_JIS,
289 HAS_INTEGRATED_BUTTON,
290 0x84, sizeof(struct bt_data),
291 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
292 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 },
293 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
294 { DIM_X, DIM_X / SN_COORD, -4415, 5050 },
295 { DIM_Y, DIM_Y / SN_COORD, -55, 6680 }
296 },
277 {} 297 {}
278}; 298};
279 299
@@ -430,10 +450,6 @@ static int report_tp_state(struct bcm5974 *dev, int size)
430 ptest = int2bound(&c->p, raw_p); 450 ptest = int2bound(&c->p, raw_p);
431 origin = raw2int(f->origin); 451 origin = raw2int(f->origin);
432 452
433 /* set the integrated button if applicable */
434 if (c->tp_type == TYPE2)
435 ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
436
437 /* while tracking finger still valid, count all fingers */ 453 /* while tracking finger still valid, count all fingers */
438 if (ptest > PRESSURE_LOW && origin) { 454 if (ptest > PRESSURE_LOW && origin) {
439 abs_p = ptest; 455 abs_p = ptest;
@@ -452,6 +468,10 @@ static int report_tp_state(struct bcm5974 *dev, int size)
452 } 468 }
453 } 469 }
454 470
471 /* set the integrated button if applicable */
472 if (c->tp_type == TYPE2)
473 ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
474
455 if (dev->fingers < nmin) 475 if (dev->fingers < nmin)
456 dev->fingers = nmin; 476 dev->fingers = nmin;
457 if (dev->fingers > nmax) 477 if (dev->fingers > nmax)
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c
index 0ae62f0bcb32..f6aa26d305ed 100644
--- a/drivers/input/mouse/synaptics_i2c.c
+++ b/drivers/input/mouse/synaptics_i2c.c
@@ -18,6 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/workqueue.h> 19#include <linux/workqueue.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/pm.h>
21 22
22#define DRIVER_NAME "synaptics_i2c" 23#define DRIVER_NAME "synaptics_i2c"
23/* maximum product id is 15 characters */ 24/* maximum product id is 15 characters */
@@ -619,8 +620,9 @@ static int __devexit synaptics_i2c_remove(struct i2c_client *client)
619} 620}
620 621
621#ifdef CONFIG_PM 622#ifdef CONFIG_PM
622static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg) 623static int synaptics_i2c_suspend(struct device *dev)
623{ 624{
625 struct i2c_client *client = to_i2c_client(dev);
624 struct synaptics_i2c *touch = i2c_get_clientdata(client); 626 struct synaptics_i2c *touch = i2c_get_clientdata(client);
625 627
626 cancel_delayed_work_sync(&touch->dwork); 628 cancel_delayed_work_sync(&touch->dwork);
@@ -631,9 +633,10 @@ static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
631 return 0; 633 return 0;
632} 634}
633 635
634static int synaptics_i2c_resume(struct i2c_client *client) 636static int synaptics_i2c_resume(struct device *dev)
635{ 637{
636 int ret; 638 int ret;
639 struct i2c_client *client = to_i2c_client(dev);
637 struct synaptics_i2c *touch = i2c_get_clientdata(client); 640 struct synaptics_i2c *touch = i2c_get_clientdata(client);
638 641
639 ret = synaptics_i2c_reset_config(client); 642 ret = synaptics_i2c_reset_config(client);
@@ -645,11 +648,11 @@ static int synaptics_i2c_resume(struct i2c_client *client)
645 648
646 return 0; 649 return 0;
647} 650}
648#else
649#define synaptics_i2c_suspend NULL
650#define synaptics_i2c_resume NULL
651#endif 651#endif
652 652
653static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend,
654 synaptics_i2c_resume);
655
653static const struct i2c_device_id synaptics_i2c_id_table[] = { 656static const struct i2c_device_id synaptics_i2c_id_table[] = {
654 { "synaptics_i2c", 0 }, 657 { "synaptics_i2c", 0 },
655 { }, 658 { },
@@ -660,13 +663,12 @@ static struct i2c_driver synaptics_i2c_driver = {
660 .driver = { 663 .driver = {
661 .name = DRIVER_NAME, 664 .name = DRIVER_NAME,
662 .owner = THIS_MODULE, 665 .owner = THIS_MODULE,
666 .pm = &synaptics_i2c_pm,
663 }, 667 },
664 668
665 .probe = synaptics_i2c_probe, 669 .probe = synaptics_i2c_probe,
666 .remove = __devexit_p(synaptics_i2c_remove), 670 .remove = __devexit_p(synaptics_i2c_remove),
667 671
668 .suspend = synaptics_i2c_suspend,
669 .resume = synaptics_i2c_resume,
670 .id_table = synaptics_i2c_id_table, 672 .id_table = synaptics_i2c_id_table,
671}; 673};
672 674
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c
index 7729e547ba65..337bf51bc984 100644
--- a/drivers/input/sparse-keymap.c
+++ b/drivers/input/sparse-keymap.c
@@ -210,8 +210,8 @@ int sparse_keymap_setup(struct input_dev *dev,
210 210
211 dev->keycode = map; 211 dev->keycode = map;
212 dev->keycodemax = map_size; 212 dev->keycodemax = map_size;
213 dev->getkeycode_new = sparse_keymap_getkeycode; 213 dev->getkeycode = sparse_keymap_getkeycode;
214 dev->setkeycode_new = sparse_keymap_setkeycode; 214 dev->setkeycode = sparse_keymap_setkeycode;
215 215
216 return 0; 216 return 0;
217 217
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index cf8fb9f5d4a8..449c0a46dbac 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -193,16 +193,16 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
193 case HID_USAGE_X: 193 case HID_USAGE_X:
194 if (usage == WCM_DESKTOP) { 194 if (usage == WCM_DESKTOP) {
195 if (finger) { 195 if (finger) {
196 features->device_type = BTN_TOOL_DOUBLETAP; 196 features->device_type = BTN_TOOL_FINGER;
197 if (features->type == TABLETPC2FG) { 197 if (features->type == TABLETPC2FG) {
198 /* need to reset back */ 198 /* need to reset back */
199 features->pktlen = WACOM_PKGLEN_TPC2FG; 199 features->pktlen = WACOM_PKGLEN_TPC2FG;
200 features->device_type = BTN_TOOL_TRIPLETAP; 200 features->device_type = BTN_TOOL_DOUBLETAP;
201 } 201 }
202 if (features->type == BAMBOO_PT) { 202 if (features->type == BAMBOO_PT) {
203 /* need to reset back */ 203 /* need to reset back */
204 features->pktlen = WACOM_PKGLEN_BBTOUCH; 204 features->pktlen = WACOM_PKGLEN_BBTOUCH;
205 features->device_type = BTN_TOOL_TRIPLETAP; 205 features->device_type = BTN_TOOL_DOUBLETAP;
206 features->x_phy = 206 features->x_phy =
207 get_unaligned_le16(&report[i + 5]); 207 get_unaligned_le16(&report[i + 5]);
208 features->x_max = 208 features->x_max =
@@ -241,11 +241,11 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
241 case HID_USAGE_Y: 241 case HID_USAGE_Y:
242 if (usage == WCM_DESKTOP) { 242 if (usage == WCM_DESKTOP) {
243 if (finger) { 243 if (finger) {
244 features->device_type = BTN_TOOL_DOUBLETAP; 244 features->device_type = BTN_TOOL_FINGER;
245 if (features->type == TABLETPC2FG) { 245 if (features->type == TABLETPC2FG) {
246 /* need to reset back */ 246 /* need to reset back */
247 features->pktlen = WACOM_PKGLEN_TPC2FG; 247 features->pktlen = WACOM_PKGLEN_TPC2FG;
248 features->device_type = BTN_TOOL_TRIPLETAP; 248 features->device_type = BTN_TOOL_DOUBLETAP;
249 features->y_max = 249 features->y_max =
250 get_unaligned_le16(&report[i + 3]); 250 get_unaligned_le16(&report[i + 3]);
251 features->y_phy = 251 features->y_phy =
@@ -254,7 +254,7 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
254 } else if (features->type == BAMBOO_PT) { 254 } else if (features->type == BAMBOO_PT) {
255 /* need to reset back */ 255 /* need to reset back */
256 features->pktlen = WACOM_PKGLEN_BBTOUCH; 256 features->pktlen = WACOM_PKGLEN_BBTOUCH;
257 features->device_type = BTN_TOOL_TRIPLETAP; 257 features->device_type = BTN_TOOL_DOUBLETAP;
258 features->y_phy = 258 features->y_phy =
259 get_unaligned_le16(&report[i + 3]); 259 get_unaligned_le16(&report[i + 3]);
260 features->y_max = 260 features->y_max =
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 367fa82a607e..5597637cfd41 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -675,169 +675,87 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
675 return 1; 675 return 1;
676} 676}
677 677
678 678static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
679static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
680{ 679{
681 struct input_dev *input = wacom->input; 680 struct input_dev *input = wacom->input;
682 int finger = idx + 1; 681 unsigned char *data = wacom->data;
683 int x = le16_to_cpup((__le16 *)&data[finger * 2]) & 0x7fff; 682 int contact_with_no_pen_down_count = 0;
684 int y = le16_to_cpup((__le16 *)&data[4 + finger * 2]) & 0x7fff; 683 int i;
685 684
686 /* 685 for (i = 0; i < 2; i++) {
687 * Work around input core suppressing "duplicate" events since 686 int p = data[1] & (1 << i);
688 * we are abusing ABS_X/ABS_Y to transmit multi-finger data. 687 bool touch = p && !wacom->shared->stylus_in_proximity;
689 * This should go away once we switch to true multitouch 688
690 * protocol. 689 input_mt_slot(input, i);
691 */ 690 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
692 if (wacom->last_finger != finger) { 691 if (touch) {
693 if (x == input_abs_get_val(input, ABS_X)) 692 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
694 x++; 693 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
695 694
696 if (y == input_abs_get_val(input, ABS_Y)) 695 input_report_abs(input, ABS_MT_POSITION_X, x);
697 y++; 696 input_report_abs(input, ABS_MT_POSITION_Y, y);
697 contact_with_no_pen_down_count++;
698 }
698 } 699 }
699 700
700 input_report_abs(input, ABS_X, x); 701 /* keep touch state for pen event */
701 input_report_abs(input, ABS_Y, y); 702 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
702 input_report_abs(input, ABS_MISC, wacom->id[0]);
703 input_report_key(input, wacom->tool[finger], 1);
704 if (!idx)
705 input_report_key(input, BTN_TOUCH, 1);
706 input_event(input, EV_MSC, MSC_SERIAL, finger);
707 input_sync(input);
708 703
709 wacom->last_finger = finger; 704 input_mt_report_pointer_emulation(input, true);
710}
711 705
712static void wacom_tpc_touch_out(struct wacom_wac *wacom, int idx) 706 return 1;
713{
714 struct input_dev *input = wacom->input;
715 int finger = idx + 1;
716
717 input_report_abs(input, ABS_X, 0);
718 input_report_abs(input, ABS_Y, 0);
719 input_report_abs(input, ABS_MISC, 0);
720 input_report_key(input, wacom->tool[finger], 0);
721 if (!idx)
722 input_report_key(input, BTN_TOUCH, 0);
723 input_event(input, EV_MSC, MSC_SERIAL, finger);
724 input_sync(input);
725} 707}
726 708
727static void wacom_tpc_touch_in(struct wacom_wac *wacom, size_t len) 709static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
728{ 710{
729 char *data = wacom->data; 711 char *data = wacom->data;
730 struct input_dev *input = wacom->input; 712 struct input_dev *input = wacom->input;
713 bool prox;
714 int x = 0, y = 0;
731 715
732 wacom->tool[1] = BTN_TOOL_DOUBLETAP; 716 if (!wacom->shared->stylus_in_proximity) {
733 wacom->id[0] = TOUCH_DEVICE_ID; 717 if (len == WACOM_PKGLEN_TPC1FG) {
734 wacom->tool[2] = BTN_TOOL_TRIPLETAP; 718 prox = data[0] & 0x01;
735 719 x = get_unaligned_le16(&data[1]);
736 if (len != WACOM_PKGLEN_TPC1FG) { 720 y = get_unaligned_le16(&data[3]);
737 721 } else { /* with capacity */
738 switch (data[0]) { 722 prox = data[1] & 0x01;
723 x = le16_to_cpup((__le16 *)&data[2]);
724 y = le16_to_cpup((__le16 *)&data[4]);
725 }
726 } else
727 /* force touch out when pen is in prox */
728 prox = 0;
739 729
740 case WACOM_REPORT_TPC1FG: 730 if (prox) {
741 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); 731 input_report_abs(input, ABS_X, x);
742 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4])); 732 input_report_abs(input, ABS_Y, y);
743 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6])); 733 }
744 input_report_key(input, BTN_TOUCH, le16_to_cpup((__le16 *)&data[6])); 734 input_report_key(input, BTN_TOUCH, prox);
745 input_report_abs(input, ABS_MISC, wacom->id[0]);
746 input_report_key(input, wacom->tool[1], 1);
747 input_sync(input);
748 break;
749 735
750 case WACOM_REPORT_TPC2FG: 736 /* keep touch state for pen events */
751 if (data[1] & 0x01) 737 wacom->shared->touch_down = prox;
752 wacom_tpc_finger_in(wacom, data, 0);
753 else if (wacom->id[1] & 0x01)
754 wacom_tpc_touch_out(wacom, 0);
755 738
756 if (data[1] & 0x02) 739 return 1;
757 wacom_tpc_finger_in(wacom, data, 1);
758 else if (wacom->id[1] & 0x02)
759 wacom_tpc_touch_out(wacom, 1);
760 break;
761 }
762 } else {
763 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
764 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
765 input_report_key(input, BTN_TOUCH, 1);
766 input_report_abs(input, ABS_MISC, wacom->id[1]);
767 input_report_key(input, wacom->tool[1], 1);
768 input_sync(input);
769 }
770} 740}
771 741
772static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) 742static int wacom_tpc_pen(struct wacom_wac *wacom)
773{ 743{
774 struct wacom_features *features = &wacom->features; 744 struct wacom_features *features = &wacom->features;
775 char *data = wacom->data; 745 char *data = wacom->data;
776 struct input_dev *input = wacom->input; 746 struct input_dev *input = wacom->input;
777 int prox = 0, pressure; 747 int pressure;
778 int retval = 0; 748 bool prox = data[1] & 0x20;
779 749
780 dbg("wacom_tpc_irq: received report #%d", data[0]); 750 if (!wacom->shared->stylus_in_proximity) /* first in prox */
781 751 /* Going into proximity select tool */
782 if (len == WACOM_PKGLEN_TPC1FG || /* single touch */ 752 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
783 data[0] == WACOM_REPORT_TPC1FG || /* single touch */
784 data[0] == WACOM_REPORT_TPC2FG) { /* 2FG touch */
785
786 if (wacom->shared->stylus_in_proximity) {
787 if (wacom->id[1] & 0x01)
788 wacom_tpc_touch_out(wacom, 0);
789
790 if (wacom->id[1] & 0x02)
791 wacom_tpc_touch_out(wacom, 1);
792
793 wacom->id[1] = 0;
794 return 0;
795 }
796
797 if (len == WACOM_PKGLEN_TPC1FG) { /* with touch */
798 prox = data[0] & 0x01;
799 } else { /* with capacity */
800 if (data[0] == WACOM_REPORT_TPC1FG)
801 /* single touch */
802 prox = data[1] & 0x01;
803 else
804 /* 2FG touch data */
805 prox = data[1] & 0x03;
806 }
807
808 if (prox) {
809 if (!wacom->id[1])
810 wacom->last_finger = 1;
811 wacom_tpc_touch_in(wacom, len);
812 } else {
813 if (data[0] == WACOM_REPORT_TPC2FG) {
814 /* 2FGT out-prox */
815 if (wacom->id[1] & 0x01)
816 wacom_tpc_touch_out(wacom, 0);
817 753
818 if (wacom->id[1] & 0x02) 754 /* keep pen state for touch events */
819 wacom_tpc_touch_out(wacom, 1); 755 wacom->shared->stylus_in_proximity = prox;
820 } else
821 /* one finger touch */
822 wacom_tpc_touch_out(wacom, 0);
823 756
824 wacom->id[0] = 0; 757 /* send pen events only when touch is up or forced out */
825 } 758 if (!wacom->shared->touch_down) {
826 /* keep prox bit to send proper out-prox event */
827 wacom->id[1] = prox;
828 } else if (data[0] == WACOM_REPORT_PENABLED) { /* Penabled */
829 prox = data[1] & 0x20;
830
831 if (!wacom->shared->stylus_in_proximity) { /* first in prox */
832 /* Going into proximity select tool */
833 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
834 if (wacom->tool[0] == BTN_TOOL_PEN)
835 wacom->id[0] = STYLUS_DEVICE_ID;
836 else
837 wacom->id[0] = ERASER_DEVICE_ID;
838
839 wacom->shared->stylus_in_proximity = true;
840 }
841 input_report_key(input, BTN_STYLUS, data[1] & 0x02); 759 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
842 input_report_key(input, BTN_STYLUS2, data[1] & 0x10); 760 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
843 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); 761 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
@@ -847,15 +765,27 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
847 pressure = features->pressure_max + pressure + 1; 765 pressure = features->pressure_max + pressure + 1;
848 input_report_abs(input, ABS_PRESSURE, pressure); 766 input_report_abs(input, ABS_PRESSURE, pressure);
849 input_report_key(input, BTN_TOUCH, data[1] & 0x05); 767 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
850 if (!prox) { /* out-prox */
851 wacom->id[0] = 0;
852 wacom->shared->stylus_in_proximity = false;
853 }
854 input_report_key(input, wacom->tool[0], prox); 768 input_report_key(input, wacom->tool[0], prox);
855 input_report_abs(input, ABS_MISC, wacom->id[0]); 769 return 1;
856 retval = 1;
857 } 770 }
858 return retval; 771
772 return 0;
773}
774
775static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
776{
777 char *data = wacom->data;
778
779 dbg("wacom_tpc_irq: received report #%d", data[0]);
780
781 if (len == WACOM_PKGLEN_TPC1FG || data[0] == WACOM_REPORT_TPC1FG)
782 return wacom_tpc_single_touch(wacom, len);
783 else if (data[0] == WACOM_REPORT_TPC2FG)
784 return wacom_tpc_mt_touch(wacom);
785 else if (data[0] == WACOM_REPORT_PENABLED)
786 return wacom_tpc_pen(wacom);
787
788 return 0;
859} 789}
860 790
861static int wacom_bpt_touch(struct wacom_wac *wacom) 791static int wacom_bpt_touch(struct wacom_wac *wacom)
@@ -1078,7 +1008,7 @@ void wacom_setup_device_quirks(struct wacom_features *features)
1078{ 1008{
1079 1009
1080 /* touch device found but size is not defined. use default */ 1010 /* touch device found but size is not defined. use default */
1081 if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { 1011 if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
1082 features->x_max = 1023; 1012 features->x_max = 1023;
1083 features->y_max = 1023; 1013 features->y_max = 1023;
1084 } 1014 }
@@ -1090,7 +1020,7 @@ void wacom_setup_device_quirks(struct wacom_features *features)
1090 1020
1091 /* quirks for bamboo touch */ 1021 /* quirks for bamboo touch */
1092 if (features->type == BAMBOO_PT && 1022 if (features->type == BAMBOO_PT &&
1093 features->device_type == BTN_TOOL_TRIPLETAP) { 1023 features->device_type == BTN_TOOL_DOUBLETAP) {
1094 features->x_max <<= 5; 1024 features->x_max <<= 5;
1095 features->y_max <<= 5; 1025 features->y_max <<= 5;
1096 features->x_fuzz <<= 5; 1026 features->x_fuzz <<= 5;
@@ -1226,27 +1156,30 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
1226 break; 1156 break;
1227 1157
1228 case TABLETPC2FG: 1158 case TABLETPC2FG:
1229 if (features->device_type == BTN_TOOL_TRIPLETAP) { 1159 if (features->device_type == BTN_TOOL_DOUBLETAP) {
1230 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); 1160
1231 input_set_capability(input_dev, EV_MSC, MSC_SERIAL); 1161 input_mt_init_slots(input_dev, 2);
1162 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
1163 0, MT_TOOL_MAX, 0, 0);
1164 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1165 0, features->x_max, 0, 0);
1166 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1167 0, features->y_max, 0, 0);
1232 } 1168 }
1233 /* fall through */ 1169 /* fall through */
1234 1170
1235 case TABLETPC: 1171 case TABLETPC:
1236 if (features->device_type == BTN_TOOL_DOUBLETAP || 1172 __clear_bit(ABS_MISC, input_dev->absbit);
1237 features->device_type == BTN_TOOL_TRIPLETAP) { 1173
1174 if (features->device_type != BTN_TOOL_PEN) {
1238 input_abs_set_res(input_dev, ABS_X, 1175 input_abs_set_res(input_dev, ABS_X,
1239 wacom_calculate_touch_res(features->x_max, 1176 wacom_calculate_touch_res(features->x_max,
1240 features->x_phy)); 1177 features->x_phy));
1241 input_abs_set_res(input_dev, ABS_Y, 1178 input_abs_set_res(input_dev, ABS_Y,
1242 wacom_calculate_touch_res(features->y_max, 1179 wacom_calculate_touch_res(features->y_max,
1243 features->y_phy)); 1180 features->y_phy));
1244 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1245 }
1246
1247 if (features->device_type != BTN_TOOL_PEN)
1248 break; /* no need to process stylus stuff */ 1181 break; /* no need to process stylus stuff */
1249 1182 }
1250 /* fall through */ 1183 /* fall through */
1251 1184
1252 case PL: 1185 case PL:
@@ -1264,7 +1197,7 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
1264 case BAMBOO_PT: 1197 case BAMBOO_PT:
1265 __clear_bit(ABS_MISC, input_dev->absbit); 1198 __clear_bit(ABS_MISC, input_dev->absbit);
1266 1199
1267 if (features->device_type == BTN_TOOL_TRIPLETAP) { 1200 if (features->device_type == BTN_TOOL_DOUBLETAP) {
1268 __set_bit(BTN_LEFT, input_dev->keybit); 1201 __set_bit(BTN_LEFT, input_dev->keybit);
1269 __set_bit(BTN_FORWARD, input_dev->keybit); 1202 __set_bit(BTN_FORWARD, input_dev->keybit);
1270 __set_bit(BTN_BACK, input_dev->keybit); 1203 __set_bit(BTN_BACK, input_dev->keybit);
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
index b1310ec9720c..835f756b150c 100644
--- a/drivers/input/tablet/wacom_wac.h
+++ b/drivers/input/tablet/wacom_wac.h
@@ -88,15 +88,15 @@ struct wacom_features {
88 88
89struct wacom_shared { 89struct wacom_shared {
90 bool stylus_in_proximity; 90 bool stylus_in_proximity;
91 bool touch_down;
91}; 92};
92 93
93struct wacom_wac { 94struct wacom_wac {
94 char name[64]; 95 char name[64];
95 unsigned char *data; 96 unsigned char *data;
96 int tool[3]; 97 int tool[2];
97 int id[3]; 98 int id[2];
98 __u32 serial[2]; 99 __u32 serial[2];
99 int last_finger;
100 struct wacom_features features; 100 struct wacom_features features;
101 struct wacom_shared *shared; 101 struct wacom_shared *shared;
102 struct input_dev *input; 102 struct input_dev *input;
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 61834ae282e1..112ec55f2939 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -86,6 +86,18 @@ config TOUCHSCREEN_AD7879_SPI
86 To compile this driver as a module, choose M here: the 86 To compile this driver as a module, choose M here: the
87 module will be called ad7879-spi. 87 module will be called ad7879-spi.
88 88
89config TOUCHSCREEN_ATMEL_MXT
90 tristate "Atmel mXT I2C Touchscreen"
91 depends on I2C
92 help
93 Say Y here if you have Atmel mXT series I2C touchscreen,
94 such as AT42QT602240/ATMXT224, connected to your system.
95
96 If unsure, say N.
97
98 To compile this driver as a module, choose M here: the
99 module will be called atmel_mxt_ts.
100
89config TOUCHSCREEN_BITSY 101config TOUCHSCREEN_BITSY
90 tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" 102 tristate "Compaq iPAQ H3600 (Bitsy) touchscreen"
91 depends on SA1100_BITSY 103 depends on SA1100_BITSY
@@ -339,18 +351,6 @@ config TOUCHSCREEN_PENMOUNT
339 To compile this driver as a module, choose M here: the 351 To compile this driver as a module, choose M here: the
340 module will be called penmount. 352 module will be called penmount.
341 353
342config TOUCHSCREEN_QT602240
343 tristate "QT602240 I2C Touchscreen"
344 depends on I2C
345 help
346 Say Y here if you have the AT42QT602240/ATMXT224 I2C touchscreen
347 connected to your system.
348
349 If unsure, say N.
350
351 To compile this driver as a module, choose M here: the
352 module will be called qt602240_ts.
353
354config TOUCHSCREEN_MIGOR 354config TOUCHSCREEN_MIGOR
355 tristate "Renesas MIGO-R touchscreen" 355 tristate "Renesas MIGO-R touchscreen"
356 depends on SH_MIGOR && I2C 356 depends on SH_MIGOR && I2C
@@ -423,6 +423,16 @@ config TOUCHSCREEN_UCB1400
423 To compile this driver as a module, choose M here: the 423 To compile this driver as a module, choose M here: the
424 module will be called ucb1400_ts. 424 module will be called ucb1400_ts.
425 425
426config TOUCHSCREEN_WM831X
427 tristate "Support for WM831x touchscreen controllers"
428 depends on MFD_WM831X
429 help
430 This enables support for the touchscreen controller on the WM831x
431 series of PMICs.
432
433 To compile this driver as a module, choose M here: the
434 module will be called wm831x-ts.
435
426config TOUCHSCREEN_WM97XX 436config TOUCHSCREEN_WM97XX
427 tristate "Support for WM97xx AC97 touchscreen controllers" 437 tristate "Support for WM97xx AC97 touchscreen controllers"
428 depends on AC97_BUS 438 depends on AC97_BUS
@@ -629,6 +639,17 @@ config TOUCHSCREEN_TOUCHIT213
629 To compile this driver as a module, choose M here: the 639 To compile this driver as a module, choose M here: the
630 module will be called touchit213. 640 module will be called touchit213.
631 641
642config TOUCHSCREEN_TSC2005
643 tristate "TSC2005 based touchscreens"
644 depends on SPI_MASTER
645 help
646 Say Y here if you have a TSC2005 based touchscreen.
647
648 If unsure, say N.
649
650 To compile this driver as a module, choose M here: the
651 module will be called tsc2005.
652
632config TOUCHSCREEN_TSC2007 653config TOUCHSCREEN_TSC2007
633 tristate "TSC2007 based touchscreens" 654 tristate "TSC2007 based touchscreens"
634 depends on I2C 655 depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 718bcc814952..ca94098d4c92 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o
12obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o 12obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o
13obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o 13obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o
14obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 14obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
15obj-$(CONFIG_TOUCHSCREEN_ATMEL_MXT) += atmel_mxt_ts.o
15obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o 16obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o
16obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 17obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
17obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o 18obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o
@@ -37,7 +38,6 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o
37obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o 38obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o
38obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o 39obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
39obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 40obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
40obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o
41obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 41obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o
42obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o 42obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o
43obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o 43obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o
@@ -45,9 +45,11 @@ obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o
45obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 45obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
46obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 46obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
47obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 47obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
48obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o
48obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o 49obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
49obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 50obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
50obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o 51obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o
52obj-$(CONFIG_TOUCHSCREEN_WM831X) += wm831x-ts.o
51obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o 53obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o
52wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o 54wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o
53wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o 55wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index a1952fcc083e..714d4e0f9f95 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -41,6 +41,7 @@
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/input.h> 42#include <linux/input.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/pm.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45#include <linux/spi/spi.h> 46#include <linux/spi/spi.h>
46#include <linux/spi/ad7877.h> 47#include <linux/spi/ad7877.h>
@@ -826,39 +827,37 @@ static int __devexit ad7877_remove(struct spi_device *spi)
826 return 0; 827 return 0;
827} 828}
828 829
829#ifdef CONFIG_PM 830#ifdef CONFIG_PM_SLEEP
830static int ad7877_suspend(struct spi_device *spi, pm_message_t message) 831static int ad7877_suspend(struct device *dev)
831{ 832{
832 struct ad7877 *ts = dev_get_drvdata(&spi->dev); 833 struct ad7877 *ts = dev_get_drvdata(dev);
833 834
834 ad7877_disable(ts); 835 ad7877_disable(ts);
835 836
836 return 0; 837 return 0;
837} 838}
838 839
839static int ad7877_resume(struct spi_device *spi) 840static int ad7877_resume(struct device *dev)
840{ 841{
841 struct ad7877 *ts = dev_get_drvdata(&spi->dev); 842 struct ad7877 *ts = dev_get_drvdata(dev);
842 843
843 ad7877_enable(ts); 844 ad7877_enable(ts);
844 845
845 return 0; 846 return 0;
846} 847}
847#else
848#define ad7877_suspend NULL
849#define ad7877_resume NULL
850#endif 848#endif
851 849
850static SIMPLE_DEV_PM_OPS(ad7877_pm, ad7877_suspend, ad7877_resume);
851
852static struct spi_driver ad7877_driver = { 852static struct spi_driver ad7877_driver = {
853 .driver = { 853 .driver = {
854 .name = "ad7877", 854 .name = "ad7877",
855 .bus = &spi_bus_type, 855 .bus = &spi_bus_type,
856 .owner = THIS_MODULE, 856 .owner = THIS_MODULE,
857 .pm = &ad7877_pm,
857 }, 858 },
858 .probe = ad7877_probe, 859 .probe = ad7877_probe,
859 .remove = __devexit_p(ad7877_remove), 860 .remove = __devexit_p(ad7877_remove),
860 .suspend = ad7877_suspend,
861 .resume = ad7877_resume,
862}; 861};
863 862
864static int __init ad7877_init(void) 863static int __init ad7877_init(void)
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c
index 59c6e68c4325..ddf732f3cafc 100644
--- a/drivers/input/touchscreen/ad7879-spi.c
+++ b/drivers/input/touchscreen/ad7879-spi.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/input.h> /* BUS_SPI */ 9#include <linux/input.h> /* BUS_SPI */
10#include <linux/pm.h>
10#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
11 12
12#include "ad7879.h" 13#include "ad7879.h"
@@ -20,9 +21,10 @@
20#define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) 21#define AD7879_WRITECMD(reg) (AD7879_CMD(reg))
21#define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) 22#define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ)
22 23
23#ifdef CONFIG_PM 24#ifdef CONFIG_PM_SLEEP
24static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) 25static int ad7879_spi_suspend(struct device *dev)
25{ 26{
27 struct spi_device *spi = to_spi_device(dev);
26 struct ad7879 *ts = spi_get_drvdata(spi); 28 struct ad7879 *ts = spi_get_drvdata(spi);
27 29
28 ad7879_suspend(ts); 30 ad7879_suspend(ts);
@@ -30,19 +32,19 @@ static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message)
30 return 0; 32 return 0;
31} 33}
32 34
33static int ad7879_spi_resume(struct spi_device *spi) 35static int ad7879_spi_resume(struct device *dev)
34{ 36{
37 struct spi_device *spi = to_spi_device(dev);
35 struct ad7879 *ts = spi_get_drvdata(spi); 38 struct ad7879 *ts = spi_get_drvdata(spi);
36 39
37 ad7879_resume(ts); 40 ad7879_resume(ts);
38 41
39 return 0; 42 return 0;
40} 43}
41#else
42# define ad7879_spi_suspend NULL
43# define ad7879_spi_resume NULL
44#endif 44#endif
45 45
46static SIMPLE_DEV_PM_OPS(ad7879_spi_pm, ad7879_spi_suspend, ad7879_spi_resume);
47
46/* 48/*
47 * ad7879_read/write are only used for initial setup and for sysfs controls. 49 * ad7879_read/write are only used for initial setup and for sysfs controls.
48 * The main traffic is done in ad7879_collect(). 50 * The main traffic is done in ad7879_collect().
@@ -173,11 +175,10 @@ static struct spi_driver ad7879_spi_driver = {
173 .name = "ad7879", 175 .name = "ad7879",
174 .bus = &spi_bus_type, 176 .bus = &spi_bus_type,
175 .owner = THIS_MODULE, 177 .owner = THIS_MODULE,
178 .pm = &ad7879_spi_pm,
176 }, 179 },
177 .probe = ad7879_spi_probe, 180 .probe = ad7879_spi_probe,
178 .remove = __devexit_p(ad7879_spi_remove), 181 .remove = __devexit_p(ad7879_spi_remove),
179 .suspend = ad7879_spi_suspend,
180 .resume = ad7879_spi_resume,
181}; 182};
182 183
183static int __init ad7879_spi_init(void) 184static int __init ad7879_spi_init(void)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 4bf2316e3284..c24946f51256 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -26,6 +26,7 @@
26#include <linux/input.h> 26#include <linux/input.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/pm.h>
29#include <linux/gpio.h> 30#include <linux/gpio.h>
30#include <linux/spi/spi.h> 31#include <linux/spi/spi.h>
31#include <linux/spi/ads7846.h> 32#include <linux/spi/ads7846.h>
@@ -892,9 +893,10 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
892 return IRQ_HANDLED; 893 return IRQ_HANDLED;
893} 894}
894 895
895static int ads7846_suspend(struct spi_device *spi, pm_message_t message) 896#ifdef CONFIG_PM_SLEEP
897static int ads7846_suspend(struct device *dev)
896{ 898{
897 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 899 struct ads7846 *ts = dev_get_drvdata(dev);
898 900
899 mutex_lock(&ts->lock); 901 mutex_lock(&ts->lock);
900 902
@@ -914,9 +916,9 @@ static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
914 return 0; 916 return 0;
915} 917}
916 918
917static int ads7846_resume(struct spi_device *spi) 919static int ads7846_resume(struct device *dev)
918{ 920{
919 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 921 struct ads7846 *ts = dev_get_drvdata(dev);
920 922
921 mutex_lock(&ts->lock); 923 mutex_lock(&ts->lock);
922 924
@@ -935,6 +937,9 @@ static int ads7846_resume(struct spi_device *spi)
935 937
936 return 0; 938 return 0;
937} 939}
940#endif
941
942static SIMPLE_DEV_PM_OPS(ads7846_pm, ads7846_suspend, ads7846_resume);
938 943
939static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) 944static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts)
940{ 945{
@@ -1408,11 +1413,10 @@ static struct spi_driver ads7846_driver = {
1408 .name = "ads7846", 1413 .name = "ads7846",
1409 .bus = &spi_bus_type, 1414 .bus = &spi_bus_type,
1410 .owner = THIS_MODULE, 1415 .owner = THIS_MODULE,
1416 .pm = &ads7846_pm,
1411 }, 1417 },
1412 .probe = ads7846_probe, 1418 .probe = ads7846_probe,
1413 .remove = __devexit_p(ads7846_remove), 1419 .remove = __devexit_p(ads7846_remove),
1414 .suspend = ads7846_suspend,
1415 .resume = ads7846_resume,
1416}; 1420};
1417 1421
1418static int __init ads7846_init(void) 1422static int __init ads7846_init(void)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
new file mode 100644
index 000000000000..4012436633b1
--- /dev/null
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -0,0 +1,1211 @@
1/*
2 * Atmel maXTouch Touchscreen driver
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/firmware.h>
18#include <linux/i2c.h>
19#include <linux/i2c/atmel_mxt_ts.h>
20#include <linux/input.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23
24/* Version */
25#define MXT_VER_20 20
26#define MXT_VER_21 21
27#define MXT_VER_22 22
28
29/* Slave addresses */
30#define MXT_APP_LOW 0x4a
31#define MXT_APP_HIGH 0x4b
32#define MXT_BOOT_LOW 0x24
33#define MXT_BOOT_HIGH 0x25
34
35/* Firmware */
36#define MXT_FW_NAME "maxtouch.fw"
37
38/* Registers */
39#define MXT_FAMILY_ID 0x00
40#define MXT_VARIANT_ID 0x01
41#define MXT_VERSION 0x02
42#define MXT_BUILD 0x03
43#define MXT_MATRIX_X_SIZE 0x04
44#define MXT_MATRIX_Y_SIZE 0x05
45#define MXT_OBJECT_NUM 0x06
46#define MXT_OBJECT_START 0x07
47
48#define MXT_OBJECT_SIZE 6
49
50/* Object types */
51#define MXT_DEBUG_DIAGNOSTIC 37
52#define MXT_GEN_MESSAGE 5
53#define MXT_GEN_COMMAND 6
54#define MXT_GEN_POWER 7
55#define MXT_GEN_ACQUIRE 8
56#define MXT_TOUCH_MULTI 9
57#define MXT_TOUCH_KEYARRAY 15
58#define MXT_TOUCH_PROXIMITY 23
59#define MXT_PROCI_GRIPFACE 20
60#define MXT_PROCG_NOISE 22
61#define MXT_PROCI_ONETOUCH 24
62#define MXT_PROCI_TWOTOUCH 27
63#define MXT_PROCI_GRIP 40
64#define MXT_PROCI_PALM 41
65#define MXT_SPT_COMMSCONFIG 18
66#define MXT_SPT_GPIOPWM 19
67#define MXT_SPT_SELFTEST 25
68#define MXT_SPT_CTECONFIG 28
69#define MXT_SPT_USERDATA 38
70#define MXT_SPT_DIGITIZER 43
71#define MXT_SPT_MESSAGECOUNT 44
72
73/* MXT_GEN_COMMAND field */
74#define MXT_COMMAND_RESET 0
75#define MXT_COMMAND_BACKUPNV 1
76#define MXT_COMMAND_CALIBRATE 2
77#define MXT_COMMAND_REPORTALL 3
78#define MXT_COMMAND_DIAGNOSTIC 5
79
80/* MXT_GEN_POWER field */
81#define MXT_POWER_IDLEACQINT 0
82#define MXT_POWER_ACTVACQINT 1
83#define MXT_POWER_ACTV2IDLETO 2
84
85/* MXT_GEN_ACQUIRE field */
86#define MXT_ACQUIRE_CHRGTIME 0
87#define MXT_ACQUIRE_TCHDRIFT 2
88#define MXT_ACQUIRE_DRIFTST 3
89#define MXT_ACQUIRE_TCHAUTOCAL 4
90#define MXT_ACQUIRE_SYNC 5
91#define MXT_ACQUIRE_ATCHCALST 6
92#define MXT_ACQUIRE_ATCHCALSTHR 7
93
94/* MXT_TOUCH_MULTI field */
95#define MXT_TOUCH_CTRL 0
96#define MXT_TOUCH_XORIGIN 1
97#define MXT_TOUCH_YORIGIN 2
98#define MXT_TOUCH_XSIZE 3
99#define MXT_TOUCH_YSIZE 4
100#define MXT_TOUCH_BLEN 6
101#define MXT_TOUCH_TCHTHR 7
102#define MXT_TOUCH_TCHDI 8
103#define MXT_TOUCH_ORIENT 9
104#define MXT_TOUCH_MOVHYSTI 11
105#define MXT_TOUCH_MOVHYSTN 12
106#define MXT_TOUCH_NUMTOUCH 14
107#define MXT_TOUCH_MRGHYST 15
108#define MXT_TOUCH_MRGTHR 16
109#define MXT_TOUCH_AMPHYST 17
110#define MXT_TOUCH_XRANGE_LSB 18
111#define MXT_TOUCH_XRANGE_MSB 19
112#define MXT_TOUCH_YRANGE_LSB 20
113#define MXT_TOUCH_YRANGE_MSB 21
114#define MXT_TOUCH_XLOCLIP 22
115#define MXT_TOUCH_XHICLIP 23
116#define MXT_TOUCH_YLOCLIP 24
117#define MXT_TOUCH_YHICLIP 25
118#define MXT_TOUCH_XEDGECTRL 26
119#define MXT_TOUCH_XEDGEDIST 27
120#define MXT_TOUCH_YEDGECTRL 28
121#define MXT_TOUCH_YEDGEDIST 29
122#define MXT_TOUCH_JUMPLIMIT 30
123
124/* MXT_PROCI_GRIPFACE field */
125#define MXT_GRIPFACE_CTRL 0
126#define MXT_GRIPFACE_XLOGRIP 1
127#define MXT_GRIPFACE_XHIGRIP 2
128#define MXT_GRIPFACE_YLOGRIP 3
129#define MXT_GRIPFACE_YHIGRIP 4
130#define MXT_GRIPFACE_MAXTCHS 5
131#define MXT_GRIPFACE_SZTHR1 7
132#define MXT_GRIPFACE_SZTHR2 8
133#define MXT_GRIPFACE_SHPTHR1 9
134#define MXT_GRIPFACE_SHPTHR2 10
135#define MXT_GRIPFACE_SUPEXTTO 11
136
137/* MXT_PROCI_NOISE field */
138#define MXT_NOISE_CTRL 0
139#define MXT_NOISE_OUTFLEN 1
140#define MXT_NOISE_GCAFUL_LSB 3
141#define MXT_NOISE_GCAFUL_MSB 4
142#define MXT_NOISE_GCAFLL_LSB 5
143#define MXT_NOISE_GCAFLL_MSB 6
144#define MXT_NOISE_ACTVGCAFVALID 7
145#define MXT_NOISE_NOISETHR 8
146#define MXT_NOISE_FREQHOPSCALE 10
147#define MXT_NOISE_FREQ0 11
148#define MXT_NOISE_FREQ1 12
149#define MXT_NOISE_FREQ2 13
150#define MXT_NOISE_FREQ3 14
151#define MXT_NOISE_FREQ4 15
152#define MXT_NOISE_IDLEGCAFVALID 16
153
154/* MXT_SPT_COMMSCONFIG */
155#define MXT_COMMS_CTRL 0
156#define MXT_COMMS_CMD 1
157
158/* MXT_SPT_CTECONFIG field */
159#define MXT_CTE_CTRL 0
160#define MXT_CTE_CMD 1
161#define MXT_CTE_MODE 2
162#define MXT_CTE_IDLEGCAFDEPTH 3
163#define MXT_CTE_ACTVGCAFDEPTH 4
164#define MXT_CTE_VOLTAGE 5
165
166#define MXT_VOLTAGE_DEFAULT 2700000
167#define MXT_VOLTAGE_STEP 10000
168
169/* Define for MXT_GEN_COMMAND */
170#define MXT_BOOT_VALUE 0xa5
171#define MXT_BACKUP_VALUE 0x55
172#define MXT_BACKUP_TIME 25 /* msec */
173#define MXT_RESET_TIME 65 /* msec */
174
175#define MXT_FWRESET_TIME 175 /* msec */
176
177/* Command to unlock bootloader */
178#define MXT_UNLOCK_CMD_MSB 0xaa
179#define MXT_UNLOCK_CMD_LSB 0xdc
180
181/* Bootloader mode status */
182#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
183#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
184#define MXT_FRAME_CRC_CHECK 0x02
185#define MXT_FRAME_CRC_FAIL 0x03
186#define MXT_FRAME_CRC_PASS 0x04
187#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
188#define MXT_BOOT_STATUS_MASK 0x3f
189
190/* Touch status */
191#define MXT_SUPPRESS (1 << 1)
192#define MXT_AMP (1 << 2)
193#define MXT_VECTOR (1 << 3)
194#define MXT_MOVE (1 << 4)
195#define MXT_RELEASE (1 << 5)
196#define MXT_PRESS (1 << 6)
197#define MXT_DETECT (1 << 7)
198
199/* Touchscreen absolute values */
200#define MXT_MAX_XC 0x3ff
201#define MXT_MAX_YC 0x3ff
202#define MXT_MAX_AREA 0xff
203
204#define MXT_MAX_FINGER 10
205
206struct mxt_info {
207 u8 family_id;
208 u8 variant_id;
209 u8 version;
210 u8 build;
211 u8 matrix_xsize;
212 u8 matrix_ysize;
213 u8 object_num;
214};
215
216struct mxt_object {
217 u8 type;
218 u16 start_address;
219 u8 size;
220 u8 instances;
221 u8 num_report_ids;
222
223 /* to map object and message */
224 u8 max_reportid;
225};
226
227struct mxt_message {
228 u8 reportid;
229 u8 message[7];
230 u8 checksum;
231};
232
233struct mxt_finger {
234 int status;
235 int x;
236 int y;
237 int area;
238};
239
240/* Each client has this additional data */
241struct mxt_data {
242 struct i2c_client *client;
243 struct input_dev *input_dev;
244 const struct mxt_platform_data *pdata;
245 struct mxt_object *object_table;
246 struct mxt_info info;
247 struct mxt_finger finger[MXT_MAX_FINGER];
248 unsigned int irq;
249};
250
251static bool mxt_object_readable(unsigned int type)
252{
253 switch (type) {
254 case MXT_GEN_MESSAGE:
255 case MXT_GEN_COMMAND:
256 case MXT_GEN_POWER:
257 case MXT_GEN_ACQUIRE:
258 case MXT_TOUCH_MULTI:
259 case MXT_TOUCH_KEYARRAY:
260 case MXT_TOUCH_PROXIMITY:
261 case MXT_PROCI_GRIPFACE:
262 case MXT_PROCG_NOISE:
263 case MXT_PROCI_ONETOUCH:
264 case MXT_PROCI_TWOTOUCH:
265 case MXT_PROCI_GRIP:
266 case MXT_PROCI_PALM:
267 case MXT_SPT_COMMSCONFIG:
268 case MXT_SPT_GPIOPWM:
269 case MXT_SPT_SELFTEST:
270 case MXT_SPT_CTECONFIG:
271 case MXT_SPT_USERDATA:
272 return true;
273 default:
274 return false;
275 }
276}
277
278static bool mxt_object_writable(unsigned int type)
279{
280 switch (type) {
281 case MXT_GEN_COMMAND:
282 case MXT_GEN_POWER:
283 case MXT_GEN_ACQUIRE:
284 case MXT_TOUCH_MULTI:
285 case MXT_TOUCH_KEYARRAY:
286 case MXT_TOUCH_PROXIMITY:
287 case MXT_PROCI_GRIPFACE:
288 case MXT_PROCG_NOISE:
289 case MXT_PROCI_ONETOUCH:
290 case MXT_PROCI_TWOTOUCH:
291 case MXT_PROCI_GRIP:
292 case MXT_PROCI_PALM:
293 case MXT_SPT_GPIOPWM:
294 case MXT_SPT_SELFTEST:
295 case MXT_SPT_CTECONFIG:
296 return true;
297 default:
298 return false;
299 }
300}
301
302static void mxt_dump_message(struct device *dev,
303 struct mxt_message *message)
304{
305 dev_dbg(dev, "reportid:\t0x%x\n", message->reportid);
306 dev_dbg(dev, "message1:\t0x%x\n", message->message[0]);
307 dev_dbg(dev, "message2:\t0x%x\n", message->message[1]);
308 dev_dbg(dev, "message3:\t0x%x\n", message->message[2]);
309 dev_dbg(dev, "message4:\t0x%x\n", message->message[3]);
310 dev_dbg(dev, "message5:\t0x%x\n", message->message[4]);
311 dev_dbg(dev, "message6:\t0x%x\n", message->message[5]);
312 dev_dbg(dev, "message7:\t0x%x\n", message->message[6]);
313 dev_dbg(dev, "checksum:\t0x%x\n", message->checksum);
314}
315
316static int mxt_check_bootloader(struct i2c_client *client,
317 unsigned int state)
318{
319 u8 val;
320
321recheck:
322 if (i2c_master_recv(client, &val, 1) != 1) {
323 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
324 return -EIO;
325 }
326
327 switch (state) {
328 case MXT_WAITING_BOOTLOAD_CMD:
329 case MXT_WAITING_FRAME_DATA:
330 val &= ~MXT_BOOT_STATUS_MASK;
331 break;
332 case MXT_FRAME_CRC_PASS:
333 if (val == MXT_FRAME_CRC_CHECK)
334 goto recheck;
335 break;
336 default:
337 return -EINVAL;
338 }
339
340 if (val != state) {
341 dev_err(&client->dev, "Unvalid bootloader mode state\n");
342 return -EINVAL;
343 }
344
345 return 0;
346}
347
348static int mxt_unlock_bootloader(struct i2c_client *client)
349{
350 u8 buf[2];
351
352 buf[0] = MXT_UNLOCK_CMD_LSB;
353 buf[1] = MXT_UNLOCK_CMD_MSB;
354
355 if (i2c_master_send(client, buf, 2) != 2) {
356 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
357 return -EIO;
358 }
359
360 return 0;
361}
362
363static int mxt_fw_write(struct i2c_client *client,
364 const u8 *data, unsigned int frame_size)
365{
366 if (i2c_master_send(client, data, frame_size) != frame_size) {
367 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
368 return -EIO;
369 }
370
371 return 0;
372}
373
374static int __mxt_read_reg(struct i2c_client *client,
375 u16 reg, u16 len, void *val)
376{
377 struct i2c_msg xfer[2];
378 u8 buf[2];
379
380 buf[0] = reg & 0xff;
381 buf[1] = (reg >> 8) & 0xff;
382
383 /* Write register */
384 xfer[0].addr = client->addr;
385 xfer[0].flags = 0;
386 xfer[0].len = 2;
387 xfer[0].buf = buf;
388
389 /* Read data */
390 xfer[1].addr = client->addr;
391 xfer[1].flags = I2C_M_RD;
392 xfer[1].len = len;
393 xfer[1].buf = val;
394
395 if (i2c_transfer(client->adapter, xfer, 2) != 2) {
396 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
397 return -EIO;
398 }
399
400 return 0;
401}
402
403static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
404{
405 return __mxt_read_reg(client, reg, 1, val);
406}
407
408static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
409{
410 u8 buf[3];
411
412 buf[0] = reg & 0xff;
413 buf[1] = (reg >> 8) & 0xff;
414 buf[2] = val;
415
416 if (i2c_master_send(client, buf, 3) != 3) {
417 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
418 return -EIO;
419 }
420
421 return 0;
422}
423
424static int mxt_read_object_table(struct i2c_client *client,
425 u16 reg, u8 *object_buf)
426{
427 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
428 object_buf);
429}
430
431static struct mxt_object *
432mxt_get_object(struct mxt_data *data, u8 type)
433{
434 struct mxt_object *object;
435 int i;
436
437 for (i = 0; i < data->info.object_num; i++) {
438 object = data->object_table + i;
439 if (object->type == type)
440 return object;
441 }
442
443 dev_err(&data->client->dev, "Invalid object type\n");
444 return NULL;
445}
446
447static int mxt_read_message(struct mxt_data *data,
448 struct mxt_message *message)
449{
450 struct mxt_object *object;
451 u16 reg;
452
453 object = mxt_get_object(data, MXT_GEN_MESSAGE);
454 if (!object)
455 return -EINVAL;
456
457 reg = object->start_address;
458 return __mxt_read_reg(data->client, reg,
459 sizeof(struct mxt_message), message);
460}
461
462static int mxt_read_object(struct mxt_data *data,
463 u8 type, u8 offset, u8 *val)
464{
465 struct mxt_object *object;
466 u16 reg;
467
468 object = mxt_get_object(data, type);
469 if (!object)
470 return -EINVAL;
471
472 reg = object->start_address;
473 return __mxt_read_reg(data->client, reg + offset, 1, val);
474}
475
476static int mxt_write_object(struct mxt_data *data,
477 u8 type, u8 offset, u8 val)
478{
479 struct mxt_object *object;
480 u16 reg;
481
482 object = mxt_get_object(data, type);
483 if (!object)
484 return -EINVAL;
485
486 reg = object->start_address;
487 return mxt_write_reg(data->client, reg + offset, val);
488}
489
490static void mxt_input_report(struct mxt_data *data, int single_id)
491{
492 struct mxt_finger *finger = data->finger;
493 struct input_dev *input_dev = data->input_dev;
494 int status = finger[single_id].status;
495 int finger_num = 0;
496 int id;
497
498 for (id = 0; id < MXT_MAX_FINGER; id++) {
499 if (!finger[id].status)
500 continue;
501
502 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
503 finger[id].status != MXT_RELEASE ?
504 finger[id].area : 0);
505 input_report_abs(input_dev, ABS_MT_POSITION_X,
506 finger[id].x);
507 input_report_abs(input_dev, ABS_MT_POSITION_Y,
508 finger[id].y);
509 input_mt_sync(input_dev);
510
511 if (finger[id].status == MXT_RELEASE)
512 finger[id].status = 0;
513 else
514 finger_num++;
515 }
516
517 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
518
519 if (status != MXT_RELEASE) {
520 input_report_abs(input_dev, ABS_X, finger[single_id].x);
521 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
522 }
523
524 input_sync(input_dev);
525}
526
527static void mxt_input_touchevent(struct mxt_data *data,
528 struct mxt_message *message, int id)
529{
530 struct mxt_finger *finger = data->finger;
531 struct device *dev = &data->client->dev;
532 u8 status = message->message[0];
533 int x;
534 int y;
535 int area;
536
537 /* Check the touch is present on the screen */
538 if (!(status & MXT_DETECT)) {
539 if (status & MXT_RELEASE) {
540 dev_dbg(dev, "[%d] released\n", id);
541
542 finger[id].status = MXT_RELEASE;
543 mxt_input_report(data, id);
544 }
545 return;
546 }
547
548 /* Check only AMP detection */
549 if (!(status & (MXT_PRESS | MXT_MOVE)))
550 return;
551
552 x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6);
553 y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2);
554 area = message->message[4];
555
556 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
557 status & MXT_MOVE ? "moved" : "pressed",
558 x, y, area);
559
560 finger[id].status = status & MXT_MOVE ?
561 MXT_MOVE : MXT_PRESS;
562 finger[id].x = x;
563 finger[id].y = y;
564 finger[id].area = area;
565
566 mxt_input_report(data, id);
567}
568
569static irqreturn_t mxt_interrupt(int irq, void *dev_id)
570{
571 struct mxt_data *data = dev_id;
572 struct mxt_message message;
573 struct mxt_object *object;
574 struct device *dev = &data->client->dev;
575 int id;
576 u8 reportid;
577 u8 max_reportid;
578 u8 min_reportid;
579
580 do {
581 if (mxt_read_message(data, &message)) {
582 dev_err(dev, "Failed to read message\n");
583 goto end;
584 }
585
586 reportid = message.reportid;
587
588 /* whether reportid is thing of MXT_TOUCH_MULTI */
589 object = mxt_get_object(data, MXT_TOUCH_MULTI);
590 if (!object)
591 goto end;
592
593 max_reportid = object->max_reportid;
594 min_reportid = max_reportid - object->num_report_ids + 1;
595 id = reportid - min_reportid;
596
597 if (reportid >= min_reportid && reportid <= max_reportid)
598 mxt_input_touchevent(data, &message, id);
599 else
600 mxt_dump_message(dev, &message);
601 } while (reportid != 0xff);
602
603end:
604 return IRQ_HANDLED;
605}
606
607static int mxt_check_reg_init(struct mxt_data *data)
608{
609 const struct mxt_platform_data *pdata = data->pdata;
610 struct mxt_object *object;
611 struct device *dev = &data->client->dev;
612 int index = 0;
613 int i, j, config_offset;
614
615 if (!pdata->config) {
616 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
617 return 0;
618 }
619
620 for (i = 0; i < data->info.object_num; i++) {
621 object = data->object_table + i;
622
623 if (!mxt_object_writable(object->type))
624 continue;
625
626 for (j = 0; j < object->size + 1; j++) {
627 config_offset = index + j;
628 if (config_offset > pdata->config_length) {
629 dev_err(dev, "Not enough config data!\n");
630 return -EINVAL;
631 }
632 mxt_write_object(data, object->type, j,
633 pdata->config[config_offset]);
634 }
635 index += object->size + 1;
636 }
637
638 return 0;
639}
640
641static int mxt_make_highchg(struct mxt_data *data)
642{
643 struct device *dev = &data->client->dev;
644 struct mxt_message message;
645 int count = 10;
646 int error;
647
648 /* Read dummy message to make high CHG pin */
649 do {
650 error = mxt_read_message(data, &message);
651 if (error)
652 return error;
653 } while (message.reportid != 0xff && --count);
654
655 if (!count) {
656 dev_err(dev, "CHG pin isn't cleared\n");
657 return -EBUSY;
658 }
659
660 return 0;
661}
662
663static void mxt_handle_pdata(struct mxt_data *data)
664{
665 const struct mxt_platform_data *pdata = data->pdata;
666 u8 voltage;
667
668 /* Set touchscreen lines */
669 mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_XSIZE,
670 pdata->x_line);
671 mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_YSIZE,
672 pdata->y_line);
673
674 /* Set touchscreen orient */
675 mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_ORIENT,
676 pdata->orient);
677
678 /* Set touchscreen burst length */
679 mxt_write_object(data, MXT_TOUCH_MULTI,
680 MXT_TOUCH_BLEN, pdata->blen);
681
682 /* Set touchscreen threshold */
683 mxt_write_object(data, MXT_TOUCH_MULTI,
684 MXT_TOUCH_TCHTHR, pdata->threshold);
685
686 /* Set touchscreen resolution */
687 mxt_write_object(data, MXT_TOUCH_MULTI,
688 MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
689 mxt_write_object(data, MXT_TOUCH_MULTI,
690 MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
691 mxt_write_object(data, MXT_TOUCH_MULTI,
692 MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
693 mxt_write_object(data, MXT_TOUCH_MULTI,
694 MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
695
696 /* Set touchscreen voltage */
697 if (pdata->voltage) {
698 if (pdata->voltage < MXT_VOLTAGE_DEFAULT) {
699 voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) /
700 MXT_VOLTAGE_STEP;
701 voltage = 0xff - voltage + 1;
702 } else
703 voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) /
704 MXT_VOLTAGE_STEP;
705
706 mxt_write_object(data, MXT_SPT_CTECONFIG,
707 MXT_CTE_VOLTAGE, voltage);
708 }
709}
710
711static int mxt_get_info(struct mxt_data *data)
712{
713 struct i2c_client *client = data->client;
714 struct mxt_info *info = &data->info;
715 int error;
716 u8 val;
717
718 error = mxt_read_reg(client, MXT_FAMILY_ID, &val);
719 if (error)
720 return error;
721 info->family_id = val;
722
723 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
724 if (error)
725 return error;
726 info->variant_id = val;
727
728 error = mxt_read_reg(client, MXT_VERSION, &val);
729 if (error)
730 return error;
731 info->version = val;
732
733 error = mxt_read_reg(client, MXT_BUILD, &val);
734 if (error)
735 return error;
736 info->build = val;
737
738 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
739 if (error)
740 return error;
741 info->object_num = val;
742
743 return 0;
744}
745
746static int mxt_get_object_table(struct mxt_data *data)
747{
748 int error;
749 int i;
750 u16 reg;
751 u8 reportid = 0;
752 u8 buf[MXT_OBJECT_SIZE];
753
754 for (i = 0; i < data->info.object_num; i++) {
755 struct mxt_object *object = data->object_table + i;
756
757 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
758 error = mxt_read_object_table(data->client, reg, buf);
759 if (error)
760 return error;
761
762 object->type = buf[0];
763 object->start_address = (buf[2] << 8) | buf[1];
764 object->size = buf[3];
765 object->instances = buf[4];
766 object->num_report_ids = buf[5];
767
768 if (object->num_report_ids) {
769 reportid += object->num_report_ids *
770 (object->instances + 1);
771 object->max_reportid = reportid;
772 }
773 }
774
775 return 0;
776}
777
778static int mxt_initialize(struct mxt_data *data)
779{
780 struct i2c_client *client = data->client;
781 struct mxt_info *info = &data->info;
782 int error;
783 u8 val;
784
785 error = mxt_get_info(data);
786 if (error)
787 return error;
788
789 data->object_table = kcalloc(info->object_num,
790 sizeof(struct mxt_object),
791 GFP_KERNEL);
792 if (!data->object_table) {
793 dev_err(&client->dev, "Failed to allocate memory\n");
794 return -ENOMEM;
795 }
796
797 /* Get object table information */
798 error = mxt_get_object_table(data);
799 if (error)
800 return error;
801
802 /* Check register init values */
803 error = mxt_check_reg_init(data);
804 if (error)
805 return error;
806
807 error = mxt_make_highchg(data);
808 if (error)
809 return error;
810
811 mxt_handle_pdata(data);
812
813 /* Backup to memory */
814 mxt_write_object(data, MXT_GEN_COMMAND,
815 MXT_COMMAND_BACKUPNV,
816 MXT_BACKUP_VALUE);
817 msleep(MXT_BACKUP_TIME);
818
819 /* Soft reset */
820 mxt_write_object(data, MXT_GEN_COMMAND,
821 MXT_COMMAND_RESET, 1);
822 msleep(MXT_RESET_TIME);
823
824 /* Update matrix size at info struct */
825 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
826 if (error)
827 return error;
828 info->matrix_xsize = val;
829
830 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
831 if (error)
832 return error;
833 info->matrix_ysize = val;
834
835 dev_info(&client->dev,
836 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
837 info->family_id, info->variant_id, info->version,
838 info->build);
839
840 dev_info(&client->dev,
841 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
842 info->matrix_xsize, info->matrix_ysize,
843 info->object_num);
844
845 return 0;
846}
847
848static ssize_t mxt_object_show(struct device *dev,
849 struct device_attribute *attr, char *buf)
850{
851 struct mxt_data *data = dev_get_drvdata(dev);
852 struct mxt_object *object;
853 int count = 0;
854 int i, j;
855 int error;
856 u8 val;
857
858 for (i = 0; i < data->info.object_num; i++) {
859 object = data->object_table + i;
860
861 count += sprintf(buf + count,
862 "Object Table Element %d(Type %d)\n",
863 i + 1, object->type);
864
865 if (!mxt_object_readable(object->type)) {
866 count += sprintf(buf + count, "\n");
867 continue;
868 }
869
870 for (j = 0; j < object->size + 1; j++) {
871 error = mxt_read_object(data,
872 object->type, j, &val);
873 if (error)
874 return error;
875
876 count += sprintf(buf + count,
877 " Byte %d: 0x%x (%d)\n", j, val, val);
878 }
879
880 count += sprintf(buf + count, "\n");
881 }
882
883 return count;
884}
885
886static int mxt_load_fw(struct device *dev, const char *fn)
887{
888 struct mxt_data *data = dev_get_drvdata(dev);
889 struct i2c_client *client = data->client;
890 const struct firmware *fw = NULL;
891 unsigned int frame_size;
892 unsigned int pos = 0;
893 int ret;
894
895 ret = request_firmware(&fw, fn, dev);
896 if (ret) {
897 dev_err(dev, "Unable to open firmware %s\n", fn);
898 return ret;
899 }
900
901 /* Change to the bootloader mode */
902 mxt_write_object(data, MXT_GEN_COMMAND,
903 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
904 msleep(MXT_RESET_TIME);
905
906 /* Change to slave address of bootloader */
907 if (client->addr == MXT_APP_LOW)
908 client->addr = MXT_BOOT_LOW;
909 else
910 client->addr = MXT_BOOT_HIGH;
911
912 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
913 if (ret)
914 goto out;
915
916 /* Unlock bootloader */
917 mxt_unlock_bootloader(client);
918
919 while (pos < fw->size) {
920 ret = mxt_check_bootloader(client,
921 MXT_WAITING_FRAME_DATA);
922 if (ret)
923 goto out;
924
925 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
926
927 /* We should add 2 at frame size as the the firmware data is not
928 * included the CRC bytes.
929 */
930 frame_size += 2;
931
932 /* Write one frame to device */
933 mxt_fw_write(client, fw->data + pos, frame_size);
934
935 ret = mxt_check_bootloader(client,
936 MXT_FRAME_CRC_PASS);
937 if (ret)
938 goto out;
939
940 pos += frame_size;
941
942 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
943 }
944
945out:
946 release_firmware(fw);
947
948 /* Change to slave address of application */
949 if (client->addr == MXT_BOOT_LOW)
950 client->addr = MXT_APP_LOW;
951 else
952 client->addr = MXT_APP_HIGH;
953
954 return ret;
955}
956
957static ssize_t mxt_update_fw_store(struct device *dev,
958 struct device_attribute *attr,
959 const char *buf, size_t count)
960{
961 struct mxt_data *data = dev_get_drvdata(dev);
962 int error;
963
964 disable_irq(data->irq);
965
966 error = mxt_load_fw(dev, MXT_FW_NAME);
967 if (error) {
968 dev_err(dev, "The firmware update failed(%d)\n", error);
969 count = error;
970 } else {
971 dev_dbg(dev, "The firmware update succeeded\n");
972
973 /* Wait for reset */
974 msleep(MXT_FWRESET_TIME);
975
976 kfree(data->object_table);
977 data->object_table = NULL;
978
979 mxt_initialize(data);
980 }
981
982 enable_irq(data->irq);
983
984 return count;
985}
986
987static DEVICE_ATTR(object, 0444, mxt_object_show, NULL);
988static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store);
989
990static struct attribute *mxt_attrs[] = {
991 &dev_attr_object.attr,
992 &dev_attr_update_fw.attr,
993 NULL
994};
995
996static const struct attribute_group mxt_attr_group = {
997 .attrs = mxt_attrs,
998};
999
1000static void mxt_start(struct mxt_data *data)
1001{
1002 /* Touch enable */
1003 mxt_write_object(data,
1004 MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0x83);
1005}
1006
1007static void mxt_stop(struct mxt_data *data)
1008{
1009 /* Touch disable */
1010 mxt_write_object(data,
1011 MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0);
1012}
1013
1014static int mxt_input_open(struct input_dev *dev)
1015{
1016 struct mxt_data *data = input_get_drvdata(dev);
1017
1018 mxt_start(data);
1019
1020 return 0;
1021}
1022
1023static void mxt_input_close(struct input_dev *dev)
1024{
1025 struct mxt_data *data = input_get_drvdata(dev);
1026
1027 mxt_stop(data);
1028}
1029
1030static int __devinit mxt_probe(struct i2c_client *client,
1031 const struct i2c_device_id *id)
1032{
1033 const struct mxt_platform_data *pdata = client->dev.platform_data;
1034 struct mxt_data *data;
1035 struct input_dev *input_dev;
1036 int error;
1037
1038 if (!pdata)
1039 return -EINVAL;
1040
1041 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
1042 input_dev = input_allocate_device();
1043 if (!data || !input_dev) {
1044 dev_err(&client->dev, "Failed to allocate memory\n");
1045 error = -ENOMEM;
1046 goto err_free_mem;
1047 }
1048
1049 input_dev->name = "Atmel maXTouch Touchscreen";
1050 input_dev->id.bustype = BUS_I2C;
1051 input_dev->dev.parent = &client->dev;
1052 input_dev->open = mxt_input_open;
1053 input_dev->close = mxt_input_close;
1054
1055 __set_bit(EV_ABS, input_dev->evbit);
1056 __set_bit(EV_KEY, input_dev->evbit);
1057 __set_bit(BTN_TOUCH, input_dev->keybit);
1058
1059 /* For single touch */
1060 input_set_abs_params(input_dev, ABS_X,
1061 0, MXT_MAX_XC, 0, 0);
1062 input_set_abs_params(input_dev, ABS_Y,
1063 0, MXT_MAX_YC, 0, 0);
1064
1065 /* For multi touch */
1066 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1067 0, MXT_MAX_AREA, 0, 0);
1068 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1069 0, MXT_MAX_XC, 0, 0);
1070 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1071 0, MXT_MAX_YC, 0, 0);
1072
1073 input_set_drvdata(input_dev, data);
1074
1075 data->client = client;
1076 data->input_dev = input_dev;
1077 data->pdata = pdata;
1078 data->irq = client->irq;
1079
1080 i2c_set_clientdata(client, data);
1081
1082 error = mxt_initialize(data);
1083 if (error)
1084 goto err_free_object;
1085
1086 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1087 pdata->irqflags, client->dev.driver->name, data);
1088 if (error) {
1089 dev_err(&client->dev, "Failed to register interrupt\n");
1090 goto err_free_object;
1091 }
1092
1093 error = input_register_device(input_dev);
1094 if (error)
1095 goto err_free_irq;
1096
1097 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
1098 if (error)
1099 goto err_unregister_device;
1100
1101 return 0;
1102
1103err_unregister_device:
1104 input_unregister_device(input_dev);
1105 input_dev = NULL;
1106err_free_irq:
1107 free_irq(client->irq, data);
1108err_free_object:
1109 kfree(data->object_table);
1110err_free_mem:
1111 input_free_device(input_dev);
1112 kfree(data);
1113 return error;
1114}
1115
1116static int __devexit mxt_remove(struct i2c_client *client)
1117{
1118 struct mxt_data *data = i2c_get_clientdata(client);
1119
1120 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
1121 free_irq(data->irq, data);
1122 input_unregister_device(data->input_dev);
1123 kfree(data->object_table);
1124 kfree(data);
1125
1126 return 0;
1127}
1128
1129#ifdef CONFIG_PM
1130static int mxt_suspend(struct device *dev)
1131{
1132 struct i2c_client *client = to_i2c_client(dev);
1133 struct mxt_data *data = i2c_get_clientdata(client);
1134 struct input_dev *input_dev = data->input_dev;
1135
1136 mutex_lock(&input_dev->mutex);
1137
1138 if (input_dev->users)
1139 mxt_stop(data);
1140
1141 mutex_unlock(&input_dev->mutex);
1142
1143 return 0;
1144}
1145
1146static int mxt_resume(struct device *dev)
1147{
1148 struct i2c_client *client = to_i2c_client(dev);
1149 struct mxt_data *data = i2c_get_clientdata(client);
1150 struct input_dev *input_dev = data->input_dev;
1151
1152 /* Soft reset */
1153 mxt_write_object(data, MXT_GEN_COMMAND,
1154 MXT_COMMAND_RESET, 1);
1155
1156 msleep(MXT_RESET_TIME);
1157
1158 mutex_lock(&input_dev->mutex);
1159
1160 if (input_dev->users)
1161 mxt_start(data);
1162
1163 mutex_unlock(&input_dev->mutex);
1164
1165 return 0;
1166}
1167
1168static const struct dev_pm_ops mxt_pm_ops = {
1169 .suspend = mxt_suspend,
1170 .resume = mxt_resume,
1171};
1172#endif
1173
1174static const struct i2c_device_id mxt_id[] = {
1175 { "qt602240_ts", 0 },
1176 { "atmel_mxt_ts", 0 },
1177 { "mXT224", 0 },
1178 { }
1179};
1180MODULE_DEVICE_TABLE(i2c, mxt_id);
1181
1182static struct i2c_driver mxt_driver = {
1183 .driver = {
1184 .name = "atmel_mxt_ts",
1185 .owner = THIS_MODULE,
1186#ifdef CONFIG_PM
1187 .pm = &mxt_pm_ops,
1188#endif
1189 },
1190 .probe = mxt_probe,
1191 .remove = __devexit_p(mxt_remove),
1192 .id_table = mxt_id,
1193};
1194
1195static int __init mxt_init(void)
1196{
1197 return i2c_add_driver(&mxt_driver);
1198}
1199
1200static void __exit mxt_exit(void)
1201{
1202 i2c_del_driver(&mxt_driver);
1203}
1204
1205module_init(mxt_init);
1206module_exit(mxt_exit);
1207
1208/* Module information */
1209MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
1210MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
1211MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/qt602240_ts.c b/drivers/input/touchscreen/qt602240_ts.c
deleted file mode 100644
index 4dcb0e872f6a..000000000000
--- a/drivers/input/touchscreen/qt602240_ts.c
+++ /dev/null
@@ -1,1406 +0,0 @@
1/*
2 * AT42QT602240/ATMXT224 Touchscreen driver
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/firmware.h>
18#include <linux/i2c.h>
19#include <linux/i2c/qt602240_ts.h>
20#include <linux/input.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23
24/* Version */
25#define QT602240_VER_20 20
26#define QT602240_VER_21 21
27#define QT602240_VER_22 22
28
29/* Slave addresses */
30#define QT602240_APP_LOW 0x4a
31#define QT602240_APP_HIGH 0x4b
32#define QT602240_BOOT_LOW 0x24
33#define QT602240_BOOT_HIGH 0x25
34
35/* Firmware */
36#define QT602240_FW_NAME "qt602240.fw"
37
38/* Registers */
39#define QT602240_FAMILY_ID 0x00
40#define QT602240_VARIANT_ID 0x01
41#define QT602240_VERSION 0x02
42#define QT602240_BUILD 0x03
43#define QT602240_MATRIX_X_SIZE 0x04
44#define QT602240_MATRIX_Y_SIZE 0x05
45#define QT602240_OBJECT_NUM 0x06
46#define QT602240_OBJECT_START 0x07
47
48#define QT602240_OBJECT_SIZE 6
49
50/* Object types */
51#define QT602240_DEBUG_DIAGNOSTIC 37
52#define QT602240_GEN_MESSAGE 5
53#define QT602240_GEN_COMMAND 6
54#define QT602240_GEN_POWER 7
55#define QT602240_GEN_ACQUIRE 8
56#define QT602240_TOUCH_MULTI 9
57#define QT602240_TOUCH_KEYARRAY 15
58#define QT602240_TOUCH_PROXIMITY 23
59#define QT602240_PROCI_GRIPFACE 20
60#define QT602240_PROCG_NOISE 22
61#define QT602240_PROCI_ONETOUCH 24
62#define QT602240_PROCI_TWOTOUCH 27
63#define QT602240_SPT_COMMSCONFIG 18 /* firmware ver 21 over */
64#define QT602240_SPT_GPIOPWM 19
65#define QT602240_SPT_SELFTEST 25
66#define QT602240_SPT_CTECONFIG 28
67#define QT602240_SPT_USERDATA 38 /* firmware ver 21 over */
68
69/* QT602240_GEN_COMMAND field */
70#define QT602240_COMMAND_RESET 0
71#define QT602240_COMMAND_BACKUPNV 1
72#define QT602240_COMMAND_CALIBRATE 2
73#define QT602240_COMMAND_REPORTALL 3
74#define QT602240_COMMAND_DIAGNOSTIC 5
75
76/* QT602240_GEN_POWER field */
77#define QT602240_POWER_IDLEACQINT 0
78#define QT602240_POWER_ACTVACQINT 1
79#define QT602240_POWER_ACTV2IDLETO 2
80
81/* QT602240_GEN_ACQUIRE field */
82#define QT602240_ACQUIRE_CHRGTIME 0
83#define QT602240_ACQUIRE_TCHDRIFT 2
84#define QT602240_ACQUIRE_DRIFTST 3
85#define QT602240_ACQUIRE_TCHAUTOCAL 4
86#define QT602240_ACQUIRE_SYNC 5
87#define QT602240_ACQUIRE_ATCHCALST 6
88#define QT602240_ACQUIRE_ATCHCALSTHR 7
89
90/* QT602240_TOUCH_MULTI field */
91#define QT602240_TOUCH_CTRL 0
92#define QT602240_TOUCH_XORIGIN 1
93#define QT602240_TOUCH_YORIGIN 2
94#define QT602240_TOUCH_XSIZE 3
95#define QT602240_TOUCH_YSIZE 4
96#define QT602240_TOUCH_BLEN 6
97#define QT602240_TOUCH_TCHTHR 7
98#define QT602240_TOUCH_TCHDI 8
99#define QT602240_TOUCH_ORIENT 9
100#define QT602240_TOUCH_MOVHYSTI 11
101#define QT602240_TOUCH_MOVHYSTN 12
102#define QT602240_TOUCH_NUMTOUCH 14
103#define QT602240_TOUCH_MRGHYST 15
104#define QT602240_TOUCH_MRGTHR 16
105#define QT602240_TOUCH_AMPHYST 17
106#define QT602240_TOUCH_XRANGE_LSB 18
107#define QT602240_TOUCH_XRANGE_MSB 19
108#define QT602240_TOUCH_YRANGE_LSB 20
109#define QT602240_TOUCH_YRANGE_MSB 21
110#define QT602240_TOUCH_XLOCLIP 22
111#define QT602240_TOUCH_XHICLIP 23
112#define QT602240_TOUCH_YLOCLIP 24
113#define QT602240_TOUCH_YHICLIP 25
114#define QT602240_TOUCH_XEDGECTRL 26
115#define QT602240_TOUCH_XEDGEDIST 27
116#define QT602240_TOUCH_YEDGECTRL 28
117#define QT602240_TOUCH_YEDGEDIST 29
118#define QT602240_TOUCH_JUMPLIMIT 30 /* firmware ver 22 over */
119
120/* QT602240_PROCI_GRIPFACE field */
121#define QT602240_GRIPFACE_CTRL 0
122#define QT602240_GRIPFACE_XLOGRIP 1
123#define QT602240_GRIPFACE_XHIGRIP 2
124#define QT602240_GRIPFACE_YLOGRIP 3
125#define QT602240_GRIPFACE_YHIGRIP 4
126#define QT602240_GRIPFACE_MAXTCHS 5
127#define QT602240_GRIPFACE_SZTHR1 7
128#define QT602240_GRIPFACE_SZTHR2 8
129#define QT602240_GRIPFACE_SHPTHR1 9
130#define QT602240_GRIPFACE_SHPTHR2 10
131#define QT602240_GRIPFACE_SUPEXTTO 11
132
133/* QT602240_PROCI_NOISE field */
134#define QT602240_NOISE_CTRL 0
135#define QT602240_NOISE_OUTFLEN 1
136#define QT602240_NOISE_GCAFUL_LSB 3
137#define QT602240_NOISE_GCAFUL_MSB 4
138#define QT602240_NOISE_GCAFLL_LSB 5
139#define QT602240_NOISE_GCAFLL_MSB 6
140#define QT602240_NOISE_ACTVGCAFVALID 7
141#define QT602240_NOISE_NOISETHR 8
142#define QT602240_NOISE_FREQHOPSCALE 10
143#define QT602240_NOISE_FREQ0 11
144#define QT602240_NOISE_FREQ1 12
145#define QT602240_NOISE_FREQ2 13
146#define QT602240_NOISE_FREQ3 14
147#define QT602240_NOISE_FREQ4 15
148#define QT602240_NOISE_IDLEGCAFVALID 16
149
150/* QT602240_SPT_COMMSCONFIG */
151#define QT602240_COMMS_CTRL 0
152#define QT602240_COMMS_CMD 1
153
154/* QT602240_SPT_CTECONFIG field */
155#define QT602240_CTE_CTRL 0
156#define QT602240_CTE_CMD 1
157#define QT602240_CTE_MODE 2
158#define QT602240_CTE_IDLEGCAFDEPTH 3
159#define QT602240_CTE_ACTVGCAFDEPTH 4
160#define QT602240_CTE_VOLTAGE 5 /* firmware ver 21 over */
161
162#define QT602240_VOLTAGE_DEFAULT 2700000
163#define QT602240_VOLTAGE_STEP 10000
164
165/* Define for QT602240_GEN_COMMAND */
166#define QT602240_BOOT_VALUE 0xa5
167#define QT602240_BACKUP_VALUE 0x55
168#define QT602240_BACKUP_TIME 25 /* msec */
169#define QT602240_RESET_TIME 65 /* msec */
170
171#define QT602240_FWRESET_TIME 175 /* msec */
172
173/* Command to unlock bootloader */
174#define QT602240_UNLOCK_CMD_MSB 0xaa
175#define QT602240_UNLOCK_CMD_LSB 0xdc
176
177/* Bootloader mode status */
178#define QT602240_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
179#define QT602240_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
180#define QT602240_FRAME_CRC_CHECK 0x02
181#define QT602240_FRAME_CRC_FAIL 0x03
182#define QT602240_FRAME_CRC_PASS 0x04
183#define QT602240_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
184#define QT602240_BOOT_STATUS_MASK 0x3f
185
186/* Touch status */
187#define QT602240_SUPPRESS (1 << 1)
188#define QT602240_AMP (1 << 2)
189#define QT602240_VECTOR (1 << 3)
190#define QT602240_MOVE (1 << 4)
191#define QT602240_RELEASE (1 << 5)
192#define QT602240_PRESS (1 << 6)
193#define QT602240_DETECT (1 << 7)
194
195/* Touchscreen absolute values */
196#define QT602240_MAX_XC 0x3ff
197#define QT602240_MAX_YC 0x3ff
198#define QT602240_MAX_AREA 0xff
199
200#define QT602240_MAX_FINGER 10
201
202/* Initial register values recommended from chip vendor */
203static const u8 init_vals_ver_20[] = {
204 /* QT602240_GEN_COMMAND(6) */
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206 /* QT602240_GEN_POWER(7) */
207 0x20, 0xff, 0x32,
208 /* QT602240_GEN_ACQUIRE(8) */
209 0x08, 0x05, 0x05, 0x00, 0x00, 0x00, 0x05, 0x14,
210 /* QT602240_TOUCH_MULTI(9) */
211 0x00, 0x00, 0x00, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00,
212 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x64,
214 /* QT602240_TOUCH_KEYARRAY(15) */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216 0x00,
217 /* QT602240_SPT_GPIOPWM(19) */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00,
220 /* QT602240_PROCI_GRIPFACE(20) */
221 0x00, 0x64, 0x64, 0x64, 0x64, 0x00, 0x00, 0x1e, 0x14, 0x04,
222 0x1e, 0x00,
223 /* QT602240_PROCG_NOISE(22) */
224 0x05, 0x00, 0x00, 0x19, 0x00, 0xe7, 0xff, 0x04, 0x32, 0x00,
225 0x01, 0x0a, 0x0f, 0x14, 0x00, 0x00, 0xe8,
226 /* QT602240_TOUCH_PROXIMITY(23) */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00,
229 /* QT602240_PROCI_ONETOUCH(24) */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 /* QT602240_SPT_SELFTEST(25) */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00,
235 /* QT602240_PROCI_TWOTOUCH(27) */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 /* QT602240_SPT_CTECONFIG(28) */
238 0x00, 0x00, 0x00, 0x04, 0x08,
239};
240
241static const u8 init_vals_ver_21[] = {
242 /* QT602240_GEN_COMMAND(6) */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 /* QT602240_GEN_POWER(7) */
245 0x20, 0xff, 0x32,
246 /* QT602240_GEN_ACQUIRE(8) */
247 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23,
248 /* QT602240_TOUCH_MULTI(9) */
249 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00,
250 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 /* QT602240_TOUCH_KEYARRAY(15) */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00,
255 /* QT602240_SPT_GPIOPWM(19) */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 /* QT602240_PROCI_GRIPFACE(20) */
259 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04,
260 0x0f, 0x0a,
261 /* QT602240_PROCG_NOISE(22) */
262 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00,
263 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03,
264 /* QT602240_TOUCH_PROXIMITY(23) */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00,
267 /* QT602240_PROCI_ONETOUCH(24) */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 /* QT602240_SPT_SELFTEST(25) */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00,
273 /* QT602240_PROCI_TWOTOUCH(27) */
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275 /* QT602240_SPT_CTECONFIG(28) */
276 0x00, 0x00, 0x00, 0x08, 0x10, 0x00,
277};
278
279static const u8 init_vals_ver_22[] = {
280 /* QT602240_GEN_COMMAND(6) */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 /* QT602240_GEN_POWER(7) */
283 0x20, 0xff, 0x32,
284 /* QT602240_GEN_ACQUIRE(8) */
285 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23,
286 /* QT602240_TOUCH_MULTI(9) */
287 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00,
288 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00,
291 /* QT602240_TOUCH_KEYARRAY(15) */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00,
294 /* QT602240_SPT_GPIOPWM(19) */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297 /* QT602240_PROCI_GRIPFACE(20) */
298 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04,
299 0x0f, 0x0a,
300 /* QT602240_PROCG_NOISE(22) */
301 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00,
302 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03,
303 /* QT602240_TOUCH_PROXIMITY(23) */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00,
306 /* QT602240_PROCI_ONETOUCH(24) */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 /* QT602240_SPT_SELFTEST(25) */
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00,
312 /* QT602240_PROCI_TWOTOUCH(27) */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 /* QT602240_SPT_CTECONFIG(28) */
315 0x00, 0x00, 0x00, 0x08, 0x10, 0x00,
316};
317
318struct qt602240_info {
319 u8 family_id;
320 u8 variant_id;
321 u8 version;
322 u8 build;
323 u8 matrix_xsize;
324 u8 matrix_ysize;
325 u8 object_num;
326};
327
328struct qt602240_object {
329 u8 type;
330 u16 start_address;
331 u8 size;
332 u8 instances;
333 u8 num_report_ids;
334
335 /* to map object and message */
336 u8 max_reportid;
337};
338
339struct qt602240_message {
340 u8 reportid;
341 u8 message[7];
342 u8 checksum;
343};
344
345struct qt602240_finger {
346 int status;
347 int x;
348 int y;
349 int area;
350};
351
352/* Each client has this additional data */
353struct qt602240_data {
354 struct i2c_client *client;
355 struct input_dev *input_dev;
356 const struct qt602240_platform_data *pdata;
357 struct qt602240_object *object_table;
358 struct qt602240_info info;
359 struct qt602240_finger finger[QT602240_MAX_FINGER];
360 unsigned int irq;
361};
362
363static bool qt602240_object_readable(unsigned int type)
364{
365 switch (type) {
366 case QT602240_GEN_MESSAGE:
367 case QT602240_GEN_COMMAND:
368 case QT602240_GEN_POWER:
369 case QT602240_GEN_ACQUIRE:
370 case QT602240_TOUCH_MULTI:
371 case QT602240_TOUCH_KEYARRAY:
372 case QT602240_TOUCH_PROXIMITY:
373 case QT602240_PROCI_GRIPFACE:
374 case QT602240_PROCG_NOISE:
375 case QT602240_PROCI_ONETOUCH:
376 case QT602240_PROCI_TWOTOUCH:
377 case QT602240_SPT_COMMSCONFIG:
378 case QT602240_SPT_GPIOPWM:
379 case QT602240_SPT_SELFTEST:
380 case QT602240_SPT_CTECONFIG:
381 case QT602240_SPT_USERDATA:
382 return true;
383 default:
384 return false;
385 }
386}
387
388static bool qt602240_object_writable(unsigned int type)
389{
390 switch (type) {
391 case QT602240_GEN_COMMAND:
392 case QT602240_GEN_POWER:
393 case QT602240_GEN_ACQUIRE:
394 case QT602240_TOUCH_MULTI:
395 case QT602240_TOUCH_KEYARRAY:
396 case QT602240_TOUCH_PROXIMITY:
397 case QT602240_PROCI_GRIPFACE:
398 case QT602240_PROCG_NOISE:
399 case QT602240_PROCI_ONETOUCH:
400 case QT602240_PROCI_TWOTOUCH:
401 case QT602240_SPT_GPIOPWM:
402 case QT602240_SPT_SELFTEST:
403 case QT602240_SPT_CTECONFIG:
404 return true;
405 default:
406 return false;
407 }
408}
409
410static void qt602240_dump_message(struct device *dev,
411 struct qt602240_message *message)
412{
413 dev_dbg(dev, "reportid:\t0x%x\n", message->reportid);
414 dev_dbg(dev, "message1:\t0x%x\n", message->message[0]);
415 dev_dbg(dev, "message2:\t0x%x\n", message->message[1]);
416 dev_dbg(dev, "message3:\t0x%x\n", message->message[2]);
417 dev_dbg(dev, "message4:\t0x%x\n", message->message[3]);
418 dev_dbg(dev, "message5:\t0x%x\n", message->message[4]);
419 dev_dbg(dev, "message6:\t0x%x\n", message->message[5]);
420 dev_dbg(dev, "message7:\t0x%x\n", message->message[6]);
421 dev_dbg(dev, "checksum:\t0x%x\n", message->checksum);
422}
423
424static int qt602240_check_bootloader(struct i2c_client *client,
425 unsigned int state)
426{
427 u8 val;
428
429recheck:
430 if (i2c_master_recv(client, &val, 1) != 1) {
431 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
432 return -EIO;
433 }
434
435 switch (state) {
436 case QT602240_WAITING_BOOTLOAD_CMD:
437 case QT602240_WAITING_FRAME_DATA:
438 val &= ~QT602240_BOOT_STATUS_MASK;
439 break;
440 case QT602240_FRAME_CRC_PASS:
441 if (val == QT602240_FRAME_CRC_CHECK)
442 goto recheck;
443 break;
444 default:
445 return -EINVAL;
446 }
447
448 if (val != state) {
449 dev_err(&client->dev, "Unvalid bootloader mode state\n");
450 return -EINVAL;
451 }
452
453 return 0;
454}
455
456static int qt602240_unlock_bootloader(struct i2c_client *client)
457{
458 u8 buf[2];
459
460 buf[0] = QT602240_UNLOCK_CMD_LSB;
461 buf[1] = QT602240_UNLOCK_CMD_MSB;
462
463 if (i2c_master_send(client, buf, 2) != 2) {
464 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
465 return -EIO;
466 }
467
468 return 0;
469}
470
471static int qt602240_fw_write(struct i2c_client *client,
472 const u8 *data, unsigned int frame_size)
473{
474 if (i2c_master_send(client, data, frame_size) != frame_size) {
475 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
476 return -EIO;
477 }
478
479 return 0;
480}
481
482static int __qt602240_read_reg(struct i2c_client *client,
483 u16 reg, u16 len, void *val)
484{
485 struct i2c_msg xfer[2];
486 u8 buf[2];
487
488 buf[0] = reg & 0xff;
489 buf[1] = (reg >> 8) & 0xff;
490
491 /* Write register */
492 xfer[0].addr = client->addr;
493 xfer[0].flags = 0;
494 xfer[0].len = 2;
495 xfer[0].buf = buf;
496
497 /* Read data */
498 xfer[1].addr = client->addr;
499 xfer[1].flags = I2C_M_RD;
500 xfer[1].len = len;
501 xfer[1].buf = val;
502
503 if (i2c_transfer(client->adapter, xfer, 2) != 2) {
504 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
505 return -EIO;
506 }
507
508 return 0;
509}
510
511static int qt602240_read_reg(struct i2c_client *client, u16 reg, u8 *val)
512{
513 return __qt602240_read_reg(client, reg, 1, val);
514}
515
516static int qt602240_write_reg(struct i2c_client *client, u16 reg, u8 val)
517{
518 u8 buf[3];
519
520 buf[0] = reg & 0xff;
521 buf[1] = (reg >> 8) & 0xff;
522 buf[2] = val;
523
524 if (i2c_master_send(client, buf, 3) != 3) {
525 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
526 return -EIO;
527 }
528
529 return 0;
530}
531
532static int qt602240_read_object_table(struct i2c_client *client,
533 u16 reg, u8 *object_buf)
534{
535 return __qt602240_read_reg(client, reg, QT602240_OBJECT_SIZE,
536 object_buf);
537}
538
539static struct qt602240_object *
540qt602240_get_object(struct qt602240_data *data, u8 type)
541{
542 struct qt602240_object *object;
543 int i;
544
545 for (i = 0; i < data->info.object_num; i++) {
546 object = data->object_table + i;
547 if (object->type == type)
548 return object;
549 }
550
551 dev_err(&data->client->dev, "Invalid object type\n");
552 return NULL;
553}
554
555static int qt602240_read_message(struct qt602240_data *data,
556 struct qt602240_message *message)
557{
558 struct qt602240_object *object;
559 u16 reg;
560
561 object = qt602240_get_object(data, QT602240_GEN_MESSAGE);
562 if (!object)
563 return -EINVAL;
564
565 reg = object->start_address;
566 return __qt602240_read_reg(data->client, reg,
567 sizeof(struct qt602240_message), message);
568}
569
570static int qt602240_read_object(struct qt602240_data *data,
571 u8 type, u8 offset, u8 *val)
572{
573 struct qt602240_object *object;
574 u16 reg;
575
576 object = qt602240_get_object(data, type);
577 if (!object)
578 return -EINVAL;
579
580 reg = object->start_address;
581 return __qt602240_read_reg(data->client, reg + offset, 1, val);
582}
583
584static int qt602240_write_object(struct qt602240_data *data,
585 u8 type, u8 offset, u8 val)
586{
587 struct qt602240_object *object;
588 u16 reg;
589
590 object = qt602240_get_object(data, type);
591 if (!object)
592 return -EINVAL;
593
594 reg = object->start_address;
595 return qt602240_write_reg(data->client, reg + offset, val);
596}
597
598static void qt602240_input_report(struct qt602240_data *data, int single_id)
599{
600 struct qt602240_finger *finger = data->finger;
601 struct input_dev *input_dev = data->input_dev;
602 int status = finger[single_id].status;
603 int finger_num = 0;
604 int id;
605
606 for (id = 0; id < QT602240_MAX_FINGER; id++) {
607 if (!finger[id].status)
608 continue;
609
610 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
611 finger[id].status != QT602240_RELEASE ?
612 finger[id].area : 0);
613 input_report_abs(input_dev, ABS_MT_POSITION_X,
614 finger[id].x);
615 input_report_abs(input_dev, ABS_MT_POSITION_Y,
616 finger[id].y);
617 input_mt_sync(input_dev);
618
619 if (finger[id].status == QT602240_RELEASE)
620 finger[id].status = 0;
621 else
622 finger_num++;
623 }
624
625 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
626
627 if (status != QT602240_RELEASE) {
628 input_report_abs(input_dev, ABS_X, finger[single_id].x);
629 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
630 }
631
632 input_sync(input_dev);
633}
634
635static void qt602240_input_touchevent(struct qt602240_data *data,
636 struct qt602240_message *message, int id)
637{
638 struct qt602240_finger *finger = data->finger;
639 struct device *dev = &data->client->dev;
640 u8 status = message->message[0];
641 int x;
642 int y;
643 int area;
644
645 /* Check the touch is present on the screen */
646 if (!(status & QT602240_DETECT)) {
647 if (status & QT602240_RELEASE) {
648 dev_dbg(dev, "[%d] released\n", id);
649
650 finger[id].status = QT602240_RELEASE;
651 qt602240_input_report(data, id);
652 }
653 return;
654 }
655
656 /* Check only AMP detection */
657 if (!(status & (QT602240_PRESS | QT602240_MOVE)))
658 return;
659
660 x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6);
661 y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2);
662 area = message->message[4];
663
664 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
665 status & QT602240_MOVE ? "moved" : "pressed",
666 x, y, area);
667
668 finger[id].status = status & QT602240_MOVE ?
669 QT602240_MOVE : QT602240_PRESS;
670 finger[id].x = x;
671 finger[id].y = y;
672 finger[id].area = area;
673
674 qt602240_input_report(data, id);
675}
676
677static irqreturn_t qt602240_interrupt(int irq, void *dev_id)
678{
679 struct qt602240_data *data = dev_id;
680 struct qt602240_message message;
681 struct qt602240_object *object;
682 struct device *dev = &data->client->dev;
683 int id;
684 u8 reportid;
685 u8 max_reportid;
686 u8 min_reportid;
687
688 do {
689 if (qt602240_read_message(data, &message)) {
690 dev_err(dev, "Failed to read message\n");
691 goto end;
692 }
693
694 reportid = message.reportid;
695
696 /* whether reportid is thing of QT602240_TOUCH_MULTI */
697 object = qt602240_get_object(data, QT602240_TOUCH_MULTI);
698 if (!object)
699 goto end;
700
701 max_reportid = object->max_reportid;
702 min_reportid = max_reportid - object->num_report_ids + 1;
703 id = reportid - min_reportid;
704
705 if (reportid >= min_reportid && reportid <= max_reportid)
706 qt602240_input_touchevent(data, &message, id);
707 else
708 qt602240_dump_message(dev, &message);
709 } while (reportid != 0xff);
710
711end:
712 return IRQ_HANDLED;
713}
714
715static int qt602240_check_reg_init(struct qt602240_data *data)
716{
717 struct qt602240_object *object;
718 struct device *dev = &data->client->dev;
719 int index = 0;
720 int i, j;
721 u8 version = data->info.version;
722 u8 *init_vals;
723
724 switch (version) {
725 case QT602240_VER_20:
726 init_vals = (u8 *)init_vals_ver_20;
727 break;
728 case QT602240_VER_21:
729 init_vals = (u8 *)init_vals_ver_21;
730 break;
731 case QT602240_VER_22:
732 init_vals = (u8 *)init_vals_ver_22;
733 break;
734 default:
735 dev_err(dev, "Firmware version %d doesn't support\n", version);
736 return -EINVAL;
737 }
738
739 for (i = 0; i < data->info.object_num; i++) {
740 object = data->object_table + i;
741
742 if (!qt602240_object_writable(object->type))
743 continue;
744
745 for (j = 0; j < object->size + 1; j++)
746 qt602240_write_object(data, object->type, j,
747 init_vals[index + j]);
748
749 index += object->size + 1;
750 }
751
752 return 0;
753}
754
755static int qt602240_check_matrix_size(struct qt602240_data *data)
756{
757 const struct qt602240_platform_data *pdata = data->pdata;
758 struct device *dev = &data->client->dev;
759 int mode = -1;
760 int error;
761 u8 val;
762
763 dev_dbg(dev, "Number of X lines: %d\n", pdata->x_line);
764 dev_dbg(dev, "Number of Y lines: %d\n", pdata->y_line);
765
766 switch (pdata->x_line) {
767 case 0 ... 15:
768 if (pdata->y_line <= 14)
769 mode = 0;
770 break;
771 case 16:
772 if (pdata->y_line <= 12)
773 mode = 1;
774 if (pdata->y_line == 13 || pdata->y_line == 14)
775 mode = 0;
776 break;
777 case 17:
778 if (pdata->y_line <= 11)
779 mode = 2;
780 if (pdata->y_line == 12 || pdata->y_line == 13)
781 mode = 1;
782 break;
783 case 18:
784 if (pdata->y_line <= 10)
785 mode = 3;
786 if (pdata->y_line == 11 || pdata->y_line == 12)
787 mode = 2;
788 break;
789 case 19:
790 if (pdata->y_line <= 9)
791 mode = 4;
792 if (pdata->y_line == 10 || pdata->y_line == 11)
793 mode = 3;
794 break;
795 case 20:
796 mode = 4;
797 }
798
799 if (mode < 0) {
800 dev_err(dev, "Invalid X/Y lines\n");
801 return -EINVAL;
802 }
803
804 error = qt602240_read_object(data, QT602240_SPT_CTECONFIG,
805 QT602240_CTE_MODE, &val);
806 if (error)
807 return error;
808
809 if (mode == val)
810 return 0;
811
812 /* Change the CTE configuration */
813 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
814 QT602240_CTE_CTRL, 1);
815 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
816 QT602240_CTE_MODE, mode);
817 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
818 QT602240_CTE_CTRL, 0);
819
820 return 0;
821}
822
823static int qt602240_make_highchg(struct qt602240_data *data)
824{
825 struct device *dev = &data->client->dev;
826 int count = 10;
827 int error;
828 u8 val;
829
830 /* Read dummy message to make high CHG pin */
831 do {
832 error = qt602240_read_object(data, QT602240_GEN_MESSAGE, 0, &val);
833 if (error)
834 return error;
835 } while ((val != 0xff) && --count);
836
837 if (!count) {
838 dev_err(dev, "CHG pin isn't cleared\n");
839 return -EBUSY;
840 }
841
842 return 0;
843}
844
845static void qt602240_handle_pdata(struct qt602240_data *data)
846{
847 const struct qt602240_platform_data *pdata = data->pdata;
848 u8 voltage;
849
850 /* Set touchscreen lines */
851 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_XSIZE,
852 pdata->x_line);
853 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_YSIZE,
854 pdata->y_line);
855
856 /* Set touchscreen orient */
857 qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_ORIENT,
858 pdata->orient);
859
860 /* Set touchscreen burst length */
861 qt602240_write_object(data, QT602240_TOUCH_MULTI,
862 QT602240_TOUCH_BLEN, pdata->blen);
863
864 /* Set touchscreen threshold */
865 qt602240_write_object(data, QT602240_TOUCH_MULTI,
866 QT602240_TOUCH_TCHTHR, pdata->threshold);
867
868 /* Set touchscreen resolution */
869 qt602240_write_object(data, QT602240_TOUCH_MULTI,
870 QT602240_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
871 qt602240_write_object(data, QT602240_TOUCH_MULTI,
872 QT602240_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
873 qt602240_write_object(data, QT602240_TOUCH_MULTI,
874 QT602240_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
875 qt602240_write_object(data, QT602240_TOUCH_MULTI,
876 QT602240_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
877
878 /* Set touchscreen voltage */
879 if (data->info.version >= QT602240_VER_21 && pdata->voltage) {
880 if (pdata->voltage < QT602240_VOLTAGE_DEFAULT) {
881 voltage = (QT602240_VOLTAGE_DEFAULT - pdata->voltage) /
882 QT602240_VOLTAGE_STEP;
883 voltage = 0xff - voltage + 1;
884 } else
885 voltage = (pdata->voltage - QT602240_VOLTAGE_DEFAULT) /
886 QT602240_VOLTAGE_STEP;
887
888 qt602240_write_object(data, QT602240_SPT_CTECONFIG,
889 QT602240_CTE_VOLTAGE, voltage);
890 }
891}
892
893static int qt602240_get_info(struct qt602240_data *data)
894{
895 struct i2c_client *client = data->client;
896 struct qt602240_info *info = &data->info;
897 int error;
898 u8 val;
899
900 error = qt602240_read_reg(client, QT602240_FAMILY_ID, &val);
901 if (error)
902 return error;
903 info->family_id = val;
904
905 error = qt602240_read_reg(client, QT602240_VARIANT_ID, &val);
906 if (error)
907 return error;
908 info->variant_id = val;
909
910 error = qt602240_read_reg(client, QT602240_VERSION, &val);
911 if (error)
912 return error;
913 info->version = val;
914
915 error = qt602240_read_reg(client, QT602240_BUILD, &val);
916 if (error)
917 return error;
918 info->build = val;
919
920 error = qt602240_read_reg(client, QT602240_OBJECT_NUM, &val);
921 if (error)
922 return error;
923 info->object_num = val;
924
925 return 0;
926}
927
928static int qt602240_get_object_table(struct qt602240_data *data)
929{
930 int error;
931 int i;
932 u16 reg;
933 u8 reportid = 0;
934 u8 buf[QT602240_OBJECT_SIZE];
935
936 for (i = 0; i < data->info.object_num; i++) {
937 struct qt602240_object *object = data->object_table + i;
938
939 reg = QT602240_OBJECT_START + QT602240_OBJECT_SIZE * i;
940 error = qt602240_read_object_table(data->client, reg, buf);
941 if (error)
942 return error;
943
944 object->type = buf[0];
945 object->start_address = (buf[2] << 8) | buf[1];
946 object->size = buf[3];
947 object->instances = buf[4];
948 object->num_report_ids = buf[5];
949
950 if (object->num_report_ids) {
951 reportid += object->num_report_ids *
952 (object->instances + 1);
953 object->max_reportid = reportid;
954 }
955 }
956
957 return 0;
958}
959
960static int qt602240_initialize(struct qt602240_data *data)
961{
962 struct i2c_client *client = data->client;
963 struct qt602240_info *info = &data->info;
964 int error;
965 u8 val;
966
967 error = qt602240_get_info(data);
968 if (error)
969 return error;
970
971 data->object_table = kcalloc(info->object_num,
972 sizeof(struct qt602240_object),
973 GFP_KERNEL);
974 if (!data->object_table) {
975 dev_err(&client->dev, "Failed to allocate memory\n");
976 return -ENOMEM;
977 }
978
979 /* Get object table information */
980 error = qt602240_get_object_table(data);
981 if (error)
982 return error;
983
984 /* Check register init values */
985 error = qt602240_check_reg_init(data);
986 if (error)
987 return error;
988
989 /* Check X/Y matrix size */
990 error = qt602240_check_matrix_size(data);
991 if (error)
992 return error;
993
994 error = qt602240_make_highchg(data);
995 if (error)
996 return error;
997
998 qt602240_handle_pdata(data);
999
1000 /* Backup to memory */
1001 qt602240_write_object(data, QT602240_GEN_COMMAND,
1002 QT602240_COMMAND_BACKUPNV,
1003 QT602240_BACKUP_VALUE);
1004 msleep(QT602240_BACKUP_TIME);
1005
1006 /* Soft reset */
1007 qt602240_write_object(data, QT602240_GEN_COMMAND,
1008 QT602240_COMMAND_RESET, 1);
1009 msleep(QT602240_RESET_TIME);
1010
1011 /* Update matrix size at info struct */
1012 error = qt602240_read_reg(client, QT602240_MATRIX_X_SIZE, &val);
1013 if (error)
1014 return error;
1015 info->matrix_xsize = val;
1016
1017 error = qt602240_read_reg(client, QT602240_MATRIX_Y_SIZE, &val);
1018 if (error)
1019 return error;
1020 info->matrix_ysize = val;
1021
1022 dev_info(&client->dev,
1023 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
1024 info->family_id, info->variant_id, info->version,
1025 info->build);
1026
1027 dev_info(&client->dev,
1028 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
1029 info->matrix_xsize, info->matrix_ysize,
1030 info->object_num);
1031
1032 return 0;
1033}
1034
1035static ssize_t qt602240_object_show(struct device *dev,
1036 struct device_attribute *attr, char *buf)
1037{
1038 struct qt602240_data *data = dev_get_drvdata(dev);
1039 struct qt602240_object *object;
1040 int count = 0;
1041 int i, j;
1042 int error;
1043 u8 val;
1044
1045 for (i = 0; i < data->info.object_num; i++) {
1046 object = data->object_table + i;
1047
1048 count += sprintf(buf + count,
1049 "Object Table Element %d(Type %d)\n",
1050 i + 1, object->type);
1051
1052 if (!qt602240_object_readable(object->type)) {
1053 count += sprintf(buf + count, "\n");
1054 continue;
1055 }
1056
1057 for (j = 0; j < object->size + 1; j++) {
1058 error = qt602240_read_object(data,
1059 object->type, j, &val);
1060 if (error)
1061 return error;
1062
1063 count += sprintf(buf + count,
1064 " Byte %d: 0x%x (%d)\n", j, val, val);
1065 }
1066
1067 count += sprintf(buf + count, "\n");
1068 }
1069
1070 return count;
1071}
1072
1073static int qt602240_load_fw(struct device *dev, const char *fn)
1074{
1075 struct qt602240_data *data = dev_get_drvdata(dev);
1076 struct i2c_client *client = data->client;
1077 const struct firmware *fw = NULL;
1078 unsigned int frame_size;
1079 unsigned int pos = 0;
1080 int ret;
1081
1082 ret = request_firmware(&fw, fn, dev);
1083 if (ret) {
1084 dev_err(dev, "Unable to open firmware %s\n", fn);
1085 return ret;
1086 }
1087
1088 /* Change to the bootloader mode */
1089 qt602240_write_object(data, QT602240_GEN_COMMAND,
1090 QT602240_COMMAND_RESET, QT602240_BOOT_VALUE);
1091 msleep(QT602240_RESET_TIME);
1092
1093 /* Change to slave address of bootloader */
1094 if (client->addr == QT602240_APP_LOW)
1095 client->addr = QT602240_BOOT_LOW;
1096 else
1097 client->addr = QT602240_BOOT_HIGH;
1098
1099 ret = qt602240_check_bootloader(client, QT602240_WAITING_BOOTLOAD_CMD);
1100 if (ret)
1101 goto out;
1102
1103 /* Unlock bootloader */
1104 qt602240_unlock_bootloader(client);
1105
1106 while (pos < fw->size) {
1107 ret = qt602240_check_bootloader(client,
1108 QT602240_WAITING_FRAME_DATA);
1109 if (ret)
1110 goto out;
1111
1112 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
1113
1114 /* We should add 2 at frame size as the the firmware data is not
1115 * included the CRC bytes.
1116 */
1117 frame_size += 2;
1118
1119 /* Write one frame to device */
1120 qt602240_fw_write(client, fw->data + pos, frame_size);
1121
1122 ret = qt602240_check_bootloader(client,
1123 QT602240_FRAME_CRC_PASS);
1124 if (ret)
1125 goto out;
1126
1127 pos += frame_size;
1128
1129 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
1130 }
1131
1132out:
1133 release_firmware(fw);
1134
1135 /* Change to slave address of application */
1136 if (client->addr == QT602240_BOOT_LOW)
1137 client->addr = QT602240_APP_LOW;
1138 else
1139 client->addr = QT602240_APP_HIGH;
1140
1141 return ret;
1142}
1143
1144static ssize_t qt602240_update_fw_store(struct device *dev,
1145 struct device_attribute *attr,
1146 const char *buf, size_t count)
1147{
1148 struct qt602240_data *data = dev_get_drvdata(dev);
1149 unsigned int version;
1150 int error;
1151
1152 if (sscanf(buf, "%u", &version) != 1) {
1153 dev_err(dev, "Invalid values\n");
1154 return -EINVAL;
1155 }
1156
1157 if (data->info.version < QT602240_VER_21 || version < QT602240_VER_21) {
1158 dev_err(dev, "FW update supported starting with version 21\n");
1159 return -EINVAL;
1160 }
1161
1162 disable_irq(data->irq);
1163
1164 error = qt602240_load_fw(dev, QT602240_FW_NAME);
1165 if (error) {
1166 dev_err(dev, "The firmware update failed(%d)\n", error);
1167 count = error;
1168 } else {
1169 dev_dbg(dev, "The firmware update succeeded\n");
1170
1171 /* Wait for reset */
1172 msleep(QT602240_FWRESET_TIME);
1173
1174 kfree(data->object_table);
1175 data->object_table = NULL;
1176
1177 qt602240_initialize(data);
1178 }
1179
1180 enable_irq(data->irq);
1181
1182 return count;
1183}
1184
1185static DEVICE_ATTR(object, 0444, qt602240_object_show, NULL);
1186static DEVICE_ATTR(update_fw, 0664, NULL, qt602240_update_fw_store);
1187
1188static struct attribute *qt602240_attrs[] = {
1189 &dev_attr_object.attr,
1190 &dev_attr_update_fw.attr,
1191 NULL
1192};
1193
1194static const struct attribute_group qt602240_attr_group = {
1195 .attrs = qt602240_attrs,
1196};
1197
1198static void qt602240_start(struct qt602240_data *data)
1199{
1200 /* Touch enable */
1201 qt602240_write_object(data,
1202 QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0x83);
1203}
1204
1205static void qt602240_stop(struct qt602240_data *data)
1206{
1207 /* Touch disable */
1208 qt602240_write_object(data,
1209 QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0);
1210}
1211
1212static int qt602240_input_open(struct input_dev *dev)
1213{
1214 struct qt602240_data *data = input_get_drvdata(dev);
1215
1216 qt602240_start(data);
1217
1218 return 0;
1219}
1220
1221static void qt602240_input_close(struct input_dev *dev)
1222{
1223 struct qt602240_data *data = input_get_drvdata(dev);
1224
1225 qt602240_stop(data);
1226}
1227
1228static int __devinit qt602240_probe(struct i2c_client *client,
1229 const struct i2c_device_id *id)
1230{
1231 struct qt602240_data *data;
1232 struct input_dev *input_dev;
1233 int error;
1234
1235 if (!client->dev.platform_data)
1236 return -EINVAL;
1237
1238 data = kzalloc(sizeof(struct qt602240_data), GFP_KERNEL);
1239 input_dev = input_allocate_device();
1240 if (!data || !input_dev) {
1241 dev_err(&client->dev, "Failed to allocate memory\n");
1242 error = -ENOMEM;
1243 goto err_free_mem;
1244 }
1245
1246 input_dev->name = "AT42QT602240/ATMXT224 Touchscreen";
1247 input_dev->id.bustype = BUS_I2C;
1248 input_dev->dev.parent = &client->dev;
1249 input_dev->open = qt602240_input_open;
1250 input_dev->close = qt602240_input_close;
1251
1252 __set_bit(EV_ABS, input_dev->evbit);
1253 __set_bit(EV_KEY, input_dev->evbit);
1254 __set_bit(BTN_TOUCH, input_dev->keybit);
1255
1256 /* For single touch */
1257 input_set_abs_params(input_dev, ABS_X,
1258 0, QT602240_MAX_XC, 0, 0);
1259 input_set_abs_params(input_dev, ABS_Y,
1260 0, QT602240_MAX_YC, 0, 0);
1261
1262 /* For multi touch */
1263 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1264 0, QT602240_MAX_AREA, 0, 0);
1265 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1266 0, QT602240_MAX_XC, 0, 0);
1267 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1268 0, QT602240_MAX_YC, 0, 0);
1269
1270 input_set_drvdata(input_dev, data);
1271
1272 data->client = client;
1273 data->input_dev = input_dev;
1274 data->pdata = client->dev.platform_data;
1275 data->irq = client->irq;
1276
1277 i2c_set_clientdata(client, data);
1278
1279 error = qt602240_initialize(data);
1280 if (error)
1281 goto err_free_object;
1282
1283 error = request_threaded_irq(client->irq, NULL, qt602240_interrupt,
1284 IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
1285 if (error) {
1286 dev_err(&client->dev, "Failed to register interrupt\n");
1287 goto err_free_object;
1288 }
1289
1290 error = input_register_device(input_dev);
1291 if (error)
1292 goto err_free_irq;
1293
1294 error = sysfs_create_group(&client->dev.kobj, &qt602240_attr_group);
1295 if (error)
1296 goto err_unregister_device;
1297
1298 return 0;
1299
1300err_unregister_device:
1301 input_unregister_device(input_dev);
1302 input_dev = NULL;
1303err_free_irq:
1304 free_irq(client->irq, data);
1305err_free_object:
1306 kfree(data->object_table);
1307err_free_mem:
1308 input_free_device(input_dev);
1309 kfree(data);
1310 return error;
1311}
1312
1313static int __devexit qt602240_remove(struct i2c_client *client)
1314{
1315 struct qt602240_data *data = i2c_get_clientdata(client);
1316
1317 sysfs_remove_group(&client->dev.kobj, &qt602240_attr_group);
1318 free_irq(data->irq, data);
1319 input_unregister_device(data->input_dev);
1320 kfree(data->object_table);
1321 kfree(data);
1322
1323 return 0;
1324}
1325
1326#ifdef CONFIG_PM
1327static int qt602240_suspend(struct device *dev)
1328{
1329 struct i2c_client *client = to_i2c_client(dev);
1330 struct qt602240_data *data = i2c_get_clientdata(client);
1331 struct input_dev *input_dev = data->input_dev;
1332
1333 mutex_lock(&input_dev->mutex);
1334
1335 if (input_dev->users)
1336 qt602240_stop(data);
1337
1338 mutex_unlock(&input_dev->mutex);
1339
1340 return 0;
1341}
1342
1343static int qt602240_resume(struct device *dev)
1344{
1345 struct i2c_client *client = to_i2c_client(dev);
1346 struct qt602240_data *data = i2c_get_clientdata(client);
1347 struct input_dev *input_dev = data->input_dev;
1348
1349 /* Soft reset */
1350 qt602240_write_object(data, QT602240_GEN_COMMAND,
1351 QT602240_COMMAND_RESET, 1);
1352
1353 msleep(QT602240_RESET_TIME);
1354
1355 mutex_lock(&input_dev->mutex);
1356
1357 if (input_dev->users)
1358 qt602240_start(data);
1359
1360 mutex_unlock(&input_dev->mutex);
1361
1362 return 0;
1363}
1364
1365static const struct dev_pm_ops qt602240_pm_ops = {
1366 .suspend = qt602240_suspend,
1367 .resume = qt602240_resume,
1368};
1369#endif
1370
1371static const struct i2c_device_id qt602240_id[] = {
1372 { "qt602240_ts", 0 },
1373 { }
1374};
1375MODULE_DEVICE_TABLE(i2c, qt602240_id);
1376
1377static struct i2c_driver qt602240_driver = {
1378 .driver = {
1379 .name = "qt602240_ts",
1380 .owner = THIS_MODULE,
1381#ifdef CONFIG_PM
1382 .pm = &qt602240_pm_ops,
1383#endif
1384 },
1385 .probe = qt602240_probe,
1386 .remove = __devexit_p(qt602240_remove),
1387 .id_table = qt602240_id,
1388};
1389
1390static int __init qt602240_init(void)
1391{
1392 return i2c_add_driver(&qt602240_driver);
1393}
1394
1395static void __exit qt602240_exit(void)
1396{
1397 i2c_del_driver(&qt602240_driver);
1398}
1399
1400module_init(qt602240_init);
1401module_exit(qt602240_exit);
1402
1403/* Module information */
1404MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
1405MODULE_DESCRIPTION("AT42QT602240/ATMXT224 Touchscreen driver");
1406MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c
new file mode 100644
index 000000000000..87420616efa4
--- /dev/null
+++ b/drivers/input/touchscreen/tsc2005.c
@@ -0,0 +1,756 @@
1/*
2 * TSC2005 touchscreen driver
3 *
4 * Copyright (C) 2006-2010 Nokia Corporation
5 *
6 * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
7 * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/input.h>
28#include <linux/interrupt.h>
29#include <linux/delay.h>
30#include <linux/pm.h>
31#include <linux/spi/spi.h>
32#include <linux/spi/tsc2005.h>
33
34/*
35 * The touchscreen interface operates as follows:
36 *
37 * 1) Pen is pressed against the touchscreen.
38 * 2) TSC2005 performs AD conversion.
39 * 3) After the conversion is done TSC2005 drives DAV line down.
40 * 4) GPIO IRQ is received and tsc2005_irq_thread() is scheduled.
41 * 5) tsc2005_irq_thread() queues up an spi transfer to fetch the x, y, z1, z2
42 * values.
43 * 6) tsc2005_irq_thread() reports coordinates to input layer and sets up
44 * tsc2005_penup_timer() to be called after TSC2005_PENUP_TIME_MS (40ms).
45 * 7) When the penup timer expires, there have not been touch or DAV interrupts
46 * during the last 40ms which means the pen has been lifted.
47 *
48 * ESD recovery via a hardware reset is done if the TSC2005 doesn't respond
49 * after a configurable period (in ms) of activity. If esd_timeout is 0, the
50 * watchdog is disabled.
51 */
52
53/* control byte 1 */
54#define TSC2005_CMD 0x80
55#define TSC2005_CMD_NORMAL 0x00
56#define TSC2005_CMD_STOP 0x01
57#define TSC2005_CMD_12BIT 0x04
58
59/* control byte 0 */
60#define TSC2005_REG_READ 0x0001
61#define TSC2005_REG_PND0 0x0002
62#define TSC2005_REG_X 0x0000
63#define TSC2005_REG_Y 0x0008
64#define TSC2005_REG_Z1 0x0010
65#define TSC2005_REG_Z2 0x0018
66#define TSC2005_REG_TEMP_HIGH 0x0050
67#define TSC2005_REG_CFR0 0x0060
68#define TSC2005_REG_CFR1 0x0068
69#define TSC2005_REG_CFR2 0x0070
70
71/* configuration register 0 */
72#define TSC2005_CFR0_PRECHARGE_276US 0x0040
73#define TSC2005_CFR0_STABTIME_1MS 0x0300
74#define TSC2005_CFR0_CLOCK_1MHZ 0x1000
75#define TSC2005_CFR0_RESOLUTION12 0x2000
76#define TSC2005_CFR0_PENMODE 0x8000
77#define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \
78 TSC2005_CFR0_CLOCK_1MHZ | \
79 TSC2005_CFR0_RESOLUTION12 | \
80 TSC2005_CFR0_PRECHARGE_276US | \
81 TSC2005_CFR0_PENMODE)
82
83/* bits common to both read and write of configuration register 0 */
84#define TSC2005_CFR0_RW_MASK 0x3fff
85
86/* configuration register 1 */
87#define TSC2005_CFR1_BATCHDELAY_4MS 0x0003
88#define TSC2005_CFR1_INITVALUE TSC2005_CFR1_BATCHDELAY_4MS
89
90/* configuration register 2 */
91#define TSC2005_CFR2_MAVE_Z 0x0004
92#define TSC2005_CFR2_MAVE_Y 0x0008
93#define TSC2005_CFR2_MAVE_X 0x0010
94#define TSC2005_CFR2_AVG_7 0x0800
95#define TSC2005_CFR2_MEDIUM_15 0x3000
96#define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_MAVE_X | \
97 TSC2005_CFR2_MAVE_Y | \
98 TSC2005_CFR2_MAVE_Z | \
99 TSC2005_CFR2_MEDIUM_15 | \
100 TSC2005_CFR2_AVG_7)
101
102#define MAX_12BIT 0xfff
103#define TSC2005_SPI_MAX_SPEED_HZ 10000000
104#define TSC2005_PENUP_TIME_MS 40
105
106struct tsc2005_spi_rd {
107 struct spi_transfer spi_xfer;
108 u32 spi_tx;
109 u32 spi_rx;
110};
111
112struct tsc2005 {
113 struct spi_device *spi;
114
115 struct spi_message spi_read_msg;
116 struct tsc2005_spi_rd spi_x;
117 struct tsc2005_spi_rd spi_y;
118 struct tsc2005_spi_rd spi_z1;
119 struct tsc2005_spi_rd spi_z2;
120
121 struct input_dev *idev;
122 char phys[32];
123
124 struct mutex mutex;
125
126 /* raw copy of previous x,y,z */
127 int in_x;
128 int in_y;
129 int in_z1;
130 int in_z2;
131
132 spinlock_t lock;
133 struct timer_list penup_timer;
134
135 unsigned int esd_timeout;
136 struct delayed_work esd_work;
137 unsigned long last_valid_interrupt;
138
139 unsigned int x_plate_ohm;
140
141 bool opened;
142 bool suspended;
143
144 bool pen_down;
145
146 void (*set_reset)(bool enable);
147};
148
149static int tsc2005_cmd(struct tsc2005 *ts, u8 cmd)
150{
151 u8 tx = TSC2005_CMD | TSC2005_CMD_12BIT | cmd;
152 struct spi_transfer xfer = {
153 .tx_buf = &tx,
154 .len = 1,
155 .bits_per_word = 8,
156 };
157 struct spi_message msg;
158 int error;
159
160 spi_message_init(&msg);
161 spi_message_add_tail(&xfer, &msg);
162
163 error = spi_sync(ts->spi, &msg);
164 if (error) {
165 dev_err(&ts->spi->dev, "%s: failed, command: %x, error: %d\n",
166 __func__, cmd, error);
167 return error;
168 }
169
170 return 0;
171}
172
173static int tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value)
174{
175 u32 tx = ((reg | TSC2005_REG_PND0) << 16) | value;
176 struct spi_transfer xfer = {
177 .tx_buf = &tx,
178 .len = 4,
179 .bits_per_word = 24,
180 };
181 struct spi_message msg;
182 int error;
183
184 spi_message_init(&msg);
185 spi_message_add_tail(&xfer, &msg);
186
187 error = spi_sync(ts->spi, &msg);
188 if (error) {
189 dev_err(&ts->spi->dev,
190 "%s: failed, register: %x, value: %x, error: %d\n",
191 __func__, reg, value, error);
192 return error;
193 }
194
195 return 0;
196}
197
198static void tsc2005_setup_read(struct tsc2005_spi_rd *rd, u8 reg, bool last)
199{
200 memset(rd, 0, sizeof(*rd));
201
202 rd->spi_tx = (reg | TSC2005_REG_READ) << 16;
203 rd->spi_xfer.tx_buf = &rd->spi_tx;
204 rd->spi_xfer.rx_buf = &rd->spi_rx;
205 rd->spi_xfer.len = 4;
206 rd->spi_xfer.bits_per_word = 24;
207 rd->spi_xfer.cs_change = !last;
208}
209
210static int tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value)
211{
212 struct tsc2005_spi_rd spi_rd;
213 struct spi_message msg;
214 int error;
215
216 tsc2005_setup_read(&spi_rd, reg, true);
217
218 spi_message_init(&msg);
219 spi_message_add_tail(&spi_rd.spi_xfer, &msg);
220
221 error = spi_sync(ts->spi, &msg);
222 if (error)
223 return error;
224
225 *value = spi_rd.spi_rx;
226 return 0;
227}
228
229static void tsc2005_update_pen_state(struct tsc2005 *ts,
230 int x, int y, int pressure)
231{
232 if (pressure) {
233 input_report_abs(ts->idev, ABS_X, x);
234 input_report_abs(ts->idev, ABS_Y, y);
235 input_report_abs(ts->idev, ABS_PRESSURE, pressure);
236 if (!ts->pen_down) {
237 input_report_key(ts->idev, BTN_TOUCH, !!pressure);
238 ts->pen_down = true;
239 }
240 } else {
241 input_report_abs(ts->idev, ABS_PRESSURE, 0);
242 if (ts->pen_down) {
243 input_report_key(ts->idev, BTN_TOUCH, 0);
244 ts->pen_down = false;
245 }
246 }
247 input_sync(ts->idev);
248 dev_dbg(&ts->spi->dev, "point(%4d,%4d), pressure (%4d)\n", x, y,
249 pressure);
250}
251
252static irqreturn_t tsc2005_irq_thread(int irq, void *_ts)
253{
254 struct tsc2005 *ts = _ts;
255 unsigned long flags;
256 unsigned int pressure;
257 u32 x, y;
258 u32 z1, z2;
259 int error;
260
261 /* read the coordinates */
262 error = spi_sync(ts->spi, &ts->spi_read_msg);
263 if (unlikely(error))
264 goto out;
265
266 x = ts->spi_x.spi_rx;
267 y = ts->spi_y.spi_rx;
268 z1 = ts->spi_z1.spi_rx;
269 z2 = ts->spi_z2.spi_rx;
270
271 /* validate position */
272 if (unlikely(x > MAX_12BIT || y > MAX_12BIT))
273 goto out;
274
275 /* Skip reading if the pressure components are out of range */
276 if (unlikely(z1 == 0 || z2 > MAX_12BIT || z1 >= z2))
277 goto out;
278
279 /*
280 * Skip point if this is a pen down with the exact same values as
281 * the value before pen-up - that implies SPI fed us stale data
282 */
283 if (!ts->pen_down &&
284 ts->in_x == x && ts->in_y == y &&
285 ts->in_z1 == z1 && ts->in_z2 == z2) {
286 goto out;
287 }
288
289 /*
290 * At this point we are happy we have a valid and useful reading.
291 * Remember it for later comparisons. We may now begin downsampling.
292 */
293 ts->in_x = x;
294 ts->in_y = y;
295 ts->in_z1 = z1;
296 ts->in_z2 = z2;
297
298 /* Compute touch pressure resistance using equation #1 */
299 pressure = x * (z2 - z1) / z1;
300 pressure = pressure * ts->x_plate_ohm / 4096;
301 if (unlikely(pressure > MAX_12BIT))
302 goto out;
303
304 spin_lock_irqsave(&ts->lock, flags);
305
306 tsc2005_update_pen_state(ts, x, y, pressure);
307 mod_timer(&ts->penup_timer,
308 jiffies + msecs_to_jiffies(TSC2005_PENUP_TIME_MS));
309
310 spin_unlock_irqrestore(&ts->lock, flags);
311
312 ts->last_valid_interrupt = jiffies;
313out:
314 return IRQ_HANDLED;
315}
316
317static void tsc2005_penup_timer(unsigned long data)
318{
319 struct tsc2005 *ts = (struct tsc2005 *)data;
320 unsigned long flags;
321
322 spin_lock_irqsave(&ts->lock, flags);
323 tsc2005_update_pen_state(ts, 0, 0, 0);
324 spin_unlock_irqrestore(&ts->lock, flags);
325}
326
327static void tsc2005_start_scan(struct tsc2005 *ts)
328{
329 tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE);
330 tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE);
331 tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE);
332 tsc2005_cmd(ts, TSC2005_CMD_NORMAL);
333}
334
335static void tsc2005_stop_scan(struct tsc2005 *ts)
336{
337 tsc2005_cmd(ts, TSC2005_CMD_STOP);
338}
339
340/* must be called with ts->mutex held */
341static void __tsc2005_disable(struct tsc2005 *ts)
342{
343 tsc2005_stop_scan(ts);
344
345 disable_irq(ts->spi->irq);
346 del_timer_sync(&ts->penup_timer);
347
348 cancel_delayed_work_sync(&ts->esd_work);
349
350 enable_irq(ts->spi->irq);
351}
352
353/* must be called with ts->mutex held */
354static void __tsc2005_enable(struct tsc2005 *ts)
355{
356 tsc2005_start_scan(ts);
357
358 if (ts->esd_timeout && ts->set_reset) {
359 ts->last_valid_interrupt = jiffies;
360 schedule_delayed_work(&ts->esd_work,
361 round_jiffies(jiffies +
362 msecs_to_jiffies(ts->esd_timeout)));
363 }
364
365}
366
367static ssize_t tsc2005_selftest_show(struct device *dev,
368 struct device_attribute *attr,
369 char *buf)
370{
371 struct spi_device *spi = to_spi_device(dev);
372 struct tsc2005 *ts = spi_get_drvdata(spi);
373 u16 temp_high;
374 u16 temp_high_orig;
375 u16 temp_high_test;
376 bool success = true;
377 int error;
378
379 mutex_lock(&ts->mutex);
380
381 /*
382 * Test TSC2005 communications via temp high register.
383 */
384 __tsc2005_disable(ts);
385
386 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig);
387 if (error) {
388 dev_warn(dev, "selftest failed: read error %d\n", error);
389 success = false;
390 goto out;
391 }
392
393 temp_high_test = (temp_high_orig - 1) & MAX_12BIT;
394
395 error = tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test);
396 if (error) {
397 dev_warn(dev, "selftest failed: write error %d\n", error);
398 success = false;
399 goto out;
400 }
401
402 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
403 if (error) {
404 dev_warn(dev, "selftest failed: read error %d after write\n",
405 error);
406 success = false;
407 goto out;
408 }
409
410 if (temp_high != temp_high_test) {
411 dev_warn(dev, "selftest failed: %d != %d\n",
412 temp_high, temp_high_test);
413 success = false;
414 }
415
416 /* hardware reset */
417 ts->set_reset(false);
418 usleep_range(100, 500); /* only 10us required */
419 ts->set_reset(true);
420
421 if (!success)
422 goto out;
423
424 /* test that the reset really happened */
425 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
426 if (error) {
427 dev_warn(dev, "selftest failed: read error %d after reset\n",
428 error);
429 success = false;
430 goto out;
431 }
432
433 if (temp_high != temp_high_orig) {
434 dev_warn(dev, "selftest failed after reset: %d != %d\n",
435 temp_high, temp_high_orig);
436 success = false;
437 }
438
439out:
440 __tsc2005_enable(ts);
441 mutex_unlock(&ts->mutex);
442
443 return sprintf(buf, "%d\n", success);
444}
445
446static DEVICE_ATTR(selftest, S_IRUGO, tsc2005_selftest_show, NULL);
447
448static struct attribute *tsc2005_attrs[] = {
449 &dev_attr_selftest.attr,
450 NULL
451};
452
453static mode_t tsc2005_attr_is_visible(struct kobject *kobj,
454 struct attribute *attr, int n)
455{
456 struct device *dev = container_of(kobj, struct device, kobj);
457 struct spi_device *spi = to_spi_device(dev);
458 struct tsc2005 *ts = spi_get_drvdata(spi);
459 mode_t mode = attr->mode;
460
461 if (attr == &dev_attr_selftest.attr) {
462 if (!ts->set_reset)
463 mode = 0;
464 }
465
466 return mode;
467}
468
469static const struct attribute_group tsc2005_attr_group = {
470 .is_visible = tsc2005_attr_is_visible,
471 .attrs = tsc2005_attrs,
472};
473
474static void tsc2005_esd_work(struct work_struct *work)
475{
476 struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work.work);
477 int error;
478 u16 r;
479
480 mutex_lock(&ts->mutex);
481
482 if (time_is_after_jiffies(ts->last_valid_interrupt +
483 msecs_to_jiffies(ts->esd_timeout)))
484 goto out;
485
486 /* We should be able to read register without disabling interrupts. */
487 error = tsc2005_read(ts, TSC2005_REG_CFR0, &r);
488 if (!error &&
489 !((r ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK)) {
490 goto out;
491 }
492
493 /*
494 * If we could not read our known value from configuration register 0
495 * then we should reset the controller as if from power-up and start
496 * scanning again.
497 */
498 dev_info(&ts->spi->dev, "TSC2005 not responding - resetting\n");
499
500 disable_irq(ts->spi->irq);
501 del_timer_sync(&ts->penup_timer);
502
503 tsc2005_update_pen_state(ts, 0, 0, 0);
504
505 ts->set_reset(false);
506 usleep_range(100, 500); /* only 10us required */
507 ts->set_reset(true);
508
509 enable_irq(ts->spi->irq);
510 tsc2005_start_scan(ts);
511
512out:
513 /* re-arm the watchdog */
514 schedule_delayed_work(&ts->esd_work,
515 round_jiffies(jiffies +
516 msecs_to_jiffies(ts->esd_timeout)));
517 mutex_unlock(&ts->mutex);
518}
519
520static int tsc2005_open(struct input_dev *input)
521{
522 struct tsc2005 *ts = input_get_drvdata(input);
523
524 mutex_lock(&ts->mutex);
525
526 if (!ts->suspended)
527 __tsc2005_enable(ts);
528
529 ts->opened = true;
530
531 mutex_unlock(&ts->mutex);
532
533 return 0;
534}
535
536static void tsc2005_close(struct input_dev *input)
537{
538 struct tsc2005 *ts = input_get_drvdata(input);
539
540 mutex_lock(&ts->mutex);
541
542 if (!ts->suspended)
543 __tsc2005_disable(ts);
544
545 ts->opened = false;
546
547 mutex_unlock(&ts->mutex);
548}
549
550static void __devinit tsc2005_setup_spi_xfer(struct tsc2005 *ts)
551{
552 tsc2005_setup_read(&ts->spi_x, TSC2005_REG_X, false);
553 tsc2005_setup_read(&ts->spi_y, TSC2005_REG_Y, false);
554 tsc2005_setup_read(&ts->spi_z1, TSC2005_REG_Z1, false);
555 tsc2005_setup_read(&ts->spi_z2, TSC2005_REG_Z2, true);
556
557 spi_message_init(&ts->spi_read_msg);
558 spi_message_add_tail(&ts->spi_x.spi_xfer, &ts->spi_read_msg);
559 spi_message_add_tail(&ts->spi_y.spi_xfer, &ts->spi_read_msg);
560 spi_message_add_tail(&ts->spi_z1.spi_xfer, &ts->spi_read_msg);
561 spi_message_add_tail(&ts->spi_z2.spi_xfer, &ts->spi_read_msg);
562}
563
564static int __devinit tsc2005_probe(struct spi_device *spi)
565{
566 const struct tsc2005_platform_data *pdata = spi->dev.platform_data;
567 struct tsc2005 *ts;
568 struct input_dev *input_dev;
569 unsigned int max_x, max_y, max_p;
570 unsigned int fudge_x, fudge_y, fudge_p;
571 int error;
572
573 if (!pdata) {
574 dev_dbg(&spi->dev, "no platform data\n");
575 return -ENODEV;
576 }
577
578 fudge_x = pdata->ts_x_fudge ? : 4;
579 fudge_y = pdata->ts_y_fudge ? : 8;
580 fudge_p = pdata->ts_pressure_fudge ? : 2;
581 max_x = pdata->ts_x_max ? : MAX_12BIT;
582 max_y = pdata->ts_y_max ? : MAX_12BIT;
583 max_p = pdata->ts_pressure_max ? : MAX_12BIT;
584
585 if (spi->irq <= 0) {
586 dev_dbg(&spi->dev, "no irq\n");
587 return -ENODEV;
588 }
589
590 spi->mode = SPI_MODE_0;
591 spi->bits_per_word = 8;
592 if (!spi->max_speed_hz)
593 spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
594
595 error = spi_setup(spi);
596 if (error)
597 return error;
598
599 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
600 input_dev = input_allocate_device();
601 if (!ts || !input_dev) {
602 error = -ENOMEM;
603 goto err_free_mem;
604 }
605
606 ts->spi = spi;
607 ts->idev = input_dev;
608
609 ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280;
610 ts->esd_timeout = pdata->esd_timeout_ms;
611 ts->set_reset = pdata->set_reset;
612
613 mutex_init(&ts->mutex);
614
615 spin_lock_init(&ts->lock);
616 setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts);
617
618 INIT_DELAYED_WORK(&ts->esd_work, tsc2005_esd_work);
619
620 tsc2005_setup_spi_xfer(ts);
621
622 snprintf(ts->phys, sizeof(ts->phys),
623 "%s/input-ts", dev_name(&spi->dev));
624
625 input_dev->name = "TSC2005 touchscreen";
626 input_dev->phys = ts->phys;
627 input_dev->id.bustype = BUS_SPI;
628 input_dev->dev.parent = &spi->dev;
629 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
630 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
631
632 input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0);
633 input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0);
634 input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0);
635
636 input_dev->open = tsc2005_open;
637 input_dev->close = tsc2005_close;
638
639 input_set_drvdata(input_dev, ts);
640
641 /* Ensure the touchscreen is off */
642 tsc2005_stop_scan(ts);
643
644 error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread,
645 IRQF_TRIGGER_RISING, "tsc2005", ts);
646 if (error) {
647 dev_err(&spi->dev, "Failed to request irq, err: %d\n", error);
648 goto err_free_mem;
649 }
650
651 spi_set_drvdata(spi, ts);
652 error = sysfs_create_group(&spi->dev.kobj, &tsc2005_attr_group);
653 if (error) {
654 dev_err(&spi->dev,
655 "Failed to create sysfs attributes, err: %d\n", error);
656 goto err_clear_drvdata;
657 }
658
659 error = input_register_device(ts->idev);
660 if (error) {
661 dev_err(&spi->dev,
662 "Failed to register input device, err: %d\n", error);
663 goto err_remove_sysfs;
664 }
665
666 set_irq_wake(spi->irq, 1);
667 return 0;
668
669err_remove_sysfs:
670 sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group);
671err_clear_drvdata:
672 spi_set_drvdata(spi, NULL);
673 free_irq(spi->irq, ts);
674err_free_mem:
675 input_free_device(input_dev);
676 kfree(ts);
677 return error;
678}
679
680static int __devexit tsc2005_remove(struct spi_device *spi)
681{
682 struct tsc2005 *ts = spi_get_drvdata(spi);
683
684 sysfs_remove_group(&ts->spi->dev.kobj, &tsc2005_attr_group);
685
686 free_irq(ts->spi->irq, ts);
687 input_unregister_device(ts->idev);
688 kfree(ts);
689
690 spi_set_drvdata(spi, NULL);
691 return 0;
692}
693
694#ifdef CONFIG_PM_SLEEP
695static int tsc2005_suspend(struct device *dev)
696{
697 struct spi_device *spi = to_spi_device(dev);
698 struct tsc2005 *ts = spi_get_drvdata(spi);
699
700 mutex_lock(&ts->mutex);
701
702 if (!ts->suspended && ts->opened)
703 __tsc2005_disable(ts);
704
705 ts->suspended = true;
706
707 mutex_unlock(&ts->mutex);
708
709 return 0;
710}
711
712static int tsc2005_resume(struct device *dev)
713{
714 struct spi_device *spi = to_spi_device(dev);
715 struct tsc2005 *ts = spi_get_drvdata(spi);
716
717 mutex_lock(&ts->mutex);
718
719 if (ts->suspended && ts->opened)
720 __tsc2005_enable(ts);
721
722 ts->suspended = false;
723
724 mutex_unlock(&ts->mutex);
725
726 return 0;
727}
728#endif
729
730static SIMPLE_DEV_PM_OPS(tsc2005_pm_ops, tsc2005_suspend, tsc2005_resume);
731
732static struct spi_driver tsc2005_driver = {
733 .driver = {
734 .name = "tsc2005",
735 .owner = THIS_MODULE,
736 .pm = &tsc2005_pm_ops,
737 },
738 .probe = tsc2005_probe,
739 .remove = __devexit_p(tsc2005_remove),
740};
741
742static int __init tsc2005_init(void)
743{
744 return spi_register_driver(&tsc2005_driver);
745}
746module_init(tsc2005_init);
747
748static void __exit tsc2005_exit(void)
749{
750 spi_unregister_driver(&tsc2005_driver);
751}
752module_exit(tsc2005_exit);
753
754MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>");
755MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
756MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm831x-ts.c b/drivers/input/touchscreen/wm831x-ts.c
new file mode 100644
index 000000000000..6ae054f8e0aa
--- /dev/null
+++ b/drivers/input/touchscreen/wm831x-ts.c
@@ -0,0 +1,368 @@
1/*
2 * Touchscreen driver for WM831x PMICs
3 *
4 * Copyright 2011 Wolfson Microelectronics plc.
5 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/string.h>
18#include <linux/pm.h>
19#include <linux/input.h>
20#include <linux/interrupt.h>
21#include <linux/io.h>
22#include <linux/mfd/wm831x/core.h>
23#include <linux/mfd/wm831x/irq.h>
24#include <linux/mfd/wm831x/pdata.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27#include <linux/types.h>
28
29/*
30 * R16424 (0x4028) - Touch Control 1
31 */
32#define WM831X_TCH_ENA 0x8000 /* TCH_ENA */
33#define WM831X_TCH_CVT_ENA 0x4000 /* TCH_CVT_ENA */
34#define WM831X_TCH_SLPENA 0x1000 /* TCH_SLPENA */
35#define WM831X_TCH_Z_ENA 0x0400 /* TCH_Z_ENA */
36#define WM831X_TCH_Y_ENA 0x0200 /* TCH_Y_ENA */
37#define WM831X_TCH_X_ENA 0x0100 /* TCH_X_ENA */
38#define WM831X_TCH_DELAY_MASK 0x00E0 /* TCH_DELAY - [7:5] */
39#define WM831X_TCH_DELAY_SHIFT 5 /* TCH_DELAY - [7:5] */
40#define WM831X_TCH_DELAY_WIDTH 3 /* TCH_DELAY - [7:5] */
41#define WM831X_TCH_RATE_MASK 0x001F /* TCH_RATE - [4:0] */
42#define WM831X_TCH_RATE_SHIFT 0 /* TCH_RATE - [4:0] */
43#define WM831X_TCH_RATE_WIDTH 5 /* TCH_RATE - [4:0] */
44
45/*
46 * R16425 (0x4029) - Touch Control 2
47 */
48#define WM831X_TCH_PD_WK 0x2000 /* TCH_PD_WK */
49#define WM831X_TCH_5WIRE 0x1000 /* TCH_5WIRE */
50#define WM831X_TCH_PDONLY 0x0800 /* TCH_PDONLY */
51#define WM831X_TCH_ISEL 0x0100 /* TCH_ISEL */
52#define WM831X_TCH_RPU_MASK 0x000F /* TCH_RPU - [3:0] */
53#define WM831X_TCH_RPU_SHIFT 0 /* TCH_RPU - [3:0] */
54#define WM831X_TCH_RPU_WIDTH 4 /* TCH_RPU - [3:0] */
55
56/*
57 * R16426-8 (0x402A-C) - Touch Data X/Y/X
58 */
59#define WM831X_TCH_PD 0x8000 /* TCH_PD1 */
60#define WM831X_TCH_DATA_MASK 0x0FFF /* TCH_DATA - [11:0] */
61#define WM831X_TCH_DATA_SHIFT 0 /* TCH_DATA - [11:0] */
62#define WM831X_TCH_DATA_WIDTH 12 /* TCH_DATA - [11:0] */
63
64struct wm831x_ts {
65 struct input_dev *input_dev;
66 struct wm831x *wm831x;
67 unsigned int data_irq;
68 unsigned int pd_irq;
69 bool pressure;
70 bool pen_down;
71};
72
73static irqreturn_t wm831x_ts_data_irq(int irq, void *irq_data)
74{
75 struct wm831x_ts *wm831x_ts = irq_data;
76 struct wm831x *wm831x = wm831x_ts->wm831x;
77 static int data_types[] = { ABS_X, ABS_Y, ABS_PRESSURE };
78 u16 data[3];
79 int count;
80 int i, ret;
81
82 if (wm831x_ts->pressure)
83 count = 3;
84 else
85 count = 2;
86
87 wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1,
88 WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT);
89
90 ret = wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count,
91 data);
92 if (ret != 0) {
93 dev_err(wm831x->dev, "Failed to read touch data: %d\n",
94 ret);
95 return IRQ_NONE;
96 }
97
98 /*
99 * We get a pen down reading on every reading, report pen up if any
100 * individual reading does so.
101 */
102 wm831x_ts->pen_down = true;
103 for (i = 0; i < count; i++) {
104 if (!(data[i] & WM831X_TCH_PD)) {
105 wm831x_ts->pen_down = false;
106 continue;
107 }
108 input_report_abs(wm831x_ts->input_dev, data_types[i],
109 data[i] & WM831X_TCH_DATA_MASK);
110 }
111
112 if (!wm831x_ts->pen_down) {
113 disable_irq_nosync(wm831x_ts->data_irq);
114
115 /* Don't need data any more */
116 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
117 WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA |
118 WM831X_TCH_Z_ENA, 0);
119
120 /* Flush any final samples that arrived while reading */
121 wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1,
122 WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT);
123
124 wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count, data);
125
126 if (wm831x_ts->pressure)
127 input_report_abs(wm831x_ts->input_dev,
128 ABS_PRESSURE, 0);
129
130 input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 0);
131 }
132
133 input_sync(wm831x_ts->input_dev);
134
135 return IRQ_HANDLED;
136}
137
138static irqreturn_t wm831x_ts_pen_down_irq(int irq, void *irq_data)
139{
140 struct wm831x_ts *wm831x_ts = irq_data;
141 struct wm831x *wm831x = wm831x_ts->wm831x;
142 int ena = 0;
143
144 /* Start collecting data */
145 if (wm831x_ts->pressure)
146 ena |= WM831X_TCH_Z_ENA;
147
148 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
149 WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | WM831X_TCH_Z_ENA,
150 WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | ena);
151
152 input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 1);
153 input_sync(wm831x_ts->input_dev);
154
155 wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1,
156 WM831X_TCHPD_EINT, WM831X_TCHPD_EINT);
157
158 wm831x_ts->pen_down = true;
159 enable_irq(wm831x_ts->data_irq);
160
161 return IRQ_HANDLED;
162}
163
164static int wm831x_ts_input_open(struct input_dev *idev)
165{
166 struct wm831x_ts *wm831x_ts = input_get_drvdata(idev);
167 struct wm831x *wm831x = wm831x_ts->wm831x;
168
169 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
170 WM831X_TCH_ENA | WM831X_TCH_CVT_ENA |
171 WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA |
172 WM831X_TCH_Z_ENA, WM831X_TCH_ENA);
173
174 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
175 WM831X_TCH_CVT_ENA, WM831X_TCH_CVT_ENA);
176
177 return 0;
178}
179
180static void wm831x_ts_input_close(struct input_dev *idev)
181{
182 struct wm831x_ts *wm831x_ts = input_get_drvdata(idev);
183 struct wm831x *wm831x = wm831x_ts->wm831x;
184
185 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
186 WM831X_TCH_ENA | WM831X_TCH_CVT_ENA |
187 WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA |
188 WM831X_TCH_Z_ENA, 0);
189
190 if (wm831x_ts->pen_down)
191 disable_irq(wm831x_ts->data_irq);
192}
193
194static __devinit int wm831x_ts_probe(struct platform_device *pdev)
195{
196 struct wm831x_ts *wm831x_ts;
197 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
198 struct wm831x_pdata *core_pdata = dev_get_platdata(pdev->dev.parent);
199 struct wm831x_touch_pdata *pdata = NULL;
200 struct input_dev *input_dev;
201 int error;
202
203 if (core_pdata)
204 pdata = core_pdata->touch;
205
206 wm831x_ts = kzalloc(sizeof(struct wm831x_ts), GFP_KERNEL);
207 input_dev = input_allocate_device();
208 if (!wm831x_ts || !input_dev) {
209 error = -ENOMEM;
210 goto err_alloc;
211 }
212
213 wm831x_ts->wm831x = wm831x;
214 wm831x_ts->input_dev = input_dev;
215
216 /*
217 * If we have a direct IRQ use it, otherwise use the interrupt
218 * from the WM831x IRQ controller.
219 */
220 if (pdata && pdata->data_irq)
221 wm831x_ts->data_irq = pdata->data_irq;
222 else
223 wm831x_ts->data_irq = platform_get_irq_byname(pdev, "TCHDATA");
224
225 if (pdata && pdata->pd_irq)
226 wm831x_ts->pd_irq = pdata->pd_irq;
227 else
228 wm831x_ts->pd_irq = platform_get_irq_byname(pdev, "TCHPD");
229
230 if (pdata)
231 wm831x_ts->pressure = pdata->pressure;
232 else
233 wm831x_ts->pressure = true;
234
235 /* Five wire touchscreens can't report pressure */
236 if (pdata && pdata->fivewire) {
237 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2,
238 WM831X_TCH_5WIRE, WM831X_TCH_5WIRE);
239
240 /* Pressure measurements are not possible for five wire mode */
241 WARN_ON(pdata->pressure && pdata->fivewire);
242 wm831x_ts->pressure = false;
243 } else {
244 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2,
245 WM831X_TCH_5WIRE, 0);
246 }
247
248 if (pdata) {
249 switch (pdata->isel) {
250 default:
251 dev_err(&pdev->dev, "Unsupported ISEL setting: %d\n",
252 pdata->isel);
253 /* Fall through */
254 case 200:
255 case 0:
256 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2,
257 WM831X_TCH_ISEL, 0);
258 break;
259 case 400:
260 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2,
261 WM831X_TCH_ISEL, WM831X_TCH_ISEL);
262 break;
263 }
264 }
265
266 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2,
267 WM831X_TCH_PDONLY, 0);
268
269 /* Default to 96 samples/sec */
270 wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1,
271 WM831X_TCH_RATE_MASK, 6);
272
273 error = request_threaded_irq(wm831x_ts->data_irq,
274 NULL, wm831x_ts_data_irq,
275 IRQF_ONESHOT,
276 "Touchscreen data", wm831x_ts);
277 if (error) {
278 dev_err(&pdev->dev, "Failed to request data IRQ %d: %d\n",
279 wm831x_ts->data_irq, error);
280 goto err_alloc;
281 }
282 disable_irq(wm831x_ts->data_irq);
283
284 error = request_threaded_irq(wm831x_ts->pd_irq,
285 NULL, wm831x_ts_pen_down_irq,
286 IRQF_ONESHOT,
287 "Touchscreen pen down", wm831x_ts);
288 if (error) {
289 dev_err(&pdev->dev, "Failed to request pen down IRQ %d: %d\n",
290 wm831x_ts->pd_irq, error);
291 goto err_data_irq;
292 }
293
294 /* set up touch configuration */
295 input_dev->name = "WM831x touchscreen";
296 input_dev->phys = "wm831x";
297 input_dev->open = wm831x_ts_input_open;
298 input_dev->close = wm831x_ts_input_close;
299
300 __set_bit(EV_ABS, input_dev->evbit);
301 __set_bit(EV_KEY, input_dev->evbit);
302 __set_bit(BTN_TOUCH, input_dev->keybit);
303
304 input_set_abs_params(input_dev, ABS_X, 0, 4095, 5, 0);
305 input_set_abs_params(input_dev, ABS_Y, 0, 4095, 5, 0);
306 if (wm831x_ts->pressure)
307 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 4095, 5, 0);
308
309 input_set_drvdata(input_dev, wm831x_ts);
310 input_dev->dev.parent = &pdev->dev;
311
312 error = input_register_device(input_dev);
313 if (error)
314 goto err_pd_irq;
315
316 platform_set_drvdata(pdev, wm831x_ts);
317 return 0;
318
319err_pd_irq:
320 free_irq(wm831x_ts->pd_irq, wm831x_ts);
321err_data_irq:
322 free_irq(wm831x_ts->data_irq, wm831x_ts);
323err_alloc:
324 input_free_device(input_dev);
325 kfree(wm831x_ts);
326
327 return error;
328}
329
330static __devexit int wm831x_ts_remove(struct platform_device *pdev)
331{
332 struct wm831x_ts *wm831x_ts = platform_get_drvdata(pdev);
333
334 free_irq(wm831x_ts->pd_irq, wm831x_ts);
335 free_irq(wm831x_ts->data_irq, wm831x_ts);
336 input_unregister_device(wm831x_ts->input_dev);
337 kfree(wm831x_ts);
338
339 platform_set_drvdata(pdev, NULL);
340 return 0;
341}
342
343static struct platform_driver wm831x_ts_driver = {
344 .driver = {
345 .name = "wm831x-touch",
346 .owner = THIS_MODULE,
347 },
348 .probe = wm831x_ts_probe,
349 .remove = __devexit_p(wm831x_ts_remove),
350};
351
352static int __init wm831x_ts_init(void)
353{
354 return platform_driver_register(&wm831x_ts_driver);
355}
356module_init(wm831x_ts_init);
357
358static void __exit wm831x_ts_exit(void)
359{
360 platform_driver_unregister(&wm831x_ts_driver);
361}
362module_exit(wm831x_ts_exit);
363
364/* Module information */
365MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
366MODULE_DESCRIPTION("WM831x PMIC touchscreen driver");
367MODULE_LICENSE("GPL");
368MODULE_ALIAS("platform:wm831x-touch");
diff --git a/drivers/isdn/hisax/Makefile b/drivers/isdn/hisax/Makefile
index ab638b083df9..646368fe41c9 100644
--- a/drivers/isdn/hisax/Makefile
+++ b/drivers/isdn/hisax/Makefile
@@ -4,7 +4,7 @@
4 4
5# Define maximum number of cards 5# Define maximum number of cards
6 6
7EXTRA_CFLAGS += -DHISAX_MAX_CARDS=$(CONFIG_HISAX_MAX_CARDS) 7ccflags-y := -DHISAX_MAX_CARDS=$(CONFIG_HISAX_MAX_CARDS)
8 8
9obj-$(CONFIG_ISDN_DRV_HISAX) += hisax.o 9obj-$(CONFIG_ISDN_DRV_HISAX) += hisax.o
10obj-$(CONFIG_HISAX_SEDLBAUER_CS) += sedlbauer_cs.o 10obj-$(CONFIG_HISAX_SEDLBAUER_CS) += sedlbauer_cs.o
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 23005b3cf30b..b2b9415d874d 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -8,60 +8,71 @@
8#include "dvb-usb-common.h" 8#include "dvb-usb-common.h"
9#include <linux/usb/input.h> 9#include <linux/usb/input.h>
10 10
11static unsigned int
12legacy_dvb_usb_get_keymap_index(const struct input_keymap_entry *ke,
13 struct rc_map_table *keymap,
14 unsigned int keymap_size)
15{
16 unsigned int index;
17 unsigned int scancode;
18
19 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
20 index = ke->index;
21 } else {
22 if (input_scancode_to_scalar(ke, &scancode))
23 return keymap_size;
24
25 /* See if we can match the raw key code. */
26 for (index = 0; index < keymap_size; index++)
27 if (keymap[index].scancode == scancode)
28 break;
29
30 /* See if there is an unused hole in the map */
31 if (index >= keymap_size) {
32 for (index = 0; index < keymap_size; index++) {
33 if (keymap[index].keycode == KEY_RESERVED ||
34 keymap[index].keycode == KEY_UNKNOWN) {
35 break;
36 }
37 }
38 }
39 }
40
41 return index;
42}
43
11static int legacy_dvb_usb_getkeycode(struct input_dev *dev, 44static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
12 unsigned int scancode, unsigned int *keycode) 45 struct input_keymap_entry *ke)
13{ 46{
14 struct dvb_usb_device *d = input_get_drvdata(dev); 47 struct dvb_usb_device *d = input_get_drvdata(dev);
15
16 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; 48 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
17 int i; 49 unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
50 unsigned int index;
18 51
19 /* See if we can match the raw key code. */ 52 index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
20 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 53 if (index >= keymap_size)
21 if (keymap[i].scancode == scancode) { 54 return -EINVAL;
22 *keycode = keymap[i].keycode;
23 return 0;
24 }
25 55
26 /* 56 ke->keycode = keymap[index].keycode;
27 * If is there extra space, returns KEY_RESERVED, 57 if (ke->keycode == KEY_UNKNOWN)
28 * otherwise, input core won't let legacy_dvb_usb_setkeycode 58 ke->keycode = KEY_RESERVED;
29 * to work 59 ke->len = sizeof(keymap[index].scancode);
30 */ 60 memcpy(&ke->scancode, &keymap[index].scancode, ke->len);
31 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 61 ke->index = index;
32 if (keymap[i].keycode == KEY_RESERVED ||
33 keymap[i].keycode == KEY_UNKNOWN) {
34 *keycode = KEY_RESERVED;
35 return 0;
36 }
37 62
38 return -EINVAL; 63 return 0;
39} 64}
40 65
41static int legacy_dvb_usb_setkeycode(struct input_dev *dev, 66static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
42 unsigned int scancode, unsigned int keycode) 67 const struct input_keymap_entry *ke,
68 unsigned int *old_keycode)
43{ 69{
44 struct dvb_usb_device *d = input_get_drvdata(dev); 70 struct dvb_usb_device *d = input_get_drvdata(dev);
45
46 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; 71 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
47 int i; 72 unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
48 73 unsigned int index;
49 /* Search if it is replacing an existing keycode */
50 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
51 if (keymap[i].scancode == scancode) {
52 keymap[i].keycode = keycode;
53 return 0;
54 }
55
56 /* Search if is there a clean entry. If so, use it */
57 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
58 if (keymap[i].keycode == KEY_RESERVED ||
59 keymap[i].keycode == KEY_UNKNOWN) {
60 keymap[i].scancode = scancode;
61 keymap[i].keycode = keycode;
62 return 0;
63 }
64 74
75 index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
65 /* 76 /*
66 * FIXME: Currently, it is not possible to increase the size of 77 * FIXME: Currently, it is not possible to increase the size of
67 * scancode table. For it to happen, one possibility 78 * scancode table. For it to happen, one possibility
@@ -69,8 +80,24 @@ static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
69 * copying data, appending the new key on it, and freeing 80 * copying data, appending the new key on it, and freeing
70 * the old one - or maybe just allocating some spare space 81 * the old one - or maybe just allocating some spare space
71 */ 82 */
83 if (index >= keymap_size)
84 return -EINVAL;
85
86 *old_keycode = keymap[index].keycode;
87 keymap->keycode = ke->keycode;
88 __set_bit(ke->keycode, dev->keybit);
89
90 if (*old_keycode != KEY_RESERVED) {
91 __clear_bit(*old_keycode, dev->keybit);
92 for (index = 0; index < keymap_size; index++) {
93 if (keymap[index].keycode == *old_keycode) {
94 __set_bit(*old_keycode, dev->keybit);
95 break;
96 }
97 }
98 }
72 99
73 return -EINVAL; 100 return 0;
74} 101}
75 102
76/* Remote-control poll function - called every dib->rc_query_interval ms to see 103/* Remote-control poll function - called every dib->rc_query_interval ms to see
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 5b4422ef4e6d..5ac1baf45c8e 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -966,8 +966,8 @@ struct rc_dev *rc_allocate_device(void)
966 return NULL; 966 return NULL;
967 } 967 }
968 968
969 dev->input_dev->getkeycode_new = ir_getkeycode; 969 dev->input_dev->getkeycode = ir_getkeycode;
970 dev->input_dev->setkeycode_new = ir_setkeycode; 970 dev->input_dev->setkeycode = ir_setkeycode;
971 input_set_drvdata(dev->input_dev, dev); 971 input_set_drvdata(dev->input_dev, dev);
972 972
973 spin_lock_init(&dev->rc_map.lock); 973 spin_lock_init(&dev->rc_map.lock);
diff --git a/drivers/memstick/Makefile b/drivers/memstick/Makefile
index dc160fb43515..98623590c7fe 100644
--- a/drivers/memstick/Makefile
+++ b/drivers/memstick/Makefile
@@ -2,9 +2,7 @@
2# Makefile for the kernel MemoryStick device drivers. 2# Makefile for the kernel MemoryStick device drivers.
3# 3#
4 4
5ifeq ($(CONFIG_MEMSTICK_DEBUG),y) 5subdir-ccflags-$(CONFIG_MEMSTICK_DEBUG) := -DDEBUG
6 EXTRA_CFLAGS += -DDEBUG
7endif
8 6
9obj-$(CONFIG_MEMSTICK) += core/ 7obj-$(CONFIG_MEMSTICK) += core/
10obj-$(CONFIG_MEMSTICK) += host/ 8obj-$(CONFIG_MEMSTICK) += host/
diff --git a/drivers/memstick/core/Makefile b/drivers/memstick/core/Makefile
index 8b2b5293877e..ecd029937738 100644
--- a/drivers/memstick/core/Makefile
+++ b/drivers/memstick/core/Makefile
@@ -2,10 +2,6 @@
2# Makefile for the kernel MemoryStick core. 2# Makefile for the kernel MemoryStick core.
3# 3#
4 4
5ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
6 EXTRA_CFLAGS += -DDEBUG
7endif
8
9obj-$(CONFIG_MEMSTICK) += memstick.o 5obj-$(CONFIG_MEMSTICK) += memstick.o
10 6
11obj-$(CONFIG_MSPRO_BLOCK) += mspro_block.o 7obj-$(CONFIG_MSPRO_BLOCK) += mspro_block.o
diff --git a/drivers/memstick/host/Makefile b/drivers/memstick/host/Makefile
index 12530e4311d3..a1815e9dd019 100644
--- a/drivers/memstick/host/Makefile
+++ b/drivers/memstick/host/Makefile
@@ -2,9 +2,5 @@
2# Makefile for MemoryStick host controller drivers 2# Makefile for MemoryStick host controller drivers
3# 3#
4 4
5ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
6 EXTRA_CFLAGS += -DDEBUG
7endif
8
9obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o 5obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o
10obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o 6obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o
diff --git a/drivers/message/fusion/Makefile b/drivers/message/fusion/Makefile
index 95c9532cb07c..d182a24b3195 100644
--- a/drivers/message/fusion/Makefile
+++ b/drivers/message/fusion/Makefile
@@ -2,7 +2,7 @@
2 2
3# enable verbose logging 3# enable verbose logging
4# CONFIG_FUSION_LOGGING needs to be enabled in Kconfig 4# CONFIG_FUSION_LOGGING needs to be enabled in Kconfig
5#EXTRA_CFLAGS += -DMPT_DEBUG_VERBOSE 5#ccflags-y := -DMPT_DEBUG_VERBOSE
6 6
7 7
8#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC 8#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC
diff --git a/drivers/misc/cb710/Makefile b/drivers/misc/cb710/Makefile
index 7b80cbf1a609..467c8e9ca3c9 100644
--- a/drivers/misc/cb710/Makefile
+++ b/drivers/misc/cb710/Makefile
@@ -1,6 +1,4 @@
1ifeq ($(CONFIG_CB710_DEBUG),y) 1ccflags-$(CONFIG_CB710_DEBUG) := -DDEBUG
2 EXTRA_CFLAGS += -DDEBUG
3endif
4 2
5obj-$(CONFIG_CB710_CORE) += cb710.o 3obj-$(CONFIG_CB710_CORE) += cb710.o
6 4
diff --git a/drivers/misc/sgi-gru/Makefile b/drivers/misc/sgi-gru/Makefile
index 7c4c306dfa8a..0003a1d56f7f 100644
--- a/drivers/misc/sgi-gru/Makefile
+++ b/drivers/misc/sgi-gru/Makefile
@@ -1,6 +1,4 @@
1ifdef CONFIG_SGI_GRU_DEBUG 1ccflags-$(CONFIG_SGI_GRU_DEBUG) := -DDEBUG
2 EXTRA_CFLAGS += -DDEBUG
3endif
4 2
5obj-$(CONFIG_SGI_GRU) := gru.o 3obj-$(CONFIG_SGI_GRU) := gru.o
6gru-y := grufile.o grumain.o grufault.o grutlbpurge.o gruprocfs.o grukservices.o gruhandles.o grukdump.o 4gru-y := grufile.o grumain.o grufault.o grutlbpurge.o gruprocfs.o grukservices.o gruhandles.o grukdump.o
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index 2a876c4099cd..3b1f783bf924 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -58,12 +58,11 @@ config SDIO_UART
58 58
59config MMC_TEST 59config MMC_TEST
60 tristate "MMC host test driver" 60 tristate "MMC host test driver"
61 default n
62 help 61 help
63 Development driver that performs a series of reads and writes 62 Development driver that performs a series of reads and writes
64 to a memory card in order to expose certain well known bugs 63 to a memory card in order to expose certain well known bugs
65 in host controllers. The tests are executed by writing to the 64 in host controllers. The tests are executed by writing to the
66 "test" file in sysfs under each card. Note that whatever is 65 "test" file in debugfs under each card. Note that whatever is
67 on your card will be overwritten by these tests. 66 on your card will be overwritten by these tests.
68 67
69 This driver is only of interest to those developing or 68 This driver is only of interest to those developing or
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index bfc8a8ae55df..61d233a7c118 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -621,6 +621,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
621 md->disk->private_data = md; 621 md->disk->private_data = md;
622 md->disk->queue = md->queue.queue; 622 md->disk->queue = md->queue.queue;
623 md->disk->driverfs_dev = &card->dev; 623 md->disk->driverfs_dev = &card->dev;
624 set_disk_ro(md->disk, md->read_only);
624 625
625 /* 626 /*
626 * As discussed on lkml, GENHD_FL_REMOVABLE should: 627 * As discussed on lkml, GENHD_FL_REMOVABLE should:
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 21adc27f4132..5ec8eddfcf6e 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -88,6 +88,7 @@ struct mmc_test_area {
88 * @sectors: amount of sectors to check in one group 88 * @sectors: amount of sectors to check in one group
89 * @ts: time values of transfer 89 * @ts: time values of transfer
90 * @rate: calculated transfer rate 90 * @rate: calculated transfer rate
91 * @iops: I/O operations per second (times 100)
91 */ 92 */
92struct mmc_test_transfer_result { 93struct mmc_test_transfer_result {
93 struct list_head link; 94 struct list_head link;
@@ -95,6 +96,7 @@ struct mmc_test_transfer_result {
95 unsigned int sectors; 96 unsigned int sectors;
96 struct timespec ts; 97 struct timespec ts;
97 unsigned int rate; 98 unsigned int rate;
99 unsigned int iops;
98}; 100};
99 101
100/** 102/**
@@ -226,9 +228,10 @@ static int mmc_test_wait_busy(struct mmc_test_card *test)
226 228
227 if (!busy && mmc_test_busy(&cmd)) { 229 if (!busy && mmc_test_busy(&cmd)) {
228 busy = 1; 230 busy = 1;
229 printk(KERN_INFO "%s: Warning: Host did not " 231 if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
230 "wait for busy state to end.\n", 232 printk(KERN_INFO "%s: Warning: Host did not "
231 mmc_hostname(test->card->host)); 233 "wait for busy state to end.\n",
234 mmc_hostname(test->card->host));
232 } 235 }
233 } while (mmc_test_busy(&cmd)); 236 } while (mmc_test_busy(&cmd));
234 237
@@ -494,7 +497,7 @@ static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
494 */ 497 */
495static void mmc_test_save_transfer_result(struct mmc_test_card *test, 498static void mmc_test_save_transfer_result(struct mmc_test_card *test,
496 unsigned int count, unsigned int sectors, struct timespec ts, 499 unsigned int count, unsigned int sectors, struct timespec ts,
497 unsigned int rate) 500 unsigned int rate, unsigned int iops)
498{ 501{
499 struct mmc_test_transfer_result *tr; 502 struct mmc_test_transfer_result *tr;
500 503
@@ -509,6 +512,7 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test,
509 tr->sectors = sectors; 512 tr->sectors = sectors;
510 tr->ts = ts; 513 tr->ts = ts;
511 tr->rate = rate; 514 tr->rate = rate;
515 tr->iops = iops;
512 516
513 list_add_tail(&tr->link, &test->gr->tr_lst); 517 list_add_tail(&tr->link, &test->gr->tr_lst);
514} 518}
@@ -519,20 +523,22 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test,
519static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, 523static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
520 struct timespec *ts1, struct timespec *ts2) 524 struct timespec *ts1, struct timespec *ts2)
521{ 525{
522 unsigned int rate, sectors = bytes >> 9; 526 unsigned int rate, iops, sectors = bytes >> 9;
523 struct timespec ts; 527 struct timespec ts;
524 528
525 ts = timespec_sub(*ts2, *ts1); 529 ts = timespec_sub(*ts2, *ts1);
526 530
527 rate = mmc_test_rate(bytes, &ts); 531 rate = mmc_test_rate(bytes, &ts);
532 iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
528 533
529 printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu " 534 printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
530 "seconds (%u kB/s, %u KiB/s)\n", 535 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
531 mmc_hostname(test->card->host), sectors, sectors >> 1, 536 mmc_hostname(test->card->host), sectors, sectors >> 1,
532 (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec, 537 (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
533 (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024); 538 (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
539 iops / 100, iops % 100);
534 540
535 mmc_test_save_transfer_result(test, 1, sectors, ts, rate); 541 mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
536} 542}
537 543
538/* 544/*
@@ -542,22 +548,24 @@ static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
542 unsigned int count, struct timespec *ts1, 548 unsigned int count, struct timespec *ts1,
543 struct timespec *ts2) 549 struct timespec *ts2)
544{ 550{
545 unsigned int rate, sectors = bytes >> 9; 551 unsigned int rate, iops, sectors = bytes >> 9;
546 uint64_t tot = bytes * count; 552 uint64_t tot = bytes * count;
547 struct timespec ts; 553 struct timespec ts;
548 554
549 ts = timespec_sub(*ts2, *ts1); 555 ts = timespec_sub(*ts2, *ts1);
550 556
551 rate = mmc_test_rate(tot, &ts); 557 rate = mmc_test_rate(tot, &ts);
558 iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
552 559
553 printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took " 560 printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
554 "%lu.%09lu seconds (%u kB/s, %u KiB/s)\n", 561 "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
562 "%u.%02u IOPS)\n",
555 mmc_hostname(test->card->host), count, sectors, count, 563 mmc_hostname(test->card->host), count, sectors, count,
556 sectors >> 1, (sectors & 1 ? ".5" : ""), 564 sectors >> 1, (sectors & 1 ? ".5" : ""),
557 (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec, 565 (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
558 rate / 1000, rate / 1024); 566 rate / 1000, rate / 1024, iops / 100, iops % 100);
559 567
560 mmc_test_save_transfer_result(test, count, sectors, ts, rate); 568 mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
561} 569}
562 570
563/* 571/*
@@ -1425,28 +1433,29 @@ static int mmc_test_area_cleanup(struct mmc_test_card *test)
1425} 1433}
1426 1434
1427/* 1435/*
1428 * Initialize an area for testing large transfers. The size of the area is the 1436 * Initialize an area for testing large transfers. The test area is set to the
1429 * preferred erase size which is a good size for optimal transfer speed. Note 1437 * middle of the card because cards may have different charateristics at the
1430 * that is typically 4MiB for modern cards. The test area is set to the middle 1438 * front (for FAT file system optimization). Optionally, the area is erased
1431 * of the card because cards may have different charateristics at the front 1439 * (if the card supports it) which may improve write performance. Optionally,
1432 * (for FAT file system optimization). Optionally, the area is erased (if the 1440 * the area is filled with data for subsequent read tests.
1433 * card supports it) which may improve write performance. Optionally, the area
1434 * is filled with data for subsequent read tests.
1435 */ 1441 */
1436static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill) 1442static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1437{ 1443{
1438 struct mmc_test_area *t = &test->area; 1444 struct mmc_test_area *t = &test->area;
1439 unsigned long min_sz = 64 * 1024; 1445 unsigned long min_sz = 64 * 1024, sz;
1440 int ret; 1446 int ret;
1441 1447
1442 ret = mmc_test_set_blksize(test, 512); 1448 ret = mmc_test_set_blksize(test, 512);
1443 if (ret) 1449 if (ret)
1444 return ret; 1450 return ret;
1445 1451
1446 if (test->card->pref_erase > TEST_AREA_MAX_SIZE >> 9) 1452 /* Make the test area size about 4MiB */
1447 t->max_sz = TEST_AREA_MAX_SIZE; 1453 sz = (unsigned long)test->card->pref_erase << 9;
1448 else 1454 t->max_sz = sz;
1449 t->max_sz = (unsigned long)test->card->pref_erase << 9; 1455 while (t->max_sz < 4 * 1024 * 1024)
1456 t->max_sz += sz;
1457 while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
1458 t->max_sz -= sz;
1450 1459
1451 t->max_segs = test->card->host->max_segs; 1460 t->max_segs = test->card->host->max_segs;
1452 t->max_seg_sz = test->card->host->max_seg_size; 1461 t->max_seg_sz = test->card->host->max_seg_size;
@@ -1766,6 +1775,188 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
1766 return 0; 1775 return 0;
1767} 1776}
1768 1777
1778static unsigned int rnd_next = 1;
1779
1780static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
1781{
1782 uint64_t r;
1783
1784 rnd_next = rnd_next * 1103515245 + 12345;
1785 r = (rnd_next >> 16) & 0x7fff;
1786 return (r * rnd_cnt) >> 15;
1787}
1788
1789static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
1790 unsigned long sz)
1791{
1792 unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
1793 unsigned int ssz;
1794 struct timespec ts1, ts2, ts;
1795 int ret;
1796
1797 ssz = sz >> 9;
1798
1799 rnd_addr = mmc_test_capacity(test->card) / 4;
1800 range1 = rnd_addr / test->card->pref_erase;
1801 range2 = range1 / ssz;
1802
1803 getnstimeofday(&ts1);
1804 for (cnt = 0; cnt < UINT_MAX; cnt++) {
1805 getnstimeofday(&ts2);
1806 ts = timespec_sub(ts2, ts1);
1807 if (ts.tv_sec >= 10)
1808 break;
1809 ea = mmc_test_rnd_num(range1);
1810 if (ea == last_ea)
1811 ea -= 1;
1812 last_ea = ea;
1813 dev_addr = rnd_addr + test->card->pref_erase * ea +
1814 ssz * mmc_test_rnd_num(range2);
1815 ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
1816 if (ret)
1817 return ret;
1818 }
1819 if (print)
1820 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1821 return 0;
1822}
1823
1824static int mmc_test_random_perf(struct mmc_test_card *test, int write)
1825{
1826 unsigned int next;
1827 unsigned long sz;
1828 int ret;
1829
1830 for (sz = 512; sz < test->area.max_tfr; sz <<= 1) {
1831 /*
1832 * When writing, try to get more consistent results by running
1833 * the test twice with exactly the same I/O but outputting the
1834 * results only for the 2nd run.
1835 */
1836 if (write) {
1837 next = rnd_next;
1838 ret = mmc_test_rnd_perf(test, write, 0, sz);
1839 if (ret)
1840 return ret;
1841 rnd_next = next;
1842 }
1843 ret = mmc_test_rnd_perf(test, write, 1, sz);
1844 if (ret)
1845 return ret;
1846 }
1847 sz = test->area.max_tfr;
1848 if (write) {
1849 next = rnd_next;
1850 ret = mmc_test_rnd_perf(test, write, 0, sz);
1851 if (ret)
1852 return ret;
1853 rnd_next = next;
1854 }
1855 return mmc_test_rnd_perf(test, write, 1, sz);
1856}
1857
1858/*
1859 * Random read performance by transfer size.
1860 */
1861static int mmc_test_random_read_perf(struct mmc_test_card *test)
1862{
1863 return mmc_test_random_perf(test, 0);
1864}
1865
1866/*
1867 * Random write performance by transfer size.
1868 */
1869static int mmc_test_random_write_perf(struct mmc_test_card *test)
1870{
1871 return mmc_test_random_perf(test, 1);
1872}
1873
1874static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
1875 unsigned int tot_sz, int max_scatter)
1876{
1877 unsigned int dev_addr, i, cnt, sz, ssz;
1878 struct timespec ts1, ts2, ts;
1879 int ret;
1880
1881 sz = test->area.max_tfr;
1882 /*
1883 * In the case of a maximally scattered transfer, the maximum transfer
1884 * size is further limited by using PAGE_SIZE segments.
1885 */
1886 if (max_scatter) {
1887 struct mmc_test_area *t = &test->area;
1888 unsigned long max_tfr;
1889
1890 if (t->max_seg_sz >= PAGE_SIZE)
1891 max_tfr = t->max_segs * PAGE_SIZE;
1892 else
1893 max_tfr = t->max_segs * t->max_seg_sz;
1894 if (sz > max_tfr)
1895 sz = max_tfr;
1896 }
1897
1898 ssz = sz >> 9;
1899 dev_addr = mmc_test_capacity(test->card) / 4;
1900 if (tot_sz > dev_addr << 9)
1901 tot_sz = dev_addr << 9;
1902 cnt = tot_sz / sz;
1903 dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
1904
1905 getnstimeofday(&ts1);
1906 for (i = 0; i < cnt; i++) {
1907 ret = mmc_test_area_io(test, sz, dev_addr, write,
1908 max_scatter, 0);
1909 if (ret)
1910 return ret;
1911 dev_addr += ssz;
1912 }
1913 getnstimeofday(&ts2);
1914
1915 ts = timespec_sub(ts2, ts1);
1916 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1917
1918 return 0;
1919}
1920
1921static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
1922{
1923 int ret, i;
1924
1925 for (i = 0; i < 10; i++) {
1926 ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
1927 if (ret)
1928 return ret;
1929 }
1930 for (i = 0; i < 5; i++) {
1931 ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
1932 if (ret)
1933 return ret;
1934 }
1935 for (i = 0; i < 3; i++) {
1936 ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
1937 if (ret)
1938 return ret;
1939 }
1940
1941 return ret;
1942}
1943
1944/*
1945 * Large sequential read performance.
1946 */
1947static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
1948{
1949 return mmc_test_large_seq_perf(test, 0);
1950}
1951
1952/*
1953 * Large sequential write performance.
1954 */
1955static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
1956{
1957 return mmc_test_large_seq_perf(test, 1);
1958}
1959
1769static const struct mmc_test_case mmc_test_cases[] = { 1960static const struct mmc_test_case mmc_test_cases[] = {
1770 { 1961 {
1771 .name = "Basic write (no data verification)", 1962 .name = "Basic write (no data verification)",
@@ -2005,6 +2196,34 @@ static const struct mmc_test_case mmc_test_cases[] = {
2005 .cleanup = mmc_test_area_cleanup, 2196 .cleanup = mmc_test_area_cleanup,
2006 }, 2197 },
2007 2198
2199 {
2200 .name = "Random read performance by transfer size",
2201 .prepare = mmc_test_area_prepare,
2202 .run = mmc_test_random_read_perf,
2203 .cleanup = mmc_test_area_cleanup,
2204 },
2205
2206 {
2207 .name = "Random write performance by transfer size",
2208 .prepare = mmc_test_area_prepare,
2209 .run = mmc_test_random_write_perf,
2210 .cleanup = mmc_test_area_cleanup,
2211 },
2212
2213 {
2214 .name = "Large sequential read into scattered pages",
2215 .prepare = mmc_test_area_prepare,
2216 .run = mmc_test_large_seq_read_perf,
2217 .cleanup = mmc_test_area_cleanup,
2218 },
2219
2220 {
2221 .name = "Large sequential write from scattered pages",
2222 .prepare = mmc_test_area_prepare,
2223 .run = mmc_test_large_seq_write_perf,
2224 .cleanup = mmc_test_area_cleanup,
2225 },
2226
2008}; 2227};
2009 2228
2010static DEFINE_MUTEX(mmc_test_lock); 2229static DEFINE_MUTEX(mmc_test_lock);
@@ -2148,11 +2367,11 @@ static int mtf_test_show(struct seq_file *sf, void *data)
2148 seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result); 2367 seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
2149 2368
2150 list_for_each_entry(tr, &gr->tr_lst, link) { 2369 list_for_each_entry(tr, &gr->tr_lst, link) {
2151 seq_printf(sf, "%u %d %lu.%09lu %u\n", 2370 seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n",
2152 tr->count, tr->sectors, 2371 tr->count, tr->sectors,
2153 (unsigned long)tr->ts.tv_sec, 2372 (unsigned long)tr->ts.tv_sec,
2154 (unsigned long)tr->ts.tv_nsec, 2373 (unsigned long)tr->ts.tv_nsec,
2155 tr->rate); 2374 tr->rate, tr->iops / 100, tr->iops % 100);
2156 } 2375 }
2157 } 2376 }
2158 2377
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 86b479119332..639501970b41 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_MMC) += mmc_core.o
6mmc_core-y := core.o bus.o host.o \ 6mmc_core-y := core.o bus.o host.o \
7 mmc.o mmc_ops.o sd.o sd_ops.o \ 7 mmc.o mmc_ops.o sd.o sd_ops.o \
8 sdio.o sdio_ops.o sdio_bus.o \ 8 sdio.o sdio_ops.o sdio_bus.o \
9 sdio_cis.o sdio_io.o sdio_irq.o 9 sdio_cis.o sdio_io.o sdio_irq.o \
10 quirks.o
10 11
11mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 150b5f3cd401..1f453acc8682 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -167,8 +167,6 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
167 167
168 WARN_ON(!host->claimed); 168 WARN_ON(!host->claimed);
169 169
170 led_trigger_event(host->led, LED_FULL);
171
172 mrq->cmd->error = 0; 170 mrq->cmd->error = 0;
173 mrq->cmd->mrq = mrq; 171 mrq->cmd->mrq = mrq;
174 if (mrq->data) { 172 if (mrq->data) {
@@ -194,6 +192,7 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
194 } 192 }
195 } 193 }
196 mmc_host_clk_ungate(host); 194 mmc_host_clk_ungate(host);
195 led_trigger_event(host->led, LED_FULL);
197 host->ops->request(host, mrq); 196 host->ops->request(host, mrq);
198} 197}
199 198
@@ -528,7 +527,14 @@ int mmc_try_claim_host(struct mmc_host *host)
528} 527}
529EXPORT_SYMBOL(mmc_try_claim_host); 528EXPORT_SYMBOL(mmc_try_claim_host);
530 529
531static void mmc_do_release_host(struct mmc_host *host) 530/**
531 * mmc_do_release_host - release a claimed host
532 * @host: mmc host to release
533 *
534 * If you successfully claimed a host, this function will
535 * release it again.
536 */
537void mmc_do_release_host(struct mmc_host *host)
532{ 538{
533 unsigned long flags; 539 unsigned long flags;
534 540
@@ -543,6 +549,7 @@ static void mmc_do_release_host(struct mmc_host *host)
543 wake_up(&host->wq); 549 wake_up(&host->wq);
544 } 550 }
545} 551}
552EXPORT_SYMBOL(mmc_do_release_host);
546 553
547void mmc_host_deeper_disable(struct work_struct *work) 554void mmc_host_deeper_disable(struct work_struct *work)
548{ 555{
@@ -1002,6 +1009,13 @@ static void mmc_power_off(struct mmc_host *host)
1002{ 1009{
1003 host->ios.clock = 0; 1010 host->ios.clock = 0;
1004 host->ios.vdd = 0; 1011 host->ios.vdd = 0;
1012
1013 /*
1014 * Reset ocr mask to be the highest possible voltage supported for
1015 * this mmc host. This value will be used at next power up.
1016 */
1017 host->ocr = 1 << (fls(host->ocr_avail) - 1);
1018
1005 if (!mmc_host_is_spi(host)) { 1019 if (!mmc_host_is_spi(host)) {
1006 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 1020 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1007 host->ios.chip_select = MMC_CS_DONTCARE; 1021 host->ios.chip_select = MMC_CS_DONTCARE;
@@ -1495,6 +1509,12 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
1495 mmc_hostname(host), __func__, host->f_init); 1509 mmc_hostname(host), __func__, host->f_init);
1496#endif 1510#endif
1497 mmc_power_up(host); 1511 mmc_power_up(host);
1512
1513 /*
1514 * sdio_reset sends CMD52 to reset card. Since we do not know
1515 * if the card is being re-initialized, just send it. CMD52
1516 * should be ignored by SD/eMMC cards.
1517 */
1498 sdio_reset(host); 1518 sdio_reset(host);
1499 mmc_go_idle(host); 1519 mmc_go_idle(host);
1500 1520
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index ca1fdde29df6..20b1c0831eac 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -61,6 +61,8 @@ int mmc_attach_mmc(struct mmc_host *host);
61int mmc_attach_sd(struct mmc_host *host); 61int mmc_attach_sd(struct mmc_host *host);
62int mmc_attach_sdio(struct mmc_host *host); 62int mmc_attach_sdio(struct mmc_host *host);
63 63
64void mmc_fixup_device(struct mmc_card *card);
65
64/* Module parameters */ 66/* Module parameters */
65extern int use_spi_crc; 67extern int use_spi_crc;
66 68
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index b3ac6c5bc5c6..461e6a17fb90 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -160,10 +160,7 @@ static bool mmc_host_may_gate_card(struct mmc_card *card)
160 * gate the clock, because there is somebody out there that may still 160 * gate the clock, because there is somebody out there that may still
161 * be using it. 161 * be using it.
162 */ 162 */
163 if (mmc_card_sdio(card)) 163 return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING);
164 return false;
165
166 return true;
167} 164}
168 165
169/** 166/**
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 16006ef153fe..14e95f39a7bf 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -302,6 +302,44 @@ static int mmc_read_ext_csd(struct mmc_card *card)
302 } 302 }
303 303
304 if (card->ext_csd.rev >= 4) { 304 if (card->ext_csd.rev >= 4) {
305 /*
306 * Enhanced area feature support -- check whether the eMMC
307 * card has the Enhanced area enabled. If so, export enhanced
308 * area offset and size to user by adding sysfs interface.
309 */
310 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
311 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
312 u8 hc_erase_grp_sz =
313 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
314 u8 hc_wp_grp_sz =
315 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
316
317 card->ext_csd.enhanced_area_en = 1;
318 /*
319 * calculate the enhanced data area offset, in bytes
320 */
321 card->ext_csd.enhanced_area_offset =
322 (ext_csd[139] << 24) + (ext_csd[138] << 16) +
323 (ext_csd[137] << 8) + ext_csd[136];
324 if (mmc_card_blockaddr(card))
325 card->ext_csd.enhanced_area_offset <<= 9;
326 /*
327 * calculate the enhanced data area size, in kilobytes
328 */
329 card->ext_csd.enhanced_area_size =
330 (ext_csd[142] << 16) + (ext_csd[141] << 8) +
331 ext_csd[140];
332 card->ext_csd.enhanced_area_size *=
333 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz);
334 card->ext_csd.enhanced_area_size <<= 9;
335 } else {
336 /*
337 * If the enhanced area is not enabled, disable these
338 * device attributes.
339 */
340 card->ext_csd.enhanced_area_offset = -EINVAL;
341 card->ext_csd.enhanced_area_size = -EINVAL;
342 }
305 card->ext_csd.sec_trim_mult = 343 card->ext_csd.sec_trim_mult =
306 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 344 ext_csd[EXT_CSD_SEC_TRIM_MULT];
307 card->ext_csd.sec_erase_mult = 345 card->ext_csd.sec_erase_mult =
@@ -336,6 +374,9 @@ MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
336MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 374MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
337MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); 375MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
338MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); 376MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
377MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
378 card->ext_csd.enhanced_area_offset);
379MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
339 380
340static struct attribute *mmc_std_attrs[] = { 381static struct attribute *mmc_std_attrs[] = {
341 &dev_attr_cid.attr, 382 &dev_attr_cid.attr,
@@ -349,6 +390,8 @@ static struct attribute *mmc_std_attrs[] = {
349 &dev_attr_name.attr, 390 &dev_attr_name.attr,
350 &dev_attr_oemid.attr, 391 &dev_attr_oemid.attr,
351 &dev_attr_serial.attr, 392 &dev_attr_serial.attr,
393 &dev_attr_enhanced_area_offset.attr,
394 &dev_attr_enhanced_area_size.attr,
352 NULL, 395 NULL,
353}; 396};
354 397
@@ -378,6 +421,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
378 int err, ddr = 0; 421 int err, ddr = 0;
379 u32 cid[4]; 422 u32 cid[4];
380 unsigned int max_dtr; 423 unsigned int max_dtr;
424 u32 rocr;
381 425
382 BUG_ON(!host); 426 BUG_ON(!host);
383 WARN_ON(!host->claimed); 427 WARN_ON(!host->claimed);
@@ -391,7 +435,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
391 mmc_go_idle(host); 435 mmc_go_idle(host);
392 436
393 /* The extra bit indicates that we support high capacity */ 437 /* The extra bit indicates that we support high capacity */
394 err = mmc_send_op_cond(host, ocr | (1 << 30), NULL); 438 err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr);
395 if (err) 439 if (err)
396 goto err; 440 goto err;
397 441
@@ -479,11 +523,51 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
479 err = mmc_read_ext_csd(card); 523 err = mmc_read_ext_csd(card);
480 if (err) 524 if (err)
481 goto free_card; 525 goto free_card;
526
527 /* If doing byte addressing, check if required to do sector
528 * addressing. Handle the case of <2GB cards needing sector
529 * addressing. See section 8.1 JEDEC Standard JED84-A441;
530 * ocr register has bit 30 set for sector addressing.
531 */
532 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30)))
533 mmc_card_set_blockaddr(card);
534
482 /* Erase size depends on CSD and Extended CSD */ 535 /* Erase size depends on CSD and Extended CSD */
483 mmc_set_erase_size(card); 536 mmc_set_erase_size(card);
484 } 537 }
485 538
486 /* 539 /*
540 * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF
541 * bit. This bit will be lost everytime after a reset or power off.
542 */
543 if (card->ext_csd.enhanced_area_en) {
544 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
545 EXT_CSD_ERASE_GROUP_DEF, 1);
546
547 if (err && err != -EBADMSG)
548 goto free_card;
549
550 if (err) {
551 err = 0;
552 /*
553 * Just disable enhanced area off & sz
554 * will try to enable ERASE_GROUP_DEF
555 * during next time reinit
556 */
557 card->ext_csd.enhanced_area_offset = -EINVAL;
558 card->ext_csd.enhanced_area_size = -EINVAL;
559 } else {
560 card->ext_csd.erase_group_def = 1;
561 /*
562 * enable ERASE_GRP_DEF successfully.
563 * This will affect the erase size, so
564 * here need to reset erase size
565 */
566 mmc_set_erase_size(card);
567 }
568 }
569
570 /*
487 * Activate high speed (if supported) 571 * Activate high speed (if supported)
488 */ 572 */
489 if ((card->ext_csd.hs_max_dtr != 0) && 573 if ((card->ext_csd.hs_max_dtr != 0) &&
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
new file mode 100644
index 000000000000..11118b74eb20
--- /dev/null
+++ b/drivers/mmc/core/quirks.c
@@ -0,0 +1,84 @@
1/*
2 * This file contains work-arounds for many known sdio hardware
3 * bugs.
4 *
5 * Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
6 * Inspired from pci fixup code:
7 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
8 *
9 */
10
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/mmc/card.h>
14#include <linux/mod_devicetable.h>
15
16/*
17 * The world is not perfect and supplies us with broken mmc/sdio devices.
18 * For at least a part of these bugs we need a work-around
19 */
20
21struct mmc_fixup {
22 u16 vendor, device; /* You can use SDIO_ANY_ID here of course */
23 void (*vendor_fixup)(struct mmc_card *card, int data);
24 int data;
25};
26
27/*
28 * This hook just adds a quirk unconditionnally
29 */
30static void __maybe_unused add_quirk(struct mmc_card *card, int data)
31{
32 card->quirks |= data;
33}
34
35/*
36 * This hook just removes a quirk unconditionnally
37 */
38static void __maybe_unused remove_quirk(struct mmc_card *card, int data)
39{
40 card->quirks &= ~data;
41}
42
43/*
44 * This hook just adds a quirk for all sdio devices
45 */
46static void add_quirk_for_sdio_devices(struct mmc_card *card, int data)
47{
48 if (mmc_card_sdio(card))
49 card->quirks |= data;
50}
51
52#ifndef SDIO_VENDOR_ID_TI
53#define SDIO_VENDOR_ID_TI 0x0097
54#endif
55
56#ifndef SDIO_DEVICE_ID_TI_WL1271
57#define SDIO_DEVICE_ID_TI_WL1271 0x4076
58#endif
59
60static const struct mmc_fixup mmc_fixup_methods[] = {
61 /* by default sdio devices are considered CLK_GATING broken */
62 /* good cards will be whitelisted as they are tested */
63 { SDIO_ANY_ID, SDIO_ANY_ID,
64 add_quirk_for_sdio_devices, MMC_QUIRK_BROKEN_CLK_GATING },
65 { SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
66 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING },
67 { 0 }
68};
69
70void mmc_fixup_device(struct mmc_card *card)
71{
72 const struct mmc_fixup *f;
73
74 for (f = mmc_fixup_methods; f->vendor_fixup; f++) {
75 if ((f->vendor == card->cis.vendor
76 || f->vendor == (u16) SDIO_ANY_ID) &&
77 (f->device == card->cis.device
78 || f->device == (u16) SDIO_ANY_ID)) {
79 dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
80 f->vendor_fixup(card, f->data);
81 }
82 }
83}
84EXPORT_SYMBOL(mmc_fixup_device);
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index d18c32bca99b..6dac89fe0535 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -21,6 +21,7 @@
21#include "core.h" 21#include "core.h"
22#include "bus.h" 22#include "bus.h"
23#include "mmc_ops.h" 23#include "mmc_ops.h"
24#include "sd.h"
24#include "sd_ops.h" 25#include "sd_ops.h"
25 26
26static const unsigned int tran_exp[] = { 27static const unsigned int tran_exp[] = {
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ebc62ad4cc56..db0f0b44d684 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -395,6 +395,14 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
395 if (err) 395 if (err)
396 goto remove; 396 goto remove;
397 397
398 /*
399 * Update oldcard with the new RCA received from the SDIO
400 * device -- we're doing this so that it's updated in the
401 * "card" struct when oldcard overwrites that later.
402 */
403 if (oldcard)
404 oldcard->rca = card->rca;
405
398 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 406 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
399 } 407 }
400 408
@@ -458,6 +466,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
458 466
459 card = oldcard; 467 card = oldcard;
460 } 468 }
469 mmc_fixup_device(card);
461 470
462 if (card->type == MMC_TYPE_SD_COMBO) { 471 if (card->type == MMC_TYPE_SD_COMBO) {
463 err = mmc_sd_setup_card(host, card, oldcard != NULL); 472 err = mmc_sd_setup_card(host, card, oldcard != NULL);
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 54f91321749a..1a21c6427a19 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -311,7 +311,7 @@ config MMC_MSM
311 311
312config MMC_MXC 312config MMC_MXC
313 tristate "Freescale i.MX2/3 Multimedia Card Interface support" 313 tristate "Freescale i.MX2/3 Multimedia Card Interface support"
314 depends on ARCH_MXC 314 depends on MACH_MX21 || MACH_MX27 || ARCH_MX31
315 help 315 help
316 This selects the Freescale i.MX2/3 Multimedia card Interface. 316 This selects the Freescale i.MX2/3 Multimedia card Interface.
317 If you have a i.MX platform with a Multimedia Card slot, 317 If you have a i.MX platform with a Multimedia Card slot,
@@ -319,6 +319,15 @@ config MMC_MXC
319 319
320 If unsure, say N. 320 If unsure, say N.
321 321
322config MMC_MXS
323 tristate "Freescale MXS Multimedia Card Interface support"
324 depends on ARCH_MXS && MXS_DMA
325 help
326 This selects the Freescale SSP MMC controller found on MXS based
327 platforms like mx23/28.
328
329 If unsure, say N.
330
322config MMC_TIFM_SD 331config MMC_TIFM_SD
323 tristate "TI Flash Media MMC/SD Interface support (EXPERIMENTAL)" 332 tristate "TI Flash Media MMC/SD Interface support (EXPERIMENTAL)"
324 depends on EXPERIMENTAL && PCI 333 depends on EXPERIMENTAL && PCI
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index e834fb223e9a..30aa6867745f 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
6obj-$(CONFIG_MMC_PXA) += pxamci.o 6obj-$(CONFIG_MMC_PXA) += pxamci.o
7obj-$(CONFIG_MMC_IMX) += imxmmc.o 7obj-$(CONFIG_MMC_IMX) += imxmmc.o
8obj-$(CONFIG_MMC_MXC) += mxcmmc.o 8obj-$(CONFIG_MMC_MXC) += mxcmmc.o
9obj-$(CONFIG_MMC_MXS) += mxs-mmc.o
9obj-$(CONFIG_MMC_SDHCI) += sdhci.o 10obj-$(CONFIG_MMC_SDHCI) += sdhci.o
10obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 11obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o
11obj-$(CONFIG_MMC_SDHCI_PXA) += sdhci-pxa.o 12obj-$(CONFIG_MMC_SDHCI_PXA) += sdhci-pxa.o
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index ad2a7a032cdf..80bc9a5c25cc 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -578,7 +578,8 @@ static void atmci_dma_cleanup(struct atmel_mci *host)
578 struct mmc_data *data = host->data; 578 struct mmc_data *data = host->data;
579 579
580 if (data) 580 if (data)
581 dma_unmap_sg(&host->pdev->dev, data->sg, data->sg_len, 581 dma_unmap_sg(host->dma.chan->device->dev,
582 data->sg, data->sg_len,
582 ((data->flags & MMC_DATA_WRITE) 583 ((data->flags & MMC_DATA_WRITE)
583 ? DMA_TO_DEVICE : DMA_FROM_DEVICE)); 584 ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
584} 585}
@@ -588,7 +589,7 @@ static void atmci_stop_dma(struct atmel_mci *host)
588 struct dma_chan *chan = host->data_chan; 589 struct dma_chan *chan = host->data_chan;
589 590
590 if (chan) { 591 if (chan) {
591 chan->device->device_control(chan, DMA_TERMINATE_ALL, 0); 592 dmaengine_terminate_all(chan);
592 atmci_dma_cleanup(host); 593 atmci_dma_cleanup(host);
593 } else { 594 } else {
594 /* Data transfer was stopped by the interrupt handler */ 595 /* Data transfer was stopped by the interrupt handler */
@@ -684,11 +685,11 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
684 else 685 else
685 direction = DMA_TO_DEVICE; 686 direction = DMA_TO_DEVICE;
686 687
687 sglen = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, direction); 688 sglen = dma_map_sg(chan->device->dev, data->sg,
688 if (sglen != data->sg_len) 689 data->sg_len, direction);
689 goto unmap_exit; 690
690 desc = chan->device->device_prep_slave_sg(chan, 691 desc = chan->device->device_prep_slave_sg(chan,
691 data->sg, data->sg_len, direction, 692 data->sg, sglen, direction,
692 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 693 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
693 if (!desc) 694 if (!desc)
694 goto unmap_exit; 695 goto unmap_exit;
@@ -699,7 +700,7 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
699 700
700 return 0; 701 return 0;
701unmap_exit: 702unmap_exit:
702 dma_unmap_sg(&host->pdev->dev, data->sg, sglen, direction); 703 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, direction);
703 return -ENOMEM; 704 return -ENOMEM;
704} 705}
705 706
@@ -709,8 +710,8 @@ static void atmci_submit_data(struct atmel_mci *host)
709 struct dma_async_tx_descriptor *desc = host->dma.data_desc; 710 struct dma_async_tx_descriptor *desc = host->dma.data_desc;
710 711
711 if (chan) { 712 if (chan) {
712 desc->tx_submit(desc); 713 dmaengine_submit(desc);
713 chan->device->device_issue_pending(chan); 714 dma_async_issue_pending(chan);
714 } 715 }
715} 716}
716 717
diff --git a/drivers/mmc/host/cb710-mmc.c b/drivers/mmc/host/cb710-mmc.c
index 66b4ce587f4b..ce2a47b71dd6 100644
--- a/drivers/mmc/host/cb710-mmc.c
+++ b/drivers/mmc/host/cb710-mmc.c
@@ -205,7 +205,7 @@ static int cb710_wait_while_busy(struct cb710_slot *slot, uint8_t mask)
205 "WAIT12: waited %d loops, mask %02X, entry val %08X, exit val %08X\n", 205 "WAIT12: waited %d loops, mask %02X, entry val %08X, exit val %08X\n",
206 limit, mask, e, x); 206 limit, mask, e, x);
207#endif 207#endif
208 return 0; 208 return err;
209} 209}
210 210
211static void cb710_mmc_set_transfer_size(struct cb710_slot *slot, 211static void cb710_mmc_set_transfer_size(struct cb710_slot *slot,
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 2fcc82577c1b..5a614069cb00 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -32,6 +32,7 @@
32#include <linux/mmc/mmc.h> 32#include <linux/mmc/mmc.h>
33#include <linux/mmc/dw_mmc.h> 33#include <linux/mmc/dw_mmc.h>
34#include <linux/bitops.h> 34#include <linux/bitops.h>
35#include <linux/regulator/consumer.h>
35 36
36#include "dw_mmc.h" 37#include "dw_mmc.h"
37 38
@@ -562,7 +563,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot)
562 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); 563 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
563 564
564 /* enable clock */ 565 /* enable clock */
565 mci_writel(host, CLKENA, SDMMC_CLKEN_ENABLE); 566 mci_writel(host, CLKENA, SDMMC_CLKEN_ENABLE |
567 SDMMC_CLKEN_LOW_PWR);
566 568
567 /* inform CIU */ 569 /* inform CIU */
568 mci_send_cmd(slot, 570 mci_send_cmd(slot,
@@ -661,6 +663,7 @@ static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
661static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 663static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
662{ 664{
663 struct dw_mci_slot *slot = mmc_priv(mmc); 665 struct dw_mci_slot *slot = mmc_priv(mmc);
666 u32 regs;
664 667
665 /* set default 1 bit mode */ 668 /* set default 1 bit mode */
666 slot->ctype = SDMMC_CTYPE_1BIT; 669 slot->ctype = SDMMC_CTYPE_1BIT;
@@ -672,6 +675,16 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
672 case MMC_BUS_WIDTH_4: 675 case MMC_BUS_WIDTH_4:
673 slot->ctype = SDMMC_CTYPE_4BIT; 676 slot->ctype = SDMMC_CTYPE_4BIT;
674 break; 677 break;
678 case MMC_BUS_WIDTH_8:
679 slot->ctype = SDMMC_CTYPE_8BIT;
680 break;
681 }
682
683 /* DDR mode set */
684 if (ios->ddr) {
685 regs = mci_readl(slot->host, UHS_REG);
686 regs |= (0x1 << slot->id) << 16;
687 mci_writel(slot->host, UHS_REG, regs);
675 } 688 }
676 689
677 if (ios->clock) { 690 if (ios->clock) {
@@ -717,7 +730,9 @@ static int dw_mci_get_cd(struct mmc_host *mmc)
717 struct dw_mci_board *brd = slot->host->pdata; 730 struct dw_mci_board *brd = slot->host->pdata;
718 731
719 /* Use platform get_cd function, else try onboard card detect */ 732 /* Use platform get_cd function, else try onboard card detect */
720 if (brd->get_cd) 733 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
734 present = 1;
735 else if (brd->get_cd)
721 present = !brd->get_cd(slot->id); 736 present = !brd->get_cd(slot->id);
722 else 737 else
723 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) 738 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
@@ -1019,13 +1034,10 @@ static void dw_mci_read_data_pio(struct dw_mci *host)
1019 struct mmc_data *data = host->data; 1034 struct mmc_data *data = host->data;
1020 int shift = host->data_shift; 1035 int shift = host->data_shift;
1021 u32 status; 1036 u32 status;
1022 unsigned int nbytes = 0, len, old_len, count = 0; 1037 unsigned int nbytes = 0, len;
1023 1038
1024 do { 1039 do {
1025 len = SDMMC_GET_FCNT(mci_readl(host, STATUS)) << shift; 1040 len = SDMMC_GET_FCNT(mci_readl(host, STATUS)) << shift;
1026 if (count == 0)
1027 old_len = len;
1028
1029 if (offset + len <= sg->length) { 1041 if (offset + len <= sg->length) {
1030 host->pull_data(host, (void *)(buf + offset), len); 1042 host->pull_data(host, (void *)(buf + offset), len);
1031 1043
@@ -1070,7 +1082,6 @@ static void dw_mci_read_data_pio(struct dw_mci *host)
1070 tasklet_schedule(&host->tasklet); 1082 tasklet_schedule(&host->tasklet);
1071 return; 1083 return;
1072 } 1084 }
1073 count++;
1074 } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/ 1085 } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/
1075 len = SDMMC_GET_FCNT(mci_readl(host, STATUS)); 1086 len = SDMMC_GET_FCNT(mci_readl(host, STATUS));
1076 host->pio_offset = offset; 1087 host->pio_offset = offset;
@@ -1395,7 +1406,11 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1395 if (host->pdata->setpower) 1406 if (host->pdata->setpower)
1396 host->pdata->setpower(id, 0); 1407 host->pdata->setpower(id, 0);
1397 1408
1398 mmc->caps = 0; 1409 if (host->pdata->caps)
1410 mmc->caps = host->pdata->caps;
1411 else
1412 mmc->caps = 0;
1413
1399 if (host->pdata->get_bus_wd) 1414 if (host->pdata->get_bus_wd)
1400 if (host->pdata->get_bus_wd(slot->id) >= 4) 1415 if (host->pdata->get_bus_wd(slot->id) >= 4)
1401 mmc->caps |= MMC_CAP_4_BIT_DATA; 1416 mmc->caps |= MMC_CAP_4_BIT_DATA;
@@ -1426,6 +1441,13 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1426 } 1441 }
1427#endif /* CONFIG_MMC_DW_IDMAC */ 1442#endif /* CONFIG_MMC_DW_IDMAC */
1428 1443
1444 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
1445 if (IS_ERR(host->vmmc)) {
1446 printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
1447 host->vmmc = NULL;
1448 } else
1449 regulator_enable(host->vmmc);
1450
1429 if (dw_mci_get_cd(mmc)) 1451 if (dw_mci_get_cd(mmc))
1430 set_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1452 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1431 else 1453 else
@@ -1441,6 +1463,12 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1441 /* Card initially undetected */ 1463 /* Card initially undetected */
1442 slot->last_detect_state = 0; 1464 slot->last_detect_state = 0;
1443 1465
1466 /*
1467 * Card may have been plugged in prior to boot so we
1468 * need to run the detect tasklet
1469 */
1470 tasklet_schedule(&host->card_tasklet);
1471
1444 return 0; 1472 return 0;
1445} 1473}
1446 1474
@@ -1619,8 +1647,9 @@ static int dw_mci_probe(struct platform_device *pdev)
1619 */ 1647 */
1620 fifo_size = mci_readl(host, FIFOTH); 1648 fifo_size = mci_readl(host, FIFOTH);
1621 fifo_size = (fifo_size >> 16) & 0x7ff; 1649 fifo_size = (fifo_size >> 16) & 0x7ff;
1622 mci_writel(host, FIFOTH, ((0x2 << 28) | ((fifo_size/2 - 1) << 16) | 1650 host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
1623 ((fifo_size/2) << 0))); 1651 ((fifo_size/2) << 0));
1652 mci_writel(host, FIFOTH, host->fifoth_val);
1624 1653
1625 /* disable clock to CIU */ 1654 /* disable clock to CIU */
1626 mci_writel(host, CLKENA, 0); 1655 mci_writel(host, CLKENA, 0);
@@ -1683,6 +1712,12 @@ err_dmaunmap:
1683 host->sg_cpu, host->sg_dma); 1712 host->sg_cpu, host->sg_dma);
1684 iounmap(host->regs); 1713 iounmap(host->regs);
1685 1714
1715 if (host->vmmc) {
1716 regulator_disable(host->vmmc);
1717 regulator_put(host->vmmc);
1718 }
1719
1720
1686err_freehost: 1721err_freehost:
1687 kfree(host); 1722 kfree(host);
1688 return ret; 1723 return ret;
@@ -1714,6 +1749,11 @@ static int __exit dw_mci_remove(struct platform_device *pdev)
1714 if (host->use_dma && host->dma_ops->exit) 1749 if (host->use_dma && host->dma_ops->exit)
1715 host->dma_ops->exit(host); 1750 host->dma_ops->exit(host);
1716 1751
1752 if (host->vmmc) {
1753 regulator_disable(host->vmmc);
1754 regulator_put(host->vmmc);
1755 }
1756
1717 iounmap(host->regs); 1757 iounmap(host->regs);
1718 1758
1719 kfree(host); 1759 kfree(host);
@@ -1729,6 +1769,9 @@ static int dw_mci_suspend(struct platform_device *pdev, pm_message_t mesg)
1729 int i, ret; 1769 int i, ret;
1730 struct dw_mci *host = platform_get_drvdata(pdev); 1770 struct dw_mci *host = platform_get_drvdata(pdev);
1731 1771
1772 if (host->vmmc)
1773 regulator_enable(host->vmmc);
1774
1732 for (i = 0; i < host->num_slots; i++) { 1775 for (i = 0; i < host->num_slots; i++) {
1733 struct dw_mci_slot *slot = host->slot[i]; 1776 struct dw_mci_slot *slot = host->slot[i];
1734 if (!slot) 1777 if (!slot)
@@ -1744,6 +1787,9 @@ static int dw_mci_suspend(struct platform_device *pdev, pm_message_t mesg)
1744 } 1787 }
1745 } 1788 }
1746 1789
1790 if (host->vmmc)
1791 regulator_disable(host->vmmc);
1792
1747 return 0; 1793 return 0;
1748} 1794}
1749 1795
@@ -1752,6 +1798,23 @@ static int dw_mci_resume(struct platform_device *pdev)
1752 int i, ret; 1798 int i, ret;
1753 struct dw_mci *host = platform_get_drvdata(pdev); 1799 struct dw_mci *host = platform_get_drvdata(pdev);
1754 1800
1801 if (host->dma_ops->init)
1802 host->dma_ops->init(host);
1803
1804 if (!mci_wait_reset(&pdev->dev, host)) {
1805 ret = -ENODEV;
1806 return ret;
1807 }
1808
1809 /* Restore the old value at FIFOTH register */
1810 mci_writel(host, FIFOTH, host->fifoth_val);
1811
1812 mci_writel(host, RINTSTS, 0xFFFFFFFF);
1813 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
1814 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
1815 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
1816 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
1817
1755 for (i = 0; i < host->num_slots; i++) { 1818 for (i = 0; i < host->num_slots; i++) {
1756 struct dw_mci_slot *slot = host->slot[i]; 1819 struct dw_mci_slot *slot = host->slot[i];
1757 if (!slot) 1820 if (!slot)
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 5dd55a75233d..23c662af5616 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -43,6 +43,7 @@
43#define SDMMC_USRID 0x068 43#define SDMMC_USRID 0x068
44#define SDMMC_VERID 0x06c 44#define SDMMC_VERID 0x06c
45#define SDMMC_HCON 0x070 45#define SDMMC_HCON 0x070
46#define SDMMC_UHS_REG 0x074
46#define SDMMC_BMOD 0x080 47#define SDMMC_BMOD 0x080
47#define SDMMC_PLDMND 0x084 48#define SDMMC_PLDMND 0x084
48#define SDMMC_DBADDR 0x088 49#define SDMMC_DBADDR 0x088
@@ -51,7 +52,6 @@
51#define SDMMC_DSCADDR 0x094 52#define SDMMC_DSCADDR 0x094
52#define SDMMC_BUFADDR 0x098 53#define SDMMC_BUFADDR 0x098
53#define SDMMC_DATA 0x100 54#define SDMMC_DATA 0x100
54#define SDMMC_DATA_ADR 0x100
55 55
56/* shift bit field */ 56/* shift bit field */
57#define _SBF(f, v) ((v) << (f)) 57#define _SBF(f, v) ((v) << (f))
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index 97c9b3638d57..a4c865a5286b 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -267,14 +267,6 @@ msmsdcc_dma_complete_tlet(unsigned long data)
267 dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, host->dma.num_ents, 267 dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, host->dma.num_ents,
268 host->dma.dir); 268 host->dma.dir);
269 269
270 if (host->curr.user_pages) {
271 struct scatterlist *sg = host->dma.sg;
272 int i;
273
274 for (i = 0; i < host->dma.num_ents; i++)
275 flush_dcache_page(sg_page(sg++));
276 }
277
278 host->dma.sg = NULL; 270 host->dma.sg = NULL;
279 host->dma.busy = 0; 271 host->dma.busy = 0;
280 272
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index 4428594261c5..cc20e0259325 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -32,16 +32,14 @@
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34#include <linux/regulator/consumer.h> 34#include <linux/regulator/consumer.h>
35#include <linux/dmaengine.h>
35 36
36#include <asm/dma.h> 37#include <asm/dma.h>
37#include <asm/irq.h> 38#include <asm/irq.h>
38#include <asm/sizes.h> 39#include <asm/sizes.h>
39#include <mach/mmc.h> 40#include <mach/mmc.h>
40 41
41#ifdef CONFIG_ARCH_MX2 42#include <mach/dma.h>
42#include <mach/dma-mx1-mx2.h>
43#define HAS_DMA
44#endif
45 43
46#define DRIVER_NAME "mxc-mmc" 44#define DRIVER_NAME "mxc-mmc"
47 45
@@ -118,7 +116,8 @@ struct mxcmci_host {
118 void __iomem *base; 116 void __iomem *base;
119 int irq; 117 int irq;
120 int detect_irq; 118 int detect_irq;
121 int dma; 119 struct dma_chan *dma;
120 struct dma_async_tx_descriptor *desc;
122 int do_dma; 121 int do_dma;
123 int default_irq_mask; 122 int default_irq_mask;
124 int use_sdio; 123 int use_sdio;
@@ -129,7 +128,6 @@ struct mxcmci_host {
129 struct mmc_command *cmd; 128 struct mmc_command *cmd;
130 struct mmc_data *data; 129 struct mmc_data *data;
131 130
132 unsigned int dma_nents;
133 unsigned int datasize; 131 unsigned int datasize;
134 unsigned int dma_dir; 132 unsigned int dma_dir;
135 133
@@ -144,6 +142,11 @@ struct mxcmci_host {
144 spinlock_t lock; 142 spinlock_t lock;
145 143
146 struct regulator *vcc; 144 struct regulator *vcc;
145
146 int burstlen;
147 int dmareq;
148 struct dma_slave_config dma_slave_config;
149 struct imx_dma_data dma_data;
147}; 150};
148 151
149static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios); 152static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios);
@@ -206,17 +209,16 @@ static void mxcmci_softreset(struct mxcmci_host *host)
206 209
207 writew(0xff, host->base + MMC_REG_RES_TO); 210 writew(0xff, host->base + MMC_REG_RES_TO);
208} 211}
212static int mxcmci_setup_dma(struct mmc_host *mmc);
209 213
210static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) 214static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
211{ 215{
212 unsigned int nob = data->blocks; 216 unsigned int nob = data->blocks;
213 unsigned int blksz = data->blksz; 217 unsigned int blksz = data->blksz;
214 unsigned int datasize = nob * blksz; 218 unsigned int datasize = nob * blksz;
215#ifdef HAS_DMA
216 struct scatterlist *sg; 219 struct scatterlist *sg;
217 int i; 220 int i, nents;
218 int ret; 221
219#endif
220 if (data->flags & MMC_DATA_STREAM) 222 if (data->flags & MMC_DATA_STREAM)
221 nob = 0xffff; 223 nob = 0xffff;
222 224
@@ -227,7 +229,9 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
227 writew(blksz, host->base + MMC_REG_BLK_LEN); 229 writew(blksz, host->base + MMC_REG_BLK_LEN);
228 host->datasize = datasize; 230 host->datasize = datasize;
229 231
230#ifdef HAS_DMA 232 if (!mxcmci_use_dma(host))
233 return 0;
234
231 for_each_sg(data->sg, sg, data->sg_len, i) { 235 for_each_sg(data->sg, sg, data->sg_len, i) {
232 if (sg->offset & 3 || sg->length & 3) { 236 if (sg->offset & 3 || sg->length & 3) {
233 host->do_dma = 0; 237 host->do_dma = 0;
@@ -235,34 +239,30 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
235 } 239 }
236 } 240 }
237 241
238 if (data->flags & MMC_DATA_READ) { 242 if (data->flags & MMC_DATA_READ)
239 host->dma_dir = DMA_FROM_DEVICE; 243 host->dma_dir = DMA_FROM_DEVICE;
240 host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, 244 else
241 data->sg_len, host->dma_dir);
242
243 ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents,
244 datasize,
245 host->res->start + MMC_REG_BUFFER_ACCESS,
246 DMA_MODE_READ);
247 } else {
248 host->dma_dir = DMA_TO_DEVICE; 245 host->dma_dir = DMA_TO_DEVICE;
249 host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg,
250 data->sg_len, host->dma_dir);
251 246
252 ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, 247 nents = dma_map_sg(host->dma->device->dev, data->sg,
253 datasize, 248 data->sg_len, host->dma_dir);
254 host->res->start + MMC_REG_BUFFER_ACCESS, 249 if (nents != data->sg_len)
255 DMA_MODE_WRITE); 250 return -EINVAL;
256 } 251
252 host->desc = host->dma->device->device_prep_slave_sg(host->dma,
253 data->sg, data->sg_len, host->dma_dir,
254 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
257 255
258 if (ret) { 256 if (!host->desc) {
259 dev_err(mmc_dev(host->mmc), "failed to setup DMA : %d\n", ret); 257 dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
260 return ret; 258 host->dma_dir);
259 host->do_dma = 0;
260 return 0; /* Fall back to PIO */
261 } 261 }
262 wmb(); 262 wmb();
263 263
264 imx_dma_enable(host->dma); 264 dmaengine_submit(host->desc);
265#endif /* HAS_DMA */ 265
266 return 0; 266 return 0;
267} 267}
268 268
@@ -337,13 +337,11 @@ static int mxcmci_finish_data(struct mxcmci_host *host, unsigned int stat)
337 struct mmc_data *data = host->data; 337 struct mmc_data *data = host->data;
338 int data_error; 338 int data_error;
339 339
340#ifdef HAS_DMA
341 if (mxcmci_use_dma(host)) { 340 if (mxcmci_use_dma(host)) {
342 imx_dma_disable(host->dma); 341 dmaengine_terminate_all(host->dma);
343 dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_nents, 342 dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len,
344 host->dma_dir); 343 host->dma_dir);
345 } 344 }
346#endif
347 345
348 if (stat & STATUS_ERR_MASK) { 346 if (stat & STATUS_ERR_MASK) {
349 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n", 347 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",
@@ -545,7 +543,6 @@ static void mxcmci_datawork(struct work_struct *work)
545 } 543 }
546} 544}
547 545
548#ifdef HAS_DMA
549static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat) 546static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat)
550{ 547{
551 struct mmc_data *data = host->data; 548 struct mmc_data *data = host->data;
@@ -568,7 +565,6 @@ static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat)
568 mxcmci_finish_request(host, host->req); 565 mxcmci_finish_request(host, host->req);
569 } 566 }
570} 567}
571#endif /* HAS_DMA */
572 568
573static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat) 569static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
574{ 570{
@@ -606,12 +602,10 @@ static irqreturn_t mxcmci_irq(int irq, void *devid)
606 sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio; 602 sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio;
607 spin_unlock_irqrestore(&host->lock, flags); 603 spin_unlock_irqrestore(&host->lock, flags);
608 604
609#ifdef HAS_DMA
610 if (mxcmci_use_dma(host) && 605 if (mxcmci_use_dma(host) &&
611 (stat & (STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE))) 606 (stat & (STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE)))
612 writel(STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE, 607 writel(STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE,
613 host->base + MMC_REG_STATUS); 608 host->base + MMC_REG_STATUS);
614#endif
615 609
616 if (sdio_irq) { 610 if (sdio_irq) {
617 writel(STATUS_SDIO_INT_ACTIVE, host->base + MMC_REG_STATUS); 611 writel(STATUS_SDIO_INT_ACTIVE, host->base + MMC_REG_STATUS);
@@ -621,14 +615,14 @@ static irqreturn_t mxcmci_irq(int irq, void *devid)
621 if (stat & STATUS_END_CMD_RESP) 615 if (stat & STATUS_END_CMD_RESP)
622 mxcmci_cmd_done(host, stat); 616 mxcmci_cmd_done(host, stat);
623 617
624#ifdef HAS_DMA
625 if (mxcmci_use_dma(host) && 618 if (mxcmci_use_dma(host) &&
626 (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE))) 619 (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE)))
627 mxcmci_data_done(host, stat); 620 mxcmci_data_done(host, stat);
628#endif 621
629 if (host->default_irq_mask && 622 if (host->default_irq_mask &&
630 (stat & (STATUS_CARD_INSERTION | STATUS_CARD_REMOVAL))) 623 (stat & (STATUS_CARD_INSERTION | STATUS_CARD_REMOVAL)))
631 mmc_detect_change(host->mmc, msecs_to_jiffies(200)); 624 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
625
632 return IRQ_HANDLED; 626 return IRQ_HANDLED;
633} 627}
634 628
@@ -642,9 +636,10 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req)
642 636
643 host->req = req; 637 host->req = req;
644 host->cmdat &= ~CMD_DAT_CONT_INIT; 638 host->cmdat &= ~CMD_DAT_CONT_INIT;
645#ifdef HAS_DMA 639
646 host->do_dma = 1; 640 if (host->dma)
647#endif 641 host->do_dma = 1;
642
648 if (req->data) { 643 if (req->data) {
649 error = mxcmci_setup_data(host, req->data); 644 error = mxcmci_setup_data(host, req->data);
650 if (error) { 645 if (error) {
@@ -660,6 +655,7 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req)
660 } 655 }
661 656
662 error = mxcmci_start_cmd(host, req->cmd, cmdat); 657 error = mxcmci_start_cmd(host, req->cmd, cmdat);
658
663out: 659out:
664 if (error) 660 if (error)
665 mxcmci_finish_request(host, req); 661 mxcmci_finish_request(host, req);
@@ -698,22 +694,46 @@ static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios)
698 prescaler, divider, clk_in, clk_ios); 694 prescaler, divider, clk_in, clk_ios);
699} 695}
700 696
697static int mxcmci_setup_dma(struct mmc_host *mmc)
698{
699 struct mxcmci_host *host = mmc_priv(mmc);
700 struct dma_slave_config *config = &host->dma_slave_config;
701
702 config->dst_addr = host->res->start + MMC_REG_BUFFER_ACCESS;
703 config->src_addr = host->res->start + MMC_REG_BUFFER_ACCESS;
704 config->dst_addr_width = 4;
705 config->src_addr_width = 4;
706 config->dst_maxburst = host->burstlen;
707 config->src_maxburst = host->burstlen;
708
709 return dmaengine_slave_config(host->dma, config);
710}
711
701static void mxcmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 712static void mxcmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
702{ 713{
703 struct mxcmci_host *host = mmc_priv(mmc); 714 struct mxcmci_host *host = mmc_priv(mmc);
704#ifdef HAS_DMA 715 int burstlen, ret;
705 unsigned int blen; 716
706 /* 717 /*
707 * use burstlen of 64 in 4 bit mode (--> reg value 0) 718 * use burstlen of 64 in 4 bit mode (--> reg value 0)
708 * use burstlen of 16 in 1 bit mode (--> reg value 16) 719 * use burstlen of 16 in 1 bit mode (--> reg value 16)
709 */ 720 */
710 if (ios->bus_width == MMC_BUS_WIDTH_4) 721 if (ios->bus_width == MMC_BUS_WIDTH_4)
711 blen = 0; 722 burstlen = 64;
712 else 723 else
713 blen = 16; 724 burstlen = 16;
725
726 if (mxcmci_use_dma(host) && burstlen != host->burstlen) {
727 host->burstlen = burstlen;
728 ret = mxcmci_setup_dma(mmc);
729 if (ret) {
730 dev_err(mmc_dev(host->mmc),
731 "failed to config DMA channel. Falling back to PIO\n");
732 dma_release_channel(host->dma);
733 host->do_dma = 0;
734 }
735 }
714 736
715 imx_dma_config_burstlen(host->dma, blen);
716#endif
717 if (ios->bus_width == MMC_BUS_WIDTH_4) 737 if (ios->bus_width == MMC_BUS_WIDTH_4)
718 host->cmdat |= CMD_DAT_CONT_BUS_WIDTH_4; 738 host->cmdat |= CMD_DAT_CONT_BUS_WIDTH_4;
719 else 739 else
@@ -794,6 +814,18 @@ static void mxcmci_init_card(struct mmc_host *host, struct mmc_card *card)
794 host->caps |= MMC_CAP_4_BIT_DATA; 814 host->caps |= MMC_CAP_4_BIT_DATA;
795} 815}
796 816
817static bool filter(struct dma_chan *chan, void *param)
818{
819 struct mxcmci_host *host = param;
820
821 if (!imx_dma_is_general_purpose(chan))
822 return false;
823
824 chan->private = &host->dma_data;
825
826 return true;
827}
828
797static const struct mmc_host_ops mxcmci_ops = { 829static const struct mmc_host_ops mxcmci_ops = {
798 .request = mxcmci_request, 830 .request = mxcmci_request,
799 .set_ios = mxcmci_set_ios, 831 .set_ios = mxcmci_set_ios,
@@ -808,6 +840,7 @@ static int mxcmci_probe(struct platform_device *pdev)
808 struct mxcmci_host *host = NULL; 840 struct mxcmci_host *host = NULL;
809 struct resource *iores, *r; 841 struct resource *iores, *r;
810 int ret = 0, irq; 842 int ret = 0, irq;
843 dma_cap_mask_t mask;
811 844
812 printk(KERN_INFO "i.MX SDHC driver\n"); 845 printk(KERN_INFO "i.MX SDHC driver\n");
813 846
@@ -883,29 +916,23 @@ static int mxcmci_probe(struct platform_device *pdev)
883 916
884 writel(host->default_irq_mask, host->base + MMC_REG_INT_CNTR); 917 writel(host->default_irq_mask, host->base + MMC_REG_INT_CNTR);
885 918
886#ifdef HAS_DMA
887 host->dma = imx_dma_request_by_prio(DRIVER_NAME, DMA_PRIO_LOW);
888 if (host->dma < 0) {
889 dev_err(mmc_dev(host->mmc), "imx_dma_request_by_prio failed\n");
890 ret = -EBUSY;
891 goto out_clk_put;
892 }
893
894 r = platform_get_resource(pdev, IORESOURCE_DMA, 0); 919 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
895 if (!r) { 920 if (r) {
896 ret = -EINVAL; 921 host->dmareq = r->start;
897 goto out_free_dma; 922 host->dma_data.peripheral_type = IMX_DMATYPE_SDHC;
923 host->dma_data.priority = DMA_PRIO_LOW;
924 host->dma_data.dma_request = host->dmareq;
925 dma_cap_zero(mask);
926 dma_cap_set(DMA_SLAVE, mask);
927 host->dma = dma_request_channel(mask, filter, host);
928 if (host->dma)
929 mmc->max_seg_size = dma_get_max_seg_size(
930 host->dma->device->dev);
898 } 931 }
899 932
900 ret = imx_dma_config_channel(host->dma, 933 if (!host->dma)
901 IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_FIFO, 934 dev_info(mmc_dev(host->mmc), "dma not available. Using PIO\n");
902 IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR, 935
903 r->start, 0);
904 if (ret) {
905 dev_err(mmc_dev(host->mmc), "failed to config DMA channel\n");
906 goto out_free_dma;
907 }
908#endif
909 INIT_WORK(&host->datawork, mxcmci_datawork); 936 INIT_WORK(&host->datawork, mxcmci_datawork);
910 937
911 ret = request_irq(host->irq, mxcmci_irq, 0, DRIVER_NAME, host); 938 ret = request_irq(host->irq, mxcmci_irq, 0, DRIVER_NAME, host);
@@ -928,9 +955,8 @@ static int mxcmci_probe(struct platform_device *pdev)
928out_free_irq: 955out_free_irq:
929 free_irq(host->irq, host); 956 free_irq(host->irq, host);
930out_free_dma: 957out_free_dma:
931#ifdef HAS_DMA 958 if (host->dma)
932 imx_dma_free(host->dma); 959 dma_release_channel(host->dma);
933#endif
934out_clk_put: 960out_clk_put:
935 clk_disable(host->clk); 961 clk_disable(host->clk);
936 clk_put(host->clk); 962 clk_put(host->clk);
@@ -960,9 +986,10 @@ static int mxcmci_remove(struct platform_device *pdev)
960 986
961 free_irq(host->irq, host); 987 free_irq(host->irq, host);
962 iounmap(host->base); 988 iounmap(host->base);
963#ifdef HAS_DMA 989
964 imx_dma_free(host->dma); 990 if (host->dma)
965#endif 991 dma_release_channel(host->dma);
992
966 clk_disable(host->clk); 993 clk_disable(host->clk);
967 clk_put(host->clk); 994 clk_put(host->clk);
968 995
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
new file mode 100644
index 000000000000..99d39a6a1032
--- /dev/null
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -0,0 +1,874 @@
1/*
2 * Portions copyright (C) 2003 Russell King, PXA MMCI Driver
3 * Portions copyright (C) 2004-2005 Pierre Ossman, W83L51xD SD/MMC driver
4 *
5 * Copyright 2008 Embedded Alley Solutions, Inc.
6 * Copyright 2009-2011 Freescale Semiconductor, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/ioport.h>
26#include <linux/platform_device.h>
27#include <linux/delay.h>
28#include <linux/interrupt.h>
29#include <linux/dma-mapping.h>
30#include <linux/dmaengine.h>
31#include <linux/highmem.h>
32#include <linux/clk.h>
33#include <linux/err.h>
34#include <linux/completion.h>
35#include <linux/mmc/host.h>
36#include <linux/mmc/mmc.h>
37#include <linux/mmc/sdio.h>
38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h>
40
41#include <mach/mxs.h>
42#include <mach/common.h>
43#include <mach/dma.h>
44#include <mach/mmc.h>
45
46#define DRIVER_NAME "mxs-mmc"
47
48/* card detect polling timeout */
49#define MXS_MMC_DETECT_TIMEOUT (HZ/2)
50
51#define SSP_VERSION_LATEST 4
52#define ssp_is_old() (host->version < SSP_VERSION_LATEST)
53
54/* SSP registers */
55#define HW_SSP_CTRL0 0x000
56#define BM_SSP_CTRL0_RUN (1 << 29)
57#define BM_SSP_CTRL0_SDIO_IRQ_CHECK (1 << 28)
58#define BM_SSP_CTRL0_IGNORE_CRC (1 << 26)
59#define BM_SSP_CTRL0_READ (1 << 25)
60#define BM_SSP_CTRL0_DATA_XFER (1 << 24)
61#define BP_SSP_CTRL0_BUS_WIDTH (22)
62#define BM_SSP_CTRL0_BUS_WIDTH (0x3 << 22)
63#define BM_SSP_CTRL0_WAIT_FOR_IRQ (1 << 21)
64#define BM_SSP_CTRL0_LONG_RESP (1 << 19)
65#define BM_SSP_CTRL0_GET_RESP (1 << 17)
66#define BM_SSP_CTRL0_ENABLE (1 << 16)
67#define BP_SSP_CTRL0_XFER_COUNT (0)
68#define BM_SSP_CTRL0_XFER_COUNT (0xffff)
69#define HW_SSP_CMD0 0x010
70#define BM_SSP_CMD0_DBL_DATA_RATE_EN (1 << 25)
71#define BM_SSP_CMD0_SLOW_CLKING_EN (1 << 22)
72#define BM_SSP_CMD0_CONT_CLKING_EN (1 << 21)
73#define BM_SSP_CMD0_APPEND_8CYC (1 << 20)
74#define BP_SSP_CMD0_BLOCK_SIZE (16)
75#define BM_SSP_CMD0_BLOCK_SIZE (0xf << 16)
76#define BP_SSP_CMD0_BLOCK_COUNT (8)
77#define BM_SSP_CMD0_BLOCK_COUNT (0xff << 8)
78#define BP_SSP_CMD0_CMD (0)
79#define BM_SSP_CMD0_CMD (0xff)
80#define HW_SSP_CMD1 0x020
81#define HW_SSP_XFER_SIZE 0x030
82#define HW_SSP_BLOCK_SIZE 0x040
83#define BP_SSP_BLOCK_SIZE_BLOCK_COUNT (4)
84#define BM_SSP_BLOCK_SIZE_BLOCK_COUNT (0xffffff << 4)
85#define BP_SSP_BLOCK_SIZE_BLOCK_SIZE (0)
86#define BM_SSP_BLOCK_SIZE_BLOCK_SIZE (0xf)
87#define HW_SSP_TIMING (ssp_is_old() ? 0x050 : 0x070)
88#define BP_SSP_TIMING_TIMEOUT (16)
89#define BM_SSP_TIMING_TIMEOUT (0xffff << 16)
90#define BP_SSP_TIMING_CLOCK_DIVIDE (8)
91#define BM_SSP_TIMING_CLOCK_DIVIDE (0xff << 8)
92#define BP_SSP_TIMING_CLOCK_RATE (0)
93#define BM_SSP_TIMING_CLOCK_RATE (0xff)
94#define HW_SSP_CTRL1 (ssp_is_old() ? 0x060 : 0x080)
95#define BM_SSP_CTRL1_SDIO_IRQ (1 << 31)
96#define BM_SSP_CTRL1_SDIO_IRQ_EN (1 << 30)
97#define BM_SSP_CTRL1_RESP_ERR_IRQ (1 << 29)
98#define BM_SSP_CTRL1_RESP_ERR_IRQ_EN (1 << 28)
99#define BM_SSP_CTRL1_RESP_TIMEOUT_IRQ (1 << 27)
100#define BM_SSP_CTRL1_RESP_TIMEOUT_IRQ_EN (1 << 26)
101#define BM_SSP_CTRL1_DATA_TIMEOUT_IRQ (1 << 25)
102#define BM_SSP_CTRL1_DATA_TIMEOUT_IRQ_EN (1 << 24)
103#define BM_SSP_CTRL1_DATA_CRC_IRQ (1 << 23)
104#define BM_SSP_CTRL1_DATA_CRC_IRQ_EN (1 << 22)
105#define BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ (1 << 21)
106#define BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ_EN (1 << 20)
107#define BM_SSP_CTRL1_RECV_TIMEOUT_IRQ (1 << 17)
108#define BM_SSP_CTRL1_RECV_TIMEOUT_IRQ_EN (1 << 16)
109#define BM_SSP_CTRL1_FIFO_OVERRUN_IRQ (1 << 15)
110#define BM_SSP_CTRL1_FIFO_OVERRUN_IRQ_EN (1 << 14)
111#define BM_SSP_CTRL1_DMA_ENABLE (1 << 13)
112#define BM_SSP_CTRL1_POLARITY (1 << 9)
113#define BP_SSP_CTRL1_WORD_LENGTH (4)
114#define BM_SSP_CTRL1_WORD_LENGTH (0xf << 4)
115#define BP_SSP_CTRL1_SSP_MODE (0)
116#define BM_SSP_CTRL1_SSP_MODE (0xf)
117#define HW_SSP_SDRESP0 (ssp_is_old() ? 0x080 : 0x0a0)
118#define HW_SSP_SDRESP1 (ssp_is_old() ? 0x090 : 0x0b0)
119#define HW_SSP_SDRESP2 (ssp_is_old() ? 0x0a0 : 0x0c0)
120#define HW_SSP_SDRESP3 (ssp_is_old() ? 0x0b0 : 0x0d0)
121#define HW_SSP_STATUS (ssp_is_old() ? 0x0c0 : 0x100)
122#define BM_SSP_STATUS_CARD_DETECT (1 << 28)
123#define BM_SSP_STATUS_SDIO_IRQ (1 << 17)
124#define HW_SSP_VERSION (cpu_is_mx23() ? 0x110 : 0x130)
125#define BP_SSP_VERSION_MAJOR (24)
126
127#define BF_SSP(value, field) (((value) << BP_SSP_##field) & BM_SSP_##field)
128
129#define MXS_MMC_IRQ_BITS (BM_SSP_CTRL1_SDIO_IRQ | \
130 BM_SSP_CTRL1_RESP_ERR_IRQ | \
131 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ | \
132 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ | \
133 BM_SSP_CTRL1_DATA_CRC_IRQ | \
134 BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ | \
135 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ | \
136 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ)
137
138#define SSP_PIO_NUM 3
139
140struct mxs_mmc_host {
141 struct mmc_host *mmc;
142 struct mmc_request *mrq;
143 struct mmc_command *cmd;
144 struct mmc_data *data;
145
146 void __iomem *base;
147 int irq;
148 struct resource *res;
149 struct resource *dma_res;
150 struct clk *clk;
151 unsigned int clk_rate;
152
153 struct dma_chan *dmach;
154 struct mxs_dma_data dma_data;
155 unsigned int dma_dir;
156 u32 ssp_pio_words[SSP_PIO_NUM];
157
158 unsigned int version;
159 unsigned char bus_width;
160 spinlock_t lock;
161 int sdio_irq_en;
162};
163
164static int mxs_mmc_get_ro(struct mmc_host *mmc)
165{
166 struct mxs_mmc_host *host = mmc_priv(mmc);
167 struct mxs_mmc_platform_data *pdata =
168 mmc_dev(host->mmc)->platform_data;
169
170 if (!pdata)
171 return -EFAULT;
172
173 if (!gpio_is_valid(pdata->wp_gpio))
174 return -EINVAL;
175
176 return gpio_get_value(pdata->wp_gpio);
177}
178
179static int mxs_mmc_get_cd(struct mmc_host *mmc)
180{
181 struct mxs_mmc_host *host = mmc_priv(mmc);
182
183 return !(readl(host->base + HW_SSP_STATUS) &
184 BM_SSP_STATUS_CARD_DETECT);
185}
186
187static void mxs_mmc_reset(struct mxs_mmc_host *host)
188{
189 u32 ctrl0, ctrl1;
190
191 mxs_reset_block(host->base);
192
193 ctrl0 = BM_SSP_CTRL0_IGNORE_CRC;
194 ctrl1 = BF_SSP(0x3, CTRL1_SSP_MODE) |
195 BF_SSP(0x7, CTRL1_WORD_LENGTH) |
196 BM_SSP_CTRL1_DMA_ENABLE |
197 BM_SSP_CTRL1_POLARITY |
198 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ_EN |
199 BM_SSP_CTRL1_DATA_CRC_IRQ_EN |
200 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ_EN |
201 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ_EN |
202 BM_SSP_CTRL1_RESP_ERR_IRQ_EN;
203
204 writel(BF_SSP(0xffff, TIMING_TIMEOUT) |
205 BF_SSP(2, TIMING_CLOCK_DIVIDE) |
206 BF_SSP(0, TIMING_CLOCK_RATE),
207 host->base + HW_SSP_TIMING);
208
209 if (host->sdio_irq_en) {
210 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
211 ctrl1 |= BM_SSP_CTRL1_SDIO_IRQ_EN;
212 }
213
214 writel(ctrl0, host->base + HW_SSP_CTRL0);
215 writel(ctrl1, host->base + HW_SSP_CTRL1);
216}
217
218static void mxs_mmc_start_cmd(struct mxs_mmc_host *host,
219 struct mmc_command *cmd);
220
221static void mxs_mmc_request_done(struct mxs_mmc_host *host)
222{
223 struct mmc_command *cmd = host->cmd;
224 struct mmc_data *data = host->data;
225 struct mmc_request *mrq = host->mrq;
226
227 if (mmc_resp_type(cmd) & MMC_RSP_PRESENT) {
228 if (mmc_resp_type(cmd) & MMC_RSP_136) {
229 cmd->resp[3] = readl(host->base + HW_SSP_SDRESP0);
230 cmd->resp[2] = readl(host->base + HW_SSP_SDRESP1);
231 cmd->resp[1] = readl(host->base + HW_SSP_SDRESP2);
232 cmd->resp[0] = readl(host->base + HW_SSP_SDRESP3);
233 } else {
234 cmd->resp[0] = readl(host->base + HW_SSP_SDRESP0);
235 }
236 }
237
238 if (data) {
239 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
240 data->sg_len, host->dma_dir);
241 /*
242 * If there was an error on any block, we mark all
243 * data blocks as being in error.
244 */
245 if (!data->error)
246 data->bytes_xfered = data->blocks * data->blksz;
247 else
248 data->bytes_xfered = 0;
249
250 host->data = NULL;
251 if (mrq->stop) {
252 mxs_mmc_start_cmd(host, mrq->stop);
253 return;
254 }
255 }
256
257 host->mrq = NULL;
258 mmc_request_done(host->mmc, mrq);
259}
260
261static void mxs_mmc_dma_irq_callback(void *param)
262{
263 struct mxs_mmc_host *host = param;
264
265 mxs_mmc_request_done(host);
266}
267
268static irqreturn_t mxs_mmc_irq_handler(int irq, void *dev_id)
269{
270 struct mxs_mmc_host *host = dev_id;
271 struct mmc_command *cmd = host->cmd;
272 struct mmc_data *data = host->data;
273 u32 stat;
274
275 spin_lock(&host->lock);
276
277 stat = readl(host->base + HW_SSP_CTRL1);
278 writel(stat & MXS_MMC_IRQ_BITS,
279 host->base + HW_SSP_CTRL1 + MXS_CLR_ADDR);
280
281 if ((stat & BM_SSP_CTRL1_SDIO_IRQ) && (stat & BM_SSP_CTRL1_SDIO_IRQ_EN))
282 mmc_signal_sdio_irq(host->mmc);
283
284 spin_unlock(&host->lock);
285
286 if (stat & BM_SSP_CTRL1_RESP_TIMEOUT_IRQ)
287 cmd->error = -ETIMEDOUT;
288 else if (stat & BM_SSP_CTRL1_RESP_ERR_IRQ)
289 cmd->error = -EIO;
290
291 if (data) {
292 if (stat & (BM_SSP_CTRL1_DATA_TIMEOUT_IRQ |
293 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ))
294 data->error = -ETIMEDOUT;
295 else if (stat & BM_SSP_CTRL1_DATA_CRC_IRQ)
296 data->error = -EILSEQ;
297 else if (stat & (BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ |
298 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ))
299 data->error = -EIO;
300 }
301
302 return IRQ_HANDLED;
303}
304
305static struct dma_async_tx_descriptor *mxs_mmc_prep_dma(
306 struct mxs_mmc_host *host, unsigned int append)
307{
308 struct dma_async_tx_descriptor *desc;
309 struct mmc_data *data = host->data;
310 struct scatterlist * sgl;
311 unsigned int sg_len;
312
313 if (data) {
314 /* data */
315 dma_map_sg(mmc_dev(host->mmc), data->sg,
316 data->sg_len, host->dma_dir);
317 sgl = data->sg;
318 sg_len = data->sg_len;
319 } else {
320 /* pio */
321 sgl = (struct scatterlist *) host->ssp_pio_words;
322 sg_len = SSP_PIO_NUM;
323 }
324
325 desc = host->dmach->device->device_prep_slave_sg(host->dmach,
326 sgl, sg_len, host->dma_dir, append);
327 if (desc) {
328 desc->callback = mxs_mmc_dma_irq_callback;
329 desc->callback_param = host;
330 } else {
331 if (data)
332 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
333 data->sg_len, host->dma_dir);
334 }
335
336 return desc;
337}
338
339static void mxs_mmc_bc(struct mxs_mmc_host *host)
340{
341 struct mmc_command *cmd = host->cmd;
342 struct dma_async_tx_descriptor *desc;
343 u32 ctrl0, cmd0, cmd1;
344
345 ctrl0 = BM_SSP_CTRL0_ENABLE | BM_SSP_CTRL0_IGNORE_CRC;
346 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD) | BM_SSP_CMD0_APPEND_8CYC;
347 cmd1 = cmd->arg;
348
349 if (host->sdio_irq_en) {
350 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
351 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
352 }
353
354 host->ssp_pio_words[0] = ctrl0;
355 host->ssp_pio_words[1] = cmd0;
356 host->ssp_pio_words[2] = cmd1;
357 host->dma_dir = DMA_NONE;
358 desc = mxs_mmc_prep_dma(host, 0);
359 if (!desc)
360 goto out;
361
362 dmaengine_submit(desc);
363 return;
364
365out:
366 dev_warn(mmc_dev(host->mmc),
367 "%s: failed to prep dma\n", __func__);
368}
369
370static void mxs_mmc_ac(struct mxs_mmc_host *host)
371{
372 struct mmc_command *cmd = host->cmd;
373 struct dma_async_tx_descriptor *desc;
374 u32 ignore_crc, get_resp, long_resp;
375 u32 ctrl0, cmd0, cmd1;
376
377 ignore_crc = (mmc_resp_type(cmd) & MMC_RSP_CRC) ?
378 0 : BM_SSP_CTRL0_IGNORE_CRC;
379 get_resp = (mmc_resp_type(cmd) & MMC_RSP_PRESENT) ?
380 BM_SSP_CTRL0_GET_RESP : 0;
381 long_resp = (mmc_resp_type(cmd) & MMC_RSP_136) ?
382 BM_SSP_CTRL0_LONG_RESP : 0;
383
384 ctrl0 = BM_SSP_CTRL0_ENABLE | ignore_crc | get_resp | long_resp;
385 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD);
386 cmd1 = cmd->arg;
387
388 if (host->sdio_irq_en) {
389 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
390 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
391 }
392
393 host->ssp_pio_words[0] = ctrl0;
394 host->ssp_pio_words[1] = cmd0;
395 host->ssp_pio_words[2] = cmd1;
396 host->dma_dir = DMA_NONE;
397 desc = mxs_mmc_prep_dma(host, 0);
398 if (!desc)
399 goto out;
400
401 dmaengine_submit(desc);
402 return;
403
404out:
405 dev_warn(mmc_dev(host->mmc),
406 "%s: failed to prep dma\n", __func__);
407}
408
409static unsigned short mxs_ns_to_ssp_ticks(unsigned clock_rate, unsigned ns)
410{
411 const unsigned int ssp_timeout_mul = 4096;
412 /*
413 * Calculate ticks in ms since ns are large numbers
414 * and might overflow
415 */
416 const unsigned int clock_per_ms = clock_rate / 1000;
417 const unsigned int ms = ns / 1000;
418 const unsigned int ticks = ms * clock_per_ms;
419 const unsigned int ssp_ticks = ticks / ssp_timeout_mul;
420
421 WARN_ON(ssp_ticks == 0);
422 return ssp_ticks;
423}
424
425static void mxs_mmc_adtc(struct mxs_mmc_host *host)
426{
427 struct mmc_command *cmd = host->cmd;
428 struct mmc_data *data = cmd->data;
429 struct dma_async_tx_descriptor *desc;
430 struct scatterlist *sgl = data->sg, *sg;
431 unsigned int sg_len = data->sg_len;
432 int i;
433
434 unsigned short dma_data_dir, timeout;
435 unsigned int data_size = 0, log2_blksz;
436 unsigned int blocks = data->blocks;
437
438 u32 ignore_crc, get_resp, long_resp, read;
439 u32 ctrl0, cmd0, cmd1, val;
440
441 ignore_crc = (mmc_resp_type(cmd) & MMC_RSP_CRC) ?
442 0 : BM_SSP_CTRL0_IGNORE_CRC;
443 get_resp = (mmc_resp_type(cmd) & MMC_RSP_PRESENT) ?
444 BM_SSP_CTRL0_GET_RESP : 0;
445 long_resp = (mmc_resp_type(cmd) & MMC_RSP_136) ?
446 BM_SSP_CTRL0_LONG_RESP : 0;
447
448 if (data->flags & MMC_DATA_WRITE) {
449 dma_data_dir = DMA_TO_DEVICE;
450 read = 0;
451 } else {
452 dma_data_dir = DMA_FROM_DEVICE;
453 read = BM_SSP_CTRL0_READ;
454 }
455
456 ctrl0 = BF_SSP(host->bus_width, CTRL0_BUS_WIDTH) |
457 ignore_crc | get_resp | long_resp |
458 BM_SSP_CTRL0_DATA_XFER | read |
459 BM_SSP_CTRL0_WAIT_FOR_IRQ |
460 BM_SSP_CTRL0_ENABLE;
461
462 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD);
463
464 /* get logarithm to base 2 of block size for setting register */
465 log2_blksz = ilog2(data->blksz);
466
467 /*
468 * take special care of the case that data size from data->sg
469 * is not equal to blocks x blksz
470 */
471 for_each_sg(sgl, sg, sg_len, i)
472 data_size += sg->length;
473
474 if (data_size != data->blocks * data->blksz)
475 blocks = 1;
476
477 /* xfer count, block size and count need to be set differently */
478 if (ssp_is_old()) {
479 ctrl0 |= BF_SSP(data_size, CTRL0_XFER_COUNT);
480 cmd0 |= BF_SSP(log2_blksz, CMD0_BLOCK_SIZE) |
481 BF_SSP(blocks - 1, CMD0_BLOCK_COUNT);
482 } else {
483 writel(data_size, host->base + HW_SSP_XFER_SIZE);
484 writel(BF_SSP(log2_blksz, BLOCK_SIZE_BLOCK_SIZE) |
485 BF_SSP(blocks - 1, BLOCK_SIZE_BLOCK_COUNT),
486 host->base + HW_SSP_BLOCK_SIZE);
487 }
488
489 if ((cmd->opcode == MMC_STOP_TRANSMISSION) ||
490 (cmd->opcode == SD_IO_RW_EXTENDED))
491 cmd0 |= BM_SSP_CMD0_APPEND_8CYC;
492
493 cmd1 = cmd->arg;
494
495 if (host->sdio_irq_en) {
496 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
497 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
498 }
499
500 /* set the timeout count */
501 timeout = mxs_ns_to_ssp_ticks(host->clk_rate, data->timeout_ns);
502 val = readl(host->base + HW_SSP_TIMING);
503 val &= ~(BM_SSP_TIMING_TIMEOUT);
504 val |= BF_SSP(timeout, TIMING_TIMEOUT);
505 writel(val, host->base + HW_SSP_TIMING);
506
507 /* pio */
508 host->ssp_pio_words[0] = ctrl0;
509 host->ssp_pio_words[1] = cmd0;
510 host->ssp_pio_words[2] = cmd1;
511 host->dma_dir = DMA_NONE;
512 desc = mxs_mmc_prep_dma(host, 0);
513 if (!desc)
514 goto out;
515
516 /* append data sg */
517 WARN_ON(host->data != NULL);
518 host->data = data;
519 host->dma_dir = dma_data_dir;
520 desc = mxs_mmc_prep_dma(host, 1);
521 if (!desc)
522 goto out;
523
524 dmaengine_submit(desc);
525 return;
526out:
527 dev_warn(mmc_dev(host->mmc),
528 "%s: failed to prep dma\n", __func__);
529}
530
531static void mxs_mmc_start_cmd(struct mxs_mmc_host *host,
532 struct mmc_command *cmd)
533{
534 host->cmd = cmd;
535
536 switch (mmc_cmd_type(cmd)) {
537 case MMC_CMD_BC:
538 mxs_mmc_bc(host);
539 break;
540 case MMC_CMD_BCR:
541 mxs_mmc_ac(host);
542 break;
543 case MMC_CMD_AC:
544 mxs_mmc_ac(host);
545 break;
546 case MMC_CMD_ADTC:
547 mxs_mmc_adtc(host);
548 break;
549 default:
550 dev_warn(mmc_dev(host->mmc),
551 "%s: unknown MMC command\n", __func__);
552 break;
553 }
554}
555
556static void mxs_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
557{
558 struct mxs_mmc_host *host = mmc_priv(mmc);
559
560 WARN_ON(host->mrq != NULL);
561 host->mrq = mrq;
562 mxs_mmc_start_cmd(host, mrq->cmd);
563}
564
565static void mxs_mmc_set_clk_rate(struct mxs_mmc_host *host, unsigned int rate)
566{
567 unsigned int ssp_rate, bit_rate;
568 u32 div1, div2;
569 u32 val;
570
571 ssp_rate = clk_get_rate(host->clk);
572
573 for (div1 = 2; div1 < 254; div1 += 2) {
574 div2 = ssp_rate / rate / div1;
575 if (div2 < 0x100)
576 break;
577 }
578
579 if (div1 >= 254) {
580 dev_err(mmc_dev(host->mmc),
581 "%s: cannot set clock to %d\n", __func__, rate);
582 return;
583 }
584
585 if (div2 == 0)
586 bit_rate = ssp_rate / div1;
587 else
588 bit_rate = ssp_rate / div1 / div2;
589
590 val = readl(host->base + HW_SSP_TIMING);
591 val &= ~(BM_SSP_TIMING_CLOCK_DIVIDE | BM_SSP_TIMING_CLOCK_RATE);
592 val |= BF_SSP(div1, TIMING_CLOCK_DIVIDE);
593 val |= BF_SSP(div2 - 1, TIMING_CLOCK_RATE);
594 writel(val, host->base + HW_SSP_TIMING);
595
596 host->clk_rate = bit_rate;
597
598 dev_dbg(mmc_dev(host->mmc),
599 "%s: div1 %d, div2 %d, ssp %d, bit %d, rate %d\n",
600 __func__, div1, div2, ssp_rate, bit_rate, rate);
601}
602
603static void mxs_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
604{
605 struct mxs_mmc_host *host = mmc_priv(mmc);
606
607 if (ios->bus_width == MMC_BUS_WIDTH_8)
608 host->bus_width = 2;
609 else if (ios->bus_width == MMC_BUS_WIDTH_4)
610 host->bus_width = 1;
611 else
612 host->bus_width = 0;
613
614 if (ios->clock)
615 mxs_mmc_set_clk_rate(host, ios->clock);
616}
617
618static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
619{
620 struct mxs_mmc_host *host = mmc_priv(mmc);
621 unsigned long flags;
622
623 spin_lock_irqsave(&host->lock, flags);
624
625 host->sdio_irq_en = enable;
626
627 if (enable) {
628 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK,
629 host->base + HW_SSP_CTRL0 + MXS_SET_ADDR);
630 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
631 host->base + HW_SSP_CTRL1 + MXS_SET_ADDR);
632
633 if (readl(host->base + HW_SSP_STATUS) & BM_SSP_STATUS_SDIO_IRQ)
634 mmc_signal_sdio_irq(host->mmc);
635
636 } else {
637 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK,
638 host->base + HW_SSP_CTRL0 + MXS_CLR_ADDR);
639 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
640 host->base + HW_SSP_CTRL1 + MXS_CLR_ADDR);
641 }
642
643 spin_unlock_irqrestore(&host->lock, flags);
644}
645
646static const struct mmc_host_ops mxs_mmc_ops = {
647 .request = mxs_mmc_request,
648 .get_ro = mxs_mmc_get_ro,
649 .get_cd = mxs_mmc_get_cd,
650 .set_ios = mxs_mmc_set_ios,
651 .enable_sdio_irq = mxs_mmc_enable_sdio_irq,
652};
653
654static bool mxs_mmc_dma_filter(struct dma_chan *chan, void *param)
655{
656 struct mxs_mmc_host *host = param;
657
658 if (!mxs_dma_is_apbh(chan))
659 return false;
660
661 if (chan->chan_id != host->dma_res->start)
662 return false;
663
664 chan->private = &host->dma_data;
665
666 return true;
667}
668
669static int mxs_mmc_probe(struct platform_device *pdev)
670{
671 struct mxs_mmc_host *host;
672 struct mmc_host *mmc;
673 struct resource *iores, *dmares, *r;
674 struct mxs_mmc_platform_data *pdata;
675 int ret = 0, irq_err, irq_dma;
676 dma_cap_mask_t mask;
677
678 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
679 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
680 irq_err = platform_get_irq(pdev, 0);
681 irq_dma = platform_get_irq(pdev, 1);
682 if (!iores || !dmares || irq_err < 0 || irq_dma < 0)
683 return -EINVAL;
684
685 r = request_mem_region(iores->start, resource_size(iores), pdev->name);
686 if (!r)
687 return -EBUSY;
688
689 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev);
690 if (!mmc) {
691 ret = -ENOMEM;
692 goto out_release_mem;
693 }
694
695 host = mmc_priv(mmc);
696 host->base = ioremap(r->start, resource_size(r));
697 if (!host->base) {
698 ret = -ENOMEM;
699 goto out_mmc_free;
700 }
701
702 /* only major verion does matter */
703 host->version = readl(host->base + HW_SSP_VERSION) >>
704 BP_SSP_VERSION_MAJOR;
705
706 host->mmc = mmc;
707 host->res = r;
708 host->dma_res = dmares;
709 host->irq = irq_err;
710 host->sdio_irq_en = 0;
711
712 host->clk = clk_get(&pdev->dev, NULL);
713 if (IS_ERR(host->clk)) {
714 ret = PTR_ERR(host->clk);
715 goto out_iounmap;
716 }
717 clk_enable(host->clk);
718
719 mxs_mmc_reset(host);
720
721 dma_cap_zero(mask);
722 dma_cap_set(DMA_SLAVE, mask);
723 host->dma_data.chan_irq = irq_dma;
724 host->dmach = dma_request_channel(mask, mxs_mmc_dma_filter, host);
725 if (!host->dmach) {
726 dev_err(mmc_dev(host->mmc),
727 "%s: failed to request dma\n", __func__);
728 goto out_clk_put;
729 }
730
731 /* set mmc core parameters */
732 mmc->ops = &mxs_mmc_ops;
733 mmc->caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED |
734 MMC_CAP_SDIO_IRQ | MMC_CAP_NEEDS_POLL;
735
736 pdata = mmc_dev(host->mmc)->platform_data;
737 if (pdata) {
738 if (pdata->flags & SLOTF_8_BIT_CAPABLE)
739 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
740 if (pdata->flags & SLOTF_4_BIT_CAPABLE)
741 mmc->caps |= MMC_CAP_4_BIT_DATA;
742 }
743
744 mmc->f_min = 400000;
745 mmc->f_max = 288000000;
746 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
747
748 mmc->max_segs = 52;
749 mmc->max_blk_size = 1 << 0xf;
750 mmc->max_blk_count = (ssp_is_old()) ? 0xff : 0xffffff;
751 mmc->max_req_size = (ssp_is_old()) ? 0xffff : 0xffffffff;
752 mmc->max_seg_size = dma_get_max_seg_size(host->dmach->device->dev);
753
754 platform_set_drvdata(pdev, mmc);
755
756 ret = request_irq(host->irq, mxs_mmc_irq_handler, 0, DRIVER_NAME, host);
757 if (ret)
758 goto out_free_dma;
759
760 spin_lock_init(&host->lock);
761
762 ret = mmc_add_host(mmc);
763 if (ret)
764 goto out_free_irq;
765
766 dev_info(mmc_dev(host->mmc), "initialized\n");
767
768 return 0;
769
770out_free_irq:
771 free_irq(host->irq, host);
772out_free_dma:
773 if (host->dmach)
774 dma_release_channel(host->dmach);
775out_clk_put:
776 clk_disable(host->clk);
777 clk_put(host->clk);
778out_iounmap:
779 iounmap(host->base);
780out_mmc_free:
781 mmc_free_host(mmc);
782out_release_mem:
783 release_mem_region(iores->start, resource_size(iores));
784 return ret;
785}
786
787static int mxs_mmc_remove(struct platform_device *pdev)
788{
789 struct mmc_host *mmc = platform_get_drvdata(pdev);
790 struct mxs_mmc_host *host = mmc_priv(mmc);
791 struct resource *res = host->res;
792
793 mmc_remove_host(mmc);
794
795 free_irq(host->irq, host);
796
797 platform_set_drvdata(pdev, NULL);
798
799 if (host->dmach)
800 dma_release_channel(host->dmach);
801
802 clk_disable(host->clk);
803 clk_put(host->clk);
804
805 iounmap(host->base);
806
807 mmc_free_host(mmc);
808
809 release_mem_region(res->start, resource_size(res));
810
811 return 0;
812}
813
814#ifdef CONFIG_PM
815static int mxs_mmc_suspend(struct device *dev)
816{
817 struct mmc_host *mmc = dev_get_drvdata(dev);
818 struct mxs_mmc_host *host = mmc_priv(mmc);
819 int ret = 0;
820
821 ret = mmc_suspend_host(mmc);
822
823 clk_disable(host->clk);
824
825 return ret;
826}
827
828static int mxs_mmc_resume(struct device *dev)
829{
830 struct mmc_host *mmc = dev_get_drvdata(dev);
831 struct mxs_mmc_host *host = mmc_priv(mmc);
832 int ret = 0;
833
834 clk_enable(host->clk);
835
836 ret = mmc_resume_host(mmc);
837
838 return ret;
839}
840
841static const struct dev_pm_ops mxs_mmc_pm_ops = {
842 .suspend = mxs_mmc_suspend,
843 .resume = mxs_mmc_resume,
844};
845#endif
846
847static struct platform_driver mxs_mmc_driver = {
848 .probe = mxs_mmc_probe,
849 .remove = mxs_mmc_remove,
850 .driver = {
851 .name = DRIVER_NAME,
852 .owner = THIS_MODULE,
853#ifdef CONFIG_PM
854 .pm = &mxs_mmc_pm_ops,
855#endif
856 },
857};
858
859static int __init mxs_mmc_init(void)
860{
861 return platform_driver_register(&mxs_mmc_driver);
862}
863
864static void __exit mxs_mmc_exit(void)
865{
866 platform_driver_unregister(&mxs_mmc_driver);
867}
868
869module_init(mxs_mmc_init);
870module_exit(mxs_mmc_exit);
871
872MODULE_DESCRIPTION("FREESCALE MXS MMC peripheral");
873MODULE_AUTHOR("Freescale Semiconductor");
874MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 9b82910b9dbb..3b5248567973 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -15,9 +15,11 @@
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/gpio.h>
18#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
19#include <linux/mmc/sdhci-pltfm.h> 20#include <linux/mmc/sdhci-pltfm.h>
20#include <mach/hardware.h> 21#include <mach/hardware.h>
22#include <mach/esdhc.h>
21#include "sdhci.h" 23#include "sdhci.h"
22#include "sdhci-pltfm.h" 24#include "sdhci-pltfm.h"
23#include "sdhci-esdhc.h" 25#include "sdhci-esdhc.h"
@@ -30,6 +32,39 @@ static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, i
30 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base); 32 writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
31} 33}
32 34
35static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
36{
37 /* fake CARD_PRESENT flag on mx25/35 */
38 u32 val = readl(host->ioaddr + reg);
39
40 if (unlikely(reg == SDHCI_PRESENT_STATE)) {
41 struct esdhc_platform_data *boarddata =
42 host->mmc->parent->platform_data;
43
44 if (boarddata && gpio_is_valid(boarddata->cd_gpio)
45 && gpio_get_value(boarddata->cd_gpio))
46 /* no card, if a valid gpio says so... */
47 val &= SDHCI_CARD_PRESENT;
48 else
49 /* ... in all other cases assume card is present */
50 val |= SDHCI_CARD_PRESENT;
51 }
52
53 return val;
54}
55
56static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
57{
58 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE))
59 /*
60 * these interrupts won't work with a custom card_detect gpio
61 * (only applied to mx25/35)
62 */
63 val &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT);
64
65 writel(val, host->ioaddr + reg);
66}
67
33static u16 esdhc_readw_le(struct sdhci_host *host, int reg) 68static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
34{ 69{
35 if (unlikely(reg == SDHCI_HOST_VERSION)) 70 if (unlikely(reg == SDHCI_HOST_VERSION))
@@ -100,10 +135,39 @@ static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
100 return clk_get_rate(pltfm_host->clk) / 256 / 16; 135 return clk_get_rate(pltfm_host->clk) / 256 / 16;
101} 136}
102 137
138static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
139{
140 struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data;
141
142 if (boarddata && gpio_is_valid(boarddata->wp_gpio))
143 return gpio_get_value(boarddata->wp_gpio);
144 else
145 return -ENOSYS;
146}
147
148static struct sdhci_ops sdhci_esdhc_ops = {
149 .read_w = esdhc_readw_le,
150 .write_w = esdhc_writew_le,
151 .write_b = esdhc_writeb_le,
152 .set_clock = esdhc_set_clock,
153 .get_max_clock = esdhc_pltfm_get_max_clock,
154 .get_min_clock = esdhc_pltfm_get_min_clock,
155};
156
157static irqreturn_t cd_irq(int irq, void *data)
158{
159 struct sdhci_host *sdhost = (struct sdhci_host *)data;
160
161 tasklet_schedule(&sdhost->card_tasklet);
162 return IRQ_HANDLED;
163};
164
103static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata) 165static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata)
104{ 166{
105 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 167 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
168 struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data;
106 struct clk *clk; 169 struct clk *clk;
170 int err;
107 171
108 clk = clk_get(mmc_dev(host->mmc), NULL); 172 clk = clk_get(mmc_dev(host->mmc), NULL);
109 if (IS_ERR(clk)) { 173 if (IS_ERR(clk)) {
@@ -116,32 +180,78 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd
116 if (cpu_is_mx35() || cpu_is_mx51()) 180 if (cpu_is_mx35() || cpu_is_mx51())
117 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 181 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
118 182
119 /* Fix errata ENGcm07207 which is present on i.MX25 and i.MX35 */ 183 if (cpu_is_mx25() || cpu_is_mx35()) {
120 if (cpu_is_mx25() || cpu_is_mx35()) 184 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
121 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK; 185 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK;
186 /* write_protect can't be routed to controller, use gpio */
187 sdhci_esdhc_ops.get_ro = esdhc_pltfm_get_ro;
188 }
189
190 if (boarddata) {
191 err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP");
192 if (err) {
193 dev_warn(mmc_dev(host->mmc),
194 "no write-protect pin available!\n");
195 boarddata->wp_gpio = err;
196 }
197
198 err = gpio_request_one(boarddata->cd_gpio, GPIOF_IN, "ESDHC_CD");
199 if (err) {
200 dev_warn(mmc_dev(host->mmc),
201 "no card-detect pin available!\n");
202 goto no_card_detect_pin;
203 }
204
205 /* i.MX5x has issues to be researched */
206 if (!cpu_is_mx25() && !cpu_is_mx35())
207 goto not_supported;
208
209 err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq,
210 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
211 mmc_hostname(host->mmc), host);
212 if (err) {
213 dev_warn(mmc_dev(host->mmc), "request irq error\n");
214 goto no_card_detect_irq;
215 }
216
217 sdhci_esdhc_ops.write_l = esdhc_writel_le;
218 sdhci_esdhc_ops.read_l = esdhc_readl_le;
219 /* Now we have a working card_detect again */
220 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
221 }
222
223 return 0;
122 224
225 no_card_detect_irq:
226 gpio_free(boarddata->cd_gpio);
227 no_card_detect_pin:
228 boarddata->cd_gpio = err;
229 not_supported:
123 return 0; 230 return 0;
124} 231}
125 232
126static void esdhc_pltfm_exit(struct sdhci_host *host) 233static void esdhc_pltfm_exit(struct sdhci_host *host)
127{ 234{
128 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 235 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
236 struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data;
237
238 if (boarddata && gpio_is_valid(boarddata->wp_gpio))
239 gpio_free(boarddata->wp_gpio);
240
241 if (boarddata && gpio_is_valid(boarddata->cd_gpio)) {
242 gpio_free(boarddata->cd_gpio);
243
244 if (!(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION))
245 free_irq(gpio_to_irq(boarddata->cd_gpio), host);
246 }
129 247
130 clk_disable(pltfm_host->clk); 248 clk_disable(pltfm_host->clk);
131 clk_put(pltfm_host->clk); 249 clk_put(pltfm_host->clk);
132} 250}
133 251
134static struct sdhci_ops sdhci_esdhc_ops = {
135 .read_w = esdhc_readw_le,
136 .write_w = esdhc_writew_le,
137 .write_b = esdhc_writeb_le,
138 .set_clock = esdhc_set_clock,
139 .get_max_clock = esdhc_pltfm_get_max_clock,
140 .get_min_clock = esdhc_pltfm_get_min_clock,
141};
142
143struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { 252struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
144 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA, 253 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA
254 | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
145 /* ADMA has issues. Might be fixable */ 255 /* ADMA has issues. Might be fixable */
146 .ops = &sdhci_esdhc_ops, 256 .ops = &sdhci_esdhc_ops,
147 .init = esdhc_pltfm_init, 257 .init = esdhc_pltfm_init,
diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h
index afaf1bc4913a..c55aae828aac 100644
--- a/drivers/mmc/host/sdhci-esdhc.h
+++ b/drivers/mmc/host/sdhci-esdhc.h
@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21#define ESDHC_DEFAULT_QUIRKS (SDHCI_QUIRK_FORCE_BLK_SZ_2048 | \ 21#define ESDHC_DEFAULT_QUIRKS (SDHCI_QUIRK_FORCE_BLK_SZ_2048 | \
22 SDHCI_QUIRK_BROKEN_CARD_DETECTION | \
23 SDHCI_QUIRK_NO_BUSY_IRQ | \ 22 SDHCI_QUIRK_NO_BUSY_IRQ | \
24 SDHCI_QUIRK_NONSTANDARD_CLOCK | \ 23 SDHCI_QUIRK_NONSTANDARD_CLOCK | \
25 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | \ 24 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | \
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index fcd0e1fcba44..08161f690ae8 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -73,7 +73,8 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
73} 73}
74 74
75struct sdhci_of_data sdhci_esdhc = { 75struct sdhci_of_data sdhci_esdhc = {
76 .quirks = ESDHC_DEFAULT_QUIRKS, 76 /* card detection could be handled via GPIO */
77 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
77 .ops = { 78 .ops = {
78 .read_l = sdhci_be32bs_readl, 79 .read_l = sdhci_be32bs_readl,
79 .read_w = esdhc_readw, 80 .read_w = esdhc_readw,
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 0dc905b20eee..2f8d46854acd 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -547,6 +547,14 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
547 }, 547 },
548 548
549 { 549 {
550 .vendor = PCI_VENDOR_ID_RICOH,
551 .device = 0xe823,
552 .subvendor = PCI_ANY_ID,
553 .subdevice = PCI_ANY_ID,
554 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
555 },
556
557 {
550 .vendor = PCI_VENDOR_ID_ENE, 558 .vendor = PCI_VENDOR_ID_ENE,
551 .device = PCI_DEVICE_ID_ENE_CB712_SD, 559 .device = PCI_DEVICE_ID_ENE_CB712_SD,
552 .subvendor = PCI_ANY_ID, 560 .subvendor = PCI_ANY_ID,
@@ -900,9 +908,6 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
900{ 908{
901 struct sdhci_pci_slot *slot; 909 struct sdhci_pci_slot *slot;
902 struct sdhci_host *host; 910 struct sdhci_host *host;
903
904 resource_size_t addr;
905
906 int ret; 911 int ret;
907 912
908 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { 913 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
@@ -949,7 +954,6 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
949 goto free; 954 goto free;
950 } 955 }
951 956
952 addr = pci_resource_start(pdev, bar);
953 host->ioaddr = pci_ioremap_bar(pdev, bar); 957 host->ioaddr = pci_ioremap_bar(pdev, bar);
954 if (!host->ioaddr) { 958 if (!host->ioaddr) {
955 dev_err(&pdev->dev, "failed to remap registers\n"); 959 dev_err(&pdev->dev, "failed to remap registers\n");
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 5309ab95aada..69e3ee321eb5 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -499,6 +499,9 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
499 * SDHCI block, or a missing configuration that needs to be set. */ 499 * SDHCI block, or a missing configuration that needs to be set. */
500 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; 500 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
501 501
502 /* This host supports the Auto CMD12 */
503 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
504
502 if (pdata->cd_type == S3C_SDHCI_CD_NONE || 505 if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
503 pdata->cd_type == S3C_SDHCI_CD_PERMANENT) 506 pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
504 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; 507 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index 4823ee94a63f..f7e1f964395f 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -169,7 +169,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
169 if (rc) { 169 if (rc) {
170 dev_err(mmc_dev(host->mmc), 170 dev_err(mmc_dev(host->mmc),
171 "failed to allocate wp gpio\n"); 171 "failed to allocate wp gpio\n");
172 goto out_cd; 172 goto out_irq;
173 } 173 }
174 tegra_gpio_enable(plat->wp_gpio); 174 tegra_gpio_enable(plat->wp_gpio);
175 gpio_direction_input(plat->wp_gpio); 175 gpio_direction_input(plat->wp_gpio);
@@ -195,6 +195,9 @@ out_wp:
195 gpio_free(plat->wp_gpio); 195 gpio_free(plat->wp_gpio);
196 } 196 }
197 197
198out_irq:
199 if (gpio_is_valid(plat->cd_gpio))
200 free_irq(gpio_to_irq(plat->cd_gpio), host);
198out_cd: 201out_cd:
199 if (gpio_is_valid(plat->cd_gpio)) { 202 if (gpio_is_valid(plat->cd_gpio)) {
200 tegra_gpio_disable(plat->cd_gpio); 203 tegra_gpio_disable(plat->cd_gpio);
@@ -225,6 +228,7 @@ static void tegra_sdhci_pltfm_exit(struct sdhci_host *host)
225 } 228 }
226 229
227 if (gpio_is_valid(plat->cd_gpio)) { 230 if (gpio_is_valid(plat->cd_gpio)) {
231 free_irq(gpio_to_irq(plat->cd_gpio), host);
228 tegra_gpio_disable(plat->cd_gpio); 232 tegra_gpio_disable(plat->cd_gpio);
229 gpio_free(plat->cd_gpio); 233 gpio_free(plat->cd_gpio);
230 } 234 }
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 12884c270171..af97015a2fc7 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -169,7 +169,7 @@ struct sh_mmcif_host {
169 struct dma_chan *chan_rx; 169 struct dma_chan *chan_rx;
170 struct dma_chan *chan_tx; 170 struct dma_chan *chan_tx;
171 struct completion dma_complete; 171 struct completion dma_complete;
172 unsigned int dma_sglen; 172 bool dma_active;
173}; 173};
174 174
175static inline void sh_mmcif_bitset(struct sh_mmcif_host *host, 175static inline void sh_mmcif_bitset(struct sh_mmcif_host *host,
@@ -194,10 +194,12 @@ static void mmcif_dma_complete(void *arg)
194 return; 194 return;
195 195
196 if (host->data->flags & MMC_DATA_READ) 196 if (host->data->flags & MMC_DATA_READ)
197 dma_unmap_sg(&host->pd->dev, host->data->sg, host->dma_sglen, 197 dma_unmap_sg(host->chan_rx->device->dev,
198 host->data->sg, host->data->sg_len,
198 DMA_FROM_DEVICE); 199 DMA_FROM_DEVICE);
199 else 200 else
200 dma_unmap_sg(&host->pd->dev, host->data->sg, host->dma_sglen, 201 dma_unmap_sg(host->chan_tx->device->dev,
202 host->data->sg, host->data->sg_len,
201 DMA_TO_DEVICE); 203 DMA_TO_DEVICE);
202 204
203 complete(&host->dma_complete); 205 complete(&host->dma_complete);
@@ -211,9 +213,10 @@ static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
211 dma_cookie_t cookie = -EINVAL; 213 dma_cookie_t cookie = -EINVAL;
212 int ret; 214 int ret;
213 215
214 ret = dma_map_sg(&host->pd->dev, sg, host->data->sg_len, DMA_FROM_DEVICE); 216 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len,
217 DMA_FROM_DEVICE);
215 if (ret > 0) { 218 if (ret > 0) {
216 host->dma_sglen = ret; 219 host->dma_active = true;
217 desc = chan->device->device_prep_slave_sg(chan, sg, ret, 220 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
218 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 221 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
219 } 222 }
@@ -221,14 +224,9 @@ static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
221 if (desc) { 224 if (desc) {
222 desc->callback = mmcif_dma_complete; 225 desc->callback = mmcif_dma_complete;
223 desc->callback_param = host; 226 desc->callback_param = host;
224 cookie = desc->tx_submit(desc); 227 cookie = dmaengine_submit(desc);
225 if (cookie < 0) { 228 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
226 desc = NULL; 229 dma_async_issue_pending(chan);
227 ret = cookie;
228 } else {
229 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
230 chan->device->device_issue_pending(chan);
231 }
232 } 230 }
233 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", 231 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
234 __func__, host->data->sg_len, ret, cookie); 232 __func__, host->data->sg_len, ret, cookie);
@@ -238,7 +236,7 @@ static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
238 if (ret >= 0) 236 if (ret >= 0)
239 ret = -EIO; 237 ret = -EIO;
240 host->chan_rx = NULL; 238 host->chan_rx = NULL;
241 host->dma_sglen = 0; 239 host->dma_active = false;
242 dma_release_channel(chan); 240 dma_release_channel(chan);
243 /* Free the Tx channel too */ 241 /* Free the Tx channel too */
244 chan = host->chan_tx; 242 chan = host->chan_tx;
@@ -263,9 +261,10 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
263 dma_cookie_t cookie = -EINVAL; 261 dma_cookie_t cookie = -EINVAL;
264 int ret; 262 int ret;
265 263
266 ret = dma_map_sg(&host->pd->dev, sg, host->data->sg_len, DMA_TO_DEVICE); 264 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len,
265 DMA_TO_DEVICE);
267 if (ret > 0) { 266 if (ret > 0) {
268 host->dma_sglen = ret; 267 host->dma_active = true;
269 desc = chan->device->device_prep_slave_sg(chan, sg, ret, 268 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
270 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 269 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
271 } 270 }
@@ -273,14 +272,9 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
273 if (desc) { 272 if (desc) {
274 desc->callback = mmcif_dma_complete; 273 desc->callback = mmcif_dma_complete;
275 desc->callback_param = host; 274 desc->callback_param = host;
276 cookie = desc->tx_submit(desc); 275 cookie = dmaengine_submit(desc);
277 if (cookie < 0) { 276 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
278 desc = NULL; 277 dma_async_issue_pending(chan);
279 ret = cookie;
280 } else {
281 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
282 chan->device->device_issue_pending(chan);
283 }
284 } 278 }
285 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", 279 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
286 __func__, host->data->sg_len, ret, cookie); 280 __func__, host->data->sg_len, ret, cookie);
@@ -290,7 +284,7 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
290 if (ret >= 0) 284 if (ret >= 0)
291 ret = -EIO; 285 ret = -EIO;
292 host->chan_tx = NULL; 286 host->chan_tx = NULL;
293 host->dma_sglen = 0; 287 host->dma_active = false;
294 dma_release_channel(chan); 288 dma_release_channel(chan);
295 /* Free the Rx channel too */ 289 /* Free the Rx channel too */
296 chan = host->chan_rx; 290 chan = host->chan_rx;
@@ -317,7 +311,7 @@ static bool sh_mmcif_filter(struct dma_chan *chan, void *arg)
317static void sh_mmcif_request_dma(struct sh_mmcif_host *host, 311static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
318 struct sh_mmcif_plat_data *pdata) 312 struct sh_mmcif_plat_data *pdata)
319{ 313{
320 host->dma_sglen = 0; 314 host->dma_active = false;
321 315
322 /* We can only either use DMA for both Tx and Rx or not use it at all */ 316 /* We can only either use DMA for both Tx and Rx or not use it at all */
323 if (pdata->dma) { 317 if (pdata->dma) {
@@ -364,7 +358,7 @@ static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
364 dma_release_channel(chan); 358 dma_release_channel(chan);
365 } 359 }
366 360
367 host->dma_sglen = 0; 361 host->dma_active = false;
368} 362}
369 363
370static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) 364static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
@@ -753,7 +747,7 @@ static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
753 } 747 }
754 sh_mmcif_get_response(host, cmd); 748 sh_mmcif_get_response(host, cmd);
755 if (host->data) { 749 if (host->data) {
756 if (!host->dma_sglen) { 750 if (!host->dma_active) {
757 ret = sh_mmcif_data_trans(host, mrq, cmd->opcode); 751 ret = sh_mmcif_data_trans(host, mrq, cmd->opcode);
758 } else { 752 } else {
759 long time = 753 long time =
@@ -765,7 +759,7 @@ static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
765 ret = time; 759 ret = time;
766 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, 760 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
767 BUF_ACC_DMAREN | BUF_ACC_DMAWEN); 761 BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
768 host->dma_sglen = 0; 762 host->dma_active = false;
769 } 763 }
770 if (ret < 0) 764 if (ret < 0)
771 mrq->data->bytes_xfered = 0; 765 mrq->data->bytes_xfered = 0;
@@ -850,15 +844,15 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
850 struct sh_mmcif_host *host = mmc_priv(mmc); 844 struct sh_mmcif_host *host = mmc_priv(mmc);
851 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; 845 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
852 846
853 if (ios->power_mode == MMC_POWER_OFF) { 847 if (ios->power_mode == MMC_POWER_UP) {
848 if (p->set_pwr)
849 p->set_pwr(host->pd, ios->power_mode);
850 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
854 /* clock stop */ 851 /* clock stop */
855 sh_mmcif_clock_control(host, 0); 852 sh_mmcif_clock_control(host, 0);
856 if (p->down_pwr) 853 if (ios->power_mode == MMC_POWER_OFF && p->down_pwr)
857 p->down_pwr(host->pd); 854 p->down_pwr(host->pd);
858 return; 855 return;
859 } else if (ios->power_mode == MMC_POWER_UP) {
860 if (p->set_pwr)
861 p->set_pwr(host->pd, ios->power_mode);
862 } 856 }
863 857
864 if (ios->clock) 858 if (ios->clock)
diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c
index e3c6ef208391..ac52eb65395e 100644
--- a/drivers/mmc/host/tmio_mmc.c
+++ b/drivers/mmc/host/tmio_mmc.c
@@ -152,7 +152,6 @@ struct tmio_mmc_host {
152 struct tasklet_struct dma_complete; 152 struct tasklet_struct dma_complete;
153 struct tasklet_struct dma_issue; 153 struct tasklet_struct dma_issue;
154#ifdef CONFIG_TMIO_MMC_DMA 154#ifdef CONFIG_TMIO_MMC_DMA
155 unsigned int dma_sglen;
156 u8 bounce_buf[PAGE_CACHE_SIZE] __attribute__((aligned(MAX_ALIGN))); 155 u8 bounce_buf[PAGE_CACHE_SIZE] __attribute__((aligned(MAX_ALIGN)));
157 struct scatterlist bounce_sg; 156 struct scatterlist bounce_sg;
158#endif 157#endif
@@ -220,44 +219,48 @@ static char *tmio_mmc_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
220 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; 219 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
221} 220}
222 221
223static void tmio_mmc_kunmap_atomic(void *virt, unsigned long *flags) 222static void tmio_mmc_kunmap_atomic(struct scatterlist *sg, unsigned long *flags, void *virt)
224{ 223{
225 kunmap_atomic(virt, KM_BIO_SRC_IRQ); 224 kunmap_atomic(virt - sg->offset, KM_BIO_SRC_IRQ);
226 local_irq_restore(*flags); 225 local_irq_restore(*flags);
227} 226}
228 227
229#ifdef CONFIG_MMC_DEBUG 228#ifdef CONFIG_MMC_DEBUG
230 229
231#define STATUS_TO_TEXT(a) \ 230#define STATUS_TO_TEXT(a, status, i) \
232 do { \ 231 do { \
233 if (status & TMIO_STAT_##a) \ 232 if (status & TMIO_STAT_##a) { \
233 if (i++) \
234 printk(" | "); \
234 printk(#a); \ 235 printk(#a); \
236 } \
235 } while (0) 237 } while (0)
236 238
237void pr_debug_status(u32 status) 239void pr_debug_status(u32 status)
238{ 240{
241 int i = 0;
239 printk(KERN_DEBUG "status: %08x = ", status); 242 printk(KERN_DEBUG "status: %08x = ", status);
240 STATUS_TO_TEXT(CARD_REMOVE); 243 STATUS_TO_TEXT(CARD_REMOVE, status, i);
241 STATUS_TO_TEXT(CARD_INSERT); 244 STATUS_TO_TEXT(CARD_INSERT, status, i);
242 STATUS_TO_TEXT(SIGSTATE); 245 STATUS_TO_TEXT(SIGSTATE, status, i);
243 STATUS_TO_TEXT(WRPROTECT); 246 STATUS_TO_TEXT(WRPROTECT, status, i);
244 STATUS_TO_TEXT(CARD_REMOVE_A); 247 STATUS_TO_TEXT(CARD_REMOVE_A, status, i);
245 STATUS_TO_TEXT(CARD_INSERT_A); 248 STATUS_TO_TEXT(CARD_INSERT_A, status, i);
246 STATUS_TO_TEXT(SIGSTATE_A); 249 STATUS_TO_TEXT(SIGSTATE_A, status, i);
247 STATUS_TO_TEXT(CMD_IDX_ERR); 250 STATUS_TO_TEXT(CMD_IDX_ERR, status, i);
248 STATUS_TO_TEXT(STOPBIT_ERR); 251 STATUS_TO_TEXT(STOPBIT_ERR, status, i);
249 STATUS_TO_TEXT(ILL_FUNC); 252 STATUS_TO_TEXT(ILL_FUNC, status, i);
250 STATUS_TO_TEXT(CMD_BUSY); 253 STATUS_TO_TEXT(CMD_BUSY, status, i);
251 STATUS_TO_TEXT(CMDRESPEND); 254 STATUS_TO_TEXT(CMDRESPEND, status, i);
252 STATUS_TO_TEXT(DATAEND); 255 STATUS_TO_TEXT(DATAEND, status, i);
253 STATUS_TO_TEXT(CRCFAIL); 256 STATUS_TO_TEXT(CRCFAIL, status, i);
254 STATUS_TO_TEXT(DATATIMEOUT); 257 STATUS_TO_TEXT(DATATIMEOUT, status, i);
255 STATUS_TO_TEXT(CMDTIMEOUT); 258 STATUS_TO_TEXT(CMDTIMEOUT, status, i);
256 STATUS_TO_TEXT(RXOVERFLOW); 259 STATUS_TO_TEXT(RXOVERFLOW, status, i);
257 STATUS_TO_TEXT(TXUNDERRUN); 260 STATUS_TO_TEXT(TXUNDERRUN, status, i);
258 STATUS_TO_TEXT(RXRDY); 261 STATUS_TO_TEXT(RXRDY, status, i);
259 STATUS_TO_TEXT(TXRQ); 262 STATUS_TO_TEXT(TXRQ, status, i);
260 STATUS_TO_TEXT(ILL_ACCESS); 263 STATUS_TO_TEXT(ILL_ACCESS, status, i);
261 printk("\n"); 264 printk("\n");
262} 265}
263 266
@@ -507,7 +510,7 @@ static void tmio_mmc_pio_irq(struct tmio_mmc_host *host)
507 510
508 host->sg_off += count; 511 host->sg_off += count;
509 512
510 tmio_mmc_kunmap_atomic(sg_virt, &flags); 513 tmio_mmc_kunmap_atomic(host->sg_ptr, &flags, sg_virt);
511 514
512 if (host->sg_off == host->sg_ptr->length) 515 if (host->sg_off == host->sg_ptr->length)
513 tmio_mmc_next_sg(host); 516 tmio_mmc_next_sg(host);
@@ -767,7 +770,7 @@ static void tmio_check_bounce_buffer(struct tmio_mmc_host *host)
767 unsigned long flags; 770 unsigned long flags;
768 void *sg_vaddr = tmio_mmc_kmap_atomic(host->sg_orig, &flags); 771 void *sg_vaddr = tmio_mmc_kmap_atomic(host->sg_orig, &flags);
769 memcpy(sg_vaddr, host->bounce_buf, host->bounce_sg.length); 772 memcpy(sg_vaddr, host->bounce_buf, host->bounce_sg.length);
770 tmio_mmc_kunmap_atomic(sg_vaddr, &flags); 773 tmio_mmc_kunmap_atomic(host->sg_orig, &flags, sg_vaddr);
771 } 774 }
772} 775}
773 776
@@ -825,23 +828,16 @@ static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
825 sg = host->sg_ptr; 828 sg = host->sg_ptr;
826 } 829 }
827 830
828 ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, DMA_FROM_DEVICE); 831 ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_FROM_DEVICE);
829 if (ret > 0) { 832 if (ret > 0)
830 host->dma_sglen = ret;
831 desc = chan->device->device_prep_slave_sg(chan, sg, ret, 833 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
832 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 834 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
833 }
834 835
835 if (desc) { 836 if (desc) {
836 desc->callback = tmio_dma_complete; 837 desc->callback = tmio_dma_complete;
837 desc->callback_param = host; 838 desc->callback_param = host;
838 cookie = desc->tx_submit(desc); 839 cookie = dmaengine_submit(desc);
839 if (cookie < 0) { 840 dma_async_issue_pending(chan);
840 desc = NULL;
841 ret = cookie;
842 } else {
843 chan->device->device_issue_pending(chan);
844 }
845 } 841 }
846 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n", 842 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n",
847 __func__, host->sg_len, ret, cookie, host->mrq); 843 __func__, host->sg_len, ret, cookie, host->mrq);
@@ -901,26 +897,20 @@ static void tmio_mmc_start_dma_tx(struct tmio_mmc_host *host)
901 void *sg_vaddr = tmio_mmc_kmap_atomic(sg, &flags); 897 void *sg_vaddr = tmio_mmc_kmap_atomic(sg, &flags);
902 sg_init_one(&host->bounce_sg, host->bounce_buf, sg->length); 898 sg_init_one(&host->bounce_sg, host->bounce_buf, sg->length);
903 memcpy(host->bounce_buf, sg_vaddr, host->bounce_sg.length); 899 memcpy(host->bounce_buf, sg_vaddr, host->bounce_sg.length);
904 tmio_mmc_kunmap_atomic(sg_vaddr, &flags); 900 tmio_mmc_kunmap_atomic(sg, &flags, sg_vaddr);
905 host->sg_ptr = &host->bounce_sg; 901 host->sg_ptr = &host->bounce_sg;
906 sg = host->sg_ptr; 902 sg = host->sg_ptr;
907 } 903 }
908 904
909 ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, DMA_TO_DEVICE); 905 ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_TO_DEVICE);
910 if (ret > 0) { 906 if (ret > 0)
911 host->dma_sglen = ret;
912 desc = chan->device->device_prep_slave_sg(chan, sg, ret, 907 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
913 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 908 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
914 }
915 909
916 if (desc) { 910 if (desc) {
917 desc->callback = tmio_dma_complete; 911 desc->callback = tmio_dma_complete;
918 desc->callback_param = host; 912 desc->callback_param = host;
919 cookie = desc->tx_submit(desc); 913 cookie = dmaengine_submit(desc);
920 if (cookie < 0) {
921 desc = NULL;
922 ret = cookie;
923 }
924 } 914 }
925 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n", 915 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n",
926 __func__, host->sg_len, ret, cookie, host->mrq); 916 __func__, host->sg_len, ret, cookie, host->mrq);
@@ -964,7 +954,7 @@ static void tmio_issue_tasklet_fn(unsigned long priv)
964 struct tmio_mmc_host *host = (struct tmio_mmc_host *)priv; 954 struct tmio_mmc_host *host = (struct tmio_mmc_host *)priv;
965 struct dma_chan *chan = host->chan_tx; 955 struct dma_chan *chan = host->chan_tx;
966 956
967 chan->device->device_issue_pending(chan); 957 dma_async_issue_pending(chan);
968} 958}
969 959
970static void tmio_tasklet_fn(unsigned long arg) 960static void tmio_tasklet_fn(unsigned long arg)
@@ -978,10 +968,12 @@ static void tmio_tasklet_fn(unsigned long arg)
978 goto out; 968 goto out;
979 969
980 if (host->data->flags & MMC_DATA_READ) 970 if (host->data->flags & MMC_DATA_READ)
981 dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->dma_sglen, 971 dma_unmap_sg(host->chan_rx->device->dev,
972 host->sg_ptr, host->sg_len,
982 DMA_FROM_DEVICE); 973 DMA_FROM_DEVICE);
983 else 974 else
984 dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->dma_sglen, 975 dma_unmap_sg(host->chan_tx->device->dev,
976 host->sg_ptr, host->sg_len,
985 DMA_TO_DEVICE); 977 DMA_TO_DEVICE);
986 978
987 tmio_mmc_do_data_irq(host); 979 tmio_mmc_do_data_irq(host);
diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
index 9ed84ddb4780..8c5b4881ccd6 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -802,12 +802,9 @@ static const struct mmc_host_ops via_sdc_ops = {
802 802
803static void via_reset_pcictrl(struct via_crdr_mmc_host *host) 803static void via_reset_pcictrl(struct via_crdr_mmc_host *host)
804{ 804{
805 void __iomem *addrbase;
806 unsigned long flags; 805 unsigned long flags;
807 u8 gatt; 806 u8 gatt;
808 807
809 addrbase = host->pcictrl_mmiobase;
810
811 spin_lock_irqsave(&host->lock, flags); 808 spin_lock_irqsave(&host->lock, flags);
812 809
813 via_save_pcictrlreg(host); 810 via_save_pcictrlreg(host);
diff --git a/drivers/net/caif/Makefile b/drivers/net/caif/Makefile
index b38d987da67d..9560b9d624bd 100644
--- a/drivers/net/caif/Makefile
+++ b/drivers/net/caif/Makefile
@@ -1,6 +1,4 @@
1ifeq ($(CONFIG_CAIF_DEBUG),y) 1ccflags-$(CONFIG_CAIF_DEBUG) := -DDEBUG
2EXTRA_CFLAGS += -DDEBUG
3endif
4 2
5# Serial interface 3# Serial interface
6obj-$(CONFIG_CAIF_TTY) += caif_serial.o 4obj-$(CONFIG_CAIF_TTY) += caif_serial.o
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 5e403511289d..493b0de3848b 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -2685,9 +2685,9 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
2685 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, 2685 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
2686 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | 2686 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
2687 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | 2687 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
2688 tp->mii.supports_gmii ? 2688 (tp->mii.supports_gmii ?
2689 ADVERTISED_1000baseT_Half | 2689 ADVERTISED_1000baseT_Half |
2690 ADVERTISED_1000baseT_Full : 0); 2690 ADVERTISED_1000baseT_Full : 0));
2691 2691
2692 if (RTL_R8(PHYstatus) & TBI_Enable) 2692 if (RTL_R8(PHYstatus) & TBI_Enable)
2693 netif_info(tp, link, dev, "TBI auto-negotiating\n"); 2693 netif_info(tp, link, dev, "TBI auto-negotiating\n");
diff --git a/drivers/net/skfp/Makefile b/drivers/net/skfp/Makefile
index cb23580fcffa..b0be0234abf6 100644
--- a/drivers/net/skfp/Makefile
+++ b/drivers/net/skfp/Makefile
@@ -17,4 +17,4 @@ skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \
17# projects. To keep the source common for all those drivers (and 17# projects. To keep the source common for all those drivers (and
18# thus simplify fixes to it), please do not clean it up! 18# thus simplify fixes to it), please do not clean it up!
19 19
20EXTRA_CFLAGS += -Idrivers/net/skfp -DPCI -DMEM_MAPPED_IO -Wno-strict-prototypes 20ccflags-y := -Idrivers/net/skfp -DPCI -DMEM_MAPPED_IO -Wno-strict-prototypes
diff --git a/drivers/net/wan/lmc/Makefile b/drivers/net/wan/lmc/Makefile
index dabdcfed4efd..609710d64eb5 100644
--- a/drivers/net/wan/lmc/Makefile
+++ b/drivers/net/wan/lmc/Makefile
@@ -14,4 +14,4 @@ lmc-objs := lmc_debug.o lmc_media.o lmc_main.o lmc_proto.o
14# -DDEBUG \ 14# -DDEBUG \
15# -DLMC_PACKET_LOG 15# -DLMC_PACKET_LOG
16 16
17EXTRA_CFLAGS += -I. $(DBGDEF) 17ccflags-y := -I. $(DBGDEF)
diff --git a/drivers/net/wireless/hostap/hostap_config.h b/drivers/net/wireless/hostap/hostap_config.h
index 30acd39d76a2..2c8f71f0ed45 100644
--- a/drivers/net/wireless/hostap/hostap_config.h
+++ b/drivers/net/wireless/hostap/hostap_config.h
@@ -30,9 +30,9 @@
30 30
31/* Following defines can be used to remove unneeded parts of the driver, e.g., 31/* Following defines can be used to remove unneeded parts of the driver, e.g.,
32 * to limit the size of the kernel module. Definitions can be added here in 32 * to limit the size of the kernel module. Definitions can be added here in
33 * hostap_config.h or they can be added to make command with EXTRA_CFLAGS, 33 * hostap_config.h or they can be added to make command with ccflags-y,
34 * e.g., 34 * e.g.,
35 * 'make pccard EXTRA_CFLAGS="-DPRISM2_NO_DEBUG -DPRISM2_NO_PROCFS_DEBUG"' 35 * 'make pccard ccflags-y="-DPRISM2_NO_DEBUG -DPRISM2_NO_PROCFS_DEBUG"'
36 */ 36 */
37 37
38/* Do not include debug messages into the driver */ 38/* Do not include debug messages into the driver */
diff --git a/drivers/net/wireless/zd1211rw/Makefile b/drivers/net/wireless/zd1211rw/Makefile
index 1907eafb9b16..5728a918e508 100644
--- a/drivers/net/wireless/zd1211rw/Makefile
+++ b/drivers/net/wireless/zd1211rw/Makefile
@@ -5,7 +5,5 @@ zd1211rw-objs := zd_chip.o zd_mac.o \
5 zd_rf_al7230b.o zd_rf_uw2453.o \ 5 zd_rf_al7230b.o zd_rf_uw2453.o \
6 zd_rf.o zd_usb.o 6 zd_rf.o zd_usb.o
7 7
8ifeq ($(CONFIG_ZD1211RW_DEBUG),y) 8ccflags-$(CONFIG_ZD1211RW_DEBUG) := -DDEBUG
9EXTRA_CFLAGS += -DDEBUG
10endif
11 9
diff --git a/drivers/pps/clients/Makefile b/drivers/pps/clients/Makefile
index 42517da07049..4feb7e9e71ee 100644
--- a/drivers/pps/clients/Makefile
+++ b/drivers/pps/clients/Makefile
@@ -6,6 +6,4 @@ obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o 6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
7obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o 7obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o
8 8
9ifeq ($(CONFIG_PPS_DEBUG),y) 9ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
10EXTRA_CFLAGS += -DDEBUG
11endif
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
index b6139fe187bf..89b8eca825b5 100644
--- a/drivers/rapidio/Makefile
+++ b/drivers/rapidio/Makefile
@@ -5,6 +5,4 @@ obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o
5 5
6obj-$(CONFIG_RAPIDIO) += switches/ 6obj-$(CONFIG_RAPIDIO) += switches/
7 7
8ifeq ($(CONFIG_RAPIDIO_DEBUG),y) 8subdir-ccflags-$(CONFIG_RAPIDIO_DEBUG) := -DDEBUG
9EXTRA_CFLAGS += -DDEBUG
10endif
diff --git a/drivers/rapidio/switches/Makefile b/drivers/rapidio/switches/Makefile
index 48d67a6b98c8..c4d3acc3c715 100644
--- a/drivers/rapidio/switches/Makefile
+++ b/drivers/rapidio/switches/Makefile
@@ -7,7 +7,3 @@ obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o
7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o 7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o
8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o 8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o
9obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o 9obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o
10
11ifeq ($(CONFIG_RAPIDIO_DEBUG),y)
12EXTRA_CFLAGS += -DDEBUG
13endif
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 2afdaf3ff986..5f6c3838dcf6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -2,9 +2,7 @@
2# Makefile for RTC class/drivers. 2# Makefile for RTC class/drivers.
3# 3#
4 4
5ifeq ($(CONFIG_RTC_DEBUG),y) 5ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG
6 EXTRA_CFLAGS += -DDEBUG
7endif
8 6
9obj-$(CONFIG_RTC_LIB) += rtc-lib.o 7obj-$(CONFIG_RTC_LIB) += rtc-lib.o
10obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 8obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
diff --git a/drivers/scsi/aacraid/Makefile b/drivers/scsi/aacraid/Makefile
index f1cca4ee5410..92df4d6b6147 100644
--- a/drivers/scsi/aacraid/Makefile
+++ b/drivers/scsi/aacraid/Makefile
@@ -5,4 +5,4 @@ obj-$(CONFIG_SCSI_AACRAID) := aacraid.o
5aacraid-objs := linit.o aachba.o commctrl.o comminit.o commsup.o \ 5aacraid-objs := linit.o aachba.o commctrl.o comminit.o commsup.o \
6 dpcsup.o rx.o sa.o rkt.o nark.o 6 dpcsup.o rx.o sa.o rkt.o nark.o
7 7
8EXTRA_CFLAGS := -Idrivers/scsi 8ccflags-y := -Idrivers/scsi
diff --git a/drivers/scsi/aic94xx/Makefile b/drivers/scsi/aic94xx/Makefile
index e78ce0fa44d2..c0a15c754585 100644
--- a/drivers/scsi/aic94xx/Makefile
+++ b/drivers/scsi/aic94xx/Makefile
@@ -22,9 +22,7 @@
22# along with the aic94xx driver; if not, write to the Free Software 22# along with the aic94xx driver; if not, write to the Free Software
23# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 24
25ifeq ($(CONFIG_AIC94XX_DEBUG),y) 25ccflags-$(CONFIG_AIC94XX_DEBUG) := -DASD_DEBUG -DASD_ENTER_EXIT
26 EXTRA_CFLAGS += -DASD_DEBUG -DASD_ENTER_EXIT
27endif
28 26
29obj-$(CONFIG_SCSI_AIC94XX) += aic94xx.o 27obj-$(CONFIG_SCSI_AIC94XX) += aic94xx.o
30aic94xx-y += aic94xx_init.o \ 28aic94xx-y += aic94xx_init.o \
diff --git a/drivers/scsi/libsas/Makefile b/drivers/scsi/libsas/Makefile
index 566a10024598..2e70140f70c3 100644
--- a/drivers/scsi/libsas/Makefile
+++ b/drivers/scsi/libsas/Makefile
@@ -32,4 +32,4 @@ libsas-y += sas_init.o \
32 sas_scsi_host.o \ 32 sas_scsi_host.o \
33 sas_task.o 33 sas_task.o
34libsas-$(CONFIG_SCSI_SAS_ATA) += sas_ata.o 34libsas-$(CONFIG_SCSI_SAS_ATA) += sas_ata.o
35libsas-$(CONFIG_SCSI_SAS_HOST_SMP) += sas_host_smp.o \ No newline at end of file 35libsas-$(CONFIG_SCSI_SAS_HOST_SMP) += sas_host_smp.o
diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
index ad05d6edb8f6..14de249917f8 100644
--- a/drivers/scsi/lpfc/Makefile
+++ b/drivers/scsi/lpfc/Makefile
@@ -19,10 +19,8 @@
19# *******************************************************************/ 19# *******************************************************************/
20###################################################################### 20######################################################################
21 21
22ifneq ($(GCOV),) 22ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
23 EXTRA_CFLAGS += -fprofile-arcs -ftest-coverage 23ccflags-$(GCOV) += -O0
24 EXTRA_CFLAGS += -O0
25endif
26 24
27obj-$(CONFIG_SCSI_LPFC) := lpfc.o 25obj-$(CONFIG_SCSI_LPFC) := lpfc.o
28 26
diff --git a/drivers/scsi/mvsas/Makefile b/drivers/scsi/mvsas/Makefile
index 52ac4264677d..ffbf759e46f1 100644
--- a/drivers/scsi/mvsas/Makefile
+++ b/drivers/scsi/mvsas/Makefile
@@ -21,9 +21,7 @@
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22# USA 22# USA
23 23
24ifeq ($(CONFIG_SCSI_MVSAS_DEBUG),y) 24ccflags-$(CONFIG_SCSI_MVSAS_DEBUG) := -DMV_DEBUG
25 EXTRA_CFLAGS += -DMV_DEBUG
26endif
27 25
28obj-$(CONFIG_SCSI_MVSAS) += mvsas.o 26obj-$(CONFIG_SCSI_MVSAS) += mvsas.o
29mvsas-y += mv_init.o \ 27mvsas-y += mv_init.o \
diff --git a/drivers/scsi/pcmcia/Makefile b/drivers/scsi/pcmcia/Makefile
index eca379059db6..683bf148b5b7 100644
--- a/drivers/scsi/pcmcia/Makefile
+++ b/drivers/scsi/pcmcia/Makefile
@@ -1,5 +1,5 @@
1 1
2EXTRA_CFLAGS += -Idrivers/scsi 2ccflags-y := -Idrivers/scsi
3 3
4# 16-bit client drivers 4# 16-bit client drivers
5obj-$(CONFIG_PCMCIA_QLOGIC) += qlogic_cs.o 5obj-$(CONFIG_PCMCIA_QLOGIC) += qlogic_cs.o
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 38072e4e74bd..e35a17687c05 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1646,7 +1646,7 @@ static int autosuspend_check(struct usb_device *udev)
1646 return 0; 1646 return 0;
1647} 1647}
1648 1648
1649static int usb_runtime_suspend(struct device *dev) 1649int usb_runtime_suspend(struct device *dev)
1650{ 1650{
1651 struct usb_device *udev = to_usb_device(dev); 1651 struct usb_device *udev = to_usb_device(dev);
1652 int status; 1652 int status;
@@ -1667,7 +1667,7 @@ static int usb_runtime_suspend(struct device *dev)
1667 return status; 1667 return status;
1668} 1668}
1669 1669
1670static int usb_runtime_resume(struct device *dev) 1670int usb_runtime_resume(struct device *dev)
1671{ 1671{
1672 struct usb_device *udev = to_usb_device(dev); 1672 struct usb_device *udev = to_usb_device(dev);
1673 int status; 1673 int status;
@@ -1679,7 +1679,7 @@ static int usb_runtime_resume(struct device *dev)
1679 return status; 1679 return status;
1680} 1680}
1681 1681
1682static int usb_runtime_idle(struct device *dev) 1682int usb_runtime_idle(struct device *dev)
1683{ 1683{
1684 struct usb_device *udev = to_usb_device(dev); 1684 struct usb_device *udev = to_usb_device(dev);
1685 1685
@@ -1691,19 +1691,10 @@ static int usb_runtime_idle(struct device *dev)
1691 return 0; 1691 return 0;
1692} 1692}
1693 1693
1694static const struct dev_pm_ops usb_bus_pm_ops = {
1695 .runtime_suspend = usb_runtime_suspend,
1696 .runtime_resume = usb_runtime_resume,
1697 .runtime_idle = usb_runtime_idle,
1698};
1699
1700#endif /* CONFIG_USB_SUSPEND */ 1694#endif /* CONFIG_USB_SUSPEND */
1701 1695
1702struct bus_type usb_bus_type = { 1696struct bus_type usb_bus_type = {
1703 .name = "usb", 1697 .name = "usb",
1704 .match = usb_device_match, 1698 .match = usb_device_match,
1705 .uevent = usb_uevent, 1699 .uevent = usb_uevent,
1706#ifdef CONFIG_USB_SUSPEND
1707 .pm = &usb_bus_pm_ops,
1708#endif
1709}; 1700};
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 079cb57bab4f..d9d4b169404f 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -315,6 +315,11 @@ static const struct dev_pm_ops usb_device_pm_ops = {
315 .thaw = usb_dev_thaw, 315 .thaw = usb_dev_thaw,
316 .poweroff = usb_dev_poweroff, 316 .poweroff = usb_dev_poweroff,
317 .restore = usb_dev_restore, 317 .restore = usb_dev_restore,
318#ifdef CONFIG_USB_SUSPEND
319 .runtime_suspend = usb_runtime_suspend,
320 .runtime_resume = usb_runtime_resume,
321 .runtime_idle = usb_runtime_idle,
322#endif
318}; 323};
319 324
320#endif /* CONFIG_PM */ 325#endif /* CONFIG_PM */
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index a9cf484ecae4..d450b742137e 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -77,6 +77,9 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
77extern void usb_autosuspend_device(struct usb_device *udev); 77extern void usb_autosuspend_device(struct usb_device *udev);
78extern int usb_autoresume_device(struct usb_device *udev); 78extern int usb_autoresume_device(struct usb_device *udev);
79extern int usb_remote_wakeup(struct usb_device *dev); 79extern int usb_remote_wakeup(struct usb_device *dev);
80extern int usb_runtime_suspend(struct device *dev);
81extern int usb_runtime_resume(struct device *dev);
82extern int usb_runtime_idle(struct device *dev);
80 83
81#else 84#else
82 85
diff --git a/drivers/video/intelfb/Makefile b/drivers/video/intelfb/Makefile
index 6c782d3ae1be..f7d631ebee8e 100644
--- a/drivers/video/intelfb/Makefile
+++ b/drivers/video/intelfb/Makefile
@@ -4,7 +4,4 @@ intelfb-y := intelfbdrv.o intelfbhw.o
4intelfb-$(CONFIG_FB_INTEL_I2C) += intelfb_i2c.o 4intelfb-$(CONFIG_FB_INTEL_I2C) += intelfb_i2c.o
5intelfb-objs := $(intelfb-y) 5intelfb-objs := $(intelfb-y)
6 6
7ifdef CONFIG_FB_INTEL_DEBUG 7ccflags-$(CONFIG_FB_INTEL_DEBUG) := -DDEBUG -DREGDUMP
8#EXTRA_CFLAGS += -DDEBUG -DVERBOSE -DREGDUMP
9EXTRA_CFLAGS += -DDEBUG -DREGDUMP
10endif
diff --git a/fs/affs/Makefile b/fs/affs/Makefile
index b2c4f54446f3..3988b4a78339 100644
--- a/fs/affs/Makefile
+++ b/fs/affs/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the Linux affs filesystem routines. 2# Makefile for the Linux affs filesystem routines.
3# 3#
4 4
5#EXTRA_CFLAGS=-DDEBUG=1 5#ccflags-y := -DDEBUG=1
6 6
7obj-$(CONFIG_AFFS_FS) += affs.o 7obj-$(CONFIG_AFFS_FS) += affs.o
8 8
diff --git a/fs/coda/Makefile b/fs/coda/Makefile
index 6c22e61da397..1bab69a0d347 100644
--- a/fs/coda/Makefile
+++ b/fs/coda/Makefile
@@ -9,4 +9,4 @@ coda-objs := psdev.o cache.o cnode.o inode.o dir.o file.o upcall.o \
9 9
10# If you want debugging output, please uncomment the following line. 10# If you want debugging output, please uncomment the following line.
11 11
12# EXTRA_CFLAGS += -DDEBUG -DDEBUG_SMB_MALLOC=1 12# ccflags-y := -DDEBUG -DDEBUG_SMB_MALLOC=1
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index 21f7e46da4c0..f3d23ef4e876 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS := -I$(src) 1ccflags-y := -I$(src)
2obj-$(CONFIG_GFS2_FS) += gfs2.o 2obj-$(CONFIG_GFS2_FS) += gfs2.o
3gfs2-y := acl.o bmap.o dir.o xattr.o glock.o \ 3gfs2-y := acl.o bmap.o dir.o xattr.o glock.o \
4 glops.o inode.o log.o lops.o main.o meta_io.o \ 4 glops.o inode.o log.o lops.o main.o meta_io.o \
diff --git a/fs/jfs/Makefile b/fs/jfs/Makefile
index 3adb6395e42d..a58fa72d7e59 100644
--- a/fs/jfs/Makefile
+++ b/fs/jfs/Makefile
@@ -13,4 +13,4 @@ jfs-y := super.o file.o inode.o namei.o jfs_mount.o jfs_umount.o \
13 13
14jfs-$(CONFIG_JFS_POSIX_ACL) += acl.o 14jfs-$(CONFIG_JFS_POSIX_ACL) += acl.o
15 15
16EXTRA_CFLAGS += -D_JFS_4K 16ccflags-y := -D_JFS_4K
diff --git a/fs/ncpfs/Makefile b/fs/ncpfs/Makefile
index 68ea095100a8..c66af563f2ce 100644
--- a/fs/ncpfs/Makefile
+++ b/fs/ncpfs/Makefile
@@ -11,6 +11,6 @@ ncpfs-$(CONFIG_NCPFS_EXTRAS) += symlink.o
11ncpfs-$(CONFIG_NCPFS_NFS_NS) += symlink.o 11ncpfs-$(CONFIG_NCPFS_NFS_NS) += symlink.o
12 12
13# If you want debugging output, please uncomment the following line 13# If you want debugging output, please uncomment the following line
14# EXTRA_CFLAGS += -DDEBUG_NCP=1 14# ccflags-y := -DDEBUG_NCP=1
15 15
16CFLAGS_ncplib_kernel.o := -finline-functions 16CFLAGS_ncplib_kernel.o := -finline-functions
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c
index d7fd696e595c..0a0a66d98cce 100644
--- a/fs/nilfs2/alloc.c
+++ b/fs/nilfs2/alloc.c
@@ -521,8 +521,8 @@ void nilfs_palloc_commit_free_entry(struct inode *inode,
521 group_offset, bitmap)) 521 group_offset, bitmap))
522 printk(KERN_WARNING "%s: entry number %llu already freed\n", 522 printk(KERN_WARNING "%s: entry number %llu already freed\n",
523 __func__, (unsigned long long)req->pr_entry_nr); 523 __func__, (unsigned long long)req->pr_entry_nr);
524 524 else
525 nilfs_palloc_group_desc_add_entries(inode, group, desc, 1); 525 nilfs_palloc_group_desc_add_entries(inode, group, desc, 1);
526 526
527 kunmap(req->pr_bitmap_bh->b_page); 527 kunmap(req->pr_bitmap_bh->b_page);
528 kunmap(req->pr_desc_bh->b_page); 528 kunmap(req->pr_desc_bh->b_page);
@@ -558,8 +558,8 @@ void nilfs_palloc_abort_alloc_entry(struct inode *inode,
558 group_offset, bitmap)) 558 group_offset, bitmap))
559 printk(KERN_WARNING "%s: entry number %llu already freed\n", 559 printk(KERN_WARNING "%s: entry number %llu already freed\n",
560 __func__, (unsigned long long)req->pr_entry_nr); 560 __func__, (unsigned long long)req->pr_entry_nr);
561 561 else
562 nilfs_palloc_group_desc_add_entries(inode, group, desc, 1); 562 nilfs_palloc_group_desc_add_entries(inode, group, desc, 1);
563 563
564 kunmap(req->pr_bitmap_bh->b_page); 564 kunmap(req->pr_bitmap_bh->b_page);
565 kunmap(req->pr_desc_bh->b_page); 565 kunmap(req->pr_desc_bh->b_page);
@@ -665,7 +665,7 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
665 for (j = i, n = 0; 665 for (j = i, n = 0;
666 (j < nitems) && nilfs_palloc_group_is_in(inode, group, 666 (j < nitems) && nilfs_palloc_group_is_in(inode, group,
667 entry_nrs[j]); 667 entry_nrs[j]);
668 j++, n++) { 668 j++) {
669 nilfs_palloc_group(inode, entry_nrs[j], &group_offset); 669 nilfs_palloc_group(inode, entry_nrs[j], &group_offset);
670 if (!nilfs_clear_bit_atomic( 670 if (!nilfs_clear_bit_atomic(
671 nilfs_mdt_bgl_lock(inode, group), 671 nilfs_mdt_bgl_lock(inode, group),
@@ -674,6 +674,8 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
674 "%s: entry number %llu already freed\n", 674 "%s: entry number %llu already freed\n",
675 __func__, 675 __func__,
676 (unsigned long long)entry_nrs[j]); 676 (unsigned long long)entry_nrs[j]);
677 } else {
678 n++;
677 } 679 }
678 } 680 }
679 nilfs_palloc_group_desc_add_entries(inode, group, desc, n); 681 nilfs_palloc_group_desc_add_entries(inode, group, desc, n);
diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c
index 3ee67c67cc52..4723f04e9b12 100644
--- a/fs/nilfs2/bmap.c
+++ b/fs/nilfs2/bmap.c
@@ -25,7 +25,6 @@
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include "nilfs.h" 26#include "nilfs.h"
27#include "bmap.h" 27#include "bmap.h"
28#include "sb.h"
29#include "btree.h" 28#include "btree.h"
30#include "direct.h" 29#include "direct.h"
31#include "btnode.h" 30#include "btnode.h"
@@ -425,17 +424,6 @@ int nilfs_bmap_test_and_clear_dirty(struct nilfs_bmap *bmap)
425/* 424/*
426 * Internal use only 425 * Internal use only
427 */ 426 */
428
429void nilfs_bmap_add_blocks(const struct nilfs_bmap *bmap, int n)
430{
431 inode_add_bytes(bmap->b_inode, (1 << bmap->b_inode->i_blkbits) * n);
432}
433
434void nilfs_bmap_sub_blocks(const struct nilfs_bmap *bmap, int n)
435{
436 inode_sub_bytes(bmap->b_inode, (1 << bmap->b_inode->i_blkbits) * n);
437}
438
439__u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap, 427__u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap,
440 const struct buffer_head *bh) 428 const struct buffer_head *bh)
441{ 429{
diff --git a/fs/nilfs2/bmap.h b/fs/nilfs2/bmap.h
index bde1c0aa2e15..40d9f453d31c 100644
--- a/fs/nilfs2/bmap.h
+++ b/fs/nilfs2/bmap.h
@@ -240,9 +240,6 @@ __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *,
240__u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64); 240__u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64);
241__u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *); 241__u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *);
242 242
243void nilfs_bmap_add_blocks(const struct nilfs_bmap *, int);
244void nilfs_bmap_sub_blocks(const struct nilfs_bmap *, int);
245
246 243
247/* Assume that bmap semaphore is locked. */ 244/* Assume that bmap semaphore is locked. */
248static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap) 245static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap)
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 300c2bc00c3f..d451ae0e0bf3 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -1174,7 +1174,7 @@ static int nilfs_btree_insert(struct nilfs_bmap *btree, __u64 key, __u64 ptr)
1174 if (ret < 0) 1174 if (ret < 0)
1175 goto out; 1175 goto out;
1176 nilfs_btree_commit_insert(btree, path, level, key, ptr); 1176 nilfs_btree_commit_insert(btree, path, level, key, ptr);
1177 nilfs_bmap_add_blocks(btree, stats.bs_nblocks); 1177 nilfs_inode_add_blocks(btree->b_inode, stats.bs_nblocks);
1178 1178
1179 out: 1179 out:
1180 nilfs_btree_free_path(path); 1180 nilfs_btree_free_path(path);
@@ -1511,7 +1511,7 @@ static int nilfs_btree_delete(struct nilfs_bmap *btree, __u64 key)
1511 if (ret < 0) 1511 if (ret < 0)
1512 goto out; 1512 goto out;
1513 nilfs_btree_commit_delete(btree, path, level, dat); 1513 nilfs_btree_commit_delete(btree, path, level, dat);
1514 nilfs_bmap_sub_blocks(btree, stats.bs_nblocks); 1514 nilfs_inode_sub_blocks(btree->b_inode, stats.bs_nblocks);
1515 1515
1516out: 1516out:
1517 nilfs_btree_free_path(path); 1517 nilfs_btree_free_path(path);
@@ -1776,7 +1776,7 @@ int nilfs_btree_convert_and_insert(struct nilfs_bmap *btree,
1776 return ret; 1776 return ret;
1777 nilfs_btree_commit_convert_and_insert(btree, key, ptr, keys, ptrs, n, 1777 nilfs_btree_commit_convert_and_insert(btree, key, ptr, keys, ptrs, n,
1778 di, ni, bh); 1778 di, ni, bh);
1779 nilfs_bmap_add_blocks(btree, stats.bs_nblocks); 1779 nilfs_inode_add_blocks(btree->b_inode, stats.bs_nblocks);
1780 return 0; 1780 return 0;
1781} 1781}
1782 1782
diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index 9d45773b79e6..3a1923943b14 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -440,7 +440,6 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
440 nilfs_commit_chunk(page, mapping, from, to); 440 nilfs_commit_chunk(page, mapping, from, to);
441 nilfs_put_page(page); 441 nilfs_put_page(page);
442 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 442 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
443/* NILFS_I(dir)->i_flags &= ~NILFS_BTREE_FL; */
444} 443}
445 444
446/* 445/*
@@ -531,7 +530,6 @@ got_it:
531 nilfs_set_de_type(de, inode); 530 nilfs_set_de_type(de, inode);
532 nilfs_commit_chunk(page, page->mapping, from, to); 531 nilfs_commit_chunk(page, page->mapping, from, to);
533 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 532 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
534/* NILFS_I(dir)->i_flags &= ~NILFS_BTREE_FL; */
535 nilfs_mark_inode_dirty(dir); 533 nilfs_mark_inode_dirty(dir);
536 /* OFFSET_CACHE */ 534 /* OFFSET_CACHE */
537out_put: 535out_put:
@@ -579,7 +577,6 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
579 dir->inode = 0; 577 dir->inode = 0;
580 nilfs_commit_chunk(page, mapping, from, to); 578 nilfs_commit_chunk(page, mapping, from, to);
581 inode->i_ctime = inode->i_mtime = CURRENT_TIME; 579 inode->i_ctime = inode->i_mtime = CURRENT_TIME;
582/* NILFS_I(inode)->i_flags &= ~NILFS_BTREE_FL; */
583out: 580out:
584 nilfs_put_page(page); 581 nilfs_put_page(page);
585 return err; 582 return err;
@@ -684,7 +681,7 @@ const struct file_operations nilfs_dir_operations = {
684 .readdir = nilfs_readdir, 681 .readdir = nilfs_readdir,
685 .unlocked_ioctl = nilfs_ioctl, 682 .unlocked_ioctl = nilfs_ioctl,
686#ifdef CONFIG_COMPAT 683#ifdef CONFIG_COMPAT
687 .compat_ioctl = nilfs_ioctl, 684 .compat_ioctl = nilfs_compat_ioctl,
688#endif /* CONFIG_COMPAT */ 685#endif /* CONFIG_COMPAT */
689 .fsync = nilfs_sync_file, 686 .fsync = nilfs_sync_file,
690 687
diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c
index 324d80c57518..82f4865e86dd 100644
--- a/fs/nilfs2/direct.c
+++ b/fs/nilfs2/direct.c
@@ -146,7 +146,7 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
146 if (NILFS_BMAP_USE_VBN(bmap)) 146 if (NILFS_BMAP_USE_VBN(bmap))
147 nilfs_bmap_set_target_v(bmap, key, req.bpr_ptr); 147 nilfs_bmap_set_target_v(bmap, key, req.bpr_ptr);
148 148
149 nilfs_bmap_add_blocks(bmap, 1); 149 nilfs_inode_add_blocks(bmap->b_inode, 1);
150 } 150 }
151 return ret; 151 return ret;
152} 152}
@@ -168,7 +168,7 @@ static int nilfs_direct_delete(struct nilfs_bmap *bmap, __u64 key)
168 if (!ret) { 168 if (!ret) {
169 nilfs_bmap_commit_end_ptr(bmap, &req, dat); 169 nilfs_bmap_commit_end_ptr(bmap, &req, dat);
170 nilfs_direct_set_ptr(bmap, key, NILFS_BMAP_INVALID_PTR); 170 nilfs_direct_set_ptr(bmap, key, NILFS_BMAP_INVALID_PTR);
171 nilfs_bmap_sub_blocks(bmap, 1); 171 nilfs_inode_sub_blocks(bmap->b_inode, 1);
172 } 172 }
173 return ret; 173 return ret;
174} 174}
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 2f560c9fb808..93589fccdd97 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -59,7 +59,7 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
59 struct nilfs_transaction_info ti; 59 struct nilfs_transaction_info ti;
60 int ret; 60 int ret;
61 61
62 if (unlikely(nilfs_near_disk_full(NILFS_SB(inode->i_sb)->s_nilfs))) 62 if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
63 return VM_FAULT_SIGBUS; /* -ENOSPC */ 63 return VM_FAULT_SIGBUS; /* -ENOSPC */
64 64
65 lock_page(page); 65 lock_page(page);
@@ -142,7 +142,7 @@ const struct file_operations nilfs_file_operations = {
142 .aio_write = generic_file_aio_write, 142 .aio_write = generic_file_aio_write,
143 .unlocked_ioctl = nilfs_ioctl, 143 .unlocked_ioctl = nilfs_ioctl,
144#ifdef CONFIG_COMPAT 144#ifdef CONFIG_COMPAT
145 .compat_ioctl = nilfs_ioctl, 145 .compat_ioctl = nilfs_compat_ioctl,
146#endif /* CONFIG_COMPAT */ 146#endif /* CONFIG_COMPAT */
147 .mmap = nilfs_file_mmap, 147 .mmap = nilfs_file_mmap,
148 .open = generic_file_open, 148 .open = generic_file_open,
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 2fd440d8d6b8..d5625be236a8 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -41,6 +41,24 @@ struct nilfs_iget_args {
41 int for_gc; 41 int for_gc;
42}; 42};
43 43
44void nilfs_inode_add_blocks(struct inode *inode, int n)
45{
46 struct nilfs_root *root = NILFS_I(inode)->i_root;
47
48 inode_add_bytes(inode, (1 << inode->i_blkbits) * n);
49 if (root)
50 atomic_add(n, &root->blocks_count);
51}
52
53void nilfs_inode_sub_blocks(struct inode *inode, int n)
54{
55 struct nilfs_root *root = NILFS_I(inode)->i_root;
56
57 inode_sub_bytes(inode, (1 << inode->i_blkbits) * n);
58 if (root)
59 atomic_sub(n, &root->blocks_count);
60}
61
44/** 62/**
45 * nilfs_get_block() - get a file block on the filesystem (callback function) 63 * nilfs_get_block() - get a file block on the filesystem (callback function)
46 * @inode - inode struct of the target file 64 * @inode - inode struct of the target file
@@ -277,7 +295,7 @@ const struct address_space_operations nilfs_aops = {
277struct inode *nilfs_new_inode(struct inode *dir, int mode) 295struct inode *nilfs_new_inode(struct inode *dir, int mode)
278{ 296{
279 struct super_block *sb = dir->i_sb; 297 struct super_block *sb = dir->i_sb;
280 struct nilfs_sb_info *sbi = NILFS_SB(sb); 298 struct the_nilfs *nilfs = sb->s_fs_info;
281 struct inode *inode; 299 struct inode *inode;
282 struct nilfs_inode_info *ii; 300 struct nilfs_inode_info *ii;
283 struct nilfs_root *root; 301 struct nilfs_root *root;
@@ -315,19 +333,16 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
315 /* No lock is needed; iget() ensures it. */ 333 /* No lock is needed; iget() ensures it. */
316 } 334 }
317 335
318 ii->i_flags = NILFS_I(dir)->i_flags; 336 ii->i_flags = nilfs_mask_flags(
319 if (S_ISLNK(mode)) 337 mode, NILFS_I(dir)->i_flags & NILFS_FL_INHERITED);
320 ii->i_flags &= ~(NILFS_IMMUTABLE_FL | NILFS_APPEND_FL);
321 if (!S_ISDIR(mode))
322 ii->i_flags &= ~NILFS_DIRSYNC_FL;
323 338
324 /* ii->i_file_acl = 0; */ 339 /* ii->i_file_acl = 0; */
325 /* ii->i_dir_acl = 0; */ 340 /* ii->i_dir_acl = 0; */
326 ii->i_dir_start_lookup = 0; 341 ii->i_dir_start_lookup = 0;
327 nilfs_set_inode_flags(inode); 342 nilfs_set_inode_flags(inode);
328 spin_lock(&sbi->s_next_gen_lock); 343 spin_lock(&nilfs->ns_next_gen_lock);
329 inode->i_generation = sbi->s_next_generation++; 344 inode->i_generation = nilfs->ns_next_generation++;
330 spin_unlock(&sbi->s_next_gen_lock); 345 spin_unlock(&nilfs->ns_next_gen_lock);
331 insert_inode_hash(inode); 346 insert_inode_hash(inode);
332 347
333 err = nilfs_init_acl(inode, dir); 348 err = nilfs_init_acl(inode, dir);
@@ -359,17 +374,15 @@ void nilfs_set_inode_flags(struct inode *inode)
359 374
360 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | 375 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
361 S_DIRSYNC); 376 S_DIRSYNC);
362 if (flags & NILFS_SYNC_FL) 377 if (flags & FS_SYNC_FL)
363 inode->i_flags |= S_SYNC; 378 inode->i_flags |= S_SYNC;
364 if (flags & NILFS_APPEND_FL) 379 if (flags & FS_APPEND_FL)
365 inode->i_flags |= S_APPEND; 380 inode->i_flags |= S_APPEND;
366 if (flags & NILFS_IMMUTABLE_FL) 381 if (flags & FS_IMMUTABLE_FL)
367 inode->i_flags |= S_IMMUTABLE; 382 inode->i_flags |= S_IMMUTABLE;
368#ifndef NILFS_ATIME_DISABLE 383 if (flags & FS_NOATIME_FL)
369 if (flags & NILFS_NOATIME_FL)
370#endif
371 inode->i_flags |= S_NOATIME; 384 inode->i_flags |= S_NOATIME;
372 if (flags & NILFS_DIRSYNC_FL) 385 if (flags & FS_DIRSYNC_FL)
373 inode->i_flags |= S_DIRSYNC; 386 inode->i_flags |= S_DIRSYNC;
374 mapping_set_gfp_mask(inode->i_mapping, 387 mapping_set_gfp_mask(inode->i_mapping,
375 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 388 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
@@ -420,7 +433,7 @@ static int __nilfs_read_inode(struct super_block *sb,
420 struct nilfs_root *root, unsigned long ino, 433 struct nilfs_root *root, unsigned long ino,
421 struct inode *inode) 434 struct inode *inode)
422{ 435{
423 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; 436 struct the_nilfs *nilfs = sb->s_fs_info;
424 struct buffer_head *bh; 437 struct buffer_head *bh;
425 struct nilfs_inode *raw_inode; 438 struct nilfs_inode *raw_inode;
426 int err; 439 int err;
@@ -707,6 +720,7 @@ void nilfs_evict_inode(struct inode *inode)
707 struct nilfs_transaction_info ti; 720 struct nilfs_transaction_info ti;
708 struct super_block *sb = inode->i_sb; 721 struct super_block *sb = inode->i_sb;
709 struct nilfs_inode_info *ii = NILFS_I(inode); 722 struct nilfs_inode_info *ii = NILFS_I(inode);
723 int ret;
710 724
711 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) { 725 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
712 if (inode->i_data.nrpages) 726 if (inode->i_data.nrpages)
@@ -725,8 +739,9 @@ void nilfs_evict_inode(struct inode *inode)
725 nilfs_mark_inode_dirty(inode); 739 nilfs_mark_inode_dirty(inode);
726 end_writeback(inode); 740 end_writeback(inode);
727 741
728 nilfs_ifile_delete_inode(ii->i_root->ifile, inode->i_ino); 742 ret = nilfs_ifile_delete_inode(ii->i_root->ifile, inode->i_ino);
729 atomic_dec(&ii->i_root->inodes_count); 743 if (!ret)
744 atomic_dec(&ii->i_root->inodes_count);
730 745
731 nilfs_clear_inode(inode); 746 nilfs_clear_inode(inode);
732 747
@@ -792,18 +807,18 @@ int nilfs_permission(struct inode *inode, int mask, unsigned int flags)
792 807
793int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh) 808int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
794{ 809{
795 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb); 810 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
796 struct nilfs_inode_info *ii = NILFS_I(inode); 811 struct nilfs_inode_info *ii = NILFS_I(inode);
797 int err; 812 int err;
798 813
799 spin_lock(&sbi->s_inode_lock); 814 spin_lock(&nilfs->ns_inode_lock);
800 if (ii->i_bh == NULL) { 815 if (ii->i_bh == NULL) {
801 spin_unlock(&sbi->s_inode_lock); 816 spin_unlock(&nilfs->ns_inode_lock);
802 err = nilfs_ifile_get_inode_block(ii->i_root->ifile, 817 err = nilfs_ifile_get_inode_block(ii->i_root->ifile,
803 inode->i_ino, pbh); 818 inode->i_ino, pbh);
804 if (unlikely(err)) 819 if (unlikely(err))
805 return err; 820 return err;
806 spin_lock(&sbi->s_inode_lock); 821 spin_lock(&nilfs->ns_inode_lock);
807 if (ii->i_bh == NULL) 822 if (ii->i_bh == NULL)
808 ii->i_bh = *pbh; 823 ii->i_bh = *pbh;
809 else { 824 else {
@@ -814,36 +829,36 @@ int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
814 *pbh = ii->i_bh; 829 *pbh = ii->i_bh;
815 830
816 get_bh(*pbh); 831 get_bh(*pbh);
817 spin_unlock(&sbi->s_inode_lock); 832 spin_unlock(&nilfs->ns_inode_lock);
818 return 0; 833 return 0;
819} 834}
820 835
821int nilfs_inode_dirty(struct inode *inode) 836int nilfs_inode_dirty(struct inode *inode)
822{ 837{
823 struct nilfs_inode_info *ii = NILFS_I(inode); 838 struct nilfs_inode_info *ii = NILFS_I(inode);
824 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb); 839 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
825 int ret = 0; 840 int ret = 0;
826 841
827 if (!list_empty(&ii->i_dirty)) { 842 if (!list_empty(&ii->i_dirty)) {
828 spin_lock(&sbi->s_inode_lock); 843 spin_lock(&nilfs->ns_inode_lock);
829 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) || 844 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) ||
830 test_bit(NILFS_I_BUSY, &ii->i_state); 845 test_bit(NILFS_I_BUSY, &ii->i_state);
831 spin_unlock(&sbi->s_inode_lock); 846 spin_unlock(&nilfs->ns_inode_lock);
832 } 847 }
833 return ret; 848 return ret;
834} 849}
835 850
836int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty) 851int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty)
837{ 852{
838 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
839 struct nilfs_inode_info *ii = NILFS_I(inode); 853 struct nilfs_inode_info *ii = NILFS_I(inode);
854 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
840 855
841 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks); 856 atomic_add(nr_dirty, &nilfs->ns_ndirtyblks);
842 857
843 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state)) 858 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state))
844 return 0; 859 return 0;
845 860
846 spin_lock(&sbi->s_inode_lock); 861 spin_lock(&nilfs->ns_inode_lock);
847 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && 862 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
848 !test_bit(NILFS_I_BUSY, &ii->i_state)) { 863 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
849 /* Because this routine may race with nilfs_dispose_list(), 864 /* Because this routine may race with nilfs_dispose_list(),
@@ -851,18 +866,18 @@ int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty)
851 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) { 866 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) {
852 /* This will happen when somebody is freeing 867 /* This will happen when somebody is freeing
853 this inode. */ 868 this inode. */
854 nilfs_warning(sbi->s_super, __func__, 869 nilfs_warning(inode->i_sb, __func__,
855 "cannot get inode (ino=%lu)\n", 870 "cannot get inode (ino=%lu)\n",
856 inode->i_ino); 871 inode->i_ino);
857 spin_unlock(&sbi->s_inode_lock); 872 spin_unlock(&nilfs->ns_inode_lock);
858 return -EINVAL; /* NILFS_I_DIRTY may remain for 873 return -EINVAL; /* NILFS_I_DIRTY may remain for
859 freeing inode */ 874 freeing inode */
860 } 875 }
861 list_del(&ii->i_dirty); 876 list_del(&ii->i_dirty);
862 list_add_tail(&ii->i_dirty, &sbi->s_dirty_files); 877 list_add_tail(&ii->i_dirty, &nilfs->ns_dirty_files);
863 set_bit(NILFS_I_QUEUED, &ii->i_state); 878 set_bit(NILFS_I_QUEUED, &ii->i_state);
864 } 879 }
865 spin_unlock(&sbi->s_inode_lock); 880 spin_unlock(&nilfs->ns_inode_lock);
866 return 0; 881 return 0;
867} 882}
868 883
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 496738963fdb..95c04c2f2b3e 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -26,7 +26,9 @@
26#include <linux/capability.h> /* capable() */ 26#include <linux/capability.h> /* capable() */
27#include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ 27#include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29#include <linux/compat.h> /* compat_ptr() */
29#include <linux/mount.h> /* mnt_want_write(), mnt_drop_write() */ 30#include <linux/mount.h> /* mnt_want_write(), mnt_drop_write() */
31#include <linux/buffer_head.h>
30#include <linux/nilfs2_fs.h> 32#include <linux/nilfs2_fs.h>
31#include "nilfs.h" 33#include "nilfs.h"
32#include "segment.h" 34#include "segment.h"
@@ -97,11 +99,74 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
97 return ret; 99 return ret;
98} 100}
99 101
102static int nilfs_ioctl_getflags(struct inode *inode, void __user *argp)
103{
104 unsigned int flags = NILFS_I(inode)->i_flags & FS_FL_USER_VISIBLE;
105
106 return put_user(flags, (int __user *)argp);
107}
108
109static int nilfs_ioctl_setflags(struct inode *inode, struct file *filp,
110 void __user *argp)
111{
112 struct nilfs_transaction_info ti;
113 unsigned int flags, oldflags;
114 int ret;
115
116 if (!is_owner_or_cap(inode))
117 return -EACCES;
118
119 if (get_user(flags, (int __user *)argp))
120 return -EFAULT;
121
122 ret = mnt_want_write(filp->f_path.mnt);
123 if (ret)
124 return ret;
125
126 flags = nilfs_mask_flags(inode->i_mode, flags);
127
128 mutex_lock(&inode->i_mutex);
129
130 oldflags = NILFS_I(inode)->i_flags;
131
132 /*
133 * The IMMUTABLE and APPEND_ONLY flags can only be changed by the
134 * relevant capability.
135 */
136 ret = -EPERM;
137 if (((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) &&
138 !capable(CAP_LINUX_IMMUTABLE))
139 goto out;
140
141 ret = nilfs_transaction_begin(inode->i_sb, &ti, 0);
142 if (ret)
143 goto out;
144
145 NILFS_I(inode)->i_flags = (oldflags & ~FS_FL_USER_MODIFIABLE) |
146 (flags & FS_FL_USER_MODIFIABLE);
147
148 nilfs_set_inode_flags(inode);
149 inode->i_ctime = CURRENT_TIME;
150 if (IS_SYNC(inode))
151 nilfs_set_transaction_flag(NILFS_TI_SYNC);
152
153 nilfs_mark_inode_dirty(inode);
154 ret = nilfs_transaction_commit(inode->i_sb);
155out:
156 mutex_unlock(&inode->i_mutex);
157 mnt_drop_write(filp->f_path.mnt);
158 return ret;
159}
160
161static int nilfs_ioctl_getversion(struct inode *inode, void __user *argp)
162{
163 return put_user(inode->i_generation, (int __user *)argp);
164}
165
100static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, 166static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,
101 unsigned int cmd, void __user *argp) 167 unsigned int cmd, void __user *argp)
102{ 168{
103 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 169 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
104 struct inode *cpfile = nilfs->ns_cpfile;
105 struct nilfs_transaction_info ti; 170 struct nilfs_transaction_info ti;
106 struct nilfs_cpmode cpmode; 171 struct nilfs_cpmode cpmode;
107 int ret; 172 int ret;
@@ -121,7 +186,7 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,
121 186
122 nilfs_transaction_begin(inode->i_sb, &ti, 0); 187 nilfs_transaction_begin(inode->i_sb, &ti, 0);
123 ret = nilfs_cpfile_change_cpmode( 188 ret = nilfs_cpfile_change_cpmode(
124 cpfile, cpmode.cm_cno, cpmode.cm_mode); 189 nilfs->ns_cpfile, cpmode.cm_cno, cpmode.cm_mode);
125 if (unlikely(ret < 0)) 190 if (unlikely(ret < 0))
126 nilfs_transaction_abort(inode->i_sb); 191 nilfs_transaction_abort(inode->i_sb);
127 else 192 else
@@ -137,7 +202,7 @@ static int
137nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp, 202nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
138 unsigned int cmd, void __user *argp) 203 unsigned int cmd, void __user *argp)
139{ 204{
140 struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile; 205 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
141 struct nilfs_transaction_info ti; 206 struct nilfs_transaction_info ti;
142 __u64 cno; 207 __u64 cno;
143 int ret; 208 int ret;
@@ -154,7 +219,7 @@ nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
154 goto out; 219 goto out;
155 220
156 nilfs_transaction_begin(inode->i_sb, &ti, 0); 221 nilfs_transaction_begin(inode->i_sb, &ti, 0);
157 ret = nilfs_cpfile_delete_checkpoint(cpfile, cno); 222 ret = nilfs_cpfile_delete_checkpoint(nilfs->ns_cpfile, cno);
158 if (unlikely(ret < 0)) 223 if (unlikely(ret < 0))
159 nilfs_transaction_abort(inode->i_sb); 224 nilfs_transaction_abort(inode->i_sb);
160 else 225 else
@@ -180,7 +245,7 @@ nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
180static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp, 245static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp,
181 unsigned int cmd, void __user *argp) 246 unsigned int cmd, void __user *argp)
182{ 247{
183 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 248 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
184 struct nilfs_cpstat cpstat; 249 struct nilfs_cpstat cpstat;
185 int ret; 250 int ret;
186 251
@@ -211,7 +276,7 @@ nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
211static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp, 276static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp,
212 unsigned int cmd, void __user *argp) 277 unsigned int cmd, void __user *argp)
213{ 278{
214 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 279 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
215 struct nilfs_sustat sustat; 280 struct nilfs_sustat sustat;
216 int ret; 281 int ret;
217 282
@@ -267,7 +332,7 @@ nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags,
267static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp, 332static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp,
268 unsigned int cmd, void __user *argp) 333 unsigned int cmd, void __user *argp)
269{ 334{
270 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 335 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
271 struct nilfs_argv argv; 336 struct nilfs_argv argv;
272 int ret; 337 int ret;
273 338
@@ -336,7 +401,7 @@ static int nilfs_ioctl_move_blocks(struct super_block *sb,
336 struct nilfs_argv *argv, void *buf) 401 struct nilfs_argv *argv, void *buf)
337{ 402{
338 size_t nmembs = argv->v_nmembs; 403 size_t nmembs = argv->v_nmembs;
339 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; 404 struct the_nilfs *nilfs = sb->s_fs_info;
340 struct inode *inode; 405 struct inode *inode;
341 struct nilfs_vdesc *vdesc; 406 struct nilfs_vdesc *vdesc;
342 struct buffer_head *bh, *n; 407 struct buffer_head *bh, *n;
@@ -550,7 +615,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
550 ret = PTR_ERR(kbufs[4]); 615 ret = PTR_ERR(kbufs[4]);
551 goto out; 616 goto out;
552 } 617 }
553 nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 618 nilfs = inode->i_sb->s_fs_info;
554 619
555 for (n = 0; n < 4; n++) { 620 for (n = 0; n < 4; n++) {
556 ret = -EINVAL; 621 ret = -EINVAL;
@@ -623,7 +688,7 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
623 return ret; 688 return ret;
624 689
625 if (argp != NULL) { 690 if (argp != NULL) {
626 nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 691 nilfs = inode->i_sb->s_fs_info;
627 down_read(&nilfs->ns_segctor_sem); 692 down_read(&nilfs->ns_segctor_sem);
628 cno = nilfs->ns_cno - 1; 693 cno = nilfs->ns_cno - 1;
629 up_read(&nilfs->ns_segctor_sem); 694 up_read(&nilfs->ns_segctor_sem);
@@ -641,7 +706,7 @@ static int nilfs_ioctl_get_info(struct inode *inode, struct file *filp,
641 void *, size_t, size_t)) 706 void *, size_t, size_t))
642 707
643{ 708{
644 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; 709 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
645 struct nilfs_argv argv; 710 struct nilfs_argv argv;
646 int ret; 711 int ret;
647 712
@@ -666,6 +731,12 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
666 void __user *argp = (void __user *)arg; 731 void __user *argp = (void __user *)arg;
667 732
668 switch (cmd) { 733 switch (cmd) {
734 case FS_IOC_GETFLAGS:
735 return nilfs_ioctl_getflags(inode, argp);
736 case FS_IOC_SETFLAGS:
737 return nilfs_ioctl_setflags(inode, filp, argp);
738 case FS_IOC_GETVERSION:
739 return nilfs_ioctl_getversion(inode, argp);
669 case NILFS_IOCTL_CHANGE_CPMODE: 740 case NILFS_IOCTL_CHANGE_CPMODE:
670 return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp); 741 return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp);
671 case NILFS_IOCTL_DELETE_CHECKPOINT: 742 case NILFS_IOCTL_DELETE_CHECKPOINT:
@@ -696,3 +767,23 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
696 return -ENOTTY; 767 return -ENOTTY;
697 } 768 }
698} 769}
770
771#ifdef CONFIG_COMPAT
772long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
773{
774 switch (cmd) {
775 case FS_IOC32_GETFLAGS:
776 cmd = FS_IOC_GETFLAGS;
777 break;
778 case FS_IOC32_SETFLAGS:
779 cmd = FS_IOC_SETFLAGS;
780 break;
781 case FS_IOC32_GETVERSION:
782 cmd = FS_IOC_GETVERSION;
783 break;
784 default:
785 return -ENOIOCTLCMD;
786 }
787 return nilfs_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
788}
789#endif
diff --git a/fs/nilfs2/mdt.h b/fs/nilfs2/mdt.h
index b13734bf3521..ed68563ec708 100644
--- a/fs/nilfs2/mdt.h
+++ b/fs/nilfs2/mdt.h
@@ -66,7 +66,7 @@ static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode)
66 66
67static inline struct the_nilfs *NILFS_I_NILFS(struct inode *inode) 67static inline struct the_nilfs *NILFS_I_NILFS(struct inode *inode)
68{ 68{
69 return NILFS_SB(inode->i_sb)->s_nilfs; 69 return inode->i_sb->s_fs_info;
70} 70}
71 71
72/* Default GFP flags using highmem */ 72/* Default GFP flags using highmem */
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 161791d26458..546849b3e88f 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -482,7 +482,7 @@ static struct dentry *nilfs_get_dentry(struct super_block *sb, u64 cno,
482 if (ino < NILFS_FIRST_INO(sb) && ino != NILFS_ROOT_INO) 482 if (ino < NILFS_FIRST_INO(sb) && ino != NILFS_ROOT_INO)
483 return ERR_PTR(-ESTALE); 483 return ERR_PTR(-ESTALE);
484 484
485 root = nilfs_lookup_root(NILFS_SB(sb)->s_nilfs, cno); 485 root = nilfs_lookup_root(sb->s_fs_info, cno);
486 if (!root) 486 if (!root)
487 return ERR_PTR(-ESTALE); 487 return ERR_PTR(-ESTALE);
488 488
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 777e8fd04304..856e8e4e0b74 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -30,7 +30,6 @@
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/nilfs2_fs.h> 31#include <linux/nilfs2_fs.h>
32#include "the_nilfs.h" 32#include "the_nilfs.h"
33#include "sb.h"
34#include "bmap.h" 33#include "bmap.h"
35 34
36/* 35/*
@@ -122,7 +121,7 @@ enum {
122#define NILFS_SYS_INO_BITS \ 121#define NILFS_SYS_INO_BITS \
123 ((unsigned int)(1 << NILFS_ROOT_INO) | NILFS_MDT_INO_BITS) 122 ((unsigned int)(1 << NILFS_ROOT_INO) | NILFS_MDT_INO_BITS)
124 123
125#define NILFS_FIRST_INO(sb) (NILFS_SB(sb)->s_nilfs->ns_first_ino) 124#define NILFS_FIRST_INO(sb) (((struct the_nilfs *)sb->s_fs_info)->ns_first_ino)
126 125
127#define NILFS_MDT_INODE(sb, ino) \ 126#define NILFS_MDT_INODE(sb, ino) \
128 ((ino) < NILFS_FIRST_INO(sb) && (NILFS_MDT_INO_BITS & (1 << (ino)))) 127 ((ino) < NILFS_FIRST_INO(sb) && (NILFS_MDT_INO_BITS & (1 << (ino))))
@@ -212,6 +211,23 @@ static inline int nilfs_init_acl(struct inode *inode, struct inode *dir)
212 211
213#define NILFS_ATIME_DISABLE 212#define NILFS_ATIME_DISABLE
214 213
214/* Flags that should be inherited by new inodes from their parent. */
215#define NILFS_FL_INHERITED \
216 (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \
217 FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\
218 FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)
219
220/* Mask out flags that are inappropriate for the given type of inode. */
221static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)
222{
223 if (S_ISDIR(mode))
224 return flags;
225 else if (S_ISREG(mode))
226 return flags & ~(FS_DIRSYNC_FL | FS_TOPDIR_FL);
227 else
228 return flags & (FS_NODUMP_FL | FS_NOATIME_FL);
229}
230
215/* dir.c */ 231/* dir.c */
216extern int nilfs_add_link(struct dentry *, struct inode *); 232extern int nilfs_add_link(struct dentry *, struct inode *);
217extern ino_t nilfs_inode_by_name(struct inode *, const struct qstr *); 233extern ino_t nilfs_inode_by_name(struct inode *, const struct qstr *);
@@ -229,10 +245,13 @@ extern int nilfs_sync_file(struct file *, int);
229 245
230/* ioctl.c */ 246/* ioctl.c */
231long nilfs_ioctl(struct file *, unsigned int, unsigned long); 247long nilfs_ioctl(struct file *, unsigned int, unsigned long);
248long nilfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
232int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *, 249int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,
233 void **); 250 void **);
234 251
235/* inode.c */ 252/* inode.c */
253void nilfs_inode_add_blocks(struct inode *inode, int n);
254void nilfs_inode_sub_blocks(struct inode *inode, int n);
236extern struct inode *nilfs_new_inode(struct inode *, int); 255extern struct inode *nilfs_new_inode(struct inode *, int);
237extern void nilfs_free_inode(struct inode *); 256extern void nilfs_free_inode(struct inode *);
238extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int); 257extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
@@ -275,11 +294,11 @@ extern int nilfs_check_feature_compatibility(struct super_block *,
275 struct nilfs_super_block *); 294 struct nilfs_super_block *);
276extern void nilfs_set_log_cursor(struct nilfs_super_block *, 295extern void nilfs_set_log_cursor(struct nilfs_super_block *,
277 struct the_nilfs *); 296 struct the_nilfs *);
278extern struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *, 297struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
279 int flip); 298 int flip);
280extern int nilfs_commit_super(struct nilfs_sb_info *, int); 299int nilfs_commit_super(struct super_block *sb, int flag);
281extern int nilfs_cleanup_super(struct nilfs_sb_info *); 300int nilfs_cleanup_super(struct super_block *sb);
282int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, 301int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
283 struct nilfs_root **root); 302 struct nilfs_root **root);
284int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno); 303int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno);
285 304
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c
index 3dfcd3b7d389..ba4a64518f38 100644
--- a/fs/nilfs2/recovery.c
+++ b/fs/nilfs2/recovery.c
@@ -425,7 +425,7 @@ void nilfs_dispose_segment_list(struct list_head *head)
425} 425}
426 426
427static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs, 427static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
428 struct nilfs_sb_info *sbi, 428 struct super_block *sb,
429 struct nilfs_recovery_info *ri) 429 struct nilfs_recovery_info *ri)
430{ 430{
431 struct list_head *head = &ri->ri_used_segments; 431 struct list_head *head = &ri->ri_used_segments;
@@ -501,7 +501,7 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
501} 501}
502 502
503static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs, 503static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
504 struct nilfs_sb_info *sbi, 504 struct super_block *sb,
505 struct nilfs_root *root, 505 struct nilfs_root *root,
506 struct list_head *head, 506 struct list_head *head,
507 unsigned long *nr_salvaged_blocks) 507 unsigned long *nr_salvaged_blocks)
@@ -514,7 +514,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
514 int err = 0, err2 = 0; 514 int err = 0, err2 = 0;
515 515
516 list_for_each_entry_safe(rb, n, head, list) { 516 list_for_each_entry_safe(rb, n, head, list) {
517 inode = nilfs_iget(sbi->s_super, root, rb->ino); 517 inode = nilfs_iget(sb, root, rb->ino);
518 if (IS_ERR(inode)) { 518 if (IS_ERR(inode)) {
519 err = PTR_ERR(inode); 519 err = PTR_ERR(inode);
520 inode = NULL; 520 inode = NULL;
@@ -572,11 +572,11 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
572 * nilfs_do_roll_forward - salvage logical segments newer than the latest 572 * nilfs_do_roll_forward - salvage logical segments newer than the latest
573 * checkpoint 573 * checkpoint
574 * @nilfs: nilfs object 574 * @nilfs: nilfs object
575 * @sbi: nilfs_sb_info 575 * @sb: super block instance
576 * @ri: pointer to a nilfs_recovery_info 576 * @ri: pointer to a nilfs_recovery_info
577 */ 577 */
578static int nilfs_do_roll_forward(struct the_nilfs *nilfs, 578static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
579 struct nilfs_sb_info *sbi, 579 struct super_block *sb,
580 struct nilfs_root *root, 580 struct nilfs_root *root,
581 struct nilfs_recovery_info *ri) 581 struct nilfs_recovery_info *ri)
582{ 582{
@@ -648,7 +648,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
648 goto failed; 648 goto failed;
649 if (flags & NILFS_SS_LOGEND) { 649 if (flags & NILFS_SS_LOGEND) {
650 err = nilfs_recover_dsync_blocks( 650 err = nilfs_recover_dsync_blocks(
651 nilfs, sbi, root, &dsync_blocks, 651 nilfs, sb, root, &dsync_blocks,
652 &nsalvaged_blocks); 652 &nsalvaged_blocks);
653 if (unlikely(err)) 653 if (unlikely(err))
654 goto failed; 654 goto failed;
@@ -681,7 +681,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
681 681
682 if (nsalvaged_blocks) { 682 if (nsalvaged_blocks) {
683 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n", 683 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n",
684 sbi->s_super->s_id, nsalvaged_blocks); 684 sb->s_id, nsalvaged_blocks);
685 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE; 685 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE;
686 } 686 }
687 out: 687 out:
@@ -695,7 +695,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
695 printk(KERN_ERR 695 printk(KERN_ERR
696 "NILFS (device %s): Error roll-forwarding " 696 "NILFS (device %s): Error roll-forwarding "
697 "(err=%d, pseg block=%llu). ", 697 "(err=%d, pseg block=%llu). ",
698 sbi->s_super->s_id, err, (unsigned long long)pseg_start); 698 sb->s_id, err, (unsigned long long)pseg_start);
699 goto out; 699 goto out;
700} 700}
701 701
@@ -724,7 +724,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
724/** 724/**
725 * nilfs_salvage_orphan_logs - salvage logs written after the latest checkpoint 725 * nilfs_salvage_orphan_logs - salvage logs written after the latest checkpoint
726 * @nilfs: nilfs object 726 * @nilfs: nilfs object
727 * @sbi: nilfs_sb_info 727 * @sb: super block instance
728 * @ri: pointer to a nilfs_recovery_info struct to store search results. 728 * @ri: pointer to a nilfs_recovery_info struct to store search results.
729 * 729 *
730 * Return Value: On success, 0 is returned. On error, one of the following 730 * Return Value: On success, 0 is returned. On error, one of the following
@@ -741,7 +741,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
741 * %-ENOMEM - Insufficient memory available. 741 * %-ENOMEM - Insufficient memory available.
742 */ 742 */
743int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, 743int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
744 struct nilfs_sb_info *sbi, 744 struct super_block *sb,
745 struct nilfs_recovery_info *ri) 745 struct nilfs_recovery_info *ri)
746{ 746{
747 struct nilfs_root *root; 747 struct nilfs_root *root;
@@ -750,32 +750,32 @@ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
750 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0) 750 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
751 return 0; 751 return 0;
752 752
753 err = nilfs_attach_checkpoint(sbi, ri->ri_cno, true, &root); 753 err = nilfs_attach_checkpoint(sb, ri->ri_cno, true, &root);
754 if (unlikely(err)) { 754 if (unlikely(err)) {
755 printk(KERN_ERR 755 printk(KERN_ERR
756 "NILFS: error loading the latest checkpoint.\n"); 756 "NILFS: error loading the latest checkpoint.\n");
757 return err; 757 return err;
758 } 758 }
759 759
760 err = nilfs_do_roll_forward(nilfs, sbi, root, ri); 760 err = nilfs_do_roll_forward(nilfs, sb, root, ri);
761 if (unlikely(err)) 761 if (unlikely(err))
762 goto failed; 762 goto failed;
763 763
764 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) { 764 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) {
765 err = nilfs_prepare_segment_for_recovery(nilfs, sbi, ri); 765 err = nilfs_prepare_segment_for_recovery(nilfs, sb, ri);
766 if (unlikely(err)) { 766 if (unlikely(err)) {
767 printk(KERN_ERR "NILFS: Error preparing segments for " 767 printk(KERN_ERR "NILFS: Error preparing segments for "
768 "recovery.\n"); 768 "recovery.\n");
769 goto failed; 769 goto failed;
770 } 770 }
771 771
772 err = nilfs_attach_segment_constructor(sbi, root); 772 err = nilfs_attach_log_writer(sb, root);
773 if (unlikely(err)) 773 if (unlikely(err))
774 goto failed; 774 goto failed;
775 775
776 set_nilfs_discontinued(nilfs); 776 set_nilfs_discontinued(nilfs);
777 err = nilfs_construct_segment(sbi->s_super); 777 err = nilfs_construct_segment(sb);
778 nilfs_detach_segment_constructor(sbi); 778 nilfs_detach_log_writer(sb);
779 779
780 if (unlikely(err)) { 780 if (unlikely(err)) {
781 printk(KERN_ERR "NILFS: Oops! recovery failed. " 781 printk(KERN_ERR "NILFS: Oops! recovery failed. "
diff --git a/fs/nilfs2/sb.h b/fs/nilfs2/sb.h
deleted file mode 100644
index 7a17715f215f..000000000000
--- a/fs/nilfs2/sb.h
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * sb.h - NILFS on-memory super block structure.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
21 *
22 */
23
24#ifndef _NILFS_SB
25#define _NILFS_SB
26
27#include <linux/types.h>
28#include <linux/fs.h>
29
30struct the_nilfs;
31struct nilfs_sc_info;
32
33/*
34 * NILFS super-block data in memory
35 */
36struct nilfs_sb_info {
37 /* Mount options */
38 unsigned long s_mount_opt;
39 uid_t s_resuid;
40 gid_t s_resgid;
41
42 unsigned long s_interval; /* construction interval */
43 unsigned long s_watermark; /* threshold of data amount
44 for the segment construction */
45
46 /* Fundamental members */
47 struct super_block *s_super; /* reverse pointer to super_block */
48 struct the_nilfs *s_nilfs;
49
50 /* Segment constructor */
51 struct list_head s_dirty_files; /* dirty files list */
52 struct nilfs_sc_info *s_sc_info; /* segment constructor info */
53 spinlock_t s_inode_lock; /* Lock for the nilfs inode.
54 It covers s_dirty_files list */
55
56 /* Inode allocator */
57 spinlock_t s_next_gen_lock;
58 u32 s_next_generation;
59};
60
61static inline struct nilfs_sb_info *NILFS_SB(struct super_block *sb)
62{
63 return sb->s_fs_info;
64}
65
66static inline struct nilfs_sc_info *NILFS_SC(struct nilfs_sb_info *sbi)
67{
68 return sbi->s_sc_info;
69}
70
71/*
72 * Bit operations for the mount option
73 */
74#define nilfs_clear_opt(sbi, opt) \
75 do { (sbi)->s_mount_opt &= ~NILFS_MOUNT_##opt; } while (0)
76#define nilfs_set_opt(sbi, opt) \
77 do { (sbi)->s_mount_opt |= NILFS_MOUNT_##opt; } while (0)
78#define nilfs_test_opt(sbi, opt) ((sbi)->s_mount_opt & NILFS_MOUNT_##opt)
79#define nilfs_write_opt(sbi, mask, opt) \
80 do { (sbi)->s_mount_opt = \
81 (((sbi)->s_mount_opt & ~NILFS_MOUNT_##mask) | \
82 NILFS_MOUNT_##opt); \
83 } while (0)
84
85#endif /* _NILFS_SB */
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 2de9f636792a..afe4f2183454 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -104,8 +104,7 @@ struct nilfs_sc_operations {
104static void nilfs_segctor_start_timer(struct nilfs_sc_info *); 104static void nilfs_segctor_start_timer(struct nilfs_sc_info *);
105static void nilfs_segctor_do_flush(struct nilfs_sc_info *, int); 105static void nilfs_segctor_do_flush(struct nilfs_sc_info *, int);
106static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *); 106static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *);
107static void nilfs_dispose_list(struct nilfs_sb_info *, struct list_head *, 107static void nilfs_dispose_list(struct the_nilfs *, struct list_head *, int);
108 int);
109 108
110#define nilfs_cnt32_gt(a, b) \ 109#define nilfs_cnt32_gt(a, b) \
111 (typecheck(__u32, a) && typecheck(__u32, b) && \ 110 (typecheck(__u32, a) && typecheck(__u32, b) && \
@@ -182,7 +181,6 @@ int nilfs_transaction_begin(struct super_block *sb,
182 struct nilfs_transaction_info *ti, 181 struct nilfs_transaction_info *ti,
183 int vacancy_check) 182 int vacancy_check)
184{ 183{
185 struct nilfs_sb_info *sbi;
186 struct the_nilfs *nilfs; 184 struct the_nilfs *nilfs;
187 int ret = nilfs_prepare_segment_lock(ti); 185 int ret = nilfs_prepare_segment_lock(ti);
188 186
@@ -193,8 +191,7 @@ int nilfs_transaction_begin(struct super_block *sb,
193 191
194 vfs_check_frozen(sb, SB_FREEZE_WRITE); 192 vfs_check_frozen(sb, SB_FREEZE_WRITE);
195 193
196 sbi = NILFS_SB(sb); 194 nilfs = sb->s_fs_info;
197 nilfs = sbi->s_nilfs;
198 down_read(&nilfs->ns_segctor_sem); 195 down_read(&nilfs->ns_segctor_sem);
199 if (vacancy_check && nilfs_near_disk_full(nilfs)) { 196 if (vacancy_check && nilfs_near_disk_full(nilfs)) {
200 up_read(&nilfs->ns_segctor_sem); 197 up_read(&nilfs->ns_segctor_sem);
@@ -225,8 +222,7 @@ int nilfs_transaction_begin(struct super_block *sb,
225int nilfs_transaction_commit(struct super_block *sb) 222int nilfs_transaction_commit(struct super_block *sb)
226{ 223{
227 struct nilfs_transaction_info *ti = current->journal_info; 224 struct nilfs_transaction_info *ti = current->journal_info;
228 struct nilfs_sb_info *sbi; 225 struct the_nilfs *nilfs = sb->s_fs_info;
229 struct nilfs_sc_info *sci;
230 int err = 0; 226 int err = 0;
231 227
232 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 228 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC);
@@ -235,16 +231,15 @@ int nilfs_transaction_commit(struct super_block *sb)
235 ti->ti_count--; 231 ti->ti_count--;
236 return 0; 232 return 0;
237 } 233 }
238 sbi = NILFS_SB(sb); 234 if (nilfs->ns_writer) {
239 sci = NILFS_SC(sbi); 235 struct nilfs_sc_info *sci = nilfs->ns_writer;
240 if (sci != NULL) { 236
241 if (ti->ti_flags & NILFS_TI_COMMIT) 237 if (ti->ti_flags & NILFS_TI_COMMIT)
242 nilfs_segctor_start_timer(sci); 238 nilfs_segctor_start_timer(sci);
243 if (atomic_read(&sbi->s_nilfs->ns_ndirtyblks) > 239 if (atomic_read(&nilfs->ns_ndirtyblks) > sci->sc_watermark)
244 sci->sc_watermark)
245 nilfs_segctor_do_flush(sci, 0); 240 nilfs_segctor_do_flush(sci, 0);
246 } 241 }
247 up_read(&sbi->s_nilfs->ns_segctor_sem); 242 up_read(&nilfs->ns_segctor_sem);
248 current->journal_info = ti->ti_save; 243 current->journal_info = ti->ti_save;
249 244
250 if (ti->ti_flags & NILFS_TI_SYNC) 245 if (ti->ti_flags & NILFS_TI_SYNC)
@@ -257,13 +252,14 @@ int nilfs_transaction_commit(struct super_block *sb)
257void nilfs_transaction_abort(struct super_block *sb) 252void nilfs_transaction_abort(struct super_block *sb)
258{ 253{
259 struct nilfs_transaction_info *ti = current->journal_info; 254 struct nilfs_transaction_info *ti = current->journal_info;
255 struct the_nilfs *nilfs = sb->s_fs_info;
260 256
261 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 257 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC);
262 if (ti->ti_count > 0) { 258 if (ti->ti_count > 0) {
263 ti->ti_count--; 259 ti->ti_count--;
264 return; 260 return;
265 } 261 }
266 up_read(&NILFS_SB(sb)->s_nilfs->ns_segctor_sem); 262 up_read(&nilfs->ns_segctor_sem);
267 263
268 current->journal_info = ti->ti_save; 264 current->journal_info = ti->ti_save;
269 if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC) 265 if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC)
@@ -272,9 +268,8 @@ void nilfs_transaction_abort(struct super_block *sb)
272 268
273void nilfs_relax_pressure_in_lock(struct super_block *sb) 269void nilfs_relax_pressure_in_lock(struct super_block *sb)
274{ 270{
275 struct nilfs_sb_info *sbi = NILFS_SB(sb); 271 struct the_nilfs *nilfs = sb->s_fs_info;
276 struct nilfs_sc_info *sci = NILFS_SC(sbi); 272 struct nilfs_sc_info *sci = nilfs->ns_writer;
277 struct the_nilfs *nilfs = sbi->s_nilfs;
278 273
279 if (!sci || !sci->sc_flush_request) 274 if (!sci || !sci->sc_flush_request)
280 return; 275 return;
@@ -294,11 +289,13 @@ void nilfs_relax_pressure_in_lock(struct super_block *sb)
294 downgrade_write(&nilfs->ns_segctor_sem); 289 downgrade_write(&nilfs->ns_segctor_sem);
295} 290}
296 291
297static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, 292static void nilfs_transaction_lock(struct super_block *sb,
298 struct nilfs_transaction_info *ti, 293 struct nilfs_transaction_info *ti,
299 int gcflag) 294 int gcflag)
300{ 295{
301 struct nilfs_transaction_info *cur_ti = current->journal_info; 296 struct nilfs_transaction_info *cur_ti = current->journal_info;
297 struct the_nilfs *nilfs = sb->s_fs_info;
298 struct nilfs_sc_info *sci = nilfs->ns_writer;
302 299
303 WARN_ON(cur_ti); 300 WARN_ON(cur_ti);
304 ti->ti_flags = NILFS_TI_WRITER; 301 ti->ti_flags = NILFS_TI_WRITER;
@@ -309,30 +306,31 @@ static void nilfs_transaction_lock(struct nilfs_sb_info *sbi,
309 current->journal_info = ti; 306 current->journal_info = ti;
310 307
311 for (;;) { 308 for (;;) {
312 down_write(&sbi->s_nilfs->ns_segctor_sem); 309 down_write(&nilfs->ns_segctor_sem);
313 if (!test_bit(NILFS_SC_PRIOR_FLUSH, &NILFS_SC(sbi)->sc_flags)) 310 if (!test_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags))
314 break; 311 break;
315 312
316 nilfs_segctor_do_immediate_flush(NILFS_SC(sbi)); 313 nilfs_segctor_do_immediate_flush(sci);
317 314
318 up_write(&sbi->s_nilfs->ns_segctor_sem); 315 up_write(&nilfs->ns_segctor_sem);
319 yield(); 316 yield();
320 } 317 }
321 if (gcflag) 318 if (gcflag)
322 ti->ti_flags |= NILFS_TI_GC; 319 ti->ti_flags |= NILFS_TI_GC;
323} 320}
324 321
325static void nilfs_transaction_unlock(struct nilfs_sb_info *sbi) 322static void nilfs_transaction_unlock(struct super_block *sb)
326{ 323{
327 struct nilfs_transaction_info *ti = current->journal_info; 324 struct nilfs_transaction_info *ti = current->journal_info;
325 struct the_nilfs *nilfs = sb->s_fs_info;
328 326
329 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 327 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC);
330 BUG_ON(ti->ti_count > 0); 328 BUG_ON(ti->ti_count > 0);
331 329
332 up_write(&sbi->s_nilfs->ns_segctor_sem); 330 up_write(&nilfs->ns_segctor_sem);
333 current->journal_info = ti->ti_save; 331 current->journal_info = ti->ti_save;
334 if (!list_empty(&ti->ti_garbage)) 332 if (!list_empty(&ti->ti_garbage))
335 nilfs_dispose_list(sbi, &ti->ti_garbage, 0); 333 nilfs_dispose_list(nilfs, &ti->ti_garbage, 0);
336} 334}
337 335
338static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci, 336static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci,
@@ -714,7 +712,7 @@ static void nilfs_lookup_dirty_node_buffers(struct inode *inode,
714 } 712 }
715} 713}
716 714
717static void nilfs_dispose_list(struct nilfs_sb_info *sbi, 715static void nilfs_dispose_list(struct the_nilfs *nilfs,
718 struct list_head *head, int force) 716 struct list_head *head, int force)
719{ 717{
720 struct nilfs_inode_info *ii, *n; 718 struct nilfs_inode_info *ii, *n;
@@ -722,7 +720,7 @@ static void nilfs_dispose_list(struct nilfs_sb_info *sbi,
722 unsigned nv = 0; 720 unsigned nv = 0;
723 721
724 while (!list_empty(head)) { 722 while (!list_empty(head)) {
725 spin_lock(&sbi->s_inode_lock); 723 spin_lock(&nilfs->ns_inode_lock);
726 list_for_each_entry_safe(ii, n, head, i_dirty) { 724 list_for_each_entry_safe(ii, n, head, i_dirty) {
727 list_del_init(&ii->i_dirty); 725 list_del_init(&ii->i_dirty);
728 if (force) { 726 if (force) {
@@ -733,14 +731,14 @@ static void nilfs_dispose_list(struct nilfs_sb_info *sbi,
733 } else if (test_bit(NILFS_I_DIRTY, &ii->i_state)) { 731 } else if (test_bit(NILFS_I_DIRTY, &ii->i_state)) {
734 set_bit(NILFS_I_QUEUED, &ii->i_state); 732 set_bit(NILFS_I_QUEUED, &ii->i_state);
735 list_add_tail(&ii->i_dirty, 733 list_add_tail(&ii->i_dirty,
736 &sbi->s_dirty_files); 734 &nilfs->ns_dirty_files);
737 continue; 735 continue;
738 } 736 }
739 ivec[nv++] = ii; 737 ivec[nv++] = ii;
740 if (nv == SC_N_INODEVEC) 738 if (nv == SC_N_INODEVEC)
741 break; 739 break;
742 } 740 }
743 spin_unlock(&sbi->s_inode_lock); 741 spin_unlock(&nilfs->ns_inode_lock);
744 742
745 for (pii = ivec; nv > 0; pii++, nv--) 743 for (pii = ivec; nv > 0; pii++, nv--)
746 iput(&(*pii)->vfs_inode); 744 iput(&(*pii)->vfs_inode);
@@ -773,24 +771,23 @@ static int nilfs_segctor_clean(struct nilfs_sc_info *sci)
773 771
774static int nilfs_segctor_confirm(struct nilfs_sc_info *sci) 772static int nilfs_segctor_confirm(struct nilfs_sc_info *sci)
775{ 773{
776 struct nilfs_sb_info *sbi = sci->sc_sbi; 774 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
777 int ret = 0; 775 int ret = 0;
778 776
779 if (nilfs_test_metadata_dirty(sbi->s_nilfs, sci->sc_root)) 777 if (nilfs_test_metadata_dirty(nilfs, sci->sc_root))
780 set_bit(NILFS_SC_DIRTY, &sci->sc_flags); 778 set_bit(NILFS_SC_DIRTY, &sci->sc_flags);
781 779
782 spin_lock(&sbi->s_inode_lock); 780 spin_lock(&nilfs->ns_inode_lock);
783 if (list_empty(&sbi->s_dirty_files) && nilfs_segctor_clean(sci)) 781 if (list_empty(&nilfs->ns_dirty_files) && nilfs_segctor_clean(sci))
784 ret++; 782 ret++;
785 783
786 spin_unlock(&sbi->s_inode_lock); 784 spin_unlock(&nilfs->ns_inode_lock);
787 return ret; 785 return ret;
788} 786}
789 787
790static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci) 788static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci)
791{ 789{
792 struct nilfs_sb_info *sbi = sci->sc_sbi; 790 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
793 struct the_nilfs *nilfs = sbi->s_nilfs;
794 791
795 nilfs_mdt_clear_dirty(sci->sc_root->ifile); 792 nilfs_mdt_clear_dirty(sci->sc_root->ifile);
796 nilfs_mdt_clear_dirty(nilfs->ns_cpfile); 793 nilfs_mdt_clear_dirty(nilfs->ns_cpfile);
@@ -800,7 +797,7 @@ static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci)
800 797
801static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) 798static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci)
802{ 799{
803 struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; 800 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
804 struct buffer_head *bh_cp; 801 struct buffer_head *bh_cp;
805 struct nilfs_checkpoint *raw_cp; 802 struct nilfs_checkpoint *raw_cp;
806 int err; 803 int err;
@@ -824,8 +821,7 @@ static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci)
824 821
825static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) 822static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci)
826{ 823{
827 struct nilfs_sb_info *sbi = sci->sc_sbi; 824 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
828 struct the_nilfs *nilfs = sbi->s_nilfs;
829 struct buffer_head *bh_cp; 825 struct buffer_head *bh_cp;
830 struct nilfs_checkpoint *raw_cp; 826 struct nilfs_checkpoint *raw_cp;
831 int err; 827 int err;
@@ -1049,8 +1045,7 @@ static int nilfs_segctor_scan_file_dsync(struct nilfs_sc_info *sci,
1049 1045
1050static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) 1046static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode)
1051{ 1047{
1052 struct nilfs_sb_info *sbi = sci->sc_sbi; 1048 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
1053 struct the_nilfs *nilfs = sbi->s_nilfs;
1054 struct list_head *head; 1049 struct list_head *head;
1055 struct nilfs_inode_info *ii; 1050 struct nilfs_inode_info *ii;
1056 size_t ndone; 1051 size_t ndone;
@@ -1859,7 +1854,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci)
1859{ 1854{
1860 struct nilfs_segment_buffer *segbuf; 1855 struct nilfs_segment_buffer *segbuf;
1861 struct page *bd_page = NULL, *fs_page = NULL; 1856 struct page *bd_page = NULL, *fs_page = NULL;
1862 struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; 1857 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
1863 int update_sr = false; 1858 int update_sr = false;
1864 1859
1865 list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { 1860 list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) {
@@ -1963,30 +1958,30 @@ static int nilfs_segctor_wait(struct nilfs_sc_info *sci)
1963 return ret; 1958 return ret;
1964} 1959}
1965 1960
1966static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, 1961static int nilfs_segctor_collect_dirty_files(struct nilfs_sc_info *sci,
1967 struct nilfs_sb_info *sbi) 1962 struct the_nilfs *nilfs)
1968{ 1963{
1969 struct nilfs_inode_info *ii, *n; 1964 struct nilfs_inode_info *ii, *n;
1970 struct inode *ifile = sci->sc_root->ifile; 1965 struct inode *ifile = sci->sc_root->ifile;
1971 1966
1972 spin_lock(&sbi->s_inode_lock); 1967 spin_lock(&nilfs->ns_inode_lock);
1973 retry: 1968 retry:
1974 list_for_each_entry_safe(ii, n, &sbi->s_dirty_files, i_dirty) { 1969 list_for_each_entry_safe(ii, n, &nilfs->ns_dirty_files, i_dirty) {
1975 if (!ii->i_bh) { 1970 if (!ii->i_bh) {
1976 struct buffer_head *ibh; 1971 struct buffer_head *ibh;
1977 int err; 1972 int err;
1978 1973
1979 spin_unlock(&sbi->s_inode_lock); 1974 spin_unlock(&nilfs->ns_inode_lock);
1980 err = nilfs_ifile_get_inode_block( 1975 err = nilfs_ifile_get_inode_block(
1981 ifile, ii->vfs_inode.i_ino, &ibh); 1976 ifile, ii->vfs_inode.i_ino, &ibh);
1982 if (unlikely(err)) { 1977 if (unlikely(err)) {
1983 nilfs_warning(sbi->s_super, __func__, 1978 nilfs_warning(sci->sc_super, __func__,
1984 "failed to get inode block.\n"); 1979 "failed to get inode block.\n");
1985 return err; 1980 return err;
1986 } 1981 }
1987 nilfs_mdt_mark_buffer_dirty(ibh); 1982 nilfs_mdt_mark_buffer_dirty(ibh);
1988 nilfs_mdt_mark_dirty(ifile); 1983 nilfs_mdt_mark_dirty(ifile);
1989 spin_lock(&sbi->s_inode_lock); 1984 spin_lock(&nilfs->ns_inode_lock);
1990 if (likely(!ii->i_bh)) 1985 if (likely(!ii->i_bh))
1991 ii->i_bh = ibh; 1986 ii->i_bh = ibh;
1992 else 1987 else
@@ -1999,18 +1994,18 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci,
1999 list_del(&ii->i_dirty); 1994 list_del(&ii->i_dirty);
2000 list_add_tail(&ii->i_dirty, &sci->sc_dirty_files); 1995 list_add_tail(&ii->i_dirty, &sci->sc_dirty_files);
2001 } 1996 }
2002 spin_unlock(&sbi->s_inode_lock); 1997 spin_unlock(&nilfs->ns_inode_lock);
2003 1998
2004 return 0; 1999 return 0;
2005} 2000}
2006 2001
2007static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci, 2002static void nilfs_segctor_drop_written_files(struct nilfs_sc_info *sci,
2008 struct nilfs_sb_info *sbi) 2003 struct the_nilfs *nilfs)
2009{ 2004{
2010 struct nilfs_transaction_info *ti = current->journal_info; 2005 struct nilfs_transaction_info *ti = current->journal_info;
2011 struct nilfs_inode_info *ii, *n; 2006 struct nilfs_inode_info *ii, *n;
2012 2007
2013 spin_lock(&sbi->s_inode_lock); 2008 spin_lock(&nilfs->ns_inode_lock);
2014 list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { 2009 list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) {
2015 if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) || 2010 if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) ||
2016 test_bit(NILFS_I_DIRTY, &ii->i_state)) 2011 test_bit(NILFS_I_DIRTY, &ii->i_state))
@@ -2022,7 +2017,7 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci,
2022 list_del(&ii->i_dirty); 2017 list_del(&ii->i_dirty);
2023 list_add_tail(&ii->i_dirty, &ti->ti_garbage); 2018 list_add_tail(&ii->i_dirty, &ti->ti_garbage);
2024 } 2019 }
2025 spin_unlock(&sbi->s_inode_lock); 2020 spin_unlock(&nilfs->ns_inode_lock);
2026} 2021}
2027 2022
2028/* 2023/*
@@ -2030,15 +2025,14 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci,
2030 */ 2025 */
2031static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) 2026static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2032{ 2027{
2033 struct nilfs_sb_info *sbi = sci->sc_sbi; 2028 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
2034 struct the_nilfs *nilfs = sbi->s_nilfs;
2035 struct page *failed_page; 2029 struct page *failed_page;
2036 int err; 2030 int err;
2037 2031
2038 sci->sc_stage.scnt = NILFS_ST_INIT; 2032 sci->sc_stage.scnt = NILFS_ST_INIT;
2039 sci->sc_cno = nilfs->ns_cno; 2033 sci->sc_cno = nilfs->ns_cno;
2040 2034
2041 err = nilfs_segctor_check_in_files(sci, sbi); 2035 err = nilfs_segctor_collect_dirty_files(sci, nilfs);
2042 if (unlikely(err)) 2036 if (unlikely(err))
2043 goto out; 2037 goto out;
2044 2038
@@ -2116,7 +2110,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2116 } while (sci->sc_stage.scnt != NILFS_ST_DONE); 2110 } while (sci->sc_stage.scnt != NILFS_ST_DONE);
2117 2111
2118 out: 2112 out:
2119 nilfs_segctor_check_out_files(sci, sbi); 2113 nilfs_segctor_drop_written_files(sci, nilfs);
2120 return err; 2114 return err;
2121 2115
2122 failed_to_write: 2116 failed_to_write:
@@ -2169,8 +2163,8 @@ static void nilfs_segctor_do_flush(struct nilfs_sc_info *sci, int bn)
2169 */ 2163 */
2170void nilfs_flush_segment(struct super_block *sb, ino_t ino) 2164void nilfs_flush_segment(struct super_block *sb, ino_t ino)
2171{ 2165{
2172 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2166 struct the_nilfs *nilfs = sb->s_fs_info;
2173 struct nilfs_sc_info *sci = NILFS_SC(sbi); 2167 struct nilfs_sc_info *sci = nilfs->ns_writer;
2174 2168
2175 if (!sci || nilfs_doing_construction()) 2169 if (!sci || nilfs_doing_construction())
2176 return; 2170 return;
@@ -2259,8 +2253,8 @@ static void nilfs_segctor_wakeup(struct nilfs_sc_info *sci, int err)
2259 */ 2253 */
2260int nilfs_construct_segment(struct super_block *sb) 2254int nilfs_construct_segment(struct super_block *sb)
2261{ 2255{
2262 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2256 struct the_nilfs *nilfs = sb->s_fs_info;
2263 struct nilfs_sc_info *sci = NILFS_SC(sbi); 2257 struct nilfs_sc_info *sci = nilfs->ns_writer;
2264 struct nilfs_transaction_info *ti; 2258 struct nilfs_transaction_info *ti;
2265 int err; 2259 int err;
2266 2260
@@ -2297,8 +2291,8 @@ int nilfs_construct_segment(struct super_block *sb)
2297int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, 2291int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2298 loff_t start, loff_t end) 2292 loff_t start, loff_t end)
2299{ 2293{
2300 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2294 struct the_nilfs *nilfs = sb->s_fs_info;
2301 struct nilfs_sc_info *sci = NILFS_SC(sbi); 2295 struct nilfs_sc_info *sci = nilfs->ns_writer;
2302 struct nilfs_inode_info *ii; 2296 struct nilfs_inode_info *ii;
2303 struct nilfs_transaction_info ti; 2297 struct nilfs_transaction_info ti;
2304 int err = 0; 2298 int err = 0;
@@ -2306,33 +2300,33 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2306 if (!sci) 2300 if (!sci)
2307 return -EROFS; 2301 return -EROFS;
2308 2302
2309 nilfs_transaction_lock(sbi, &ti, 0); 2303 nilfs_transaction_lock(sb, &ti, 0);
2310 2304
2311 ii = NILFS_I(inode); 2305 ii = NILFS_I(inode);
2312 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) || 2306 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) ||
2313 nilfs_test_opt(sbi, STRICT_ORDER) || 2307 nilfs_test_opt(nilfs, STRICT_ORDER) ||
2314 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || 2308 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) ||
2315 nilfs_discontinued(sbi->s_nilfs)) { 2309 nilfs_discontinued(nilfs)) {
2316 nilfs_transaction_unlock(sbi); 2310 nilfs_transaction_unlock(sb);
2317 err = nilfs_segctor_sync(sci); 2311 err = nilfs_segctor_sync(sci);
2318 return err; 2312 return err;
2319 } 2313 }
2320 2314
2321 spin_lock(&sbi->s_inode_lock); 2315 spin_lock(&nilfs->ns_inode_lock);
2322 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && 2316 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
2323 !test_bit(NILFS_I_BUSY, &ii->i_state)) { 2317 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
2324 spin_unlock(&sbi->s_inode_lock); 2318 spin_unlock(&nilfs->ns_inode_lock);
2325 nilfs_transaction_unlock(sbi); 2319 nilfs_transaction_unlock(sb);
2326 return 0; 2320 return 0;
2327 } 2321 }
2328 spin_unlock(&sbi->s_inode_lock); 2322 spin_unlock(&nilfs->ns_inode_lock);
2329 sci->sc_dsync_inode = ii; 2323 sci->sc_dsync_inode = ii;
2330 sci->sc_dsync_start = start; 2324 sci->sc_dsync_start = start;
2331 sci->sc_dsync_end = end; 2325 sci->sc_dsync_end = end;
2332 2326
2333 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); 2327 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC);
2334 2328
2335 nilfs_transaction_unlock(sbi); 2329 nilfs_transaction_unlock(sb);
2336 return err; 2330 return err;
2337} 2331}
2338 2332
@@ -2388,8 +2382,7 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err)
2388 */ 2382 */
2389static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) 2383static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2390{ 2384{
2391 struct nilfs_sb_info *sbi = sci->sc_sbi; 2385 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
2392 struct the_nilfs *nilfs = sbi->s_nilfs;
2393 struct nilfs_super_block **sbp; 2386 struct nilfs_super_block **sbp;
2394 int err = 0; 2387 int err = 0;
2395 2388
@@ -2407,11 +2400,12 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2407 nilfs_discontinued(nilfs)) { 2400 nilfs_discontinued(nilfs)) {
2408 down_write(&nilfs->ns_sem); 2401 down_write(&nilfs->ns_sem);
2409 err = -EIO; 2402 err = -EIO;
2410 sbp = nilfs_prepare_super(sbi, 2403 sbp = nilfs_prepare_super(sci->sc_super,
2411 nilfs_sb_will_flip(nilfs)); 2404 nilfs_sb_will_flip(nilfs));
2412 if (likely(sbp)) { 2405 if (likely(sbp)) {
2413 nilfs_set_log_cursor(sbp[0], nilfs); 2406 nilfs_set_log_cursor(sbp[0], nilfs);
2414 err = nilfs_commit_super(sbi, NILFS_SB_COMMIT); 2407 err = nilfs_commit_super(sci->sc_super,
2408 NILFS_SB_COMMIT);
2415 } 2409 }
2416 up_write(&nilfs->ns_sem); 2410 up_write(&nilfs->ns_sem);
2417 } 2411 }
@@ -2443,16 +2437,15 @@ nilfs_remove_written_gcinodes(struct the_nilfs *nilfs, struct list_head *head)
2443int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, 2437int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2444 void **kbufs) 2438 void **kbufs)
2445{ 2439{
2446 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2440 struct the_nilfs *nilfs = sb->s_fs_info;
2447 struct nilfs_sc_info *sci = NILFS_SC(sbi); 2441 struct nilfs_sc_info *sci = nilfs->ns_writer;
2448 struct the_nilfs *nilfs = sbi->s_nilfs;
2449 struct nilfs_transaction_info ti; 2442 struct nilfs_transaction_info ti;
2450 int err; 2443 int err;
2451 2444
2452 if (unlikely(!sci)) 2445 if (unlikely(!sci))
2453 return -EROFS; 2446 return -EROFS;
2454 2447
2455 nilfs_transaction_lock(sbi, &ti, 1); 2448 nilfs_transaction_lock(sb, &ti, 1);
2456 2449
2457 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); 2450 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat);
2458 if (unlikely(err)) 2451 if (unlikely(err))
@@ -2480,14 +2473,14 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2480 set_current_state(TASK_INTERRUPTIBLE); 2473 set_current_state(TASK_INTERRUPTIBLE);
2481 schedule_timeout(sci->sc_interval); 2474 schedule_timeout(sci->sc_interval);
2482 } 2475 }
2483 if (nilfs_test_opt(sbi, DISCARD)) { 2476 if (nilfs_test_opt(nilfs, DISCARD)) {
2484 int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs, 2477 int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs,
2485 sci->sc_nfreesegs); 2478 sci->sc_nfreesegs);
2486 if (ret) { 2479 if (ret) {
2487 printk(KERN_WARNING 2480 printk(KERN_WARNING
2488 "NILFS warning: error %d on discard request, " 2481 "NILFS warning: error %d on discard request, "
2489 "turning discards off for the device\n", ret); 2482 "turning discards off for the device\n", ret);
2490 nilfs_clear_opt(sbi, DISCARD); 2483 nilfs_clear_opt(nilfs, DISCARD);
2491 } 2484 }
2492 } 2485 }
2493 2486
@@ -2495,16 +2488,15 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2495 sci->sc_freesegs = NULL; 2488 sci->sc_freesegs = NULL;
2496 sci->sc_nfreesegs = 0; 2489 sci->sc_nfreesegs = 0;
2497 nilfs_mdt_clear_shadow_map(nilfs->ns_dat); 2490 nilfs_mdt_clear_shadow_map(nilfs->ns_dat);
2498 nilfs_transaction_unlock(sbi); 2491 nilfs_transaction_unlock(sb);
2499 return err; 2492 return err;
2500} 2493}
2501 2494
2502static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) 2495static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2503{ 2496{
2504 struct nilfs_sb_info *sbi = sci->sc_sbi;
2505 struct nilfs_transaction_info ti; 2497 struct nilfs_transaction_info ti;
2506 2498
2507 nilfs_transaction_lock(sbi, &ti, 0); 2499 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2508 nilfs_segctor_construct(sci, mode); 2500 nilfs_segctor_construct(sci, mode);
2509 2501
2510 /* 2502 /*
@@ -2515,7 +2507,7 @@ static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2515 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) 2507 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags))
2516 nilfs_segctor_start_timer(sci); 2508 nilfs_segctor_start_timer(sci);
2517 2509
2518 nilfs_transaction_unlock(sbi); 2510 nilfs_transaction_unlock(sci->sc_super);
2519} 2511}
2520 2512
2521static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) 2513static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci)
@@ -2561,7 +2553,7 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc_info *sci)
2561static int nilfs_segctor_thread(void *arg) 2553static int nilfs_segctor_thread(void *arg)
2562{ 2554{
2563 struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; 2555 struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg;
2564 struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; 2556 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
2565 int timeout = 0; 2557 int timeout = 0;
2566 2558
2567 sci->sc_timer.data = (unsigned long)current; 2559 sci->sc_timer.data = (unsigned long)current;
@@ -2672,17 +2664,17 @@ static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci)
2672/* 2664/*
2673 * Setup & clean-up functions 2665 * Setup & clean-up functions
2674 */ 2666 */
2675static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, 2667static struct nilfs_sc_info *nilfs_segctor_new(struct super_block *sb,
2676 struct nilfs_root *root) 2668 struct nilfs_root *root)
2677{ 2669{
2670 struct the_nilfs *nilfs = sb->s_fs_info;
2678 struct nilfs_sc_info *sci; 2671 struct nilfs_sc_info *sci;
2679 2672
2680 sci = kzalloc(sizeof(*sci), GFP_KERNEL); 2673 sci = kzalloc(sizeof(*sci), GFP_KERNEL);
2681 if (!sci) 2674 if (!sci)
2682 return NULL; 2675 return NULL;
2683 2676
2684 sci->sc_sbi = sbi; 2677 sci->sc_super = sb;
2685 sci->sc_super = sbi->s_super;
2686 2678
2687 nilfs_get_root(root); 2679 nilfs_get_root(root);
2688 sci->sc_root = root; 2680 sci->sc_root = root;
@@ -2702,10 +2694,10 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi,
2702 sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ; 2694 sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ;
2703 sci->sc_watermark = NILFS_SC_DEFAULT_WATERMARK; 2695 sci->sc_watermark = NILFS_SC_DEFAULT_WATERMARK;
2704 2696
2705 if (sbi->s_interval) 2697 if (nilfs->ns_interval)
2706 sci->sc_interval = sbi->s_interval; 2698 sci->sc_interval = nilfs->ns_interval;
2707 if (sbi->s_watermark) 2699 if (nilfs->ns_watermark)
2708 sci->sc_watermark = sbi->s_watermark; 2700 sci->sc_watermark = nilfs->ns_watermark;
2709 return sci; 2701 return sci;
2710} 2702}
2711 2703
@@ -2716,12 +2708,11 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci)
2716 /* The segctord thread was stopped and its timer was removed. 2708 /* The segctord thread was stopped and its timer was removed.
2717 But some tasks remain. */ 2709 But some tasks remain. */
2718 do { 2710 do {
2719 struct nilfs_sb_info *sbi = sci->sc_sbi;
2720 struct nilfs_transaction_info ti; 2711 struct nilfs_transaction_info ti;
2721 2712
2722 nilfs_transaction_lock(sbi, &ti, 0); 2713 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2723 ret = nilfs_segctor_construct(sci, SC_LSEG_SR); 2714 ret = nilfs_segctor_construct(sci, SC_LSEG_SR);
2724 nilfs_transaction_unlock(sbi); 2715 nilfs_transaction_unlock(sci->sc_super);
2725 2716
2726 } while (ret && retrycount-- > 0); 2717 } while (ret && retrycount-- > 0);
2727} 2718}
@@ -2736,10 +2727,10 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci)
2736 */ 2727 */
2737static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) 2728static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)
2738{ 2729{
2739 struct nilfs_sb_info *sbi = sci->sc_sbi; 2730 struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
2740 int flag; 2731 int flag;
2741 2732
2742 up_write(&sbi->s_nilfs->ns_segctor_sem); 2733 up_write(&nilfs->ns_segctor_sem);
2743 2734
2744 spin_lock(&sci->sc_state_lock); 2735 spin_lock(&sci->sc_state_lock);
2745 nilfs_segctor_kill_thread(sci); 2736 nilfs_segctor_kill_thread(sci);
@@ -2753,9 +2744,9 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)
2753 WARN_ON(!list_empty(&sci->sc_copied_buffers)); 2744 WARN_ON(!list_empty(&sci->sc_copied_buffers));
2754 2745
2755 if (!list_empty(&sci->sc_dirty_files)) { 2746 if (!list_empty(&sci->sc_dirty_files)) {
2756 nilfs_warning(sbi->s_super, __func__, 2747 nilfs_warning(sci->sc_super, __func__,
2757 "dirty file(s) after the final construction\n"); 2748 "dirty file(s) after the final construction\n");
2758 nilfs_dispose_list(sbi, &sci->sc_dirty_files, 1); 2749 nilfs_dispose_list(nilfs, &sci->sc_dirty_files, 1);
2759 } 2750 }
2760 2751
2761 WARN_ON(!list_empty(&sci->sc_segbufs)); 2752 WARN_ON(!list_empty(&sci->sc_segbufs));
@@ -2763,79 +2754,78 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)
2763 2754
2764 nilfs_put_root(sci->sc_root); 2755 nilfs_put_root(sci->sc_root);
2765 2756
2766 down_write(&sbi->s_nilfs->ns_segctor_sem); 2757 down_write(&nilfs->ns_segctor_sem);
2767 2758
2768 del_timer_sync(&sci->sc_timer); 2759 del_timer_sync(&sci->sc_timer);
2769 kfree(sci); 2760 kfree(sci);
2770} 2761}
2771 2762
2772/** 2763/**
2773 * nilfs_attach_segment_constructor - attach a segment constructor 2764 * nilfs_attach_log_writer - attach log writer
2774 * @sbi: nilfs_sb_info 2765 * @sb: super block instance
2775 * @root: root object of the current filesystem tree 2766 * @root: root object of the current filesystem tree
2776 * 2767 *
2777 * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, 2768 * This allocates a log writer object, initializes it, and starts the
2778 * initializes it, and starts the segment constructor. 2769 * log writer.
2779 * 2770 *
2780 * Return Value: On success, 0 is returned. On error, one of the following 2771 * Return Value: On success, 0 is returned. On error, one of the following
2781 * negative error code is returned. 2772 * negative error code is returned.
2782 * 2773 *
2783 * %-ENOMEM - Insufficient memory available. 2774 * %-ENOMEM - Insufficient memory available.
2784 */ 2775 */
2785int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 2776int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root)
2786 struct nilfs_root *root)
2787{ 2777{
2778 struct the_nilfs *nilfs = sb->s_fs_info;
2788 int err; 2779 int err;
2789 2780
2790 if (NILFS_SC(sbi)) { 2781 if (nilfs->ns_writer) {
2791 /* 2782 /*
2792 * This happens if the filesystem was remounted 2783 * This happens if the filesystem was remounted
2793 * read/write after nilfs_error degenerated it into a 2784 * read/write after nilfs_error degenerated it into a
2794 * read-only mount. 2785 * read-only mount.
2795 */ 2786 */
2796 nilfs_detach_segment_constructor(sbi); 2787 nilfs_detach_log_writer(sb);
2797 } 2788 }
2798 2789
2799 sbi->s_sc_info = nilfs_segctor_new(sbi, root); 2790 nilfs->ns_writer = nilfs_segctor_new(sb, root);
2800 if (!sbi->s_sc_info) 2791 if (!nilfs->ns_writer)
2801 return -ENOMEM; 2792 return -ENOMEM;
2802 2793
2803 err = nilfs_segctor_start_thread(NILFS_SC(sbi)); 2794 err = nilfs_segctor_start_thread(nilfs->ns_writer);
2804 if (err) { 2795 if (err) {
2805 kfree(sbi->s_sc_info); 2796 kfree(nilfs->ns_writer);
2806 sbi->s_sc_info = NULL; 2797 nilfs->ns_writer = NULL;
2807 } 2798 }
2808 return err; 2799 return err;
2809} 2800}
2810 2801
2811/** 2802/**
2812 * nilfs_detach_segment_constructor - destroy the segment constructor 2803 * nilfs_detach_log_writer - destroy log writer
2813 * @sbi: nilfs_sb_info 2804 * @sb: super block instance
2814 * 2805 *
2815 * nilfs_detach_segment_constructor() kills the segment constructor daemon, 2806 * This kills log writer daemon, frees the log writer object, and
2816 * frees the struct nilfs_sc_info, and destroy the dirty file list. 2807 * destroys list of dirty files.
2817 */ 2808 */
2818void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi) 2809void nilfs_detach_log_writer(struct super_block *sb)
2819{ 2810{
2820 struct the_nilfs *nilfs = sbi->s_nilfs; 2811 struct the_nilfs *nilfs = sb->s_fs_info;
2821 LIST_HEAD(garbage_list); 2812 LIST_HEAD(garbage_list);
2822 2813
2823 down_write(&nilfs->ns_segctor_sem); 2814 down_write(&nilfs->ns_segctor_sem);
2824 if (NILFS_SC(sbi)) { 2815 if (nilfs->ns_writer) {
2825 nilfs_segctor_destroy(NILFS_SC(sbi)); 2816 nilfs_segctor_destroy(nilfs->ns_writer);
2826 sbi->s_sc_info = NULL; 2817 nilfs->ns_writer = NULL;
2827 } 2818 }
2828 2819
2829 /* Force to free the list of dirty files */ 2820 /* Force to free the list of dirty files */
2830 spin_lock(&sbi->s_inode_lock); 2821 spin_lock(&nilfs->ns_inode_lock);
2831 if (!list_empty(&sbi->s_dirty_files)) { 2822 if (!list_empty(&nilfs->ns_dirty_files)) {
2832 list_splice_init(&sbi->s_dirty_files, &garbage_list); 2823 list_splice_init(&nilfs->ns_dirty_files, &garbage_list);
2833 nilfs_warning(sbi->s_super, __func__, 2824 nilfs_warning(sb, __func__,
2834 "Non empty dirty list after the last " 2825 "Hit dirty file after stopped log writer\n");
2835 "segment construction\n"); 2826 }
2836 } 2827 spin_unlock(&nilfs->ns_inode_lock);
2837 spin_unlock(&sbi->s_inode_lock);
2838 up_write(&nilfs->ns_segctor_sem); 2828 up_write(&nilfs->ns_segctor_sem);
2839 2829
2840 nilfs_dispose_list(sbi, &garbage_list, 1); 2830 nilfs_dispose_list(nilfs, &garbage_list, 1);
2841} 2831}
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index cd8056e7cbed..6c02a86745fb 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -27,7 +27,7 @@
27#include <linux/fs.h> 27#include <linux/fs.h>
28#include <linux/buffer_head.h> 28#include <linux/buffer_head.h>
29#include <linux/nilfs2_fs.h> 29#include <linux/nilfs2_fs.h>
30#include "sb.h" 30#include "nilfs.h"
31 31
32struct nilfs_root; 32struct nilfs_root;
33 33
@@ -88,7 +88,6 @@ struct nilfs_segsum_pointer {
88/** 88/**
89 * struct nilfs_sc_info - Segment constructor information 89 * struct nilfs_sc_info - Segment constructor information
90 * @sc_super: Back pointer to super_block struct 90 * @sc_super: Back pointer to super_block struct
91 * @sc_sbi: Back pointer to nilfs_sb_info struct
92 * @sc_root: root object of the current filesystem tree 91 * @sc_root: root object of the current filesystem tree
93 * @sc_nblk_inc: Block count of current generation 92 * @sc_nblk_inc: Block count of current generation
94 * @sc_dirty_files: List of files to be written 93 * @sc_dirty_files: List of files to be written
@@ -131,7 +130,6 @@ struct nilfs_segsum_pointer {
131 */ 130 */
132struct nilfs_sc_info { 131struct nilfs_sc_info {
133 struct super_block *sc_super; 132 struct super_block *sc_super;
134 struct nilfs_sb_info *sc_sbi;
135 struct nilfs_root *sc_root; 133 struct nilfs_root *sc_root;
136 134
137 unsigned long sc_nblk_inc; 135 unsigned long sc_nblk_inc;
@@ -235,18 +233,16 @@ extern void nilfs_flush_segment(struct super_block *, ino_t);
235extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *, 233extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
236 void **); 234 void **);
237 235
238int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 236int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
239 struct nilfs_root *root); 237void nilfs_detach_log_writer(struct super_block *sb);
240extern void nilfs_detach_segment_constructor(struct nilfs_sb_info *);
241 238
242/* recovery.c */ 239/* recovery.c */
243extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t, 240extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
244 struct buffer_head **, int); 241 struct buffer_head **, int);
245extern int nilfs_search_super_root(struct the_nilfs *, 242extern int nilfs_search_super_root(struct the_nilfs *,
246 struct nilfs_recovery_info *); 243 struct nilfs_recovery_info *);
247extern int nilfs_salvage_orphan_logs(struct the_nilfs *, 244int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
248 struct nilfs_sb_info *, 245 struct nilfs_recovery_info *ri);
249 struct nilfs_recovery_info *);
250extern void nilfs_dispose_segment_list(struct list_head *); 246extern void nilfs_dispose_segment_list(struct list_head *);
251 247
252#endif /* _NILFS_SEGMENT_H */ 248#endif /* _NILFS_SEGMENT_H */
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 1673b3d99842..062cca065195 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -43,7 +43,6 @@
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/blkdev.h> 44#include <linux/blkdev.h>
45#include <linux/parser.h> 45#include <linux/parser.h>
46#include <linux/random.h>
47#include <linux/crc32.h> 46#include <linux/crc32.h>
48#include <linux/vfs.h> 47#include <linux/vfs.h>
49#include <linux/writeback.h> 48#include <linux/writeback.h>
@@ -72,23 +71,23 @@ struct kmem_cache *nilfs_transaction_cachep;
72struct kmem_cache *nilfs_segbuf_cachep; 71struct kmem_cache *nilfs_segbuf_cachep;
73struct kmem_cache *nilfs_btree_path_cache; 72struct kmem_cache *nilfs_btree_path_cache;
74 73
75static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount); 74static int nilfs_setup_super(struct super_block *sb, int is_mount);
76static int nilfs_remount(struct super_block *sb, int *flags, char *data); 75static int nilfs_remount(struct super_block *sb, int *flags, char *data);
77 76
78static void nilfs_set_error(struct nilfs_sb_info *sbi) 77static void nilfs_set_error(struct super_block *sb)
79{ 78{
80 struct the_nilfs *nilfs = sbi->s_nilfs; 79 struct the_nilfs *nilfs = sb->s_fs_info;
81 struct nilfs_super_block **sbp; 80 struct nilfs_super_block **sbp;
82 81
83 down_write(&nilfs->ns_sem); 82 down_write(&nilfs->ns_sem);
84 if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { 83 if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) {
85 nilfs->ns_mount_state |= NILFS_ERROR_FS; 84 nilfs->ns_mount_state |= NILFS_ERROR_FS;
86 sbp = nilfs_prepare_super(sbi, 0); 85 sbp = nilfs_prepare_super(sb, 0);
87 if (likely(sbp)) { 86 if (likely(sbp)) {
88 sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS); 87 sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
89 if (sbp[1]) 88 if (sbp[1])
90 sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS); 89 sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
91 nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); 90 nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
92 } 91 }
93 } 92 }
94 up_write(&nilfs->ns_sem); 93 up_write(&nilfs->ns_sem);
@@ -109,7 +108,7 @@ static void nilfs_set_error(struct nilfs_sb_info *sbi)
109void nilfs_error(struct super_block *sb, const char *function, 108void nilfs_error(struct super_block *sb, const char *function,
110 const char *fmt, ...) 109 const char *fmt, ...)
111{ 110{
112 struct nilfs_sb_info *sbi = NILFS_SB(sb); 111 struct the_nilfs *nilfs = sb->s_fs_info;
113 struct va_format vaf; 112 struct va_format vaf;
114 va_list args; 113 va_list args;
115 114
@@ -124,15 +123,15 @@ void nilfs_error(struct super_block *sb, const char *function,
124 va_end(args); 123 va_end(args);
125 124
126 if (!(sb->s_flags & MS_RDONLY)) { 125 if (!(sb->s_flags & MS_RDONLY)) {
127 nilfs_set_error(sbi); 126 nilfs_set_error(sb);
128 127
129 if (nilfs_test_opt(sbi, ERRORS_RO)) { 128 if (nilfs_test_opt(nilfs, ERRORS_RO)) {
130 printk(KERN_CRIT "Remounting filesystem read-only\n"); 129 printk(KERN_CRIT "Remounting filesystem read-only\n");
131 sb->s_flags |= MS_RDONLY; 130 sb->s_flags |= MS_RDONLY;
132 } 131 }
133 } 132 }
134 133
135 if (nilfs_test_opt(sbi, ERRORS_PANIC)) 134 if (nilfs_test_opt(nilfs, ERRORS_PANIC))
136 panic("NILFS (device %s): panic forced after error\n", 135 panic("NILFS (device %s): panic forced after error\n",
137 sb->s_id); 136 sb->s_id);
138} 137}
@@ -189,14 +188,14 @@ void nilfs_destroy_inode(struct inode *inode)
189 call_rcu(&inode->i_rcu, nilfs_i_callback); 188 call_rcu(&inode->i_rcu, nilfs_i_callback);
190} 189}
191 190
192static int nilfs_sync_super(struct nilfs_sb_info *sbi, int flag) 191static int nilfs_sync_super(struct super_block *sb, int flag)
193{ 192{
194 struct the_nilfs *nilfs = sbi->s_nilfs; 193 struct the_nilfs *nilfs = sb->s_fs_info;
195 int err; 194 int err;
196 195
197 retry: 196 retry:
198 set_buffer_dirty(nilfs->ns_sbh[0]); 197 set_buffer_dirty(nilfs->ns_sbh[0]);
199 if (nilfs_test_opt(sbi, BARRIER)) { 198 if (nilfs_test_opt(nilfs, BARRIER)) {
200 err = __sync_dirty_buffer(nilfs->ns_sbh[0], 199 err = __sync_dirty_buffer(nilfs->ns_sbh[0],
201 WRITE_SYNC | WRITE_FLUSH_FUA); 200 WRITE_SYNC | WRITE_FLUSH_FUA);
202 } else { 201 } else {
@@ -263,10 +262,10 @@ void nilfs_set_log_cursor(struct nilfs_super_block *sbp,
263 spin_unlock(&nilfs->ns_last_segment_lock); 262 spin_unlock(&nilfs->ns_last_segment_lock);
264} 263}
265 264
266struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi, 265struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
267 int flip) 266 int flip)
268{ 267{
269 struct the_nilfs *nilfs = sbi->s_nilfs; 268 struct the_nilfs *nilfs = sb->s_fs_info;
270 struct nilfs_super_block **sbp = nilfs->ns_sbp; 269 struct nilfs_super_block **sbp = nilfs->ns_sbp;
271 270
272 /* nilfs->ns_sem must be locked by the caller. */ 271 /* nilfs->ns_sem must be locked by the caller. */
@@ -276,7 +275,7 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi,
276 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); 275 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize);
277 } else { 276 } else {
278 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", 277 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n",
279 sbi->s_super->s_id); 278 sb->s_id);
280 return NULL; 279 return NULL;
281 } 280 }
282 } else if (sbp[1] && 281 } else if (sbp[1] &&
@@ -290,9 +289,9 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi,
290 return sbp; 289 return sbp;
291} 290}
292 291
293int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag) 292int nilfs_commit_super(struct super_block *sb, int flag)
294{ 293{
295 struct the_nilfs *nilfs = sbi->s_nilfs; 294 struct the_nilfs *nilfs = sb->s_fs_info;
296 struct nilfs_super_block **sbp = nilfs->ns_sbp; 295 struct nilfs_super_block **sbp = nilfs->ns_sbp;
297 time_t t; 296 time_t t;
298 297
@@ -312,27 +311,28 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag)
312 nilfs->ns_sbsize)); 311 nilfs->ns_sbsize));
313 } 312 }
314 clear_nilfs_sb_dirty(nilfs); 313 clear_nilfs_sb_dirty(nilfs);
315 return nilfs_sync_super(sbi, flag); 314 return nilfs_sync_super(sb, flag);
316} 315}
317 316
318/** 317/**
319 * nilfs_cleanup_super() - write filesystem state for cleanup 318 * nilfs_cleanup_super() - write filesystem state for cleanup
320 * @sbi: nilfs_sb_info to be unmounted or degraded to read-only 319 * @sb: super block instance to be unmounted or degraded to read-only
321 * 320 *
322 * This function restores state flags in the on-disk super block. 321 * This function restores state flags in the on-disk super block.
323 * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the 322 * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the
324 * filesystem was not clean previously. 323 * filesystem was not clean previously.
325 */ 324 */
326int nilfs_cleanup_super(struct nilfs_sb_info *sbi) 325int nilfs_cleanup_super(struct super_block *sb)
327{ 326{
327 struct the_nilfs *nilfs = sb->s_fs_info;
328 struct nilfs_super_block **sbp; 328 struct nilfs_super_block **sbp;
329 int flag = NILFS_SB_COMMIT; 329 int flag = NILFS_SB_COMMIT;
330 int ret = -EIO; 330 int ret = -EIO;
331 331
332 sbp = nilfs_prepare_super(sbi, 0); 332 sbp = nilfs_prepare_super(sb, 0);
333 if (sbp) { 333 if (sbp) {
334 sbp[0]->s_state = cpu_to_le16(sbi->s_nilfs->ns_mount_state); 334 sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
335 nilfs_set_log_cursor(sbp[0], sbi->s_nilfs); 335 nilfs_set_log_cursor(sbp[0], nilfs);
336 if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) { 336 if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) {
337 /* 337 /*
338 * make the "clean" flag also to the opposite 338 * make the "clean" flag also to the opposite
@@ -342,21 +342,20 @@ int nilfs_cleanup_super(struct nilfs_sb_info *sbi)
342 sbp[1]->s_state = sbp[0]->s_state; 342 sbp[1]->s_state = sbp[0]->s_state;
343 flag = NILFS_SB_COMMIT_ALL; 343 flag = NILFS_SB_COMMIT_ALL;
344 } 344 }
345 ret = nilfs_commit_super(sbi, flag); 345 ret = nilfs_commit_super(sb, flag);
346 } 346 }
347 return ret; 347 return ret;
348} 348}
349 349
350static void nilfs_put_super(struct super_block *sb) 350static void nilfs_put_super(struct super_block *sb)
351{ 351{
352 struct nilfs_sb_info *sbi = NILFS_SB(sb); 352 struct the_nilfs *nilfs = sb->s_fs_info;
353 struct the_nilfs *nilfs = sbi->s_nilfs;
354 353
355 nilfs_detach_segment_constructor(sbi); 354 nilfs_detach_log_writer(sb);
356 355
357 if (!(sb->s_flags & MS_RDONLY)) { 356 if (!(sb->s_flags & MS_RDONLY)) {
358 down_write(&nilfs->ns_sem); 357 down_write(&nilfs->ns_sem);
359 nilfs_cleanup_super(sbi); 358 nilfs_cleanup_super(sb);
360 up_write(&nilfs->ns_sem); 359 up_write(&nilfs->ns_sem);
361 } 360 }
362 361
@@ -365,15 +364,12 @@ static void nilfs_put_super(struct super_block *sb)
365 iput(nilfs->ns_dat); 364 iput(nilfs->ns_dat);
366 365
367 destroy_nilfs(nilfs); 366 destroy_nilfs(nilfs);
368 sbi->s_super = NULL;
369 sb->s_fs_info = NULL; 367 sb->s_fs_info = NULL;
370 kfree(sbi);
371} 368}
372 369
373static int nilfs_sync_fs(struct super_block *sb, int wait) 370static int nilfs_sync_fs(struct super_block *sb, int wait)
374{ 371{
375 struct nilfs_sb_info *sbi = NILFS_SB(sb); 372 struct the_nilfs *nilfs = sb->s_fs_info;
376 struct the_nilfs *nilfs = sbi->s_nilfs;
377 struct nilfs_super_block **sbp; 373 struct nilfs_super_block **sbp;
378 int err = 0; 374 int err = 0;
379 375
@@ -383,10 +379,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
383 379
384 down_write(&nilfs->ns_sem); 380 down_write(&nilfs->ns_sem);
385 if (nilfs_sb_dirty(nilfs)) { 381 if (nilfs_sb_dirty(nilfs)) {
386 sbp = nilfs_prepare_super(sbi, nilfs_sb_will_flip(nilfs)); 382 sbp = nilfs_prepare_super(sb, nilfs_sb_will_flip(nilfs));
387 if (likely(sbp)) { 383 if (likely(sbp)) {
388 nilfs_set_log_cursor(sbp[0], nilfs); 384 nilfs_set_log_cursor(sbp[0], nilfs);
389 nilfs_commit_super(sbi, NILFS_SB_COMMIT); 385 nilfs_commit_super(sb, NILFS_SB_COMMIT);
390 } 386 }
391 } 387 }
392 up_write(&nilfs->ns_sem); 388 up_write(&nilfs->ns_sem);
@@ -394,10 +390,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
394 return err; 390 return err;
395} 391}
396 392
397int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, 393int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
398 struct nilfs_root **rootp) 394 struct nilfs_root **rootp)
399{ 395{
400 struct the_nilfs *nilfs = sbi->s_nilfs; 396 struct the_nilfs *nilfs = sb->s_fs_info;
401 struct nilfs_root *root; 397 struct nilfs_root *root;
402 struct nilfs_checkpoint *raw_cp; 398 struct nilfs_checkpoint *raw_cp;
403 struct buffer_head *bh_cp; 399 struct buffer_head *bh_cp;
@@ -426,7 +422,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt,
426 goto failed; 422 goto failed;
427 } 423 }
428 424
429 err = nilfs_ifile_read(sbi->s_super, root, nilfs->ns_inode_size, 425 err = nilfs_ifile_read(sb, root, nilfs->ns_inode_size,
430 &raw_cp->cp_ifile_inode, &root->ifile); 426 &raw_cp->cp_ifile_inode, &root->ifile);
431 if (err) 427 if (err)
432 goto failed_bh; 428 goto failed_bh;
@@ -450,8 +446,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt,
450 446
451static int nilfs_freeze(struct super_block *sb) 447static int nilfs_freeze(struct super_block *sb)
452{ 448{
453 struct nilfs_sb_info *sbi = NILFS_SB(sb); 449 struct the_nilfs *nilfs = sb->s_fs_info;
454 struct the_nilfs *nilfs = sbi->s_nilfs;
455 int err; 450 int err;
456 451
457 if (sb->s_flags & MS_RDONLY) 452 if (sb->s_flags & MS_RDONLY)
@@ -459,21 +454,20 @@ static int nilfs_freeze(struct super_block *sb)
459 454
460 /* Mark super block clean */ 455 /* Mark super block clean */
461 down_write(&nilfs->ns_sem); 456 down_write(&nilfs->ns_sem);
462 err = nilfs_cleanup_super(sbi); 457 err = nilfs_cleanup_super(sb);
463 up_write(&nilfs->ns_sem); 458 up_write(&nilfs->ns_sem);
464 return err; 459 return err;
465} 460}
466 461
467static int nilfs_unfreeze(struct super_block *sb) 462static int nilfs_unfreeze(struct super_block *sb)
468{ 463{
469 struct nilfs_sb_info *sbi = NILFS_SB(sb); 464 struct the_nilfs *nilfs = sb->s_fs_info;
470 struct the_nilfs *nilfs = sbi->s_nilfs;
471 465
472 if (sb->s_flags & MS_RDONLY) 466 if (sb->s_flags & MS_RDONLY)
473 return 0; 467 return 0;
474 468
475 down_write(&nilfs->ns_sem); 469 down_write(&nilfs->ns_sem);
476 nilfs_setup_super(sbi, false); 470 nilfs_setup_super(sb, false);
477 up_write(&nilfs->ns_sem); 471 up_write(&nilfs->ns_sem);
478 return 0; 472 return 0;
479} 473}
@@ -530,22 +524,22 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
530static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs) 524static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
531{ 525{
532 struct super_block *sb = vfs->mnt_sb; 526 struct super_block *sb = vfs->mnt_sb;
533 struct nilfs_sb_info *sbi = NILFS_SB(sb); 527 struct the_nilfs *nilfs = sb->s_fs_info;
534 struct nilfs_root *root = NILFS_I(vfs->mnt_root->d_inode)->i_root; 528 struct nilfs_root *root = NILFS_I(vfs->mnt_root->d_inode)->i_root;
535 529
536 if (!nilfs_test_opt(sbi, BARRIER)) 530 if (!nilfs_test_opt(nilfs, BARRIER))
537 seq_puts(seq, ",nobarrier"); 531 seq_puts(seq, ",nobarrier");
538 if (root->cno != NILFS_CPTREE_CURRENT_CNO) 532 if (root->cno != NILFS_CPTREE_CURRENT_CNO)
539 seq_printf(seq, ",cp=%llu", (unsigned long long)root->cno); 533 seq_printf(seq, ",cp=%llu", (unsigned long long)root->cno);
540 if (nilfs_test_opt(sbi, ERRORS_PANIC)) 534 if (nilfs_test_opt(nilfs, ERRORS_PANIC))
541 seq_puts(seq, ",errors=panic"); 535 seq_puts(seq, ",errors=panic");
542 if (nilfs_test_opt(sbi, ERRORS_CONT)) 536 if (nilfs_test_opt(nilfs, ERRORS_CONT))
543 seq_puts(seq, ",errors=continue"); 537 seq_puts(seq, ",errors=continue");
544 if (nilfs_test_opt(sbi, STRICT_ORDER)) 538 if (nilfs_test_opt(nilfs, STRICT_ORDER))
545 seq_puts(seq, ",order=strict"); 539 seq_puts(seq, ",order=strict");
546 if (nilfs_test_opt(sbi, NORECOVERY)) 540 if (nilfs_test_opt(nilfs, NORECOVERY))
547 seq_puts(seq, ",norecovery"); 541 seq_puts(seq, ",norecovery");
548 if (nilfs_test_opt(sbi, DISCARD)) 542 if (nilfs_test_opt(nilfs, DISCARD))
549 seq_puts(seq, ",discard"); 543 seq_puts(seq, ",discard");
550 544
551 return 0; 545 return 0;
@@ -594,7 +588,7 @@ static match_table_t tokens = {
594 588
595static int parse_options(char *options, struct super_block *sb, int is_remount) 589static int parse_options(char *options, struct super_block *sb, int is_remount)
596{ 590{
597 struct nilfs_sb_info *sbi = NILFS_SB(sb); 591 struct the_nilfs *nilfs = sb->s_fs_info;
598 char *p; 592 char *p;
599 substring_t args[MAX_OPT_ARGS]; 593 substring_t args[MAX_OPT_ARGS];
600 594
@@ -609,29 +603,29 @@ static int parse_options(char *options, struct super_block *sb, int is_remount)
609 token = match_token(p, tokens, args); 603 token = match_token(p, tokens, args);
610 switch (token) { 604 switch (token) {
611 case Opt_barrier: 605 case Opt_barrier:
612 nilfs_set_opt(sbi, BARRIER); 606 nilfs_set_opt(nilfs, BARRIER);
613 break; 607 break;
614 case Opt_nobarrier: 608 case Opt_nobarrier:
615 nilfs_clear_opt(sbi, BARRIER); 609 nilfs_clear_opt(nilfs, BARRIER);
616 break; 610 break;
617 case Opt_order: 611 case Opt_order:
618 if (strcmp(args[0].from, "relaxed") == 0) 612 if (strcmp(args[0].from, "relaxed") == 0)
619 /* Ordered data semantics */ 613 /* Ordered data semantics */
620 nilfs_clear_opt(sbi, STRICT_ORDER); 614 nilfs_clear_opt(nilfs, STRICT_ORDER);
621 else if (strcmp(args[0].from, "strict") == 0) 615 else if (strcmp(args[0].from, "strict") == 0)
622 /* Strict in-order semantics */ 616 /* Strict in-order semantics */
623 nilfs_set_opt(sbi, STRICT_ORDER); 617 nilfs_set_opt(nilfs, STRICT_ORDER);
624 else 618 else
625 return 0; 619 return 0;
626 break; 620 break;
627 case Opt_err_panic: 621 case Opt_err_panic:
628 nilfs_write_opt(sbi, ERROR_MODE, ERRORS_PANIC); 622 nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_PANIC);
629 break; 623 break;
630 case Opt_err_ro: 624 case Opt_err_ro:
631 nilfs_write_opt(sbi, ERROR_MODE, ERRORS_RO); 625 nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_RO);
632 break; 626 break;
633 case Opt_err_cont: 627 case Opt_err_cont:
634 nilfs_write_opt(sbi, ERROR_MODE, ERRORS_CONT); 628 nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_CONT);
635 break; 629 break;
636 case Opt_snapshot: 630 case Opt_snapshot:
637 if (is_remount) { 631 if (is_remount) {
@@ -642,13 +636,13 @@ static int parse_options(char *options, struct super_block *sb, int is_remount)
642 } 636 }
643 break; 637 break;
644 case Opt_norecovery: 638 case Opt_norecovery:
645 nilfs_set_opt(sbi, NORECOVERY); 639 nilfs_set_opt(nilfs, NORECOVERY);
646 break; 640 break;
647 case Opt_discard: 641 case Opt_discard:
648 nilfs_set_opt(sbi, DISCARD); 642 nilfs_set_opt(nilfs, DISCARD);
649 break; 643 break;
650 case Opt_nodiscard: 644 case Opt_nodiscard:
651 nilfs_clear_opt(sbi, DISCARD); 645 nilfs_clear_opt(nilfs, DISCARD);
652 break; 646 break;
653 default: 647 default:
654 printk(KERN_ERR 648 printk(KERN_ERR
@@ -660,22 +654,24 @@ static int parse_options(char *options, struct super_block *sb, int is_remount)
660} 654}
661 655
662static inline void 656static inline void
663nilfs_set_default_options(struct nilfs_sb_info *sbi, 657nilfs_set_default_options(struct super_block *sb,
664 struct nilfs_super_block *sbp) 658 struct nilfs_super_block *sbp)
665{ 659{
666 sbi->s_mount_opt = 660 struct the_nilfs *nilfs = sb->s_fs_info;
661
662 nilfs->ns_mount_opt =
667 NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER; 663 NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
668} 664}
669 665
670static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount) 666static int nilfs_setup_super(struct super_block *sb, int is_mount)
671{ 667{
672 struct the_nilfs *nilfs = sbi->s_nilfs; 668 struct the_nilfs *nilfs = sb->s_fs_info;
673 struct nilfs_super_block **sbp; 669 struct nilfs_super_block **sbp;
674 int max_mnt_count; 670 int max_mnt_count;
675 int mnt_count; 671 int mnt_count;
676 672
677 /* nilfs->ns_sem must be locked by the caller. */ 673 /* nilfs->ns_sem must be locked by the caller. */
678 sbp = nilfs_prepare_super(sbi, 0); 674 sbp = nilfs_prepare_super(sb, 0);
679 if (!sbp) 675 if (!sbp)
680 return -EIO; 676 return -EIO;
681 677
@@ -706,7 +702,7 @@ skip_mount_setup:
706 /* synchronize sbp[1] with sbp[0] */ 702 /* synchronize sbp[1] with sbp[0] */
707 if (sbp[1]) 703 if (sbp[1])
708 memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); 704 memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
709 return nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); 705 return nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
710} 706}
711 707
712struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb, 708struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb,
@@ -727,7 +723,7 @@ int nilfs_store_magic_and_option(struct super_block *sb,
727 struct nilfs_super_block *sbp, 723 struct nilfs_super_block *sbp,
728 char *data) 724 char *data)
729{ 725{
730 struct nilfs_sb_info *sbi = NILFS_SB(sb); 726 struct the_nilfs *nilfs = sb->s_fs_info;
731 727
732 sb->s_magic = le16_to_cpu(sbp->s_magic); 728 sb->s_magic = le16_to_cpu(sbp->s_magic);
733 729
@@ -736,12 +732,12 @@ int nilfs_store_magic_and_option(struct super_block *sb,
736 sb->s_flags |= MS_NOATIME; 732 sb->s_flags |= MS_NOATIME;
737#endif 733#endif
738 734
739 nilfs_set_default_options(sbi, sbp); 735 nilfs_set_default_options(sb, sbp);
740 736
741 sbi->s_resuid = le16_to_cpu(sbp->s_def_resuid); 737 nilfs->ns_resuid = le16_to_cpu(sbp->s_def_resuid);
742 sbi->s_resgid = le16_to_cpu(sbp->s_def_resgid); 738 nilfs->ns_resgid = le16_to_cpu(sbp->s_def_resgid);
743 sbi->s_interval = le32_to_cpu(sbp->s_c_interval); 739 nilfs->ns_interval = le32_to_cpu(sbp->s_c_interval);
744 sbi->s_watermark = le32_to_cpu(sbp->s_c_block_max); 740 nilfs->ns_watermark = le32_to_cpu(sbp->s_c_block_max);
745 741
746 return !parse_options(data, sb, 0) ? -EINVAL : 0 ; 742 return !parse_options(data, sb, 0) ? -EINVAL : 0 ;
747} 743}
@@ -822,7 +818,7 @@ static int nilfs_get_root_dentry(struct super_block *sb,
822static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, 818static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
823 struct dentry **root_dentry) 819 struct dentry **root_dentry)
824{ 820{
825 struct the_nilfs *nilfs = NILFS_SB(s)->s_nilfs; 821 struct the_nilfs *nilfs = s->s_fs_info;
826 struct nilfs_root *root; 822 struct nilfs_root *root;
827 int ret; 823 int ret;
828 824
@@ -840,7 +836,7 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
840 goto out; 836 goto out;
841 } 837 }
842 838
843 ret = nilfs_attach_checkpoint(NILFS_SB(s), cno, false, &root); 839 ret = nilfs_attach_checkpoint(s, cno, false, &root);
844 if (ret) { 840 if (ret) {
845 printk(KERN_ERR "NILFS: error loading snapshot " 841 printk(KERN_ERR "NILFS: error loading snapshot "
846 "(checkpoint number=%llu).\n", 842 "(checkpoint number=%llu).\n",
@@ -874,7 +870,7 @@ static int nilfs_try_to_shrink_tree(struct dentry *root_dentry)
874 870
875int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) 871int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno)
876{ 872{
877 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; 873 struct the_nilfs *nilfs = sb->s_fs_info;
878 struct nilfs_root *root; 874 struct nilfs_root *root;
879 struct inode *inode; 875 struct inode *inode;
880 struct dentry *dentry; 876 struct dentry *dentry;
@@ -887,7 +883,7 @@ int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno)
887 return true; /* protect recent checkpoints */ 883 return true; /* protect recent checkpoints */
888 884
889 ret = false; 885 ret = false;
890 root = nilfs_lookup_root(NILFS_SB(sb)->s_nilfs, cno); 886 root = nilfs_lookup_root(nilfs, cno);
891 if (root) { 887 if (root) {
892 inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO); 888 inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO);
893 if (inode) { 889 if (inode) {
@@ -917,43 +913,21 @@ static int
917nilfs_fill_super(struct super_block *sb, void *data, int silent) 913nilfs_fill_super(struct super_block *sb, void *data, int silent)
918{ 914{
919 struct the_nilfs *nilfs; 915 struct the_nilfs *nilfs;
920 struct nilfs_sb_info *sbi;
921 struct nilfs_root *fsroot; 916 struct nilfs_root *fsroot;
922 struct backing_dev_info *bdi; 917 struct backing_dev_info *bdi;
923 __u64 cno; 918 __u64 cno;
924 int err; 919 int err;
925 920
926 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 921 nilfs = alloc_nilfs(sb->s_bdev);
927 if (!sbi) 922 if (!nilfs)
928 return -ENOMEM; 923 return -ENOMEM;
929 924
930 sb->s_fs_info = sbi; 925 sb->s_fs_info = nilfs;
931 sbi->s_super = sb;
932
933 nilfs = alloc_nilfs(sb->s_bdev);
934 if (!nilfs) {
935 err = -ENOMEM;
936 goto failed_sbi;
937 }
938 sbi->s_nilfs = nilfs;
939 926
940 err = init_nilfs(nilfs, sbi, (char *)data); 927 err = init_nilfs(nilfs, sb, (char *)data);
941 if (err) 928 if (err)
942 goto failed_nilfs; 929 goto failed_nilfs;
943 930
944 spin_lock_init(&sbi->s_inode_lock);
945 INIT_LIST_HEAD(&sbi->s_dirty_files);
946
947 /*
948 * Following initialization is overlapped because
949 * nilfs_sb_info structure has been cleared at the beginning.
950 * But we reserve them to keep our interest and make ready
951 * for the future change.
952 */
953 get_random_bytes(&sbi->s_next_generation,
954 sizeof(sbi->s_next_generation));
955 spin_lock_init(&sbi->s_next_gen_lock);
956
957 sb->s_op = &nilfs_sops; 931 sb->s_op = &nilfs_sops;
958 sb->s_export_op = &nilfs_export_ops; 932 sb->s_export_op = &nilfs_export_ops;
959 sb->s_root = NULL; 933 sb->s_root = NULL;
@@ -962,12 +936,12 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
962 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; 936 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
963 sb->s_bdi = bdi ? : &default_backing_dev_info; 937 sb->s_bdi = bdi ? : &default_backing_dev_info;
964 938
965 err = load_nilfs(nilfs, sbi); 939 err = load_nilfs(nilfs, sb);
966 if (err) 940 if (err)
967 goto failed_nilfs; 941 goto failed_nilfs;
968 942
969 cno = nilfs_last_cno(nilfs); 943 cno = nilfs_last_cno(nilfs);
970 err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot); 944 err = nilfs_attach_checkpoint(sb, cno, true, &fsroot);
971 if (err) { 945 if (err) {
972 printk(KERN_ERR "NILFS: error loading last checkpoint " 946 printk(KERN_ERR "NILFS: error loading last checkpoint "
973 "(checkpoint number=%llu).\n", (unsigned long long)cno); 947 "(checkpoint number=%llu).\n", (unsigned long long)cno);
@@ -975,7 +949,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
975 } 949 }
976 950
977 if (!(sb->s_flags & MS_RDONLY)) { 951 if (!(sb->s_flags & MS_RDONLY)) {
978 err = nilfs_attach_segment_constructor(sbi, fsroot); 952 err = nilfs_attach_log_writer(sb, fsroot);
979 if (err) 953 if (err)
980 goto failed_checkpoint; 954 goto failed_checkpoint;
981 } 955 }
@@ -988,14 +962,14 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
988 962
989 if (!(sb->s_flags & MS_RDONLY)) { 963 if (!(sb->s_flags & MS_RDONLY)) {
990 down_write(&nilfs->ns_sem); 964 down_write(&nilfs->ns_sem);
991 nilfs_setup_super(sbi, true); 965 nilfs_setup_super(sb, true);
992 up_write(&nilfs->ns_sem); 966 up_write(&nilfs->ns_sem);
993 } 967 }
994 968
995 return 0; 969 return 0;
996 970
997 failed_segctor: 971 failed_segctor:
998 nilfs_detach_segment_constructor(sbi); 972 nilfs_detach_log_writer(sb);
999 973
1000 failed_checkpoint: 974 failed_checkpoint:
1001 nilfs_put_root(fsroot); 975 nilfs_put_root(fsroot);
@@ -1007,23 +981,18 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
1007 981
1008 failed_nilfs: 982 failed_nilfs:
1009 destroy_nilfs(nilfs); 983 destroy_nilfs(nilfs);
1010
1011 failed_sbi:
1012 sb->s_fs_info = NULL;
1013 kfree(sbi);
1014 return err; 984 return err;
1015} 985}
1016 986
1017static int nilfs_remount(struct super_block *sb, int *flags, char *data) 987static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1018{ 988{
1019 struct nilfs_sb_info *sbi = NILFS_SB(sb); 989 struct the_nilfs *nilfs = sb->s_fs_info;
1020 struct the_nilfs *nilfs = sbi->s_nilfs;
1021 unsigned long old_sb_flags; 990 unsigned long old_sb_flags;
1022 unsigned long old_mount_opt; 991 unsigned long old_mount_opt;
1023 int err; 992 int err;
1024 993
1025 old_sb_flags = sb->s_flags; 994 old_sb_flags = sb->s_flags;
1026 old_mount_opt = sbi->s_mount_opt; 995 old_mount_opt = nilfs->ns_mount_opt;
1027 996
1028 if (!parse_options(data, sb, 1)) { 997 if (!parse_options(data, sb, 1)) {
1029 err = -EINVAL; 998 err = -EINVAL;
@@ -1043,8 +1012,8 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1043 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) 1012 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1044 goto out; 1013 goto out;
1045 if (*flags & MS_RDONLY) { 1014 if (*flags & MS_RDONLY) {
1046 /* Shutting down the segment constructor */ 1015 /* Shutting down log writer */
1047 nilfs_detach_segment_constructor(sbi); 1016 nilfs_detach_log_writer(sb);
1048 sb->s_flags |= MS_RDONLY; 1017 sb->s_flags |= MS_RDONLY;
1049 1018
1050 /* 1019 /*
@@ -1052,7 +1021,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1052 * the RDONLY flag and then mark the partition as valid again. 1021 * the RDONLY flag and then mark the partition as valid again.
1053 */ 1022 */
1054 down_write(&nilfs->ns_sem); 1023 down_write(&nilfs->ns_sem);
1055 nilfs_cleanup_super(sbi); 1024 nilfs_cleanup_super(sb);
1056 up_write(&nilfs->ns_sem); 1025 up_write(&nilfs->ns_sem);
1057 } else { 1026 } else {
1058 __u64 features; 1027 __u64 features;
@@ -1079,12 +1048,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1079 sb->s_flags &= ~MS_RDONLY; 1048 sb->s_flags &= ~MS_RDONLY;
1080 1049
1081 root = NILFS_I(sb->s_root->d_inode)->i_root; 1050 root = NILFS_I(sb->s_root->d_inode)->i_root;
1082 err = nilfs_attach_segment_constructor(sbi, root); 1051 err = nilfs_attach_log_writer(sb, root);
1083 if (err) 1052 if (err)
1084 goto restore_opts; 1053 goto restore_opts;
1085 1054
1086 down_write(&nilfs->ns_sem); 1055 down_write(&nilfs->ns_sem);
1087 nilfs_setup_super(sbi, true); 1056 nilfs_setup_super(sb, true);
1088 up_write(&nilfs->ns_sem); 1057 up_write(&nilfs->ns_sem);
1089 } 1058 }
1090 out: 1059 out:
@@ -1092,13 +1061,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1092 1061
1093 restore_opts: 1062 restore_opts:
1094 sb->s_flags = old_sb_flags; 1063 sb->s_flags = old_sb_flags;
1095 sbi->s_mount_opt = old_mount_opt; 1064 nilfs->ns_mount_opt = old_mount_opt;
1096 return err; 1065 return err;
1097} 1066}
1098 1067
1099struct nilfs_super_data { 1068struct nilfs_super_data {
1100 struct block_device *bdev; 1069 struct block_device *bdev;
1101 struct nilfs_sb_info *sbi;
1102 __u64 cno; 1070 __u64 cno;
1103 int flags; 1071 int flags;
1104}; 1072};
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index ad4ac607cf57..d2acd1a651f3 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/backing-dev.h> 27#include <linux/backing-dev.h>
28#include <linux/random.h>
28#include <linux/crc32.h> 29#include <linux/crc32.h>
29#include "nilfs.h" 30#include "nilfs.h"
30#include "segment.h" 31#include "segment.h"
@@ -75,7 +76,10 @@ struct the_nilfs *alloc_nilfs(struct block_device *bdev)
75 nilfs->ns_bdev = bdev; 76 nilfs->ns_bdev = bdev;
76 atomic_set(&nilfs->ns_ndirtyblks, 0); 77 atomic_set(&nilfs->ns_ndirtyblks, 0);
77 init_rwsem(&nilfs->ns_sem); 78 init_rwsem(&nilfs->ns_sem);
79 INIT_LIST_HEAD(&nilfs->ns_dirty_files);
78 INIT_LIST_HEAD(&nilfs->ns_gc_inodes); 80 INIT_LIST_HEAD(&nilfs->ns_gc_inodes);
81 spin_lock_init(&nilfs->ns_inode_lock);
82 spin_lock_init(&nilfs->ns_next_gen_lock);
79 spin_lock_init(&nilfs->ns_last_segment_lock); 83 spin_lock_init(&nilfs->ns_last_segment_lock);
80 nilfs->ns_cptree = RB_ROOT; 84 nilfs->ns_cptree = RB_ROOT;
81 spin_lock_init(&nilfs->ns_cptree_lock); 85 spin_lock_init(&nilfs->ns_cptree_lock);
@@ -197,16 +201,16 @@ static int nilfs_store_log_cursor(struct the_nilfs *nilfs,
197/** 201/**
198 * load_nilfs - load and recover the nilfs 202 * load_nilfs - load and recover the nilfs
199 * @nilfs: the_nilfs structure to be released 203 * @nilfs: the_nilfs structure to be released
200 * @sbi: nilfs_sb_info used to recover past segment 204 * @sb: super block isntance used to recover past segment
201 * 205 *
202 * load_nilfs() searches and load the latest super root, 206 * load_nilfs() searches and load the latest super root,
203 * attaches the last segment, and does recovery if needed. 207 * attaches the last segment, and does recovery if needed.
204 * The caller must call this exclusively for simultaneous mounts. 208 * The caller must call this exclusively for simultaneous mounts.
205 */ 209 */
206int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) 210int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
207{ 211{
208 struct nilfs_recovery_info ri; 212 struct nilfs_recovery_info ri;
209 unsigned int s_flags = sbi->s_super->s_flags; 213 unsigned int s_flags = sb->s_flags;
210 int really_read_only = bdev_read_only(nilfs->ns_bdev); 214 int really_read_only = bdev_read_only(nilfs->ns_bdev);
211 int valid_fs = nilfs_valid_fs(nilfs); 215 int valid_fs = nilfs_valid_fs(nilfs);
212 int err; 216 int err;
@@ -271,7 +275,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
271 goto scan_error; 275 goto scan_error;
272 } 276 }
273 277
274 err = nilfs_load_super_root(nilfs, sbi->s_super, ri.ri_super_root); 278 err = nilfs_load_super_root(nilfs, sb, ri.ri_super_root);
275 if (unlikely(err)) { 279 if (unlikely(err)) {
276 printk(KERN_ERR "NILFS: error loading super root.\n"); 280 printk(KERN_ERR "NILFS: error loading super root.\n");
277 goto failed; 281 goto failed;
@@ -283,7 +287,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
283 if (s_flags & MS_RDONLY) { 287 if (s_flags & MS_RDONLY) {
284 __u64 features; 288 __u64 features;
285 289
286 if (nilfs_test_opt(sbi, NORECOVERY)) { 290 if (nilfs_test_opt(nilfs, NORECOVERY)) {
287 printk(KERN_INFO "NILFS: norecovery option specified. " 291 printk(KERN_INFO "NILFS: norecovery option specified. "
288 "skipping roll-forward recovery\n"); 292 "skipping roll-forward recovery\n");
289 goto skip_recovery; 293 goto skip_recovery;
@@ -304,21 +308,21 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
304 err = -EROFS; 308 err = -EROFS;
305 goto failed_unload; 309 goto failed_unload;
306 } 310 }
307 sbi->s_super->s_flags &= ~MS_RDONLY; 311 sb->s_flags &= ~MS_RDONLY;
308 } else if (nilfs_test_opt(sbi, NORECOVERY)) { 312 } else if (nilfs_test_opt(nilfs, NORECOVERY)) {
309 printk(KERN_ERR "NILFS: recovery cancelled because norecovery " 313 printk(KERN_ERR "NILFS: recovery cancelled because norecovery "
310 "option was specified for a read/write mount\n"); 314 "option was specified for a read/write mount\n");
311 err = -EINVAL; 315 err = -EINVAL;
312 goto failed_unload; 316 goto failed_unload;
313 } 317 }
314 318
315 err = nilfs_salvage_orphan_logs(nilfs, sbi, &ri); 319 err = nilfs_salvage_orphan_logs(nilfs, sb, &ri);
316 if (err) 320 if (err)
317 goto failed_unload; 321 goto failed_unload;
318 322
319 down_write(&nilfs->ns_sem); 323 down_write(&nilfs->ns_sem);
320 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ 324 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */
321 err = nilfs_cleanup_super(sbi); 325 err = nilfs_cleanup_super(sb);
322 up_write(&nilfs->ns_sem); 326 up_write(&nilfs->ns_sem);
323 327
324 if (err) { 328 if (err) {
@@ -330,7 +334,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
330 334
331 skip_recovery: 335 skip_recovery:
332 nilfs_clear_recovery_info(&ri); 336 nilfs_clear_recovery_info(&ri);
333 sbi->s_super->s_flags = s_flags; 337 sb->s_flags = s_flags;
334 return 0; 338 return 0;
335 339
336 scan_error: 340 scan_error:
@@ -344,7 +348,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
344 348
345 failed: 349 failed:
346 nilfs_clear_recovery_info(&ri); 350 nilfs_clear_recovery_info(&ri);
347 sbi->s_super->s_flags = s_flags; 351 sb->s_flags = s_flags;
348 return err; 352 return err;
349} 353}
350 354
@@ -475,10 +479,13 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
475 return -EIO; 479 return -EIO;
476 } 480 }
477 printk(KERN_WARNING 481 printk(KERN_WARNING
478 "NILFS warning: unable to read primary superblock\n"); 482 "NILFS warning: unable to read primary superblock "
479 } else if (!sbp[1]) 483 "(blocksize = %d)\n", blocksize);
484 } else if (!sbp[1]) {
480 printk(KERN_WARNING 485 printk(KERN_WARNING
481 "NILFS warning: unable to read secondary superblock\n"); 486 "NILFS warning: unable to read secondary superblock "
487 "(blocksize = %d)\n", blocksize);
488 }
482 489
483 /* 490 /*
484 * Compare two super blocks and set 1 in swp if the secondary 491 * Compare two super blocks and set 1 in swp if the secondary
@@ -505,7 +512,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
505 512
506 if (!valid[!swp]) 513 if (!valid[!swp])
507 printk(KERN_WARNING "NILFS warning: broken superblock. " 514 printk(KERN_WARNING "NILFS warning: broken superblock. "
508 "using spare superblock.\n"); 515 "using spare superblock (blocksize = %d).\n", blocksize);
509 if (swp) 516 if (swp)
510 nilfs_swap_super_block(nilfs); 517 nilfs_swap_super_block(nilfs);
511 518
@@ -519,7 +526,6 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
519/** 526/**
520 * init_nilfs - initialize a NILFS instance. 527 * init_nilfs - initialize a NILFS instance.
521 * @nilfs: the_nilfs structure 528 * @nilfs: the_nilfs structure
522 * @sbi: nilfs_sb_info
523 * @sb: super block 529 * @sb: super block
524 * @data: mount options 530 * @data: mount options
525 * 531 *
@@ -530,9 +536,8 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
530 * Return Value: On success, 0 is returned. On error, a negative error 536 * Return Value: On success, 0 is returned. On error, a negative error
531 * code is returned. 537 * code is returned.
532 */ 538 */
533int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) 539int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data)
534{ 540{
535 struct super_block *sb = sbi->s_super;
536 struct nilfs_super_block *sbp; 541 struct nilfs_super_block *sbp;
537 int blocksize; 542 int blocksize;
538 int err; 543 int err;
@@ -588,6 +593,9 @@ int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data)
588 nilfs->ns_blocksize_bits = sb->s_blocksize_bits; 593 nilfs->ns_blocksize_bits = sb->s_blocksize_bits;
589 nilfs->ns_blocksize = blocksize; 594 nilfs->ns_blocksize = blocksize;
590 595
596 get_random_bytes(&nilfs->ns_next_generation,
597 sizeof(nilfs->ns_next_generation));
598
591 err = nilfs_store_disk_layout(nilfs, sbp); 599 err = nilfs_store_disk_layout(nilfs, sbp);
592 if (err) 600 if (err)
593 goto failed_sbh; 601 goto failed_sbh;
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index fd85e4c05c6b..f4968145c2a3 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -31,7 +31,8 @@
31#include <linux/blkdev.h> 31#include <linux/blkdev.h>
32#include <linux/backing-dev.h> 32#include <linux/backing-dev.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include "sb.h" 34
35struct nilfs_sc_info;
35 36
36/* the_nilfs struct */ 37/* the_nilfs struct */
37enum { 38enum {
@@ -65,13 +66,23 @@ enum {
65 * @ns_last_cno: checkpoint number of the latest segment 66 * @ns_last_cno: checkpoint number of the latest segment
66 * @ns_prot_seq: least sequence number of segments which must not be reclaimed 67 * @ns_prot_seq: least sequence number of segments which must not be reclaimed
67 * @ns_prev_seq: base sequence number used to decide if advance log cursor 68 * @ns_prev_seq: base sequence number used to decide if advance log cursor
68 * @ns_segctor_sem: segment constructor semaphore 69 * @ns_writer: log writer
70 * @ns_segctor_sem: semaphore protecting log write
69 * @ns_dat: DAT file inode 71 * @ns_dat: DAT file inode
70 * @ns_cpfile: checkpoint file inode 72 * @ns_cpfile: checkpoint file inode
71 * @ns_sufile: segusage file inode 73 * @ns_sufile: segusage file inode
72 * @ns_cptree: rb-tree of all mounted checkpoints (nilfs_root) 74 * @ns_cptree: rb-tree of all mounted checkpoints (nilfs_root)
73 * @ns_cptree_lock: lock protecting @ns_cptree 75 * @ns_cptree_lock: lock protecting @ns_cptree
76 * @ns_dirty_files: list of dirty files
77 * @ns_inode_lock: lock protecting @ns_dirty_files
74 * @ns_gc_inodes: dummy inodes to keep live blocks 78 * @ns_gc_inodes: dummy inodes to keep live blocks
79 * @ns_next_generation: next generation number for inodes
80 * @ns_next_gen_lock: lock protecting @ns_next_generation
81 * @ns_mount_opt: mount options
82 * @ns_resuid: uid for reserved blocks
83 * @ns_resgid: gid for reserved blocks
84 * @ns_interval: checkpoint creation interval
85 * @ns_watermark: watermark for the number of dirty buffers
75 * @ns_blocksize_bits: bit length of block size 86 * @ns_blocksize_bits: bit length of block size
76 * @ns_blocksize: block size 87 * @ns_blocksize: block size
77 * @ns_nsegments: number of segments in filesystem 88 * @ns_nsegments: number of segments in filesystem
@@ -131,6 +142,7 @@ struct the_nilfs {
131 u64 ns_prot_seq; 142 u64 ns_prot_seq;
132 u64 ns_prev_seq; 143 u64 ns_prev_seq;
133 144
145 struct nilfs_sc_info *ns_writer;
134 struct rw_semaphore ns_segctor_sem; 146 struct rw_semaphore ns_segctor_sem;
135 147
136 /* 148 /*
@@ -145,9 +157,25 @@ struct the_nilfs {
145 struct rb_root ns_cptree; 157 struct rb_root ns_cptree;
146 spinlock_t ns_cptree_lock; 158 spinlock_t ns_cptree_lock;
147 159
160 /* Dirty inode list */
161 struct list_head ns_dirty_files;
162 spinlock_t ns_inode_lock;
163
148 /* GC inode list */ 164 /* GC inode list */
149 struct list_head ns_gc_inodes; 165 struct list_head ns_gc_inodes;
150 166
167 /* Inode allocator */
168 u32 ns_next_generation;
169 spinlock_t ns_next_gen_lock;
170
171 /* Mount options */
172 unsigned long ns_mount_opt;
173
174 uid_t ns_resuid;
175 gid_t ns_resgid;
176 unsigned long ns_interval;
177 unsigned long ns_watermark;
178
151 /* Disk layout information (static) */ 179 /* Disk layout information (static) */
152 unsigned int ns_blocksize_bits; 180 unsigned int ns_blocksize_bits;
153 unsigned int ns_blocksize; 181 unsigned int ns_blocksize;
@@ -180,6 +208,20 @@ THE_NILFS_FNS(DISCONTINUED, discontinued)
180THE_NILFS_FNS(GC_RUNNING, gc_running) 208THE_NILFS_FNS(GC_RUNNING, gc_running)
181THE_NILFS_FNS(SB_DIRTY, sb_dirty) 209THE_NILFS_FNS(SB_DIRTY, sb_dirty)
182 210
211/*
212 * Mount option operations
213 */
214#define nilfs_clear_opt(nilfs, opt) \
215 do { (nilfs)->ns_mount_opt &= ~NILFS_MOUNT_##opt; } while (0)
216#define nilfs_set_opt(nilfs, opt) \
217 do { (nilfs)->ns_mount_opt |= NILFS_MOUNT_##opt; } while (0)
218#define nilfs_test_opt(nilfs, opt) ((nilfs)->ns_mount_opt & NILFS_MOUNT_##opt)
219#define nilfs_write_opt(nilfs, mask, opt) \
220 do { (nilfs)->ns_mount_opt = \
221 (((nilfs)->ns_mount_opt & ~NILFS_MOUNT_##mask) | \
222 NILFS_MOUNT_##opt); \
223 } while (0)
224
183/** 225/**
184 * struct nilfs_root - nilfs root object 226 * struct nilfs_root - nilfs root object
185 * @cno: checkpoint number 227 * @cno: checkpoint number
@@ -224,15 +266,14 @@ static inline int nilfs_sb_will_flip(struct the_nilfs *nilfs)
224void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64); 266void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64);
225struct the_nilfs *alloc_nilfs(struct block_device *bdev); 267struct the_nilfs *alloc_nilfs(struct block_device *bdev);
226void destroy_nilfs(struct the_nilfs *nilfs); 268void destroy_nilfs(struct the_nilfs *nilfs);
227int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); 269int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data);
228int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); 270int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb);
229int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); 271int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t);
230int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); 272int nilfs_count_free_blocks(struct the_nilfs *, sector_t *);
231struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno); 273struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno);
232struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs, 274struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs,
233 __u64 cno); 275 __u64 cno);
234void nilfs_put_root(struct nilfs_root *root); 276void nilfs_put_root(struct nilfs_root *root);
235struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64);
236int nilfs_near_disk_full(struct the_nilfs *); 277int nilfs_near_disk_full(struct the_nilfs *);
237void nilfs_fall_back_super_block(struct the_nilfs *); 278void nilfs_fall_back_super_block(struct the_nilfs *);
238void nilfs_swap_super_block(struct the_nilfs *); 279void nilfs_swap_super_block(struct the_nilfs *);
diff --git a/fs/ntfs/Makefile b/fs/ntfs/Makefile
index 4ff028fcfd6e..30206b238433 100644
--- a/fs/ntfs/Makefile
+++ b/fs/ntfs/Makefile
@@ -2,18 +2,13 @@
2 2
3obj-$(CONFIG_NTFS_FS) += ntfs.o 3obj-$(CONFIG_NTFS_FS) += ntfs.o
4 4
5ntfs-objs := aops.o attrib.o collate.o compress.o debug.o dir.o file.o \ 5ntfs-y := aops.o attrib.o collate.o compress.o debug.o dir.o file.o \
6 index.o inode.o mft.o mst.o namei.o runlist.o super.o sysctl.o \ 6 index.o inode.o mft.o mst.o namei.o runlist.o super.o sysctl.o \
7 unistr.o upcase.o 7 unistr.o upcase.o
8 8
9EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.30\" 9ntfs-$(CONFIG_NTFS_RW) += bitmap.o lcnalloc.o logfile.o quota.o usnjrnl.o
10 10
11ifeq ($(CONFIG_NTFS_DEBUG),y) 11ccflags-y := -DNTFS_VERSION=\"2.1.30\"
12EXTRA_CFLAGS += -DDEBUG 12ccflags-$(CONFIG_NTFS_DEBUG) += -DDEBUG
13endif 13ccflags-$(CONFIG_NTFS_RW) += -DNTFS_RW
14 14
15ifeq ($(CONFIG_NTFS_RW),y)
16EXTRA_CFLAGS += -DNTFS_RW
17
18ntfs-objs += bitmap.o lcnalloc.o logfile.o quota.o usnjrnl.o
19endif
diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile
index 07d9fd854350..d8a0313e99e6 100644
--- a/fs/ocfs2/Makefile
+++ b/fs/ocfs2/Makefile
@@ -1,6 +1,6 @@
1EXTRA_CFLAGS += -Ifs/ocfs2 1ccflags-y := -Ifs/ocfs2
2 2
3EXTRA_CFLAGS += -DCATCH_BH_JBD_RACES 3ccflags-y += -DCATCH_BH_JBD_RACES
4 4
5obj-$(CONFIG_OCFS2_FS) += \ 5obj-$(CONFIG_OCFS2_FS) += \
6 ocfs2.o \ 6 ocfs2.o \
diff --git a/fs/ocfs2/dlm/Makefile b/fs/ocfs2/dlm/Makefile
index dcebf0d920fa..c8a044efbb15 100644
--- a/fs/ocfs2/dlm/Makefile
+++ b/fs/ocfs2/dlm/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS += -Ifs/ocfs2 1ccflags-y := -Ifs/ocfs2
2 2
3obj-$(CONFIG_OCFS2_FS_O2CB) += ocfs2_dlm.o 3obj-$(CONFIG_OCFS2_FS_O2CB) += ocfs2_dlm.o
4 4
diff --git a/fs/ocfs2/dlmfs/Makefile b/fs/ocfs2/dlmfs/Makefile
index df69b4856d0d..f14be89a6701 100644
--- a/fs/ocfs2/dlmfs/Makefile
+++ b/fs/ocfs2/dlmfs/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS += -Ifs/ocfs2 1ccflags-y := -Ifs/ocfs2
2 2
3obj-$(CONFIG_OCFS2_FS) += ocfs2_dlmfs.o 3obj-$(CONFIG_OCFS2_FS) += ocfs2_dlmfs.o
4 4
diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile
index 792b3cb2cd18..3c3b00165114 100644
--- a/fs/reiserfs/Makefile
+++ b/fs/reiserfs/Makefile
@@ -31,9 +31,7 @@ endif
31# and causing a panic. Since this behavior only affects ppc32, this ifeq 31# and causing a panic. Since this behavior only affects ppc32, this ifeq
32# will work around it. If any other architecture displays this behavior, 32# will work around it. If any other architecture displays this behavior,
33# add it here. 33# add it here.
34ifeq ($(CONFIG_PPC32),y) 34ccflags-$(CONFIG_PPC32) := $(call cc-ifversion, -lt, 0400, -O1)
35EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0400, -O1)
36endif
37 35
38TAGS: 36TAGS:
39 etags *.c 37 etags *.c
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index faca44997099..82b1371775c0 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -16,14 +16,11 @@
16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17# 17#
18 18
19EXTRA_CFLAGS += -I$(src) -I$(src)/linux-2.6 19ccflags-y := -I$(src) -I$(src)/linux-2.6
20ccflags-$(CONFIG_XFS_DEBUG) += -g
20 21
21XFS_LINUX := linux-2.6 22XFS_LINUX := linux-2.6
22 23
23ifeq ($(CONFIG_XFS_DEBUG),y)
24 EXTRA_CFLAGS += -g
25endif
26
27obj-$(CONFIG_XFS_FS) += xfs.o 24obj-$(CONFIG_XFS_FS) += xfs.o
28 25
29xfs-y += linux-2.6/xfs_trace.o 26xfs-y += linux-2.6/xfs_trace.o
diff --git a/include/asm-generic/unistd.h b/include/asm-generic/unistd.h
index 57af0338d270..d94f447c667a 100644
--- a/include/asm-generic/unistd.h
+++ b/include/asm-generic/unistd.h
@@ -650,9 +650,11 @@ __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
650__SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at) 650__SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at)
651#define __NR_open_by_handle_at 265 651#define __NR_open_by_handle_at 265
652__SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at) 652__SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at)
653#define __NR_clock_adjtime 266
654__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)
653 655
654#undef __NR_syscalls 656#undef __NR_syscalls
655#define __NR_syscalls 266 657#define __NR_syscalls 267
656 658
657/* 659/*
658 * All syscalls below here should go away really, 660 * All syscalls below here should go away really,
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
deleted file mode 100644
index 4bef5c557160..000000000000
--- a/include/linux/i2c-id.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/* ------------------------------------------------------------------------- */
2/* */
3/* i2c-id.h - identifier values for i2c drivers and adapters */
4/* */
5/* ------------------------------------------------------------------------- */
6/* Copyright (C) 1995-1999 Simon G. Vogl
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21/* ------------------------------------------------------------------------- */
22
23#ifndef LINUX_I2C_ID_H
24#define LINUX_I2C_ID_H
25
26/* Please note that I2C driver IDs are optional. They are only needed if a
27 legacy chip driver needs to identify a bus or a bus driver needs to
28 identify a legacy client. If you don't need them, just don't set them. */
29
30/*
31 * ---- Adapter types ----------------------------------------------------
32 */
33
34/* --- Bit algorithm adapters */
35#define I2C_HW_B_CX2388x 0x01001b /* connexant 2388x based tv cards */
36
37#endif /* LINUX_I2C_ID_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 06a8d9c7de98..f1e3ff5880a9 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -29,7 +29,6 @@
29#include <linux/types.h> 29#include <linux/types.h>
30#ifdef __KERNEL__ 30#ifdef __KERNEL__
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/i2c-id.h>
33#include <linux/mod_devicetable.h> 32#include <linux/mod_devicetable.h>
34#include <linux/device.h> /* for struct device */ 33#include <linux/device.h> /* for struct device */
35#include <linux/sched.h> /* for completion */ 34#include <linux/sched.h> /* for completion */
@@ -105,8 +104,8 @@ extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client,
105/** 104/**
106 * struct i2c_driver - represent an I2C device driver 105 * struct i2c_driver - represent an I2C device driver
107 * @class: What kind of i2c device we instantiate (for detect) 106 * @class: What kind of i2c device we instantiate (for detect)
108 * @attach_adapter: Callback for bus addition (for legacy drivers) 107 * @attach_adapter: Callback for bus addition (deprecated)
109 * @detach_adapter: Callback for bus removal (for legacy drivers) 108 * @detach_adapter: Callback for bus removal (deprecated)
110 * @probe: Callback for device binding 109 * @probe: Callback for device binding
111 * @remove: Callback for device unbinding 110 * @remove: Callback for device unbinding
112 * @shutdown: Callback for device shutdown 111 * @shutdown: Callback for device shutdown
@@ -144,11 +143,11 @@ struct i2c_driver {
144 unsigned int class; 143 unsigned int class;
145 144
146 /* Notifies the driver that a new bus has appeared or is about to be 145 /* Notifies the driver that a new bus has appeared or is about to be
147 * removed. You should avoid using this if you can, it will probably 146 * removed. You should avoid using this, it will be removed in a
148 * be removed in a near future. 147 * near future.
149 */ 148 */
150 int (*attach_adapter)(struct i2c_adapter *); 149 int (*attach_adapter)(struct i2c_adapter *) __deprecated;
151 int (*detach_adapter)(struct i2c_adapter *); 150 int (*detach_adapter)(struct i2c_adapter *) __deprecated;
152 151
153 /* Standard driver model interfaces */ 152 /* Standard driver model interfaces */
154 int (*probe)(struct i2c_client *, const struct i2c_device_id *); 153 int (*probe)(struct i2c_client *, const struct i2c_device_id *);
@@ -354,7 +353,6 @@ struct i2c_algorithm {
354 */ 353 */
355struct i2c_adapter { 354struct i2c_adapter {
356 struct module *owner; 355 struct module *owner;
357 unsigned int id __deprecated;
358 unsigned int class; /* classes to allow probing for */ 356 unsigned int class; /* classes to allow probing for */
359 const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 357 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
360 void *algo_data; 358 void *algo_data;
@@ -396,6 +394,8 @@ i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
396 return NULL; 394 return NULL;
397} 395}
398 396
397int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *));
398
399/* Adapter locking functions, exported for shared pin cases */ 399/* Adapter locking functions, exported for shared pin cases */
400void i2c_lock_adapter(struct i2c_adapter *); 400void i2c_lock_adapter(struct i2c_adapter *);
401void i2c_unlock_adapter(struct i2c_adapter *); 401void i2c_unlock_adapter(struct i2c_adapter *);
@@ -447,7 +447,7 @@ extern void i2c_release_client(struct i2c_client *client);
447extern void i2c_clients_command(struct i2c_adapter *adap, 447extern void i2c_clients_command(struct i2c_adapter *adap,
448 unsigned int cmd, void *arg); 448 unsigned int cmd, void *arg);
449 449
450extern struct i2c_adapter *i2c_get_adapter(int id); 450extern struct i2c_adapter *i2c_get_adapter(int nr);
451extern void i2c_put_adapter(struct i2c_adapter *adap); 451extern void i2c_put_adapter(struct i2c_adapter *adap);
452 452
453 453
diff --git a/include/linux/i2c/qt602240_ts.h b/include/linux/i2c/atmel_mxt_ts.h
index c5033e101094..f027f7a63511 100644
--- a/include/linux/i2c/qt602240_ts.h
+++ b/include/linux/i2c/atmel_mxt_ts.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * AT42QT602240/ATMXT224 Touchscreen driver 2 * Atmel maXTouch Touchscreen driver
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd 4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com> 5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
@@ -10,21 +10,26 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13#ifndef __LINUX_QT602240_TS_H 13#ifndef __LINUX_ATMEL_MXT_TS_H
14#define __LINUX_QT602240_TS_H 14#define __LINUX_ATMEL_MXT_TS_H
15
16#include <linux/types.h>
15 17
16/* Orient */ 18/* Orient */
17#define QT602240_NORMAL 0x0 19#define MXT_NORMAL 0x0
18#define QT602240_DIAGONAL 0x1 20#define MXT_DIAGONAL 0x1
19#define QT602240_HORIZONTAL_FLIP 0x2 21#define MXT_HORIZONTAL_FLIP 0x2
20#define QT602240_ROTATED_90_COUNTER 0x3 22#define MXT_ROTATED_90_COUNTER 0x3
21#define QT602240_VERTICAL_FLIP 0x4 23#define MXT_VERTICAL_FLIP 0x4
22#define QT602240_ROTATED_90 0x5 24#define MXT_ROTATED_90 0x5
23#define QT602240_ROTATED_180 0x6 25#define MXT_ROTATED_180 0x6
24#define QT602240_DIAGONAL_COUNTER 0x7 26#define MXT_DIAGONAL_COUNTER 0x7
27
28/* The platform data for the Atmel maXTouch touchscreen driver */
29struct mxt_platform_data {
30 const u8 *config;
31 size_t config_length;
25 32
26/* The platform data for the AT42QT602240/ATMXT224 touchscreen driver */
27struct qt602240_platform_data {
28 unsigned int x_line; 33 unsigned int x_line;
29 unsigned int y_line; 34 unsigned int y_line;
30 unsigned int x_size; 35 unsigned int x_size;
@@ -33,6 +38,7 @@ struct qt602240_platform_data {
33 unsigned int threshold; 38 unsigned int threshold;
34 unsigned int voltage; 39 unsigned int voltage;
35 unsigned char orient; 40 unsigned char orient;
41 unsigned long irqflags;
36}; 42};
37 43
38#endif /* __LINUX_QT602240_TS_H */ 44#endif /* __LINUX_ATMEL_MXT_TS_H */
diff --git a/include/linux/i2c/mcs.h b/include/linux/i2c/mcs.h
index 725ae7c313ff..61bb18a4fd3c 100644
--- a/include/linux/i2c/mcs.h
+++ b/include/linux/i2c/mcs.h
@@ -18,6 +18,7 @@
18#define MCS_KEY_CODE(v) ((v) & 0xffff) 18#define MCS_KEY_CODE(v) ((v) & 0xffff)
19 19
20struct mcs_platform_data { 20struct mcs_platform_data {
21 void (*poweron)(bool);
21 void (*cfg_pin)(void); 22 void (*cfg_pin)(void);
22 23
23 /* touchscreen */ 24 /* touchscreen */
diff --git a/include/linux/input-polldev.h b/include/linux/input-polldev.h
index 5e3dddf8f562..ce0b72464eb8 100644
--- a/include/linux/input-polldev.h
+++ b/include/linux/input-polldev.h
@@ -22,12 +22,12 @@
22 * @poll: driver-supplied method that polls the device and posts 22 * @poll: driver-supplied method that polls the device and posts
23 * input events (mandatory). 23 * input events (mandatory).
24 * @poll_interval: specifies how often the poll() method should be called. 24 * @poll_interval: specifies how often the poll() method should be called.
25 * Defaults to 500 msec unless overriden when registering the device. 25 * Defaults to 500 msec unless overridden when registering the device.
26 * @poll_interval_max: specifies upper bound for the poll interval. 26 * @poll_interval_max: specifies upper bound for the poll interval.
27 * Defaults to the initial value of @poll_interval. 27 * Defaults to the initial value of @poll_interval.
28 * @poll_interval_min: specifies lower bound for the poll interval. 28 * @poll_interval_min: specifies lower bound for the poll interval.
29 * Defaults to 0. 29 * Defaults to 0.
30 * @input: input device structire associated with the polled device. 30 * @input: input device structure associated with the polled device.
31 * Must be properly initialized by the driver (id, name, phys, bits). 31 * Must be properly initialized by the driver (id, name, phys, bits).
32 * 32 *
33 * Polled input device provides a skeleton for supporting simple input 33 * Polled input device provides a skeleton for supporting simple input
diff --git a/include/linux/input.h b/include/linux/input.h
index e428382ca28a..056ae8a5bd9b 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1154,8 +1154,6 @@ struct ff_effect {
1154 * sparse keymaps. If not supplied default mechanism will be used. 1154 * sparse keymaps. If not supplied default mechanism will be used.
1155 * The method is being called while holding event_lock and thus must 1155 * The method is being called while holding event_lock and thus must
1156 * not sleep 1156 * not sleep
1157 * @getkeycode_new: transition method
1158 * @setkeycode_new: transition method
1159 * @ff: force feedback structure associated with the device if device 1157 * @ff: force feedback structure associated with the device if device
1160 * supports force feedback effects 1158 * supports force feedback effects
1161 * @repeat_key: stores key code of the last key pressed; used to implement 1159 * @repeat_key: stores key code of the last key pressed; used to implement
@@ -1234,14 +1232,10 @@ struct input_dev {
1234 void *keycode; 1232 void *keycode;
1235 1233
1236 int (*setkeycode)(struct input_dev *dev, 1234 int (*setkeycode)(struct input_dev *dev,
1237 unsigned int scancode, unsigned int keycode); 1235 const struct input_keymap_entry *ke,
1236 unsigned int *old_keycode);
1238 int (*getkeycode)(struct input_dev *dev, 1237 int (*getkeycode)(struct input_dev *dev,
1239 unsigned int scancode, unsigned int *keycode); 1238 struct input_keymap_entry *ke);
1240 int (*setkeycode_new)(struct input_dev *dev,
1241 const struct input_keymap_entry *ke,
1242 unsigned int *old_keycode);
1243 int (*getkeycode_new)(struct input_dev *dev,
1244 struct input_keymap_entry *ke);
1245 1239
1246 struct ff_device *ff; 1240 struct ff_device *ff;
1247 1241
diff --git a/include/linux/magic.h b/include/linux/magic.h
index 6cfe344f9559..1e5df2af8d84 100644
--- a/include/linux/magic.h
+++ b/include/linux/magic.h
@@ -23,6 +23,7 @@
23#define XENFS_SUPER_MAGIC 0xabba1974 23#define XENFS_SUPER_MAGIC 0xabba1974
24#define EXT4_SUPER_MAGIC 0xEF53 24#define EXT4_SUPER_MAGIC 0xEF53
25#define BTRFS_SUPER_MAGIC 0x9123683E 25#define BTRFS_SUPER_MAGIC 0x9123683E
26#define NILFS_SUPER_MAGIC 0x3434
26#define HPFS_SUPER_MAGIC 0xf995e849 27#define HPFS_SUPER_MAGIC 0xf995e849
27#define ISOFS_SUPER_MAGIC 0x9660 28#define ISOFS_SUPER_MAGIC 0x9660
28#define JFFS2_SUPER_MAGIC 0x72b6 29#define JFFS2_SUPER_MAGIC 0x72b6
diff --git a/include/linux/mfd/wm831x/pdata.h b/include/linux/mfd/wm831x/pdata.h
index fd322aca33ba..173086d42af4 100644
--- a/include/linux/mfd/wm831x/pdata.h
+++ b/include/linux/mfd/wm831x/pdata.h
@@ -80,7 +80,8 @@ struct wm831x_touch_pdata {
80 int isel; /** Current for pen down (uA) */ 80 int isel; /** Current for pen down (uA) */
81 int rpu; /** Pen down sensitivity resistor divider */ 81 int rpu; /** Pen down sensitivity resistor divider */
82 int pressure; /** Report pressure (boolean) */ 82 int pressure; /** Report pressure (boolean) */
83 int data_irq; /** Touch data ready IRQ */ 83 unsigned int data_irq; /** Touch data ready IRQ */
84 unsigned int pd_irq; /** Touch pendown detect IRQ */
84}; 85};
85 86
86enum wm831x_watchdog_action { 87enum wm831x_watchdog_action {
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 8ce082781ccb..adb4888248be 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -54,6 +54,9 @@ struct mmc_ext_csd {
54 unsigned int sec_trim_mult; /* Secure trim multiplier */ 54 unsigned int sec_trim_mult; /* Secure trim multiplier */
55 unsigned int sec_erase_mult; /* Secure erase multiplier */ 55 unsigned int sec_erase_mult; /* Secure erase multiplier */
56 unsigned int trim_timeout; /* In milliseconds */ 56 unsigned int trim_timeout; /* In milliseconds */
57 bool enhanced_area_en; /* enable bit */
58 unsigned long long enhanced_area_offset; /* Units: Byte */
59 unsigned int enhanced_area_size; /* Units: KB */
57}; 60};
58 61
59struct sd_scr { 62struct sd_scr {
@@ -121,6 +124,7 @@ struct mmc_card {
121 /* for byte mode */ 124 /* for byte mode */
122#define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ 125#define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
123 /* (missing CIA registers) */ 126 /* (missing CIA registers) */
127#define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */
124 128
125 unsigned int erase_size; /* erase size in sectors */ 129 unsigned int erase_size; /* erase size in sectors */
126 unsigned int erase_shift; /* if erase unit is power 2 */ 130 unsigned int erase_shift; /* if erase unit is power 2 */
@@ -148,6 +152,8 @@ struct mmc_card {
148 struct dentry *debugfs_root; 152 struct dentry *debugfs_root;
149}; 153};
150 154
155void mmc_fixup_device(struct mmc_card *dev);
156
151#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) 157#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
152#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) 158#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
153#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO) 159#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 64e013f1cfb8..07f27af4dba5 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -160,6 +160,7 @@ extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
160 160
161extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort); 161extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
162extern void mmc_release_host(struct mmc_host *host); 162extern void mmc_release_host(struct mmc_host *host);
163extern void mmc_do_release_host(struct mmc_host *host);
163extern int mmc_try_claim_host(struct mmc_host *host); 164extern int mmc_try_claim_host(struct mmc_host *host);
164 165
165/** 166/**
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 16b0261763ed..c0207a770476 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -140,6 +140,7 @@ struct dw_mci {
140 u32 bus_hz; 140 u32 bus_hz;
141 u32 current_speed; 141 u32 current_speed;
142 u32 num_slots; 142 u32 num_slots;
143 u32 fifoth_val;
143 struct platform_device *pdev; 144 struct platform_device *pdev;
144 struct dw_mci_board *pdata; 145 struct dw_mci_board *pdata;
145 struct dw_mci_slot *slot[MAX_MCI_SLOTS]; 146 struct dw_mci_slot *slot[MAX_MCI_SLOTS];
@@ -151,6 +152,8 @@ struct dw_mci {
151 152
152 /* Workaround flags */ 153 /* Workaround flags */
153 u32 quirks; 154 u32 quirks;
155
156 struct regulator *vmmc; /* Power regulator */
154}; 157};
155 158
156/* DMA ops for Internal/External DMAC interface */ 159/* DMA ops for Internal/External DMAC interface */
@@ -165,14 +168,14 @@ struct dw_mci_dma_ops {
165}; 168};
166 169
167/* IP Quirks/flags. */ 170/* IP Quirks/flags. */
168/* No special quirks or flags to cater for */
169#define DW_MCI_QUIRK_NONE 0
170/* DTO fix for command transmission with IDMAC configured */ 171/* DTO fix for command transmission with IDMAC configured */
171#define DW_MCI_QUIRK_IDMAC_DTO 1 172#define DW_MCI_QUIRK_IDMAC_DTO BIT(0)
172/* delay needed between retries on some 2.11a implementations */ 173/* delay needed between retries on some 2.11a implementations */
173#define DW_MCI_QUIRK_RETRY_DELAY 2 174#define DW_MCI_QUIRK_RETRY_DELAY BIT(1)
174/* High Speed Capable - Supports HS cards (upto 50MHz) */ 175/* High Speed Capable - Supports HS cards (upto 50MHz) */
175#define DW_MCI_QUIRK_HIGHSPEED 4 176#define DW_MCI_QUIRK_HIGHSPEED BIT(2)
177/* Unreliable card detection */
178#define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
176 179
177 180
178struct dma_pdata; 181struct dma_pdata;
@@ -192,6 +195,8 @@ struct dw_mci_board {
192 u32 quirks; /* Workaround / Quirk flags */ 195 u32 quirks; /* Workaround / Quirk flags */
193 unsigned int bus_hz; /* Bus speed */ 196 unsigned int bus_hz; /* Bus speed */
194 197
198 unsigned int caps; /* Capabilities */
199
195 /* delay in mS before detecting cards after interrupt */ 200 /* delay in mS before detecting cards after interrupt */
196 u32 detect_delay_ms; 201 u32 detect_delay_ms;
197 202
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 612301f85d14..264ba5451e3b 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -253,6 +253,8 @@ struct _mmc_csd {
253 * EXT_CSD fields 253 * EXT_CSD fields
254 */ 254 */
255 255
256#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
257#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */
256#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ 258#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
257#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ 259#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
258#define EXT_CSD_BUS_WIDTH 183 /* R/W */ 260#define EXT_CSD_BUS_WIDTH 183 /* R/W */
@@ -262,6 +264,7 @@ struct _mmc_csd {
262#define EXT_CSD_CARD_TYPE 196 /* RO */ 264#define EXT_CSD_CARD_TYPE 196 /* RO */
263#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ 265#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
264#define EXT_CSD_S_A_TIMEOUT 217 /* RO */ 266#define EXT_CSD_S_A_TIMEOUT 217 /* RO */
267#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
265#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ 268#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */
266#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ 269#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
267#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */ 270#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */
diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h
index 227e49dd5720..8768c469e93e 100644
--- a/include/linux/nilfs2_fs.h
+++ b/include/linux/nilfs2_fs.h
@@ -40,26 +40,7 @@
40 40
41#include <linux/types.h> 41#include <linux/types.h>
42#include <linux/ioctl.h> 42#include <linux/ioctl.h>
43 43#include <linux/magic.h>
44/*
45 * Inode flags stored in nilfs_inode and on-memory nilfs inode
46 *
47 * We define these flags based on ext2-fs because of the
48 * compatibility reason; to avoid problems in chattr(1)
49 */
50#define NILFS_SECRM_FL 0x00000001 /* Secure deletion */
51#define NILFS_UNRM_FL 0x00000002 /* Undelete */
52#define NILFS_SYNC_FL 0x00000008 /* Synchronous updates */
53#define NILFS_IMMUTABLE_FL 0x00000010 /* Immutable file */
54#define NILFS_APPEND_FL 0x00000020 /* writes to file may only append */
55#define NILFS_NODUMP_FL 0x00000040 /* do not dump file */
56#define NILFS_NOATIME_FL 0x00000080 /* do not update atime */
57/* Reserved for compression usage... */
58#define NILFS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
59#define NILFS_DIRSYNC_FL 0x00010000 /* dirsync behaviour */
60
61#define NILFS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
62#define NILFS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
63 44
64 45
65#define NILFS_INODE_BMAP_SIZE 7 46#define NILFS_INODE_BMAP_SIZE 7
@@ -236,8 +217,10 @@ struct nilfs_super_block {
236 * If there is a bit set in the incompatible feature set that the kernel 217 * If there is a bit set in the incompatible feature set that the kernel
237 * doesn't know about, it should refuse to mount the filesystem. 218 * doesn't know about, it should refuse to mount the filesystem.
238 */ 219 */
220#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
221
239#define NILFS_FEATURE_COMPAT_SUPP 0ULL 222#define NILFS_FEATURE_COMPAT_SUPP 0ULL
240#define NILFS_FEATURE_COMPAT_RO_SUPP 0ULL 223#define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
241#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL 224#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
242 225
243/* 226/*
@@ -260,7 +243,6 @@ struct nilfs_super_block {
260#define NILFS_USER_INO 11 /* Fisrt user's file inode number */ 243#define NILFS_USER_INO 11 /* Fisrt user's file inode number */
261 244
262#define NILFS_SB_OFFSET_BYTES 1024 /* byte offset of nilfs superblock */ 245#define NILFS_SB_OFFSET_BYTES 1024 /* byte offset of nilfs superblock */
263#define NILFS_SUPER_MAGIC 0x3434 /* NILFS filesystem magic number */
264 246
265#define NILFS_SEG_MIN_BLOCKS 16 /* Minimum number of blocks in 247#define NILFS_SEG_MIN_BLOCKS 16 /* Minimum number of blocks in
266 a full segment */ 248 a full segment */
@@ -346,17 +328,21 @@ static inline unsigned nilfs_rec_len_from_disk(__le16 dlen)
346{ 328{
347 unsigned len = le16_to_cpu(dlen); 329 unsigned len = le16_to_cpu(dlen);
348 330
331#if !defined(__KERNEL__) || (PAGE_CACHE_SIZE >= 65536)
349 if (len == NILFS_MAX_REC_LEN) 332 if (len == NILFS_MAX_REC_LEN)
350 return 1 << 16; 333 return 1 << 16;
334#endif
351 return len; 335 return len;
352} 336}
353 337
354static inline __le16 nilfs_rec_len_to_disk(unsigned len) 338static inline __le16 nilfs_rec_len_to_disk(unsigned len)
355{ 339{
340#if !defined(__KERNEL__) || (PAGE_CACHE_SIZE >= 65536)
356 if (len == (1 << 16)) 341 if (len == (1 << 16))
357 return cpu_to_le16(NILFS_MAX_REC_LEN); 342 return cpu_to_le16(NILFS_MAX_REC_LEN);
358 else if (len > (1 << 16)) 343 else if (len > (1 << 16))
359 BUG(); 344 BUG();
345#endif
360 return cpu_to_le16(len); 346 return cpu_to_le16(len);
361} 347}
362 348
@@ -525,7 +511,7 @@ struct nilfs_checkpoint {
525 __le64 cp_create; 511 __le64 cp_create;
526 __le64 cp_nblk_inc; 512 __le64 cp_nblk_inc;
527 __le64 cp_inodes_count; 513 __le64 cp_inodes_count;
528 __le64 cp_blocks_count; /* Reserved (might be deleted) */ 514 __le64 cp_blocks_count;
529 515
530 /* Do not change the byte offset of ifile inode. 516 /* Do not change the byte offset of ifile inode.
531 To keep the compatibility of the disk format, 517 To keep the compatibility of the disk format,
diff --git a/include/linux/spi/tsc2005.h b/include/linux/spi/tsc2005.h
new file mode 100644
index 000000000000..d9b0c84220c7
--- /dev/null
+++ b/include/linux/spi/tsc2005.h
@@ -0,0 +1,41 @@
1/*
2 * This file is part of TSC2005 touchscreen driver
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * Contact: Aaro Koskinen <aaro.koskinen@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef _LINUX_SPI_TSC2005_H
25#define _LINUX_SPI_TSC2005_H
26
27#include <linux/types.h>
28
29struct tsc2005_platform_data {
30 int ts_pressure_max;
31 int ts_pressure_fudge;
32 int ts_x_max;
33 int ts_x_fudge;
34 int ts_y_max;
35 int ts_y_fudge;
36 int ts_x_plate_ohm;
37 unsigned int esd_timeout_ms;
38 void (*set_reset)(bool enable);
39};
40
41#endif
diff --git a/kernel/gcov/Makefile b/kernel/gcov/Makefile
index 3f761001d517..e97ca59e2520 100644
--- a/kernel/gcov/Makefile
+++ b/kernel/gcov/Makefile
@@ -1,3 +1,3 @@
1EXTRA_CFLAGS := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"' 1ccflags-y := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"'
2 2
3obj-$(CONFIG_GCOV_KERNEL) := base.o fs.o gcc_3_4.o 3obj-$(CONFIG_GCOV_KERNEL) := base.o fs.o gcc_3_4.o
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index c350e18b53e3..c5ebc6a90643 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -1,4 +1,5 @@
1ccflags-$(CONFIG_PM_DEBUG) := -DDEBUG 1
2ccflags-$(CONFIG_PM_DEBUG) := -DDEBUG
2 3
3obj-$(CONFIG_PM) += main.o 4obj-$(CONFIG_PM) += main.o
4obj-$(CONFIG_PM_SLEEP) += console.o 5obj-$(CONFIG_PM_SLEEP) += console.o
diff --git a/scripts/extract-ikconfig b/scripts/extract-ikconfig
index 1512c0a755ac..e1862429ccda 100755
--- a/scripts/extract-ikconfig
+++ b/scripts/extract-ikconfig
@@ -56,10 +56,11 @@ trap "rm -f $tmp1 $tmp2" 0
56dump_config "$img" 56dump_config "$img"
57 57
58# That didn't work, so retry after decompression. 58# That didn't work, so retry after decompression.
59try_decompress '\037\213\010' xy gunzip 59try_decompress '\037\213\010' xy gunzip
60try_decompress 'BZh' xy bunzip2 60try_decompress '\3757zXZ\000' abcde unxz
61try_decompress '\135\0\0\0' xxx unlzma 61try_decompress 'BZh' xy bunzip2
62try_decompress '\211\114\132' xy 'lzop -d' 62try_decompress '\135\0\0\0' xxx unlzma
63try_decompress '\211\114\132' xy 'lzop -d'
63 64
64# Bail out: 65# Bail out:
65echo "$me: Cannot find kernel config." >&2 66echo "$me: Cannot find kernel config." >&2
diff --git a/scripts/package/Makefile b/scripts/package/Makefile
index d0b931b994fc..a834b935f536 100644
--- a/scripts/package/Makefile
+++ b/scripts/package/Makefile
@@ -127,7 +127,8 @@ rm -r $(perf-tar); \
127$(if $(findstring tar-src,$@),, \ 127$(if $(findstring tar-src,$@),, \
128$(if $(findstring bz2,$@),bzip2, \ 128$(if $(findstring bz2,$@),bzip2, \
129$(if $(findstring gz,$@),gzip, \ 129$(if $(findstring gz,$@),gzip, \
130$(error unknown target $@))) \ 130$(if $(findstring xz,$@),xz, \
131$(error unknown target $@)))) \
131 -f -9 $(perf-tar).tar) 132 -f -9 $(perf-tar).tar)
132 133
133perf-%pkg: FORCE 134perf-%pkg: FORCE
@@ -142,7 +143,9 @@ help: FORCE
142 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 143 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
143 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 144 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
144 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 145 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
146 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
145 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' 147 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
146 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' 148 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
147 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' 149 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
150 @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'
148 151
diff --git a/scripts/package/buildtar b/scripts/package/buildtar
index 51b2aa0acb82..83c9c04102f2 100644
--- a/scripts/package/buildtar
+++ b/scripts/package/buildtar
@@ -35,6 +35,10 @@ case "${1}" in
35 compress="bzip2 -c9" 35 compress="bzip2 -c9"
36 file_ext=".bz2" 36 file_ext=".bz2"
37 ;; 37 ;;
38 tarxz-pkg)
39 compress="xz -c9"
40 file_ext=".xz"
41 ;;
38 *) 42 *)
39 echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2 43 echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2
40 exit 1 44 exit 1
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index ef8729f48586..4d403844e137 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -86,12 +86,16 @@ scm_version()
86 86
87 # Check for mercurial and a mercurial repo. 87 # Check for mercurial and a mercurial repo.
88 if test -d .hg && hgid=`hg id 2>/dev/null`; then 88 if test -d .hg && hgid=`hg id 2>/dev/null`; then
89 tag=`printf '%s' "$hgid" | cut -s -d' ' -f2` 89 # Do we have an tagged version? If so, latesttagdistance == 1
90 90 if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
91 # Do we have an untagged version? 91 id=`hg log -r . --template '{latesttag}'`
92 if [ -z "$tag" -o "$tag" = tip ]; then
93 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
94 printf '%s%s' -hg "$id" 92 printf '%s%s' -hg "$id"
93 else
94 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
95 if [ -z "$tag" -o "$tag" = tip ]; then
96 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
97 printf '%s%s' -hg "$id"
98 fi
95 fi 99 fi
96 100
97 # Are there uncommitted changes? 101 # Are there uncommitted changes?
diff --git a/scripts/tags.sh b/scripts/tags.sh
index 92fdc4546141..bd6185d529cf 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -114,6 +114,11 @@ docscope()
114 cscope -b -f cscope.out 114 cscope -b -f cscope.out
115} 115}
116 116
117dogtags()
118{
119 all_sources | gtags -f -
120}
121
117exuberant() 122exuberant()
118{ 123{
119 all_sources | xargs $1 -a \ 124 all_sources | xargs $1 -a \
@@ -187,6 +192,10 @@ case "$1" in
187 docscope 192 docscope
188 ;; 193 ;;
189 194
195 "gtags")
196 dogtags
197 ;;
198
190 "tags") 199 "tags")
191 rm -f tags 200 rm -f tags
192 xtags ctags 201 xtags ctags