aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/stable/sysfs-bus-usb8
-rw-r--r--Documentation/ABI/testing/sysfs-devices-power32
-rw-r--r--Documentation/ABI/testing/sysfs-power22
-rw-r--r--Documentation/acpi/dsdt-override.txt2
-rw-r--r--Documentation/devicetree/bindings/memory.txt168
-rw-r--r--Documentation/devicetree/bindings/spi/sh-hspi.txt7
-rw-r--r--Documentation/driver-model/devres.txt3
-rw-r--r--MAINTAINERS32
-rw-r--r--Makefile2
-rw-r--r--arch/arm/common/mcpm_entry.c6
-rw-r--r--arch/arm/common/sharpsl_param.c5
-rw-r--r--arch/arm/include/asm/Kbuild1
-rw-r--r--arch/arm/include/asm/mcpm.h14
-rw-r--r--arch/arm/include/asm/syscall.h6
-rw-r--r--arch/arm/kernel/head.S21
-rw-r--r--arch/arm/mm/dma-mapping.c43
-rw-r--r--arch/arm/mm/init.c3
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c2
-rw-r--r--arch/x86/kernel/kvm.c17
-rw-r--r--arch/x86/xen/smp.c9
-rw-r--r--block/partitions/efi.c7
-rw-r--r--drivers/acpi/Kconfig8
-rw-r--r--drivers/acpi/device_pm.c56
-rw-r--r--drivers/acpi/power.c104
-rw-r--r--drivers/acpi/scan.c1
-rw-r--r--drivers/ata/libata-acpi.c14
-rw-r--r--drivers/ata/libata-scsi.c3
-rw-r--r--drivers/ata/libata.h4
-rw-r--r--drivers/base/memory.c7
-rw-r--r--drivers/char/tpm/xen-tpmfront.c1
-rw-r--r--drivers/cpufreq/intel_pstate.c14
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c2
-rw-r--r--drivers/gpio/gpio-lynxpoint.c5
-rw-r--r--drivers/gpio/gpiolib.c6
-rw-r--r--drivers/iio/frequency/adf4350.c6
-rw-r--r--drivers/iio/industrialio-buffer.c3
-rw-r--r--drivers/infiniband/hw/amso1100/c2_ae.c2
-rw-r--r--drivers/infiniband/hw/mlx5/main.c16
-rw-r--r--drivers/infiniband/hw/mlx5/mr.c70
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c80
-rw-r--r--drivers/infiniband/hw/mlx5/srq.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c2
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_hw.c6
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_main.c2
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c6
-rw-r--r--drivers/md/dm-snap-persistent.c18
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/cmd.c28
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eq.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c21
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c16
-rw-r--r--drivers/of/Kconfig6
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/base.c4
-rw-r--r--drivers/of/fdt.c12
-rw-r--r--drivers/of/of_reserved_mem.c173
-rw-r--r--drivers/of/platform.c4
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c8
-rw-r--r--drivers/spi/Kconfig5
-rw-r--r--drivers/spi/spi-altera.c2
-rw-r--r--drivers/spi/spi-ath79.c2
-rw-r--r--drivers/spi/spi-atmel.c50
-rw-r--r--drivers/spi/spi-au1550.c5
-rw-r--r--drivers/spi/spi-bcm2835.c4
-rw-r--r--drivers/spi/spi-bcm63xx.c6
-rw-r--r--drivers/spi/spi-bfin-sport.c29
-rw-r--r--drivers/spi/spi-bfin-v3.c3
-rw-r--r--drivers/spi/spi-bfin5xx.c48
-rw-r--r--drivers/spi/spi-bitbang.c25
-rw-r--r--drivers/spi/spi-butterfly.c15
-rw-r--r--drivers/spi/spi-clps711x.c7
-rw-r--r--drivers/spi/spi-davinci.c13
-rw-r--r--drivers/spi/spi-dw-mmio.c5
-rw-r--r--drivers/spi/spi-dw-pci.c3
-rw-r--r--drivers/spi/spi-dw.c4
-rw-r--r--drivers/spi/spi-efm32.c12
-rw-r--r--drivers/spi/spi-ep93xx.c7
-rw-r--r--drivers/spi/spi-fsl-cpm.c2
-rw-r--r--drivers/spi/spi-fsl-dspi.c10
-rw-r--r--drivers/spi/spi-fsl-espi.c4
-rw-r--r--drivers/spi/spi-gpio.c6
-rw-r--r--drivers/spi/spi-imx.c35
-rw-r--r--drivers/spi/spi-lm70llp.c2
-rw-r--r--drivers/spi/spi-mpc512x-psc.c4
-rw-r--r--drivers/spi/spi-mpc52xx-psc.c4
-rw-r--r--drivers/spi/spi-mxs.c193
-rw-r--r--drivers/spi/spi-nuc900.c3
-rw-r--r--drivers/spi/spi-oc-tiny.c2
-rw-r--r--drivers/spi/spi-octeon.c4
-rw-r--r--drivers/spi/spi-omap-100k.c4
-rw-r--r--drivers/spi/spi-omap-uwire.c5
-rw-r--r--drivers/spi/spi-omap2-mcspi.c19
-rw-r--r--drivers/spi/spi-orion.c10
-rw-r--r--drivers/spi/spi-pl022.c10
-rw-r--r--drivers/spi/spi-ppc4xx.c3
-rw-r--r--drivers/spi/spi-pxa2xx.c41
-rw-r--r--drivers/spi/spi-rspi.c270
-rw-r--r--drivers/spi/spi-s3c24xx.c4
-rw-r--r--drivers/spi/spi-s3c64xx.c260
-rw-r--r--drivers/spi/spi-sh-hspi.c13
-rw-r--r--drivers/spi/spi-sh-sci.c2
-rw-r--r--drivers/spi/spi-sirf.c2
-rw-r--r--drivers/spi/spi-tegra114.c90
-rw-r--r--drivers/spi/spi-tegra20-sflash.c5
-rw-r--r--drivers/spi/spi-tegra20-slink.c144
-rw-r--r--drivers/spi/spi-ti-qspi.c46
-rw-r--r--drivers/spi/spi-topcliff-pch.c17
-rw-r--r--drivers/spi/spi-txx9.c7
-rw-r--r--drivers/spi/spi-xilinx.c2
-rw-r--r--drivers/spi/spi.c244
-rw-r--r--drivers/spi/spidev.c7
-rw-r--r--drivers/tty/serial/imx.c3
-rw-r--r--drivers/tty/serial/vt8500_serial.c5
-rw-r--r--drivers/usb/chipidea/host.c6
-rw-r--r--drivers/usb/core/quirks.c6
-rw-r--r--drivers/usb/host/pci-quirks.c4
-rw-r--r--drivers/usb/host/xhci-hub.c26
-rw-r--r--drivers/usb/host/xhci-pci.c25
-rw-r--r--drivers/usb/host/xhci.c14
-rw-r--r--drivers/usb/host/xhci.h2
-rw-r--r--drivers/usb/misc/Kconfig2
-rw-r--r--drivers/usb/musb/musb_core.c46
-rw-r--r--drivers/usb/musb/musb_core.h1
-rw-r--r--drivers/usb/musb/musb_gadget.c3
-rw-r--r--drivers/usb/musb/musb_virthub.c46
-rw-r--r--drivers/usb/serial/option.c225
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c1
-rw-r--r--drivers/usb/storage/scsiglue.c5
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/vfio/vfio_iommu_type1.c40
-rw-r--r--drivers/w1/w1.c6
-rw-r--r--fs/btrfs/inode.c1
-rw-r--r--fs/buffer.c14
-rw-r--r--fs/cifs/cifsfs.c6
-rw-r--r--fs/cifs/cifspdu.h31
-rw-r--r--fs/cifs/cifssmb.c40
-rw-r--r--fs/cifs/netmisc.c4
-rw-r--r--fs/cifs/sess.c4
-rw-r--r--fs/cifs/smb2pdu.c6
-rw-r--r--fs/cifs/smbfsctl.h14
-rw-r--r--fs/cifs/transport.c9
-rw-r--r--fs/ext3/namei.c5
-rw-r--r--fs/ext4/namei.c5
-rw-r--r--fs/proc/inode.c10
-rw-r--r--fs/proc/task_mmu.c4
-rw-r--r--include/acpi/acpi_bus.h7
-rw-r--r--include/linux/memcontrol.h50
-rw-r--r--include/linux/mlx5/device.h4
-rw-r--r--include/linux/mlx5/driver.h6
-rw-r--r--include/linux/of_reserved_mem.h14
-rw-r--r--include/linux/sched.h7
-rw-r--r--include/linux/spi/rspi.h2
-rw-r--r--include/linux/spi/spi.h34
-rw-r--r--include/linux/usb/usb_phy_gen_xceiv.h2
-rw-r--r--include/linux/usb_usual.h4
-rw-r--r--include/trace/events/spi.h156
-rw-r--r--ipc/sem.c42
-rw-r--r--ipc/util.c27
-rw-r--r--lib/percpu-refcount.c3
-rw-r--r--mm/filemap.c11
-rw-r--r--mm/huge_memory.c10
-rw-r--r--mm/hugetlb.c17
-rw-r--r--mm/memcontrol.c143
-rw-r--r--mm/memory.c20
-rw-r--r--mm/migrate.c2
-rw-r--r--mm/mprotect.c7
-rw-r--r--mm/mremap.c5
-rw-r--r--mm/oom_kill.c2
-rw-r--r--mm/page-writeback.c10
-rw-r--r--mm/slab_common.c2
-rw-r--r--mm/swapfile.c4
-rw-r--r--mm/vmscan.c1
-rw-r--r--mm/zswap.c4
-rw-r--r--security/apparmor/apparmorfs.c4
-rw-r--r--security/apparmor/policy.c1
-rw-r--r--sound/pci/hda/hda_generic.c2
-rw-r--r--sound/pci/rme9652/hdsp.c1
-rw-r--r--sound/usb/usx2y/us122l.c4
-rw-r--r--tools/testing/selftests/timers/posix_timers.c2
179 files changed, 2256 insertions, 1827 deletions
diff --git a/Documentation/ABI/stable/sysfs-bus-usb b/Documentation/ABI/stable/sysfs-bus-usb
index 2be603c52a24..a6b685724740 100644
--- a/Documentation/ABI/stable/sysfs-bus-usb
+++ b/Documentation/ABI/stable/sysfs-bus-usb
@@ -37,8 +37,8 @@ Description:
37 that the USB device has been connected to the machine. This 37 that the USB device has been connected to the machine. This
38 file is read-only. 38 file is read-only.
39Users: 39Users:
40 PowerTOP <power@bughost.org> 40 PowerTOP <powertop@lists.01.org>
41 http://www.lesswatts.org/projects/powertop/ 41 https://01.org/powertop/
42 42
43What: /sys/bus/usb/device/.../power/active_duration 43What: /sys/bus/usb/device/.../power/active_duration
44Date: January 2008 44Date: January 2008
@@ -57,8 +57,8 @@ Description:
57 will give an integer percentage. Note that this does not 57 will give an integer percentage. Note that this does not
58 account for counter wrap. 58 account for counter wrap.
59Users: 59Users:
60 PowerTOP <power@bughost.org> 60 PowerTOP <powertop@lists.01.org>
61 http://www.lesswatts.org/projects/powertop/ 61 https://01.org/powertop/
62 62
63What: /sys/bus/usb/devices/<busnum>-<port[.port]>...:<config num>-<interface num>/supports_autosuspend 63What: /sys/bus/usb/devices/<busnum>-<port[.port]>...:<config num>-<interface num>/supports_autosuspend
64Date: January 2008 64Date: January 2008
diff --git a/Documentation/ABI/testing/sysfs-devices-power b/Documentation/ABI/testing/sysfs-devices-power
index 9d43e7670841..efe449bdf811 100644
--- a/Documentation/ABI/testing/sysfs-devices-power
+++ b/Documentation/ABI/testing/sysfs-devices-power
@@ -1,6 +1,6 @@
1What: /sys/devices/.../power/ 1What: /sys/devices/.../power/
2Date: January 2009 2Date: January 2009
3Contact: Rafael J. Wysocki <rjw@sisk.pl> 3Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
4Description: 4Description:
5 The /sys/devices/.../power directory contains attributes 5 The /sys/devices/.../power directory contains attributes
6 allowing the user space to check and modify some power 6 allowing the user space to check and modify some power
@@ -8,7 +8,7 @@ Description:
8 8
9What: /sys/devices/.../power/wakeup 9What: /sys/devices/.../power/wakeup
10Date: January 2009 10Date: January 2009
11Contact: Rafael J. Wysocki <rjw@sisk.pl> 11Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
12Description: 12Description:
13 The /sys/devices/.../power/wakeup attribute allows the user 13 The /sys/devices/.../power/wakeup attribute allows the user
14 space to check if the device is enabled to wake up the system 14 space to check if the device is enabled to wake up the system
@@ -34,7 +34,7 @@ Description:
34 34
35What: /sys/devices/.../power/control 35What: /sys/devices/.../power/control
36Date: January 2009 36Date: January 2009
37Contact: Rafael J. Wysocki <rjw@sisk.pl> 37Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
38Description: 38Description:
39 The /sys/devices/.../power/control attribute allows the user 39 The /sys/devices/.../power/control attribute allows the user
40 space to control the run-time power management of the device. 40 space to control the run-time power management of the device.
@@ -53,7 +53,7 @@ Description:
53 53
54What: /sys/devices/.../power/async 54What: /sys/devices/.../power/async
55Date: January 2009 55Date: January 2009
56Contact: Rafael J. Wysocki <rjw@sisk.pl> 56Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
57Description: 57Description:
58 The /sys/devices/.../async attribute allows the user space to 58 The /sys/devices/.../async attribute allows the user space to
59 enable or diasble the device's suspend and resume callbacks to 59 enable or diasble the device's suspend and resume callbacks to
@@ -79,7 +79,7 @@ Description:
79 79
80What: /sys/devices/.../power/wakeup_count 80What: /sys/devices/.../power/wakeup_count
81Date: September 2010 81Date: September 2010
82Contact: Rafael J. Wysocki <rjw@sisk.pl> 82Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
83Description: 83Description:
84 The /sys/devices/.../wakeup_count attribute contains the number 84 The /sys/devices/.../wakeup_count attribute contains the number
85 of signaled wakeup events associated with the device. This 85 of signaled wakeup events associated with the device. This
@@ -88,7 +88,7 @@ Description:
88 88
89What: /sys/devices/.../power/wakeup_active_count 89What: /sys/devices/.../power/wakeup_active_count
90Date: September 2010 90Date: September 2010
91Contact: Rafael J. Wysocki <rjw@sisk.pl> 91Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
92Description: 92Description:
93 The /sys/devices/.../wakeup_active_count attribute contains the 93 The /sys/devices/.../wakeup_active_count attribute contains the
94 number of times the processing of wakeup events associated with 94 number of times the processing of wakeup events associated with
@@ -98,7 +98,7 @@ Description:
98 98
99What: /sys/devices/.../power/wakeup_abort_count 99What: /sys/devices/.../power/wakeup_abort_count
100Date: February 2012 100Date: February 2012
101Contact: Rafael J. Wysocki <rjw@sisk.pl> 101Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
102Description: 102Description:
103 The /sys/devices/.../wakeup_abort_count attribute contains the 103 The /sys/devices/.../wakeup_abort_count attribute contains the
104 number of times the processing of a wakeup event associated with 104 number of times the processing of a wakeup event associated with
@@ -109,7 +109,7 @@ Description:
109 109
110What: /sys/devices/.../power/wakeup_expire_count 110What: /sys/devices/.../power/wakeup_expire_count
111Date: February 2012 111Date: February 2012
112Contact: Rafael J. Wysocki <rjw@sisk.pl> 112Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
113Description: 113Description:
114 The /sys/devices/.../wakeup_expire_count attribute contains the 114 The /sys/devices/.../wakeup_expire_count attribute contains the
115 number of times a wakeup event associated with the device has 115 number of times a wakeup event associated with the device has
@@ -119,7 +119,7 @@ Description:
119 119
120What: /sys/devices/.../power/wakeup_active 120What: /sys/devices/.../power/wakeup_active
121Date: September 2010 121Date: September 2010
122Contact: Rafael J. Wysocki <rjw@sisk.pl> 122Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
123Description: 123Description:
124 The /sys/devices/.../wakeup_active attribute contains either 1, 124 The /sys/devices/.../wakeup_active attribute contains either 1,
125 or 0, depending on whether or not a wakeup event associated with 125 or 0, depending on whether or not a wakeup event associated with
@@ -129,7 +129,7 @@ Description:
129 129
130What: /sys/devices/.../power/wakeup_total_time_ms 130What: /sys/devices/.../power/wakeup_total_time_ms
131Date: September 2010 131Date: September 2010
132Contact: Rafael J. Wysocki <rjw@sisk.pl> 132Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
133Description: 133Description:
134 The /sys/devices/.../wakeup_total_time_ms attribute contains 134 The /sys/devices/.../wakeup_total_time_ms attribute contains
135 the total time of processing wakeup events associated with the 135 the total time of processing wakeup events associated with the
@@ -139,7 +139,7 @@ Description:
139 139
140What: /sys/devices/.../power/wakeup_max_time_ms 140What: /sys/devices/.../power/wakeup_max_time_ms
141Date: September 2010 141Date: September 2010
142Contact: Rafael J. Wysocki <rjw@sisk.pl> 142Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
143Description: 143Description:
144 The /sys/devices/.../wakeup_max_time_ms attribute contains 144 The /sys/devices/.../wakeup_max_time_ms attribute contains
145 the maximum time of processing a single wakeup event associated 145 the maximum time of processing a single wakeup event associated
@@ -149,7 +149,7 @@ Description:
149 149
150What: /sys/devices/.../power/wakeup_last_time_ms 150What: /sys/devices/.../power/wakeup_last_time_ms
151Date: September 2010 151Date: September 2010
152Contact: Rafael J. Wysocki <rjw@sisk.pl> 152Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
153Description: 153Description:
154 The /sys/devices/.../wakeup_last_time_ms attribute contains 154 The /sys/devices/.../wakeup_last_time_ms attribute contains
155 the value of the monotonic clock corresponding to the time of 155 the value of the monotonic clock corresponding to the time of
@@ -160,7 +160,7 @@ Description:
160 160
161What: /sys/devices/.../power/wakeup_prevent_sleep_time_ms 161What: /sys/devices/.../power/wakeup_prevent_sleep_time_ms
162Date: February 2012 162Date: February 2012
163Contact: Rafael J. Wysocki <rjw@sisk.pl> 163Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
164Description: 164Description:
165 The /sys/devices/.../wakeup_prevent_sleep_time_ms attribute 165 The /sys/devices/.../wakeup_prevent_sleep_time_ms attribute
166 contains the total time the device has been preventing 166 contains the total time the device has been preventing
@@ -189,7 +189,7 @@ Description:
189 189
190What: /sys/devices/.../power/pm_qos_latency_us 190What: /sys/devices/.../power/pm_qos_latency_us
191Date: March 2012 191Date: March 2012
192Contact: Rafael J. Wysocki <rjw@sisk.pl> 192Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
193Description: 193Description:
194 The /sys/devices/.../power/pm_qos_resume_latency_us attribute 194 The /sys/devices/.../power/pm_qos_resume_latency_us attribute
195 contains the PM QoS resume latency limit for the given device, 195 contains the PM QoS resume latency limit for the given device,
@@ -207,7 +207,7 @@ Description:
207 207
208What: /sys/devices/.../power/pm_qos_no_power_off 208What: /sys/devices/.../power/pm_qos_no_power_off
209Date: September 2012 209Date: September 2012
210Contact: Rafael J. Wysocki <rjw@sisk.pl> 210Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
211Description: 211Description:
212 The /sys/devices/.../power/pm_qos_no_power_off attribute 212 The /sys/devices/.../power/pm_qos_no_power_off attribute
213 is used for manipulating the PM QoS "no power off" flag. If 213 is used for manipulating the PM QoS "no power off" flag. If
@@ -222,7 +222,7 @@ Description:
222 222
223What: /sys/devices/.../power/pm_qos_remote_wakeup 223What: /sys/devices/.../power/pm_qos_remote_wakeup
224Date: September 2012 224Date: September 2012
225Contact: Rafael J. Wysocki <rjw@sisk.pl> 225Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
226Description: 226Description:
227 The /sys/devices/.../power/pm_qos_remote_wakeup attribute 227 The /sys/devices/.../power/pm_qos_remote_wakeup attribute
228 is used for manipulating the PM QoS "remote wakeup required" 228 is used for manipulating the PM QoS "remote wakeup required"
diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index 217772615d02..205a73878441 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -1,6 +1,6 @@
1What: /sys/power/ 1What: /sys/power/
2Date: August 2006 2Date: August 2006
3Contact: Rafael J. Wysocki <rjw@sisk.pl> 3Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
4Description: 4Description:
5 The /sys/power directory will contain files that will 5 The /sys/power directory will contain files that will
6 provide a unified interface to the power management 6 provide a unified interface to the power management
@@ -8,7 +8,7 @@ Description:
8 8
9What: /sys/power/state 9What: /sys/power/state
10Date: August 2006 10Date: August 2006
11Contact: Rafael J. Wysocki <rjw@sisk.pl> 11Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
12Description: 12Description:
13 The /sys/power/state file controls the system power state. 13 The /sys/power/state file controls the system power state.
14 Reading from this file returns what states are supported, 14 Reading from this file returns what states are supported,
@@ -22,7 +22,7 @@ Description:
22 22
23What: /sys/power/disk 23What: /sys/power/disk
24Date: September 2006 24Date: September 2006
25Contact: Rafael J. Wysocki <rjw@sisk.pl> 25Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
26Description: 26Description:
27 The /sys/power/disk file controls the operating mode of the 27 The /sys/power/disk file controls the operating mode of the
28 suspend-to-disk mechanism. Reading from this file returns 28 suspend-to-disk mechanism. Reading from this file returns
@@ -67,7 +67,7 @@ Description:
67 67
68What: /sys/power/image_size 68What: /sys/power/image_size
69Date: August 2006 69Date: August 2006
70Contact: Rafael J. Wysocki <rjw@sisk.pl> 70Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
71Description: 71Description:
72 The /sys/power/image_size file controls the size of the image 72 The /sys/power/image_size file controls the size of the image
73 created by the suspend-to-disk mechanism. It can be written a 73 created by the suspend-to-disk mechanism. It can be written a
@@ -84,7 +84,7 @@ Description:
84 84
85What: /sys/power/pm_trace 85What: /sys/power/pm_trace
86Date: August 2006 86Date: August 2006
87Contact: Rafael J. Wysocki <rjw@sisk.pl> 87Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
88Description: 88Description:
89 The /sys/power/pm_trace file controls the code which saves the 89 The /sys/power/pm_trace file controls the code which saves the
90 last PM event point in the RTC across reboots, so that you can 90 last PM event point in the RTC across reboots, so that you can
@@ -133,7 +133,7 @@ Description:
133 133
134What: /sys/power/pm_async 134What: /sys/power/pm_async
135Date: January 2009 135Date: January 2009
136Contact: Rafael J. Wysocki <rjw@sisk.pl> 136Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
137Description: 137Description:
138 The /sys/power/pm_async file controls the switch allowing the 138 The /sys/power/pm_async file controls the switch allowing the
139 user space to enable or disable asynchronous suspend and resume 139 user space to enable or disable asynchronous suspend and resume
@@ -146,7 +146,7 @@ Description:
146 146
147What: /sys/power/wakeup_count 147What: /sys/power/wakeup_count
148Date: July 2010 148Date: July 2010
149Contact: Rafael J. Wysocki <rjw@sisk.pl> 149Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
150Description: 150Description:
151 The /sys/power/wakeup_count file allows user space to put the 151 The /sys/power/wakeup_count file allows user space to put the
152 system into a sleep state while taking into account the 152 system into a sleep state while taking into account the
@@ -161,7 +161,7 @@ Description:
161 161
162What: /sys/power/reserved_size 162What: /sys/power/reserved_size
163Date: May 2011 163Date: May 2011
164Contact: Rafael J. Wysocki <rjw@sisk.pl> 164Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
165Description: 165Description:
166 The /sys/power/reserved_size file allows user space to control 166 The /sys/power/reserved_size file allows user space to control
167 the amount of memory reserved for allocations made by device 167 the amount of memory reserved for allocations made by device
@@ -175,7 +175,7 @@ Description:
175 175
176What: /sys/power/autosleep 176What: /sys/power/autosleep
177Date: April 2012 177Date: April 2012
178Contact: Rafael J. Wysocki <rjw@sisk.pl> 178Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
179Description: 179Description:
180 The /sys/power/autosleep file can be written one of the strings 180 The /sys/power/autosleep file can be written one of the strings
181 returned by reads from /sys/power/state. If that happens, a 181 returned by reads from /sys/power/state. If that happens, a
@@ -192,7 +192,7 @@ Description:
192 192
193What: /sys/power/wake_lock 193What: /sys/power/wake_lock
194Date: February 2012 194Date: February 2012
195Contact: Rafael J. Wysocki <rjw@sisk.pl> 195Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
196Description: 196Description:
197 The /sys/power/wake_lock file allows user space to create 197 The /sys/power/wake_lock file allows user space to create
198 wakeup source objects and activate them on demand (if one of 198 wakeup source objects and activate them on demand (if one of
@@ -219,7 +219,7 @@ Description:
219 219
220What: /sys/power/wake_unlock 220What: /sys/power/wake_unlock
221Date: February 2012 221Date: February 2012
222Contact: Rafael J. Wysocki <rjw@sisk.pl> 222Contact: Rafael J. Wysocki <rjw@rjwysocki.net>
223Description: 223Description:
224 The /sys/power/wake_unlock file allows user space to deactivate 224 The /sys/power/wake_unlock file allows user space to deactivate
225 wakeup sources created with the help of /sys/power/wake_lock. 225 wakeup sources created with the help of /sys/power/wake_lock.
diff --git a/Documentation/acpi/dsdt-override.txt b/Documentation/acpi/dsdt-override.txt
index febbb1ba4d23..784841caa6e6 100644
--- a/Documentation/acpi/dsdt-override.txt
+++ b/Documentation/acpi/dsdt-override.txt
@@ -4,4 +4,4 @@ CONFIG_ACPI_CUSTOM_DSDT builds the image into the kernel.
4 4
5When to use this method is described in detail on the 5When to use this method is described in detail on the
6Linux/ACPI home page: 6Linux/ACPI home page:
7http://www.lesswatts.org/projects/acpi/overridingDSDT.php 7https://01.org/linux-acpi/documentation/overriding-dsdt
diff --git a/Documentation/devicetree/bindings/memory.txt b/Documentation/devicetree/bindings/memory.txt
deleted file mode 100644
index eb2469365593..000000000000
--- a/Documentation/devicetree/bindings/memory.txt
+++ /dev/null
@@ -1,168 +0,0 @@
1*** Memory binding ***
2
3The /memory node provides basic information about the address and size
4of the physical memory. This node is usually filled or updated by the
5bootloader, depending on the actual memory configuration of the given
6hardware.
7
8The memory layout is described by the following node:
9
10/ {
11 #address-cells = <(n)>;
12 #size-cells = <(m)>;
13 memory {
14 device_type = "memory";
15 reg = <(baseaddr1) (size1)
16 (baseaddr2) (size2)
17 ...
18 (baseaddrN) (sizeN)>;
19 };
20 ...
21};
22
23A memory node follows the typical device tree rules for "reg" property:
24n: number of cells used to store base address value
25m: number of cells used to store size value
26baseaddrX: defines a base address of the defined memory bank
27sizeX: the size of the defined memory bank
28
29
30More than one memory bank can be defined.
31
32
33*** Reserved memory regions ***
34
35In /memory/reserved-memory node one can create child nodes describing
36particular reserved (excluded from normal use) memory regions. Such
37memory regions are usually designed for the special usage by various
38device drivers. A good example are contiguous memory allocations or
39memory sharing with other operating system on the same hardware board.
40Those special memory regions might depend on the board configuration and
41devices used on the target system.
42
43Parameters for each memory region can be encoded into the device tree
44with the following convention:
45
46[(label):] (name) {
47 compatible = "linux,contiguous-memory-region", "reserved-memory-region";
48 reg = <(address) (size)>;
49 (linux,default-contiguous-region);
50};
51
52compatible: one or more of:
53 - "linux,contiguous-memory-region" - enables binding of this
54 region to Contiguous Memory Allocator (special region for
55 contiguous memory allocations, shared with movable system
56 memory, Linux kernel-specific).
57 - "reserved-memory-region" - compatibility is defined, given
58 region is assigned for exclusive usage for by the respective
59 devices.
60
61reg: standard property defining the base address and size of
62 the memory region
63
64linux,default-contiguous-region: property indicating that the region
65 is the default region for all contiguous memory
66 allocations, Linux specific (optional)
67
68It is optional to specify the base address, so if one wants to use
69autoconfiguration of the base address, '0' can be specified as a base
70address in the 'reg' property.
71
72The /memory/reserved-memory node must contain the same #address-cells
73and #size-cells value as the root node.
74
75
76*** Device node's properties ***
77
78Once regions in the /memory/reserved-memory node have been defined, they
79may be referenced by other device nodes. Bindings that wish to reference
80memory regions should explicitly document their use of the following
81property:
82
83memory-region = <&phandle_to_defined_region>;
84
85This property indicates that the device driver should use the memory
86region pointed by the given phandle.
87
88
89*** Example ***
90
91This example defines a memory consisting of 4 memory banks. 3 contiguous
92regions are defined for Linux kernel, one default of all device drivers
93(named contig_mem, placed at 0x72000000, 64MiB), one dedicated to the
94framebuffer device (labelled display_mem, placed at 0x78000000, 8MiB)
95and one for multimedia processing (labelled multimedia_mem, placed at
960x77000000, 64MiB). 'display_mem' region is then assigned to fb@12300000
97device for DMA memory allocations (Linux kernel drivers will use CMA is
98available or dma-exclusive usage otherwise). 'multimedia_mem' is
99assigned to scaler@12500000 and codec@12600000 devices for contiguous
100memory allocations when CMA driver is enabled.
101
102The reason for creating a separate region for framebuffer device is to
103match the framebuffer base address to the one configured by bootloader,
104so once Linux kernel drivers starts no glitches on the displayed boot
105logo appears. Scaller and codec drivers should share the memory
106allocations.
107
108/ {
109 #address-cells = <1>;
110 #size-cells = <1>;
111
112 /* ... */
113
114 memory {
115 reg = <0x40000000 0x10000000
116 0x50000000 0x10000000
117 0x60000000 0x10000000
118 0x70000000 0x10000000>;
119
120 reserved-memory {
121 #address-cells = <1>;
122 #size-cells = <1>;
123
124 /*
125 * global autoconfigured region for contiguous allocations
126 * (used only with Contiguous Memory Allocator)
127 */
128 contig_region@0 {
129 compatible = "linux,contiguous-memory-region";
130 reg = <0x0 0x4000000>;
131 linux,default-contiguous-region;
132 };
133
134 /*
135 * special region for framebuffer
136 */
137 display_region: region@78000000 {
138 compatible = "linux,contiguous-memory-region", "reserved-memory-region";
139 reg = <0x78000000 0x800000>;
140 };
141
142 /*
143 * special region for multimedia processing devices
144 */
145 multimedia_region: region@77000000 {
146 compatible = "linux,contiguous-memory-region";
147 reg = <0x77000000 0x4000000>;
148 };
149 };
150 };
151
152 /* ... */
153
154 fb0: fb@12300000 {
155 status = "okay";
156 memory-region = <&display_region>;
157 };
158
159 scaler: scaler@12500000 {
160 status = "okay";
161 memory-region = <&multimedia_region>;
162 };
163
164 codec: codec@12600000 {
165 status = "okay";
166 memory-region = <&multimedia_region>;
167 };
168};
diff --git a/Documentation/devicetree/bindings/spi/sh-hspi.txt b/Documentation/devicetree/bindings/spi/sh-hspi.txt
new file mode 100644
index 000000000000..30b57b1c8a13
--- /dev/null
+++ b/Documentation/devicetree/bindings/spi/sh-hspi.txt
@@ -0,0 +1,7 @@
1Renesas HSPI.
2
3Required properties:
4- compatible : "renesas,hspi"
5- reg : Offset and length of the register set for the device
6- interrupts : interrupt line used by HSPI
7
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index fcb34a5697ea..84ea8216cc7d 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -302,3 +302,6 @@ PHY
302 302
303SLAVE DMA ENGINE 303SLAVE DMA ENGINE
304 devm_acpi_dma_controller_register() 304 devm_acpi_dma_controller_register()
305
306SPI
307 devm_spi_register_master()
diff --git a/MAINTAINERS b/MAINTAINERS
index 8a0cbf3cf2c8..a7c34ef3509d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -237,11 +237,11 @@ F: drivers/platform/x86/acer-wmi.c
237 237
238ACPI 238ACPI
239M: Len Brown <lenb@kernel.org> 239M: Len Brown <lenb@kernel.org>
240M: Rafael J. Wysocki <rjw@sisk.pl> 240M: Rafael J. Wysocki <rjw@rjwysocki.net>
241L: linux-acpi@vger.kernel.org 241L: linux-acpi@vger.kernel.org
242W: http://www.lesswatts.org/projects/acpi/ 242W: https://01.org/linux-acpi
243Q: http://patchwork.kernel.org/project/linux-acpi/list/ 243Q: https://patchwork.kernel.org/project/linux-acpi/list/
244T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux 244T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
245S: Supported 245S: Supported
246F: drivers/acpi/ 246F: drivers/acpi/
247F: drivers/pnp/pnpacpi/ 247F: drivers/pnp/pnpacpi/
@@ -256,21 +256,21 @@ F: drivers/pci/*/*/*acpi*
256ACPI FAN DRIVER 256ACPI FAN DRIVER
257M: Zhang Rui <rui.zhang@intel.com> 257M: Zhang Rui <rui.zhang@intel.com>
258L: linux-acpi@vger.kernel.org 258L: linux-acpi@vger.kernel.org
259W: http://www.lesswatts.org/projects/acpi/ 259W: https://01.org/linux-acpi
260S: Supported 260S: Supported
261F: drivers/acpi/fan.c 261F: drivers/acpi/fan.c
262 262
263ACPI THERMAL DRIVER 263ACPI THERMAL DRIVER
264M: Zhang Rui <rui.zhang@intel.com> 264M: Zhang Rui <rui.zhang@intel.com>
265L: linux-acpi@vger.kernel.org 265L: linux-acpi@vger.kernel.org
266W: http://www.lesswatts.org/projects/acpi/ 266W: https://01.org/linux-acpi
267S: Supported 267S: Supported
268F: drivers/acpi/*thermal* 268F: drivers/acpi/*thermal*
269 269
270ACPI VIDEO DRIVER 270ACPI VIDEO DRIVER
271M: Zhang Rui <rui.zhang@intel.com> 271M: Zhang Rui <rui.zhang@intel.com>
272L: linux-acpi@vger.kernel.org 272L: linux-acpi@vger.kernel.org
273W: http://www.lesswatts.org/projects/acpi/ 273W: https://01.org/linux-acpi
274S: Supported 274S: Supported
275F: drivers/acpi/video.c 275F: drivers/acpi/video.c
276 276
@@ -2300,7 +2300,7 @@ S: Maintained
2300F: drivers/net/ethernet/ti/cpmac.c 2300F: drivers/net/ethernet/ti/cpmac.c
2301 2301
2302CPU FREQUENCY DRIVERS 2302CPU FREQUENCY DRIVERS
2303M: Rafael J. Wysocki <rjw@sisk.pl> 2303M: Rafael J. Wysocki <rjw@rjwysocki.net>
2304M: Viresh Kumar <viresh.kumar@linaro.org> 2304M: Viresh Kumar <viresh.kumar@linaro.org>
2305L: cpufreq@vger.kernel.org 2305L: cpufreq@vger.kernel.org
2306L: linux-pm@vger.kernel.org 2306L: linux-pm@vger.kernel.org
@@ -2331,7 +2331,7 @@ S: Maintained
2331F: drivers/cpuidle/cpuidle-big_little.c 2331F: drivers/cpuidle/cpuidle-big_little.c
2332 2332
2333CPUIDLE DRIVERS 2333CPUIDLE DRIVERS
2334M: Rafael J. Wysocki <rjw@sisk.pl> 2334M: Rafael J. Wysocki <rjw@rjwysocki.net>
2335M: Daniel Lezcano <daniel.lezcano@linaro.org> 2335M: Daniel Lezcano <daniel.lezcano@linaro.org>
2336L: linux-pm@vger.kernel.org 2336L: linux-pm@vger.kernel.org
2337S: Maintained 2337S: Maintained
@@ -3553,7 +3553,7 @@ F: fs/freevxfs/
3553 3553
3554FREEZER 3554FREEZER
3555M: Pavel Machek <pavel@ucw.cz> 3555M: Pavel Machek <pavel@ucw.cz>
3556M: "Rafael J. Wysocki" <rjw@sisk.pl> 3556M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
3557L: linux-pm@vger.kernel.org 3557L: linux-pm@vger.kernel.org
3558S: Supported 3558S: Supported
3559F: Documentation/power/freezing-of-tasks.txt 3559F: Documentation/power/freezing-of-tasks.txt
@@ -3624,6 +3624,12 @@ L: linux-scsi@vger.kernel.org
3624S: Odd Fixes (e.g., new signatures) 3624S: Odd Fixes (e.g., new signatures)
3625F: drivers/scsi/fdomain.* 3625F: drivers/scsi/fdomain.*
3626 3626
3627GCOV BASED KERNEL PROFILING
3628M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
3629S: Maintained
3630F: kernel/gcov/
3631F: Documentation/gcov.txt
3632
3627GDT SCSI DISK ARRAY CONTROLLER DRIVER 3633GDT SCSI DISK ARRAY CONTROLLER DRIVER
3628M: Achim Leubner <achim_leubner@adaptec.com> 3634M: Achim Leubner <achim_leubner@adaptec.com>
3629L: linux-scsi@vger.kernel.org 3635L: linux-scsi@vger.kernel.org
@@ -3889,7 +3895,7 @@ F: drivers/video/hgafb.c
3889 3895
3890HIBERNATION (aka Software Suspend, aka swsusp) 3896HIBERNATION (aka Software Suspend, aka swsusp)
3891M: Pavel Machek <pavel@ucw.cz> 3897M: Pavel Machek <pavel@ucw.cz>
3892M: "Rafael J. Wysocki" <rjw@sisk.pl> 3898M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
3893L: linux-pm@vger.kernel.org 3899L: linux-pm@vger.kernel.org
3894S: Supported 3900S: Supported
3895F: arch/x86/power/ 3901F: arch/x86/power/
@@ -4339,7 +4345,7 @@ F: drivers/video/i810/
4339INTEL MENLOW THERMAL DRIVER 4345INTEL MENLOW THERMAL DRIVER
4340M: Sujith Thomas <sujith.thomas@intel.com> 4346M: Sujith Thomas <sujith.thomas@intel.com>
4341L: platform-driver-x86@vger.kernel.org 4347L: platform-driver-x86@vger.kernel.org
4342W: http://www.lesswatts.org/projects/acpi/ 4348W: https://01.org/linux-acpi
4343S: Supported 4349S: Supported
4344F: drivers/platform/x86/intel_menlow.c 4350F: drivers/platform/x86/intel_menlow.c
4345 4351
@@ -8095,7 +8101,7 @@ F: drivers/sh/
8095SUSPEND TO RAM 8101SUSPEND TO RAM
8096M: Len Brown <len.brown@intel.com> 8102M: Len Brown <len.brown@intel.com>
8097M: Pavel Machek <pavel@ucw.cz> 8103M: Pavel Machek <pavel@ucw.cz>
8098M: "Rafael J. Wysocki" <rjw@sisk.pl> 8104M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
8099L: linux-pm@vger.kernel.org 8105L: linux-pm@vger.kernel.org
8100S: Supported 8106S: Supported
8101F: Documentation/power/ 8107F: Documentation/power/
diff --git a/Makefile b/Makefile
index deec08b7612b..126321d2e6ad 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 12 2PATCHLEVEL = 12
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc5 4EXTRAVERSION = -rc6
5NAME = One Giant Leap for Frogkind 5NAME = One Giant Leap for Frogkind
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c
index 370236dd1a03..990250965f2c 100644
--- a/arch/arm/common/mcpm_entry.c
+++ b/arch/arm/common/mcpm_entry.c
@@ -51,7 +51,8 @@ void mcpm_cpu_power_down(void)
51{ 51{
52 phys_reset_t phys_reset; 52 phys_reset_t phys_reset;
53 53
54 BUG_ON(!platform_ops); 54 if (WARN_ON_ONCE(!platform_ops || !platform_ops->power_down))
55 return;
55 BUG_ON(!irqs_disabled()); 56 BUG_ON(!irqs_disabled());
56 57
57 /* 58 /*
@@ -93,7 +94,8 @@ void mcpm_cpu_suspend(u64 expected_residency)
93{ 94{
94 phys_reset_t phys_reset; 95 phys_reset_t phys_reset;
95 96
96 BUG_ON(!platform_ops); 97 if (WARN_ON_ONCE(!platform_ops || !platform_ops->suspend))
98 return;
97 BUG_ON(!irqs_disabled()); 99 BUG_ON(!irqs_disabled());
98 100
99 /* Very similar to mcpm_cpu_power_down() */ 101 /* Very similar to mcpm_cpu_power_down() */
diff --git a/arch/arm/common/sharpsl_param.c b/arch/arm/common/sharpsl_param.c
index d56c932580eb..025f6ce38596 100644
--- a/arch/arm/common/sharpsl_param.c
+++ b/arch/arm/common/sharpsl_param.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <asm/mach/sharpsl_param.h> 17#include <asm/mach/sharpsl_param.h>
18#include <asm/memory.h>
18 19
19/* 20/*
20 * Certain hardware parameters determined at the time of device manufacture, 21 * Certain hardware parameters determined at the time of device manufacture,
@@ -25,8 +26,10 @@
25 */ 26 */
26#ifdef CONFIG_ARCH_SA1100 27#ifdef CONFIG_ARCH_SA1100
27#define PARAM_BASE 0xe8ffc000 28#define PARAM_BASE 0xe8ffc000
29#define param_start(x) (void *)(x)
28#else 30#else
29#define PARAM_BASE 0xa0000a00 31#define PARAM_BASE 0xa0000a00
32#define param_start(x) __va(x)
30#endif 33#endif
31#define MAGIC_CHG(a,b,c,d) ( ( d << 24 ) | ( c << 16 ) | ( b << 8 ) | a ) 34#define MAGIC_CHG(a,b,c,d) ( ( d << 24 ) | ( c << 16 ) | ( b << 8 ) | a )
32 35
@@ -41,7 +44,7 @@ EXPORT_SYMBOL(sharpsl_param);
41 44
42void sharpsl_save_param(void) 45void sharpsl_save_param(void)
43{ 46{
44 memcpy(&sharpsl_param, (void *)PARAM_BASE, sizeof(struct sharpsl_param_info)); 47 memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
45 48
46 if (sharpsl_param.comadj_keyword != COMADJ_MAGIC) 49 if (sharpsl_param.comadj_keyword != COMADJ_MAGIC)
47 sharpsl_param.comadj=-1; 50 sharpsl_param.comadj=-1;
diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild
index d3db39860b9c..59ceae8f3c95 100644
--- a/arch/arm/include/asm/Kbuild
+++ b/arch/arm/include/asm/Kbuild
@@ -31,5 +31,4 @@ generic-y += termbits.h
31generic-y += termios.h 31generic-y += termios.h
32generic-y += timex.h 32generic-y += timex.h
33generic-y += trace_clock.h 33generic-y += trace_clock.h
34generic-y += types.h
35generic-y += unaligned.h 34generic-y += unaligned.h
diff --git a/arch/arm/include/asm/mcpm.h b/arch/arm/include/asm/mcpm.h
index 0f7b7620e9a5..fc82a88f5b69 100644
--- a/arch/arm/include/asm/mcpm.h
+++ b/arch/arm/include/asm/mcpm.h
@@ -76,8 +76,11 @@ int mcpm_cpu_power_up(unsigned int cpu, unsigned int cluster);
76 * 76 *
77 * This must be called with interrupts disabled. 77 * This must be called with interrupts disabled.
78 * 78 *
79 * This does not return. Re-entry in the kernel is expected via 79 * On success this does not return. Re-entry in the kernel is expected
80 * mcpm_entry_point. 80 * via mcpm_entry_point.
81 *
82 * This will return if mcpm_platform_register() has not been called
83 * previously in which case the caller should take appropriate action.
81 */ 84 */
82void mcpm_cpu_power_down(void); 85void mcpm_cpu_power_down(void);
83 86
@@ -98,8 +101,11 @@ void mcpm_cpu_power_down(void);
98 * 101 *
99 * This must be called with interrupts disabled. 102 * This must be called with interrupts disabled.
100 * 103 *
101 * This does not return. Re-entry in the kernel is expected via 104 * On success this does not return. Re-entry in the kernel is expected
102 * mcpm_entry_point. 105 * via mcpm_entry_point.
106 *
107 * This will return if mcpm_platform_register() has not been called
108 * previously in which case the caller should take appropriate action.
103 */ 109 */
104void mcpm_cpu_suspend(u64 expected_residency); 110void mcpm_cpu_suspend(u64 expected_residency);
105 111
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index f1d96d4e8092..73ddd7239b33 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -57,6 +57,9 @@ static inline void syscall_get_arguments(struct task_struct *task,
57 unsigned int i, unsigned int n, 57 unsigned int i, unsigned int n,
58 unsigned long *args) 58 unsigned long *args)
59{ 59{
60 if (n == 0)
61 return;
62
60 if (i + n > SYSCALL_MAX_ARGS) { 63 if (i + n > SYSCALL_MAX_ARGS) {
61 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i; 64 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
62 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS; 65 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
@@ -81,6 +84,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
81 unsigned int i, unsigned int n, 84 unsigned int i, unsigned int n,
82 const unsigned long *args) 85 const unsigned long *args)
83{ 86{
87 if (n == 0)
88 return;
89
84 if (i + n > SYSCALL_MAX_ARGS) { 90 if (i + n > SYSCALL_MAX_ARGS) {
85 pr_warning("%s called with max args %d, handling only %d\n", 91 pr_warning("%s called with max args %d, handling only %d\n",
86 __func__, i + n, SYSCALL_MAX_ARGS); 92 __func__, i + n, SYSCALL_MAX_ARGS);
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 2c7cc1e03473..476de57dcef2 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -487,7 +487,26 @@ __fixup_smp:
487 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR 487 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
488 and r0, r0, #0xc0000000 @ multiprocessing extensions and 488 and r0, r0, #0xc0000000 @ multiprocessing extensions and
489 teq r0, #0x80000000 @ not part of a uniprocessor system? 489 teq r0, #0x80000000 @ not part of a uniprocessor system?
490 moveq pc, lr @ yes, assume SMP 490 bne __fixup_smp_on_up @ no, assume UP
491
492 @ Core indicates it is SMP. Check for Aegis SOC where a single
493 @ Cortex-A9 CPU is present but SMP operations fault.
494 mov r4, #0x41000000
495 orr r4, r4, #0x0000c000
496 orr r4, r4, #0x00000090
497 teq r3, r4 @ Check for ARM Cortex-A9
498 movne pc, lr @ Not ARM Cortex-A9,
499
500 @ If a future SoC *does* use 0x0 as the PERIPH_BASE, then the
501 @ below address check will need to be #ifdef'd or equivalent
502 @ for the Aegis platform.
503 mrc p15, 4, r0, c15, c0 @ get SCU base address
504 teq r0, #0x0 @ '0' on actual UP A9 hardware
505 beq __fixup_smp_on_up @ So its an A9 UP
506 ldr r0, [r0, #4] @ read SCU Config
507 and r0, r0, #0x3 @ number of CPUs
508 teq r0, #0x0 @ is 1?
509 movne pc, lr
491 510
492__fixup_smp_on_up: 511__fixup_smp_on_up:
493 adr r0, 1f 512 adr r0, 1f
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f5e1a8471714..1272ed202dde 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1232,7 +1232,8 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
1232 break; 1232 break;
1233 1233
1234 len = (j - i) << PAGE_SHIFT; 1234 len = (j - i) << PAGE_SHIFT;
1235 ret = iommu_map(mapping->domain, iova, phys, len, 0); 1235 ret = iommu_map(mapping->domain, iova, phys, len,
1236 IOMMU_READ|IOMMU_WRITE);
1236 if (ret < 0) 1237 if (ret < 0)
1237 goto fail; 1238 goto fail;
1238 iova += len; 1239 iova += len;
@@ -1431,6 +1432,27 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
1431 GFP_KERNEL); 1432 GFP_KERNEL);
1432} 1433}
1433 1434
1435static int __dma_direction_to_prot(enum dma_data_direction dir)
1436{
1437 int prot;
1438
1439 switch (dir) {
1440 case DMA_BIDIRECTIONAL:
1441 prot = IOMMU_READ | IOMMU_WRITE;
1442 break;
1443 case DMA_TO_DEVICE:
1444 prot = IOMMU_READ;
1445 break;
1446 case DMA_FROM_DEVICE:
1447 prot = IOMMU_WRITE;
1448 break;
1449 default:
1450 prot = 0;
1451 }
1452
1453 return prot;
1454}
1455
1434/* 1456/*
1435 * Map a part of the scatter-gather list into contiguous io address space 1457 * Map a part of the scatter-gather list into contiguous io address space
1436 */ 1458 */
@@ -1444,6 +1466,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
1444 int ret = 0; 1466 int ret = 0;
1445 unsigned int count; 1467 unsigned int count;
1446 struct scatterlist *s; 1468 struct scatterlist *s;
1469 int prot;
1447 1470
1448 size = PAGE_ALIGN(size); 1471 size = PAGE_ALIGN(size);
1449 *handle = DMA_ERROR_CODE; 1472 *handle = DMA_ERROR_CODE;
@@ -1460,7 +1483,9 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
1460 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) 1483 !dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
1461 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir); 1484 __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
1462 1485
1463 ret = iommu_map(mapping->domain, iova, phys, len, 0); 1486 prot = __dma_direction_to_prot(dir);
1487
1488 ret = iommu_map(mapping->domain, iova, phys, len, prot);
1464 if (ret < 0) 1489 if (ret < 0)
1465 goto fail; 1490 goto fail;
1466 count += len >> PAGE_SHIFT; 1491 count += len >> PAGE_SHIFT;
@@ -1665,19 +1690,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
1665 if (dma_addr == DMA_ERROR_CODE) 1690 if (dma_addr == DMA_ERROR_CODE)
1666 return dma_addr; 1691 return dma_addr;
1667 1692
1668 switch (dir) { 1693 prot = __dma_direction_to_prot(dir);
1669 case DMA_BIDIRECTIONAL:
1670 prot = IOMMU_READ | IOMMU_WRITE;
1671 break;
1672 case DMA_TO_DEVICE:
1673 prot = IOMMU_READ;
1674 break;
1675 case DMA_FROM_DEVICE:
1676 prot = IOMMU_WRITE;
1677 break;
1678 default:
1679 prot = 0;
1680 }
1681 1694
1682 ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, prot); 1695 ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, prot);
1683 if (ret < 0) 1696 if (ret < 0)
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index febaee7ca57b..18ec4c504abf 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -17,7 +17,6 @@
17#include <linux/nodemask.h> 17#include <linux/nodemask.h>
18#include <linux/initrd.h> 18#include <linux/initrd.h>
19#include <linux/of_fdt.h> 19#include <linux/of_fdt.h>
20#include <linux/of_reserved_mem.h>
21#include <linux/highmem.h> 20#include <linux/highmem.h>
22#include <linux/gfp.h> 21#include <linux/gfp.h>
23#include <linux/memblock.h> 22#include <linux/memblock.h>
@@ -379,8 +378,6 @@ void __init arm_memblock_init(struct meminfo *mi,
379 if (mdesc->reserve) 378 if (mdesc->reserve)
380 mdesc->reserve(); 379 mdesc->reserve();
381 380
382 early_init_dt_scan_reserved_mem();
383
384 /* 381 /*
385 * reserve memory for DMA contigouos allocations, 382 * reserve memory for DMA contigouos allocations,
386 * must come from DMA area inside low memory 383 * must come from DMA area inside low memory
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 145d703227bf..f67e839f06c8 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1033,6 +1033,7 @@ config X86_REBOOTFIXUPS
1033 1033
1034config MICROCODE 1034config MICROCODE
1035 tristate "CPU microcode loading support" 1035 tristate "CPU microcode loading support"
1036 depends on CPU_SUP_AMD || CPU_SUP_INTEL
1036 select FW_LOADER 1037 select FW_LOADER
1037 ---help--- 1038 ---help---
1038 1039
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 1191ac1c9d25..a419814cea57 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -113,7 +113,7 @@ static int __init early_get_pnodeid(void)
113 break; 113 break;
114 case UV3_HUB_PART_NUMBER: 114 case UV3_HUB_PART_NUMBER:
115 case UV3_HUB_PART_NUMBER_X: 115 case UV3_HUB_PART_NUMBER_X:
116 uv_min_hub_revision_id += UV3_HUB_REVISION_BASE - 1; 116 uv_min_hub_revision_id += UV3_HUB_REVISION_BASE;
117 break; 117 break;
118 } 118 }
119 119
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 697b93af02dd..a0e2a8a80c94 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -775,11 +775,22 @@ void __init kvm_spinlock_init(void)
775 if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) 775 if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
776 return; 776 return;
777 777
778 printk(KERN_INFO "KVM setup paravirtual spinlock\n"); 778 pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning);
779 pv_lock_ops.unlock_kick = kvm_unlock_kick;
780}
781
782static __init int kvm_spinlock_init_jump(void)
783{
784 if (!kvm_para_available())
785 return 0;
786 if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
787 return 0;
779 788
780 static_key_slow_inc(&paravirt_ticketlocks_enabled); 789 static_key_slow_inc(&paravirt_ticketlocks_enabled);
790 printk(KERN_INFO "KVM setup paravirtual spinlock\n");
781 791
782 pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning); 792 return 0;
783 pv_lock_ops.unlock_kick = kvm_unlock_kick;
784} 793}
794early_initcall(kvm_spinlock_init_jump);
795
785#endif /* CONFIG_PARAVIRT_SPINLOCKS */ 796#endif /* CONFIG_PARAVIRT_SPINLOCKS */
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index d1e4777b4e75..31d04758b76f 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -278,6 +278,15 @@ static void __init xen_smp_prepare_boot_cpu(void)
278 old memory can be recycled */ 278 old memory can be recycled */
279 make_lowmem_page_readwrite(xen_initial_gdt); 279 make_lowmem_page_readwrite(xen_initial_gdt);
280 280
281#ifdef CONFIG_X86_32
282 /*
283 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
284 * expects __USER_DS
285 */
286 loadsegment(ds, __USER_DS);
287 loadsegment(es, __USER_DS);
288#endif
289
281 xen_filter_cpu_maps(); 290 xen_filter_cpu_maps();
282 xen_setup_vcpu_info_placement(); 291 xen_setup_vcpu_info_placement();
283 } 292 }
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 1eb09ee5311b..a8287b49d062 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -222,11 +222,16 @@ check_hybrid:
222 * the disk size. 222 * the disk size.
223 * 223 *
224 * Hybrid MBRs do not necessarily comply with this. 224 * Hybrid MBRs do not necessarily comply with this.
225 *
226 * Consider a bad value here to be a warning to support dd'ing
227 * an image from a smaller disk to a larger disk.
225 */ 228 */
226 if (ret == GPT_MBR_PROTECTIVE) { 229 if (ret == GPT_MBR_PROTECTIVE) {
227 sz = le32_to_cpu(mbr->partition_record[part].size_in_lba); 230 sz = le32_to_cpu(mbr->partition_record[part].size_in_lba);
228 if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF) 231 if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF)
229 ret = 0; 232 pr_debug("GPT: mbr size in lba (%u) different than whole disk (%u).\n",
233 sz, min_t(uint32_t,
234 total_sectors - 1, 0xFFFFFFFF));
230 } 235 }
231done: 236done:
232 return ret; 237 return ret;
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 22327e6a7236..6efe2ac6902f 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -24,7 +24,7 @@ menuconfig ACPI
24 are configured, ACPI is used. 24 are configured, ACPI is used.
25 25
26 The project home page for the Linux ACPI subsystem is here: 26 The project home page for the Linux ACPI subsystem is here:
27 <http://www.lesswatts.org/projects/acpi/> 27 <https://01.org/linux-acpi>
28 28
29 Linux support for ACPI is based on Intel Corporation's ACPI 29 Linux support for ACPI is based on Intel Corporation's ACPI
30 Component Architecture (ACPI CA). For more information on the 30 Component Architecture (ACPI CA). For more information on the
@@ -123,9 +123,9 @@ config ACPI_BUTTON
123 default y 123 default y
124 help 124 help
125 This driver handles events on the power, sleep, and lid buttons. 125 This driver handles events on the power, sleep, and lid buttons.
126 A daemon reads /proc/acpi/event and perform user-defined actions 126 A daemon reads events from input devices or via netlink and
127 such as shutting down the system. This is necessary for 127 performs user-defined actions such as shutting down the system.
128 software-controlled poweroff. 128 This is necessary for software-controlled poweroff.
129 129
130 To compile this driver as a module, choose M here: 130 To compile this driver as a module, choose M here:
131 the module will be called button. 131 the module will be called button.
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 59d3202f6b36..a94383d1f350 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1025,60 +1025,4 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
1025 } 1025 }
1026} 1026}
1027EXPORT_SYMBOL_GPL(acpi_dev_pm_detach); 1027EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
1028
1029/**
1030 * acpi_dev_pm_add_dependent - Add physical device depending for PM.
1031 * @handle: Handle of ACPI device node.
1032 * @depdev: Device depending on that node for PM.
1033 */
1034void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev)
1035{
1036 struct acpi_device_physical_node *dep;
1037 struct acpi_device *adev;
1038
1039 if (!depdev || acpi_bus_get_device(handle, &adev))
1040 return;
1041
1042 mutex_lock(&adev->physical_node_lock);
1043
1044 list_for_each_entry(dep, &adev->power_dependent, node)
1045 if (dep->dev == depdev)
1046 goto out;
1047
1048 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
1049 if (dep) {
1050 dep->dev = depdev;
1051 list_add_tail(&dep->node, &adev->power_dependent);
1052 }
1053
1054 out:
1055 mutex_unlock(&adev->physical_node_lock);
1056}
1057EXPORT_SYMBOL_GPL(acpi_dev_pm_add_dependent);
1058
1059/**
1060 * acpi_dev_pm_remove_dependent - Remove physical device depending for PM.
1061 * @handle: Handle of ACPI device node.
1062 * @depdev: Device depending on that node for PM.
1063 */
1064void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev)
1065{
1066 struct acpi_device_physical_node *dep;
1067 struct acpi_device *adev;
1068
1069 if (!depdev || acpi_bus_get_device(handle, &adev))
1070 return;
1071
1072 mutex_lock(&adev->physical_node_lock);
1073
1074 list_for_each_entry(dep, &adev->power_dependent, node)
1075 if (dep->dev == depdev) {
1076 list_del(&dep->node);
1077 kfree(dep);
1078 break;
1079 }
1080
1081 mutex_unlock(&adev->physical_node_lock);
1082}
1083EXPORT_SYMBOL_GPL(acpi_dev_pm_remove_dependent);
1084#endif /* CONFIG_PM */ 1028#endif /* CONFIG_PM */
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 0dbe5cdf3396..c2ad391d8041 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -59,16 +59,9 @@ ACPI_MODULE_NAME("power");
59#define ACPI_POWER_RESOURCE_STATE_ON 0x01 59#define ACPI_POWER_RESOURCE_STATE_ON 0x01
60#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 60#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
61 61
62struct acpi_power_dependent_device {
63 struct list_head node;
64 struct acpi_device *adev;
65 struct work_struct work;
66};
67
68struct acpi_power_resource { 62struct acpi_power_resource {
69 struct acpi_device device; 63 struct acpi_device device;
70 struct list_head list_node; 64 struct list_head list_node;
71 struct list_head dependent;
72 char *name; 65 char *name;
73 u32 system_level; 66 u32 system_level;
74 u32 order; 67 u32 order;
@@ -233,32 +226,6 @@ static int acpi_power_get_list_state(struct list_head *list, int *state)
233 return 0; 226 return 0;
234} 227}
235 228
236static void acpi_power_resume_dependent(struct work_struct *work)
237{
238 struct acpi_power_dependent_device *dep;
239 struct acpi_device_physical_node *pn;
240 struct acpi_device *adev;
241 int state;
242
243 dep = container_of(work, struct acpi_power_dependent_device, work);
244 adev = dep->adev;
245 if (acpi_power_get_inferred_state(adev, &state))
246 return;
247
248 if (state > ACPI_STATE_D0)
249 return;
250
251 mutex_lock(&adev->physical_node_lock);
252
253 list_for_each_entry(pn, &adev->physical_node_list, node)
254 pm_request_resume(pn->dev);
255
256 list_for_each_entry(pn, &adev->power_dependent, node)
257 pm_request_resume(pn->dev);
258
259 mutex_unlock(&adev->physical_node_lock);
260}
261
262static int __acpi_power_on(struct acpi_power_resource *resource) 229static int __acpi_power_on(struct acpi_power_resource *resource)
263{ 230{
264 acpi_status status = AE_OK; 231 acpi_status status = AE_OK;
@@ -283,14 +250,8 @@ static int acpi_power_on_unlocked(struct acpi_power_resource *resource)
283 resource->name)); 250 resource->name));
284 } else { 251 } else {
285 result = __acpi_power_on(resource); 252 result = __acpi_power_on(resource);
286 if (result) { 253 if (result)
287 resource->ref_count--; 254 resource->ref_count--;
288 } else {
289 struct acpi_power_dependent_device *dep;
290
291 list_for_each_entry(dep, &resource->dependent, node)
292 schedule_work(&dep->work);
293 }
294 } 255 }
295 return result; 256 return result;
296} 257}
@@ -390,52 +351,6 @@ static int acpi_power_on_list(struct list_head *list)
390 return result; 351 return result;
391} 352}
392 353
393static void acpi_power_add_dependent(struct acpi_power_resource *resource,
394 struct acpi_device *adev)
395{
396 struct acpi_power_dependent_device *dep;
397
398 mutex_lock(&resource->resource_lock);
399
400 list_for_each_entry(dep, &resource->dependent, node)
401 if (dep->adev == adev)
402 goto out;
403
404 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
405 if (!dep)
406 goto out;
407
408 dep->adev = adev;
409 INIT_WORK(&dep->work, acpi_power_resume_dependent);
410 list_add_tail(&dep->node, &resource->dependent);
411
412 out:
413 mutex_unlock(&resource->resource_lock);
414}
415
416static void acpi_power_remove_dependent(struct acpi_power_resource *resource,
417 struct acpi_device *adev)
418{
419 struct acpi_power_dependent_device *dep;
420 struct work_struct *work = NULL;
421
422 mutex_lock(&resource->resource_lock);
423
424 list_for_each_entry(dep, &resource->dependent, node)
425 if (dep->adev == adev) {
426 list_del(&dep->node);
427 work = &dep->work;
428 break;
429 }
430
431 mutex_unlock(&resource->resource_lock);
432
433 if (work) {
434 cancel_work_sync(work);
435 kfree(dep);
436 }
437}
438
439static struct attribute *attrs[] = { 354static struct attribute *attrs[] = {
440 NULL, 355 NULL,
441}; 356};
@@ -524,8 +439,6 @@ static void acpi_power_expose_hide(struct acpi_device *adev,
524 439
525void acpi_power_add_remove_device(struct acpi_device *adev, bool add) 440void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
526{ 441{
527 struct acpi_device_power_state *ps;
528 struct acpi_power_resource_entry *entry;
529 int state; 442 int state;
530 443
531 if (adev->wakeup.flags.valid) 444 if (adev->wakeup.flags.valid)
@@ -535,16 +448,6 @@ void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
535 if (!adev->power.flags.power_resources) 448 if (!adev->power.flags.power_resources)
536 return; 449 return;
537 450
538 ps = &adev->power.states[ACPI_STATE_D0];
539 list_for_each_entry(entry, &ps->resources, node) {
540 struct acpi_power_resource *resource = entry->resource;
541
542 if (add)
543 acpi_power_add_dependent(resource, adev);
544 else
545 acpi_power_remove_dependent(resource, adev);
546 }
547
548 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++) 451 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++)
549 acpi_power_expose_hide(adev, 452 acpi_power_expose_hide(adev,
550 &adev->power.states[state].resources, 453 &adev->power.states[state].resources,
@@ -882,7 +785,6 @@ int acpi_add_power_resource(acpi_handle handle)
882 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER, 785 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
883 ACPI_STA_DEFAULT); 786 ACPI_STA_DEFAULT);
884 mutex_init(&resource->resource_lock); 787 mutex_init(&resource->resource_lock);
885 INIT_LIST_HEAD(&resource->dependent);
886 INIT_LIST_HEAD(&resource->list_node); 788 INIT_LIST_HEAD(&resource->list_node);
887 resource->name = device->pnp.bus_id; 789 resource->name = device->pnp.bus_id;
888 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 790 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
@@ -936,8 +838,10 @@ void acpi_resume_power_resources(void)
936 mutex_lock(&resource->resource_lock); 838 mutex_lock(&resource->resource_lock);
937 839
938 result = acpi_power_get_state(resource->device.handle, &state); 840 result = acpi_power_get_state(resource->device.handle, &state);
939 if (result) 841 if (result) {
842 mutex_unlock(&resource->resource_lock);
940 continue; 843 continue;
844 }
941 845
942 if (state == ACPI_POWER_RESOURCE_STATE_OFF 846 if (state == ACPI_POWER_RESOURCE_STATE_OFF
943 && resource->ref_count) { 847 && resource->ref_count) {
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 407ad13cac2f..fee8a297c7d9 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -999,7 +999,6 @@ int acpi_device_add(struct acpi_device *device,
999 INIT_LIST_HEAD(&device->wakeup_list); 999 INIT_LIST_HEAD(&device->wakeup_list);
1000 INIT_LIST_HEAD(&device->physical_node_list); 1000 INIT_LIST_HEAD(&device->physical_node_list);
1001 mutex_init(&device->physical_node_lock); 1001 mutex_init(&device->physical_node_lock);
1002 INIT_LIST_HEAD(&device->power_dependent);
1003 1002
1004 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); 1003 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
1005 if (!new_bus_id) { 1004 if (!new_bus_id) {
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 4ba8b0405572..ab714d2ad978 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -1035,17 +1035,3 @@ void ata_acpi_on_disable(struct ata_device *dev)
1035{ 1035{
1036 ata_acpi_clear_gtf(dev); 1036 ata_acpi_clear_gtf(dev);
1037} 1037}
1038
1039void ata_scsi_acpi_bind(struct ata_device *dev)
1040{
1041 acpi_handle handle = ata_dev_acpi_handle(dev);
1042 if (handle)
1043 acpi_dev_pm_add_dependent(handle, &dev->sdev->sdev_gendev);
1044}
1045
1046void ata_scsi_acpi_unbind(struct ata_device *dev)
1047{
1048 acpi_handle handle = ata_dev_acpi_handle(dev);
1049 if (handle)
1050 acpi_dev_pm_remove_dependent(handle, &dev->sdev->sdev_gendev);
1051}
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 97a0cef12959..db6dfcfa3e2e 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3679,7 +3679,6 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3679 if (!IS_ERR(sdev)) { 3679 if (!IS_ERR(sdev)) {
3680 dev->sdev = sdev; 3680 dev->sdev = sdev;
3681 scsi_device_put(sdev); 3681 scsi_device_put(sdev);
3682 ata_scsi_acpi_bind(dev);
3683 } else { 3682 } else {
3684 dev->sdev = NULL; 3683 dev->sdev = NULL;
3685 } 3684 }
@@ -3767,8 +3766,6 @@ static void ata_scsi_remove_dev(struct ata_device *dev)
3767 struct scsi_device *sdev; 3766 struct scsi_device *sdev;
3768 unsigned long flags; 3767 unsigned long flags;
3769 3768
3770 ata_scsi_acpi_unbind(dev);
3771
3772 /* Alas, we need to grab scan_mutex to ensure SCSI device 3769 /* Alas, we need to grab scan_mutex to ensure SCSI device
3773 * state doesn't change underneath us and thus 3770 * state doesn't change underneath us and thus
3774 * scsi_device_get() always succeeds. The mutex locking can 3771 * scsi_device_get() always succeeds. The mutex locking can
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index eeeb77845d48..45b5ab3a95d5 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -121,8 +121,6 @@ extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
121extern void ata_acpi_bind_port(struct ata_port *ap); 121extern void ata_acpi_bind_port(struct ata_port *ap);
122extern void ata_acpi_bind_dev(struct ata_device *dev); 122extern void ata_acpi_bind_dev(struct ata_device *dev);
123extern acpi_handle ata_dev_acpi_handle(struct ata_device *dev); 123extern acpi_handle ata_dev_acpi_handle(struct ata_device *dev);
124extern void ata_scsi_acpi_bind(struct ata_device *dev);
125extern void ata_scsi_acpi_unbind(struct ata_device *dev);
126#else 124#else
127static inline void ata_acpi_dissociate(struct ata_host *host) { } 125static inline void ata_acpi_dissociate(struct ata_host *host) { }
128static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; } 126static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
@@ -133,8 +131,6 @@ static inline void ata_acpi_set_state(struct ata_port *ap,
133 pm_message_t state) { } 131 pm_message_t state) { }
134static inline void ata_acpi_bind_port(struct ata_port *ap) {} 132static inline void ata_acpi_bind_port(struct ata_port *ap) {}
135static inline void ata_acpi_bind_dev(struct ata_device *dev) {} 133static inline void ata_acpi_bind_dev(struct ata_device *dev) {}
136static inline void ata_scsi_acpi_bind(struct ata_device *dev) {}
137static inline void ata_scsi_acpi_unbind(struct ata_device *dev) {}
138#endif 134#endif
139 135
140/* libata-scsi.c */ 136/* libata-scsi.c */
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 9e59f6535c44..bece691cb5d9 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -333,8 +333,10 @@ store_mem_state(struct device *dev,
333 online_type = ONLINE_KEEP; 333 online_type = ONLINE_KEEP;
334 else if (!strncmp(buf, "offline", min_t(int, count, 7))) 334 else if (!strncmp(buf, "offline", min_t(int, count, 7)))
335 online_type = -1; 335 online_type = -1;
336 else 336 else {
337 return -EINVAL; 337 ret = -EINVAL;
338 goto err;
339 }
338 340
339 switch (online_type) { 341 switch (online_type) {
340 case ONLINE_KERNEL: 342 case ONLINE_KERNEL:
@@ -357,6 +359,7 @@ store_mem_state(struct device *dev,
357 ret = -EINVAL; /* should never happen */ 359 ret = -EINVAL; /* should never happen */
358 } 360 }
359 361
362err:
360 unlock_device_hotplug(); 363 unlock_device_hotplug();
361 364
362 if (ret) 365 if (ret)
diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 06189e55b4e5..94c280d36e8b 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -10,6 +10,7 @@
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <xen/xen.h>
13#include <xen/events.h> 14#include <xen/events.h>
14#include <xen/interface/io/tpmif.h> 15#include <xen/interface/io/tpmif.h>
15#include <xen/grant_table.h> 16#include <xen/grant_table.h>
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 32b3479a2405..badf6206b2b2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
383static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) 383static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
384{ 384{
385 int max_perf, min_perf; 385 int max_perf, min_perf;
386 u64 val;
386 387
387 intel_pstate_get_min_max(cpu, &min_perf, &max_perf); 388 intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
388 389
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
394 trace_cpu_frequency(pstate * 100000, cpu->cpu); 395 trace_cpu_frequency(pstate * 100000, cpu->cpu);
395 396
396 cpu->pstate.current_pstate = pstate; 397 cpu->pstate.current_pstate = pstate;
398 val = pstate << 8;
397 if (limits.no_turbo) 399 if (limits.no_turbo)
398 wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8)); 400 val |= (u64)1 << 32;
399 else
400 wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
401 401
402 wrmsrl(MSR_IA32_PERF_CTL, val);
402} 403}
403 404
404static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps) 405static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
@@ -637,8 +638,8 @@ static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
637 638
638static int intel_pstate_cpu_init(struct cpufreq_policy *policy) 639static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
639{ 640{
640 int rc, min_pstate, max_pstate;
641 struct cpudata *cpu; 641 struct cpudata *cpu;
642 int rc;
642 643
643 rc = intel_pstate_init_cpu(policy->cpu); 644 rc = intel_pstate_init_cpu(policy->cpu);
644 if (rc) 645 if (rc)
@@ -652,9 +653,8 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
652 else 653 else
653 policy->policy = CPUFREQ_POLICY_POWERSAVE; 654 policy->policy = CPUFREQ_POLICY_POWERSAVE;
654 655
655 intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate); 656 policy->min = cpu->pstate.min_pstate * 100000;
656 policy->min = min_pstate * 100000; 657 policy->max = cpu->pstate.turbo_pstate * 100000;
657 policy->max = max_pstate * 100000;
658 658
659 /* cpuinfo and default policy values */ 659 /* cpuinfo and default policy values */
660 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * 100000; 660 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * 100000;
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index 8a72b0c555f8..15631f92ab7d 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -166,7 +166,7 @@ static void __init s3c64xx_cpufreq_config_regulator(void)
166 if (freq->frequency == CPUFREQ_ENTRY_INVALID) 166 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
167 continue; 167 continue;
168 168
169 dvfs = &s3c64xx_dvfs_table[freq->index]; 169 dvfs = &s3c64xx_dvfs_table[freq->driver_data];
170 found = 0; 170 found = 0;
171 171
172 for (i = 0; i < count; i++) { 172 for (i = 0; i < count; i++) {
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c
index 2d9ca6055e5e..41b5913ddabe 100644
--- a/drivers/gpio/gpio-lynxpoint.c
+++ b/drivers/gpio/gpio-lynxpoint.c
@@ -248,14 +248,15 @@ static void lp_gpio_irq_handler(unsigned irq, struct irq_desc *desc)
248 struct lp_gpio *lg = irq_data_get_irq_handler_data(data); 248 struct lp_gpio *lg = irq_data_get_irq_handler_data(data);
249 struct irq_chip *chip = irq_data_get_irq_chip(data); 249 struct irq_chip *chip = irq_data_get_irq_chip(data);
250 u32 base, pin, mask; 250 u32 base, pin, mask;
251 unsigned long reg, pending; 251 unsigned long reg, ena, pending;
252 unsigned virq; 252 unsigned virq;
253 253
254 /* check from GPIO controller which pin triggered the interrupt */ 254 /* check from GPIO controller which pin triggered the interrupt */
255 for (base = 0; base < lg->chip.ngpio; base += 32) { 255 for (base = 0; base < lg->chip.ngpio; base += 32) {
256 reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT); 256 reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT);
257 ena = lp_gpio_reg(&lg->chip, base, LP_INT_ENABLE);
257 258
258 while ((pending = inl(reg))) { 259 while ((pending = (inl(reg) & inl(ena)))) {
259 pin = __ffs(pending); 260 pin = __ffs(pending);
260 mask = BIT(pin); 261 mask = BIT(pin);
261 /* Clear before handling so we don't lose an edge */ 262 /* Clear before handling so we don't lose an edge */
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 86ef3461ec06..0dee0e0c247a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -136,7 +136,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio)
136 */ 136 */
137static int desc_to_gpio(const struct gpio_desc *desc) 137static int desc_to_gpio(const struct gpio_desc *desc)
138{ 138{
139 return desc->chip->base + gpio_chip_hwgpio(desc); 139 return desc - &gpio_desc[0];
140} 140}
141 141
142 142
@@ -1398,7 +1398,7 @@ static int gpiod_request(struct gpio_desc *desc, const char *label)
1398 int status = -EPROBE_DEFER; 1398 int status = -EPROBE_DEFER;
1399 unsigned long flags; 1399 unsigned long flags;
1400 1400
1401 if (!desc || !desc->chip) { 1401 if (!desc) {
1402 pr_warn("%s: invalid GPIO\n", __func__); 1402 pr_warn("%s: invalid GPIO\n", __func__);
1403 return -EINVAL; 1403 return -EINVAL;
1404 } 1404 }
@@ -1406,6 +1406,8 @@ static int gpiod_request(struct gpio_desc *desc, const char *label)
1406 spin_lock_irqsave(&gpio_lock, flags); 1406 spin_lock_irqsave(&gpio_lock, flags);
1407 1407
1408 chip = desc->chip; 1408 chip = desc->chip;
1409 if (chip == NULL)
1410 goto done;
1409 1411
1410 if (!try_module_get(chip->owner)) 1412 if (!try_module_get(chip->owner))
1411 goto done; 1413 goto done;
diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index a7b30be86ae0..52605c0ea3a6 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -525,8 +525,10 @@ static int adf4350_probe(struct spi_device *spi)
525 } 525 }
526 526
527 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 527 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
528 if (indio_dev == NULL) 528 if (indio_dev == NULL) {
529 return -ENOMEM; 529 ret = -ENOMEM;
530 goto error_disable_clk;
531 }
530 532
531 st = iio_priv(indio_dev); 533 st = iio_priv(indio_dev);
532 534
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 2710f7245c3b..2db7dcd826b9 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -477,6 +477,9 @@ void iio_disable_all_buffers(struct iio_dev *indio_dev)
477 indio_dev->currentmode = INDIO_DIRECT_MODE; 477 indio_dev->currentmode = INDIO_DIRECT_MODE;
478 if (indio_dev->setup_ops->postdisable) 478 if (indio_dev->setup_ops->postdisable)
479 indio_dev->setup_ops->postdisable(indio_dev); 479 indio_dev->setup_ops->postdisable(indio_dev);
480
481 if (indio_dev->available_scan_masks == NULL)
482 kfree(indio_dev->active_scan_mask);
480} 483}
481 484
482int iio_update_buffers(struct iio_dev *indio_dev, 485int iio_update_buffers(struct iio_dev *indio_dev,
diff --git a/drivers/infiniband/hw/amso1100/c2_ae.c b/drivers/infiniband/hw/amso1100/c2_ae.c
index d5d1929753e4..cedda25232be 100644
--- a/drivers/infiniband/hw/amso1100/c2_ae.c
+++ b/drivers/infiniband/hw/amso1100/c2_ae.c
@@ -141,7 +141,7 @@ static const char *to_qp_state_str(int state)
141 return "C2_QP_STATE_ERROR"; 141 return "C2_QP_STATE_ERROR";
142 default: 142 default:
143 return "<invalid QP state>"; 143 return "<invalid QP state>";
144 }; 144 }
145} 145}
146 146
147void c2_ae_event(struct c2_dev *c2dev, u32 mq_index) 147void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 3f831de9a4d8..b1a6cb3a2809 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -164,6 +164,7 @@ int mlx5_vector2eqn(struct mlx5_ib_dev *dev, int vector, int *eqn, int *irqn)
164static int alloc_comp_eqs(struct mlx5_ib_dev *dev) 164static int alloc_comp_eqs(struct mlx5_ib_dev *dev)
165{ 165{
166 struct mlx5_eq_table *table = &dev->mdev.priv.eq_table; 166 struct mlx5_eq_table *table = &dev->mdev.priv.eq_table;
167 char name[MLX5_MAX_EQ_NAME];
167 struct mlx5_eq *eq, *n; 168 struct mlx5_eq *eq, *n;
168 int ncomp_vec; 169 int ncomp_vec;
169 int nent; 170 int nent;
@@ -180,11 +181,10 @@ static int alloc_comp_eqs(struct mlx5_ib_dev *dev)
180 goto clean; 181 goto clean;
181 } 182 }
182 183
183 snprintf(eq->name, MLX5_MAX_EQ_NAME, "mlx5_comp%d", i); 184 snprintf(name, MLX5_MAX_EQ_NAME, "mlx5_comp%d", i);
184 err = mlx5_create_map_eq(&dev->mdev, eq, 185 err = mlx5_create_map_eq(&dev->mdev, eq,
185 i + MLX5_EQ_VEC_COMP_BASE, nent, 0, 186 i + MLX5_EQ_VEC_COMP_BASE, nent, 0,
186 eq->name, 187 name, &dev->mdev.priv.uuari.uars[0]);
187 &dev->mdev.priv.uuari.uars[0]);
188 if (err) { 188 if (err) {
189 kfree(eq); 189 kfree(eq);
190 goto clean; 190 goto clean;
@@ -301,9 +301,8 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
301 props->max_srq_sge = max_rq_sg - 1; 301 props->max_srq_sge = max_rq_sg - 1;
302 props->max_fast_reg_page_list_len = (unsigned int)-1; 302 props->max_fast_reg_page_list_len = (unsigned int)-1;
303 props->local_ca_ack_delay = dev->mdev.caps.local_ca_ack_delay; 303 props->local_ca_ack_delay = dev->mdev.caps.local_ca_ack_delay;
304 props->atomic_cap = dev->mdev.caps.flags & MLX5_DEV_CAP_FLAG_ATOMIC ? 304 props->atomic_cap = IB_ATOMIC_NONE;
305 IB_ATOMIC_HCA : IB_ATOMIC_NONE; 305 props->masked_atomic_cap = IB_ATOMIC_NONE;
306 props->masked_atomic_cap = IB_ATOMIC_HCA;
307 props->max_pkeys = be16_to_cpup((__be16 *)(out_mad->data + 28)); 306 props->max_pkeys = be16_to_cpup((__be16 *)(out_mad->data + 28));
308 props->max_mcast_grp = 1 << dev->mdev.caps.log_max_mcg; 307 props->max_mcast_grp = 1 << dev->mdev.caps.log_max_mcg;
309 props->max_mcast_qp_attach = dev->mdev.caps.max_qp_mcg; 308 props->max_mcast_qp_attach = dev->mdev.caps.max_qp_mcg;
@@ -1006,6 +1005,11 @@ static void mlx5_ib_event(struct mlx5_core_dev *dev, enum mlx5_dev_event event,
1006 ibev.device = &ibdev->ib_dev; 1005 ibev.device = &ibdev->ib_dev;
1007 ibev.element.port_num = port; 1006 ibev.element.port_num = port;
1008 1007
1008 if (port < 1 || port > ibdev->num_ports) {
1009 mlx5_ib_warn(ibdev, "warning: event on port %d\n", port);
1010 return;
1011 }
1012
1009 if (ibdev->ib_active) 1013 if (ibdev->ib_active)
1010 ib_dispatch_event(&ibev); 1014 ib_dispatch_event(&ibev);
1011} 1015}
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index bd41df95b6f0..3453580b1eb2 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -42,6 +42,10 @@ enum {
42 DEF_CACHE_SIZE = 10, 42 DEF_CACHE_SIZE = 10,
43}; 43};
44 44
45enum {
46 MLX5_UMR_ALIGN = 2048
47};
48
45static __be64 *mr_align(__be64 *ptr, int align) 49static __be64 *mr_align(__be64 *ptr, int align)
46{ 50{
47 unsigned long mask = align - 1; 51 unsigned long mask = align - 1;
@@ -61,13 +65,11 @@ static int order2idx(struct mlx5_ib_dev *dev, int order)
61 65
62static int add_keys(struct mlx5_ib_dev *dev, int c, int num) 66static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
63{ 67{
64 struct device *ddev = dev->ib_dev.dma_device;
65 struct mlx5_mr_cache *cache = &dev->cache; 68 struct mlx5_mr_cache *cache = &dev->cache;
66 struct mlx5_cache_ent *ent = &cache->ent[c]; 69 struct mlx5_cache_ent *ent = &cache->ent[c];
67 struct mlx5_create_mkey_mbox_in *in; 70 struct mlx5_create_mkey_mbox_in *in;
68 struct mlx5_ib_mr *mr; 71 struct mlx5_ib_mr *mr;
69 int npages = 1 << ent->order; 72 int npages = 1 << ent->order;
70 int size = sizeof(u64) * npages;
71 int err = 0; 73 int err = 0;
72 int i; 74 int i;
73 75
@@ -83,21 +85,6 @@ static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
83 } 85 }
84 mr->order = ent->order; 86 mr->order = ent->order;
85 mr->umred = 1; 87 mr->umred = 1;
86 mr->pas = kmalloc(size + 0x3f, GFP_KERNEL);
87 if (!mr->pas) {
88 kfree(mr);
89 err = -ENOMEM;
90 goto out;
91 }
92 mr->dma = dma_map_single(ddev, mr_align(mr->pas, 0x40), size,
93 DMA_TO_DEVICE);
94 if (dma_mapping_error(ddev, mr->dma)) {
95 kfree(mr->pas);
96 kfree(mr);
97 err = -ENOMEM;
98 goto out;
99 }
100
101 in->seg.status = 1 << 6; 88 in->seg.status = 1 << 6;
102 in->seg.xlt_oct_size = cpu_to_be32((npages + 1) / 2); 89 in->seg.xlt_oct_size = cpu_to_be32((npages + 1) / 2);
103 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 90 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
@@ -108,8 +95,6 @@ static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
108 sizeof(*in)); 95 sizeof(*in));
109 if (err) { 96 if (err) {
110 mlx5_ib_warn(dev, "create mkey failed %d\n", err); 97 mlx5_ib_warn(dev, "create mkey failed %d\n", err);
111 dma_unmap_single(ddev, mr->dma, size, DMA_TO_DEVICE);
112 kfree(mr->pas);
113 kfree(mr); 98 kfree(mr);
114 goto out; 99 goto out;
115 } 100 }
@@ -129,11 +114,9 @@ out:
129 114
130static void remove_keys(struct mlx5_ib_dev *dev, int c, int num) 115static void remove_keys(struct mlx5_ib_dev *dev, int c, int num)
131{ 116{
132 struct device *ddev = dev->ib_dev.dma_device;
133 struct mlx5_mr_cache *cache = &dev->cache; 117 struct mlx5_mr_cache *cache = &dev->cache;
134 struct mlx5_cache_ent *ent = &cache->ent[c]; 118 struct mlx5_cache_ent *ent = &cache->ent[c];
135 struct mlx5_ib_mr *mr; 119 struct mlx5_ib_mr *mr;
136 int size;
137 int err; 120 int err;
138 int i; 121 int i;
139 122
@@ -149,14 +132,10 @@ static void remove_keys(struct mlx5_ib_dev *dev, int c, int num)
149 ent->size--; 132 ent->size--;
150 spin_unlock(&ent->lock); 133 spin_unlock(&ent->lock);
151 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr); 134 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
152 if (err) { 135 if (err)
153 mlx5_ib_warn(dev, "failed destroy mkey\n"); 136 mlx5_ib_warn(dev, "failed destroy mkey\n");
154 } else { 137 else
155 size = ALIGN(sizeof(u64) * (1 << mr->order), 0x40);
156 dma_unmap_single(ddev, mr->dma, size, DMA_TO_DEVICE);
157 kfree(mr->pas);
158 kfree(mr); 138 kfree(mr);
159 }
160 } 139 }
161} 140}
162 141
@@ -408,13 +387,12 @@ static void free_cached_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
408 387
409static void clean_keys(struct mlx5_ib_dev *dev, int c) 388static void clean_keys(struct mlx5_ib_dev *dev, int c)
410{ 389{
411 struct device *ddev = dev->ib_dev.dma_device;
412 struct mlx5_mr_cache *cache = &dev->cache; 390 struct mlx5_mr_cache *cache = &dev->cache;
413 struct mlx5_cache_ent *ent = &cache->ent[c]; 391 struct mlx5_cache_ent *ent = &cache->ent[c];
414 struct mlx5_ib_mr *mr; 392 struct mlx5_ib_mr *mr;
415 int size;
416 int err; 393 int err;
417 394
395 cancel_delayed_work(&ent->dwork);
418 while (1) { 396 while (1) {
419 spin_lock(&ent->lock); 397 spin_lock(&ent->lock);
420 if (list_empty(&ent->head)) { 398 if (list_empty(&ent->head)) {
@@ -427,14 +405,10 @@ static void clean_keys(struct mlx5_ib_dev *dev, int c)
427 ent->size--; 405 ent->size--;
428 spin_unlock(&ent->lock); 406 spin_unlock(&ent->lock);
429 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr); 407 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
430 if (err) { 408 if (err)
431 mlx5_ib_warn(dev, "failed destroy mkey\n"); 409 mlx5_ib_warn(dev, "failed destroy mkey\n");
432 } else { 410 else
433 size = ALIGN(sizeof(u64) * (1 << mr->order), 0x40);
434 dma_unmap_single(ddev, mr->dma, size, DMA_TO_DEVICE);
435 kfree(mr->pas);
436 kfree(mr); 411 kfree(mr);
437 }
438 } 412 }
439} 413}
440 414
@@ -540,13 +514,15 @@ int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev)
540 int i; 514 int i;
541 515
542 dev->cache.stopped = 1; 516 dev->cache.stopped = 1;
543 destroy_workqueue(dev->cache.wq); 517 flush_workqueue(dev->cache.wq);
544 518
545 mlx5_mr_cache_debugfs_cleanup(dev); 519 mlx5_mr_cache_debugfs_cleanup(dev);
546 520
547 for (i = 0; i < MAX_MR_CACHE_ENTRIES; i++) 521 for (i = 0; i < MAX_MR_CACHE_ENTRIES; i++)
548 clean_keys(dev, i); 522 clean_keys(dev, i);
549 523
524 destroy_workqueue(dev->cache.wq);
525
550 return 0; 526 return 0;
551} 527}
552 528
@@ -675,10 +651,12 @@ static struct mlx5_ib_mr *reg_umr(struct ib_pd *pd, struct ib_umem *umem,
675 int page_shift, int order, int access_flags) 651 int page_shift, int order, int access_flags)
676{ 652{
677 struct mlx5_ib_dev *dev = to_mdev(pd->device); 653 struct mlx5_ib_dev *dev = to_mdev(pd->device);
654 struct device *ddev = dev->ib_dev.dma_device;
678 struct umr_common *umrc = &dev->umrc; 655 struct umr_common *umrc = &dev->umrc;
679 struct ib_send_wr wr, *bad; 656 struct ib_send_wr wr, *bad;
680 struct mlx5_ib_mr *mr; 657 struct mlx5_ib_mr *mr;
681 struct ib_sge sg; 658 struct ib_sge sg;
659 int size = sizeof(u64) * npages;
682 int err; 660 int err;
683 int i; 661 int i;
684 662
@@ -697,7 +675,22 @@ static struct mlx5_ib_mr *reg_umr(struct ib_pd *pd, struct ib_umem *umem,
697 if (!mr) 675 if (!mr)
698 return ERR_PTR(-EAGAIN); 676 return ERR_PTR(-EAGAIN);
699 677
700 mlx5_ib_populate_pas(dev, umem, page_shift, mr_align(mr->pas, 0x40), 1); 678 mr->pas = kmalloc(size + MLX5_UMR_ALIGN - 1, GFP_KERNEL);
679 if (!mr->pas) {
680 err = -ENOMEM;
681 goto error;
682 }
683
684 mlx5_ib_populate_pas(dev, umem, page_shift,
685 mr_align(mr->pas, MLX5_UMR_ALIGN), 1);
686
687 mr->dma = dma_map_single(ddev, mr_align(mr->pas, MLX5_UMR_ALIGN), size,
688 DMA_TO_DEVICE);
689 if (dma_mapping_error(ddev, mr->dma)) {
690 kfree(mr->pas);
691 err = -ENOMEM;
692 goto error;
693 }
701 694
702 memset(&wr, 0, sizeof(wr)); 695 memset(&wr, 0, sizeof(wr));
703 wr.wr_id = (u64)(unsigned long)mr; 696 wr.wr_id = (u64)(unsigned long)mr;
@@ -718,6 +711,9 @@ static struct mlx5_ib_mr *reg_umr(struct ib_pd *pd, struct ib_umem *umem,
718 wait_for_completion(&mr->done); 711 wait_for_completion(&mr->done);
719 up(&umrc->sem); 712 up(&umrc->sem);
720 713
714 dma_unmap_single(ddev, mr->dma, size, DMA_TO_DEVICE);
715 kfree(mr->pas);
716
721 if (mr->status != IB_WC_SUCCESS) { 717 if (mr->status != IB_WC_SUCCESS) {
722 mlx5_ib_warn(dev, "reg umr failed\n"); 718 mlx5_ib_warn(dev, "reg umr failed\n");
723 err = -EFAULT; 719 err = -EFAULT;
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 045f8cdbd303..5659ea880741 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -203,7 +203,7 @@ static int sq_overhead(enum ib_qp_type qp_type)
203 203
204 switch (qp_type) { 204 switch (qp_type) {
205 case IB_QPT_XRC_INI: 205 case IB_QPT_XRC_INI:
206 size = sizeof(struct mlx5_wqe_xrc_seg); 206 size += sizeof(struct mlx5_wqe_xrc_seg);
207 /* fall through */ 207 /* fall through */
208 case IB_QPT_RC: 208 case IB_QPT_RC:
209 size += sizeof(struct mlx5_wqe_ctrl_seg) + 209 size += sizeof(struct mlx5_wqe_ctrl_seg) +
@@ -211,20 +211,23 @@ static int sq_overhead(enum ib_qp_type qp_type)
211 sizeof(struct mlx5_wqe_raddr_seg); 211 sizeof(struct mlx5_wqe_raddr_seg);
212 break; 212 break;
213 213
214 case IB_QPT_XRC_TGT:
215 return 0;
216
214 case IB_QPT_UC: 217 case IB_QPT_UC:
215 size = sizeof(struct mlx5_wqe_ctrl_seg) + 218 size += sizeof(struct mlx5_wqe_ctrl_seg) +
216 sizeof(struct mlx5_wqe_raddr_seg); 219 sizeof(struct mlx5_wqe_raddr_seg);
217 break; 220 break;
218 221
219 case IB_QPT_UD: 222 case IB_QPT_UD:
220 case IB_QPT_SMI: 223 case IB_QPT_SMI:
221 case IB_QPT_GSI: 224 case IB_QPT_GSI:
222 size = sizeof(struct mlx5_wqe_ctrl_seg) + 225 size += sizeof(struct mlx5_wqe_ctrl_seg) +
223 sizeof(struct mlx5_wqe_datagram_seg); 226 sizeof(struct mlx5_wqe_datagram_seg);
224 break; 227 break;
225 228
226 case MLX5_IB_QPT_REG_UMR: 229 case MLX5_IB_QPT_REG_UMR:
227 size = sizeof(struct mlx5_wqe_ctrl_seg) + 230 size += sizeof(struct mlx5_wqe_ctrl_seg) +
228 sizeof(struct mlx5_wqe_umr_ctrl_seg) + 231 sizeof(struct mlx5_wqe_umr_ctrl_seg) +
229 sizeof(struct mlx5_mkey_seg); 232 sizeof(struct mlx5_mkey_seg);
230 break; 233 break;
@@ -270,7 +273,8 @@ static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr,
270 return wqe_size; 273 return wqe_size;
271 274
272 if (wqe_size > dev->mdev.caps.max_sq_desc_sz) { 275 if (wqe_size > dev->mdev.caps.max_sq_desc_sz) {
273 mlx5_ib_dbg(dev, "\n"); 276 mlx5_ib_dbg(dev, "wqe_size(%d) > max_sq_desc_sz(%d)\n",
277 wqe_size, dev->mdev.caps.max_sq_desc_sz);
274 return -EINVAL; 278 return -EINVAL;
275 } 279 }
276 280
@@ -280,9 +284,15 @@ static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr,
280 284
281 wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size); 285 wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size);
282 qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB; 286 qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB;
287 if (qp->sq.wqe_cnt > dev->mdev.caps.max_wqes) {
288 mlx5_ib_dbg(dev, "wqe count(%d) exceeds limits(%d)\n",
289 qp->sq.wqe_cnt, dev->mdev.caps.max_wqes);
290 return -ENOMEM;
291 }
283 qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); 292 qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB);
284 qp->sq.max_gs = attr->cap.max_send_sge; 293 qp->sq.max_gs = attr->cap.max_send_sge;
285 qp->sq.max_post = 1 << ilog2(wq_size / wqe_size); 294 qp->sq.max_post = wq_size / wqe_size;
295 attr->cap.max_send_wr = qp->sq.max_post;
286 296
287 return wq_size; 297 return wq_size;
288} 298}
@@ -1280,6 +1290,11 @@ static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_Q
1280 MLX5_QP_OPTPAR_Q_KEY, 1290 MLX5_QP_OPTPAR_Q_KEY,
1281 [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX | 1291 [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX |
1282 MLX5_QP_OPTPAR_Q_KEY, 1292 MLX5_QP_OPTPAR_Q_KEY,
1293 [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH |
1294 MLX5_QP_OPTPAR_RRE |
1295 MLX5_QP_OPTPAR_RAE |
1296 MLX5_QP_OPTPAR_RWE |
1297 MLX5_QP_OPTPAR_PKEY_INDEX,
1283 }, 1298 },
1284 }, 1299 },
1285 [MLX5_QP_STATE_RTR] = { 1300 [MLX5_QP_STATE_RTR] = {
@@ -1314,6 +1329,11 @@ static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_Q
1314 [MLX5_QP_STATE_RTS] = { 1329 [MLX5_QP_STATE_RTS] = {
1315 [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, 1330 [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY,
1316 [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY, 1331 [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY,
1332 [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE,
1333 [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RNR_TIMEOUT |
1334 MLX5_QP_OPTPAR_RWE |
1335 MLX5_QP_OPTPAR_RAE |
1336 MLX5_QP_OPTPAR_RRE,
1317 }, 1337 },
1318 }, 1338 },
1319}; 1339};
@@ -1651,29 +1671,6 @@ static __always_inline void set_raddr_seg(struct mlx5_wqe_raddr_seg *rseg,
1651 rseg->reserved = 0; 1671 rseg->reserved = 0;
1652} 1672}
1653 1673
1654static void set_atomic_seg(struct mlx5_wqe_atomic_seg *aseg, struct ib_send_wr *wr)
1655{
1656 if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
1657 aseg->swap_add = cpu_to_be64(wr->wr.atomic.swap);
1658 aseg->compare = cpu_to_be64(wr->wr.atomic.compare_add);
1659 } else if (wr->opcode == IB_WR_MASKED_ATOMIC_FETCH_AND_ADD) {
1660 aseg->swap_add = cpu_to_be64(wr->wr.atomic.compare_add);
1661 aseg->compare = cpu_to_be64(wr->wr.atomic.compare_add_mask);
1662 } else {
1663 aseg->swap_add = cpu_to_be64(wr->wr.atomic.compare_add);
1664 aseg->compare = 0;
1665 }
1666}
1667
1668static void set_masked_atomic_seg(struct mlx5_wqe_masked_atomic_seg *aseg,
1669 struct ib_send_wr *wr)
1670{
1671 aseg->swap_add = cpu_to_be64(wr->wr.atomic.swap);
1672 aseg->swap_add_mask = cpu_to_be64(wr->wr.atomic.swap_mask);
1673 aseg->compare = cpu_to_be64(wr->wr.atomic.compare_add);
1674 aseg->compare_mask = cpu_to_be64(wr->wr.atomic.compare_add_mask);
1675}
1676
1677static void set_datagram_seg(struct mlx5_wqe_datagram_seg *dseg, 1674static void set_datagram_seg(struct mlx5_wqe_datagram_seg *dseg,
1678 struct ib_send_wr *wr) 1675 struct ib_send_wr *wr)
1679{ 1676{
@@ -2063,28 +2060,11 @@ int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
2063 2060
2064 case IB_WR_ATOMIC_CMP_AND_SWP: 2061 case IB_WR_ATOMIC_CMP_AND_SWP:
2065 case IB_WR_ATOMIC_FETCH_AND_ADD: 2062 case IB_WR_ATOMIC_FETCH_AND_ADD:
2066 set_raddr_seg(seg, wr->wr.atomic.remote_addr,
2067 wr->wr.atomic.rkey);
2068 seg += sizeof(struct mlx5_wqe_raddr_seg);
2069
2070 set_atomic_seg(seg, wr);
2071 seg += sizeof(struct mlx5_wqe_atomic_seg);
2072
2073 size += (sizeof(struct mlx5_wqe_raddr_seg) +
2074 sizeof(struct mlx5_wqe_atomic_seg)) / 16;
2075 break;
2076
2077 case IB_WR_MASKED_ATOMIC_CMP_AND_SWP: 2063 case IB_WR_MASKED_ATOMIC_CMP_AND_SWP:
2078 set_raddr_seg(seg, wr->wr.atomic.remote_addr, 2064 mlx5_ib_warn(dev, "Atomic operations are not supported yet\n");
2079 wr->wr.atomic.rkey); 2065 err = -ENOSYS;
2080 seg += sizeof(struct mlx5_wqe_raddr_seg); 2066 *bad_wr = wr;
2081 2067 goto out;
2082 set_masked_atomic_seg(seg, wr);
2083 seg += sizeof(struct mlx5_wqe_masked_atomic_seg);
2084
2085 size += (sizeof(struct mlx5_wqe_raddr_seg) +
2086 sizeof(struct mlx5_wqe_masked_atomic_seg)) / 16;
2087 break;
2088 2068
2089 case IB_WR_LOCAL_INV: 2069 case IB_WR_LOCAL_INV:
2090 next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL; 2070 next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL;
diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c
index 84d297afd6a9..0aa478bc291a 100644
--- a/drivers/infiniband/hw/mlx5/srq.c
+++ b/drivers/infiniband/hw/mlx5/srq.c
@@ -295,7 +295,7 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
295 mlx5_vfree(in); 295 mlx5_vfree(in);
296 if (err) { 296 if (err) {
297 mlx5_ib_dbg(dev, "create SRQ failed, err %d\n", err); 297 mlx5_ib_dbg(dev, "create SRQ failed, err %d\n", err);
298 goto err_srq; 298 goto err_usr_kern_srq;
299 } 299 }
300 300
301 mlx5_ib_dbg(dev, "create SRQ with srqn 0x%x\n", srq->msrq.srqn); 301 mlx5_ib_dbg(dev, "create SRQ with srqn 0x%x\n", srq->msrq.srqn);
@@ -316,6 +316,8 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
316 316
317err_core: 317err_core:
318 mlx5_core_destroy_srq(&dev->mdev, &srq->msrq); 318 mlx5_core_destroy_srq(&dev->mdev, &srq->msrq);
319
320err_usr_kern_srq:
319 if (pd->uobject) 321 if (pd->uobject)
320 destroy_srq_user(pd, srq); 322 destroy_srq_user(pd, srq);
321 else 323 else
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index 7c9d35f39d75..690201738993 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -357,7 +357,7 @@ static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
357 mthca_warn(dev, "Unhandled event %02x(%02x) on EQ %d\n", 357 mthca_warn(dev, "Unhandled event %02x(%02x) on EQ %d\n",
358 eqe->type, eqe->subtype, eq->eqn); 358 eqe->type, eqe->subtype, eq->eqn);
359 break; 359 break;
360 }; 360 }
361 361
362 set_eqe_hw(eqe); 362 set_eqe_hw(eqe);
363 ++eq->cons_index; 363 ++eq->cons_index;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 4ed8235d2d36..50219ab2279d 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -150,7 +150,7 @@ enum ib_qp_state get_ibqp_state(enum ocrdma_qp_state qps)
150 return IB_QPS_SQE; 150 return IB_QPS_SQE;
151 case OCRDMA_QPS_ERR: 151 case OCRDMA_QPS_ERR:
152 return IB_QPS_ERR; 152 return IB_QPS_ERR;
153 }; 153 }
154 return IB_QPS_ERR; 154 return IB_QPS_ERR;
155} 155}
156 156
@@ -171,7 +171,7 @@ static enum ocrdma_qp_state get_ocrdma_qp_state(enum ib_qp_state qps)
171 return OCRDMA_QPS_SQE; 171 return OCRDMA_QPS_SQE;
172 case IB_QPS_ERR: 172 case IB_QPS_ERR:
173 return OCRDMA_QPS_ERR; 173 return OCRDMA_QPS_ERR;
174 }; 174 }
175 return OCRDMA_QPS_ERR; 175 return OCRDMA_QPS_ERR;
176} 176}
177 177
@@ -1982,7 +1982,7 @@ int ocrdma_mbx_create_qp(struct ocrdma_qp *qp, struct ib_qp_init_attr *attrs,
1982 break; 1982 break;
1983 default: 1983 default:
1984 return -EINVAL; 1984 return -EINVAL;
1985 }; 1985 }
1986 1986
1987 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_CREATE_QP, sizeof(*cmd)); 1987 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_CREATE_QP, sizeof(*cmd));
1988 if (!cmd) 1988 if (!cmd)
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
index 56e004940f18..0ce7674621ea 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
@@ -531,7 +531,7 @@ static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event)
531 case BE_DEV_DOWN: 531 case BE_DEV_DOWN:
532 ocrdma_close(dev); 532 ocrdma_close(dev);
533 break; 533 break;
534 }; 534 }
535} 535}
536 536
537static struct ocrdma_driver ocrdma_drv = { 537static struct ocrdma_driver ocrdma_drv = {
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 6e982bb43c31..69f1d1221a6b 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -141,7 +141,7 @@ static inline void get_link_speed_and_width(struct ocrdma_dev *dev,
141 /* Unsupported */ 141 /* Unsupported */
142 *ib_speed = IB_SPEED_SDR; 142 *ib_speed = IB_SPEED_SDR;
143 *ib_width = IB_WIDTH_1X; 143 *ib_width = IB_WIDTH_1X;
144 }; 144 }
145} 145}
146 146
147 147
@@ -2331,7 +2331,7 @@ static enum ib_wc_status ocrdma_to_ibwc_err(u16 status)
2331 default: 2331 default:
2332 ibwc_status = IB_WC_GENERAL_ERR; 2332 ibwc_status = IB_WC_GENERAL_ERR;
2333 break; 2333 break;
2334 }; 2334 }
2335 return ibwc_status; 2335 return ibwc_status;
2336} 2336}
2337 2337
@@ -2370,7 +2370,7 @@ static void ocrdma_update_wc(struct ocrdma_qp *qp, struct ib_wc *ibwc,
2370 pr_err("%s() invalid opcode received = 0x%x\n", 2370 pr_err("%s() invalid opcode received = 0x%x\n",
2371 __func__, hdr->cw & OCRDMA_WQE_OPCODE_MASK); 2371 __func__, hdr->cw & OCRDMA_WQE_OPCODE_MASK);
2372 break; 2372 break;
2373 }; 2373 }
2374} 2374}
2375 2375
2376static void ocrdma_set_cqe_status_flushed(struct ocrdma_qp *qp, 2376static void ocrdma_set_cqe_status_flushed(struct ocrdma_qp *qp,
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index 4caa8e6d59d7..2d2b1b7588d7 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -269,6 +269,14 @@ static chunk_t area_location(struct pstore *ps, chunk_t area)
269 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area); 269 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area);
270} 270}
271 271
272static void skip_metadata(struct pstore *ps)
273{
274 uint32_t stride = ps->exceptions_per_area + 1;
275 chunk_t next_free = ps->next_free;
276 if (sector_div(next_free, stride) == NUM_SNAPSHOT_HDR_CHUNKS)
277 ps->next_free++;
278}
279
272/* 280/*
273 * Read or write a metadata area. Remembering to skip the first 281 * Read or write a metadata area. Remembering to skip the first
274 * chunk which holds the header. 282 * chunk which holds the header.
@@ -502,6 +510,8 @@ static int read_exceptions(struct pstore *ps,
502 510
503 ps->current_area--; 511 ps->current_area--;
504 512
513 skip_metadata(ps);
514
505 return 0; 515 return 0;
506} 516}
507 517
@@ -616,8 +626,6 @@ static int persistent_prepare_exception(struct dm_exception_store *store,
616 struct dm_exception *e) 626 struct dm_exception *e)
617{ 627{
618 struct pstore *ps = get_info(store); 628 struct pstore *ps = get_info(store);
619 uint32_t stride;
620 chunk_t next_free;
621 sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev); 629 sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev);
622 630
623 /* Is there enough room ? */ 631 /* Is there enough room ? */
@@ -630,10 +638,8 @@ static int persistent_prepare_exception(struct dm_exception_store *store,
630 * Move onto the next free pending, making sure to take 638 * Move onto the next free pending, making sure to take
631 * into account the location of the metadata chunks. 639 * into account the location of the metadata chunks.
632 */ 640 */
633 stride = (ps->exceptions_per_area + 1); 641 ps->next_free++;
634 next_free = ++ps->next_free; 642 skip_metadata(ps);
635 if (sector_div(next_free, stride) == 1)
636 ps->next_free++;
637 643
638 atomic_inc(&ps->pending_count); 644 atomic_inc(&ps->pending_count);
639 return 0; 645 return 0;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 5472cbd34028..6ca30739625f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -180,28 +180,32 @@ static int verify_block_sig(struct mlx5_cmd_prot_block *block)
180 return 0; 180 return 0;
181} 181}
182 182
183static void calc_block_sig(struct mlx5_cmd_prot_block *block, u8 token) 183static void calc_block_sig(struct mlx5_cmd_prot_block *block, u8 token,
184 int csum)
184{ 185{
185 block->token = token; 186 block->token = token;
186 block->ctrl_sig = ~xor8_buf(block->rsvd0, sizeof(*block) - sizeof(block->data) - 2); 187 if (csum) {
187 block->sig = ~xor8_buf(block, sizeof(*block) - 1); 188 block->ctrl_sig = ~xor8_buf(block->rsvd0, sizeof(*block) -
189 sizeof(block->data) - 2);
190 block->sig = ~xor8_buf(block, sizeof(*block) - 1);
191 }
188} 192}
189 193
190static void calc_chain_sig(struct mlx5_cmd_msg *msg, u8 token) 194static void calc_chain_sig(struct mlx5_cmd_msg *msg, u8 token, int csum)
191{ 195{
192 struct mlx5_cmd_mailbox *next = msg->next; 196 struct mlx5_cmd_mailbox *next = msg->next;
193 197
194 while (next) { 198 while (next) {
195 calc_block_sig(next->buf, token); 199 calc_block_sig(next->buf, token, csum);
196 next = next->next; 200 next = next->next;
197 } 201 }
198} 202}
199 203
200static void set_signature(struct mlx5_cmd_work_ent *ent) 204static void set_signature(struct mlx5_cmd_work_ent *ent, int csum)
201{ 205{
202 ent->lay->sig = ~xor8_buf(ent->lay, sizeof(*ent->lay)); 206 ent->lay->sig = ~xor8_buf(ent->lay, sizeof(*ent->lay));
203 calc_chain_sig(ent->in, ent->token); 207 calc_chain_sig(ent->in, ent->token, csum);
204 calc_chain_sig(ent->out, ent->token); 208 calc_chain_sig(ent->out, ent->token, csum);
205} 209}
206 210
207static void poll_timeout(struct mlx5_cmd_work_ent *ent) 211static void poll_timeout(struct mlx5_cmd_work_ent *ent)
@@ -539,8 +543,7 @@ static void cmd_work_handler(struct work_struct *work)
539 lay->type = MLX5_PCI_CMD_XPORT; 543 lay->type = MLX5_PCI_CMD_XPORT;
540 lay->token = ent->token; 544 lay->token = ent->token;
541 lay->status_own = CMD_OWNER_HW; 545 lay->status_own = CMD_OWNER_HW;
542 if (!cmd->checksum_disabled) 546 set_signature(ent, !cmd->checksum_disabled);
543 set_signature(ent);
544 dump_command(dev, ent, 1); 547 dump_command(dev, ent, 1);
545 ktime_get_ts(&ent->ts1); 548 ktime_get_ts(&ent->ts1);
546 549
@@ -773,8 +776,6 @@ static int mlx5_copy_from_msg(void *to, struct mlx5_cmd_msg *from, int size)
773 776
774 copy = min_t(int, size, MLX5_CMD_DATA_BLOCK_SIZE); 777 copy = min_t(int, size, MLX5_CMD_DATA_BLOCK_SIZE);
775 block = next->buf; 778 block = next->buf;
776 if (xor8_buf(block, sizeof(*block)) != 0xff)
777 return -EINVAL;
778 779
779 memcpy(to, block->data, copy); 780 memcpy(to, block->data, copy);
780 to += copy; 781 to += copy;
@@ -1361,6 +1362,7 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
1361 goto err_map; 1362 goto err_map;
1362 } 1363 }
1363 1364
1365 cmd->checksum_disabled = 1;
1364 cmd->max_reg_cmds = (1 << cmd->log_sz) - 1; 1366 cmd->max_reg_cmds = (1 << cmd->log_sz) - 1;
1365 cmd->bitmask = (1 << cmd->max_reg_cmds) - 1; 1367 cmd->bitmask = (1 << cmd->max_reg_cmds) - 1;
1366 1368
@@ -1510,7 +1512,7 @@ int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr)
1510 case MLX5_CMD_STAT_BAD_SYS_STATE_ERR: return -EIO; 1512 case MLX5_CMD_STAT_BAD_SYS_STATE_ERR: return -EIO;
1511 case MLX5_CMD_STAT_BAD_RES_ERR: return -EINVAL; 1513 case MLX5_CMD_STAT_BAD_RES_ERR: return -EINVAL;
1512 case MLX5_CMD_STAT_RES_BUSY: return -EBUSY; 1514 case MLX5_CMD_STAT_RES_BUSY: return -EBUSY;
1513 case MLX5_CMD_STAT_LIM_ERR: return -EINVAL; 1515 case MLX5_CMD_STAT_LIM_ERR: return -ENOMEM;
1514 case MLX5_CMD_STAT_BAD_RES_STATE_ERR: return -EINVAL; 1516 case MLX5_CMD_STAT_BAD_RES_STATE_ERR: return -EINVAL;
1515 case MLX5_CMD_STAT_IX_ERR: return -EINVAL; 1517 case MLX5_CMD_STAT_IX_ERR: return -EINVAL;
1516 case MLX5_CMD_STAT_NO_RES_ERR: return -EAGAIN; 1518 case MLX5_CMD_STAT_NO_RES_ERR: return -EAGAIN;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index 443cc4d7b024..2231d93cc7ad 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -366,9 +366,11 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
366 goto err_in; 366 goto err_in;
367 } 367 }
368 368
369 snprintf(eq->name, MLX5_MAX_EQ_NAME, "%s@pci:%s",
370 name, pci_name(dev->pdev));
369 eq->eqn = out.eq_number; 371 eq->eqn = out.eq_number;
370 err = request_irq(table->msix_arr[vecidx].vector, mlx5_msix_handler, 0, 372 err = request_irq(table->msix_arr[vecidx].vector, mlx5_msix_handler, 0,
371 name, eq); 373 eq->name, eq);
372 if (err) 374 if (err)
373 goto err_eq; 375 goto err_eq;
374 376
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index b47739b0b5f6..bc0f5fb66e24 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -165,9 +165,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
165 struct mlx5_cmd_set_hca_cap_mbox_in *set_ctx = NULL; 165 struct mlx5_cmd_set_hca_cap_mbox_in *set_ctx = NULL;
166 struct mlx5_cmd_query_hca_cap_mbox_in query_ctx; 166 struct mlx5_cmd_query_hca_cap_mbox_in query_ctx;
167 struct mlx5_cmd_set_hca_cap_mbox_out set_out; 167 struct mlx5_cmd_set_hca_cap_mbox_out set_out;
168 struct mlx5_profile *prof = dev->profile;
169 u64 flags; 168 u64 flags;
170 int csum = 1;
171 int err; 169 int err;
172 170
173 memset(&query_ctx, 0, sizeof(query_ctx)); 171 memset(&query_ctx, 0, sizeof(query_ctx));
@@ -197,20 +195,14 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
197 memcpy(&set_ctx->hca_cap, &query_out->hca_cap, 195 memcpy(&set_ctx->hca_cap, &query_out->hca_cap,
198 sizeof(set_ctx->hca_cap)); 196 sizeof(set_ctx->hca_cap));
199 197
200 if (prof->mask & MLX5_PROF_MASK_CMDIF_CSUM) {
201 csum = !!prof->cmdif_csum;
202 flags = be64_to_cpu(set_ctx->hca_cap.flags);
203 if (csum)
204 flags |= MLX5_DEV_CAP_FLAG_CMDIF_CSUM;
205 else
206 flags &= ~MLX5_DEV_CAP_FLAG_CMDIF_CSUM;
207
208 set_ctx->hca_cap.flags = cpu_to_be64(flags);
209 }
210
211 if (dev->profile->mask & MLX5_PROF_MASK_QP_SIZE) 198 if (dev->profile->mask & MLX5_PROF_MASK_QP_SIZE)
212 set_ctx->hca_cap.log_max_qp = dev->profile->log_max_qp; 199 set_ctx->hca_cap.log_max_qp = dev->profile->log_max_qp;
213 200
201 flags = be64_to_cpu(query_out->hca_cap.flags);
202 /* disable checksum */
203 flags &= ~MLX5_DEV_CAP_FLAG_CMDIF_CSUM;
204
205 set_ctx->hca_cap.flags = cpu_to_be64(flags);
214 memset(&set_out, 0, sizeof(set_out)); 206 memset(&set_out, 0, sizeof(set_out));
215 set_ctx->hca_cap.log_uar_page_sz = cpu_to_be16(PAGE_SHIFT - 12); 207 set_ctx->hca_cap.log_uar_page_sz = cpu_to_be16(PAGE_SHIFT - 12);
216 set_ctx->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_SET_HCA_CAP); 208 set_ctx->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_SET_HCA_CAP);
@@ -225,9 +217,6 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
225 if (err) 217 if (err)
226 goto query_ex; 218 goto query_ex;
227 219
228 if (!csum)
229 dev->cmd.checksum_disabled = 1;
230
231query_ex: 220query_ex:
232 kfree(query_out); 221 kfree(query_out);
233 kfree(set_ctx); 222 kfree(set_ctx);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
index 3a2408d44820..7b12acf210f8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
@@ -90,6 +90,10 @@ struct mlx5_manage_pages_outbox {
90 __be64 pas[0]; 90 __be64 pas[0];
91}; 91};
92 92
93enum {
94 MAX_RECLAIM_TIME_MSECS = 5000,
95};
96
93static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u16 func_id) 97static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u16 func_id)
94{ 98{
95 struct rb_root *root = &dev->priv.page_root; 99 struct rb_root *root = &dev->priv.page_root;
@@ -279,6 +283,9 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u32 func_id, int npages,
279 int err; 283 int err;
280 int i; 284 int i;
281 285
286 if (nclaimed)
287 *nclaimed = 0;
288
282 memset(&in, 0, sizeof(in)); 289 memset(&in, 0, sizeof(in));
283 outlen = sizeof(*out) + npages * sizeof(out->pas[0]); 290 outlen = sizeof(*out) + npages * sizeof(out->pas[0]);
284 out = mlx5_vzalloc(outlen); 291 out = mlx5_vzalloc(outlen);
@@ -388,20 +395,25 @@ static int optimal_reclaimed_pages(void)
388 395
389int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev) 396int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev)
390{ 397{
391 unsigned long end = jiffies + msecs_to_jiffies(5000); 398 unsigned long end = jiffies + msecs_to_jiffies(MAX_RECLAIM_TIME_MSECS);
392 struct fw_page *fwp; 399 struct fw_page *fwp;
393 struct rb_node *p; 400 struct rb_node *p;
401 int nclaimed = 0;
394 int err; 402 int err;
395 403
396 do { 404 do {
397 p = rb_first(&dev->priv.page_root); 405 p = rb_first(&dev->priv.page_root);
398 if (p) { 406 if (p) {
399 fwp = rb_entry(p, struct fw_page, rb_node); 407 fwp = rb_entry(p, struct fw_page, rb_node);
400 err = reclaim_pages(dev, fwp->func_id, optimal_reclaimed_pages(), NULL); 408 err = reclaim_pages(dev, fwp->func_id,
409 optimal_reclaimed_pages(),
410 &nclaimed);
401 if (err) { 411 if (err) {
402 mlx5_core_warn(dev, "failed reclaiming pages (%d)\n", err); 412 mlx5_core_warn(dev, "failed reclaiming pages (%d)\n", err);
403 return err; 413 return err;
404 } 414 }
415 if (nclaimed)
416 end = jiffies + msecs_to_jiffies(MAX_RECLAIM_TIME_MSECS);
405 } 417 }
406 if (time_after(jiffies, end)) { 418 if (time_after(jiffies, end)) {
407 mlx5_core_warn(dev, "FW did not return all pages. giving up...\n"); 419 mlx5_core_warn(dev, "FW did not return all pages. giving up...\n");
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 9d2009a9004d..78cc76053328 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -74,10 +74,4 @@ config OF_MTD
74 depends on MTD 74 depends on MTD
75 def_bool y 75 def_bool y
76 76
77config OF_RESERVED_MEM
78 depends on OF_FLATTREE && (DMA_CMA || (HAVE_GENERIC_DMA_COHERENT && HAVE_MEMBLOCK))
79 def_bool y
80 help
81 Initialization code for DMA reserved memory
82
83endmenu # OF 77endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index ed9660adad77..efd05102c405 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -9,4 +9,3 @@ obj-$(CONFIG_OF_MDIO) += of_mdio.o
9obj-$(CONFIG_OF_PCI) += of_pci.o 9obj-$(CONFIG_OF_PCI) += of_pci.o
10obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o 10obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o
11obj-$(CONFIG_OF_MTD) += of_mtd.o 11obj-$(CONFIG_OF_MTD) += of_mtd.o
12obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 865d3f66c86b..7d4c70f859e3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -303,10 +303,8 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
303 struct device_node *cpun, *cpus; 303 struct device_node *cpun, *cpus;
304 304
305 cpus = of_find_node_by_path("/cpus"); 305 cpus = of_find_node_by_path("/cpus");
306 if (!cpus) { 306 if (!cpus)
307 pr_warn("Missing cpus node, bailing out\n");
308 return NULL; 307 return NULL;
309 }
310 308
311 for_each_child_of_node(cpus, cpun) { 309 for_each_child_of_node(cpus, cpun) {
312 if (of_node_cmp(cpun->type, "cpu")) 310 if (of_node_cmp(cpun->type, "cpu"))
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 229dd9d69e18..a4fa9ad31b8f 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -18,7 +18,6 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/random.h>
22 21
23#include <asm/setup.h> /* for COMMAND_LINE_SIZE */ 22#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
24#ifdef CONFIG_PPC 23#ifdef CONFIG_PPC
@@ -803,14 +802,3 @@ void __init unflatten_device_tree(void)
803} 802}
804 803
805#endif /* CONFIG_OF_EARLY_FLATTREE */ 804#endif /* CONFIG_OF_EARLY_FLATTREE */
806
807/* Feed entire flattened device tree into the random pool */
808static int __init add_fdt_randomness(void)
809{
810 if (initial_boot_params)
811 add_device_randomness(initial_boot_params,
812 be32_to_cpu(initial_boot_params->totalsize));
813
814 return 0;
815}
816core_initcall(add_fdt_randomness);
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
deleted file mode 100644
index 0fe40c7d6904..000000000000
--- a/drivers/of/of_reserved_mem.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/*
2 * Device tree based initialization code for reserved memory.
3 *
4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 * Author: Marek Szyprowski <m.szyprowski@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License or (at your optional) any later version of the license.
12 */
13
14#include <linux/memblock.h>
15#include <linux/err.h>
16#include <linux/of.h>
17#include <linux/of_fdt.h>
18#include <linux/of_platform.h>
19#include <linux/mm.h>
20#include <linux/sizes.h>
21#include <linux/mm_types.h>
22#include <linux/dma-contiguous.h>
23#include <linux/dma-mapping.h>
24#include <linux/of_reserved_mem.h>
25
26#define MAX_RESERVED_REGIONS 16
27struct reserved_mem {
28 phys_addr_t base;
29 unsigned long size;
30 struct cma *cma;
31 char name[32];
32};
33static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS];
34static int reserved_mem_count;
35
36static int __init fdt_scan_reserved_mem(unsigned long node, const char *uname,
37 int depth, void *data)
38{
39 struct reserved_mem *rmem = &reserved_mem[reserved_mem_count];
40 phys_addr_t base, size;
41 int is_cma, is_reserved;
42 unsigned long len;
43 const char *status;
44 __be32 *prop;
45
46 is_cma = IS_ENABLED(CONFIG_DMA_CMA) &&
47 of_flat_dt_is_compatible(node, "linux,contiguous-memory-region");
48 is_reserved = of_flat_dt_is_compatible(node, "reserved-memory-region");
49
50 if (!is_reserved && !is_cma) {
51 /* ignore node and scan next one */
52 return 0;
53 }
54
55 status = of_get_flat_dt_prop(node, "status", &len);
56 if (status && strcmp(status, "okay") != 0) {
57 /* ignore disabled node nad scan next one */
58 return 0;
59 }
60
61 prop = of_get_flat_dt_prop(node, "reg", &len);
62 if (!prop || (len < (dt_root_size_cells + dt_root_addr_cells) *
63 sizeof(__be32))) {
64 pr_err("Reserved mem: node %s, incorrect \"reg\" property\n",
65 uname);
66 /* ignore node and scan next one */
67 return 0;
68 }
69 base = dt_mem_next_cell(dt_root_addr_cells, &prop);
70 size = dt_mem_next_cell(dt_root_size_cells, &prop);
71
72 if (!size) {
73 /* ignore node and scan next one */
74 return 0;
75 }
76
77 pr_info("Reserved mem: found %s, memory base %lx, size %ld MiB\n",
78 uname, (unsigned long)base, (unsigned long)size / SZ_1M);
79
80 if (reserved_mem_count == ARRAY_SIZE(reserved_mem))
81 return -ENOSPC;
82
83 rmem->base = base;
84 rmem->size = size;
85 strlcpy(rmem->name, uname, sizeof(rmem->name));
86
87 if (is_cma) {
88 struct cma *cma;
89 if (dma_contiguous_reserve_area(size, base, 0, &cma) == 0) {
90 rmem->cma = cma;
91 reserved_mem_count++;
92 if (of_get_flat_dt_prop(node,
93 "linux,default-contiguous-region",
94 NULL))
95 dma_contiguous_set_default(cma);
96 }
97 } else if (is_reserved) {
98 if (memblock_remove(base, size) == 0)
99 reserved_mem_count++;
100 else
101 pr_err("Failed to reserve memory for %s\n", uname);
102 }
103
104 return 0;
105}
106
107static struct reserved_mem *get_dma_memory_region(struct device *dev)
108{
109 struct device_node *node;
110 const char *name;
111 int i;
112
113 node = of_parse_phandle(dev->of_node, "memory-region", 0);
114 if (!node)
115 return NULL;
116
117 name = kbasename(node->full_name);
118 for (i = 0; i < reserved_mem_count; i++)
119 if (strcmp(name, reserved_mem[i].name) == 0)
120 return &reserved_mem[i];
121 return NULL;
122}
123
124/**
125 * of_reserved_mem_device_init() - assign reserved memory region to given device
126 *
127 * This function assign memory region pointed by "memory-region" device tree
128 * property to the given device.
129 */
130void of_reserved_mem_device_init(struct device *dev)
131{
132 struct reserved_mem *region = get_dma_memory_region(dev);
133 if (!region)
134 return;
135
136 if (region->cma) {
137 dev_set_cma_area(dev, region->cma);
138 pr_info("Assigned CMA %s to %s device\n", region->name,
139 dev_name(dev));
140 } else {
141 if (dma_declare_coherent_memory(dev, region->base, region->base,
142 region->size, DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) != 0)
143 pr_info("Declared reserved memory %s to %s device\n",
144 region->name, dev_name(dev));
145 }
146}
147
148/**
149 * of_reserved_mem_device_release() - release reserved memory device structures
150 *
151 * This function releases structures allocated for memory region handling for
152 * the given device.
153 */
154void of_reserved_mem_device_release(struct device *dev)
155{
156 struct reserved_mem *region = get_dma_memory_region(dev);
157 if (!region && !region->cma)
158 dma_release_declared_memory(dev);
159}
160
161/**
162 * early_init_dt_scan_reserved_mem() - create reserved memory regions
163 *
164 * This function grabs memory from early allocator for device exclusive use
165 * defined in device tree structures. It should be called by arch specific code
166 * once the early allocator (memblock) has been activated and all other
167 * subsystems have already allocated/reserved memory.
168 */
169void __init early_init_dt_scan_reserved_mem(void)
170{
171 of_scan_flat_dt_by_path("/memory/reserved-memory",
172 fdt_scan_reserved_mem, NULL);
173}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9b439ac63d8e..f6dcde220821 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -21,7 +21,6 @@
21#include <linux/of_device.h> 21#include <linux/of_device.h>
22#include <linux/of_irq.h> 22#include <linux/of_irq.h>
23#include <linux/of_platform.h> 23#include <linux/of_platform.h>
24#include <linux/of_reserved_mem.h>
25#include <linux/platform_device.h> 24#include <linux/platform_device.h>
26 25
27const struct of_device_id of_default_bus_match_table[] = { 26const struct of_device_id of_default_bus_match_table[] = {
@@ -219,8 +218,6 @@ static struct platform_device *of_platform_device_create_pdata(
219 dev->dev.bus = &platform_bus_type; 218 dev->dev.bus = &platform_bus_type;
220 dev->dev.platform_data = platform_data; 219 dev->dev.platform_data = platform_data;
221 220
222 of_reserved_mem_device_init(&dev->dev);
223
224 /* We do not fill the DMA ops for platform devices by default. 221 /* We do not fill the DMA ops for platform devices by default.
225 * This is currently the responsibility of the platform code 222 * This is currently the responsibility of the platform code
226 * to do such, possibly using a device notifier 223 * to do such, possibly using a device notifier
@@ -228,7 +225,6 @@ static struct platform_device *of_platform_device_create_pdata(
228 225
229 if (of_device_add(dev) != 0) { 226 if (of_device_add(dev) != 0) {
230 platform_device_put(dev); 227 platform_device_put(dev);
231 of_reserved_mem_device_release(&dev->dev);
232 return NULL; 228 return NULL;
233 } 229 }
234 230
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 0b7d23b4ad95..be12fbfcae10 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -994,14 +994,16 @@ void acpiphp_enumerate_slots(struct pci_bus *bus)
994 994
995 /* 995 /*
996 * This bridge should have been registered as a hotplug function 996 * This bridge should have been registered as a hotplug function
997 * under its parent, so the context has to be there. If not, we 997 * under its parent, so the context should be there, unless the
998 * are in deep goo. 998 * parent is going to be handled by pciehp, in which case this
999 * bridge is not interesting to us either.
999 */ 1000 */
1000 mutex_lock(&acpiphp_context_lock); 1001 mutex_lock(&acpiphp_context_lock);
1001 context = acpiphp_get_context(handle); 1002 context = acpiphp_get_context(handle);
1002 if (WARN_ON(!context)) { 1003 if (!context) {
1003 mutex_unlock(&acpiphp_context_lock); 1004 mutex_unlock(&acpiphp_context_lock);
1004 put_device(&bus->dev); 1005 put_device(&bus->dev);
1006 pci_dev_put(bridge->pci_dev);
1005 kfree(bridge); 1007 kfree(bridge);
1006 return; 1008 return;
1007 } 1009 }
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index b9c53cc40e1f..eb1f1ef5fa2e 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -264,6 +264,7 @@ config SPI_FSL_SPI
264config SPI_FSL_DSPI 264config SPI_FSL_DSPI
265 tristate "Freescale DSPI controller" 265 tristate "Freescale DSPI controller"
266 select SPI_BITBANG 266 select SPI_BITBANG
267 depends on SOC_VF610 || COMPILE_TEST
267 help 268 help
268 This enables support for the Freescale DSPI controller in master 269 This enables support for the Freescale DSPI controller in master
269 mode. VF610 platform uses the controller. 270 mode. VF610 platform uses the controller.
@@ -369,7 +370,7 @@ config SPI_PXA2XX_PCI
369 370
370config SPI_RSPI 371config SPI_RSPI
371 tristate "Renesas RSPI controller" 372 tristate "Renesas RSPI controller"
372 depends on SUPERH && SH_DMAE_BASE 373 depends on (SUPERH || ARCH_SHMOBILE) && SH_DMAE_BASE
373 help 374 help
374 SPI driver for Renesas RSPI blocks. 375 SPI driver for Renesas RSPI blocks.
375 376
@@ -393,7 +394,7 @@ config SPI_S3C24XX_FIQ
393 394
394config SPI_S3C64XX 395config SPI_S3C64XX
395 tristate "Samsung S3C64XX series type SPI" 396 tristate "Samsung S3C64XX series type SPI"
396 depends on (ARCH_S3C24XX || ARCH_S3C64XX || ARCH_S5P64X0 || ARCH_EXYNOS) 397 depends on PLAT_SAMSUNG
397 select S3C64XX_DMA if ARCH_S3C64XX 398 select S3C64XX_DMA if ARCH_S3C64XX
398 help 399 help
399 SPI driver for Samsung S3C64XX and newer SoCs. 400 SPI driver for Samsung S3C64XX and newer SoCs.
diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c
index 9a64c3fee218..595b62cb545d 100644
--- a/drivers/spi/spi-altera.c
+++ b/drivers/spi/spi-altera.c
@@ -219,7 +219,7 @@ static int altera_spi_probe(struct platform_device *pdev)
219 platform_set_drvdata(pdev, hw); 219 platform_set_drvdata(pdev, hw);
220 220
221 /* setup the state for the bitbang driver */ 221 /* setup the state for the bitbang driver */
222 hw->bitbang.master = spi_master_get(master); 222 hw->bitbang.master = master;
223 if (!hw->bitbang.master) 223 if (!hw->bitbang.master)
224 return err; 224 return err;
225 hw->bitbang.chipselect = altera_spi_chipsel; 225 hw->bitbang.chipselect = altera_spi_chipsel;
diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 37bad952ab38..821bf7ac218d 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -231,7 +231,7 @@ static int ath79_spi_probe(struct platform_device *pdev)
231 master->num_chipselect = pdata->num_chipselect; 231 master->num_chipselect = pdata->num_chipselect;
232 } 232 }
233 233
234 sp->bitbang.master = spi_master_get(master); 234 sp->bitbang.master = master;
235 sp->bitbang.chipselect = ath79_spi_chipselect; 235 sp->bitbang.chipselect = ath79_spi_chipselect;
236 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0; 236 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0;
237 sp->bitbang.setup_transfer = spi_bitbang_setup_transfer; 237 sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index d4ac60b4a56e..273db0beb2b8 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -170,18 +170,18 @@
170/* Bit manipulation macros */ 170/* Bit manipulation macros */
171#define SPI_BIT(name) \ 171#define SPI_BIT(name) \
172 (1 << SPI_##name##_OFFSET) 172 (1 << SPI_##name##_OFFSET)
173#define SPI_BF(name,value) \ 173#define SPI_BF(name, value) \
174 (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET) 174 (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET)
175#define SPI_BFEXT(name,value) \ 175#define SPI_BFEXT(name, value) \
176 (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1)) 176 (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1))
177#define SPI_BFINS(name,value,old) \ 177#define SPI_BFINS(name, value, old) \
178 ( ((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) \ 178 (((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) \
179 | SPI_BF(name,value)) 179 | SPI_BF(name, value))
180 180
181/* Register access macros */ 181/* Register access macros */
182#define spi_readl(port,reg) \ 182#define spi_readl(port, reg) \
183 __raw_readl((port)->regs + SPI_##reg) 183 __raw_readl((port)->regs + SPI_##reg)
184#define spi_writel(port,reg,value) \ 184#define spi_writel(port, reg, value) \
185 __raw_writel((value), (port)->regs + SPI_##reg) 185 __raw_writel((value), (port)->regs + SPI_##reg)
186 186
187/* use PIO for small transfers, avoiding DMA setup/teardown overhead and 187/* use PIO for small transfers, avoiding DMA setup/teardown overhead and
@@ -1401,8 +1401,8 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
1401 asd = spi->controller_state; 1401 asd = spi->controller_state;
1402 bits = (asd->csr >> 4) & 0xf; 1402 bits = (asd->csr >> 4) & 0xf;
1403 if (bits != xfer->bits_per_word - 8) { 1403 if (bits != xfer->bits_per_word - 8) {
1404 dev_dbg(&spi->dev, "you can't yet change " 1404 dev_dbg(&spi->dev,
1405 "bits_per_word in transfers\n"); 1405 "you can't yet change bits_per_word in transfers\n");
1406 return -ENOPROTOOPT; 1406 return -ENOPROTOOPT;
1407 } 1407 }
1408 } 1408 }
@@ -1516,7 +1516,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
1516 1516
1517 /* setup spi core then atmel-specific driver state */ 1517 /* setup spi core then atmel-specific driver state */
1518 ret = -ENOMEM; 1518 ret = -ENOMEM;
1519 master = spi_alloc_master(&pdev->dev, sizeof *as); 1519 master = spi_alloc_master(&pdev->dev, sizeof(*as));
1520 if (!master) 1520 if (!master)
1521 goto out_free; 1521 goto out_free;
1522 1522
@@ -1546,9 +1546,11 @@ static int atmel_spi_probe(struct platform_device *pdev)
1546 INIT_LIST_HEAD(&as->queue); 1546 INIT_LIST_HEAD(&as->queue);
1547 1547
1548 as->pdev = pdev; 1548 as->pdev = pdev;
1549 as->regs = ioremap(regs->start, resource_size(regs)); 1549 as->regs = devm_ioremap_resource(&pdev->dev, regs);
1550 if (!as->regs) 1550 if (IS_ERR(as->regs)) {
1551 ret = PTR_ERR(as->regs);
1551 goto out_free_buffer; 1552 goto out_free_buffer;
1553 }
1552 as->phybase = regs->start; 1554 as->phybase = regs->start;
1553 as->irq = irq; 1555 as->irq = irq;
1554 as->clk = clk; 1556 as->clk = clk;
@@ -1617,7 +1619,6 @@ out_free_dma:
1617out_free_irq: 1619out_free_irq:
1618 free_irq(irq, master); 1620 free_irq(irq, master);
1619out_unmap_regs: 1621out_unmap_regs:
1620 iounmap(as->regs);
1621out_free_buffer: 1622out_free_buffer:
1622 if (!as->use_pdc) 1623 if (!as->use_pdc)
1623 tasklet_kill(&as->tasklet); 1624 tasklet_kill(&as->tasklet);
@@ -1669,36 +1670,36 @@ static int atmel_spi_remove(struct platform_device *pdev)
1669 clk_disable_unprepare(as->clk); 1670 clk_disable_unprepare(as->clk);
1670 clk_put(as->clk); 1671 clk_put(as->clk);
1671 free_irq(as->irq, master); 1672 free_irq(as->irq, master);
1672 iounmap(as->regs);
1673 1673
1674 spi_unregister_master(master); 1674 spi_unregister_master(master);
1675 1675
1676 return 0; 1676 return 0;
1677} 1677}
1678 1678
1679#ifdef CONFIG_PM 1679#ifdef CONFIG_PM_SLEEP
1680 1680static int atmel_spi_suspend(struct device *dev)
1681static int atmel_spi_suspend(struct platform_device *pdev, pm_message_t mesg)
1682{ 1681{
1683 struct spi_master *master = platform_get_drvdata(pdev); 1682 struct spi_master *master = dev_get_drvdata(dev);
1684 struct atmel_spi *as = spi_master_get_devdata(master); 1683 struct atmel_spi *as = spi_master_get_devdata(master);
1685 1684
1686 clk_disable_unprepare(as->clk); 1685 clk_disable_unprepare(as->clk);
1687 return 0; 1686 return 0;
1688} 1687}
1689 1688
1690static int atmel_spi_resume(struct platform_device *pdev) 1689static int atmel_spi_resume(struct device *dev)
1691{ 1690{
1692 struct spi_master *master = platform_get_drvdata(pdev); 1691 struct spi_master *master = dev_get_drvdata(dev);
1693 struct atmel_spi *as = spi_master_get_devdata(master); 1692 struct atmel_spi *as = spi_master_get_devdata(master);
1694 1693
1695 return clk_prepare_enable(as->clk); 1694 clk_prepare_enable(as->clk);
1696 return 0; 1695 return 0;
1697} 1696}
1698 1697
1698static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume);
1699
1700#define ATMEL_SPI_PM_OPS (&atmel_spi_pm_ops)
1699#else 1701#else
1700#define atmel_spi_suspend NULL 1702#define ATMEL_SPI_PM_OPS NULL
1701#define atmel_spi_resume NULL
1702#endif 1703#endif
1703 1704
1704#if defined(CONFIG_OF) 1705#if defined(CONFIG_OF)
@@ -1714,10 +1715,9 @@ static struct platform_driver atmel_spi_driver = {
1714 .driver = { 1715 .driver = {
1715 .name = "atmel_spi", 1716 .name = "atmel_spi",
1716 .owner = THIS_MODULE, 1717 .owner = THIS_MODULE,
1718 .pm = ATMEL_SPI_PM_OPS,
1717 .of_match_table = of_match_ptr(atmel_spi_dt_ids), 1719 .of_match_table = of_match_ptr(atmel_spi_dt_ids),
1718 }, 1720 },
1719 .suspend = atmel_spi_suspend,
1720 .resume = atmel_spi_resume,
1721 .probe = atmel_spi_probe, 1721 .probe = atmel_spi_probe,
1722 .remove = atmel_spi_remove, 1722 .remove = atmel_spi_remove,
1723}; 1723};
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c
index 1d00d9b397dd..c4141c92bcff 100644
--- a/drivers/spi/spi-au1550.c
+++ b/drivers/spi/spi-au1550.c
@@ -775,7 +775,7 @@ static int au1550_spi_probe(struct platform_device *pdev)
775 775
776 hw = spi_master_get_devdata(master); 776 hw = spi_master_get_devdata(master);
777 777
778 hw->master = spi_master_get(master); 778 hw->master = master;
779 hw->pdata = dev_get_platdata(&pdev->dev); 779 hw->pdata = dev_get_platdata(&pdev->dev);
780 hw->dev = &pdev->dev; 780 hw->dev = &pdev->dev;
781 781
@@ -985,6 +985,7 @@ static int au1550_spi_remove(struct platform_device *pdev)
985MODULE_ALIAS("platform:au1550-spi"); 985MODULE_ALIAS("platform:au1550-spi");
986 986
987static struct platform_driver au1550_spi_drv = { 987static struct platform_driver au1550_spi_drv = {
988 .probe = au1550_spi_probe,
988 .remove = au1550_spi_remove, 989 .remove = au1550_spi_remove,
989 .driver = { 990 .driver = {
990 .name = "au1550-spi", 991 .name = "au1550-spi",
@@ -1004,7 +1005,7 @@ static int __init au1550_spi_init(void)
1004 printk(KERN_ERR "au1550-spi: cannot add memory" 1005 printk(KERN_ERR "au1550-spi: cannot add memory"
1005 "dbdma device\n"); 1006 "dbdma device\n");
1006 } 1007 }
1007 return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe); 1008 return platform_driver_register(&au1550_spi_drv);
1008} 1009}
1009module_init(au1550_spi_init); 1010module_init(au1550_spi_init);
1010 1011
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index 52c81481c5c7..4c332143a310 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -358,7 +358,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
358 bcm2835_wr(bs, BCM2835_SPI_CS, 358 bcm2835_wr(bs, BCM2835_SPI_CS,
359 BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); 359 BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);
360 360
361 err = spi_register_master(master); 361 err = devm_spi_register_master(&pdev->dev, master);
362 if (err) { 362 if (err) {
363 dev_err(&pdev->dev, "could not register SPI master: %d\n", err); 363 dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
364 goto out_free_irq; 364 goto out_free_irq;
@@ -381,14 +381,12 @@ static int bcm2835_spi_remove(struct platform_device *pdev)
381 struct bcm2835_spi *bs = spi_master_get_devdata(master); 381 struct bcm2835_spi *bs = spi_master_get_devdata(master);
382 382
383 free_irq(bs->irq, master); 383 free_irq(bs->irq, master);
384 spi_unregister_master(master);
385 384
386 /* Clear FIFOs, and disable the HW block */ 385 /* Clear FIFOs, and disable the HW block */
387 bcm2835_wr(bs, BCM2835_SPI_CS, 386 bcm2835_wr(bs, BCM2835_SPI_CS,
388 BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); 387 BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);
389 388
390 clk_disable_unprepare(bs->clk); 389 clk_disable_unprepare(bs->clk);
391 spi_master_put(master);
392 390
393 return 0; 391 return 0;
394} 392}
diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c
index 536b0e363826..80d56b214eb5 100644
--- a/drivers/spi/spi-bcm63xx.c
+++ b/drivers/spi/spi-bcm63xx.c
@@ -412,7 +412,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
412 bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); 412 bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS);
413 413
414 /* register and we are done */ 414 /* register and we are done */
415 ret = spi_register_master(master); 415 ret = devm_spi_register_master(dev, master);
416 if (ret) { 416 if (ret) {
417 dev_err(dev, "spi register failed\n"); 417 dev_err(dev, "spi register failed\n");
418 goto out_clk_disable; 418 goto out_clk_disable;
@@ -438,8 +438,6 @@ static int bcm63xx_spi_remove(struct platform_device *pdev)
438 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 438 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
439 struct bcm63xx_spi *bs = spi_master_get_devdata(master); 439 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
440 440
441 spi_unregister_master(master);
442
443 /* reset spi block */ 441 /* reset spi block */
444 bcm_spi_writeb(bs, 0, SPI_INT_MASK); 442 bcm_spi_writeb(bs, 0, SPI_INT_MASK);
445 443
@@ -447,8 +445,6 @@ static int bcm63xx_spi_remove(struct platform_device *pdev)
447 clk_disable_unprepare(bs->clk); 445 clk_disable_unprepare(bs->clk);
448 clk_put(bs->clk); 446 clk_put(bs->clk);
449 447
450 spi_master_put(master);
451
452 return 0; 448 return 0;
453} 449}
454 450
diff --git a/drivers/spi/spi-bfin-sport.c b/drivers/spi/spi-bfin-sport.c
index 91921b5f5817..38941e5920b5 100644
--- a/drivers/spi/spi-bfin-sport.c
+++ b/drivers/spi/spi-bfin-sport.c
@@ -592,7 +592,7 @@ bfin_sport_spi_setup(struct spi_device *spi)
592 */ 592 */
593 if (chip_info->ctl_reg || chip_info->enable_dma) { 593 if (chip_info->ctl_reg || chip_info->enable_dma) {
594 ret = -EINVAL; 594 ret = -EINVAL;
595 dev_err(&spi->dev, "don't set ctl_reg/enable_dma fields"); 595 dev_err(&spi->dev, "don't set ctl_reg/enable_dma fields\n");
596 goto error; 596 goto error;
597 } 597 }
598 chip->cs_chg_udelay = chip_info->cs_chg_udelay; 598 chip->cs_chg_udelay = chip_info->cs_chg_udelay;
@@ -879,11 +879,10 @@ static int bfin_sport_spi_remove(struct platform_device *pdev)
879 return 0; 879 return 0;
880} 880}
881 881
882#ifdef CONFIG_PM 882#ifdef CONFIG_PM_SLEEP
883static int 883static int bfin_sport_spi_suspend(struct device *dev)
884bfin_sport_spi_suspend(struct platform_device *pdev, pm_message_t state)
885{ 884{
886 struct bfin_sport_spi_master_data *drv_data = platform_get_drvdata(pdev); 885 struct bfin_sport_spi_master_data *drv_data = dev_get_drvdata(dev);
887 int status; 886 int status;
888 887
889 status = bfin_sport_spi_stop_queue(drv_data); 888 status = bfin_sport_spi_stop_queue(drv_data);
@@ -896,10 +895,9 @@ bfin_sport_spi_suspend(struct platform_device *pdev, pm_message_t state)
896 return status; 895 return status;
897} 896}
898 897
899static int 898static int bfin_sport_spi_resume(struct device *dev)
900bfin_sport_spi_resume(struct platform_device *pdev)
901{ 899{
902 struct bfin_sport_spi_master_data *drv_data = platform_get_drvdata(pdev); 900 struct bfin_sport_spi_master_data *drv_data = dev_get_drvdata(dev);
903 int status; 901 int status;
904 902
905 /* Enable the SPI interface */ 903 /* Enable the SPI interface */
@@ -912,19 +910,22 @@ bfin_sport_spi_resume(struct platform_device *pdev)
912 910
913 return status; 911 return status;
914} 912}
913
914static SIMPLE_DEV_PM_OPS(bfin_sport_spi_pm_ops, bfin_sport_spi_suspend,
915 bfin_sport_spi_resume);
916
917#define BFIN_SPORT_SPI_PM_OPS (&bfin_sport_spi_pm_ops)
915#else 918#else
916# define bfin_sport_spi_suspend NULL 919#define BFIN_SPORT_SPI_PM_OPS NULL
917# define bfin_sport_spi_resume NULL
918#endif 920#endif
919 921
920static struct platform_driver bfin_sport_spi_driver = { 922static struct platform_driver bfin_sport_spi_driver = {
921 .driver = { 923 .driver = {
922 .name = DRV_NAME, 924 .name = DRV_NAME,
923 .owner = THIS_MODULE, 925 .owner = THIS_MODULE,
926 .pm = BFIN_SPORT_SPI_PM_OPS,
924 }, 927 },
925 .probe = bfin_sport_spi_probe, 928 .probe = bfin_sport_spi_probe,
926 .remove = bfin_sport_spi_remove, 929 .remove = bfin_sport_spi_remove,
927 .suspend = bfin_sport_spi_suspend,
928 .resume = bfin_sport_spi_resume,
929}; 930};
930module_platform_driver(bfin_sport_spi_driver); 931module_platform_driver(bfin_sport_spi_driver);
diff --git a/drivers/spi/spi-bfin-v3.c b/drivers/spi/spi-bfin-v3.c
index f4bf81347d68..8f8598834b30 100644
--- a/drivers/spi/spi-bfin-v3.c
+++ b/drivers/spi/spi-bfin-v3.c
@@ -867,7 +867,7 @@ static int bfin_spi_probe(struct platform_device *pdev)
867 tasklet_init(&drv_data->pump_transfers, 867 tasklet_init(&drv_data->pump_transfers,
868 bfin_spi_pump_transfers, (unsigned long)drv_data); 868 bfin_spi_pump_transfers, (unsigned long)drv_data);
869 /* register with the SPI framework */ 869 /* register with the SPI framework */
870 ret = spi_register_master(master); 870 ret = devm_spi_register_master(dev, master);
871 if (ret) { 871 if (ret) {
872 dev_err(dev, "can not register spi master\n"); 872 dev_err(dev, "can not register spi master\n");
873 goto err_free_peripheral; 873 goto err_free_peripheral;
@@ -898,7 +898,6 @@ static int bfin_spi_remove(struct platform_device *pdev)
898 free_dma(drv_data->rx_dma); 898 free_dma(drv_data->rx_dma);
899 free_dma(drv_data->tx_dma); 899 free_dma(drv_data->tx_dma);
900 900
901 spi_unregister_master(drv_data->master);
902 return 0; 901 return 0;
903} 902}
904 903
diff --git a/drivers/spi/spi-bfin5xx.c b/drivers/spi/spi-bfin5xx.c
index 45bdf73d6868..f0f195af75d4 100644
--- a/drivers/spi/spi-bfin5xx.c
+++ b/drivers/spi/spi-bfin5xx.c
@@ -524,7 +524,7 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
524 timeout = jiffies + HZ; 524 timeout = jiffies + HZ;
525 while (!(bfin_read(&drv_data->regs->stat) & BIT_STAT_SPIF)) 525 while (!(bfin_read(&drv_data->regs->stat) & BIT_STAT_SPIF))
526 if (!time_before(jiffies, timeout)) { 526 if (!time_before(jiffies, timeout)) {
527 dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF"); 527 dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF\n");
528 break; 528 break;
529 } else 529 } else
530 cpu_relax(); 530 cpu_relax();
@@ -913,8 +913,9 @@ static void bfin_spi_pump_messages(struct work_struct *work)
913 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, 913 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
914 struct spi_transfer, transfer_list); 914 struct spi_transfer, transfer_list);
915 915
916 dev_dbg(&drv_data->pdev->dev, "got a message to pump, " 916 dev_dbg(&drv_data->pdev->dev,
917 "state is set to: baud %d, flag 0x%x, ctl 0x%x\n", 917 "got a message to pump, state is set to: baud "
918 "%d, flag 0x%x, ctl 0x%x\n",
918 drv_data->cur_chip->baud, drv_data->cur_chip->flag, 919 drv_data->cur_chip->baud, drv_data->cur_chip->flag,
919 drv_data->cur_chip->ctl_reg); 920 drv_data->cur_chip->ctl_reg);
920 921
@@ -1013,8 +1014,8 @@ static int bfin_spi_setup(struct spi_device *spi)
1013 * but let's assume (for now) they do. 1014 * but let's assume (for now) they do.
1014 */ 1015 */
1015 if (chip_info->ctl_reg & ~bfin_ctl_reg) { 1016 if (chip_info->ctl_reg & ~bfin_ctl_reg) {
1016 dev_err(&spi->dev, "do not set bits in ctl_reg " 1017 dev_err(&spi->dev,
1017 "that the SPI framework manages\n"); 1018 "do not set bits in ctl_reg that the SPI framework manages\n");
1018 goto error; 1019 goto error;
1019 } 1020 }
1020 chip->enable_dma = chip_info->enable_dma != 0 1021 chip->enable_dma = chip_info->enable_dma != 0
@@ -1050,17 +1051,17 @@ static int bfin_spi_setup(struct spi_device *spi)
1050 chip->chip_select_num = spi->chip_select; 1051 chip->chip_select_num = spi->chip_select;
1051 if (chip->chip_select_num < MAX_CTRL_CS) { 1052 if (chip->chip_select_num < MAX_CTRL_CS) {
1052 if (!(spi->mode & SPI_CPHA)) 1053 if (!(spi->mode & SPI_CPHA))
1053 dev_warn(&spi->dev, "Warning: SPI CPHA not set:" 1054 dev_warn(&spi->dev,
1054 " Slave Select not under software control!\n" 1055 "Warning: SPI CPHA not set: Slave Select not under software control!\n"
1055 " See Documentation/blackfin/bfin-spi-notes.txt"); 1056 "See Documentation/blackfin/bfin-spi-notes.txt\n");
1056 1057
1057 chip->flag = (1 << spi->chip_select) << 8; 1058 chip->flag = (1 << spi->chip_select) << 8;
1058 } else 1059 } else
1059 chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS; 1060 chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS;
1060 1061
1061 if (chip->enable_dma && chip->pio_interrupt) { 1062 if (chip->enable_dma && chip->pio_interrupt) {
1062 dev_err(&spi->dev, "enable_dma is set, " 1063 dev_err(&spi->dev,
1063 "do not set pio_interrupt\n"); 1064 "enable_dma is set, do not set pio_interrupt\n");
1064 goto error; 1065 goto error;
1065 } 1066 }
1066 /* 1067 /*
@@ -1410,10 +1411,10 @@ static int bfin_spi_remove(struct platform_device *pdev)
1410 return 0; 1411 return 0;
1411} 1412}
1412 1413
1413#ifdef CONFIG_PM 1414#ifdef CONFIG_PM_SLEEP
1414static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state) 1415static int bfin_spi_suspend(struct device *dev)
1415{ 1416{
1416 struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev); 1417 struct bfin_spi_master_data *drv_data = dev_get_drvdata(dev);
1417 int status = 0; 1418 int status = 0;
1418 1419
1419 status = bfin_spi_stop_queue(drv_data); 1420 status = bfin_spi_stop_queue(drv_data);
@@ -1432,9 +1433,9 @@ static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state)
1432 return 0; 1433 return 0;
1433} 1434}
1434 1435
1435static int bfin_spi_resume(struct platform_device *pdev) 1436static int bfin_spi_resume(struct device *dev)
1436{ 1437{
1437 struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev); 1438 struct bfin_spi_master_data *drv_data = dev_get_drvdata(dev);
1438 int status = 0; 1439 int status = 0;
1439 1440
1440 bfin_write(&drv_data->regs->ctl, drv_data->ctrl_reg); 1441 bfin_write(&drv_data->regs->ctl, drv_data->ctrl_reg);
@@ -1443,31 +1444,34 @@ static int bfin_spi_resume(struct platform_device *pdev)
1443 /* Start the queue running */ 1444 /* Start the queue running */
1444 status = bfin_spi_start_queue(drv_data); 1445 status = bfin_spi_start_queue(drv_data);
1445 if (status != 0) { 1446 if (status != 0) {
1446 dev_err(&pdev->dev, "problem starting queue (%d)\n", status); 1447 dev_err(dev, "problem starting queue (%d)\n", status);
1447 return status; 1448 return status;
1448 } 1449 }
1449 1450
1450 return 0; 1451 return 0;
1451} 1452}
1453
1454static SIMPLE_DEV_PM_OPS(bfin_spi_pm_ops, bfin_spi_suspend, bfin_spi_resume);
1455
1456#define BFIN_SPI_PM_OPS (&bfin_spi_pm_ops)
1452#else 1457#else
1453#define bfin_spi_suspend NULL 1458#define BFIN_SPI_PM_OPS NULL
1454#define bfin_spi_resume NULL 1459#endif
1455#endif /* CONFIG_PM */
1456 1460
1457MODULE_ALIAS("platform:bfin-spi"); 1461MODULE_ALIAS("platform:bfin-spi");
1458static struct platform_driver bfin_spi_driver = { 1462static struct platform_driver bfin_spi_driver = {
1459 .driver = { 1463 .driver = {
1460 .name = DRV_NAME, 1464 .name = DRV_NAME,
1461 .owner = THIS_MODULE, 1465 .owner = THIS_MODULE,
1466 .pm = BFIN_SPI_PM_OPS,
1462 }, 1467 },
1463 .suspend = bfin_spi_suspend, 1468 .probe = bfin_spi_probe,
1464 .resume = bfin_spi_resume,
1465 .remove = bfin_spi_remove, 1469 .remove = bfin_spi_remove,
1466}; 1470};
1467 1471
1468static int __init bfin_spi_init(void) 1472static int __init bfin_spi_init(void)
1469{ 1473{
1470 return platform_driver_probe(&bfin_spi_driver, bfin_spi_probe); 1474 return platform_driver_register(&bfin_spi_driver);
1471} 1475}
1472subsys_initcall(bfin_spi_init); 1476subsys_initcall(bfin_spi_init);
1473 1477
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index 8c11355dec23..bd222f6b677d 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -191,7 +191,7 @@ int spi_bitbang_setup(struct spi_device *spi)
191 bitbang = spi_master_get_devdata(spi->master); 191 bitbang = spi_master_get_devdata(spi->master);
192 192
193 if (!cs) { 193 if (!cs) {
194 cs = kzalloc(sizeof *cs, GFP_KERNEL); 194 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
195 if (!cs) 195 if (!cs)
196 return -ENOMEM; 196 return -ENOMEM;
197 spi->controller_state = cs; 197 spi->controller_state = cs;
@@ -258,7 +258,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
258 258
259static int spi_bitbang_prepare_hardware(struct spi_master *spi) 259static int spi_bitbang_prepare_hardware(struct spi_master *spi)
260{ 260{
261 struct spi_bitbang *bitbang; 261 struct spi_bitbang *bitbang;
262 unsigned long flags; 262 unsigned long flags;
263 263
264 bitbang = spi_master_get_devdata(spi); 264 bitbang = spi_master_get_devdata(spi);
@@ -273,7 +273,7 @@ static int spi_bitbang_prepare_hardware(struct spi_master *spi)
273static int spi_bitbang_transfer_one(struct spi_master *master, 273static int spi_bitbang_transfer_one(struct spi_master *master,
274 struct spi_message *m) 274 struct spi_message *m)
275{ 275{
276 struct spi_bitbang *bitbang; 276 struct spi_bitbang *bitbang;
277 unsigned nsecs; 277 unsigned nsecs;
278 struct spi_transfer *t = NULL; 278 struct spi_transfer *t = NULL;
279 unsigned cs_change; 279 unsigned cs_change;
@@ -292,7 +292,7 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
292 cs_change = 1; 292 cs_change = 1;
293 status = 0; 293 status = 0;
294 294
295 list_for_each_entry (t, &m->transfers, transfer_list) { 295 list_for_each_entry(t, &m->transfers, transfer_list) {
296 296
297 /* override speed or wordsize? */ 297 /* override speed or wordsize? */
298 if (t->speed_hz || t->bits_per_word) 298 if (t->speed_hz || t->bits_per_word)
@@ -349,7 +349,8 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
349 if (t->delay_usecs) 349 if (t->delay_usecs)
350 udelay(t->delay_usecs); 350 udelay(t->delay_usecs);
351 351
352 if (cs_change && !list_is_last(&t->transfer_list, &m->transfers)) { 352 if (cs_change &&
353 !list_is_last(&t->transfer_list, &m->transfers)) {
353 /* sometimes a short mid-message deselect of the chip 354 /* sometimes a short mid-message deselect of the chip
354 * may be needed to terminate a mode or command 355 * may be needed to terminate a mode or command
355 */ 356 */
@@ -378,7 +379,7 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
378 379
379static int spi_bitbang_unprepare_hardware(struct spi_master *spi) 380static int spi_bitbang_unprepare_hardware(struct spi_master *spi)
380{ 381{
381 struct spi_bitbang *bitbang; 382 struct spi_bitbang *bitbang;
382 unsigned long flags; 383 unsigned long flags;
383 384
384 bitbang = spi_master_get_devdata(spi); 385 bitbang = spi_master_get_devdata(spi);
@@ -414,10 +415,16 @@ static int spi_bitbang_unprepare_hardware(struct spi_master *spi)
414 * This routine registers the spi_master, which will process requests in a 415 * This routine registers the spi_master, which will process requests in a
415 * dedicated task, keeping IRQs unblocked most of the time. To stop 416 * dedicated task, keeping IRQs unblocked most of the time. To stop
416 * processing those requests, call spi_bitbang_stop(). 417 * processing those requests, call spi_bitbang_stop().
418 *
419 * On success, this routine will take a reference to master. The caller is
420 * responsible for calling spi_bitbang_stop() to decrement the reference and
421 * spi_master_put() as counterpart of spi_alloc_master() to prevent a memory
422 * leak.
417 */ 423 */
418int spi_bitbang_start(struct spi_bitbang *bitbang) 424int spi_bitbang_start(struct spi_bitbang *bitbang)
419{ 425{
420 struct spi_master *master = bitbang->master; 426 struct spi_master *master = bitbang->master;
427 int ret;
421 428
422 if (!master || !bitbang->chipselect) 429 if (!master || !bitbang->chipselect)
423 return -EINVAL; 430 return -EINVAL;
@@ -449,7 +456,11 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)
449 /* driver may get busy before register() returns, especially 456 /* driver may get busy before register() returns, especially
450 * if someone registered boardinfo for devices 457 * if someone registered boardinfo for devices
451 */ 458 */
452 return spi_register_master(master); 459 ret = spi_register_master(spi_master_get(master));
460 if (ret)
461 spi_master_put(master);
462
463 return 0;
453} 464}
454EXPORT_SYMBOL_GPL(spi_bitbang_start); 465EXPORT_SYMBOL_GPL(spi_bitbang_start);
455 466
diff --git a/drivers/spi/spi-butterfly.c b/drivers/spi/spi-butterfly.c
index 5ed08e537433..8081f96bd1d5 100644
--- a/drivers/spi/spi-butterfly.c
+++ b/drivers/spi/spi-butterfly.c
@@ -147,8 +147,8 @@ static void butterfly_chipselect(struct spi_device *spi, int value)
147 147
148/* we only needed to implement one mode here, and choose SPI_MODE_0 */ 148/* we only needed to implement one mode here, and choose SPI_MODE_0 */
149 149
150#define spidelay(X) do{}while(0) 150#define spidelay(X) do { } while (0)
151//#define spidelay ndelay 151/* #define spidelay ndelay */
152 152
153#include "spi-bitbang-txrx.h" 153#include "spi-bitbang-txrx.h"
154 154
@@ -171,15 +171,15 @@ static struct mtd_partition partitions[] = { {
171 /* sector 0 = 8 pages * 264 bytes/page (1 block) 171 /* sector 0 = 8 pages * 264 bytes/page (1 block)
172 * sector 1 = 248 pages * 264 bytes/page 172 * sector 1 = 248 pages * 264 bytes/page
173 */ 173 */
174 .name = "bookkeeping", // 66 KB 174 .name = "bookkeeping", /* 66 KB */
175 .offset = 0, 175 .offset = 0,
176 .size = (8 + 248) * 264, 176 .size = (8 + 248) * 264,
177// .mask_flags = MTD_WRITEABLE, 177 /* .mask_flags = MTD_WRITEABLE, */
178}, { 178}, {
179 /* sector 2 = 256 pages * 264 bytes/page 179 /* sector 2 = 256 pages * 264 bytes/page
180 * sectors 3-5 = 512 pages * 264 bytes/page 180 * sectors 3-5 = 512 pages * 264 bytes/page
181 */ 181 */
182 .name = "filesystem", // 462 KB 182 .name = "filesystem", /* 462 KB */
183 .offset = MTDPART_OFS_APPEND, 183 .offset = MTDPART_OFS_APPEND,
184 .size = MTDPART_SIZ_FULL, 184 .size = MTDPART_SIZ_FULL,
185} }; 185} };
@@ -209,7 +209,7 @@ static void butterfly_attach(struct parport *p)
209 * and no way to be selective about what it binds to. 209 * and no way to be selective about what it binds to.
210 */ 210 */
211 211
212 master = spi_alloc_master(dev, sizeof *pp); 212 master = spi_alloc_master(dev, sizeof(*pp));
213 if (!master) { 213 if (!master) {
214 status = -ENOMEM; 214 status = -ENOMEM;
215 goto done; 215 goto done;
@@ -225,7 +225,7 @@ static void butterfly_attach(struct parport *p)
225 master->bus_num = 42; 225 master->bus_num = 42;
226 master->num_chipselect = 2; 226 master->num_chipselect = 2;
227 227
228 pp->bitbang.master = spi_master_get(master); 228 pp->bitbang.master = master;
229 pp->bitbang.chipselect = butterfly_chipselect; 229 pp->bitbang.chipselect = butterfly_chipselect;
230 pp->bitbang.txrx_word[SPI_MODE_0] = butterfly_txrx_word_mode0; 230 pp->bitbang.txrx_word[SPI_MODE_0] = butterfly_txrx_word_mode0;
231 231
@@ -289,7 +289,6 @@ static void butterfly_attach(struct parport *p)
289 pr_debug("%s: dataflash at %s\n", p->name, 289 pr_debug("%s: dataflash at %s\n", p->name,
290 dev_name(&pp->dataflash->dev)); 290 dev_name(&pp->dataflash->dev));
291 291
292 // dev_info(_what?_, ...)
293 pr_info("%s: AVR Butterfly\n", p->name); 292 pr_info("%s: AVR Butterfly\n", p->name);
294 butterfly = pp; 293 butterfly = pp;
295 return; 294 return;
diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c
index 6416798828e7..e2a5a426b2ef 100644
--- a/drivers/spi/spi-clps711x.c
+++ b/drivers/spi/spi-clps711x.c
@@ -226,10 +226,10 @@ static int spi_clps711x_probe(struct platform_device *pdev)
226 dev_name(&pdev->dev), hw); 226 dev_name(&pdev->dev), hw);
227 if (ret) { 227 if (ret) {
228 dev_err(&pdev->dev, "Can't request IRQ\n"); 228 dev_err(&pdev->dev, "Can't request IRQ\n");
229 goto clk_out; 229 goto err_out;
230 } 230 }
231 231
232 ret = spi_register_master(master); 232 ret = devm_spi_register_master(&pdev->dev, master);
233 if (!ret) { 233 if (!ret) {
234 dev_info(&pdev->dev, 234 dev_info(&pdev->dev,
235 "SPI bus driver initialized. Master clock %u Hz\n", 235 "SPI bus driver initialized. Master clock %u Hz\n",
@@ -239,7 +239,6 @@ static int spi_clps711x_probe(struct platform_device *pdev)
239 239
240 dev_err(&pdev->dev, "Failed to register master\n"); 240 dev_err(&pdev->dev, "Failed to register master\n");
241 241
242clk_out:
243err_out: 242err_out:
244 while (--i >= 0) 243 while (--i >= 0)
245 if (gpio_is_valid(hw->chipselect[i])) 244 if (gpio_is_valid(hw->chipselect[i]))
@@ -260,8 +259,6 @@ static int spi_clps711x_remove(struct platform_device *pdev)
260 if (gpio_is_valid(hw->chipselect[i])) 259 if (gpio_is_valid(hw->chipselect[i]))
261 gpio_free(hw->chipselect[i]); 260 gpio_free(hw->chipselect[i]);
262 261
263 spi_unregister_master(master);
264
265 return 0; 262 return 0;
266} 263}
267 264
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 8fbfe2483ffd..dd72445ba2ea 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -279,7 +279,8 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
279 struct davinci_spi *dspi; 279 struct davinci_spi *dspi;
280 struct davinci_spi_config *spicfg; 280 struct davinci_spi_config *spicfg;
281 u8 bits_per_word = 0; 281 u8 bits_per_word = 0;
282 u32 hz = 0, spifmt = 0, prescale = 0; 282 u32 hz = 0, spifmt = 0;
283 int prescale;
283 284
284 dspi = spi_master_get_devdata(spi->master); 285 dspi = spi_master_get_devdata(spi->master);
285 spicfg = (struct davinci_spi_config *)spi->controller_data; 286 spicfg = (struct davinci_spi_config *)spi->controller_data;
@@ -916,7 +917,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
916 if (ret) 917 if (ret)
917 goto unmap_io; 918 goto unmap_io;
918 919
919 dspi->bitbang.master = spi_master_get(master); 920 dspi->bitbang.master = master;
920 if (dspi->bitbang.master == NULL) { 921 if (dspi->bitbang.master == NULL) {
921 ret = -ENODEV; 922 ret = -ENODEV;
922 goto irq_free; 923 goto irq_free;
@@ -925,7 +926,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
925 dspi->clk = clk_get(&pdev->dev, NULL); 926 dspi->clk = clk_get(&pdev->dev, NULL);
926 if (IS_ERR(dspi->clk)) { 927 if (IS_ERR(dspi->clk)) {
927 ret = -ENODEV; 928 ret = -ENODEV;
928 goto put_master; 929 goto irq_free;
929 } 930 }
930 clk_prepare_enable(dspi->clk); 931 clk_prepare_enable(dspi->clk);
931 932
@@ -1015,8 +1016,6 @@ free_dma:
1015free_clk: 1016free_clk:
1016 clk_disable_unprepare(dspi->clk); 1017 clk_disable_unprepare(dspi->clk);
1017 clk_put(dspi->clk); 1018 clk_put(dspi->clk);
1018put_master:
1019 spi_master_put(master);
1020irq_free: 1019irq_free:
1021 free_irq(dspi->irq, dspi); 1020 free_irq(dspi->irq, dspi);
1022unmap_io: 1021unmap_io:
@@ -1024,7 +1023,7 @@ unmap_io:
1024release_region: 1023release_region:
1025 release_mem_region(dspi->pbase, resource_size(r)); 1024 release_mem_region(dspi->pbase, resource_size(r));
1026free_master: 1025free_master:
1027 kfree(master); 1026 spi_master_put(master);
1028err: 1027err:
1029 return ret; 1028 return ret;
1030} 1029}
@@ -1051,11 +1050,11 @@ static int davinci_spi_remove(struct platform_device *pdev)
1051 1050
1052 clk_disable_unprepare(dspi->clk); 1051 clk_disable_unprepare(dspi->clk);
1053 clk_put(dspi->clk); 1052 clk_put(dspi->clk);
1054 spi_master_put(master);
1055 free_irq(dspi->irq, dspi); 1053 free_irq(dspi->irq, dspi);
1056 iounmap(dspi->base); 1054 iounmap(dspi->base);
1057 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1055 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1058 release_mem_region(dspi->pbase, resource_size(r)); 1056 release_mem_region(dspi->pbase, resource_size(r));
1057 spi_master_put(master);
1059 1058
1060 return 0; 1059 return 0;
1061} 1060}
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index 4aa8be865cc0..168c620947f4 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -74,7 +74,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
74 dwsmmio->clk = clk_get(&pdev->dev, NULL); 74 dwsmmio->clk = clk_get(&pdev->dev, NULL);
75 if (IS_ERR(dwsmmio->clk)) { 75 if (IS_ERR(dwsmmio->clk)) {
76 ret = PTR_ERR(dwsmmio->clk); 76 ret = PTR_ERR(dwsmmio->clk);
77 goto err_irq; 77 goto err_unmap;
78 } 78 }
79 clk_enable(dwsmmio->clk); 79 clk_enable(dwsmmio->clk);
80 80
@@ -94,8 +94,6 @@ err_clk:
94 clk_disable(dwsmmio->clk); 94 clk_disable(dwsmmio->clk);
95 clk_put(dwsmmio->clk); 95 clk_put(dwsmmio->clk);
96 dwsmmio->clk = NULL; 96 dwsmmio->clk = NULL;
97err_irq:
98 free_irq(dws->irq, dws);
99err_unmap: 97err_unmap:
100 iounmap(dws->regs); 98 iounmap(dws->regs);
101err_release_reg: 99err_release_reg:
@@ -115,7 +113,6 @@ static int dw_spi_mmio_remove(struct platform_device *pdev)
115 clk_put(dwsmmio->clk); 113 clk_put(dwsmmio->clk);
116 dwsmmio->clk = NULL; 114 dwsmmio->clk = NULL;
117 115
118 free_irq(dwsmmio->dws.irq, &dwsmmio->dws);
119 dw_spi_remove_host(&dwsmmio->dws); 116 dw_spi_remove_host(&dwsmmio->dws);
120 iounmap(dwsmmio->dws.regs); 117 iounmap(dwsmmio->dws.regs);
121 kfree(dwsmmio); 118 kfree(dwsmmio);
diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
index 6055c8d9fdd7..66fa9955ea14 100644
--- a/drivers/spi/spi-dw-pci.c
+++ b/drivers/spi/spi-dw-pci.c
@@ -40,7 +40,7 @@ static int spi_pci_probe(struct pci_dev *pdev,
40 int pci_bar = 0; 40 int pci_bar = 0;
41 int ret; 41 int ret;
42 42
43 printk(KERN_INFO "DW: found PCI SPI controller(ID: %04x:%04x)\n", 43 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
44 pdev->vendor, pdev->device); 44 pdev->vendor, pdev->device);
45 45
46 ret = pci_enable_device(pdev); 46 ret = pci_enable_device(pdev);
@@ -109,7 +109,6 @@ static void spi_pci_remove(struct pci_dev *pdev)
109{ 109{
110 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev); 110 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
111 111
112 pci_set_drvdata(pdev, NULL);
113 dw_spi_remove_host(&dwpci->dws); 112 dw_spi_remove_host(&dwpci->dws);
114 iounmap(dwpci->dws.regs); 113 iounmap(dwpci->dws.regs);
115 pci_release_region(pdev, 0); 114 pci_release_region(pdev, 0);
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 79c958e49f61..b897c4adb39d 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -870,8 +870,8 @@ void dw_spi_remove_host(struct dw_spi *dws)
870 /* Remove the queue */ 870 /* Remove the queue */
871 status = destroy_queue(dws); 871 status = destroy_queue(dws);
872 if (status != 0) 872 if (status != 0)
873 dev_err(&dws->master->dev, "dw_spi_remove: workqueue will not " 873 dev_err(&dws->master->dev,
874 "complete, message memory not freed\n"); 874 "dw_spi_remove: workqueue will not complete, message memory not freed\n");
875 875
876 if (dws->dma_ops && dws->dma_ops->dma_exit) 876 if (dws->dma_ops && dws->dma_ops->dma_exit)
877 dws->dma_ops->dma_exit(dws); 877 dws->dma_ops->dma_exit(dws);
diff --git a/drivers/spi/spi-efm32.c b/drivers/spi/spi-efm32.c
index 7d84418a01d8..d4d3cc534792 100644
--- a/drivers/spi/spi-efm32.c
+++ b/drivers/spi/spi-efm32.c
@@ -280,10 +280,6 @@ static irqreturn_t efm32_spi_txirq(int irq, void *data)
280 return IRQ_HANDLED; 280 return IRQ_HANDLED;
281} 281}
282 282
283static const struct efm32_spi_pdata efm32_spi_pdata_default = {
284 .location = 1,
285};
286
287static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) 283static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata)
288{ 284{
289 u32 reg = efm32_spi_read32(ddata, REG_ROUTE); 285 u32 reg = efm32_spi_read32(ddata, REG_ROUTE);
@@ -347,7 +343,7 @@ static int efm32_spi_probe(struct platform_device *pdev)
347 343
348 ddata = spi_master_get_devdata(master); 344 ddata = spi_master_get_devdata(master);
349 345
350 ddata->bitbang.master = spi_master_get(master); 346 ddata->bitbang.master = master;
351 ddata->bitbang.chipselect = efm32_spi_chipselect; 347 ddata->bitbang.chipselect = efm32_spi_chipselect;
352 ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; 348 ddata->bitbang.setup_transfer = efm32_spi_setup_transfer;
353 ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; 349 ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs;
@@ -387,7 +383,7 @@ static int efm32_spi_probe(struct platform_device *pdev)
387 goto err; 383 goto err;
388 } 384 }
389 385
390 if (resource_size(res) < 60) { 386 if (resource_size(res) < 0x60) {
391 ret = -EINVAL; 387 ret = -EINVAL;
392 dev_err(&pdev->dev, "memory resource too small\n"); 388 dev_err(&pdev->dev, "memory resource too small\n");
393 goto err; 389 goto err;
@@ -467,7 +463,6 @@ err_disable_clk:
467 clk_disable_unprepare(ddata->clk); 463 clk_disable_unprepare(ddata->clk);
468err: 464err:
469 spi_master_put(master); 465 spi_master_put(master);
470 kfree(master);
471 } 466 }
472 467
473 return ret; 468 return ret;
@@ -478,13 +473,14 @@ static int efm32_spi_remove(struct platform_device *pdev)
478 struct spi_master *master = platform_get_drvdata(pdev); 473 struct spi_master *master = platform_get_drvdata(pdev);
479 struct efm32_spi_ddata *ddata = spi_master_get_devdata(master); 474 struct efm32_spi_ddata *ddata = spi_master_get_devdata(master);
480 475
476 spi_bitbang_stop(&ddata->bitbang);
477
481 efm32_spi_write32(ddata, 0, REG_IEN); 478 efm32_spi_write32(ddata, 0, REG_IEN);
482 479
483 free_irq(ddata->txirq, ddata); 480 free_irq(ddata->txirq, ddata);
484 free_irq(ddata->rxirq, ddata); 481 free_irq(ddata->rxirq, ddata);
485 clk_disable_unprepare(ddata->clk); 482 clk_disable_unprepare(ddata->clk);
486 spi_master_put(master); 483 spi_master_put(master);
487 kfree(master);
488 484
489 return 0; 485 return 0;
490} 486}
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c
index d22c00a227b6..1bfaed6e4073 100644
--- a/drivers/spi/spi-ep93xx.c
+++ b/drivers/spi/spi-ep93xx.c
@@ -330,7 +330,7 @@ static int ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
330 330
331 dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n", 331 dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n",
332 chip->spi->mode, div_cpsr, div_scr, dss); 332 chip->spi->mode, div_cpsr, div_scr, dss);
333 dev_dbg(&espi->pdev->dev, "setup: cr0 %#x", cr0); 333 dev_dbg(&espi->pdev->dev, "setup: cr0 %#x\n", cr0);
334 334
335 ep93xx_spi_write_u8(espi, SSPCPSR, div_cpsr); 335 ep93xx_spi_write_u8(espi, SSPCPSR, div_cpsr);
336 ep93xx_spi_write_u16(espi, SSPCR0, cr0); 336 ep93xx_spi_write_u16(espi, SSPCR0, cr0);
@@ -509,7 +509,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
509 } 509 }
510 510
511 if (WARN_ON(len)) { 511 if (WARN_ON(len)) {
512 dev_warn(&espi->pdev->dev, "len = %zu expected 0!", len); 512 dev_warn(&espi->pdev->dev, "len = %zu expected 0!\n", len);
513 return ERR_PTR(-EINVAL); 513 return ERR_PTR(-EINVAL);
514 } 514 }
515 515
@@ -942,7 +942,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
942 /* make sure that the hardware is disabled */ 942 /* make sure that the hardware is disabled */
943 ep93xx_spi_write_u8(espi, SSPCR1, 0); 943 ep93xx_spi_write_u8(espi, SSPCR1, 0);
944 944
945 error = spi_register_master(master); 945 error = devm_spi_register_master(&pdev->dev, master);
946 if (error) { 946 if (error) {
947 dev_err(&pdev->dev, "failed to register SPI master\n"); 947 dev_err(&pdev->dev, "failed to register SPI master\n");
948 goto fail_free_dma; 948 goto fail_free_dma;
@@ -968,7 +968,6 @@ static int ep93xx_spi_remove(struct platform_device *pdev)
968 968
969 ep93xx_spi_release_dma(espi); 969 ep93xx_spi_release_dma(espi);
970 970
971 spi_unregister_master(master);
972 return 0; 971 return 0;
973} 972}
974 973
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c
index 07971e3fe58b..58630edb8c21 100644
--- a/drivers/spi/spi-fsl-cpm.c
+++ b/drivers/spi/spi-fsl-cpm.c
@@ -299,7 +299,7 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
299 299
300 switch (mspi->subblock) { 300 switch (mspi->subblock) {
301 default: 301 default:
302 dev_warn(dev, "cell-index unspecified, assuming SPI1"); 302 dev_warn(dev, "cell-index unspecified, assuming SPI1\n");
303 /* fall through */ 303 /* fall through */
304 case 0: 304 case 0:
305 mspi->subblock = QE_CR_SUBBLOCK_SPI1; 305 mspi->subblock = QE_CR_SUBBLOCK_SPI1;
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 4e44575bd87a..8641b03bdd7a 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -108,7 +108,7 @@ struct fsl_dspi {
108 struct spi_bitbang bitbang; 108 struct spi_bitbang bitbang;
109 struct platform_device *pdev; 109 struct platform_device *pdev;
110 110
111 void *base; 111 void __iomem *base;
112 int irq; 112 int irq;
113 struct clk *clk; 113 struct clk *clk;
114 114
@@ -165,7 +165,7 @@ static void hz_to_spi_baud(char *pbr, char *br, int speed_hz,
165 } 165 }
166 } 166 }
167 167
168 pr_warn("Can not find valid buad rate,speed_hz is %d,clkrate is %ld\ 168 pr_warn("Can not find valid baud rate,speed_hz is %d,clkrate is %ld\
169 ,we use the max prescaler value.\n", speed_hz, clkrate); 169 ,we use the max prescaler value.\n", speed_hz, clkrate);
170 *pbr = ARRAY_SIZE(pbr_tbl) - 1; 170 *pbr = ARRAY_SIZE(pbr_tbl) - 1;
171 *br = ARRAY_SIZE(brs) - 1; 171 *br = ARRAY_SIZE(brs) - 1;
@@ -450,7 +450,7 @@ static int dspi_probe(struct platform_device *pdev)
450 450
451 dspi = spi_master_get_devdata(master); 451 dspi = spi_master_get_devdata(master);
452 dspi->pdev = pdev; 452 dspi->pdev = pdev;
453 dspi->bitbang.master = spi_master_get(master); 453 dspi->bitbang.master = master;
454 dspi->bitbang.chipselect = dspi_chipselect; 454 dspi->bitbang.chipselect = dspi_chipselect;
455 dspi->bitbang.setup_transfer = dspi_setup_transfer; 455 dspi->bitbang.setup_transfer = dspi_setup_transfer;
456 dspi->bitbang.txrx_bufs = dspi_txrx_transfer; 456 dspi->bitbang.txrx_bufs = dspi_txrx_transfer;
@@ -520,7 +520,6 @@ out_clk_put:
520 clk_disable_unprepare(dspi->clk); 520 clk_disable_unprepare(dspi->clk);
521out_master_put: 521out_master_put:
522 spi_master_put(master); 522 spi_master_put(master);
523 platform_set_drvdata(pdev, NULL);
524 523
525 return ret; 524 return ret;
526} 525}
@@ -531,6 +530,7 @@ static int dspi_remove(struct platform_device *pdev)
531 530
532 /* Disconnect from the SPI framework */ 531 /* Disconnect from the SPI framework */
533 spi_bitbang_stop(&dspi->bitbang); 532 spi_bitbang_stop(&dspi->bitbang);
533 clk_disable_unprepare(dspi->clk);
534 spi_master_put(dspi->bitbang.master); 534 spi_master_put(dspi->bitbang.master);
535 535
536 return 0; 536 return 0;
@@ -547,5 +547,5 @@ static struct platform_driver fsl_dspi_driver = {
547module_platform_driver(fsl_dspi_driver); 547module_platform_driver(fsl_dspi_driver);
548 548
549MODULE_DESCRIPTION("Freescale DSPI Controller Driver"); 549MODULE_DESCRIPTION("Freescale DSPI Controller Driver");
550MODULE_LICENSE("GPL v2"); 550MODULE_LICENSE("GPL");
551MODULE_ALIAS("platform:" DRIVER_NAME); 551MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index b8f1103fe28e..43222d7532d1 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -289,8 +289,8 @@ static void fsl_espi_do_trans(struct spi_message *m,
289 if ((first->bits_per_word != t->bits_per_word) || 289 if ((first->bits_per_word != t->bits_per_word) ||
290 (first->speed_hz != t->speed_hz)) { 290 (first->speed_hz != t->speed_hz)) {
291 espi_trans->status = -EINVAL; 291 espi_trans->status = -EINVAL;
292 dev_err(mspi->dev, "bits_per_word/speed_hz should be" 292 dev_err(mspi->dev,
293 " same for the same SPI transfer\n"); 293 "bits_per_word/speed_hz should be same for the same SPI transfer\n");
294 return; 294 return;
295 } 295 }
296 296
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 68b69fec13a9..3fb09f981980 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/of.h>
25#include <linux/of_device.h> 26#include <linux/of_device.h>
26#include <linux/of_gpio.h> 27#include <linux/of_gpio.h>
27 28
@@ -467,7 +468,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
467 } 468 }
468#endif 469#endif
469 470
470 spi_gpio->bitbang.master = spi_master_get(master); 471 spi_gpio->bitbang.master = master;
471 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 472 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
472 473
473 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { 474 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) {
@@ -486,7 +487,6 @@ static int spi_gpio_probe(struct platform_device *pdev)
486 487
487 status = spi_bitbang_start(&spi_gpio->bitbang); 488 status = spi_bitbang_start(&spi_gpio->bitbang);
488 if (status < 0) { 489 if (status < 0) {
489 spi_master_put(spi_gpio->bitbang.master);
490gpio_free: 490gpio_free:
491 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) 491 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
492 gpio_free(SPI_MISO_GPIO); 492 gpio_free(SPI_MISO_GPIO);
@@ -510,13 +510,13 @@ static int spi_gpio_remove(struct platform_device *pdev)
510 510
511 /* stop() unregisters child devices too */ 511 /* stop() unregisters child devices too */
512 status = spi_bitbang_stop(&spi_gpio->bitbang); 512 status = spi_bitbang_stop(&spi_gpio->bitbang);
513 spi_master_put(spi_gpio->bitbang.master);
514 513
515 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) 514 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
516 gpio_free(SPI_MISO_GPIO); 515 gpio_free(SPI_MISO_GPIO);
517 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) 516 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
518 gpio_free(SPI_MOSI_GPIO); 517 gpio_free(SPI_MOSI_GPIO);
519 gpio_free(SPI_SCK_GPIO); 518 gpio_free(SPI_SCK_GPIO);
519 spi_master_put(spi_gpio->bitbang.master);
520 520
521 return status; 521 return status;
522} 522}
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 15323d8bd9cf..b80f2f70fef7 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -749,6 +749,35 @@ static void spi_imx_cleanup(struct spi_device *spi)
749{ 749{
750} 750}
751 751
752static int
753spi_imx_prepare_message(struct spi_master *master, struct spi_message *msg)
754{
755 struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
756 int ret;
757
758 ret = clk_enable(spi_imx->clk_per);
759 if (ret)
760 return ret;
761
762 ret = clk_enable(spi_imx->clk_ipg);
763 if (ret) {
764 clk_disable(spi_imx->clk_per);
765 return ret;
766 }
767
768 return 0;
769}
770
771static int
772spi_imx_unprepare_message(struct spi_master *master, struct spi_message *msg)
773{
774 struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
775
776 clk_disable(spi_imx->clk_ipg);
777 clk_disable(spi_imx->clk_per);
778 return 0;
779}
780
752static int spi_imx_probe(struct platform_device *pdev) 781static int spi_imx_probe(struct platform_device *pdev)
753{ 782{
754 struct device_node *np = pdev->dev.of_node; 783 struct device_node *np = pdev->dev.of_node;
@@ -786,7 +815,7 @@ static int spi_imx_probe(struct platform_device *pdev)
786 master->num_chipselect = num_cs; 815 master->num_chipselect = num_cs;
787 816
788 spi_imx = spi_master_get_devdata(master); 817 spi_imx = spi_master_get_devdata(master);
789 spi_imx->bitbang.master = spi_master_get(master); 818 spi_imx->bitbang.master = master;
790 819
791 for (i = 0; i < master->num_chipselect; i++) { 820 for (i = 0; i < master->num_chipselect; i++) {
792 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 821 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
@@ -810,6 +839,8 @@ static int spi_imx_probe(struct platform_device *pdev)
810 spi_imx->bitbang.txrx_bufs = spi_imx_transfer; 839 spi_imx->bitbang.txrx_bufs = spi_imx_transfer;
811 spi_imx->bitbang.master->setup = spi_imx_setup; 840 spi_imx->bitbang.master->setup = spi_imx_setup;
812 spi_imx->bitbang.master->cleanup = spi_imx_cleanup; 841 spi_imx->bitbang.master->cleanup = spi_imx_cleanup;
842 spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message;
843 spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message;
813 spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 844 spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
814 845
815 init_completion(&spi_imx->xfer_done); 846 init_completion(&spi_imx->xfer_done);
@@ -872,6 +903,8 @@ static int spi_imx_probe(struct platform_device *pdev)
872 903
873 dev_info(&pdev->dev, "probed\n"); 904 dev_info(&pdev->dev, "probed\n");
874 905
906 clk_disable(spi_imx->clk_ipg);
907 clk_disable(spi_imx->clk_per);
875 return ret; 908 return ret;
876 909
877out_clk_put: 910out_clk_put:
diff --git a/drivers/spi/spi-lm70llp.c b/drivers/spi/spi-lm70llp.c
index 0759b5db9883..41c5765be746 100644
--- a/drivers/spi/spi-lm70llp.c
+++ b/drivers/spi/spi-lm70llp.c
@@ -222,7 +222,7 @@ static void spi_lm70llp_attach(struct parport *p)
222 /* 222 /*
223 * SPI and bitbang hookup. 223 * SPI and bitbang hookup.
224 */ 224 */
225 pp->bitbang.master = spi_master_get(master); 225 pp->bitbang.master = master;
226 pp->bitbang.chipselect = lm70_chipselect; 226 pp->bitbang.chipselect = lm70_chipselect;
227 pp->bitbang.txrx_word[SPI_MODE_0] = lm70_txrx; 227 pp->bitbang.txrx_word[SPI_MODE_0] = lm70_txrx;
228 pp->bitbang.flags = SPI_3WIRE; 228 pp->bitbang.flags = SPI_3WIRE;
diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c
index 6adf4e35816d..ee6e61cbf7f5 100644
--- a/drivers/spi/spi-mpc512x-psc.c
+++ b/drivers/spi/spi-mpc512x-psc.c
@@ -536,7 +536,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
536 if (ret < 0) 536 if (ret < 0)
537 goto free_clock; 537 goto free_clock;
538 538
539 ret = spi_register_master(master); 539 ret = devm_spi_register_master(dev, master);
540 if (ret < 0) 540 if (ret < 0)
541 goto free_clock; 541 goto free_clock;
542 542
@@ -559,12 +559,10 @@ static int mpc512x_psc_spi_do_remove(struct device *dev)
559 struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 559 struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
560 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 560 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
561 561
562 spi_unregister_master(master);
563 clk_disable_unprepare(mps->clk_mclk); 562 clk_disable_unprepare(mps->clk_mclk);
564 free_irq(mps->irq, mps); 563 free_irq(mps->irq, mps);
565 if (mps->psc) 564 if (mps->psc)
566 iounmap(mps->psc); 565 iounmap(mps->psc);
567 spi_master_put(master);
568 566
569 return 0; 567 return 0;
570} 568}
diff --git a/drivers/spi/spi-mpc52xx-psc.c b/drivers/spi/spi-mpc52xx-psc.c
index 6e925dc34396..00ba910ab302 100644
--- a/drivers/spi/spi-mpc52xx-psc.c
+++ b/drivers/spi/spi-mpc52xx-psc.c
@@ -383,8 +383,8 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
383 383
384 mps->irq = irq; 384 mps->irq = irq;
385 if (pdata == NULL) { 385 if (pdata == NULL) {
386 dev_warn(dev, "probe called without platform data, no " 386 dev_warn(dev,
387 "cs_control function will be called\n"); 387 "probe called without platform data, no cs_control function will be called\n");
388 mps->cs_control = NULL; 388 mps->cs_control = NULL;
389 mps->sysclk = 0; 389 mps->sysclk = 0;
390 master->bus_num = bus_num; 390 master->bus_num = bus_num;
diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
index de7b1141b90f..de333059a9a7 100644
--- a/drivers/spi/spi-mxs.c
+++ b/drivers/spi/spi-mxs.c
@@ -57,34 +57,53 @@
57 57
58#define SG_MAXLEN 0xff00 58#define SG_MAXLEN 0xff00
59 59
60/*
61 * Flags for txrx functions. More efficient that using an argument register for
62 * each one.
63 */
64#define TXRX_WRITE (1<<0) /* This is a write */
65#define TXRX_DEASSERT_CS (1<<1) /* De-assert CS at end of txrx */
66
60struct mxs_spi { 67struct mxs_spi {
61 struct mxs_ssp ssp; 68 struct mxs_ssp ssp;
62 struct completion c; 69 struct completion c;
70 unsigned int sck; /* Rate requested (vs actual) */
63}; 71};
64 72
65static int mxs_spi_setup_transfer(struct spi_device *dev, 73static int mxs_spi_setup_transfer(struct spi_device *dev,
66 struct spi_transfer *t) 74 const struct spi_transfer *t)
67{ 75{
68 struct mxs_spi *spi = spi_master_get_devdata(dev->master); 76 struct mxs_spi *spi = spi_master_get_devdata(dev->master);
69 struct mxs_ssp *ssp = &spi->ssp; 77 struct mxs_ssp *ssp = &spi->ssp;
70 uint32_t hz = 0; 78 const unsigned int hz = min(dev->max_speed_hz, t->speed_hz);
71 79
72 hz = dev->max_speed_hz;
73 if (t && t->speed_hz)
74 hz = min(hz, t->speed_hz);
75 if (hz == 0) { 80 if (hz == 0) {
76 dev_err(&dev->dev, "Cannot continue with zero clock\n"); 81 dev_err(&dev->dev, "SPI clock rate of zero not allowed\n");
77 return -EINVAL; 82 return -EINVAL;
78 } 83 }
79 84
80 mxs_ssp_set_clk_rate(ssp, hz); 85 if (hz != spi->sck) {
86 mxs_ssp_set_clk_rate(ssp, hz);
87 /*
88 * Save requested rate, hz, rather than the actual rate,
89 * ssp->clk_rate. Otherwise we would set the rate every trasfer
90 * when the actual rate is not quite the same as requested rate.
91 */
92 spi->sck = hz;
93 /*
94 * Perhaps we should return an error if the actual clock is
95 * nowhere close to what was requested?
96 */
97 }
98
99 writel(BM_SSP_CTRL0_LOCK_CS,
100 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
81 101
82 writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) | 102 writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) |
83 BF_SSP_CTRL1_WORD_LENGTH 103 BF_SSP_CTRL1_WORD_LENGTH(BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) |
84 (BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) | 104 ((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) |
85 ((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) | 105 ((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0),
86 ((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0), 106 ssp->base + HW_SSP_CTRL1(ssp));
87 ssp->base + HW_SSP_CTRL1(ssp));
88 107
89 writel(0x0, ssp->base + HW_SSP_CMD0); 108 writel(0x0, ssp->base + HW_SSP_CMD0);
90 writel(0x0, ssp->base + HW_SSP_CMD1); 109 writel(0x0, ssp->base + HW_SSP_CMD1);
@@ -94,26 +113,15 @@ static int mxs_spi_setup_transfer(struct spi_device *dev,
94 113
95static int mxs_spi_setup(struct spi_device *dev) 114static int mxs_spi_setup(struct spi_device *dev)
96{ 115{
97 int err = 0;
98
99 if (!dev->bits_per_word) 116 if (!dev->bits_per_word)
100 dev->bits_per_word = 8; 117 dev->bits_per_word = 8;
101 118
102 if (dev->mode & ~(SPI_CPOL | SPI_CPHA)) 119 return 0;
103 return -EINVAL;
104
105 err = mxs_spi_setup_transfer(dev, NULL);
106 if (err) {
107 dev_err(&dev->dev,
108 "Failed to setup transfer, error = %d\n", err);
109 }
110
111 return err;
112} 120}
113 121
114static uint32_t mxs_spi_cs_to_reg(unsigned cs) 122static u32 mxs_spi_cs_to_reg(unsigned cs)
115{ 123{
116 uint32_t select = 0; 124 u32 select = 0;
117 125
118 /* 126 /*
119 * i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0 127 * i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0
@@ -131,43 +139,11 @@ static uint32_t mxs_spi_cs_to_reg(unsigned cs)
131 return select; 139 return select;
132} 140}
133 141
134static void mxs_spi_set_cs(struct mxs_spi *spi, unsigned cs)
135{
136 const uint32_t mask =
137 BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ;
138 uint32_t select;
139 struct mxs_ssp *ssp = &spi->ssp;
140
141 writel(mask, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
142 select = mxs_spi_cs_to_reg(cs);
143 writel(select, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
144}
145
146static inline void mxs_spi_enable(struct mxs_spi *spi)
147{
148 struct mxs_ssp *ssp = &spi->ssp;
149
150 writel(BM_SSP_CTRL0_LOCK_CS,
151 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
152 writel(BM_SSP_CTRL0_IGNORE_CRC,
153 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
154}
155
156static inline void mxs_spi_disable(struct mxs_spi *spi)
157{
158 struct mxs_ssp *ssp = &spi->ssp;
159
160 writel(BM_SSP_CTRL0_LOCK_CS,
161 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
162 writel(BM_SSP_CTRL0_IGNORE_CRC,
163 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
164}
165
166static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set) 142static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set)
167{ 143{
168 const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT); 144 const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT);
169 struct mxs_ssp *ssp = &spi->ssp; 145 struct mxs_ssp *ssp = &spi->ssp;
170 uint32_t reg; 146 u32 reg;
171 147
172 do { 148 do {
173 reg = readl_relaxed(ssp->base + offset); 149 reg = readl_relaxed(ssp->base + offset);
@@ -200,9 +176,9 @@ static irqreturn_t mxs_ssp_irq_handler(int irq, void *dev_id)
200 return IRQ_HANDLED; 176 return IRQ_HANDLED;
201} 177}
202 178
203static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, 179static int mxs_spi_txrx_dma(struct mxs_spi *spi,
204 unsigned char *buf, int len, 180 unsigned char *buf, int len,
205 int *first, int *last, int write) 181 unsigned int flags)
206{ 182{
207 struct mxs_ssp *ssp = &spi->ssp; 183 struct mxs_ssp *ssp = &spi->ssp;
208 struct dma_async_tx_descriptor *desc = NULL; 184 struct dma_async_tx_descriptor *desc = NULL;
@@ -211,11 +187,11 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs,
211 const int sgs = DIV_ROUND_UP(len, desc_len); 187 const int sgs = DIV_ROUND_UP(len, desc_len);
212 int sg_count; 188 int sg_count;
213 int min, ret; 189 int min, ret;
214 uint32_t ctrl0; 190 u32 ctrl0;
215 struct page *vm_page; 191 struct page *vm_page;
216 void *sg_buf; 192 void *sg_buf;
217 struct { 193 struct {
218 uint32_t pio[4]; 194 u32 pio[4];
219 struct scatterlist sg; 195 struct scatterlist sg;
220 } *dma_xfer; 196 } *dma_xfer;
221 197
@@ -228,21 +204,25 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs,
228 204
229 INIT_COMPLETION(spi->c); 205 INIT_COMPLETION(spi->c);
230 206
207 /* Chip select was already programmed into CTRL0 */
231 ctrl0 = readl(ssp->base + HW_SSP_CTRL0); 208 ctrl0 = readl(ssp->base + HW_SSP_CTRL0);
232 ctrl0 &= ~BM_SSP_CTRL0_XFER_COUNT; 209 ctrl0 &= ~(BM_SSP_CTRL0_XFER_COUNT | BM_SSP_CTRL0_IGNORE_CRC |
233 ctrl0 |= BM_SSP_CTRL0_DATA_XFER | mxs_spi_cs_to_reg(cs); 210 BM_SSP_CTRL0_READ);
211 ctrl0 |= BM_SSP_CTRL0_DATA_XFER;
234 212
235 if (*first) 213 if (!(flags & TXRX_WRITE))
236 ctrl0 |= BM_SSP_CTRL0_LOCK_CS;
237 if (!write)
238 ctrl0 |= BM_SSP_CTRL0_READ; 214 ctrl0 |= BM_SSP_CTRL0_READ;
239 215
240 /* Queue the DMA data transfer. */ 216 /* Queue the DMA data transfer. */
241 for (sg_count = 0; sg_count < sgs; sg_count++) { 217 for (sg_count = 0; sg_count < sgs; sg_count++) {
218 /* Prepare the transfer descriptor. */
242 min = min(len, desc_len); 219 min = min(len, desc_len);
243 220
244 /* Prepare the transfer descriptor. */ 221 /*
245 if ((sg_count + 1 == sgs) && *last) 222 * De-assert CS on last segment if flag is set (i.e., no more
223 * transfers will follow)
224 */
225 if ((sg_count + 1 == sgs) && (flags & TXRX_DEASSERT_CS))
246 ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC; 226 ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC;
247 227
248 if (ssp->devid == IMX23_SSP) { 228 if (ssp->devid == IMX23_SSP) {
@@ -267,7 +247,7 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs,
267 247
268 sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min); 248 sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min);
269 ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, 249 ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
270 write ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 250 (flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
271 251
272 len -= min; 252 len -= min;
273 buf += min; 253 buf += min;
@@ -287,7 +267,7 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs,
287 267
288 desc = dmaengine_prep_slave_sg(ssp->dmach, 268 desc = dmaengine_prep_slave_sg(ssp->dmach,
289 &dma_xfer[sg_count].sg, 1, 269 &dma_xfer[sg_count].sg, 1,
290 write ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 270 (flags & TXRX_WRITE) ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
291 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 271 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
292 272
293 if (!desc) { 273 if (!desc) {
@@ -324,7 +304,7 @@ err_vmalloc:
324 while (--sg_count >= 0) { 304 while (--sg_count >= 0) {
325err_mapped: 305err_mapped:
326 dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, 306 dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
327 write ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 307 (flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
328 } 308 }
329 309
330 kfree(dma_xfer); 310 kfree(dma_xfer);
@@ -332,20 +312,19 @@ err_mapped:
332 return ret; 312 return ret;
333} 313}
334 314
335static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs, 315static int mxs_spi_txrx_pio(struct mxs_spi *spi,
336 unsigned char *buf, int len, 316 unsigned char *buf, int len,
337 int *first, int *last, int write) 317 unsigned int flags)
338{ 318{
339 struct mxs_ssp *ssp = &spi->ssp; 319 struct mxs_ssp *ssp = &spi->ssp;
340 320
341 if (*first) 321 writel(BM_SSP_CTRL0_IGNORE_CRC,
342 mxs_spi_enable(spi); 322 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
343
344 mxs_spi_set_cs(spi, cs);
345 323
346 while (len--) { 324 while (len--) {
347 if (*last && len == 0) 325 if (len == 0 && (flags & TXRX_DEASSERT_CS))
348 mxs_spi_disable(spi); 326 writel(BM_SSP_CTRL0_IGNORE_CRC,
327 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
349 328
350 if (ssp->devid == IMX23_SSP) { 329 if (ssp->devid == IMX23_SSP) {
351 writel(BM_SSP_CTRL0_XFER_COUNT, 330 writel(BM_SSP_CTRL0_XFER_COUNT,
@@ -356,7 +335,7 @@ static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs,
356 writel(1, ssp->base + HW_SSP_XFER_SIZE); 335 writel(1, ssp->base + HW_SSP_XFER_SIZE);
357 } 336 }
358 337
359 if (write) 338 if (flags & TXRX_WRITE)
360 writel(BM_SSP_CTRL0_READ, 339 writel(BM_SSP_CTRL0_READ,
361 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); 340 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
362 else 341 else
@@ -369,13 +348,13 @@ static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs,
369 if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1)) 348 if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1))
370 return -ETIMEDOUT; 349 return -ETIMEDOUT;
371 350
372 if (write) 351 if (flags & TXRX_WRITE)
373 writel(*buf, ssp->base + HW_SSP_DATA(ssp)); 352 writel(*buf, ssp->base + HW_SSP_DATA(ssp));
374 353
375 writel(BM_SSP_CTRL0_DATA_XFER, 354 writel(BM_SSP_CTRL0_DATA_XFER,
376 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); 355 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
377 356
378 if (!write) { 357 if (!(flags & TXRX_WRITE)) {
379 if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp), 358 if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp),
380 BM_SSP_STATUS_FIFO_EMPTY, 0)) 359 BM_SSP_STATUS_FIFO_EMPTY, 0))
381 return -ETIMEDOUT; 360 return -ETIMEDOUT;
@@ -400,14 +379,15 @@ static int mxs_spi_transfer_one(struct spi_master *master,
400{ 379{
401 struct mxs_spi *spi = spi_master_get_devdata(master); 380 struct mxs_spi *spi = spi_master_get_devdata(master);
402 struct mxs_ssp *ssp = &spi->ssp; 381 struct mxs_ssp *ssp = &spi->ssp;
403 int first, last;
404 struct spi_transfer *t, *tmp_t; 382 struct spi_transfer *t, *tmp_t;
383 unsigned int flag;
405 int status = 0; 384 int status = 0;
406 int cs;
407
408 first = last = 0;
409 385
410 cs = m->spi->chip_select; 386 /* Program CS register bits here, it will be used for all transfers. */
387 writel(BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ,
388 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
389 writel(mxs_spi_cs_to_reg(m->spi->chip_select),
390 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
411 391
412 list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) { 392 list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) {
413 393
@@ -415,16 +395,9 @@ static int mxs_spi_transfer_one(struct spi_master *master,
415 if (status) 395 if (status)
416 break; 396 break;
417 397
418 if (&t->transfer_list == m->transfers.next) 398 /* De-assert on last transfer, inverted by cs_change flag */
419 first = 1; 399 flag = (&t->transfer_list == m->transfers.prev) ^ t->cs_change ?
420 if (&t->transfer_list == m->transfers.prev) 400 TXRX_DEASSERT_CS : 0;
421 last = 1;
422 if ((t->rx_buf && t->tx_buf) || (t->rx_dma && t->tx_dma)) {
423 dev_err(ssp->dev,
424 "Cannot send and receive simultaneously\n");
425 status = -EINVAL;
426 break;
427 }
428 401
429 /* 402 /*
430 * Small blocks can be transfered via PIO. 403 * Small blocks can be transfered via PIO.
@@ -441,26 +414,26 @@ static int mxs_spi_transfer_one(struct spi_master *master,
441 STMP_OFFSET_REG_CLR); 414 STMP_OFFSET_REG_CLR);
442 415
443 if (t->tx_buf) 416 if (t->tx_buf)
444 status = mxs_spi_txrx_pio(spi, cs, 417 status = mxs_spi_txrx_pio(spi,
445 (void *)t->tx_buf, 418 (void *)t->tx_buf,
446 t->len, &first, &last, 1); 419 t->len, flag | TXRX_WRITE);
447 if (t->rx_buf) 420 if (t->rx_buf)
448 status = mxs_spi_txrx_pio(spi, cs, 421 status = mxs_spi_txrx_pio(spi,
449 t->rx_buf, t->len, 422 t->rx_buf, t->len,
450 &first, &last, 0); 423 flag);
451 } else { 424 } else {
452 writel(BM_SSP_CTRL1_DMA_ENABLE, 425 writel(BM_SSP_CTRL1_DMA_ENABLE,
453 ssp->base + HW_SSP_CTRL1(ssp) + 426 ssp->base + HW_SSP_CTRL1(ssp) +
454 STMP_OFFSET_REG_SET); 427 STMP_OFFSET_REG_SET);
455 428
456 if (t->tx_buf) 429 if (t->tx_buf)
457 status = mxs_spi_txrx_dma(spi, cs, 430 status = mxs_spi_txrx_dma(spi,
458 (void *)t->tx_buf, t->len, 431 (void *)t->tx_buf, t->len,
459 &first, &last, 1); 432 flag | TXRX_WRITE);
460 if (t->rx_buf) 433 if (t->rx_buf)
461 status = mxs_spi_txrx_dma(spi, cs, 434 status = mxs_spi_txrx_dma(spi,
462 t->rx_buf, t->len, 435 t->rx_buf, t->len,
463 &first, &last, 0); 436 flag);
464 } 437 }
465 438
466 if (status) { 439 if (status) {
@@ -469,7 +442,6 @@ static int mxs_spi_transfer_one(struct spi_master *master,
469 } 442 }
470 443
471 m->actual_length += t->len; 444 m->actual_length += t->len;
472 first = last = 0;
473 } 445 }
474 446
475 m->status = status; 447 m->status = status;
@@ -563,7 +535,6 @@ static int mxs_spi_probe(struct platform_device *pdev)
563 goto out_dma_release; 535 goto out_dma_release;
564 536
565 clk_set_rate(ssp->clk, clk_freq); 537 clk_set_rate(ssp->clk, clk_freq);
566 ssp->clk_rate = clk_get_rate(ssp->clk) / 1000;
567 538
568 ret = stmp_reset_block(ssp->base); 539 ret = stmp_reset_block(ssp->base);
569 if (ret) 540 if (ret)
@@ -571,7 +542,7 @@ static int mxs_spi_probe(struct platform_device *pdev)
571 542
572 platform_set_drvdata(pdev, master); 543 platform_set_drvdata(pdev, master);
573 544
574 ret = spi_register_master(master); 545 ret = devm_spi_register_master(&pdev->dev, master);
575 if (ret) { 546 if (ret) {
576 dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret); 547 dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret);
577 goto out_disable_clk; 548 goto out_disable_clk;
@@ -598,10 +569,8 @@ static int mxs_spi_remove(struct platform_device *pdev)
598 spi = spi_master_get_devdata(master); 569 spi = spi_master_get_devdata(master);
599 ssp = &spi->ssp; 570 ssp = &spi->ssp;
600 571
601 spi_unregister_master(master);
602 clk_disable_unprepare(ssp->clk); 572 clk_disable_unprepare(ssp->clk);
603 dma_release_channel(ssp->dmach); 573 dma_release_channel(ssp->dmach);
604 spi_master_put(master);
605 574
606 return 0; 575 return 0;
607} 576}
diff --git a/drivers/spi/spi-nuc900.c b/drivers/spi/spi-nuc900.c
index 47a68b43bcd5..e0c32bc69ee2 100644
--- a/drivers/spi/spi-nuc900.c
+++ b/drivers/spi/spi-nuc900.c
@@ -349,7 +349,7 @@ static int nuc900_spi_probe(struct platform_device *pdev)
349 } 349 }
350 350
351 hw = spi_master_get_devdata(master); 351 hw = spi_master_get_devdata(master);
352 hw->master = spi_master_get(master); 352 hw->master = master;
353 hw->pdata = dev_get_platdata(&pdev->dev); 353 hw->pdata = dev_get_platdata(&pdev->dev);
354 hw->dev = &pdev->dev; 354 hw->dev = &pdev->dev;
355 355
@@ -435,7 +435,6 @@ err_iomap:
435 kfree(hw->ioarea); 435 kfree(hw->ioarea);
436err_pdata: 436err_pdata:
437 spi_master_put(hw->master); 437 spi_master_put(hw->master);
438
439err_nomem: 438err_nomem:
440 return err; 439 return err;
441} 440}
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 333cb1badcd7..91c668596202 100644
--- a/drivers/spi/spi-oc-tiny.c
+++ b/drivers/spi/spi-oc-tiny.c
@@ -306,7 +306,7 @@ static int tiny_spi_probe(struct platform_device *pdev)
306 platform_set_drvdata(pdev, hw); 306 platform_set_drvdata(pdev, hw);
307 307
308 /* setup the state for the bitbang driver */ 308 /* setup the state for the bitbang driver */
309 hw->bitbang.master = spi_master_get(master); 309 hw->bitbang.master = master;
310 if (!hw->bitbang.master) 310 if (!hw->bitbang.master)
311 return err; 311 return err;
312 hw->bitbang.setup_transfer = tiny_spi_setup_transfer; 312 hw->bitbang.setup_transfer = tiny_spi_setup_transfer;
diff --git a/drivers/spi/spi-octeon.c b/drivers/spi/spi-octeon.c
index 5f28ddbe4f7e..67249a48b391 100644
--- a/drivers/spi/spi-octeon.c
+++ b/drivers/spi/spi-octeon.c
@@ -272,7 +272,7 @@ static int octeon_spi_probe(struct platform_device *pdev)
272 master->bits_per_word_mask = SPI_BPW_MASK(8); 272 master->bits_per_word_mask = SPI_BPW_MASK(8);
273 273
274 master->dev.of_node = pdev->dev.of_node; 274 master->dev.of_node = pdev->dev.of_node;
275 err = spi_register_master(master); 275 err = devm_spi_register_master(&pdev->dev, master);
276 if (err) { 276 if (err) {
277 dev_err(&pdev->dev, "register master failed: %d\n", err); 277 dev_err(&pdev->dev, "register master failed: %d\n", err);
278 goto fail; 278 goto fail;
@@ -292,8 +292,6 @@ static int octeon_spi_remove(struct platform_device *pdev)
292 struct octeon_spi *p = spi_master_get_devdata(master); 292 struct octeon_spi *p = spi_master_get_devdata(master);
293 u64 register_base = p->register_base; 293 u64 register_base = p->register_base;
294 294
295 spi_unregister_master(master);
296
297 /* Clear the CSENA* and put everything in a known state. */ 295 /* Clear the CSENA* and put everything in a known state. */
298 cvmx_write_csr(register_base + OCTEON_SPI_CFG, 0); 296 cvmx_write_csr(register_base + OCTEON_SPI_CFG, 0);
299 297
diff --git a/drivers/spi/spi-omap-100k.c b/drivers/spi/spi-omap-100k.c
index 69ecf05757dd..b6ed82beb01d 100644
--- a/drivers/spi/spi-omap-100k.c
+++ b/drivers/spi/spi-omap-100k.c
@@ -457,7 +457,7 @@ static int omap1_spi100k_probe(struct platform_device *pdev)
457 goto err; 457 goto err;
458 } 458 }
459 459
460 status = spi_register_master(master); 460 status = devm_spi_register_master(&pdev->dev, master);
461 if (status < 0) 461 if (status < 0)
462 goto err; 462 goto err;
463 463
@@ -485,8 +485,6 @@ static int omap1_spi100k_remove(struct platform_device *pdev)
485 485
486 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 486 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
487 487
488 spi_unregister_master(master);
489
490 return 0; 488 return 0;
491} 489}
492 490
diff --git a/drivers/spi/spi-omap-uwire.c b/drivers/spi/spi-omap-uwire.c
index a6a8f0961750..9313fd3b413d 100644
--- a/drivers/spi/spi-omap-uwire.c
+++ b/drivers/spi/spi-omap-uwire.c
@@ -557,7 +557,8 @@ static struct platform_driver uwire_driver = {
557 .name = "omap_uwire", 557 .name = "omap_uwire",
558 .owner = THIS_MODULE, 558 .owner = THIS_MODULE,
559 }, 559 },
560 .remove = uwire_remove, 560 .probe = uwire_probe,
561 .remove = uwire_remove,
561 // suspend ... unuse ck 562 // suspend ... unuse ck
562 // resume ... use ck 563 // resume ... use ck
563}; 564};
@@ -579,7 +580,7 @@ static int __init omap_uwire_init(void)
579 omap_writel(val | 0x00AAA000, OMAP7XX_IO_CONF_9); 580 omap_writel(val | 0x00AAA000, OMAP7XX_IO_CONF_9);
580 } 581 }
581 582
582 return platform_driver_probe(&uwire_driver, uwire_probe); 583 return platform_driver_register(&uwire_driver);
583} 584}
584 585
585static void __exit omap_uwire_exit(void) 586static void __exit omap_uwire_exit(void)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index ed4af4708d9a..443df39840bc 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -276,7 +276,7 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
276 struct omap2_mcspi_cs *cs = spi->controller_state; 276 struct omap2_mcspi_cs *cs = spi->controller_state;
277 struct omap2_mcspi *mcspi; 277 struct omap2_mcspi *mcspi;
278 unsigned int wcnt; 278 unsigned int wcnt;
279 int fifo_depth, bytes_per_word; 279 int max_fifo_depth, fifo_depth, bytes_per_word;
280 u32 chconf, xferlevel; 280 u32 chconf, xferlevel;
281 281
282 mcspi = spi_master_get_devdata(master); 282 mcspi = spi_master_get_devdata(master);
@@ -287,7 +287,12 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
287 if (t->len % bytes_per_word != 0) 287 if (t->len % bytes_per_word != 0)
288 goto disable_fifo; 288 goto disable_fifo;
289 289
290 fifo_depth = gcd(t->len, OMAP2_MCSPI_MAX_FIFODEPTH); 290 if (t->rx_buf != NULL && t->tx_buf != NULL)
291 max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH / 2;
292 else
293 max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH;
294
295 fifo_depth = gcd(t->len, max_fifo_depth);
291 if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0) 296 if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0)
292 goto disable_fifo; 297 goto disable_fifo;
293 298
@@ -299,7 +304,8 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
299 if (t->rx_buf != NULL) { 304 if (t->rx_buf != NULL) {
300 chconf |= OMAP2_MCSPI_CHCONF_FFER; 305 chconf |= OMAP2_MCSPI_CHCONF_FFER;
301 xferlevel |= (fifo_depth - 1) << 8; 306 xferlevel |= (fifo_depth - 1) << 8;
302 } else { 307 }
308 if (t->tx_buf != NULL) {
303 chconf |= OMAP2_MCSPI_CHCONF_FFET; 309 chconf |= OMAP2_MCSPI_CHCONF_FFET;
304 xferlevel |= fifo_depth - 1; 310 xferlevel |= fifo_depth - 1;
305 } 311 }
@@ -498,7 +504,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
498 ((u32 *)xfer->rx_buf)[elements++] = w; 504 ((u32 *)xfer->rx_buf)[elements++] = w;
499 } else { 505 } else {
500 int bytes_per_word = mcspi_bytes_per_word(word_len); 506 int bytes_per_word = mcspi_bytes_per_word(word_len);
501 dev_err(&spi->dev, "DMA RX penultimate word empty"); 507 dev_err(&spi->dev, "DMA RX penultimate word empty\n");
502 count -= (bytes_per_word << 1); 508 count -= (bytes_per_word << 1);
503 omap2_mcspi_set_enable(spi, 1); 509 omap2_mcspi_set_enable(spi, 1);
504 return count; 510 return count;
@@ -516,7 +522,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
516 else /* word_len <= 32 */ 522 else /* word_len <= 32 */
517 ((u32 *)xfer->rx_buf)[elements] = w; 523 ((u32 *)xfer->rx_buf)[elements] = w;
518 } else { 524 } else {
519 dev_err(&spi->dev, "DMA RX last word empty"); 525 dev_err(&spi->dev, "DMA RX last word empty\n");
520 count -= mcspi_bytes_per_word(word_len); 526 count -= mcspi_bytes_per_word(word_len);
521 } 527 }
522 omap2_mcspi_set_enable(spi, 1); 528 omap2_mcspi_set_enable(spi, 1);
@@ -1407,7 +1413,7 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
1407 if (status < 0) 1413 if (status < 0)
1408 goto disable_pm; 1414 goto disable_pm;
1409 1415
1410 status = spi_register_master(master); 1416 status = devm_spi_register_master(&pdev->dev, master);
1411 if (status < 0) 1417 if (status < 0)
1412 goto disable_pm; 1418 goto disable_pm;
1413 1419
@@ -1435,7 +1441,6 @@ static int omap2_mcspi_remove(struct platform_device *pdev)
1435 pm_runtime_put_sync(mcspi->dev); 1441 pm_runtime_put_sync(mcspi->dev);
1436 pm_runtime_disable(&pdev->dev); 1442 pm_runtime_disable(&pdev->dev);
1437 1443
1438 spi_unregister_master(master);
1439 kfree(dma_channels); 1444 kfree(dma_channels);
1440 1445
1441 return 0; 1446 return 0;
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 1d1d321d90c4..744841e095e4 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -84,8 +84,8 @@ static int orion_spi_set_transfer_size(struct orion_spi *orion_spi, int size)
84 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, 84 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
85 ORION_SPI_IF_8_16_BIT_MODE); 85 ORION_SPI_IF_8_16_BIT_MODE);
86 } else { 86 } else {
87 pr_debug("Bad bits per word value %d (only 8 or 16 are " 87 pr_debug("Bad bits per word value %d (only 8 or 16 are allowed).\n",
88 "allowed).\n", size); 88 size);
89 return -EINVAL; 89 return -EINVAL;
90 } 90 }
91 91
@@ -407,7 +407,7 @@ static int orion_spi_probe(struct platform_device *pdev)
407 const u32 *iprop; 407 const u32 *iprop;
408 int size; 408 int size;
409 409
410 master = spi_alloc_master(&pdev->dev, sizeof *spi); 410 master = spi_alloc_master(&pdev->dev, sizeof(*spi));
411 if (master == NULL) { 411 if (master == NULL) {
412 dev_dbg(&pdev->dev, "master allocation failed\n"); 412 dev_dbg(&pdev->dev, "master allocation failed\n");
413 return -ENOMEM; 413 return -ENOMEM;
@@ -457,7 +457,7 @@ static int orion_spi_probe(struct platform_device *pdev)
457 goto out_rel_clk; 457 goto out_rel_clk;
458 458
459 master->dev.of_node = pdev->dev.of_node; 459 master->dev.of_node = pdev->dev.of_node;
460 status = spi_register_master(master); 460 status = devm_spi_register_master(&pdev->dev, master);
461 if (status < 0) 461 if (status < 0)
462 goto out_rel_clk; 462 goto out_rel_clk;
463 463
@@ -483,8 +483,6 @@ static int orion_spi_remove(struct platform_device *pdev)
483 clk_disable_unprepare(spi->clk); 483 clk_disable_unprepare(spi->clk);
484 clk_put(spi->clk); 484 clk_put(spi->clk);
485 485
486 spi_unregister_master(master);
487
488 return 0; 486 return 0;
489} 487}
490 488
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 9c511a954d21..2789b452e711 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1619,7 +1619,6 @@ static int verify_controller_parameters(struct pl022 *pl022,
1619 dev_err(&pl022->adev->dev, 1619 dev_err(&pl022->adev->dev,
1620 "RX FIFO Trigger Level is configured incorrectly\n"); 1620 "RX FIFO Trigger Level is configured incorrectly\n");
1621 return -EINVAL; 1621 return -EINVAL;
1622 break;
1623 } 1622 }
1624 switch (chip_info->tx_lev_trig) { 1623 switch (chip_info->tx_lev_trig) {
1625 case SSP_TX_1_OR_MORE_EMPTY_LOC: 1624 case SSP_TX_1_OR_MORE_EMPTY_LOC:
@@ -1645,7 +1644,6 @@ static int verify_controller_parameters(struct pl022 *pl022,
1645 dev_err(&pl022->adev->dev, 1644 dev_err(&pl022->adev->dev,
1646 "TX FIFO Trigger Level is configured incorrectly\n"); 1645 "TX FIFO Trigger Level is configured incorrectly\n");
1647 return -EINVAL; 1646 return -EINVAL;
1648 break;
1649 } 1647 }
1650 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { 1648 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) {
1651 if ((chip_info->ctrl_len < SSP_BITS_4) 1649 if ((chip_info->ctrl_len < SSP_BITS_4)
@@ -2175,8 +2173,8 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
2175 status = -ENOMEM; 2173 status = -ENOMEM;
2176 goto err_no_ioremap; 2174 goto err_no_ioremap;
2177 } 2175 }
2178 printk(KERN_INFO "pl022: mapped registers from %pa to %p\n", 2176 dev_info(&adev->dev, "mapped registers from %pa to %p\n",
2179 &adev->res.start, pl022->virtbase); 2177 &adev->res.start, pl022->virtbase);
2180 2178
2181 pl022->clk = devm_clk_get(&adev->dev, NULL); 2179 pl022->clk = devm_clk_get(&adev->dev, NULL);
2182 if (IS_ERR(pl022->clk)) { 2180 if (IS_ERR(pl022->clk)) {
@@ -2227,7 +2225,7 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
2227 2225
2228 /* Register with the SPI framework */ 2226 /* Register with the SPI framework */
2229 amba_set_drvdata(adev, pl022); 2227 amba_set_drvdata(adev, pl022);
2230 status = spi_register_master(master); 2228 status = devm_spi_register_master(&adev->dev, master);
2231 if (status != 0) { 2229 if (status != 0) {
2232 dev_err(&adev->dev, 2230 dev_err(&adev->dev,
2233 "probe - problem registering spi master\n"); 2231 "probe - problem registering spi master\n");
@@ -2287,8 +2285,6 @@ pl022_remove(struct amba_device *adev)
2287 clk_unprepare(pl022->clk); 2285 clk_unprepare(pl022->clk);
2288 amba_release_regions(adev); 2286 amba_release_regions(adev);
2289 tasklet_disable(&pl022->pump_transfers); 2287 tasklet_disable(&pl022->pump_transfers);
2290 spi_unregister_master(pl022->master);
2291 amba_set_drvdata(adev, NULL);
2292 return 0; 2288 return 0;
2293} 2289}
2294 2290
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 0ee53c25ba58..c57740bb70d3 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -396,7 +396,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
396 master->dev.of_node = np; 396 master->dev.of_node = np;
397 platform_set_drvdata(op, master); 397 platform_set_drvdata(op, master);
398 hw = spi_master_get_devdata(master); 398 hw = spi_master_get_devdata(master);
399 hw->master = spi_master_get(master); 399 hw->master = master;
400 hw->dev = dev; 400 hw->dev = dev;
401 401
402 init_completion(&hw->done); 402 init_completion(&hw->done);
@@ -558,6 +558,7 @@ static int spi_ppc4xx_of_remove(struct platform_device *op)
558 free_irq(hw->irqnum, hw); 558 free_irq(hw->irqnum, hw);
559 iounmap(hw->regs); 559 iounmap(hw->regs);
560 free_gpios(hw); 560 free_gpios(hw);
561 spi_master_put(master);
561 return 0; 562 return 0;
562} 563}
563 564
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index c1a50674c1e3..cb0e1f1137ad 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -573,8 +573,8 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
573 write_SSTO(0, reg); 573 write_SSTO(0, reg);
574 write_SSSR_CS(drv_data, drv_data->clear_sr); 574 write_SSSR_CS(drv_data, drv_data->clear_sr);
575 575
576 dev_err(&drv_data->pdev->dev, "bad message state " 576 dev_err(&drv_data->pdev->dev,
577 "in interrupt handler\n"); 577 "bad message state in interrupt handler\n");
578 578
579 /* Never fail */ 579 /* Never fail */
580 return IRQ_HANDLED; 580 return IRQ_HANDLED;
@@ -651,8 +651,8 @@ static void pump_transfers(unsigned long data)
651 if (message->is_dma_mapped 651 if (message->is_dma_mapped
652 || transfer->rx_dma || transfer->tx_dma) { 652 || transfer->rx_dma || transfer->tx_dma) {
653 dev_err(&drv_data->pdev->dev, 653 dev_err(&drv_data->pdev->dev,
654 "pump_transfers: mapped transfer length " 654 "pump_transfers: mapped transfer length of "
655 "of %u is greater than %d\n", 655 "%u is greater than %d\n",
656 transfer->len, MAX_DMA_LEN); 656 transfer->len, MAX_DMA_LEN);
657 message->status = -EINVAL; 657 message->status = -EINVAL;
658 giveback(drv_data); 658 giveback(drv_data);
@@ -660,11 +660,10 @@ static void pump_transfers(unsigned long data)
660 } 660 }
661 661
662 /* warn ... we force this to PIO mode */ 662 /* warn ... we force this to PIO mode */
663 if (printk_ratelimit()) 663 dev_warn_ratelimited(&message->spi->dev,
664 dev_warn(&message->spi->dev, "pump_transfers: " 664 "pump_transfers: DMA disabled for transfer length %ld "
665 "DMA disabled for transfer length %ld " 665 "greater than %d\n",
666 "greater than %d\n", 666 (long)drv_data->len, MAX_DMA_LEN);
667 (long)drv_data->len, MAX_DMA_LEN);
668 } 667 }
669 668
670 /* Setup the transfer state based on the type of transfer */ 669 /* Setup the transfer state based on the type of transfer */
@@ -726,11 +725,8 @@ static void pump_transfers(unsigned long data)
726 message->spi, 725 message->spi,
727 bits, &dma_burst, 726 bits, &dma_burst,
728 &dma_thresh)) 727 &dma_thresh))
729 if (printk_ratelimit()) 728 dev_warn_ratelimited(&message->spi->dev,
730 dev_warn(&message->spi->dev, 729 "pump_transfers: DMA burst size reduced to match bits_per_word\n");
731 "pump_transfers: "
732 "DMA burst size reduced to "
733 "match bits_per_word\n");
734 } 730 }
735 731
736 cr0 = clk_div 732 cr0 = clk_div
@@ -854,8 +850,8 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
854 if (gpio_is_valid(chip_info->gpio_cs)) { 850 if (gpio_is_valid(chip_info->gpio_cs)) {
855 err = gpio_request(chip_info->gpio_cs, "SPI_CS"); 851 err = gpio_request(chip_info->gpio_cs, "SPI_CS");
856 if (err) { 852 if (err) {
857 dev_err(&spi->dev, "failed to request chip select " 853 dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
858 "GPIO%d\n", chip_info->gpio_cs); 854 chip_info->gpio_cs);
859 return err; 855 return err;
860 } 856 }
861 857
@@ -899,8 +895,8 @@ static int setup(struct spi_device *spi)
899 895
900 if (drv_data->ssp_type == CE4100_SSP) { 896 if (drv_data->ssp_type == CE4100_SSP) {
901 if (spi->chip_select > 4) { 897 if (spi->chip_select > 4) {
902 dev_err(&spi->dev, "failed setup: " 898 dev_err(&spi->dev,
903 "cs number must not be > 4.\n"); 899 "failed setup: cs number must not be > 4.\n");
904 kfree(chip); 900 kfree(chip);
905 return -EINVAL; 901 return -EINVAL;
906 } 902 }
@@ -956,8 +952,8 @@ static int setup(struct spi_device *spi)
956 spi->bits_per_word, 952 spi->bits_per_word,
957 &chip->dma_burst_size, 953 &chip->dma_burst_size,
958 &chip->dma_threshold)) { 954 &chip->dma_threshold)) {
959 dev_warn(&spi->dev, "in setup: DMA burst size reduced " 955 dev_warn(&spi->dev,
960 "to match bits_per_word\n"); 956 "in setup: DMA burst size reduced to match bits_per_word\n");
961 } 957 }
962 } 958 }
963 959
@@ -1205,7 +1201,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1205 1201
1206 /* Register with the SPI framework */ 1202 /* Register with the SPI framework */
1207 platform_set_drvdata(pdev, drv_data); 1203 platform_set_drvdata(pdev, drv_data);
1208 status = spi_register_master(master); 1204 status = devm_spi_register_master(&pdev->dev, master);
1209 if (status != 0) { 1205 if (status != 0) {
1210 dev_err(&pdev->dev, "problem registering spi master\n"); 1206 dev_err(&pdev->dev, "problem registering spi master\n");
1211 goto out_error_clock_enabled; 1207 goto out_error_clock_enabled;
@@ -1257,9 +1253,6 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
1257 /* Release SSP */ 1253 /* Release SSP */
1258 pxa_ssp_free(ssp); 1254 pxa_ssp_free(ssp);
1259 1255
1260 /* Disconnect from the SPI framework */
1261 spi_unregister_master(drv_data->master);
1262
1263 return 0; 1256 return 0;
1264} 1257}
1265 1258
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 8719206a03a0..58449ad4ad0d 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -59,6 +59,14 @@
59#define RSPI_SPCMD6 0x1c 59#define RSPI_SPCMD6 0x1c
60#define RSPI_SPCMD7 0x1e 60#define RSPI_SPCMD7 0x1e
61 61
62/*qspi only */
63#define QSPI_SPBFCR 0x18
64#define QSPI_SPBDCR 0x1a
65#define QSPI_SPBMUL0 0x1c
66#define QSPI_SPBMUL1 0x20
67#define QSPI_SPBMUL2 0x24
68#define QSPI_SPBMUL3 0x28
69
62/* SPCR */ 70/* SPCR */
63#define SPCR_SPRIE 0x80 71#define SPCR_SPRIE 0x80
64#define SPCR_SPE 0x40 72#define SPCR_SPE 0x40
@@ -126,6 +134,8 @@
126#define SPCMD_LSBF 0x1000 134#define SPCMD_LSBF 0x1000
127#define SPCMD_SPB_MASK 0x0f00 135#define SPCMD_SPB_MASK 0x0f00
128#define SPCMD_SPB_8_TO_16(bit) (((bit - 1) << 8) & SPCMD_SPB_MASK) 136#define SPCMD_SPB_8_TO_16(bit) (((bit - 1) << 8) & SPCMD_SPB_MASK)
137#define SPCMD_SPB_8BIT 0x0000 /* qspi only */
138#define SPCMD_SPB_16BIT 0x0100
129#define SPCMD_SPB_20BIT 0x0000 139#define SPCMD_SPB_20BIT 0x0000
130#define SPCMD_SPB_24BIT 0x0100 140#define SPCMD_SPB_24BIT 0x0100
131#define SPCMD_SPB_32BIT 0x0200 141#define SPCMD_SPB_32BIT 0x0200
@@ -135,6 +145,10 @@
135#define SPCMD_CPOL 0x0002 145#define SPCMD_CPOL 0x0002
136#define SPCMD_CPHA 0x0001 146#define SPCMD_CPHA 0x0001
137 147
148/* SPBFCR */
149#define SPBFCR_TXRST 0x80 /* qspi only */
150#define SPBFCR_RXRST 0x40 /* qspi only */
151
138struct rspi_data { 152struct rspi_data {
139 void __iomem *addr; 153 void __iomem *addr;
140 u32 max_speed_hz; 154 u32 max_speed_hz;
@@ -145,6 +159,7 @@ struct rspi_data {
145 spinlock_t lock; 159 spinlock_t lock;
146 struct clk *clk; 160 struct clk *clk;
147 unsigned char spsr; 161 unsigned char spsr;
162 const struct spi_ops *ops;
148 163
149 /* for dmaengine */ 164 /* for dmaengine */
150 struct dma_chan *chan_tx; 165 struct dma_chan *chan_tx;
@@ -165,6 +180,11 @@ static void rspi_write16(struct rspi_data *rspi, u16 data, u16 offset)
165 iowrite16(data, rspi->addr + offset); 180 iowrite16(data, rspi->addr + offset);
166} 181}
167 182
183static void rspi_write32(struct rspi_data *rspi, u32 data, u16 offset)
184{
185 iowrite32(data, rspi->addr + offset);
186}
187
168static u8 rspi_read8(struct rspi_data *rspi, u16 offset) 188static u8 rspi_read8(struct rspi_data *rspi, u16 offset)
169{ 189{
170 return ioread8(rspi->addr + offset); 190 return ioread8(rspi->addr + offset);
@@ -175,17 +195,103 @@ static u16 rspi_read16(struct rspi_data *rspi, u16 offset)
175 return ioread16(rspi->addr + offset); 195 return ioread16(rspi->addr + offset);
176} 196}
177 197
178static unsigned char rspi_calc_spbr(struct rspi_data *rspi) 198/* optional functions */
199struct spi_ops {
200 int (*set_config_register)(struct rspi_data *rspi, int access_size);
201 int (*send_pio)(struct rspi_data *rspi, struct spi_message *mesg,
202 struct spi_transfer *t);
203 int (*receive_pio)(struct rspi_data *rspi, struct spi_message *mesg,
204 struct spi_transfer *t);
205
206};
207
208/*
209 * functions for RSPI
210 */
211static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
212{
213 int spbr;
214
215 /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */
216 rspi_write8(rspi, 0x00, RSPI_SPPCR);
217
218 /* Sets transfer bit rate */
219 spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1;
220 rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
221
222 /* Sets number of frames to be used: 1 frame */
223 rspi_write8(rspi, 0x00, RSPI_SPDCR);
224
225 /* Sets RSPCK, SSL, next-access delay value */
226 rspi_write8(rspi, 0x00, RSPI_SPCKD);
227 rspi_write8(rspi, 0x00, RSPI_SSLND);
228 rspi_write8(rspi, 0x00, RSPI_SPND);
229
230 /* Sets parity, interrupt mask */
231 rspi_write8(rspi, 0x00, RSPI_SPCR2);
232
233 /* Sets SPCMD */
234 rspi_write16(rspi, SPCMD_SPB_8_TO_16(access_size) | SPCMD_SSLKP,
235 RSPI_SPCMD0);
236
237 /* Sets RSPI mode */
238 rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR);
239
240 return 0;
241}
242
243/*
244 * functions for QSPI
245 */
246static int qspi_set_config_register(struct rspi_data *rspi, int access_size)
179{ 247{
180 int tmp; 248 u16 spcmd;
181 unsigned char spbr; 249 int spbr;
250
251 /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */
252 rspi_write8(rspi, 0x00, RSPI_SPPCR);
253
254 /* Sets transfer bit rate */
255 spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz);
256 rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
257
258 /* Sets number of frames to be used: 1 frame */
259 rspi_write8(rspi, 0x00, RSPI_SPDCR);
260
261 /* Sets RSPCK, SSL, next-access delay value */
262 rspi_write8(rspi, 0x00, RSPI_SPCKD);
263 rspi_write8(rspi, 0x00, RSPI_SSLND);
264 rspi_write8(rspi, 0x00, RSPI_SPND);
265
266 /* Data Length Setting */
267 if (access_size == 8)
268 spcmd = SPCMD_SPB_8BIT;
269 else if (access_size == 16)
270 spcmd = SPCMD_SPB_16BIT;
271 else if (access_size == 32)
272 spcmd = SPCMD_SPB_32BIT;
273
274 spcmd |= SPCMD_SCKDEN | SPCMD_SLNDEN | SPCMD_SSLKP | SPCMD_SPNDEN;
275
276 /* Resets transfer data length */
277 rspi_write32(rspi, 0, QSPI_SPBMUL0);
278
279 /* Resets transmit and receive buffer */
280 rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR);
281 /* Sets buffer to allow normal operation */
282 rspi_write8(rspi, 0x00, QSPI_SPBFCR);
283
284 /* Sets SPCMD */
285 rspi_write16(rspi, spcmd, RSPI_SPCMD0);
182 286
183 tmp = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1; 287 /* Enables SPI function in a master mode */
184 spbr = clamp(tmp, 0, 255); 288 rspi_write8(rspi, SPCR_SPE | SPCR_MSTR, RSPI_SPCR);
185 289
186 return spbr; 290 return 0;
187} 291}
188 292
293#define set_config_register(spi, n) spi->ops->set_config_register(spi, n)
294
189static void rspi_enable_irq(struct rspi_data *rspi, u8 enable) 295static void rspi_enable_irq(struct rspi_data *rspi, u8 enable)
190{ 296{
191 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | enable, RSPI_SPCR); 297 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | enable, RSPI_SPCR);
@@ -220,54 +326,60 @@ static void rspi_negate_ssl(struct rspi_data *rspi)
220 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR); 326 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR);
221} 327}
222 328
223static int rspi_set_config_register(struct rspi_data *rspi, int access_size) 329static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg,
330 struct spi_transfer *t)
224{ 331{
225 /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */ 332 int remain = t->len;
226 rspi_write8(rspi, 0x00, RSPI_SPPCR); 333 u8 *data;
227
228 /* Sets transfer bit rate */
229 rspi_write8(rspi, rspi_calc_spbr(rspi), RSPI_SPBR);
230
231 /* Sets number of frames to be used: 1 frame */
232 rspi_write8(rspi, 0x00, RSPI_SPDCR);
233 334
234 /* Sets RSPCK, SSL, next-access delay value */ 335 data = (u8 *)t->tx_buf;
235 rspi_write8(rspi, 0x00, RSPI_SPCKD); 336 while (remain > 0) {
236 rspi_write8(rspi, 0x00, RSPI_SSLND); 337 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD,
237 rspi_write8(rspi, 0x00, RSPI_SPND); 338 RSPI_SPCR);
238 339
239 /* Sets parity, interrupt mask */ 340 if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) {
240 rspi_write8(rspi, 0x00, RSPI_SPCR2); 341 dev_err(&rspi->master->dev,
342 "%s: tx empty timeout\n", __func__);
343 return -ETIMEDOUT;
344 }
241 345
242 /* Sets SPCMD */ 346 rspi_write16(rspi, *data, RSPI_SPDR);
243 rspi_write16(rspi, SPCMD_SPB_8_TO_16(access_size) | SPCMD_SSLKP, 347 data++;
244 RSPI_SPCMD0); 348 remain--;
349 }
245 350
246 /* Sets RSPI mode */ 351 /* Waiting for the last transmition */
247 rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); 352 rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE);
248 353
249 return 0; 354 return 0;
250} 355}
251 356
252static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, 357static int qspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg,
253 struct spi_transfer *t) 358 struct spi_transfer *t)
254{ 359{
255 int remain = t->len; 360 int remain = t->len;
256 u8 *data; 361 u8 *data;
257 362
363 rspi_write8(rspi, SPBFCR_TXRST, QSPI_SPBFCR);
364 rspi_write8(rspi, 0x00, QSPI_SPBFCR);
365
258 data = (u8 *)t->tx_buf; 366 data = (u8 *)t->tx_buf;
259 while (remain > 0) { 367 while (remain > 0) {
260 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD,
261 RSPI_SPCR);
262 368
263 if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { 369 if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) {
264 dev_err(&rspi->master->dev, 370 dev_err(&rspi->master->dev,
265 "%s: tx empty timeout\n", __func__); 371 "%s: tx empty timeout\n", __func__);
266 return -ETIMEDOUT; 372 return -ETIMEDOUT;
267 } 373 }
374 rspi_write8(rspi, *data++, RSPI_SPDR);
375
376 if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) {
377 dev_err(&rspi->master->dev,
378 "%s: receive timeout\n", __func__);
379 return -ETIMEDOUT;
380 }
381 rspi_read8(rspi, RSPI_SPDR);
268 382
269 rspi_write16(rspi, *data, RSPI_SPDR);
270 data++;
271 remain--; 383 remain--;
272 } 384 }
273 385
@@ -277,6 +389,8 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg,
277 return 0; 389 return 0;
278} 390}
279 391
392#define send_pio(spi, mesg, t) spi->ops->send_pio(spi, mesg, t)
393
280static void rspi_dma_complete(void *arg) 394static void rspi_dma_complete(void *arg)
281{ 395{
282 struct rspi_data *rspi = arg; 396 struct rspi_data *rspi = arg;
@@ -442,6 +556,51 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
442 return 0; 556 return 0;
443} 557}
444 558
559static void qspi_receive_init(struct rspi_data *rspi)
560{
561 unsigned char spsr;
562
563 spsr = rspi_read8(rspi, RSPI_SPSR);
564 if (spsr & SPSR_SPRF)
565 rspi_read8(rspi, RSPI_SPDR); /* dummy read */
566 rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR);
567 rspi_write8(rspi, 0x00, QSPI_SPBFCR);
568}
569
570static int qspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
571 struct spi_transfer *t)
572{
573 int remain = t->len;
574 u8 *data;
575
576 qspi_receive_init(rspi);
577
578 data = (u8 *)t->rx_buf;
579 while (remain > 0) {
580
581 if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) {
582 dev_err(&rspi->master->dev,
583 "%s: tx empty timeout\n", __func__);
584 return -ETIMEDOUT;
585 }
586 /* dummy write for generate clock */
587 rspi_write8(rspi, 0x00, RSPI_SPDR);
588
589 if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) {
590 dev_err(&rspi->master->dev,
591 "%s: receive timeout\n", __func__);
592 return -ETIMEDOUT;
593 }
594 /* SPDR allows 8, 16 or 32-bit access */
595 *data++ = rspi_read8(rspi, RSPI_SPDR);
596 remain--;
597 }
598
599 return 0;
600}
601
602#define receive_pio(spi, mesg, t) spi->ops->receive_pio(spi, mesg, t)
603
445static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t) 604static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t)
446{ 605{
447 struct scatterlist sg, sg_dummy; 606 struct scatterlist sg, sg_dummy;
@@ -581,7 +740,7 @@ static void rspi_work(struct work_struct *work)
581 if (rspi_is_dma(rspi, t)) 740 if (rspi_is_dma(rspi, t))
582 ret = rspi_send_dma(rspi, t); 741 ret = rspi_send_dma(rspi, t);
583 else 742 else
584 ret = rspi_send_pio(rspi, mesg, t); 743 ret = send_pio(rspi, mesg, t);
585 if (ret < 0) 744 if (ret < 0)
586 goto error; 745 goto error;
587 } 746 }
@@ -589,7 +748,7 @@ static void rspi_work(struct work_struct *work)
589 if (rspi_is_dma(rspi, t)) 748 if (rspi_is_dma(rspi, t))
590 ret = rspi_receive_dma(rspi, t); 749 ret = rspi_receive_dma(rspi, t);
591 else 750 else
592 ret = rspi_receive_pio(rspi, mesg, t); 751 ret = receive_pio(rspi, mesg, t);
593 if (ret < 0) 752 if (ret < 0)
594 goto error; 753 goto error;
595 } 754 }
@@ -616,7 +775,7 @@ static int rspi_setup(struct spi_device *spi)
616 spi->bits_per_word = 8; 775 spi->bits_per_word = 8;
617 rspi->max_speed_hz = spi->max_speed_hz; 776 rspi->max_speed_hz = spi->max_speed_hz;
618 777
619 rspi_set_config_register(rspi, 8); 778 set_config_register(rspi, 8);
620 779
621 return 0; 780 return 0;
622} 781}
@@ -745,7 +904,16 @@ static int rspi_probe(struct platform_device *pdev)
745 struct rspi_data *rspi; 904 struct rspi_data *rspi;
746 int ret, irq; 905 int ret, irq;
747 char clk_name[16]; 906 char clk_name[16];
748 907 struct rspi_plat_data *rspi_pd = pdev->dev.platform_data;
908 const struct spi_ops *ops;
909 const struct platform_device_id *id_entry = pdev->id_entry;
910
911 ops = (struct spi_ops *)id_entry->driver_data;
912 /* ops parameter check */
913 if (!ops->set_config_register) {
914 dev_err(&pdev->dev, "there is no set_config_register\n");
915 return -ENODEV;
916 }
749 /* get base addr */ 917 /* get base addr */
750 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 918 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
751 if (unlikely(res == NULL)) { 919 if (unlikely(res == NULL)) {
@@ -767,7 +935,7 @@ static int rspi_probe(struct platform_device *pdev)
767 935
768 rspi = spi_master_get_devdata(master); 936 rspi = spi_master_get_devdata(master);
769 platform_set_drvdata(pdev, rspi); 937 platform_set_drvdata(pdev, rspi);
770 938 rspi->ops = ops;
771 rspi->master = master; 939 rspi->master = master;
772 rspi->addr = ioremap(res->start, resource_size(res)); 940 rspi->addr = ioremap(res->start, resource_size(res));
773 if (rspi->addr == NULL) { 941 if (rspi->addr == NULL) {
@@ -776,7 +944,7 @@ static int rspi_probe(struct platform_device *pdev)
776 goto error1; 944 goto error1;
777 } 945 }
778 946
779 snprintf(clk_name, sizeof(clk_name), "rspi%d", pdev->id); 947 snprintf(clk_name, sizeof(clk_name), "%s%d", id_entry->name, pdev->id);
780 rspi->clk = clk_get(&pdev->dev, clk_name); 948 rspi->clk = clk_get(&pdev->dev, clk_name);
781 if (IS_ERR(rspi->clk)) { 949 if (IS_ERR(rspi->clk)) {
782 dev_err(&pdev->dev, "cannot get clock\n"); 950 dev_err(&pdev->dev, "cannot get clock\n");
@@ -790,7 +958,10 @@ static int rspi_probe(struct platform_device *pdev)
790 INIT_WORK(&rspi->ws, rspi_work); 958 INIT_WORK(&rspi->ws, rspi_work);
791 init_waitqueue_head(&rspi->wait); 959 init_waitqueue_head(&rspi->wait);
792 960
793 master->num_chipselect = 2; 961 master->num_chipselect = rspi_pd->num_chipselect;
962 if (!master->num_chipselect)
963 master->num_chipselect = 2; /* default */
964
794 master->bus_num = pdev->id; 965 master->bus_num = pdev->id;
795 master->setup = rspi_setup; 966 master->setup = rspi_setup;
796 master->transfer = rspi_transfer; 967 master->transfer = rspi_transfer;
@@ -832,11 +1003,32 @@ error1:
832 return ret; 1003 return ret;
833} 1004}
834 1005
1006static struct spi_ops rspi_ops = {
1007 .set_config_register = rspi_set_config_register,
1008 .send_pio = rspi_send_pio,
1009 .receive_pio = rspi_receive_pio,
1010};
1011
1012static struct spi_ops qspi_ops = {
1013 .set_config_register = qspi_set_config_register,
1014 .send_pio = qspi_send_pio,
1015 .receive_pio = qspi_receive_pio,
1016};
1017
1018static struct platform_device_id spi_driver_ids[] = {
1019 { "rspi", (kernel_ulong_t)&rspi_ops },
1020 { "qspi", (kernel_ulong_t)&qspi_ops },
1021 {},
1022};
1023
1024MODULE_DEVICE_TABLE(platform, spi_driver_ids);
1025
835static struct platform_driver rspi_driver = { 1026static struct platform_driver rspi_driver = {
836 .probe = rspi_probe, 1027 .probe = rspi_probe,
837 .remove = rspi_remove, 1028 .remove = rspi_remove,
1029 .id_table = spi_driver_ids,
838 .driver = { 1030 .driver = {
839 .name = "rspi", 1031 .name = "renesas_spi",
840 .owner = THIS_MODULE, 1032 .owner = THIS_MODULE,
841 }, 1033 },
842}; 1034};
diff --git a/drivers/spi/spi-s3c24xx.c b/drivers/spi/spi-s3c24xx.c
index ce318d95a6ee..0dc32a11bd3c 100644
--- a/drivers/spi/spi-s3c24xx.c
+++ b/drivers/spi/spi-s3c24xx.c
@@ -280,7 +280,7 @@ static inline u32 ack_bit(unsigned int irq)
280 * so the caller does not need to do anything more than start the transfer 280 * so the caller does not need to do anything more than start the transfer
281 * as normal, since the IRQ will have been re-routed to the FIQ handler. 281 * as normal, since the IRQ will have been re-routed to the FIQ handler.
282*/ 282*/
283void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw) 283static void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw)
284{ 284{
285 struct pt_regs regs; 285 struct pt_regs regs;
286 enum spi_fiq_mode mode; 286 enum spi_fiq_mode mode;
@@ -524,7 +524,7 @@ static int s3c24xx_spi_probe(struct platform_device *pdev)
524 hw = spi_master_get_devdata(master); 524 hw = spi_master_get_devdata(master);
525 memset(hw, 0, sizeof(struct s3c24xx_spi)); 525 memset(hw, 0, sizeof(struct s3c24xx_spi));
526 526
527 hw->master = spi_master_get(master); 527 hw->master = master;
528 hw->pdata = pdata = dev_get_platdata(&pdev->dev); 528 hw->pdata = pdata = dev_get_platdata(&pdev->dev);
529 hw->dev = &pdev->dev; 529 hw->dev = &pdev->dev;
530 530
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index a80376dc3a10..9e2020df9e0f 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -205,7 +205,6 @@ struct s3c64xx_spi_driver_data {
205#endif 205#endif
206 struct s3c64xx_spi_port_config *port_conf; 206 struct s3c64xx_spi_port_config *port_conf;
207 unsigned int port_id; 207 unsigned int port_id;
208 unsigned long gpios[4];
209 bool cs_gpio; 208 bool cs_gpio;
210}; 209};
211 210
@@ -559,25 +558,18 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
559static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd, 558static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd,
560 struct spi_device *spi) 559 struct spi_device *spi)
561{ 560{
562 struct s3c64xx_spi_csinfo *cs;
563
564 if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */ 561 if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */
565 if (sdd->tgl_spi != spi) { /* if last mssg on diff device */ 562 if (sdd->tgl_spi != spi) { /* if last mssg on diff device */
566 /* Deselect the last toggled device */ 563 /* Deselect the last toggled device */
567 cs = sdd->tgl_spi->controller_data; 564 if (spi->cs_gpio >= 0)
568 if (sdd->cs_gpio) 565 gpio_set_value(spi->cs_gpio,
569 gpio_set_value(cs->line,
570 spi->mode & SPI_CS_HIGH ? 0 : 1); 566 spi->mode & SPI_CS_HIGH ? 0 : 1);
571 } 567 }
572 sdd->tgl_spi = NULL; 568 sdd->tgl_spi = NULL;
573 } 569 }
574 570
575 cs = spi->controller_data; 571 if (spi->cs_gpio >= 0)
576 if (sdd->cs_gpio) 572 gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH ? 1 : 0);
577 gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 1 : 0);
578
579 /* Start the signals */
580 writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
581} 573}
582 574
583static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd, 575static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd,
@@ -702,16 +694,11 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd,
702static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd, 694static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
703 struct spi_device *spi) 695 struct spi_device *spi)
704{ 696{
705 struct s3c64xx_spi_csinfo *cs = spi->controller_data;
706
707 if (sdd->tgl_spi == spi) 697 if (sdd->tgl_spi == spi)
708 sdd->tgl_spi = NULL; 698 sdd->tgl_spi = NULL;
709 699
710 if (sdd->cs_gpio) 700 if (spi->cs_gpio >= 0)
711 gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 0 : 1); 701 gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH ? 0 : 1);
712
713 /* Quiese the signals */
714 writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
715} 702}
716 703
717static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) 704static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
@@ -862,16 +849,12 @@ static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd,
862 } 849 }
863} 850}
864 851
865static int s3c64xx_spi_transfer_one_message(struct spi_master *master, 852static int s3c64xx_spi_prepare_message(struct spi_master *master,
866 struct spi_message *msg) 853 struct spi_message *msg)
867{ 854{
868 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 855 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
869 struct spi_device *spi = msg->spi; 856 struct spi_device *spi = msg->spi;
870 struct s3c64xx_spi_csinfo *cs = spi->controller_data; 857 struct s3c64xx_spi_csinfo *cs = spi->controller_data;
871 struct spi_transfer *xfer;
872 int status = 0, cs_toggle = 0;
873 u32 speed;
874 u8 bpw;
875 858
876 /* If Master's(controller) state differs from that needed by Slave */ 859 /* If Master's(controller) state differs from that needed by Slave */
877 if (sdd->cur_speed != spi->max_speed_hz 860 if (sdd->cur_speed != spi->max_speed_hz
@@ -887,106 +870,98 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master,
887 if (s3c64xx_spi_map_mssg(sdd, msg)) { 870 if (s3c64xx_spi_map_mssg(sdd, msg)) {
888 dev_err(&spi->dev, 871 dev_err(&spi->dev,
889 "Xfer: Unable to map message buffers!\n"); 872 "Xfer: Unable to map message buffers!\n");
890 status = -ENOMEM; 873 return -ENOMEM;
891 goto out;
892 } 874 }
893 875
894 /* Configure feedback delay */ 876 /* Configure feedback delay */
895 writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK); 877 writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK);
896 878
897 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 879 return 0;
898 880}
899 unsigned long flags;
900 int use_dma;
901
902 INIT_COMPLETION(sdd->xfer_completion);
903
904 /* Only BPW and Speed may change across transfers */
905 bpw = xfer->bits_per_word;
906 speed = xfer->speed_hz ? : spi->max_speed_hz;
907
908 if (xfer->len % (bpw / 8)) {
909 dev_err(&spi->dev,
910 "Xfer length(%u) not a multiple of word size(%u)\n",
911 xfer->len, bpw / 8);
912 status = -EIO;
913 goto out;
914 }
915 881
916 if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) { 882static int s3c64xx_spi_transfer_one(struct spi_master *master,
917 sdd->cur_bpw = bpw; 883 struct spi_device *spi,
918 sdd->cur_speed = speed; 884 struct spi_transfer *xfer)
919 s3c64xx_spi_config(sdd); 885{
920 } 886 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
887 int status;
888 u32 speed;
889 u8 bpw;
890 unsigned long flags;
891 int use_dma;
921 892
922 /* Polling method for xfers not bigger than FIFO capacity */ 893 INIT_COMPLETION(sdd->xfer_completion);
923 use_dma = 0;
924 if (!is_polling(sdd) &&
925 (sdd->rx_dma.ch && sdd->tx_dma.ch &&
926 (xfer->len > ((FIFO_LVL_MASK(sdd) >> 1) + 1))))
927 use_dma = 1;
928 894
929 spin_lock_irqsave(&sdd->lock, flags); 895 /* Only BPW and Speed may change across transfers */
896 bpw = xfer->bits_per_word;
897 speed = xfer->speed_hz ? : spi->max_speed_hz;
930 898
931 /* Pending only which is to be done */ 899 if (xfer->len % (bpw / 8)) {
932 sdd->state &= ~RXBUSY; 900 dev_err(&spi->dev,
933 sdd->state &= ~TXBUSY; 901 "Xfer length(%u) not a multiple of word size(%u)\n",
902 xfer->len, bpw / 8);
903 return -EIO;
904 }
934 905
935 enable_datapath(sdd, spi, xfer, use_dma); 906 if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
907 sdd->cur_bpw = bpw;
908 sdd->cur_speed = speed;
909 s3c64xx_spi_config(sdd);
910 }
936 911
937 /* Slave Select */ 912 /* Polling method for xfers not bigger than FIFO capacity */
938 enable_cs(sdd, spi); 913 use_dma = 0;
914 if (!is_polling(sdd) &&
915 (sdd->rx_dma.ch && sdd->tx_dma.ch &&
916 (xfer->len > ((FIFO_LVL_MASK(sdd) >> 1) + 1))))
917 use_dma = 1;
939 918
940 spin_unlock_irqrestore(&sdd->lock, flags); 919 spin_lock_irqsave(&sdd->lock, flags);
941 920
942 status = wait_for_xfer(sdd, xfer, use_dma); 921 /* Pending only which is to be done */
922 sdd->state &= ~RXBUSY;
923 sdd->state &= ~TXBUSY;
943 924
944 if (status) { 925 enable_datapath(sdd, spi, xfer, use_dma);
945 dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n",
946 xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0,
947 (sdd->state & RXBUSY) ? 'f' : 'p',
948 (sdd->state & TXBUSY) ? 'f' : 'p',
949 xfer->len);
950 926
951 if (use_dma) { 927 /* Start the signals */
952 if (xfer->tx_buf != NULL 928 writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
953 && (sdd->state & TXBUSY))
954 s3c64xx_spi_dma_stop(sdd, &sdd->tx_dma);
955 if (xfer->rx_buf != NULL
956 && (sdd->state & RXBUSY))
957 s3c64xx_spi_dma_stop(sdd, &sdd->rx_dma);
958 }
959 929
960 goto out; 930 /* Start the signals */
961 } 931 writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
962 932
963 if (xfer->delay_usecs) 933 spin_unlock_irqrestore(&sdd->lock, flags);
964 udelay(xfer->delay_usecs);
965 934
966 if (xfer->cs_change) { 935 status = wait_for_xfer(sdd, xfer, use_dma);
967 /* Hint that the next mssg is gonna be 936
968 for the same device */ 937 if (status) {
969 if (list_is_last(&xfer->transfer_list, 938 dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n",
970 &msg->transfers)) 939 xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0,
971 cs_toggle = 1; 940 (sdd->state & RXBUSY) ? 'f' : 'p',
941 (sdd->state & TXBUSY) ? 'f' : 'p',
942 xfer->len);
943
944 if (use_dma) {
945 if (xfer->tx_buf != NULL
946 && (sdd->state & TXBUSY))
947 s3c64xx_spi_dma_stop(sdd, &sdd->tx_dma);
948 if (xfer->rx_buf != NULL
949 && (sdd->state & RXBUSY))
950 s3c64xx_spi_dma_stop(sdd, &sdd->rx_dma);
972 } 951 }
973 952 } else {
974 msg->actual_length += xfer->len;
975
976 flush_fifo(sdd); 953 flush_fifo(sdd);
977 } 954 }
978 955
979out: 956 return status;
980 if (!cs_toggle || status) 957}
981 disable_cs(sdd, spi);
982 else
983 sdd->tgl_spi = spi;
984
985 s3c64xx_spi_unmap_mssg(sdd, msg);
986 958
987 msg->status = status; 959static int s3c64xx_spi_unprepare_message(struct spi_master *master,
960 struct spi_message *msg)
961{
962 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
988 963
989 spi_finalize_current_message(master); 964 s3c64xx_spi_unmap_mssg(sdd, msg);
990 965
991 return 0; 966 return 0;
992} 967}
@@ -1071,6 +1046,8 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
1071 cs->line, err); 1046 cs->line, err);
1072 goto err_gpio_req; 1047 goto err_gpio_req;
1073 } 1048 }
1049
1050 spi->cs_gpio = cs->line;
1074 } 1051 }
1075 1052
1076 spi_set_ctldata(spi, cs); 1053 spi_set_ctldata(spi, cs);
@@ -1117,11 +1094,14 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
1117 } 1094 }
1118 1095
1119 pm_runtime_put(&sdd->pdev->dev); 1096 pm_runtime_put(&sdd->pdev->dev);
1097 writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
1120 disable_cs(sdd, spi); 1098 disable_cs(sdd, spi);
1121 return 0; 1099 return 0;
1122 1100
1123setup_exit: 1101setup_exit:
1102 pm_runtime_put(&sdd->pdev->dev);
1124 /* setup() returns with device de-selected */ 1103 /* setup() returns with device de-selected */
1104 writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
1125 disable_cs(sdd, spi); 1105 disable_cs(sdd, spi);
1126 1106
1127 gpio_free(cs->line); 1107 gpio_free(cs->line);
@@ -1140,8 +1120,8 @@ static void s3c64xx_spi_cleanup(struct spi_device *spi)
1140 struct s3c64xx_spi_driver_data *sdd; 1120 struct s3c64xx_spi_driver_data *sdd;
1141 1121
1142 sdd = spi_master_get_devdata(spi->master); 1122 sdd = spi_master_get_devdata(spi->master);
1143 if (cs && sdd->cs_gpio) { 1123 if (spi->cs_gpio) {
1144 gpio_free(cs->line); 1124 gpio_free(spi->cs_gpio);
1145 if (spi->dev.of_node) 1125 if (spi->dev.of_node)
1146 kfree(cs); 1126 kfree(cs);
1147 } 1127 }
@@ -1359,7 +1339,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
1359 master->setup = s3c64xx_spi_setup; 1339 master->setup = s3c64xx_spi_setup;
1360 master->cleanup = s3c64xx_spi_cleanup; 1340 master->cleanup = s3c64xx_spi_cleanup;
1361 master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer; 1341 master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer;
1362 master->transfer_one_message = s3c64xx_spi_transfer_one_message; 1342 master->prepare_message = s3c64xx_spi_prepare_message;
1343 master->transfer_one = s3c64xx_spi_transfer_one;
1344 master->unprepare_message = s3c64xx_spi_unprepare_message;
1363 master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer; 1345 master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer;
1364 master->num_chipselect = sci->num_cs; 1346 master->num_chipselect = sci->num_cs;
1365 master->dma_alignment = 8; 1347 master->dma_alignment = 8;
@@ -1428,11 +1410,12 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
1428 S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN, 1410 S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN,
1429 sdd->regs + S3C64XX_SPI_INT_EN); 1411 sdd->regs + S3C64XX_SPI_INT_EN);
1430 1412
1413 pm_runtime_set_active(&pdev->dev);
1431 pm_runtime_enable(&pdev->dev); 1414 pm_runtime_enable(&pdev->dev);
1432 1415
1433 if (spi_register_master(master)) { 1416 ret = devm_spi_register_master(&pdev->dev, master);
1434 dev_err(&pdev->dev, "cannot register SPI master\n"); 1417 if (ret != 0) {
1435 ret = -EBUSY; 1418 dev_err(&pdev->dev, "cannot register SPI master: %d\n", ret);
1436 goto err3; 1419 goto err3;
1437 } 1420 }
1438 1421
@@ -1461,16 +1444,12 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
1461 1444
1462 pm_runtime_disable(&pdev->dev); 1445 pm_runtime_disable(&pdev->dev);
1463 1446
1464 spi_unregister_master(master);
1465
1466 writel(0, sdd->regs + S3C64XX_SPI_INT_EN); 1447 writel(0, sdd->regs + S3C64XX_SPI_INT_EN);
1467 1448
1468 clk_disable_unprepare(sdd->src_clk); 1449 clk_disable_unprepare(sdd->src_clk);
1469 1450
1470 clk_disable_unprepare(sdd->clk); 1451 clk_disable_unprepare(sdd->clk);
1471 1452
1472 spi_master_put(master);
1473
1474 return 0; 1453 return 0;
1475} 1454}
1476 1455
@@ -1480,11 +1459,14 @@ static int s3c64xx_spi_suspend(struct device *dev)
1480 struct spi_master *master = dev_get_drvdata(dev); 1459 struct spi_master *master = dev_get_drvdata(dev);
1481 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1460 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1482 1461
1483 spi_master_suspend(master); 1462 int ret = spi_master_suspend(master);
1463 if (ret)
1464 return ret;
1484 1465
1485 /* Disable the clock */ 1466 if (!pm_runtime_suspended(dev)) {
1486 clk_disable_unprepare(sdd->src_clk); 1467 clk_disable_unprepare(sdd->clk);
1487 clk_disable_unprepare(sdd->clk); 1468 clk_disable_unprepare(sdd->src_clk);
1469 }
1488 1470
1489 sdd->cur_speed = 0; /* Output Clock is stopped */ 1471 sdd->cur_speed = 0; /* Output Clock is stopped */
1490 1472
@@ -1500,15 +1482,14 @@ static int s3c64xx_spi_resume(struct device *dev)
1500 if (sci->cfg_gpio) 1482 if (sci->cfg_gpio)
1501 sci->cfg_gpio(); 1483 sci->cfg_gpio();
1502 1484
1503 /* Enable the clock */ 1485 if (!pm_runtime_suspended(dev)) {
1504 clk_prepare_enable(sdd->src_clk); 1486 clk_prepare_enable(sdd->src_clk);
1505 clk_prepare_enable(sdd->clk); 1487 clk_prepare_enable(sdd->clk);
1488 }
1506 1489
1507 s3c64xx_spi_hwinit(sdd, sdd->port_id); 1490 s3c64xx_spi_hwinit(sdd, sdd->port_id);
1508 1491
1509 spi_master_resume(master); 1492 return spi_master_resume(master);
1510
1511 return 0;
1512} 1493}
1513#endif /* CONFIG_PM_SLEEP */ 1494#endif /* CONFIG_PM_SLEEP */
1514 1495
@@ -1528,9 +1509,17 @@ static int s3c64xx_spi_runtime_resume(struct device *dev)
1528{ 1509{
1529 struct spi_master *master = dev_get_drvdata(dev); 1510 struct spi_master *master = dev_get_drvdata(dev);
1530 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1511 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1512 int ret;
1531 1513
1532 clk_prepare_enable(sdd->src_clk); 1514 ret = clk_prepare_enable(sdd->src_clk);
1533 clk_prepare_enable(sdd->clk); 1515 if (ret != 0)
1516 return ret;
1517
1518 ret = clk_prepare_enable(sdd->clk);
1519 if (ret != 0) {
1520 clk_disable_unprepare(sdd->src_clk);
1521 return ret;
1522 }
1534 1523
1535 return 0; 1524 return 0;
1536} 1525}
@@ -1616,6 +1605,18 @@ static struct platform_device_id s3c64xx_spi_driver_ids[] = {
1616}; 1605};
1617 1606
1618static const struct of_device_id s3c64xx_spi_dt_match[] = { 1607static const struct of_device_id s3c64xx_spi_dt_match[] = {
1608 { .compatible = "samsung,s3c2443-spi",
1609 .data = (void *)&s3c2443_spi_port_config,
1610 },
1611 { .compatible = "samsung,s3c6410-spi",
1612 .data = (void *)&s3c6410_spi_port_config,
1613 },
1614 { .compatible = "samsung,s5pc100-spi",
1615 .data = (void *)&s5pc100_spi_port_config,
1616 },
1617 { .compatible = "samsung,s5pv210-spi",
1618 .data = (void *)&s5pv210_spi_port_config,
1619 },
1619 { .compatible = "samsung,exynos4210-spi", 1620 { .compatible = "samsung,exynos4210-spi",
1620 .data = (void *)&exynos4_spi_port_config, 1621 .data = (void *)&exynos4_spi_port_config,
1621 }, 1622 },
@@ -1633,22 +1634,13 @@ static struct platform_driver s3c64xx_spi_driver = {
1633 .pm = &s3c64xx_spi_pm, 1634 .pm = &s3c64xx_spi_pm,
1634 .of_match_table = of_match_ptr(s3c64xx_spi_dt_match), 1635 .of_match_table = of_match_ptr(s3c64xx_spi_dt_match),
1635 }, 1636 },
1637 .probe = s3c64xx_spi_probe,
1636 .remove = s3c64xx_spi_remove, 1638 .remove = s3c64xx_spi_remove,
1637 .id_table = s3c64xx_spi_driver_ids, 1639 .id_table = s3c64xx_spi_driver_ids,
1638}; 1640};
1639MODULE_ALIAS("platform:s3c64xx-spi"); 1641MODULE_ALIAS("platform:s3c64xx-spi");
1640 1642
1641static int __init s3c64xx_spi_init(void) 1643module_platform_driver(s3c64xx_spi_driver);
1642{
1643 return platform_driver_probe(&s3c64xx_spi_driver, s3c64xx_spi_probe);
1644}
1645subsys_initcall(s3c64xx_spi_init);
1646
1647static void __exit s3c64xx_spi_exit(void)
1648{
1649 platform_driver_unregister(&s3c64xx_spi_driver);
1650}
1651module_exit(s3c64xx_spi_exit);
1652 1644
1653MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>"); 1645MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>");
1654MODULE_DESCRIPTION("S3C64XX SPI Controller Driver"); 1646MODULE_DESCRIPTION("S3C64XX SPI Controller Driver");
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index e488a90a98b8..292567ab4c6c 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -137,7 +137,7 @@ static void hspi_hw_setup(struct hspi_priv *hspi,
137 rate /= 16; 137 rate /= 16;
138 138
139 /* CLKCx calculation */ 139 /* CLKCx calculation */
140 rate /= (((idiv_clk & 0x1F) + 1) * 2) ; 140 rate /= (((idiv_clk & 0x1F) + 1) * 2);
141 141
142 /* save best settings */ 142 /* save best settings */
143 tmp = abs(target_rate - rate); 143 tmp = abs(target_rate - rate);
@@ -303,9 +303,10 @@ static int hspi_probe(struct platform_device *pdev)
303 master->setup = hspi_setup; 303 master->setup = hspi_setup;
304 master->cleanup = hspi_cleanup; 304 master->cleanup = hspi_cleanup;
305 master->mode_bits = SPI_CPOL | SPI_CPHA; 305 master->mode_bits = SPI_CPOL | SPI_CPHA;
306 master->dev.of_node = pdev->dev.of_node;
306 master->auto_runtime_pm = true; 307 master->auto_runtime_pm = true;
307 master->transfer_one_message = hspi_transfer_one_message; 308 master->transfer_one_message = hspi_transfer_one_message;
308 ret = spi_register_master(master); 309 ret = devm_spi_register_master(&pdev->dev, master);
309 if (ret < 0) { 310 if (ret < 0) {
310 dev_err(&pdev->dev, "spi_register_master error.\n"); 311 dev_err(&pdev->dev, "spi_register_master error.\n");
311 goto error1; 312 goto error1;
@@ -328,17 +329,23 @@ static int hspi_remove(struct platform_device *pdev)
328 pm_runtime_disable(&pdev->dev); 329 pm_runtime_disable(&pdev->dev);
329 330
330 clk_put(hspi->clk); 331 clk_put(hspi->clk);
331 spi_unregister_master(hspi->master);
332 332
333 return 0; 333 return 0;
334} 334}
335 335
336static struct of_device_id hspi_of_match[] = {
337 { .compatible = "renesas,hspi", },
338 { /* sentinel */ }
339};
340MODULE_DEVICE_TABLE(of, hspi_of_match);
341
336static struct platform_driver hspi_driver = { 342static struct platform_driver hspi_driver = {
337 .probe = hspi_probe, 343 .probe = hspi_probe,
338 .remove = hspi_remove, 344 .remove = hspi_remove,
339 .driver = { 345 .driver = {
340 .name = "sh-hspi", 346 .name = "sh-hspi",
341 .owner = THIS_MODULE, 347 .owner = THIS_MODULE,
348 .of_match_table = hspi_of_match,
342 }, 349 },
343}; 350};
344module_platform_driver(hspi_driver); 351module_platform_driver(hspi_driver);
diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c
index 8eefeb6007df..38eb24df796c 100644
--- a/drivers/spi/spi-sh-sci.c
+++ b/drivers/spi/spi-sh-sci.c
@@ -133,7 +133,7 @@ static int sh_sci_spi_probe(struct platform_device *dev)
133 sp->info = dev_get_platdata(&dev->dev); 133 sp->info = dev_get_platdata(&dev->dev);
134 134
135 /* setup spi bitbang adaptor */ 135 /* setup spi bitbang adaptor */
136 sp->bitbang.master = spi_master_get(master); 136 sp->bitbang.master = master;
137 sp->bitbang.master->bus_num = sp->info->bus_num; 137 sp->bitbang.master->bus_num = sp->info->bus_num;
138 sp->bitbang.master->num_chipselect = sp->info->num_chipselect; 138 sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
139 sp->bitbang.chipselect = sh_sci_spi_chipselect; 139 sp->bitbang.chipselect = sh_sci_spi_chipselect;
diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c
index a1f21b747733..592b4aff651f 100644
--- a/drivers/spi/spi-sirf.c
+++ b/drivers/spi/spi-sirf.c
@@ -632,7 +632,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev)
632 if (ret) 632 if (ret)
633 goto free_master; 633 goto free_master;
634 634
635 sspi->bitbang.master = spi_master_get(master); 635 sspi->bitbang.master = master;
636 sspi->bitbang.chipselect = spi_sirfsoc_chipselect; 636 sspi->bitbang.chipselect = spi_sirfsoc_chipselect;
637 sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; 637 sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer;
638 sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; 638 sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer;
diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c
index 145dd435483b..9146bb3c2489 100644
--- a/drivers/spi/spi-tegra114.c
+++ b/drivers/spi/spi-tegra114.c
@@ -182,6 +182,7 @@ struct tegra_spi_data {
182 u32 cur_speed; 182 u32 cur_speed;
183 183
184 struct spi_device *cur_spi; 184 struct spi_device *cur_spi;
185 struct spi_device *cs_control;
185 unsigned cur_pos; 186 unsigned cur_pos;
186 unsigned cur_len; 187 unsigned cur_len;
187 unsigned words_per_32bit; 188 unsigned words_per_32bit;
@@ -267,7 +268,7 @@ static unsigned tegra_spi_calculate_curr_xfer_param(
267 unsigned max_len; 268 unsigned max_len;
268 unsigned total_fifo_words; 269 unsigned total_fifo_words;
269 270
270 tspi->bytes_per_word = (bits_per_word - 1) / 8 + 1; 271 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8);
271 272
272 if (bits_per_word == 8 || bits_per_word == 16) { 273 if (bits_per_word == 8 || bits_per_word == 16) {
273 tspi->is_packed = 1; 274 tspi->is_packed = 1;
@@ -676,15 +677,12 @@ static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi,
676 dma_release_channel(dma_chan); 677 dma_release_channel(dma_chan);
677} 678}
678 679
679static int tegra_spi_start_transfer_one(struct spi_device *spi, 680static unsigned long tegra_spi_setup_transfer_one(struct spi_device *spi,
680 struct spi_transfer *t, bool is_first_of_msg, 681 struct spi_transfer *t, bool is_first_of_msg)
681 bool is_single_xfer)
682{ 682{
683 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); 683 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
684 u32 speed = t->speed_hz; 684 u32 speed = t->speed_hz;
685 u8 bits_per_word = t->bits_per_word; 685 u8 bits_per_word = t->bits_per_word;
686 unsigned total_fifo_words;
687 int ret;
688 unsigned long command1; 686 unsigned long command1;
689 int req_mode; 687 int req_mode;
690 688
@@ -698,7 +696,6 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi,
698 tspi->cur_rx_pos = 0; 696 tspi->cur_rx_pos = 0;
699 tspi->cur_tx_pos = 0; 697 tspi->cur_tx_pos = 0;
700 tspi->curr_xfer = t; 698 tspi->curr_xfer = t;
701 total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t);
702 699
703 if (is_first_of_msg) { 700 if (is_first_of_msg) {
704 tegra_spi_clear_status(tspi); 701 tegra_spi_clear_status(tspi);
@@ -717,7 +714,12 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi,
717 else if (req_mode == SPI_MODE_3) 714 else if (req_mode == SPI_MODE_3)
718 command1 |= SPI_CONTROL_MODE_3; 715 command1 |= SPI_CONTROL_MODE_3;
719 716
720 tegra_spi_writel(tspi, command1, SPI_COMMAND1); 717 if (tspi->cs_control) {
718 if (tspi->cs_control != spi)
719 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
720 tspi->cs_control = NULL;
721 } else
722 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
721 723
722 command1 |= SPI_CS_SW_HW; 724 command1 |= SPI_CS_SW_HW;
723 if (spi->mode & SPI_CS_HIGH) 725 if (spi->mode & SPI_CS_HIGH)
@@ -732,6 +734,18 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi,
732 command1 |= SPI_BIT_LENGTH(bits_per_word - 1); 734 command1 |= SPI_BIT_LENGTH(bits_per_word - 1);
733 } 735 }
734 736
737 return command1;
738}
739
740static int tegra_spi_start_transfer_one(struct spi_device *spi,
741 struct spi_transfer *t, unsigned long command1)
742{
743 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
744 unsigned total_fifo_words;
745 int ret;
746
747 total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t);
748
735 if (tspi->is_packed) 749 if (tspi->is_packed)
736 command1 |= SPI_PACKED; 750 command1 |= SPI_PACKED;
737 751
@@ -803,29 +817,50 @@ static int tegra_spi_setup(struct spi_device *spi)
803 return 0; 817 return 0;
804} 818}
805 819
820static void tegra_spi_transfer_delay(int delay)
821{
822 if (!delay)
823 return;
824
825 if (delay >= 1000)
826 mdelay(delay / 1000);
827
828 udelay(delay % 1000);
829}
830
806static int tegra_spi_transfer_one_message(struct spi_master *master, 831static int tegra_spi_transfer_one_message(struct spi_master *master,
807 struct spi_message *msg) 832 struct spi_message *msg)
808{ 833{
809 bool is_first_msg = true; 834 bool is_first_msg = true;
810 int single_xfer;
811 struct tegra_spi_data *tspi = spi_master_get_devdata(master); 835 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
812 struct spi_transfer *xfer; 836 struct spi_transfer *xfer;
813 struct spi_device *spi = msg->spi; 837 struct spi_device *spi = msg->spi;
814 int ret; 838 int ret;
839 bool skip = false;
815 840
816 msg->status = 0; 841 msg->status = 0;
817 msg->actual_length = 0; 842 msg->actual_length = 0;
818 843
819 single_xfer = list_is_singular(&msg->transfers);
820 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 844 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
845 unsigned long cmd1;
846
821 INIT_COMPLETION(tspi->xfer_completion); 847 INIT_COMPLETION(tspi->xfer_completion);
822 ret = tegra_spi_start_transfer_one(spi, xfer, 848
823 is_first_msg, single_xfer); 849 cmd1 = tegra_spi_setup_transfer_one(spi, xfer, is_first_msg);
850
851 if (!xfer->len) {
852 ret = 0;
853 skip = true;
854 goto complete_xfer;
855 }
856
857 ret = tegra_spi_start_transfer_one(spi, xfer, cmd1);
824 if (ret < 0) { 858 if (ret < 0) {
825 dev_err(tspi->dev, 859 dev_err(tspi->dev,
826 "spi can not start transfer, err %d\n", ret); 860 "spi can not start transfer, err %d\n", ret);
827 goto exit; 861 goto complete_xfer;
828 } 862 }
863
829 is_first_msg = false; 864 is_first_msg = false;
830 ret = wait_for_completion_timeout(&tspi->xfer_completion, 865 ret = wait_for_completion_timeout(&tspi->xfer_completion,
831 SPI_DMA_TIMEOUT); 866 SPI_DMA_TIMEOUT);
@@ -833,24 +868,40 @@ static int tegra_spi_transfer_one_message(struct spi_master *master,
833 dev_err(tspi->dev, 868 dev_err(tspi->dev,
834 "spi trasfer timeout, err %d\n", ret); 869 "spi trasfer timeout, err %d\n", ret);
835 ret = -EIO; 870 ret = -EIO;
836 goto exit; 871 goto complete_xfer;
837 } 872 }
838 873
839 if (tspi->tx_status || tspi->rx_status) { 874 if (tspi->tx_status || tspi->rx_status) {
840 dev_err(tspi->dev, "Error in Transfer\n"); 875 dev_err(tspi->dev, "Error in Transfer\n");
841 ret = -EIO; 876 ret = -EIO;
842 goto exit; 877 goto complete_xfer;
843 } 878 }
844 msg->actual_length += xfer->len; 879 msg->actual_length += xfer->len;
845 if (xfer->cs_change && xfer->delay_usecs) { 880
881complete_xfer:
882 if (ret < 0 || skip) {
846 tegra_spi_writel(tspi, tspi->def_command1_reg, 883 tegra_spi_writel(tspi, tspi->def_command1_reg,
847 SPI_COMMAND1); 884 SPI_COMMAND1);
848 udelay(xfer->delay_usecs); 885 tegra_spi_transfer_delay(xfer->delay_usecs);
886 goto exit;
887 } else if (msg->transfers.prev == &xfer->transfer_list) {
888 /* This is the last transfer in message */
889 if (xfer->cs_change)
890 tspi->cs_control = spi;
891 else {
892 tegra_spi_writel(tspi, tspi->def_command1_reg,
893 SPI_COMMAND1);
894 tegra_spi_transfer_delay(xfer->delay_usecs);
895 }
896 } else if (xfer->cs_change) {
897 tegra_spi_writel(tspi, tspi->def_command1_reg,
898 SPI_COMMAND1);
899 tegra_spi_transfer_delay(xfer->delay_usecs);
849 } 900 }
901
850 } 902 }
851 ret = 0; 903 ret = 0;
852exit: 904exit:
853 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
854 msg->status = ret; 905 msg->status = ret;
855 spi_finalize_current_message(master); 906 spi_finalize_current_message(master);
856 return ret; 907 return ret;
@@ -1115,7 +1166,7 @@ static int tegra_spi_probe(struct platform_device *pdev)
1115 pm_runtime_put(&pdev->dev); 1166 pm_runtime_put(&pdev->dev);
1116 1167
1117 master->dev.of_node = pdev->dev.of_node; 1168 master->dev.of_node = pdev->dev.of_node;
1118 ret = spi_register_master(master); 1169 ret = devm_spi_register_master(&pdev->dev, master);
1119 if (ret < 0) { 1170 if (ret < 0) {
1120 dev_err(&pdev->dev, "can not register to master err %d\n", ret); 1171 dev_err(&pdev->dev, "can not register to master err %d\n", ret);
1121 goto exit_pm_disable; 1172 goto exit_pm_disable;
@@ -1142,7 +1193,6 @@ static int tegra_spi_remove(struct platform_device *pdev)
1142 struct tegra_spi_data *tspi = spi_master_get_devdata(master); 1193 struct tegra_spi_data *tspi = spi_master_get_devdata(master);
1143 1194
1144 free_irq(tspi->irq, tspi); 1195 free_irq(tspi->irq, tspi);
1145 spi_unregister_master(master);
1146 1196
1147 if (tspi->tx_dma_chan) 1197 if (tspi->tx_dma_chan)
1148 tegra_spi_deinit_dma_param(tspi, false); 1198 tegra_spi_deinit_dma_param(tspi, false);
diff --git a/drivers/spi/spi-tegra20-sflash.c b/drivers/spi/spi-tegra20-sflash.c
index 1d814dc6e000..79be8ce6a9d1 100644
--- a/drivers/spi/spi-tegra20-sflash.c
+++ b/drivers/spi/spi-tegra20-sflash.c
@@ -173,7 +173,7 @@ static unsigned tegra_sflash_calculate_curr_xfer_param(
173 unsigned remain_len = t->len - tsd->cur_pos; 173 unsigned remain_len = t->len - tsd->cur_pos;
174 unsigned max_word; 174 unsigned max_word;
175 175
176 tsd->bytes_per_word = (t->bits_per_word - 1) / 8 + 1; 176 tsd->bytes_per_word = DIV_ROUND_UP(t->bits_per_word, 8);
177 max_word = remain_len / tsd->bytes_per_word; 177 max_word = remain_len / tsd->bytes_per_word;
178 if (max_word > SPI_FIFO_DEPTH) 178 if (max_word > SPI_FIFO_DEPTH)
179 max_word = SPI_FIFO_DEPTH; 179 max_word = SPI_FIFO_DEPTH;
@@ -529,7 +529,7 @@ static int tegra_sflash_probe(struct platform_device *pdev)
529 pm_runtime_put(&pdev->dev); 529 pm_runtime_put(&pdev->dev);
530 530
531 master->dev.of_node = pdev->dev.of_node; 531 master->dev.of_node = pdev->dev.of_node;
532 ret = spi_register_master(master); 532 ret = devm_spi_register_master(&pdev->dev, master);
533 if (ret < 0) { 533 if (ret < 0) {
534 dev_err(&pdev->dev, "can not register to master err %d\n", ret); 534 dev_err(&pdev->dev, "can not register to master err %d\n", ret);
535 goto exit_pm_disable; 535 goto exit_pm_disable;
@@ -553,7 +553,6 @@ static int tegra_sflash_remove(struct platform_device *pdev)
553 struct tegra_sflash_data *tsd = spi_master_get_devdata(master); 553 struct tegra_sflash_data *tsd = spi_master_get_devdata(master);
554 554
555 free_irq(tsd->irq, tsd); 555 free_irq(tsd->irq, tsd);
556 spi_unregister_master(master);
557 556
558 pm_runtime_disable(&pdev->dev); 557 pm_runtime_disable(&pdev->dev);
559 if (!pm_runtime_status_suspended(&pdev->dev)) 558 if (!pm_runtime_status_suspended(&pdev->dev))
diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c
index c70353672a23..af0a67886ae8 100644
--- a/drivers/spi/spi-tegra20-slink.c
+++ b/drivers/spi/spi-tegra20-slink.c
@@ -278,12 +278,12 @@ static unsigned tegra_slink_calculate_curr_xfer_param(
278{ 278{
279 unsigned remain_len = t->len - tspi->cur_pos; 279 unsigned remain_len = t->len - tspi->cur_pos;
280 unsigned max_word; 280 unsigned max_word;
281 unsigned bits_per_word ; 281 unsigned bits_per_word;
282 unsigned max_len; 282 unsigned max_len;
283 unsigned total_fifo_words; 283 unsigned total_fifo_words;
284 284
285 bits_per_word = t->bits_per_word; 285 bits_per_word = t->bits_per_word;
286 tspi->bytes_per_word = (bits_per_word - 1) / 8 + 1; 286 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8);
287 287
288 if (bits_per_word == 8 || bits_per_word == 16) { 288 if (bits_per_word == 8 || bits_per_word == 16) {
289 tspi->is_packed = 1; 289 tspi->is_packed = 1;
@@ -707,8 +707,7 @@ static void tegra_slink_deinit_dma_param(struct tegra_slink_data *tspi,
707} 707}
708 708
709static int tegra_slink_start_transfer_one(struct spi_device *spi, 709static int tegra_slink_start_transfer_one(struct spi_device *spi,
710 struct spi_transfer *t, bool is_first_of_msg, 710 struct spi_transfer *t)
711 bool is_single_xfer)
712{ 711{
713 struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master); 712 struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master);
714 u32 speed; 713 u32 speed;
@@ -732,32 +731,12 @@ static int tegra_slink_start_transfer_one(struct spi_device *spi,
732 tspi->curr_xfer = t; 731 tspi->curr_xfer = t;
733 total_fifo_words = tegra_slink_calculate_curr_xfer_param(spi, tspi, t); 732 total_fifo_words = tegra_slink_calculate_curr_xfer_param(spi, tspi, t);
734 733
735 if (is_first_of_msg) { 734 command = tspi->command_reg;
736 tegra_slink_clear_status(tspi); 735 command &= ~SLINK_BIT_LENGTH(~0);
736 command |= SLINK_BIT_LENGTH(bits_per_word - 1);
737 737
738 command = tspi->def_command_reg; 738 command2 = tspi->command2_reg;
739 command |= SLINK_BIT_LENGTH(bits_per_word - 1); 739 command2 &= ~(SLINK_RXEN | SLINK_TXEN);
740 command |= SLINK_CS_SW | SLINK_CS_VALUE;
741
742 command2 = tspi->def_command2_reg;
743 command2 |= SLINK_SS_EN_CS(spi->chip_select);
744
745 command &= ~SLINK_MODES;
746 if (spi->mode & SPI_CPHA)
747 command |= SLINK_CK_SDA;
748
749 if (spi->mode & SPI_CPOL)
750 command |= SLINK_IDLE_SCLK_DRIVE_HIGH;
751 else
752 command |= SLINK_IDLE_SCLK_DRIVE_LOW;
753 } else {
754 command = tspi->command_reg;
755 command &= ~SLINK_BIT_LENGTH(~0);
756 command |= SLINK_BIT_LENGTH(bits_per_word - 1);
757
758 command2 = tspi->command2_reg;
759 command2 &= ~(SLINK_RXEN | SLINK_TXEN);
760 }
761 740
762 tegra_slink_writel(tspi, command, SLINK_COMMAND); 741 tegra_slink_writel(tspi, command, SLINK_COMMAND);
763 tspi->command_reg = command; 742 tspi->command_reg = command;
@@ -824,58 +803,72 @@ static int tegra_slink_setup(struct spi_device *spi)
824 return 0; 803 return 0;
825} 804}
826 805
827static int tegra_slink_transfer_one_message(struct spi_master *master, 806static int tegra_slink_prepare_message(struct spi_master *master,
828 struct spi_message *msg) 807 struct spi_message *msg)
829{ 808{
830 bool is_first_msg = true;
831 int single_xfer;
832 struct tegra_slink_data *tspi = spi_master_get_devdata(master); 809 struct tegra_slink_data *tspi = spi_master_get_devdata(master);
833 struct spi_transfer *xfer;
834 struct spi_device *spi = msg->spi; 810 struct spi_device *spi = msg->spi;
835 int ret;
836 811
837 msg->status = 0; 812 tegra_slink_clear_status(tspi);
838 msg->actual_length = 0;
839 813
840 single_xfer = list_is_singular(&msg->transfers); 814 tspi->command_reg = tspi->def_command_reg;
841 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 815 tspi->command_reg |= SLINK_CS_SW | SLINK_CS_VALUE;
842 INIT_COMPLETION(tspi->xfer_completion);
843 ret = tegra_slink_start_transfer_one(spi, xfer,
844 is_first_msg, single_xfer);
845 if (ret < 0) {
846 dev_err(tspi->dev,
847 "spi can not start transfer, err %d\n", ret);
848 goto exit;
849 }
850 is_first_msg = false;
851 ret = wait_for_completion_timeout(&tspi->xfer_completion,
852 SLINK_DMA_TIMEOUT);
853 if (WARN_ON(ret == 0)) {
854 dev_err(tspi->dev,
855 "spi trasfer timeout, err %d\n", ret);
856 ret = -EIO;
857 goto exit;
858 }
859 816
860 if (tspi->tx_status || tspi->rx_status) { 817 tspi->command2_reg = tspi->def_command2_reg;
861 dev_err(tspi->dev, "Error in Transfer\n"); 818 tspi->command2_reg |= SLINK_SS_EN_CS(spi->chip_select);
862 ret = -EIO; 819
863 goto exit; 820 tspi->command_reg &= ~SLINK_MODES;
864 } 821 if (spi->mode & SPI_CPHA)
865 msg->actual_length += xfer->len; 822 tspi->command_reg |= SLINK_CK_SDA;
866 if (xfer->cs_change && xfer->delay_usecs) { 823
867 tegra_slink_writel(tspi, tspi->def_command_reg, 824 if (spi->mode & SPI_CPOL)
868 SLINK_COMMAND); 825 tspi->command_reg |= SLINK_IDLE_SCLK_DRIVE_HIGH;
869 udelay(xfer->delay_usecs); 826 else
870 } 827 tspi->command_reg |= SLINK_IDLE_SCLK_DRIVE_LOW;
828
829 return 0;
830}
831
832static int tegra_slink_transfer_one(struct spi_master *master,
833 struct spi_device *spi,
834 struct spi_transfer *xfer)
835{
836 struct tegra_slink_data *tspi = spi_master_get_devdata(master);
837 int ret;
838
839 INIT_COMPLETION(tspi->xfer_completion);
840 ret = tegra_slink_start_transfer_one(spi, xfer);
841 if (ret < 0) {
842 dev_err(tspi->dev,
843 "spi can not start transfer, err %d\n", ret);
844 return ret;
871 } 845 }
872 ret = 0; 846
873exit: 847 ret = wait_for_completion_timeout(&tspi->xfer_completion,
848 SLINK_DMA_TIMEOUT);
849 if (WARN_ON(ret == 0)) {
850 dev_err(tspi->dev,
851 "spi trasfer timeout, err %d\n", ret);
852 return -EIO;
853 }
854
855 if (tspi->tx_status)
856 return tspi->tx_status;
857 if (tspi->rx_status)
858 return tspi->rx_status;
859
860 return 0;
861}
862
863static int tegra_slink_unprepare_message(struct spi_master *master,
864 struct spi_message *msg)
865{
866 struct tegra_slink_data *tspi = spi_master_get_devdata(master);
867
874 tegra_slink_writel(tspi, tspi->def_command_reg, SLINK_COMMAND); 868 tegra_slink_writel(tspi, tspi->def_command_reg, SLINK_COMMAND);
875 tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2); 869 tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2);
876 msg->status = ret; 870
877 spi_finalize_current_message(master); 871 return 0;
878 return ret;
879} 872}
880 873
881static irqreturn_t handle_cpu_based_xfer(struct tegra_slink_data *tspi) 874static irqreturn_t handle_cpu_based_xfer(struct tegra_slink_data *tspi)
@@ -1078,7 +1071,9 @@ static int tegra_slink_probe(struct platform_device *pdev)
1078 /* the spi->mode bits understood by this driver: */ 1071 /* the spi->mode bits understood by this driver: */
1079 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 1072 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1080 master->setup = tegra_slink_setup; 1073 master->setup = tegra_slink_setup;
1081 master->transfer_one_message = tegra_slink_transfer_one_message; 1074 master->prepare_message = tegra_slink_prepare_message;
1075 master->transfer_one = tegra_slink_transfer_one;
1076 master->unprepare_message = tegra_slink_unprepare_message;
1082 master->auto_runtime_pm = true; 1077 master->auto_runtime_pm = true;
1083 master->num_chipselect = MAX_CHIP_SELECT; 1078 master->num_chipselect = MAX_CHIP_SELECT;
1084 master->bus_num = -1; 1079 master->bus_num = -1;
@@ -1164,7 +1159,7 @@ static int tegra_slink_probe(struct platform_device *pdev)
1164 pm_runtime_put(&pdev->dev); 1159 pm_runtime_put(&pdev->dev);
1165 1160
1166 master->dev.of_node = pdev->dev.of_node; 1161 master->dev.of_node = pdev->dev.of_node;
1167 ret = spi_register_master(master); 1162 ret = devm_spi_register_master(&pdev->dev, master);
1168 if (ret < 0) { 1163 if (ret < 0) {
1169 dev_err(&pdev->dev, "can not register to master err %d\n", ret); 1164 dev_err(&pdev->dev, "can not register to master err %d\n", ret);
1170 goto exit_pm_disable; 1165 goto exit_pm_disable;
@@ -1191,7 +1186,6 @@ static int tegra_slink_remove(struct platform_device *pdev)
1191 struct tegra_slink_data *tspi = spi_master_get_devdata(master); 1186 struct tegra_slink_data *tspi = spi_master_get_devdata(master);
1192 1187
1193 free_irq(tspi->irq, tspi); 1188 free_irq(tspi->irq, tspi);
1194 spi_unregister_master(master);
1195 1189
1196 if (tspi->tx_dma_chan) 1190 if (tspi->tx_dma_chan)
1197 tegra_slink_deinit_dma_param(tspi, false); 1191 tegra_slink_deinit_dma_param(tspi, false);
diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c
index e12d962a289f..0b71270fbf67 100644
--- a/drivers/spi/spi-ti-qspi.c
+++ b/drivers/spi/spi-ti-qspi.c
@@ -41,9 +41,6 @@ struct ti_qspi_regs {
41struct ti_qspi { 41struct ti_qspi {
42 struct completion transfer_complete; 42 struct completion transfer_complete;
43 43
44 /* IRQ synchronization */
45 spinlock_t lock;
46
47 /* list synchronization */ 44 /* list synchronization */
48 struct mutex list_lock; 45 struct mutex list_lock;
49 46
@@ -57,7 +54,6 @@ struct ti_qspi {
57 u32 spi_max_frequency; 54 u32 spi_max_frequency;
58 u32 cmd; 55 u32 cmd;
59 u32 dc; 56 u32 dc;
60 u32 stat;
61}; 57};
62 58
63#define QSPI_PID (0x0) 59#define QSPI_PID (0x0)
@@ -397,13 +393,12 @@ static irqreturn_t ti_qspi_isr(int irq, void *dev_id)
397{ 393{
398 struct ti_qspi *qspi = dev_id; 394 struct ti_qspi *qspi = dev_id;
399 u16 int_stat; 395 u16 int_stat;
396 u32 stat;
400 397
401 irqreturn_t ret = IRQ_HANDLED; 398 irqreturn_t ret = IRQ_HANDLED;
402 399
403 spin_lock(&qspi->lock);
404
405 int_stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR); 400 int_stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR);
406 qspi->stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); 401 stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG);
407 402
408 if (!int_stat) { 403 if (!int_stat) {
409 dev_dbg(qspi->dev, "No IRQ triggered\n"); 404 dev_dbg(qspi->dev, "No IRQ triggered\n");
@@ -411,35 +406,14 @@ static irqreturn_t ti_qspi_isr(int irq, void *dev_id)
411 goto out; 406 goto out;
412 } 407 }
413 408
414 ret = IRQ_WAKE_THREAD;
415
416 ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG);
417 ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, 409 ti_qspi_write(qspi, QSPI_WC_INT_DISABLE,
418 QSPI_INTR_STATUS_ENABLED_CLEAR); 410 QSPI_INTR_STATUS_ENABLED_CLEAR);
419 411 if (stat & WC)
412 complete(&qspi->transfer_complete);
420out: 413out:
421 spin_unlock(&qspi->lock);
422
423 return ret; 414 return ret;
424} 415}
425 416
426static irqreturn_t ti_qspi_threaded_isr(int this_irq, void *dev_id)
427{
428 struct ti_qspi *qspi = dev_id;
429 unsigned long flags;
430
431 spin_lock_irqsave(&qspi->lock, flags);
432
433 if (qspi->stat & WC)
434 complete(&qspi->transfer_complete);
435
436 spin_unlock_irqrestore(&qspi->lock, flags);
437
438 ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
439
440 return IRQ_HANDLED;
441}
442
443static int ti_qspi_runtime_resume(struct device *dev) 417static int ti_qspi_runtime_resume(struct device *dev)
444{ 418{
445 struct ti_qspi *qspi; 419 struct ti_qspi *qspi;
@@ -472,7 +446,7 @@ static int ti_qspi_probe(struct platform_device *pdev)
472 if (!master) 446 if (!master)
473 return -ENOMEM; 447 return -ENOMEM;
474 448
475 master->mode_bits = SPI_CPOL | SPI_CPHA; 449 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD;
476 450
477 master->bus_num = -1; 451 master->bus_num = -1;
478 master->flags = SPI_MASTER_HALF_DUPLEX; 452 master->flags = SPI_MASTER_HALF_DUPLEX;
@@ -499,7 +473,6 @@ static int ti_qspi_probe(struct platform_device *pdev)
499 return irq; 473 return irq;
500 } 474 }
501 475
502 spin_lock_init(&qspi->lock);
503 mutex_init(&qspi->list_lock); 476 mutex_init(&qspi->list_lock);
504 477
505 qspi->base = devm_ioremap_resource(&pdev->dev, r); 478 qspi->base = devm_ioremap_resource(&pdev->dev, r);
@@ -508,8 +481,7 @@ static int ti_qspi_probe(struct platform_device *pdev)
508 goto free_master; 481 goto free_master;
509 } 482 }
510 483
511 ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr, 484 ret = devm_request_irq(&pdev->dev, irq, ti_qspi_isr, 0,
512 ti_qspi_threaded_isr, 0,
513 dev_name(&pdev->dev), qspi); 485 dev_name(&pdev->dev), qspi);
514 if (ret < 0) { 486 if (ret < 0) {
515 dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", 487 dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
@@ -532,7 +504,7 @@ static int ti_qspi_probe(struct platform_device *pdev)
532 if (!of_property_read_u32(np, "spi-max-frequency", &max_freq)) 504 if (!of_property_read_u32(np, "spi-max-frequency", &max_freq))
533 qspi->spi_max_frequency = max_freq; 505 qspi->spi_max_frequency = max_freq;
534 506
535 ret = spi_register_master(master); 507 ret = devm_spi_register_master(&pdev->dev, master);
536 if (ret) 508 if (ret)
537 goto free_master; 509 goto free_master;
538 510
@@ -547,7 +519,7 @@ static int ti_qspi_remove(struct platform_device *pdev)
547{ 519{
548 struct ti_qspi *qspi = platform_get_drvdata(pdev); 520 struct ti_qspi *qspi = platform_get_drvdata(pdev);
549 521
550 spi_unregister_master(qspi->master); 522 ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG);
551 523
552 return 0; 524 return 0;
553} 525}
@@ -558,7 +530,7 @@ static const struct dev_pm_ops ti_qspi_pm_ops = {
558 530
559static struct platform_driver ti_qspi_driver = { 531static struct platform_driver ti_qspi_driver = {
560 .probe = ti_qspi_probe, 532 .probe = ti_qspi_probe,
561 .remove = ti_qspi_remove, 533 .remove = ti_qspi_remove,
562 .driver = { 534 .driver = {
563 .name = "ti,dra7xxx-qspi", 535 .name = "ti,dra7xxx-qspi",
564 .owner = THIS_MODULE, 536 .owner = THIS_MODULE,
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index eaeeed51bbbf..446131308acb 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -506,8 +506,8 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
506 goto err_out; 506 goto err_out;
507 } 507 }
508 508
509 dev_dbg(&pspi->dev, "%s Transfer List not empty. " 509 dev_dbg(&pspi->dev,
510 "Transfer Speed is set.\n", __func__); 510 "%s Transfer List not empty. Transfer Speed is set.\n", __func__);
511 511
512 spin_lock_irqsave(&data->lock, flags); 512 spin_lock_irqsave(&data->lock, flags);
513 /* validate Tx/Rx buffers and Transfer length */ 513 /* validate Tx/Rx buffers and Transfer length */
@@ -526,8 +526,9 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
526 goto err_return_spinlock; 526 goto err_return_spinlock;
527 } 527 }
528 528
529 dev_dbg(&pspi->dev, "%s Tx/Rx buffer valid. Transfer length" 529 dev_dbg(&pspi->dev,
530 " valid\n", __func__); 530 "%s Tx/Rx buffer valid. Transfer length valid\n",
531 __func__);
531 532
532 /* if baud rate has been specified validate the same */ 533 /* if baud rate has been specified validate the same */
533 if (transfer->speed_hz > PCH_MAX_BAUDRATE) 534 if (transfer->speed_hz > PCH_MAX_BAUDRATE)
@@ -1181,8 +1182,8 @@ static void pch_spi_process_messages(struct work_struct *pwork)
1181 spin_lock(&data->lock); 1182 spin_lock(&data->lock);
1182 /* check if suspend has been initiated;if yes flush queue */ 1183 /* check if suspend has been initiated;if yes flush queue */
1183 if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) { 1184 if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) {
1184 dev_dbg(&data->master->dev, "%s suspend/remove initiated," 1185 dev_dbg(&data->master->dev,
1185 "flushing queue\n", __func__); 1186 "%s suspend/remove initiated, flushing queue\n", __func__);
1186 list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { 1187 list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) {
1187 pmsg->status = -EIO; 1188 pmsg->status = -EIO;
1188 1189
@@ -1410,13 +1411,13 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
1410 /* baseaddress + address offset) */ 1411 /* baseaddress + address offset) */
1411 data->io_base_addr = pci_resource_start(board_dat->pdev, 1) + 1412 data->io_base_addr = pci_resource_start(board_dat->pdev, 1) +
1412 PCH_ADDRESS_SIZE * plat_dev->id; 1413 PCH_ADDRESS_SIZE * plat_dev->id;
1413 data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0) + 1414 data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0);
1414 PCH_ADDRESS_SIZE * plat_dev->id;
1415 if (!data->io_remap_addr) { 1415 if (!data->io_remap_addr) {
1416 dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__); 1416 dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__);
1417 ret = -ENOMEM; 1417 ret = -ENOMEM;
1418 goto err_pci_iomap; 1418 goto err_pci_iomap;
1419 } 1419 }
1420 data->io_remap_addr += PCH_ADDRESS_SIZE * plat_dev->id;
1420 1421
1421 dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n", 1422 dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n",
1422 plat_dev->id, data->io_remap_addr); 1423 plat_dev->id, data->io_remap_addr);
diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c
index 017139bdec99..637cce2b8bdd 100644
--- a/drivers/spi/spi-txx9.c
+++ b/drivers/spi/spi-txx9.c
@@ -406,7 +406,7 @@ static int txx9spi_probe(struct platform_device *dev)
406 master->num_chipselect = (u16)UINT_MAX; /* any GPIO numbers */ 406 master->num_chipselect = (u16)UINT_MAX; /* any GPIO numbers */
407 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); 407 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
408 408
409 ret = spi_register_master(master); 409 ret = devm_spi_register_master(&dev->dev, master);
410 if (ret) 410 if (ret)
411 goto exit; 411 goto exit;
412 return 0; 412 return 0;
@@ -428,11 +428,9 @@ static int txx9spi_remove(struct platform_device *dev)
428 struct spi_master *master = spi_master_get(platform_get_drvdata(dev)); 428 struct spi_master *master = spi_master_get(platform_get_drvdata(dev));
429 struct txx9spi *c = spi_master_get_devdata(master); 429 struct txx9spi *c = spi_master_get_devdata(master);
430 430
431 spi_unregister_master(master);
432 destroy_workqueue(c->workqueue); 431 destroy_workqueue(c->workqueue);
433 clk_disable(c->clk); 432 clk_disable(c->clk);
434 clk_put(c->clk); 433 clk_put(c->clk);
435 spi_master_put(master);
436 return 0; 434 return 0;
437} 435}
438 436
@@ -440,6 +438,7 @@ static int txx9spi_remove(struct platform_device *dev)
440MODULE_ALIAS("platform:spi_txx9"); 438MODULE_ALIAS("platform:spi_txx9");
441 439
442static struct platform_driver txx9spi_driver = { 440static struct platform_driver txx9spi_driver = {
441 .probe = txx9spi_probe,
443 .remove = txx9spi_remove, 442 .remove = txx9spi_remove,
444 .driver = { 443 .driver = {
445 .name = "spi_txx9", 444 .name = "spi_txx9",
@@ -449,7 +448,7 @@ static struct platform_driver txx9spi_driver = {
449 448
450static int __init txx9spi_init(void) 449static int __init txx9spi_init(void)
451{ 450{
452 return platform_driver_probe(&txx9spi_driver, txx9spi_probe); 451 return platform_driver_register(&txx9spi_driver);
453} 452}
454subsys_initcall(txx9spi_init); 453subsys_initcall(txx9spi_init);
455 454
diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index 0bf1b2c457a1..ec3a83f52ea2 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -372,7 +372,7 @@ static int xilinx_spi_probe(struct platform_device *pdev)
372 master->mode_bits = SPI_CPOL | SPI_CPHA; 372 master->mode_bits = SPI_CPOL | SPI_CPHA;
373 373
374 xspi = spi_master_get_devdata(master); 374 xspi = spi_master_get_devdata(master);
375 xspi->bitbang.master = spi_master_get(master); 375 xspi->bitbang.master = master;
376 xspi->bitbang.chipselect = xilinx_spi_chipselect; 376 xspi->bitbang.chipselect = xilinx_spi_chipselect;
377 xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer; 377 xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer;
378 xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs; 378 xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 9e039c60c068..8d05accf706c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -39,6 +39,9 @@
39#include <linux/ioport.h> 39#include <linux/ioport.h>
40#include <linux/acpi.h> 40#include <linux/acpi.h>
41 41
42#define CREATE_TRACE_POINTS
43#include <trace/events/spi.h>
44
42static void spidev_release(struct device *dev) 45static void spidev_release(struct device *dev)
43{ 46{
44 struct spi_device *spi = to_spi_device(dev); 47 struct spi_device *spi = to_spi_device(dev);
@@ -58,11 +61,13 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
58 61
59 return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias); 62 return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias);
60} 63}
64static DEVICE_ATTR_RO(modalias);
61 65
62static struct device_attribute spi_dev_attrs[] = { 66static struct attribute *spi_dev_attrs[] = {
63 __ATTR_RO(modalias), 67 &dev_attr_modalias.attr,
64 __ATTR_NULL, 68 NULL,
65}; 69};
70ATTRIBUTE_GROUPS(spi_dev);
66 71
67/* modalias support makes "modprobe $MODALIAS" new-style hotplug work, 72/* modalias support makes "modprobe $MODALIAS" new-style hotplug work,
68 * and the sysfs version makes coldplug work too. 73 * and the sysfs version makes coldplug work too.
@@ -229,7 +234,7 @@ static const struct dev_pm_ops spi_pm = {
229 234
230struct bus_type spi_bus_type = { 235struct bus_type spi_bus_type = {
231 .name = "spi", 236 .name = "spi",
232 .dev_attrs = spi_dev_attrs, 237 .dev_groups = spi_dev_groups,
233 .match = spi_match_device, 238 .match = spi_match_device,
234 .uevent = spi_uevent, 239 .uevent = spi_uevent,
235 .pm = &spi_pm, 240 .pm = &spi_pm,
@@ -323,7 +328,7 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
323 if (!spi_master_get(master)) 328 if (!spi_master_get(master))
324 return NULL; 329 return NULL;
325 330
326 spi = kzalloc(sizeof *spi, GFP_KERNEL); 331 spi = kzalloc(sizeof(*spi), GFP_KERNEL);
327 if (!spi) { 332 if (!spi) {
328 dev_err(dev, "cannot alloc spi_device\n"); 333 dev_err(dev, "cannot alloc spi_device\n");
329 spi_master_put(master); 334 spi_master_put(master);
@@ -523,6 +528,95 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
523 528
524/*-------------------------------------------------------------------------*/ 529/*-------------------------------------------------------------------------*/
525 530
531static void spi_set_cs(struct spi_device *spi, bool enable)
532{
533 if (spi->mode & SPI_CS_HIGH)
534 enable = !enable;
535
536 if (spi->cs_gpio >= 0)
537 gpio_set_value(spi->cs_gpio, !enable);
538 else if (spi->master->set_cs)
539 spi->master->set_cs(spi, !enable);
540}
541
542/*
543 * spi_transfer_one_message - Default implementation of transfer_one_message()
544 *
545 * This is a standard implementation of transfer_one_message() for
546 * drivers which impelment a transfer_one() operation. It provides
547 * standard handling of delays and chip select management.
548 */
549static int spi_transfer_one_message(struct spi_master *master,
550 struct spi_message *msg)
551{
552 struct spi_transfer *xfer;
553 bool cur_cs = true;
554 bool keep_cs = false;
555 int ret = 0;
556
557 spi_set_cs(msg->spi, true);
558
559 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
560 trace_spi_transfer_start(msg, xfer);
561
562 INIT_COMPLETION(master->xfer_completion);
563
564 ret = master->transfer_one(master, msg->spi, xfer);
565 if (ret < 0) {
566 dev_err(&msg->spi->dev,
567 "SPI transfer failed: %d\n", ret);
568 goto out;
569 }
570
571 if (ret > 0)
572 wait_for_completion(&master->xfer_completion);
573
574 trace_spi_transfer_stop(msg, xfer);
575
576 if (msg->status != -EINPROGRESS)
577 goto out;
578
579 if (xfer->delay_usecs)
580 udelay(xfer->delay_usecs);
581
582 if (xfer->cs_change) {
583 if (list_is_last(&xfer->transfer_list,
584 &msg->transfers)) {
585 keep_cs = true;
586 } else {
587 cur_cs = !cur_cs;
588 spi_set_cs(msg->spi, cur_cs);
589 }
590 }
591
592 msg->actual_length += xfer->len;
593 }
594
595out:
596 if (ret != 0 || !keep_cs)
597 spi_set_cs(msg->spi, false);
598
599 if (msg->status == -EINPROGRESS)
600 msg->status = ret;
601
602 spi_finalize_current_message(master);
603
604 return ret;
605}
606
607/**
608 * spi_finalize_current_transfer - report completion of a transfer
609 *
610 * Called by SPI drivers using the core transfer_one_message()
611 * implementation to notify it that the current interrupt driven
612 * transfer has finised and the next one may be scheduled.
613 */
614void spi_finalize_current_transfer(struct spi_master *master)
615{
616 complete(&master->xfer_completion);
617}
618EXPORT_SYMBOL_GPL(spi_finalize_current_transfer);
619
526/** 620/**
527 * spi_pump_messages - kthread work function which processes spi message queue 621 * spi_pump_messages - kthread work function which processes spi message queue
528 * @work: pointer to kthread work struct contained in the master struct 622 * @work: pointer to kthread work struct contained in the master struct
@@ -557,6 +651,7 @@ static void spi_pump_messages(struct kthread_work *work)
557 pm_runtime_mark_last_busy(master->dev.parent); 651 pm_runtime_mark_last_busy(master->dev.parent);
558 pm_runtime_put_autosuspend(master->dev.parent); 652 pm_runtime_put_autosuspend(master->dev.parent);
559 } 653 }
654 trace_spi_master_idle(master);
560 return; 655 return;
561 } 656 }
562 657
@@ -585,6 +680,9 @@ static void spi_pump_messages(struct kthread_work *work)
585 } 680 }
586 } 681 }
587 682
683 if (!was_busy)
684 trace_spi_master_busy(master);
685
588 if (!was_busy && master->prepare_transfer_hardware) { 686 if (!was_busy && master->prepare_transfer_hardware) {
589 ret = master->prepare_transfer_hardware(master); 687 ret = master->prepare_transfer_hardware(master);
590 if (ret) { 688 if (ret) {
@@ -597,6 +695,20 @@ static void spi_pump_messages(struct kthread_work *work)
597 } 695 }
598 } 696 }
599 697
698 trace_spi_message_start(master->cur_msg);
699
700 if (master->prepare_message) {
701 ret = master->prepare_message(master, master->cur_msg);
702 if (ret) {
703 dev_err(&master->dev,
704 "failed to prepare message: %d\n", ret);
705 master->cur_msg->status = ret;
706 spi_finalize_current_message(master);
707 return;
708 }
709 master->cur_msg_prepared = true;
710 }
711
600 ret = master->transfer_one_message(master, master->cur_msg); 712 ret = master->transfer_one_message(master, master->cur_msg);
601 if (ret) { 713 if (ret) {
602 dev_err(&master->dev, 714 dev_err(&master->dev,
@@ -678,6 +790,7 @@ void spi_finalize_current_message(struct spi_master *master)
678{ 790{
679 struct spi_message *mesg; 791 struct spi_message *mesg;
680 unsigned long flags; 792 unsigned long flags;
793 int ret;
681 794
682 spin_lock_irqsave(&master->queue_lock, flags); 795 spin_lock_irqsave(&master->queue_lock, flags);
683 mesg = master->cur_msg; 796 mesg = master->cur_msg;
@@ -686,9 +799,20 @@ void spi_finalize_current_message(struct spi_master *master)
686 queue_kthread_work(&master->kworker, &master->pump_messages); 799 queue_kthread_work(&master->kworker, &master->pump_messages);
687 spin_unlock_irqrestore(&master->queue_lock, flags); 800 spin_unlock_irqrestore(&master->queue_lock, flags);
688 801
802 if (master->cur_msg_prepared && master->unprepare_message) {
803 ret = master->unprepare_message(master, mesg);
804 if (ret) {
805 dev_err(&master->dev,
806 "failed to unprepare message: %d\n", ret);
807 }
808 }
809 master->cur_msg_prepared = false;
810
689 mesg->state = NULL; 811 mesg->state = NULL;
690 if (mesg->complete) 812 if (mesg->complete)
691 mesg->complete(mesg->context); 813 mesg->complete(mesg->context);
814
815 trace_spi_message_done(mesg);
692} 816}
693EXPORT_SYMBOL_GPL(spi_finalize_current_message); 817EXPORT_SYMBOL_GPL(spi_finalize_current_message);
694 818
@@ -803,6 +927,8 @@ static int spi_master_initialize_queue(struct spi_master *master)
803 927
804 master->queued = true; 928 master->queued = true;
805 master->transfer = spi_queued_transfer; 929 master->transfer = spi_queued_transfer;
930 if (!master->transfer_one_message)
931 master->transfer_one_message = spi_transfer_one_message;
806 932
807 /* Initialize and start queue */ 933 /* Initialize and start queue */
808 ret = spi_init_queue(master); 934 ret = spi_init_queue(master);
@@ -838,10 +964,8 @@ static void of_register_spi_devices(struct spi_master *master)
838{ 964{
839 struct spi_device *spi; 965 struct spi_device *spi;
840 struct device_node *nc; 966 struct device_node *nc;
841 const __be32 *prop;
842 char modalias[SPI_NAME_SIZE + 4];
843 int rc; 967 int rc;
844 int len; 968 u32 value;
845 969
846 if (!master->dev.of_node) 970 if (!master->dev.of_node)
847 return; 971 return;
@@ -866,14 +990,14 @@ static void of_register_spi_devices(struct spi_master *master)
866 } 990 }
867 991
868 /* Device address */ 992 /* Device address */
869 prop = of_get_property(nc, "reg", &len); 993 rc = of_property_read_u32(nc, "reg", &value);
870 if (!prop || len < sizeof(*prop)) { 994 if (rc) {
871 dev_err(&master->dev, "%s has no 'reg' property\n", 995 dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n",
872 nc->full_name); 996 nc->full_name, rc);
873 spi_dev_put(spi); 997 spi_dev_put(spi);
874 continue; 998 continue;
875 } 999 }
876 spi->chip_select = be32_to_cpup(prop); 1000 spi->chip_select = value;
877 1001
878 /* Mode (clock phase/polarity/etc.) */ 1002 /* Mode (clock phase/polarity/etc.) */
879 if (of_find_property(nc, "spi-cpha", NULL)) 1003 if (of_find_property(nc, "spi-cpha", NULL))
@@ -886,55 +1010,53 @@ static void of_register_spi_devices(struct spi_master *master)
886 spi->mode |= SPI_3WIRE; 1010 spi->mode |= SPI_3WIRE;
887 1011
888 /* Device DUAL/QUAD mode */ 1012 /* Device DUAL/QUAD mode */
889 prop = of_get_property(nc, "spi-tx-bus-width", &len); 1013 if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
890 if (prop && len == sizeof(*prop)) { 1014 switch (value) {
891 switch (be32_to_cpup(prop)) { 1015 case 1:
892 case SPI_NBITS_SINGLE:
893 break; 1016 break;
894 case SPI_NBITS_DUAL: 1017 case 2:
895 spi->mode |= SPI_TX_DUAL; 1018 spi->mode |= SPI_TX_DUAL;
896 break; 1019 break;
897 case SPI_NBITS_QUAD: 1020 case 4:
898 spi->mode |= SPI_TX_QUAD; 1021 spi->mode |= SPI_TX_QUAD;
899 break; 1022 break;
900 default: 1023 default:
901 dev_err(&master->dev, 1024 dev_err(&master->dev,
902 "spi-tx-bus-width %d not supported\n", 1025 "spi-tx-bus-width %d not supported\n",
903 be32_to_cpup(prop)); 1026 value);
904 spi_dev_put(spi); 1027 spi_dev_put(spi);
905 continue; 1028 continue;
906 } 1029 }
907 } 1030 }
908 1031
909 prop = of_get_property(nc, "spi-rx-bus-width", &len); 1032 if (!of_property_read_u32(nc, "spi-rx-bus-width", &value)) {
910 if (prop && len == sizeof(*prop)) { 1033 switch (value) {
911 switch (be32_to_cpup(prop)) { 1034 case 1:
912 case SPI_NBITS_SINGLE:
913 break; 1035 break;
914 case SPI_NBITS_DUAL: 1036 case 2:
915 spi->mode |= SPI_RX_DUAL; 1037 spi->mode |= SPI_RX_DUAL;
916 break; 1038 break;
917 case SPI_NBITS_QUAD: 1039 case 4:
918 spi->mode |= SPI_RX_QUAD; 1040 spi->mode |= SPI_RX_QUAD;
919 break; 1041 break;
920 default: 1042 default:
921 dev_err(&master->dev, 1043 dev_err(&master->dev,
922 "spi-rx-bus-width %d not supported\n", 1044 "spi-rx-bus-width %d not supported\n",
923 be32_to_cpup(prop)); 1045 value);
924 spi_dev_put(spi); 1046 spi_dev_put(spi);
925 continue; 1047 continue;
926 } 1048 }
927 } 1049 }
928 1050
929 /* Device speed */ 1051 /* Device speed */
930 prop = of_get_property(nc, "spi-max-frequency", &len); 1052 rc = of_property_read_u32(nc, "spi-max-frequency", &value);
931 if (!prop || len < sizeof(*prop)) { 1053 if (rc) {
932 dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n", 1054 dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n",
933 nc->full_name); 1055 nc->full_name, rc);
934 spi_dev_put(spi); 1056 spi_dev_put(spi);
935 continue; 1057 continue;
936 } 1058 }
937 spi->max_speed_hz = be32_to_cpup(prop); 1059 spi->max_speed_hz = value;
938 1060
939 /* IRQ */ 1061 /* IRQ */
940 spi->irq = irq_of_parse_and_map(nc, 0); 1062 spi->irq = irq_of_parse_and_map(nc, 0);
@@ -944,9 +1066,7 @@ static void of_register_spi_devices(struct spi_master *master)
944 spi->dev.of_node = nc; 1066 spi->dev.of_node = nc;
945 1067
946 /* Register the new device */ 1068 /* Register the new device */
947 snprintf(modalias, sizeof(modalias), "%s%s", SPI_MODULE_PREFIX, 1069 request_module("%s%s", SPI_MODULE_PREFIX, spi->modalias);
948 spi->modalias);
949 request_module(modalias);
950 rc = spi_add_device(spi); 1070 rc = spi_add_device(spi);
951 if (rc) { 1071 if (rc) {
952 dev_err(&master->dev, "spi_device register error %s\n", 1072 dev_err(&master->dev, "spi_device register error %s\n",
@@ -1025,7 +1145,7 @@ static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level,
1025 return AE_OK; 1145 return AE_OK;
1026 } 1146 }
1027 1147
1028 strlcpy(spi->modalias, dev_name(&adev->dev), sizeof(spi->modalias)); 1148 strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias));
1029 if (spi_add_device(spi)) { 1149 if (spi_add_device(spi)) {
1030 dev_err(&master->dev, "failed to add SPI device %s from ACPI\n", 1150 dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",
1031 dev_name(&adev->dev)); 1151 dev_name(&adev->dev));
@@ -1097,7 +1217,7 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
1097 if (!dev) 1217 if (!dev)
1098 return NULL; 1218 return NULL;
1099 1219
1100 master = kzalloc(size + sizeof *master, GFP_KERNEL); 1220 master = kzalloc(size + sizeof(*master), GFP_KERNEL);
1101 if (!master) 1221 if (!master)
1102 return NULL; 1222 return NULL;
1103 1223
@@ -1122,7 +1242,7 @@ static int of_spi_register_master(struct spi_master *master)
1122 return 0; 1242 return 0;
1123 1243
1124 nb = of_gpio_named_count(np, "cs-gpios"); 1244 nb = of_gpio_named_count(np, "cs-gpios");
1125 master->num_chipselect = max(nb, (int)master->num_chipselect); 1245 master->num_chipselect = max_t(int, nb, master->num_chipselect);
1126 1246
1127 /* Return error only for an incorrectly formed cs-gpios property */ 1247 /* Return error only for an incorrectly formed cs-gpios property */
1128 if (nb == 0 || nb == -ENOENT) 1248 if (nb == 0 || nb == -ENOENT)
@@ -1209,6 +1329,7 @@ int spi_register_master(struct spi_master *master)
1209 spin_lock_init(&master->bus_lock_spinlock); 1329 spin_lock_init(&master->bus_lock_spinlock);
1210 mutex_init(&master->bus_lock_mutex); 1330 mutex_init(&master->bus_lock_mutex);
1211 master->bus_lock_flag = 0; 1331 master->bus_lock_flag = 0;
1332 init_completion(&master->xfer_completion);
1212 1333
1213 /* register the device, then userspace will see it. 1334 /* register the device, then userspace will see it.
1214 * registration fails if the bus ID is in use. 1335 * registration fails if the bus ID is in use.
@@ -1245,6 +1366,41 @@ done:
1245} 1366}
1246EXPORT_SYMBOL_GPL(spi_register_master); 1367EXPORT_SYMBOL_GPL(spi_register_master);
1247 1368
1369static void devm_spi_unregister(struct device *dev, void *res)
1370{
1371 spi_unregister_master(*(struct spi_master **)res);
1372}
1373
1374/**
1375 * dev_spi_register_master - register managed SPI master controller
1376 * @dev: device managing SPI master
1377 * @master: initialized master, originally from spi_alloc_master()
1378 * Context: can sleep
1379 *
1380 * Register a SPI device as with spi_register_master() which will
1381 * automatically be unregister
1382 */
1383int devm_spi_register_master(struct device *dev, struct spi_master *master)
1384{
1385 struct spi_master **ptr;
1386 int ret;
1387
1388 ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
1389 if (!ptr)
1390 return -ENOMEM;
1391
1392 ret = spi_register_master(master);
1393 if (ret != 0) {
1394 *ptr = master;
1395 devres_add(dev, ptr);
1396 } else {
1397 devres_free(ptr);
1398 }
1399
1400 return ret;
1401}
1402EXPORT_SYMBOL_GPL(devm_spi_register_master);
1403
1248static int __unregister(struct device *dev, void *null) 1404static int __unregister(struct device *dev, void *null)
1249{ 1405{
1250 spi_unregister_device(to_spi_device(dev)); 1406 spi_unregister_device(to_spi_device(dev));
@@ -1402,8 +1558,7 @@ int spi_setup(struct spi_device *spi)
1402 if (spi->master->setup) 1558 if (spi->master->setup)
1403 status = spi->master->setup(spi); 1559 status = spi->master->setup(spi);
1404 1560
1405 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s" 1561 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n",
1406 "%u bits/w, %u Hz max --> %d\n",
1407 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), 1562 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),
1408 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", 1563 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",
1409 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", 1564 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",
@@ -1421,6 +1576,10 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1421 struct spi_master *master = spi->master; 1576 struct spi_master *master = spi->master;
1422 struct spi_transfer *xfer; 1577 struct spi_transfer *xfer;
1423 1578
1579 message->spi = spi;
1580
1581 trace_spi_message_submit(message);
1582
1424 if (list_empty(&message->transfers)) 1583 if (list_empty(&message->transfers))
1425 return -EINVAL; 1584 return -EINVAL;
1426 if (!message->complete) 1585 if (!message->complete)
@@ -1520,7 +1679,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1520 } 1679 }
1521 } 1680 }
1522 1681
1523 message->spi = spi;
1524 message->status = -EINPROGRESS; 1682 message->status = -EINPROGRESS;
1525 return master->transfer(spi, message); 1683 return master->transfer(spi, message);
1526} 1684}
@@ -1762,7 +1920,7 @@ int spi_bus_unlock(struct spi_master *master)
1762EXPORT_SYMBOL_GPL(spi_bus_unlock); 1920EXPORT_SYMBOL_GPL(spi_bus_unlock);
1763 1921
1764/* portable code must never pass more than 32 bytes */ 1922/* portable code must never pass more than 32 bytes */
1765#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES) 1923#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
1766 1924
1767static u8 *buf; 1925static u8 *buf;
1768 1926
@@ -1811,7 +1969,7 @@ int spi_write_then_read(struct spi_device *spi,
1811 } 1969 }
1812 1970
1813 spi_message_init(&message); 1971 spi_message_init(&message);
1814 memset(x, 0, sizeof x); 1972 memset(x, 0, sizeof(x));
1815 if (n_tx) { 1973 if (n_tx) {
1816 x[0].len = n_tx; 1974 x[0].len = n_tx;
1817 spi_message_add_tail(&x[0], &message); 1975 spi_message_add_tail(&x[0], &message);
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index ca5bcfe874d0..d7c6e36021e8 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -37,7 +37,7 @@
37#include <linux/spi/spi.h> 37#include <linux/spi/spi.h>
38#include <linux/spi/spidev.h> 38#include <linux/spi/spidev.h>
39 39
40#include <asm/uaccess.h> 40#include <linux/uaccess.h>
41 41
42 42
43/* 43/*
@@ -206,9 +206,9 @@ spidev_write(struct file *filp, const char __user *buf,
206 206
207 mutex_lock(&spidev->buf_lock); 207 mutex_lock(&spidev->buf_lock);
208 missing = copy_from_user(spidev->buffer, buf, count); 208 missing = copy_from_user(spidev->buffer, buf, count);
209 if (missing == 0) { 209 if (missing == 0)
210 status = spidev_sync_write(spidev, count); 210 status = spidev_sync_write(spidev, count);
211 } else 211 else
212 status = -EFAULT; 212 status = -EFAULT;
213 mutex_unlock(&spidev->buf_lock); 213 mutex_unlock(&spidev->buf_lock);
214 214
@@ -629,7 +629,6 @@ static int spidev_remove(struct spi_device *spi)
629 /* make sure ops on existing fds can abort cleanly */ 629 /* make sure ops on existing fds can abort cleanly */
630 spin_lock_irq(&spidev->spi_lock); 630 spin_lock_irq(&spidev->spi_lock);
631 spidev->spi = NULL; 631 spidev->spi = NULL;
632 spi_set_drvdata(spi, NULL);
633 spin_unlock_irq(&spidev->spi_lock); 632 spin_unlock_irq(&spidev->spi_lock);
634 633
635 /* prevent new opens */ 634 /* prevent new opens */
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index a0ebbc9ce5cd..042aa077b5b3 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1912,9 +1912,6 @@ static int serial_imx_probe_dt(struct imx_port *sport,
1912 1912
1913 sport->devdata = of_id->data; 1913 sport->devdata = of_id->data;
1914 1914
1915 if (of_device_is_stdout_path(np))
1916 add_preferred_console(imx_reg.cons->name, sport->port.line, 0);
1917
1918 return 0; 1915 return 0;
1919} 1916}
1920#else 1917#else
diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 93b697a0de65..15ad6fcda88b 100644
--- a/drivers/tty/serial/vt8500_serial.c
+++ b/drivers/tty/serial/vt8500_serial.c
@@ -561,12 +561,13 @@ static int vt8500_serial_probe(struct platform_device *pdev)
561 if (!mmres || !irqres) 561 if (!mmres || !irqres)
562 return -ENODEV; 562 return -ENODEV;
563 563
564 if (np) 564 if (np) {
565 port = of_alias_get_id(np, "serial"); 565 port = of_alias_get_id(np, "serial");
566 if (port >= VT8500_MAX_PORTS) 566 if (port >= VT8500_MAX_PORTS)
567 port = -1; 567 port = -1;
568 else 568 } else {
569 port = -1; 569 port = -1;
570 }
570 571
571 if (port < 0) { 572 if (port < 0) {
572 /* calculate the port id */ 573 /* calculate the port id */
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 6f96795dd20c..64d7a6d9a1ad 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -100,8 +100,10 @@ static void host_stop(struct ci_hdrc *ci)
100{ 100{
101 struct usb_hcd *hcd = ci->hcd; 101 struct usb_hcd *hcd = ci->hcd;
102 102
103 usb_remove_hcd(hcd); 103 if (hcd) {
104 usb_put_hcd(hcd); 104 usb_remove_hcd(hcd);
105 usb_put_hcd(hcd);
106 }
105 if (ci->platdata->reg_vbus) 107 if (ci->platdata->reg_vbus)
106 regulator_disable(ci->platdata->reg_vbus); 108 regulator_disable(ci->platdata->reg_vbus);
107} 109}
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 5b44cd47da5b..01fe36273f3b 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -97,6 +97,9 @@ static const struct usb_device_id usb_quirk_list[] = {
97 /* Alcor Micro Corp. Hub */ 97 /* Alcor Micro Corp. Hub */
98 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME }, 98 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME },
99 99
100 /* MicroTouch Systems touchscreen */
101 { USB_DEVICE(0x0596, 0x051e), .driver_info = USB_QUIRK_RESET_RESUME },
102
100 /* appletouch */ 103 /* appletouch */
101 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME }, 104 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME },
102 105
@@ -130,6 +133,9 @@ static const struct usb_device_id usb_quirk_list[] = {
130 /* Broadcom BCM92035DGROM BT dongle */ 133 /* Broadcom BCM92035DGROM BT dongle */
131 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME }, 134 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME },
132 135
136 /* MAYA44USB sound device */
137 { USB_DEVICE(0x0a92, 0x0091), .driver_info = USB_QUIRK_RESET_RESUME },
138
133 /* Action Semiconductor flash disk */ 139 /* Action Semiconductor flash disk */
134 { USB_DEVICE(0x10d6, 0x2200), .driver_info = 140 { USB_DEVICE(0x10d6, 0x2200), .driver_info =
135 USB_QUIRK_STRING_FETCH_255 }, 141 USB_QUIRK_STRING_FETCH_255 },
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 2c76ef1320ea..08ef2829a7e2 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -799,7 +799,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
799 * switchable ports. 799 * switchable ports.
800 */ 800 */
801 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 801 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
802 cpu_to_le32(ports_available)); 802 ports_available);
803 803
804 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 804 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
805 &ports_available); 805 &ports_available);
@@ -821,7 +821,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
821 * host. 821 * host.
822 */ 822 */
823 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 823 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
824 cpu_to_le32(ports_available)); 824 ports_available);
825 825
826 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 826 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
827 &ports_available); 827 &ports_available);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 773a6b28c4f1..e8b4c56dcf62 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1157,18 +1157,6 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1157 t1 = xhci_port_state_to_neutral(t1); 1157 t1 = xhci_port_state_to_neutral(t1);
1158 if (t1 != t2) 1158 if (t1 != t2)
1159 xhci_writel(xhci, t2, port_array[port_index]); 1159 xhci_writel(xhci, t2, port_array[port_index]);
1160
1161 if (hcd->speed != HCD_USB3) {
1162 /* enable remote wake up for USB 2.0 */
1163 __le32 __iomem *addr;
1164 u32 tmp;
1165
1166 /* Get the port power control register address. */
1167 addr = port_array[port_index] + PORTPMSC;
1168 tmp = xhci_readl(xhci, addr);
1169 tmp |= PORT_RWE;
1170 xhci_writel(xhci, tmp, addr);
1171 }
1172 } 1160 }
1173 hcd->state = HC_STATE_SUSPENDED; 1161 hcd->state = HC_STATE_SUSPENDED;
1174 bus_state->next_statechange = jiffies + msecs_to_jiffies(10); 1162 bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
@@ -1247,20 +1235,6 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1247 xhci_ring_device(xhci, slot_id); 1235 xhci_ring_device(xhci, slot_id);
1248 } else 1236 } else
1249 xhci_writel(xhci, temp, port_array[port_index]); 1237 xhci_writel(xhci, temp, port_array[port_index]);
1250
1251 if (hcd->speed != HCD_USB3) {
1252 /* disable remote wake up for USB 2.0 */
1253 __le32 __iomem *addr;
1254 u32 tmp;
1255
1256 /* Add one to the port status register address to get
1257 * the port power control register address.
1258 */
1259 addr = port_array[port_index] + PORTPMSC;
1260 tmp = xhci_readl(xhci, addr);
1261 tmp &= ~PORT_RWE;
1262 xhci_writel(xhci, tmp, addr);
1263 }
1264 } 1238 }
1265 1239
1266 (void) xhci_readl(xhci, &xhci->op_regs->command); 1240 (void) xhci_readl(xhci, &xhci->op_regs->command);
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 236c3aabe940..b8dffd59eb25 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -35,6 +35,9 @@
35#define PCI_VENDOR_ID_ETRON 0x1b6f 35#define PCI_VENDOR_ID_ETRON 0x1b6f
36#define PCI_DEVICE_ID_ASROCK_P67 0x7023 36#define PCI_DEVICE_ID_ASROCK_P67 0x7023
37 37
38#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
39#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
40
38static const char hcd_name[] = "xhci_hcd"; 41static const char hcd_name[] = "xhci_hcd";
39 42
40/* called after powerup, by probe or system-pm "wakeup" */ 43/* called after powerup, by probe or system-pm "wakeup" */
@@ -69,6 +72,14 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
69 "QUIRK: Fresco Logic xHC needs configure" 72 "QUIRK: Fresco Logic xHC needs configure"
70 " endpoint cmd after reset endpoint"); 73 " endpoint cmd after reset endpoint");
71 } 74 }
75 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
76 pdev->revision == 0x4) {
77 xhci->quirks |= XHCI_SLOW_SUSPEND;
78 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
79 "QUIRK: Fresco Logic xHC revision %u"
80 "must be suspended extra slowly",
81 pdev->revision);
82 }
72 /* Fresco Logic confirms: all revisions of this chip do not 83 /* Fresco Logic confirms: all revisions of this chip do not
73 * support MSI, even though some of them claim to in their PCI 84 * support MSI, even though some of them claim to in their PCI
74 * capabilities. 85 * capabilities.
@@ -110,6 +121,15 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
110 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 121 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
111 xhci->quirks |= XHCI_AVOID_BEI; 122 xhci->quirks |= XHCI_AVOID_BEI;
112 } 123 }
124 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
125 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||
126 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI)) {
127 /* Workaround for occasional spurious wakeups from S5 (or
128 * any other sleep) on Haswell machines with LPT and LPT-LP
129 * with the new Intel BIOS
130 */
131 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
132 }
113 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 133 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
114 pdev->device == PCI_DEVICE_ID_ASROCK_P67) { 134 pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
115 xhci->quirks |= XHCI_RESET_ON_RESUME; 135 xhci->quirks |= XHCI_RESET_ON_RESUME;
@@ -217,6 +237,11 @@ static void xhci_pci_remove(struct pci_dev *dev)
217 usb_put_hcd(xhci->shared_hcd); 237 usb_put_hcd(xhci->shared_hcd);
218 } 238 }
219 usb_hcd_pci_remove(dev); 239 usb_hcd_pci_remove(dev);
240
241 /* Workaround for spurious wakeups at shutdown with HSW */
242 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
243 pci_set_power_state(dev, PCI_D3hot);
244
220 kfree(xhci); 245 kfree(xhci);
221} 246}
222 247
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1e36dbb48366..6e0d886bcce5 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -730,6 +730,9 @@ void xhci_shutdown(struct usb_hcd *hcd)
730 730
731 spin_lock_irq(&xhci->lock); 731 spin_lock_irq(&xhci->lock);
732 xhci_halt(xhci); 732 xhci_halt(xhci);
733 /* Workaround for spurious wakeups at shutdown with HSW */
734 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
735 xhci_reset(xhci);
733 spin_unlock_irq(&xhci->lock); 736 spin_unlock_irq(&xhci->lock);
734 737
735 xhci_cleanup_msix(xhci); 738 xhci_cleanup_msix(xhci);
@@ -737,6 +740,10 @@ void xhci_shutdown(struct usb_hcd *hcd)
737 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 740 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
738 "xhci_shutdown completed - status = %x", 741 "xhci_shutdown completed - status = %x",
739 xhci_readl(xhci, &xhci->op_regs->status)); 742 xhci_readl(xhci, &xhci->op_regs->status));
743
744 /* Yet another workaround for spurious wakeups at shutdown with HSW */
745 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
746 pci_set_power_state(to_pci_dev(hcd->self.controller), PCI_D3hot);
740} 747}
741 748
742#ifdef CONFIG_PM 749#ifdef CONFIG_PM
@@ -839,6 +846,7 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
839int xhci_suspend(struct xhci_hcd *xhci) 846int xhci_suspend(struct xhci_hcd *xhci)
840{ 847{
841 int rc = 0; 848 int rc = 0;
849 unsigned int delay = XHCI_MAX_HALT_USEC;
842 struct usb_hcd *hcd = xhci_to_hcd(xhci); 850 struct usb_hcd *hcd = xhci_to_hcd(xhci);
843 u32 command; 851 u32 command;
844 852
@@ -861,8 +869,12 @@ int xhci_suspend(struct xhci_hcd *xhci)
861 command = xhci_readl(xhci, &xhci->op_regs->command); 869 command = xhci_readl(xhci, &xhci->op_regs->command);
862 command &= ~CMD_RUN; 870 command &= ~CMD_RUN;
863 xhci_writel(xhci, command, &xhci->op_regs->command); 871 xhci_writel(xhci, command, &xhci->op_regs->command);
872
873 /* Some chips from Fresco Logic need an extraordinary delay */
874 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1;
875
864 if (xhci_handshake(xhci, &xhci->op_regs->status, 876 if (xhci_handshake(xhci, &xhci->op_regs->status,
865 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC)) { 877 STS_HALT, STS_HALT, delay)) {
866 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); 878 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n");
867 spin_unlock_irq(&xhci->lock); 879 spin_unlock_irq(&xhci->lock);
868 return -ETIMEDOUT; 880 return -ETIMEDOUT;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 289fbfbae746..941d5f59e4dc 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1548,6 +1548,8 @@ struct xhci_hcd {
1548#define XHCI_COMP_MODE_QUIRK (1 << 14) 1548#define XHCI_COMP_MODE_QUIRK (1 << 14)
1549#define XHCI_AVOID_BEI (1 << 15) 1549#define XHCI_AVOID_BEI (1 << 15)
1550#define XHCI_PLAT (1 << 16) 1550#define XHCI_PLAT (1 << 16)
1551#define XHCI_SLOW_SUSPEND (1 << 17)
1552#define XHCI_SPURIOUS_WAKEUP (1 << 18)
1551 unsigned int num_active_eps; 1553 unsigned int num_active_eps;
1552 unsigned int limit_active_eps; 1554 unsigned int limit_active_eps;
1553 /* There are two roothubs to keep track of bus suspend info for */ 1555 /* There are two roothubs to keep track of bus suspend info for */
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index e2b21c1d9c40..ba5f70f92888 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -246,6 +246,6 @@ config USB_EZUSB_FX2
246config USB_HSIC_USB3503 246config USB_HSIC_USB3503
247 tristate "USB3503 HSIC to USB20 Driver" 247 tristate "USB3503 HSIC to USB20 Driver"
248 depends on I2C 248 depends on I2C
249 select REGMAP 249 select REGMAP_I2C
250 help 250 help
251 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver. 251 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver.
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 18e877ffe7b7..cd70cc886171 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -922,6 +922,52 @@ static void musb_generic_disable(struct musb *musb)
922} 922}
923 923
924/* 924/*
925 * Program the HDRC to start (enable interrupts, dma, etc.).
926 */
927void musb_start(struct musb *musb)
928{
929 void __iomem *regs = musb->mregs;
930 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
931
932 dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
933
934 /* Set INT enable registers, enable interrupts */
935 musb->intrtxe = musb->epmask;
936 musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
937 musb->intrrxe = musb->epmask & 0xfffe;
938 musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
939 musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
940
941 musb_writeb(regs, MUSB_TESTMODE, 0);
942
943 /* put into basic highspeed mode and start session */
944 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
945 | MUSB_POWER_HSENAB
946 /* ENSUSPEND wedges tusb */
947 /* | MUSB_POWER_ENSUSPEND */
948 );
949
950 musb->is_active = 0;
951 devctl = musb_readb(regs, MUSB_DEVCTL);
952 devctl &= ~MUSB_DEVCTL_SESSION;
953
954 /* session started after:
955 * (a) ID-grounded irq, host mode;
956 * (b) vbus present/connect IRQ, peripheral mode;
957 * (c) peripheral initiates, using SRP
958 */
959 if (musb->port_mode != MUSB_PORT_MODE_HOST &&
960 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
961 musb->is_active = 1;
962 } else {
963 devctl |= MUSB_DEVCTL_SESSION;
964 }
965
966 musb_platform_enable(musb);
967 musb_writeb(regs, MUSB_DEVCTL, devctl);
968}
969
970/*
925 * Make the HDRC stop (disable interrupts, etc.); 971 * Make the HDRC stop (disable interrupts, etc.);
926 * reversible by musb_start 972 * reversible by musb_start
927 * called on gadget driver unregister 973 * called on gadget driver unregister
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 65f3917b4fc5..1c5bf75ee8ff 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -503,6 +503,7 @@ static inline void musb_configure_ep0(struct musb *musb)
503extern const char musb_driver_name[]; 503extern const char musb_driver_name[];
504 504
505extern void musb_stop(struct musb *musb); 505extern void musb_stop(struct musb *musb);
506extern void musb_start(struct musb *musb);
506 507
507extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src); 508extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
508extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst); 509extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index b19ed213ab85..3671898a4535 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1853,11 +1853,14 @@ static int musb_gadget_start(struct usb_gadget *g,
1853 musb->gadget_driver = driver; 1853 musb->gadget_driver = driver;
1854 1854
1855 spin_lock_irqsave(&musb->lock, flags); 1855 spin_lock_irqsave(&musb->lock, flags);
1856 musb->is_active = 1;
1856 1857
1857 otg_set_peripheral(otg, &musb->g); 1858 otg_set_peripheral(otg, &musb->g);
1858 musb->xceiv->state = OTG_STATE_B_IDLE; 1859 musb->xceiv->state = OTG_STATE_B_IDLE;
1859 spin_unlock_irqrestore(&musb->lock, flags); 1860 spin_unlock_irqrestore(&musb->lock, flags);
1860 1861
1862 musb_start(musb);
1863
1861 /* REVISIT: funcall to other code, which also 1864 /* REVISIT: funcall to other code, which also
1862 * handles power budgeting ... this way also 1865 * handles power budgeting ... this way also
1863 * ensures HdrcStart is indirectly called. 1866 * ensures HdrcStart is indirectly called.
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index a523950c2b32..d1d6b83aabca 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -44,52 +44,6 @@
44 44
45#include "musb_core.h" 45#include "musb_core.h"
46 46
47/*
48* Program the HDRC to start (enable interrupts, dma, etc.).
49*/
50static void musb_start(struct musb *musb)
51{
52 void __iomem *regs = musb->mregs;
53 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
54
55 dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
56
57 /* Set INT enable registers, enable interrupts */
58 musb->intrtxe = musb->epmask;
59 musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
60 musb->intrrxe = musb->epmask & 0xfffe;
61 musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
62 musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
63
64 musb_writeb(regs, MUSB_TESTMODE, 0);
65
66 /* put into basic highspeed mode and start session */
67 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
68 | MUSB_POWER_HSENAB
69 /* ENSUSPEND wedges tusb */
70 /* | MUSB_POWER_ENSUSPEND */
71 );
72
73 musb->is_active = 0;
74 devctl = musb_readb(regs, MUSB_DEVCTL);
75 devctl &= ~MUSB_DEVCTL_SESSION;
76
77 /* session started after:
78 * (a) ID-grounded irq, host mode;
79 * (b) vbus present/connect IRQ, peripheral mode;
80 * (c) peripheral initiates, using SRP
81 */
82 if (musb->port_mode != MUSB_PORT_MODE_HOST &&
83 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
84 musb->is_active = 1;
85 } else {
86 devctl |= MUSB_DEVCTL_SESSION;
87 }
88
89 musb_platform_enable(musb);
90 musb_writeb(regs, MUSB_DEVCTL, devctl);
91}
92
93static void musb_port_suspend(struct musb *musb, bool do_suspend) 47static void musb_port_suspend(struct musb *musb, bool do_suspend)
94{ 48{
95 struct usb_otg *otg = musb->xceiv->otg; 49 struct usb_otg *otg = musb->xceiv->otg;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 80a7104d5ddb..acaee066b99a 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -451,6 +451,10 @@ static void option_instat_callback(struct urb *urb);
451#define CHANGHONG_VENDOR_ID 0x2077 451#define CHANGHONG_VENDOR_ID 0x2077
452#define CHANGHONG_PRODUCT_CH690 0x7001 452#define CHANGHONG_PRODUCT_CH690 0x7001
453 453
454/* Inovia */
455#define INOVIA_VENDOR_ID 0x20a6
456#define INOVIA_SEW858 0x1105
457
454/* some devices interfaces need special handling due to a number of reasons */ 458/* some devices interfaces need special handling due to a number of reasons */
455enum option_blacklist_reason { 459enum option_blacklist_reason {
456 OPTION_BLACKLIST_NONE = 0, 460 OPTION_BLACKLIST_NONE = 0,
@@ -689,6 +693,222 @@ static const struct usb_device_id option_ids[] = {
689 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7A) }, 693 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7A) },
690 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7B) }, 694 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7B) },
691 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7C) }, 695 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7C) },
696 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x01) },
697 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x02) },
698 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x03) },
699 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x04) },
700 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x05) },
701 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x06) },
702 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0A) },
703 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0B) },
704 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0D) },
705 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0E) },
706 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0F) },
707 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x10) },
708 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x12) },
709 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x13) },
710 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x14) },
711 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x15) },
712 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x17) },
713 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x18) },
714 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x19) },
715 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1A) },
716 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1B) },
717 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1C) },
718 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x31) },
719 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x32) },
720 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x33) },
721 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x34) },
722 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x35) },
723 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x36) },
724 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3A) },
725 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3B) },
726 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3D) },
727 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3E) },
728 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3F) },
729 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x48) },
730 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x49) },
731 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4A) },
732 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4B) },
733 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4C) },
734 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x61) },
735 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x62) },
736 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x63) },
737 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x64) },
738 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x65) },
739 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x66) },
740 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6A) },
741 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6B) },
742 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6D) },
743 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6E) },
744 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6F) },
745 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x78) },
746 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x79) },
747 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7A) },
748 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7B) },
749 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7C) },
750 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x01) },
751 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x02) },
752 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x03) },
753 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x04) },
754 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x05) },
755 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x06) },
756 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0A) },
757 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0B) },
758 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0D) },
759 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0E) },
760 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0F) },
761 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x10) },
762 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x12) },
763 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x13) },
764 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x14) },
765 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x15) },
766 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x17) },
767 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x18) },
768 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x19) },
769 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1A) },
770 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1B) },
771 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1C) },
772 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x31) },
773 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x32) },
774 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x33) },
775 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x34) },
776 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x35) },
777 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x36) },
778 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3A) },
779 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3B) },
780 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3D) },
781 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3E) },
782 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3F) },
783 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x48) },
784 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x49) },
785 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4A) },
786 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4B) },
787 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4C) },
788 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x61) },
789 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x62) },
790 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x63) },
791 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x64) },
792 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x65) },
793 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x66) },
794 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6A) },
795 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6B) },
796 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6D) },
797 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6E) },
798 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6F) },
799 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x78) },
800 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x79) },
801 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7A) },
802 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7B) },
803 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7C) },
804 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x01) },
805 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x02) },
806 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x03) },
807 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x04) },
808 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x05) },
809 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x06) },
810 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0A) },
811 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0B) },
812 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0D) },
813 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0E) },
814 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0F) },
815 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x10) },
816 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x12) },
817 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x13) },
818 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x14) },
819 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x15) },
820 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x17) },
821 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x18) },
822 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x19) },
823 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1A) },
824 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1B) },
825 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1C) },
826 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x31) },
827 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x32) },
828 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x33) },
829 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x34) },
830 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x35) },
831 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x36) },
832 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3A) },
833 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3B) },
834 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3D) },
835 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3E) },
836 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3F) },
837 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x48) },
838 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x49) },
839 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4A) },
840 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4B) },
841 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4C) },
842 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x61) },
843 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x62) },
844 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x63) },
845 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x64) },
846 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x65) },
847 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x66) },
848 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6A) },
849 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6B) },
850 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6D) },
851 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6E) },
852 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6F) },
853 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x78) },
854 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x79) },
855 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7A) },
856 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7B) },
857 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7C) },
858 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x01) },
859 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x02) },
860 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x03) },
861 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x04) },
862 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x05) },
863 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x06) },
864 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0A) },
865 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0B) },
866 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0D) },
867 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0E) },
868 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0F) },
869 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x10) },
870 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x12) },
871 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x13) },
872 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x14) },
873 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x15) },
874 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x17) },
875 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x18) },
876 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x19) },
877 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1A) },
878 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1B) },
879 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1C) },
880 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x31) },
881 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x32) },
882 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x33) },
883 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x34) },
884 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x35) },
885 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x36) },
886 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3A) },
887 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3B) },
888 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3D) },
889 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3E) },
890 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3F) },
891 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x48) },
892 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x49) },
893 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4A) },
894 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4B) },
895 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4C) },
896 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x61) },
897 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x62) },
898 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x63) },
899 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x64) },
900 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x65) },
901 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x66) },
902 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6A) },
903 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6B) },
904 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6D) },
905 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6E) },
906 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6F) },
907 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x78) },
908 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x79) },
909 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7A) },
910 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7B) },
911 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7C) },
692 912
693 913
694 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 914 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
@@ -1257,7 +1477,9 @@ static const struct usb_device_id option_ids[] = {
1257 1477
1258 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) }, 1478 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) },
1259 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD145) }, 1479 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD145) },
1260 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD200) }, 1480 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD200),
1481 .driver_info = (kernel_ulong_t)&net_intf6_blacklist
1482 },
1261 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */ 1483 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */
1262 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/ 1484 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/
1263 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM600) }, 1485 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM600) },
@@ -1345,6 +1567,7 @@ static const struct usb_device_id option_ids[] = {
1345 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) }, 1567 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) },
1346 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */ 1568 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */
1347 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */ 1569 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */
1570 { USB_DEVICE(INOVIA_VENDOR_ID, INOVIA_SEW858) },
1348 { } /* Terminating entry */ 1571 { } /* Terminating entry */
1349}; 1572};
1350MODULE_DEVICE_TABLE(usb, option_ids); 1573MODULE_DEVICE_TABLE(usb, option_ids);
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 760b78560f67..c9a35697ebe9 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -190,6 +190,7 @@ static struct usb_device_id ti_id_table_combined[] = {
190 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) }, 190 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) },
191 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, 191 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
192 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) }, 192 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) },
193 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STRIP_PORT_ID) },
193 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, 194 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
194 { } /* terminator */ 195 { } /* terminator */
195}; 196};
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 94d75edef77f..18509e6c21ab 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -211,8 +211,11 @@ static int slave_configure(struct scsi_device *sdev)
211 /* 211 /*
212 * Many devices do not respond properly to READ_CAPACITY_16. 212 * Many devices do not respond properly to READ_CAPACITY_16.
213 * Tell the SCSI layer to try READ_CAPACITY_10 first. 213 * Tell the SCSI layer to try READ_CAPACITY_10 first.
214 * However some USB 3.0 drive enclosures return capacity
215 * modulo 2TB. Those must use READ_CAPACITY_16
214 */ 216 */
215 sdev->try_rc_10_first = 1; 217 if (!(us->fflags & US_FL_NEEDS_CAP16))
218 sdev->try_rc_10_first = 1;
216 219
217 /* assume SPC3 or latter devices support sense size > 18 */ 220 /* assume SPC3 or latter devices support sense size > 18 */
218 if (sdev->scsi_level > SCSI_SPC_2) 221 if (sdev->scsi_level > SCSI_SPC_2)
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index c015f2c16729..de32cfa5bfa6 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1925,6 +1925,13 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1925 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1925 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1926 US_FL_IGNORE_RESIDUE ), 1926 US_FL_IGNORE_RESIDUE ),
1927 1927
1928/* Reported by Oliver Neukum <oneukum@suse.com> */
1929UNUSUAL_DEV( 0x174c, 0x55aa, 0x0100, 0x0100,
1930 "ASMedia",
1931 "AS2105",
1932 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1933 US_FL_NEEDS_CAP16),
1934
1928/* Reported by Jesse Feddema <jdfeddema@gmail.com> */ 1935/* Reported by Jesse Feddema <jdfeddema@gmail.com> */
1929UNUSUAL_DEV( 0x177f, 0x0400, 0x0000, 0x0000, 1936UNUSUAL_DEV( 0x177f, 0x0400, 0x0000, 0x0000,
1930 "Yarvik", 1937 "Yarvik",
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index a9807dea3887..4fb7a8f83c8a 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -545,6 +545,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
545 long npage; 545 long npage;
546 int ret = 0, prot = 0; 546 int ret = 0, prot = 0;
547 uint64_t mask; 547 uint64_t mask;
548 struct vfio_dma *dma = NULL;
549 unsigned long pfn;
548 550
549 end = map->iova + map->size; 551 end = map->iova + map->size;
550 552
@@ -587,8 +589,6 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
587 } 589 }
588 590
589 for (iova = map->iova; iova < end; iova += size, vaddr += size) { 591 for (iova = map->iova; iova < end; iova += size, vaddr += size) {
590 struct vfio_dma *dma = NULL;
591 unsigned long pfn;
592 long i; 592 long i;
593 593
594 /* Pin a contiguous chunk of memory */ 594 /* Pin a contiguous chunk of memory */
@@ -597,16 +597,15 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
597 if (npage <= 0) { 597 if (npage <= 0) {
598 WARN_ON(!npage); 598 WARN_ON(!npage);
599 ret = (int)npage; 599 ret = (int)npage;
600 break; 600 goto out;
601 } 601 }
602 602
603 /* Verify pages are not already mapped */ 603 /* Verify pages are not already mapped */
604 for (i = 0; i < npage; i++) { 604 for (i = 0; i < npage; i++) {
605 if (iommu_iova_to_phys(iommu->domain, 605 if (iommu_iova_to_phys(iommu->domain,
606 iova + (i << PAGE_SHIFT))) { 606 iova + (i << PAGE_SHIFT))) {
607 vfio_unpin_pages(pfn, npage, prot, true);
608 ret = -EBUSY; 607 ret = -EBUSY;
609 break; 608 goto out_unpin;
610 } 609 }
611 } 610 }
612 611
@@ -616,8 +615,7 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
616 if (ret) { 615 if (ret) {
617 if (ret != -EBUSY || 616 if (ret != -EBUSY ||
618 map_try_harder(iommu, iova, pfn, npage, prot)) { 617 map_try_harder(iommu, iova, pfn, npage, prot)) {
619 vfio_unpin_pages(pfn, npage, prot, true); 618 goto out_unpin;
620 break;
621 } 619 }
622 } 620 }
623 621
@@ -672,9 +670,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
672 dma = kzalloc(sizeof(*dma), GFP_KERNEL); 670 dma = kzalloc(sizeof(*dma), GFP_KERNEL);
673 if (!dma) { 671 if (!dma) {
674 iommu_unmap(iommu->domain, iova, size); 672 iommu_unmap(iommu->domain, iova, size);
675 vfio_unpin_pages(pfn, npage, prot, true);
676 ret = -ENOMEM; 673 ret = -ENOMEM;
677 break; 674 goto out_unpin;
678 } 675 }
679 676
680 dma->size = size; 677 dma->size = size;
@@ -685,16 +682,21 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
685 } 682 }
686 } 683 }
687 684
688 if (ret) { 685 WARN_ON(ret);
689 struct vfio_dma *tmp; 686 mutex_unlock(&iommu->lock);
690 iova = map->iova; 687 return ret;
691 size = map->size; 688
692 while ((tmp = vfio_find_dma(iommu, iova, size))) { 689out_unpin:
693 int r = vfio_remove_dma_overlap(iommu, iova, 690 vfio_unpin_pages(pfn, npage, prot, true);
694 &size, tmp); 691
695 if (WARN_ON(r || !size)) 692out:
696 break; 693 iova = map->iova;
697 } 694 size = map->size;
695 while ((dma = vfio_find_dma(iommu, iova, size))) {
696 int r = vfio_remove_dma_overlap(iommu, iova,
697 &size, dma);
698 if (WARN_ON(r || !size))
699 break;
698 } 700 }
699 701
700 mutex_unlock(&iommu->lock); 702 mutex_unlock(&iommu->lock);
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index c7c64f18773d..fa932c2f7d97 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -613,6 +613,9 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action,
613 sl = dev_to_w1_slave(dev); 613 sl = dev_to_w1_slave(dev);
614 fops = sl->family->fops; 614 fops = sl->family->fops;
615 615
616 if (!fops)
617 return 0;
618
616 switch (action) { 619 switch (action) {
617 case BUS_NOTIFY_ADD_DEVICE: 620 case BUS_NOTIFY_ADD_DEVICE:
618 /* if the family driver needs to initialize something... */ 621 /* if the family driver needs to initialize something... */
@@ -713,7 +716,10 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
713 atomic_set(&sl->refcnt, 0); 716 atomic_set(&sl->refcnt, 0);
714 init_completion(&sl->released); 717 init_completion(&sl->released);
715 718
719 /* slave modules need to be loaded in a context with unlocked mutex */
720 mutex_unlock(&dev->mutex);
716 request_module("w1-family-0x%0x", rn->family); 721 request_module("w1-family-0x%0x", rn->family);
722 mutex_lock(&dev->mutex);
717 723
718 spin_lock(&w1_flock); 724 spin_lock(&w1_flock);
719 f = w1_family_registered(rn->family); 725 f = w1_family_registered(rn->family);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b0ef7b07b1b3..51e3afa78354 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6437,6 +6437,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
6437 6437
6438 if (btrfs_extent_readonly(root, disk_bytenr)) 6438 if (btrfs_extent_readonly(root, disk_bytenr))
6439 goto out; 6439 goto out;
6440 btrfs_release_path(path);
6440 6441
6441 /* 6442 /*
6442 * look for other files referencing this extent, if we 6443 * look for other files referencing this extent, if we
diff --git a/fs/buffer.c b/fs/buffer.c
index 4d7433534f5c..6024877335ca 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1005,9 +1005,19 @@ grow_dev_page(struct block_device *bdev, sector_t block,
1005 struct buffer_head *bh; 1005 struct buffer_head *bh;
1006 sector_t end_block; 1006 sector_t end_block;
1007 int ret = 0; /* Will call free_more_memory() */ 1007 int ret = 0; /* Will call free_more_memory() */
1008 gfp_t gfp_mask;
1008 1009
1009 page = find_or_create_page(inode->i_mapping, index, 1010 gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
1010 (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE); 1011 gfp_mask |= __GFP_MOVABLE;
1012 /*
1013 * XXX: __getblk_slow() can not really deal with failure and
1014 * will endlessly loop on improvised global reclaim. Prefer
1015 * looping in the allocator rather than here, at least that
1016 * code knows what it's doing.
1017 */
1018 gfp_mask |= __GFP_NOFAIL;
1019
1020 page = find_or_create_page(inode->i_mapping, index, gfp_mask);
1011 if (!page) 1021 if (!page)
1012 return ret; 1022 return ret;
1013 1023
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index a16b4e58bcc6..77fc5e181077 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -120,14 +120,16 @@ cifs_read_super(struct super_block *sb)
120{ 120{
121 struct inode *inode; 121 struct inode *inode;
122 struct cifs_sb_info *cifs_sb; 122 struct cifs_sb_info *cifs_sb;
123 struct cifs_tcon *tcon;
123 int rc = 0; 124 int rc = 0;
124 125
125 cifs_sb = CIFS_SB(sb); 126 cifs_sb = CIFS_SB(sb);
127 tcon = cifs_sb_master_tcon(cifs_sb);
126 128
127 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL) 129 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
128 sb->s_flags |= MS_POSIXACL; 130 sb->s_flags |= MS_POSIXACL;
129 131
130 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES) 132 if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
131 sb->s_maxbytes = MAX_LFS_FILESIZE; 133 sb->s_maxbytes = MAX_LFS_FILESIZE;
132 else 134 else
133 sb->s_maxbytes = MAX_NON_LFS; 135 sb->s_maxbytes = MAX_NON_LFS;
@@ -147,7 +149,7 @@ cifs_read_super(struct super_block *sb)
147 goto out_no_root; 149 goto out_no_root;
148 } 150 }
149 151
150 if (cifs_sb_master_tcon(cifs_sb)->nocase) 152 if (tcon->nocase)
151 sb->s_d_op = &cifs_ci_dentry_ops; 153 sb->s_d_op = &cifs_ci_dentry_ops;
152 else 154 else
153 sb->s_d_op = &cifs_dentry_ops; 155 sb->s_d_op = &cifs_dentry_ops;
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index a630475e421c..08f9dfb1a894 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -1491,15 +1491,30 @@ struct file_notify_information {
1491 __u8 FileName[0]; 1491 __u8 FileName[0];
1492} __attribute__((packed)); 1492} __attribute__((packed));
1493 1493
1494struct reparse_data { 1494/* For IO_REPARSE_TAG_SYMLINK */
1495 __u32 ReparseTag; 1495struct reparse_symlink_data {
1496 __u16 ReparseDataLength; 1496 __le32 ReparseTag;
1497 __le16 ReparseDataLength;
1497 __u16 Reserved; 1498 __u16 Reserved;
1498 __u16 SubstituteNameOffset; 1499 __le16 SubstituteNameOffset;
1499 __u16 SubstituteNameLength; 1500 __le16 SubstituteNameLength;
1500 __u16 PrintNameOffset; 1501 __le16 PrintNameOffset;
1501 __u16 PrintNameLength; 1502 __le16 PrintNameLength;
1502 __u32 Flags; 1503 __le32 Flags;
1504 char PathBuffer[0];
1505} __attribute__((packed));
1506
1507/* For IO_REPARSE_TAG_NFS */
1508#define NFS_SPECFILE_LNK 0x00000000014B4E4C
1509#define NFS_SPECFILE_CHR 0x0000000000524843
1510#define NFS_SPECFILE_BLK 0x00000000004B4C42
1511#define NFS_SPECFILE_FIFO 0x000000004F464946
1512#define NFS_SPECFILE_SOCK 0x000000004B434F53
1513struct reparse_posix_data {
1514 __le32 ReparseTag;
1515 __le16 ReparseDataLength;
1516 __u16 Reserved;
1517 __le64 InodeType; /* LNK, FIFO, CHR etc. */
1503 char PathBuffer[0]; 1518 char PathBuffer[0];
1504} __attribute__((packed)); 1519} __attribute__((packed));
1505 1520
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 4baf35949b51..ccd31ab815d4 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -3088,7 +3088,8 @@ CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
3088 bool is_unicode; 3088 bool is_unicode;
3089 unsigned int sub_len; 3089 unsigned int sub_len;
3090 char *sub_start; 3090 char *sub_start;
3091 struct reparse_data *reparse_buf; 3091 struct reparse_symlink_data *reparse_buf;
3092 struct reparse_posix_data *posix_buf;
3092 __u32 data_offset, data_count; 3093 __u32 data_offset, data_count;
3093 char *end_of_smb; 3094 char *end_of_smb;
3094 3095
@@ -3137,20 +3138,47 @@ CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
3137 goto qreparse_out; 3138 goto qreparse_out;
3138 } 3139 }
3139 end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; 3140 end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount;
3140 reparse_buf = (struct reparse_data *) 3141 reparse_buf = (struct reparse_symlink_data *)
3141 ((char *)&pSMBr->hdr.Protocol + data_offset); 3142 ((char *)&pSMBr->hdr.Protocol + data_offset);
3142 if ((char *)reparse_buf >= end_of_smb) { 3143 if ((char *)reparse_buf >= end_of_smb) {
3143 rc = -EIO; 3144 rc = -EIO;
3144 goto qreparse_out; 3145 goto qreparse_out;
3145 } 3146 }
3146 if ((reparse_buf->PathBuffer + reparse_buf->PrintNameOffset + 3147 if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) {
3147 reparse_buf->PrintNameLength) > end_of_smb) { 3148 cifs_dbg(FYI, "NFS style reparse tag\n");
3149 posix_buf = (struct reparse_posix_data *)reparse_buf;
3150
3151 if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) {
3152 cifs_dbg(FYI, "unsupported file type 0x%llx\n",
3153 le64_to_cpu(posix_buf->InodeType));
3154 rc = -EOPNOTSUPP;
3155 goto qreparse_out;
3156 }
3157 is_unicode = true;
3158 sub_len = le16_to_cpu(reparse_buf->ReparseDataLength);
3159 if (posix_buf->PathBuffer + sub_len > end_of_smb) {
3160 cifs_dbg(FYI, "reparse buf beyond SMB\n");
3161 rc = -EIO;
3162 goto qreparse_out;
3163 }
3164 *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer,
3165 sub_len, is_unicode, nls_codepage);
3166 goto qreparse_out;
3167 } else if (reparse_buf->ReparseTag !=
3168 cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) {
3169 rc = -EOPNOTSUPP;
3170 goto qreparse_out;
3171 }
3172
3173 /* Reparse tag is NTFS symlink */
3174 sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) +
3175 reparse_buf->PathBuffer;
3176 sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength);
3177 if (sub_start + sub_len > end_of_smb) {
3148 cifs_dbg(FYI, "reparse buf beyond SMB\n"); 3178 cifs_dbg(FYI, "reparse buf beyond SMB\n");
3149 rc = -EIO; 3179 rc = -EIO;
3150 goto qreparse_out; 3180 goto qreparse_out;
3151 } 3181 }
3152 sub_start = reparse_buf->SubstituteNameOffset + reparse_buf->PathBuffer;
3153 sub_len = reparse_buf->SubstituteNameLength;
3154 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) 3182 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
3155 is_unicode = true; 3183 is_unicode = true;
3156 else 3184 else
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index af847e1cf1c1..651a5279607b 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -780,7 +780,9 @@ static const struct {
780 ERRDOS, ERRnoaccess, 0xc0000290}, { 780 ERRDOS, ERRnoaccess, 0xc0000290}, {
781 ERRDOS, ERRbadfunc, 0xc000029c}, { 781 ERRDOS, ERRbadfunc, 0xc000029c}, {
782 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, { 782 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
783 ERRDOS, ERRinvlevel, 0x007c0001}, }; 783 ERRDOS, ERRinvlevel, 0x007c0001}, {
784 0, 0, 0 }
785};
784 786
785/***************************************************************************** 787/*****************************************************************************
786 Print an error message from the status code 788 Print an error message from the status code
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 352358de1d7e..e87387dbf39f 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -500,9 +500,9 @@ select_sectype(struct TCP_Server_Info *server, enum securityEnum requested)
500 return NTLMv2; 500 return NTLMv2;
501 if (global_secflags & CIFSSEC_MAY_NTLM) 501 if (global_secflags & CIFSSEC_MAY_NTLM)
502 return NTLM; 502 return NTLM;
503 /* Fallthrough */
504 default: 503 default:
505 return Unspecified; 504 /* Fallthrough to attempt LANMAN authentication next */
505 break;
506 } 506 }
507 case CIFS_NEGFLAVOR_LANMAN: 507 case CIFS_NEGFLAVOR_LANMAN:
508 switch (requested) { 508 switch (requested) {
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index eba0efde66d7..edccb5252462 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -687,6 +687,10 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
687 else 687 else
688 return -EIO; 688 return -EIO;
689 689
690 /* no need to send SMB logoff if uid already closed due to reconnect */
691 if (ses->need_reconnect)
692 goto smb2_session_already_dead;
693
690 rc = small_smb2_init(SMB2_LOGOFF, NULL, (void **) &req); 694 rc = small_smb2_init(SMB2_LOGOFF, NULL, (void **) &req);
691 if (rc) 695 if (rc)
692 return rc; 696 return rc;
@@ -701,6 +705,8 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
701 * No tcon so can't do 705 * No tcon so can't do
702 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); 706 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
703 */ 707 */
708
709smb2_session_already_dead:
704 return rc; 710 return rc;
705} 711}
706 712
diff --git a/fs/cifs/smbfsctl.h b/fs/cifs/smbfsctl.h
index d952ee48f4dc..a4b2391fe66e 100644
--- a/fs/cifs/smbfsctl.h
+++ b/fs/cifs/smbfsctl.h
@@ -97,9 +97,23 @@
97#define FSCTL_QUERY_NETWORK_INTERFACE_INFO 0x001401FC /* BB add struct */ 97#define FSCTL_QUERY_NETWORK_INTERFACE_INFO 0x001401FC /* BB add struct */
98#define FSCTL_SRV_READ_HASH 0x001441BB /* BB add struct */ 98#define FSCTL_SRV_READ_HASH 0x001441BB /* BB add struct */
99 99
100/* See FSCC 2.1.2.5 */
100#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003 101#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
101#define IO_REPARSE_TAG_HSM 0xC0000004 102#define IO_REPARSE_TAG_HSM 0xC0000004
102#define IO_REPARSE_TAG_SIS 0x80000007 103#define IO_REPARSE_TAG_SIS 0x80000007
104#define IO_REPARSE_TAG_HSM2 0x80000006
105#define IO_REPARSE_TAG_DRIVER_EXTENDER 0x80000005
106/* Used by the DFS filter. See MS-DFSC */
107#define IO_REPARSE_TAG_DFS 0x8000000A
108/* Used by the DFS filter See MS-DFSC */
109#define IO_REPARSE_TAG_DFSR 0x80000012
110#define IO_REPARSE_TAG_FILTER_MANAGER 0x8000000B
111/* See section MS-FSCC 2.1.2.4 */
112#define IO_REPARSE_TAG_SYMLINK 0xA000000C
113#define IO_REPARSE_TAG_DEDUP 0x80000013
114#define IO_REPARSE_APPXSTREAM 0xC0000014
115/* NFS symlinks, Win 8/SMB3 and later */
116#define IO_REPARSE_TAG_NFS 0x80000014
103 117
104/* fsctl flags */ 118/* fsctl flags */
105/* If Flags is set to this value, the request is an FSCTL not ioctl request */ 119/* If Flags is set to this value, the request is an FSCTL not ioctl request */
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 6fdcb1b4a106..800b938e4061 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -410,8 +410,13 @@ static int
410wait_for_free_request(struct TCP_Server_Info *server, const int timeout, 410wait_for_free_request(struct TCP_Server_Info *server, const int timeout,
411 const int optype) 411 const int optype)
412{ 412{
413 return wait_for_free_credits(server, timeout, 413 int *val;
414 server->ops->get_credits_field(server, optype)); 414
415 val = server->ops->get_credits_field(server, optype);
416 /* Since an echo is already inflight, no need to wait to send another */
417 if (*val <= 0 && optype == CIFS_ECHO_OP)
418 return -EAGAIN;
419 return wait_for_free_credits(server, timeout, val);
415} 420}
416 421
417static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf, 422static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 1194b1f0f839..f8cde46de9cd 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -1783,7 +1783,7 @@ retry:
1783 d_tmpfile(dentry, inode); 1783 d_tmpfile(dentry, inode);
1784 err = ext3_orphan_add(handle, inode); 1784 err = ext3_orphan_add(handle, inode);
1785 if (err) 1785 if (err)
1786 goto err_drop_inode; 1786 goto err_unlock_inode;
1787 mark_inode_dirty(inode); 1787 mark_inode_dirty(inode);
1788 unlock_new_inode(inode); 1788 unlock_new_inode(inode);
1789 } 1789 }
@@ -1791,10 +1791,9 @@ retry:
1791 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 1791 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
1792 goto retry; 1792 goto retry;
1793 return err; 1793 return err;
1794err_drop_inode: 1794err_unlock_inode:
1795 ext3_journal_stop(handle); 1795 ext3_journal_stop(handle);
1796 unlock_new_inode(inode); 1796 unlock_new_inode(inode);
1797 iput(inode);
1798 return err; 1797 return err;
1799} 1798}
1800 1799
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 1bec5a5c1e45..5a0408d7b114 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2319,7 +2319,7 @@ retry:
2319 d_tmpfile(dentry, inode); 2319 d_tmpfile(dentry, inode);
2320 err = ext4_orphan_add(handle, inode); 2320 err = ext4_orphan_add(handle, inode);
2321 if (err) 2321 if (err)
2322 goto err_drop_inode; 2322 goto err_unlock_inode;
2323 mark_inode_dirty(inode); 2323 mark_inode_dirty(inode);
2324 unlock_new_inode(inode); 2324 unlock_new_inode(inode);
2325 } 2325 }
@@ -2328,10 +2328,9 @@ retry:
2328 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries)) 2328 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2329 goto retry; 2329 goto retry;
2330 return err; 2330 return err;
2331err_drop_inode: 2331err_unlock_inode:
2332 ext4_journal_stop(handle); 2332 ext4_journal_stop(handle);
2333 unlock_new_inode(inode); 2333 unlock_new_inode(inode);
2334 iput(inode);
2335 return err; 2334 return err;
2336} 2335}
2337 2336
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 9f8ef9b7674d..8eaa1ba793fc 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -288,10 +288,14 @@ static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma)
288static unsigned long proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags) 288static unsigned long proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
289{ 289{
290 struct proc_dir_entry *pde = PDE(file_inode(file)); 290 struct proc_dir_entry *pde = PDE(file_inode(file));
291 int rv = -EIO; 291 unsigned long rv = -EIO;
292 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 292 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) = NULL;
293 if (use_pde(pde)) { 293 if (use_pde(pde)) {
294 get_unmapped_area = pde->proc_fops->get_unmapped_area; 294#ifdef CONFIG_MMU
295 get_unmapped_area = current->mm->get_unmapped_area;
296#endif
297 if (pde->proc_fops->get_unmapped_area)
298 get_unmapped_area = pde->proc_fops->get_unmapped_area;
295 if (get_unmapped_area) 299 if (get_unmapped_area)
296 rv = get_unmapped_area(file, orig_addr, len, pgoff, flags); 300 rv = get_unmapped_area(file, orig_addr, len, pgoff, flags);
297 unuse_pde(pde); 301 unuse_pde(pde);
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 7366e9d63cee..390bdab01c3c 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -941,6 +941,8 @@ static void pte_to_pagemap_entry(pagemap_entry_t *pme, struct pagemapread *pm,
941 frame = pte_pfn(pte); 941 frame = pte_pfn(pte);
942 flags = PM_PRESENT; 942 flags = PM_PRESENT;
943 page = vm_normal_page(vma, addr, pte); 943 page = vm_normal_page(vma, addr, pte);
944 if (pte_soft_dirty(pte))
945 flags2 |= __PM_SOFT_DIRTY;
944 } else if (is_swap_pte(pte)) { 946 } else if (is_swap_pte(pte)) {
945 swp_entry_t entry; 947 swp_entry_t entry;
946 if (pte_swp_soft_dirty(pte)) 948 if (pte_swp_soft_dirty(pte))
@@ -960,7 +962,7 @@ static void pte_to_pagemap_entry(pagemap_entry_t *pme, struct pagemapread *pm,
960 962
961 if (page && !PageAnon(page)) 963 if (page && !PageAnon(page))
962 flags |= PM_FILE; 964 flags |= PM_FILE;
963 if ((vma->vm_flags & VM_SOFTDIRTY) || pte_soft_dirty(pte)) 965 if ((vma->vm_flags & VM_SOFTDIRTY))
964 flags2 |= __PM_SOFT_DIRTY; 966 flags2 |= __PM_SOFT_DIRTY;
965 967
966 *pme = make_pme(PM_PFRAME(frame) | PM_STATUS2(pm->v2, flags2) | flags); 968 *pme = make_pme(PM_PFRAME(frame) | PM_STATUS2(pm->v2, flags2) | flags);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 02e113bb8b7d..d9019821aa60 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -311,7 +311,6 @@ struct acpi_device {
311 unsigned int physical_node_count; 311 unsigned int physical_node_count;
312 struct list_head physical_node_list; 312 struct list_head physical_node_list;
313 struct mutex physical_node_lock; 313 struct mutex physical_node_lock;
314 struct list_head power_dependent;
315 void (*remove)(struct acpi_device *); 314 void (*remove)(struct acpi_device *);
316}; 315};
317 316
@@ -456,8 +455,6 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
456acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, 455acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
457 acpi_notify_handler handler); 456 acpi_notify_handler handler);
458int acpi_pm_device_sleep_state(struct device *, int *, int); 457int acpi_pm_device_sleep_state(struct device *, int *, int);
459void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev);
460void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev);
461#else 458#else
462static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 459static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
463 acpi_notify_handler handler, 460 acpi_notify_handler handler,
@@ -478,10 +475,6 @@ static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
478 return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ? 475 return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
479 m : ACPI_STATE_D0; 476 m : ACPI_STATE_D0;
480} 477}
481static inline void acpi_dev_pm_add_dependent(acpi_handle handle,
482 struct device *depdev) {}
483static inline void acpi_dev_pm_remove_dependent(acpi_handle handle,
484 struct device *depdev) {}
485#endif 478#endif
486 479
487#ifdef CONFIG_PM_RUNTIME 480#ifdef CONFIG_PM_RUNTIME
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index ecc82b37c4cc..b3e7a667e03c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -137,47 +137,24 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
137extern void mem_cgroup_replace_page_cache(struct page *oldpage, 137extern void mem_cgroup_replace_page_cache(struct page *oldpage,
138 struct page *newpage); 138 struct page *newpage);
139 139
140/** 140static inline void mem_cgroup_oom_enable(void)
141 * mem_cgroup_toggle_oom - toggle the memcg OOM killer for the current task
142 * @new: true to enable, false to disable
143 *
144 * Toggle whether a failed memcg charge should invoke the OOM killer
145 * or just return -ENOMEM. Returns the previous toggle state.
146 *
147 * NOTE: Any path that enables the OOM killer before charging must
148 * call mem_cgroup_oom_synchronize() afterward to finalize the
149 * OOM handling and clean up.
150 */
151static inline bool mem_cgroup_toggle_oom(bool new)
152{ 141{
153 bool old; 142 WARN_ON(current->memcg_oom.may_oom);
154 143 current->memcg_oom.may_oom = 1;
155 old = current->memcg_oom.may_oom;
156 current->memcg_oom.may_oom = new;
157
158 return old;
159} 144}
160 145
161static inline void mem_cgroup_enable_oom(void) 146static inline void mem_cgroup_oom_disable(void)
162{ 147{
163 bool old = mem_cgroup_toggle_oom(true); 148 WARN_ON(!current->memcg_oom.may_oom);
164 149 current->memcg_oom.may_oom = 0;
165 WARN_ON(old == true);
166}
167
168static inline void mem_cgroup_disable_oom(void)
169{
170 bool old = mem_cgroup_toggle_oom(false);
171
172 WARN_ON(old == false);
173} 150}
174 151
175static inline bool task_in_memcg_oom(struct task_struct *p) 152static inline bool task_in_memcg_oom(struct task_struct *p)
176{ 153{
177 return p->memcg_oom.in_memcg_oom; 154 return p->memcg_oom.memcg;
178} 155}
179 156
180bool mem_cgroup_oom_synchronize(void); 157bool mem_cgroup_oom_synchronize(bool wait);
181 158
182#ifdef CONFIG_MEMCG_SWAP 159#ifdef CONFIG_MEMCG_SWAP
183extern int do_swap_account; 160extern int do_swap_account;
@@ -402,16 +379,11 @@ static inline void mem_cgroup_end_update_page_stat(struct page *page,
402{ 379{
403} 380}
404 381
405static inline bool mem_cgroup_toggle_oom(bool new) 382static inline void mem_cgroup_oom_enable(void)
406{
407 return false;
408}
409
410static inline void mem_cgroup_enable_oom(void)
411{ 383{
412} 384}
413 385
414static inline void mem_cgroup_disable_oom(void) 386static inline void mem_cgroup_oom_disable(void)
415{ 387{
416} 388}
417 389
@@ -420,7 +392,7 @@ static inline bool task_in_memcg_oom(struct task_struct *p)
420 return false; 392 return false;
421} 393}
422 394
423static inline bool mem_cgroup_oom_synchronize(void) 395static inline bool mem_cgroup_oom_synchronize(bool wait)
424{ 396{
425 return false; 397 return false;
426} 398}
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 68029b30c3dc..5eb4e31af22b 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -181,7 +181,7 @@ enum {
181 MLX5_DEV_CAP_FLAG_TLP_HINTS = 1LL << 39, 181 MLX5_DEV_CAP_FLAG_TLP_HINTS = 1LL << 39,
182 MLX5_DEV_CAP_FLAG_SIG_HAND_OVER = 1LL << 40, 182 MLX5_DEV_CAP_FLAG_SIG_HAND_OVER = 1LL << 40,
183 MLX5_DEV_CAP_FLAG_DCT = 1LL << 41, 183 MLX5_DEV_CAP_FLAG_DCT = 1LL << 41,
184 MLX5_DEV_CAP_FLAG_CMDIF_CSUM = 1LL << 46, 184 MLX5_DEV_CAP_FLAG_CMDIF_CSUM = 3LL << 46,
185}; 185};
186 186
187enum { 187enum {
@@ -417,7 +417,7 @@ struct mlx5_init_seg {
417 struct health_buffer health; 417 struct health_buffer health;
418 __be32 rsvd2[884]; 418 __be32 rsvd2[884];
419 __be32 health_counter; 419 __be32 health_counter;
420 __be32 rsvd3[1023]; 420 __be32 rsvd3[1019];
421 __be64 ieee1588_clk; 421 __be64 ieee1588_clk;
422 __be32 ieee1588_clk_type; 422 __be32 ieee1588_clk_type;
423 __be32 clr_intx; 423 __be32 clr_intx;
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 8888381fc150..6b8c496572c8 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -82,7 +82,7 @@ enum {
82}; 82};
83 83
84enum { 84enum {
85 MLX5_MAX_EQ_NAME = 20 85 MLX5_MAX_EQ_NAME = 32
86}; 86};
87 87
88enum { 88enum {
@@ -747,8 +747,7 @@ static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
747 747
748enum { 748enum {
749 MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0, 749 MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
750 MLX5_PROF_MASK_CMDIF_CSUM = (u64)1 << 1, 750 MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
751 MLX5_PROF_MASK_MR_CACHE = (u64)1 << 2,
752}; 751};
753 752
754enum { 753enum {
@@ -758,7 +757,6 @@ enum {
758struct mlx5_profile { 757struct mlx5_profile {
759 u64 mask; 758 u64 mask;
760 u32 log_max_qp; 759 u32 log_max_qp;
761 int cmdif_csum;
762 struct { 760 struct {
763 int size; 761 int size;
764 int limit; 762 int limit;
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
deleted file mode 100644
index c84128255814..000000000000
--- a/include/linux/of_reserved_mem.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef __OF_RESERVED_MEM_H
2#define __OF_RESERVED_MEM_H
3
4#ifdef CONFIG_OF_RESERVED_MEM
5void of_reserved_mem_device_init(struct device *dev);
6void of_reserved_mem_device_release(struct device *dev);
7void early_init_dt_scan_reserved_mem(void);
8#else
9static inline void of_reserved_mem_device_init(struct device *dev) { }
10static inline void of_reserved_mem_device_release(struct device *dev) { }
11static inline void early_init_dt_scan_reserved_mem(void) { }
12#endif
13
14#endif /* __OF_RESERVED_MEM_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 6682da36b293..e27baeeda3f4 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1394,11 +1394,10 @@ struct task_struct {
1394 } memcg_batch; 1394 } memcg_batch;
1395 unsigned int memcg_kmem_skip_account; 1395 unsigned int memcg_kmem_skip_account;
1396 struct memcg_oom_info { 1396 struct memcg_oom_info {
1397 struct mem_cgroup *memcg;
1398 gfp_t gfp_mask;
1399 int order;
1397 unsigned int may_oom:1; 1400 unsigned int may_oom:1;
1398 unsigned int in_memcg_oom:1;
1399 unsigned int oom_locked:1;
1400 int wakeups;
1401 struct mem_cgroup *wait_on_memcg;
1402 } memcg_oom; 1401 } memcg_oom;
1403#endif 1402#endif
1404#ifdef CONFIG_UPROBES 1403#ifdef CONFIG_UPROBES
diff --git a/include/linux/spi/rspi.h b/include/linux/spi/rspi.h
index 900f0e328235..a25bd6f65e7f 100644
--- a/include/linux/spi/rspi.h
+++ b/include/linux/spi/rspi.h
@@ -26,6 +26,8 @@ struct rspi_plat_data {
26 unsigned int dma_rx_id; 26 unsigned int dma_rx_id;
27 27
28 unsigned dma_width_16bit:1; /* DMAC read/write width = 16-bit */ 28 unsigned dma_width_16bit:1; /* DMAC read/write width = 16-bit */
29
30 u16 num_chipselect;
29}; 31};
30 32
31#endif 33#endif
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 887116dbce2c..1619ed48e75d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -23,6 +23,7 @@
23#include <linux/mod_devicetable.h> 23#include <linux/mod_devicetable.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/kthread.h> 25#include <linux/kthread.h>
26#include <linux/completion.h>
26 27
27/* 28/*
28 * INTERFACES between SPI master-side drivers and SPI infrastructure. 29 * INTERFACES between SPI master-side drivers and SPI infrastructure.
@@ -150,8 +151,7 @@ static inline void *spi_get_drvdata(struct spi_device *spi)
150} 151}
151 152
152struct spi_message; 153struct spi_message;
153 154struct spi_transfer;
154
155 155
156/** 156/**
157 * struct spi_driver - Host side "protocol" driver 157 * struct spi_driver - Host side "protocol" driver
@@ -257,6 +257,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
257 * @queue_lock: spinlock to syncronise access to message queue 257 * @queue_lock: spinlock to syncronise access to message queue
258 * @queue: message queue 258 * @queue: message queue
259 * @cur_msg: the currently in-flight message 259 * @cur_msg: the currently in-flight message
260 * @cur_msg_prepared: spi_prepare_message was called for the currently
261 * in-flight message
262 * @xfer_completion: used by core tranfer_one_message()
260 * @busy: message pump is busy 263 * @busy: message pump is busy
261 * @running: message pump is running 264 * @running: message pump is running
262 * @rt: whether this queue is set to run as a realtime task 265 * @rt: whether this queue is set to run as a realtime task
@@ -274,6 +277,16 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
274 * @unprepare_transfer_hardware: there are currently no more messages on the 277 * @unprepare_transfer_hardware: there are currently no more messages on the
275 * queue so the subsystem notifies the driver that it may relax the 278 * queue so the subsystem notifies the driver that it may relax the
276 * hardware by issuing this call 279 * hardware by issuing this call
280 * @set_cs: assert or deassert chip select, true to assert. May be called
281 * from interrupt context.
282 * @prepare_message: set up the controller to transfer a single message,
283 * for example doing DMA mapping. Called from threaded
284 * context.
285 * @transfer_one: transfer a single spi_transfer. When the
286 * driver is finished with this transfer it must call
287 * spi_finalize_current_transfer() so the subsystem can issue
288 * the next transfer
289 * @unprepare_message: undo any work done by prepare_message().
277 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS 290 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
278 * number. Any individual value may be -ENOENT for CS lines that 291 * number. Any individual value may be -ENOENT for CS lines that
279 * are not GPIOs (driven by the SPI controller itself). 292 * are not GPIOs (driven by the SPI controller itself).
@@ -388,11 +401,25 @@ struct spi_master {
388 bool running; 401 bool running;
389 bool rt; 402 bool rt;
390 bool auto_runtime_pm; 403 bool auto_runtime_pm;
404 bool cur_msg_prepared;
405 struct completion xfer_completion;
391 406
392 int (*prepare_transfer_hardware)(struct spi_master *master); 407 int (*prepare_transfer_hardware)(struct spi_master *master);
393 int (*transfer_one_message)(struct spi_master *master, 408 int (*transfer_one_message)(struct spi_master *master,
394 struct spi_message *mesg); 409 struct spi_message *mesg);
395 int (*unprepare_transfer_hardware)(struct spi_master *master); 410 int (*unprepare_transfer_hardware)(struct spi_master *master);
411 int (*prepare_message)(struct spi_master *master,
412 struct spi_message *message);
413 int (*unprepare_message)(struct spi_master *master,
414 struct spi_message *message);
415
416 /*
417 * These hooks are for drivers that use a generic implementation
418 * of transfer_one_message() provied by the core.
419 */
420 void (*set_cs)(struct spi_device *spi, bool enable);
421 int (*transfer_one)(struct spi_master *master, struct spi_device *spi,
422 struct spi_transfer *transfer);
396 423
397 /* gpio chip select */ 424 /* gpio chip select */
398 int *cs_gpios; 425 int *cs_gpios;
@@ -428,12 +455,15 @@ extern int spi_master_resume(struct spi_master *master);
428/* Calls the driver make to interact with the message queue */ 455/* Calls the driver make to interact with the message queue */
429extern struct spi_message *spi_get_next_queued_message(struct spi_master *master); 456extern struct spi_message *spi_get_next_queued_message(struct spi_master *master);
430extern void spi_finalize_current_message(struct spi_master *master); 457extern void spi_finalize_current_message(struct spi_master *master);
458extern void spi_finalize_current_transfer(struct spi_master *master);
431 459
432/* the spi driver core manages memory for the spi_master classdev */ 460/* the spi driver core manages memory for the spi_master classdev */
433extern struct spi_master * 461extern struct spi_master *
434spi_alloc_master(struct device *host, unsigned size); 462spi_alloc_master(struct device *host, unsigned size);
435 463
436extern int spi_register_master(struct spi_master *master); 464extern int spi_register_master(struct spi_master *master);
465extern int devm_spi_register_master(struct device *dev,
466 struct spi_master *master);
437extern void spi_unregister_master(struct spi_master *master); 467extern void spi_unregister_master(struct spi_master *master);
438 468
439extern struct spi_master *spi_busnum_to_master(u16 busnum); 469extern struct spi_master *spi_busnum_to_master(u16 busnum);
diff --git a/include/linux/usb/usb_phy_gen_xceiv.h b/include/linux/usb/usb_phy_gen_xceiv.h
index f9a7e7bc925b..11d85b9c1b08 100644
--- a/include/linux/usb/usb_phy_gen_xceiv.h
+++ b/include/linux/usb/usb_phy_gen_xceiv.h
@@ -12,7 +12,7 @@ struct usb_phy_gen_xceiv_platform_data {
12 unsigned int needs_reset:1; 12 unsigned int needs_reset:1;
13}; 13};
14 14
15#if IS_ENABLED(CONFIG_NOP_USB_XCEIV) 15#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
16/* sometimes transceivers are accessed only through e.g. ULPI */ 16/* sometimes transceivers are accessed only through e.g. ULPI */
17extern void usb_nop_xceiv_register(void); 17extern void usb_nop_xceiv_register(void);
18extern void usb_nop_xceiv_unregister(void); 18extern void usb_nop_xceiv_unregister(void);
diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
index bf99cd01be20..630356866030 100644
--- a/include/linux/usb_usual.h
+++ b/include/linux/usb_usual.h
@@ -66,7 +66,9 @@
66 US_FLAG(INITIAL_READ10, 0x00100000) \ 66 US_FLAG(INITIAL_READ10, 0x00100000) \
67 /* Initial READ(10) (and others) must be retried */ \ 67 /* Initial READ(10) (and others) must be retried */ \
68 US_FLAG(WRITE_CACHE, 0x00200000) \ 68 US_FLAG(WRITE_CACHE, 0x00200000) \
69 /* Write Cache status is not available */ 69 /* Write Cache status is not available */ \
70 US_FLAG(NEEDS_CAP16, 0x00400000)
71 /* cannot handle READ_CAPACITY_10 */
70 72
71#define US_FLAG(name, value) US_FL_##name = value , 73#define US_FLAG(name, value) US_FL_##name = value ,
72enum { US_DO_ALL_FLAGS }; 74enum { US_DO_ALL_FLAGS };
diff --git a/include/trace/events/spi.h b/include/trace/events/spi.h
new file mode 100644
index 000000000000..7e02c983bbe2
--- /dev/null
+++ b/include/trace/events/spi.h
@@ -0,0 +1,156 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM spi
3
4#if !defined(_TRACE_SPI_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_SPI_H
6
7#include <linux/ktime.h>
8#include <linux/tracepoint.h>
9
10DECLARE_EVENT_CLASS(spi_master,
11
12 TP_PROTO(struct spi_master *master),
13
14 TP_ARGS(master),
15
16 TP_STRUCT__entry(
17 __field( int, bus_num )
18 ),
19
20 TP_fast_assign(
21 __entry->bus_num = master->bus_num;
22 ),
23
24 TP_printk("spi%d", (int)__entry->bus_num)
25
26);
27
28DEFINE_EVENT(spi_master, spi_master_idle,
29
30 TP_PROTO(struct spi_master *master),
31
32 TP_ARGS(master)
33
34);
35
36DEFINE_EVENT(spi_master, spi_master_busy,
37
38 TP_PROTO(struct spi_master *master),
39
40 TP_ARGS(master)
41
42);
43
44DECLARE_EVENT_CLASS(spi_message,
45
46 TP_PROTO(struct spi_message *msg),
47
48 TP_ARGS(msg),
49
50 TP_STRUCT__entry(
51 __field( int, bus_num )
52 __field( int, chip_select )
53 __field( struct spi_message *, msg )
54 ),
55
56 TP_fast_assign(
57 __entry->bus_num = msg->spi->master->bus_num;
58 __entry->chip_select = msg->spi->chip_select;
59 __entry->msg = msg;
60 ),
61
62 TP_printk("spi%d.%d %p", (int)__entry->bus_num,
63 (int)__entry->chip_select,
64 (struct spi_message *)__entry->msg)
65);
66
67DEFINE_EVENT(spi_message, spi_message_submit,
68
69 TP_PROTO(struct spi_message *msg),
70
71 TP_ARGS(msg)
72
73);
74
75DEFINE_EVENT(spi_message, spi_message_start,
76
77 TP_PROTO(struct spi_message *msg),
78
79 TP_ARGS(msg)
80
81);
82
83TRACE_EVENT(spi_message_done,
84
85 TP_PROTO(struct spi_message *msg),
86
87 TP_ARGS(msg),
88
89 TP_STRUCT__entry(
90 __field( int, bus_num )
91 __field( int, chip_select )
92 __field( struct spi_message *, msg )
93 __field( unsigned, frame )
94 __field( unsigned, actual )
95 ),
96
97 TP_fast_assign(
98 __entry->bus_num = msg->spi->master->bus_num;
99 __entry->chip_select = msg->spi->chip_select;
100 __entry->msg = msg;
101 __entry->frame = msg->frame_length;
102 __entry->actual = msg->actual_length;
103 ),
104
105 TP_printk("spi%d.%d %p len=%u/%u", (int)__entry->bus_num,
106 (int)__entry->chip_select,
107 (struct spi_message *)__entry->msg,
108 (unsigned)__entry->actual, (unsigned)__entry->frame)
109);
110
111DECLARE_EVENT_CLASS(spi_transfer,
112
113 TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
114
115 TP_ARGS(msg, xfer),
116
117 TP_STRUCT__entry(
118 __field( int, bus_num )
119 __field( int, chip_select )
120 __field( struct spi_transfer *, xfer )
121 __field( int, len )
122 ),
123
124 TP_fast_assign(
125 __entry->bus_num = msg->spi->master->bus_num;
126 __entry->chip_select = msg->spi->chip_select;
127 __entry->xfer = xfer;
128 __entry->len = xfer->len;
129 ),
130
131 TP_printk("spi%d.%d %p len=%d", (int)__entry->bus_num,
132 (int)__entry->chip_select,
133 (struct spi_message *)__entry->xfer,
134 (int)__entry->len)
135);
136
137DEFINE_EVENT(spi_transfer, spi_transfer_start,
138
139 TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
140
141 TP_ARGS(msg, xfer)
142
143);
144
145DEFINE_EVENT(spi_transfer, spi_transfer_stop,
146
147 TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
148
149 TP_ARGS(msg, xfer)
150
151);
152
153#endif /* _TRACE_POWER_H */
154
155/* This part must be outside protection */
156#include <trace/define_trace.h>
diff --git a/ipc/sem.c b/ipc/sem.c
index 8c4f59b0204a..db9d241af133 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1282,6 +1282,12 @@ static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum,
1282 1282
1283 sem_lock(sma, NULL, -1); 1283 sem_lock(sma, NULL, -1);
1284 1284
1285 if (sma->sem_perm.deleted) {
1286 sem_unlock(sma, -1);
1287 rcu_read_unlock();
1288 return -EIDRM;
1289 }
1290
1285 curr = &sma->sem_base[semnum]; 1291 curr = &sma->sem_base[semnum];
1286 1292
1287 ipc_assert_locked_object(&sma->sem_perm); 1293 ipc_assert_locked_object(&sma->sem_perm);
@@ -1336,12 +1342,14 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1336 int i; 1342 int i;
1337 1343
1338 sem_lock(sma, NULL, -1); 1344 sem_lock(sma, NULL, -1);
1345 if (sma->sem_perm.deleted) {
1346 err = -EIDRM;
1347 goto out_unlock;
1348 }
1339 if(nsems > SEMMSL_FAST) { 1349 if(nsems > SEMMSL_FAST) {
1340 if (!ipc_rcu_getref(sma)) { 1350 if (!ipc_rcu_getref(sma)) {
1341 sem_unlock(sma, -1);
1342 rcu_read_unlock();
1343 err = -EIDRM; 1351 err = -EIDRM;
1344 goto out_free; 1352 goto out_unlock;
1345 } 1353 }
1346 sem_unlock(sma, -1); 1354 sem_unlock(sma, -1);
1347 rcu_read_unlock(); 1355 rcu_read_unlock();
@@ -1354,10 +1362,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1354 rcu_read_lock(); 1362 rcu_read_lock();
1355 sem_lock_and_putref(sma); 1363 sem_lock_and_putref(sma);
1356 if (sma->sem_perm.deleted) { 1364 if (sma->sem_perm.deleted) {
1357 sem_unlock(sma, -1);
1358 rcu_read_unlock();
1359 err = -EIDRM; 1365 err = -EIDRM;
1360 goto out_free; 1366 goto out_unlock;
1361 } 1367 }
1362 } 1368 }
1363 for (i = 0; i < sma->sem_nsems; i++) 1369 for (i = 0; i < sma->sem_nsems; i++)
@@ -1375,8 +1381,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1375 struct sem_undo *un; 1381 struct sem_undo *un;
1376 1382
1377 if (!ipc_rcu_getref(sma)) { 1383 if (!ipc_rcu_getref(sma)) {
1378 rcu_read_unlock(); 1384 err = -EIDRM;
1379 return -EIDRM; 1385 goto out_rcu_wakeup;
1380 } 1386 }
1381 rcu_read_unlock(); 1387 rcu_read_unlock();
1382 1388
@@ -1404,10 +1410,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1404 rcu_read_lock(); 1410 rcu_read_lock();
1405 sem_lock_and_putref(sma); 1411 sem_lock_and_putref(sma);
1406 if (sma->sem_perm.deleted) { 1412 if (sma->sem_perm.deleted) {
1407 sem_unlock(sma, -1);
1408 rcu_read_unlock();
1409 err = -EIDRM; 1413 err = -EIDRM;
1410 goto out_free; 1414 goto out_unlock;
1411 } 1415 }
1412 1416
1413 for (i = 0; i < nsems; i++) 1417 for (i = 0; i < nsems; i++)
@@ -1431,6 +1435,10 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1431 goto out_rcu_wakeup; 1435 goto out_rcu_wakeup;
1432 1436
1433 sem_lock(sma, NULL, -1); 1437 sem_lock(sma, NULL, -1);
1438 if (sma->sem_perm.deleted) {
1439 err = -EIDRM;
1440 goto out_unlock;
1441 }
1434 curr = &sma->sem_base[semnum]; 1442 curr = &sma->sem_base[semnum];
1435 1443
1436 switch (cmd) { 1444 switch (cmd) {
@@ -1836,6 +1844,10 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
1836 if (error) 1844 if (error)
1837 goto out_rcu_wakeup; 1845 goto out_rcu_wakeup;
1838 1846
1847 error = -EIDRM;
1848 locknum = sem_lock(sma, sops, nsops);
1849 if (sma->sem_perm.deleted)
1850 goto out_unlock_free;
1839 /* 1851 /*
1840 * semid identifiers are not unique - find_alloc_undo may have 1852 * semid identifiers are not unique - find_alloc_undo may have
1841 * allocated an undo structure, it was invalidated by an RMID 1853 * allocated an undo structure, it was invalidated by an RMID
@@ -1843,8 +1855,6 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
1843 * This case can be detected checking un->semid. The existence of 1855 * This case can be detected checking un->semid. The existence of
1844 * "un" itself is guaranteed by rcu. 1856 * "un" itself is guaranteed by rcu.
1845 */ 1857 */
1846 error = -EIDRM;
1847 locknum = sem_lock(sma, sops, nsops);
1848 if (un && un->semid == -1) 1858 if (un && un->semid == -1)
1849 goto out_unlock_free; 1859 goto out_unlock_free;
1850 1860
@@ -2057,6 +2067,12 @@ void exit_sem(struct task_struct *tsk)
2057 } 2067 }
2058 2068
2059 sem_lock(sma, NULL, -1); 2069 sem_lock(sma, NULL, -1);
2070 /* exit_sem raced with IPC_RMID, nothing to do */
2071 if (sma->sem_perm.deleted) {
2072 sem_unlock(sma, -1);
2073 rcu_read_unlock();
2074 continue;
2075 }
2060 un = __lookup_undo(ulp, semid); 2076 un = __lookup_undo(ulp, semid);
2061 if (un == NULL) { 2077 if (un == NULL) {
2062 /* exit_sem raced with IPC_RMID+semget() that created 2078 /* exit_sem raced with IPC_RMID+semget() that created
diff --git a/ipc/util.c b/ipc/util.c
index fdb8ae740775..7684f41bce76 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -17,12 +17,27 @@
17 * Pavel Emelianov <xemul@openvz.org> 17 * Pavel Emelianov <xemul@openvz.org>
18 * 18 *
19 * General sysv ipc locking scheme: 19 * General sysv ipc locking scheme:
20 * when doing ipc id lookups, take the ids->rwsem 20 * rcu_read_lock()
21 * rcu_read_lock() 21 * obtain the ipc object (kern_ipc_perm) by looking up the id in an idr
22 * obtain the ipc object (kern_ipc_perm) 22 * tree.
23 * perform security, capabilities, auditing and permission checks, etc. 23 * - perform initial checks (capabilities, auditing and permission,
24 * acquire the ipc lock (kern_ipc_perm.lock) throught ipc_lock_object() 24 * etc).
25 * perform data updates (ie: SET, RMID, LOCK/UNLOCK commands) 25 * - perform read-only operations, such as STAT, INFO commands.
26 * acquire the ipc lock (kern_ipc_perm.lock) through
27 * ipc_lock_object()
28 * - perform data updates, such as SET, RMID commands and
29 * mechanism-specific operations (semop/semtimedop,
30 * msgsnd/msgrcv, shmat/shmdt).
31 * drop the ipc lock, through ipc_unlock_object().
32 * rcu_read_unlock()
33 *
34 * The ids->rwsem must be taken when:
35 * - creating, removing and iterating the existing entries in ipc
36 * identifier sets.
37 * - iterating through files under /proc/sysvipc/
38 *
39 * Note that sems have a special fast path that avoids kern_ipc_perm.lock -
40 * see sem_lock().
26 */ 41 */
27 42
28#include <linux/mm.h> 43#include <linux/mm.h>
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 7deeb6297a48..1a53d497a8c5 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -53,6 +53,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release)
53 ref->release = release; 53 ref->release = release;
54 return 0; 54 return 0;
55} 55}
56EXPORT_SYMBOL_GPL(percpu_ref_init);
56 57
57/** 58/**
58 * percpu_ref_cancel_init - cancel percpu_ref_init() 59 * percpu_ref_cancel_init - cancel percpu_ref_init()
@@ -84,6 +85,7 @@ void percpu_ref_cancel_init(struct percpu_ref *ref)
84 free_percpu(ref->pcpu_count); 85 free_percpu(ref->pcpu_count);
85 } 86 }
86} 87}
88EXPORT_SYMBOL_GPL(percpu_ref_cancel_init);
87 89
88static void percpu_ref_kill_rcu(struct rcu_head *rcu) 90static void percpu_ref_kill_rcu(struct rcu_head *rcu)
89{ 91{
@@ -156,3 +158,4 @@ void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
156 158
157 call_rcu_sched(&ref->rcu, percpu_ref_kill_rcu); 159 call_rcu_sched(&ref->rcu, percpu_ref_kill_rcu);
158} 160}
161EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm);
diff --git a/mm/filemap.c b/mm/filemap.c
index 1e6aec4a2d2e..ae4846ff4849 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1616,7 +1616,6 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1616 struct inode *inode = mapping->host; 1616 struct inode *inode = mapping->host;
1617 pgoff_t offset = vmf->pgoff; 1617 pgoff_t offset = vmf->pgoff;
1618 struct page *page; 1618 struct page *page;
1619 bool memcg_oom;
1620 pgoff_t size; 1619 pgoff_t size;
1621 int ret = 0; 1620 int ret = 0;
1622 1621
@@ -1625,11 +1624,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1625 return VM_FAULT_SIGBUS; 1624 return VM_FAULT_SIGBUS;
1626 1625
1627 /* 1626 /*
1628 * Do we have something in the page cache already? Either 1627 * Do we have something in the page cache already?
1629 * way, try readahead, but disable the memcg OOM killer for it
1630 * as readahead is optional and no errors are propagated up
1631 * the fault stack. The OOM killer is enabled while trying to
1632 * instantiate the faulting page individually below.
1633 */ 1628 */
1634 page = find_get_page(mapping, offset); 1629 page = find_get_page(mapping, offset);
1635 if (likely(page) && !(vmf->flags & FAULT_FLAG_TRIED)) { 1630 if (likely(page) && !(vmf->flags & FAULT_FLAG_TRIED)) {
@@ -1637,14 +1632,10 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1637 * We found the page, so try async readahead before 1632 * We found the page, so try async readahead before
1638 * waiting for the lock. 1633 * waiting for the lock.
1639 */ 1634 */
1640 memcg_oom = mem_cgroup_toggle_oom(false);
1641 do_async_mmap_readahead(vma, ra, file, page, offset); 1635 do_async_mmap_readahead(vma, ra, file, page, offset);
1642 mem_cgroup_toggle_oom(memcg_oom);
1643 } else if (!page) { 1636 } else if (!page) {
1644 /* No page in the page cache at all */ 1637 /* No page in the page cache at all */
1645 memcg_oom = mem_cgroup_toggle_oom(false);
1646 do_sync_mmap_readahead(vma, ra, file, offset); 1638 do_sync_mmap_readahead(vma, ra, file, offset);
1647 mem_cgroup_toggle_oom(memcg_oom);
1648 count_vm_event(PGMAJFAULT); 1639 count_vm_event(PGMAJFAULT);
1649 mem_cgroup_count_vm_event(vma->vm_mm, PGMAJFAULT); 1640 mem_cgroup_count_vm_event(vma->vm_mm, PGMAJFAULT);
1650 ret = VM_FAULT_MAJOR; 1641 ret = VM_FAULT_MAJOR;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 7489884682d8..610e3df2768a 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2697,6 +2697,7 @@ void __split_huge_page_pmd(struct vm_area_struct *vma, unsigned long address,
2697 2697
2698 mmun_start = haddr; 2698 mmun_start = haddr;
2699 mmun_end = haddr + HPAGE_PMD_SIZE; 2699 mmun_end = haddr + HPAGE_PMD_SIZE;
2700again:
2700 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end); 2701 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
2701 spin_lock(&mm->page_table_lock); 2702 spin_lock(&mm->page_table_lock);
2702 if (unlikely(!pmd_trans_huge(*pmd))) { 2703 if (unlikely(!pmd_trans_huge(*pmd))) {
@@ -2719,7 +2720,14 @@ void __split_huge_page_pmd(struct vm_area_struct *vma, unsigned long address,
2719 split_huge_page(page); 2720 split_huge_page(page);
2720 2721
2721 put_page(page); 2722 put_page(page);
2722 BUG_ON(pmd_trans_huge(*pmd)); 2723
2724 /*
2725 * We don't always have down_write of mmap_sem here: a racing
2726 * do_huge_pmd_wp_page() might have copied-on-write to another
2727 * huge page before our split_huge_page() got the anon_vma lock.
2728 */
2729 if (unlikely(pmd_trans_huge(*pmd)))
2730 goto again;
2723} 2731}
2724 2732
2725void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address, 2733void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address,
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b49579c7f2a5..0b7656e804d1 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -653,6 +653,7 @@ static void free_huge_page(struct page *page)
653 BUG_ON(page_count(page)); 653 BUG_ON(page_count(page));
654 BUG_ON(page_mapcount(page)); 654 BUG_ON(page_mapcount(page));
655 restore_reserve = PagePrivate(page); 655 restore_reserve = PagePrivate(page);
656 ClearPagePrivate(page);
656 657
657 spin_lock(&hugetlb_lock); 658 spin_lock(&hugetlb_lock);
658 hugetlb_cgroup_uncharge_page(hstate_index(h), 659 hugetlb_cgroup_uncharge_page(hstate_index(h),
@@ -695,8 +696,22 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
695 /* we rely on prep_new_huge_page to set the destructor */ 696 /* we rely on prep_new_huge_page to set the destructor */
696 set_compound_order(page, order); 697 set_compound_order(page, order);
697 __SetPageHead(page); 698 __SetPageHead(page);
699 __ClearPageReserved(page);
698 for (i = 1; i < nr_pages; i++, p = mem_map_next(p, page, i)) { 700 for (i = 1; i < nr_pages; i++, p = mem_map_next(p, page, i)) {
699 __SetPageTail(p); 701 __SetPageTail(p);
702 /*
703 * For gigantic hugepages allocated through bootmem at
704 * boot, it's safer to be consistent with the not-gigantic
705 * hugepages and clear the PG_reserved bit from all tail pages
706 * too. Otherwse drivers using get_user_pages() to access tail
707 * pages may get the reference counting wrong if they see
708 * PG_reserved set on a tail page (despite the head page not
709 * having PG_reserved set). Enforcing this consistency between
710 * head and tail pages allows drivers to optimize away a check
711 * on the head page when they need know if put_page() is needed
712 * after get_user_pages().
713 */
714 __ClearPageReserved(p);
700 set_page_count(p, 0); 715 set_page_count(p, 0);
701 p->first_page = page; 716 p->first_page = page;
702 } 717 }
@@ -1329,9 +1344,9 @@ static void __init gather_bootmem_prealloc(void)
1329#else 1344#else
1330 page = virt_to_page(m); 1345 page = virt_to_page(m);
1331#endif 1346#endif
1332 __ClearPageReserved(page);
1333 WARN_ON(page_count(page) != 1); 1347 WARN_ON(page_count(page) != 1);
1334 prep_compound_huge_page(page, h->order); 1348 prep_compound_huge_page(page, h->order);
1349 WARN_ON(PageReserved(page));
1335 prep_new_huge_page(h, page, page_to_nid(page)); 1350 prep_new_huge_page(h, page, page_to_nid(page));
1336 /* 1351 /*
1337 * If we had gigantic hugepages allocated at boot time, we need 1352 * If we had gigantic hugepages allocated at boot time, we need
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1c52ddbc839b..34d3ca9572d6 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -866,6 +866,7 @@ static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
866 unsigned long val = 0; 866 unsigned long val = 0;
867 int cpu; 867 int cpu;
868 868
869 get_online_cpus();
869 for_each_online_cpu(cpu) 870 for_each_online_cpu(cpu)
870 val += per_cpu(memcg->stat->events[idx], cpu); 871 val += per_cpu(memcg->stat->events[idx], cpu);
871#ifdef CONFIG_HOTPLUG_CPU 872#ifdef CONFIG_HOTPLUG_CPU
@@ -873,6 +874,7 @@ static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
873 val += memcg->nocpu_base.events[idx]; 874 val += memcg->nocpu_base.events[idx];
874 spin_unlock(&memcg->pcp_counter_lock); 875 spin_unlock(&memcg->pcp_counter_lock);
875#endif 876#endif
877 put_online_cpus();
876 return val; 878 return val;
877} 879}
878 880
@@ -2159,110 +2161,59 @@ static void memcg_oom_recover(struct mem_cgroup *memcg)
2159 memcg_wakeup_oom(memcg); 2161 memcg_wakeup_oom(memcg);
2160} 2162}
2161 2163
2162/*
2163 * try to call OOM killer
2164 */
2165static void mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int order) 2164static void mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int order)
2166{ 2165{
2167 bool locked;
2168 int wakeups;
2169
2170 if (!current->memcg_oom.may_oom) 2166 if (!current->memcg_oom.may_oom)
2171 return; 2167 return;
2172
2173 current->memcg_oom.in_memcg_oom = 1;
2174
2175 /* 2168 /*
2176 * As with any blocking lock, a contender needs to start 2169 * We are in the middle of the charge context here, so we
2177 * listening for wakeups before attempting the trylock, 2170 * don't want to block when potentially sitting on a callstack
2178 * otherwise it can miss the wakeup from the unlock and sleep 2171 * that holds all kinds of filesystem and mm locks.
2179 * indefinitely. This is just open-coded because our locking 2172 *
2180 * is so particular to memcg hierarchies. 2173 * Also, the caller may handle a failed allocation gracefully
2174 * (like optional page cache readahead) and so an OOM killer
2175 * invocation might not even be necessary.
2176 *
2177 * That's why we don't do anything here except remember the
2178 * OOM context and then deal with it at the end of the page
2179 * fault when the stack is unwound, the locks are released,
2180 * and when we know whether the fault was overall successful.
2181 */ 2181 */
2182 wakeups = atomic_read(&memcg->oom_wakeups); 2182 css_get(&memcg->css);
2183 mem_cgroup_mark_under_oom(memcg); 2183 current->memcg_oom.memcg = memcg;
2184 2184 current->memcg_oom.gfp_mask = mask;
2185 locked = mem_cgroup_oom_trylock(memcg); 2185 current->memcg_oom.order = order;
2186
2187 if (locked)
2188 mem_cgroup_oom_notify(memcg);
2189
2190 if (locked && !memcg->oom_kill_disable) {
2191 mem_cgroup_unmark_under_oom(memcg);
2192 mem_cgroup_out_of_memory(memcg, mask, order);
2193 mem_cgroup_oom_unlock(memcg);
2194 /*
2195 * There is no guarantee that an OOM-lock contender
2196 * sees the wakeups triggered by the OOM kill
2197 * uncharges. Wake any sleepers explicitely.
2198 */
2199 memcg_oom_recover(memcg);
2200 } else {
2201 /*
2202 * A system call can just return -ENOMEM, but if this
2203 * is a page fault and somebody else is handling the
2204 * OOM already, we need to sleep on the OOM waitqueue
2205 * for this memcg until the situation is resolved.
2206 * Which can take some time because it might be
2207 * handled by a userspace task.
2208 *
2209 * However, this is the charge context, which means
2210 * that we may sit on a large call stack and hold
2211 * various filesystem locks, the mmap_sem etc. and we
2212 * don't want the OOM handler to deadlock on them
2213 * while we sit here and wait. Store the current OOM
2214 * context in the task_struct, then return -ENOMEM.
2215 * At the end of the page fault handler, with the
2216 * stack unwound, pagefault_out_of_memory() will check
2217 * back with us by calling
2218 * mem_cgroup_oom_synchronize(), possibly putting the
2219 * task to sleep.
2220 */
2221 current->memcg_oom.oom_locked = locked;
2222 current->memcg_oom.wakeups = wakeups;
2223 css_get(&memcg->css);
2224 current->memcg_oom.wait_on_memcg = memcg;
2225 }
2226} 2186}
2227 2187
2228/** 2188/**
2229 * mem_cgroup_oom_synchronize - complete memcg OOM handling 2189 * mem_cgroup_oom_synchronize - complete memcg OOM handling
2190 * @handle: actually kill/wait or just clean up the OOM state
2230 * 2191 *
2231 * This has to be called at the end of a page fault if the the memcg 2192 * This has to be called at the end of a page fault if the memcg OOM
2232 * OOM handler was enabled and the fault is returning %VM_FAULT_OOM. 2193 * handler was enabled.
2233 * 2194 *
2234 * Memcg supports userspace OOM handling, so failed allocations must 2195 * Memcg supports userspace OOM handling where failed allocations must
2235 * sleep on a waitqueue until the userspace task resolves the 2196 * sleep on a waitqueue until the userspace task resolves the
2236 * situation. Sleeping directly in the charge context with all kinds 2197 * situation. Sleeping directly in the charge context with all kinds
2237 * of locks held is not a good idea, instead we remember an OOM state 2198 * of locks held is not a good idea, instead we remember an OOM state
2238 * in the task and mem_cgroup_oom_synchronize() has to be called at 2199 * in the task and mem_cgroup_oom_synchronize() has to be called at
2239 * the end of the page fault to put the task to sleep and clean up the 2200 * the end of the page fault to complete the OOM handling.
2240 * OOM state.
2241 * 2201 *
2242 * Returns %true if an ongoing memcg OOM situation was detected and 2202 * Returns %true if an ongoing memcg OOM situation was detected and
2243 * finalized, %false otherwise. 2203 * completed, %false otherwise.
2244 */ 2204 */
2245bool mem_cgroup_oom_synchronize(void) 2205bool mem_cgroup_oom_synchronize(bool handle)
2246{ 2206{
2207 struct mem_cgroup *memcg = current->memcg_oom.memcg;
2247 struct oom_wait_info owait; 2208 struct oom_wait_info owait;
2248 struct mem_cgroup *memcg; 2209 bool locked;
2249 2210
2250 /* OOM is global, do not handle */ 2211 /* OOM is global, do not handle */
2251 if (!current->memcg_oom.in_memcg_oom)
2252 return false;
2253
2254 /*
2255 * We invoked the OOM killer but there is a chance that a kill
2256 * did not free up any charges. Everybody else might already
2257 * be sleeping, so restart the fault and keep the rampage
2258 * going until some charges are released.
2259 */
2260 memcg = current->memcg_oom.wait_on_memcg;
2261 if (!memcg) 2212 if (!memcg)
2262 goto out; 2213 return false;
2263 2214
2264 if (test_thread_flag(TIF_MEMDIE) || fatal_signal_pending(current)) 2215 if (!handle)
2265 goto out_memcg; 2216 goto cleanup;
2266 2217
2267 owait.memcg = memcg; 2218 owait.memcg = memcg;
2268 owait.wait.flags = 0; 2219 owait.wait.flags = 0;
@@ -2271,13 +2222,25 @@ bool mem_cgroup_oom_synchronize(void)
2271 INIT_LIST_HEAD(&owait.wait.task_list); 2222 INIT_LIST_HEAD(&owait.wait.task_list);
2272 2223
2273 prepare_to_wait(&memcg_oom_waitq, &owait.wait, TASK_KILLABLE); 2224 prepare_to_wait(&memcg_oom_waitq, &owait.wait, TASK_KILLABLE);
2274 /* Only sleep if we didn't miss any wakeups since OOM */ 2225 mem_cgroup_mark_under_oom(memcg);
2275 if (atomic_read(&memcg->oom_wakeups) == current->memcg_oom.wakeups) 2226
2227 locked = mem_cgroup_oom_trylock(memcg);
2228
2229 if (locked)
2230 mem_cgroup_oom_notify(memcg);
2231
2232 if (locked && !memcg->oom_kill_disable) {
2233 mem_cgroup_unmark_under_oom(memcg);
2234 finish_wait(&memcg_oom_waitq, &owait.wait);
2235 mem_cgroup_out_of_memory(memcg, current->memcg_oom.gfp_mask,
2236 current->memcg_oom.order);
2237 } else {
2276 schedule(); 2238 schedule();
2277 finish_wait(&memcg_oom_waitq, &owait.wait); 2239 mem_cgroup_unmark_under_oom(memcg);
2278out_memcg: 2240 finish_wait(&memcg_oom_waitq, &owait.wait);
2279 mem_cgroup_unmark_under_oom(memcg); 2241 }
2280 if (current->memcg_oom.oom_locked) { 2242
2243 if (locked) {
2281 mem_cgroup_oom_unlock(memcg); 2244 mem_cgroup_oom_unlock(memcg);
2282 /* 2245 /*
2283 * There is no guarantee that an OOM-lock contender 2246 * There is no guarantee that an OOM-lock contender
@@ -2286,10 +2249,9 @@ out_memcg:
2286 */ 2249 */
2287 memcg_oom_recover(memcg); 2250 memcg_oom_recover(memcg);
2288 } 2251 }
2252cleanup:
2253 current->memcg_oom.memcg = NULL;
2289 css_put(&memcg->css); 2254 css_put(&memcg->css);
2290 current->memcg_oom.wait_on_memcg = NULL;
2291out:
2292 current->memcg_oom.in_memcg_oom = 0;
2293 return true; 2255 return true;
2294} 2256}
2295 2257
@@ -2703,6 +2665,9 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
2703 || fatal_signal_pending(current))) 2665 || fatal_signal_pending(current)))
2704 goto bypass; 2666 goto bypass;
2705 2667
2668 if (unlikely(task_in_memcg_oom(current)))
2669 goto bypass;
2670
2706 /* 2671 /*
2707 * We always charge the cgroup the mm_struct belongs to. 2672 * We always charge the cgroup the mm_struct belongs to.
2708 * The mm_struct's mem_cgroup changes on task migration if the 2673 * The mm_struct's mem_cgroup changes on task migration if the
@@ -2801,6 +2766,8 @@ done:
2801 return 0; 2766 return 0;
2802nomem: 2767nomem:
2803 *ptr = NULL; 2768 *ptr = NULL;
2769 if (gfp_mask & __GFP_NOFAIL)
2770 return 0;
2804 return -ENOMEM; 2771 return -ENOMEM;
2805bypass: 2772bypass:
2806 *ptr = root_mem_cgroup; 2773 *ptr = root_mem_cgroup;
diff --git a/mm/memory.c b/mm/memory.c
index ca0003947115..1311f26497e6 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -837,6 +837,8 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
837 */ 837 */
838 make_migration_entry_read(&entry); 838 make_migration_entry_read(&entry);
839 pte = swp_entry_to_pte(entry); 839 pte = swp_entry_to_pte(entry);
840 if (pte_swp_soft_dirty(*src_pte))
841 pte = pte_swp_mksoft_dirty(pte);
840 set_pte_at(src_mm, addr, src_pte, pte); 842 set_pte_at(src_mm, addr, src_pte, pte);
841 } 843 }
842 } 844 }
@@ -3863,15 +3865,21 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
3863 * space. Kernel faults are handled more gracefully. 3865 * space. Kernel faults are handled more gracefully.
3864 */ 3866 */
3865 if (flags & FAULT_FLAG_USER) 3867 if (flags & FAULT_FLAG_USER)
3866 mem_cgroup_enable_oom(); 3868 mem_cgroup_oom_enable();
3867 3869
3868 ret = __handle_mm_fault(mm, vma, address, flags); 3870 ret = __handle_mm_fault(mm, vma, address, flags);
3869 3871
3870 if (flags & FAULT_FLAG_USER) 3872 if (flags & FAULT_FLAG_USER) {
3871 mem_cgroup_disable_oom(); 3873 mem_cgroup_oom_disable();
3872 3874 /*
3873 if (WARN_ON(task_in_memcg_oom(current) && !(ret & VM_FAULT_OOM))) 3875 * The task may have entered a memcg OOM situation but
3874 mem_cgroup_oom_synchronize(); 3876 * if the allocation error was handled gracefully (no
3877 * VM_FAULT_OOM), there is no need to kill anything.
3878 * Just clean up the OOM state peacefully.
3879 */
3880 if (task_in_memcg_oom(current) && !(ret & VM_FAULT_OOM))
3881 mem_cgroup_oom_synchronize(false);
3882 }
3875 3883
3876 return ret; 3884 return ret;
3877} 3885}
diff --git a/mm/migrate.c b/mm/migrate.c
index a26bccd44ccb..7a7325ee1d08 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -161,6 +161,8 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
161 161
162 get_page(new); 162 get_page(new);
163 pte = pte_mkold(mk_pte(new, vma->vm_page_prot)); 163 pte = pte_mkold(mk_pte(new, vma->vm_page_prot));
164 if (pte_swp_soft_dirty(*ptep))
165 pte = pte_mksoft_dirty(pte);
164 if (is_write_migration_entry(entry)) 166 if (is_write_migration_entry(entry))
165 pte = pte_mkwrite(pte); 167 pte = pte_mkwrite(pte);
166#ifdef CONFIG_HUGETLB_PAGE 168#ifdef CONFIG_HUGETLB_PAGE
diff --git a/mm/mprotect.c b/mm/mprotect.c
index 94722a4d6b43..a3af058f68e4 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -94,13 +94,16 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
94 swp_entry_t entry = pte_to_swp_entry(oldpte); 94 swp_entry_t entry = pte_to_swp_entry(oldpte);
95 95
96 if (is_write_migration_entry(entry)) { 96 if (is_write_migration_entry(entry)) {
97 pte_t newpte;
97 /* 98 /*
98 * A protection check is difficult so 99 * A protection check is difficult so
99 * just be safe and disable write 100 * just be safe and disable write
100 */ 101 */
101 make_migration_entry_read(&entry); 102 make_migration_entry_read(&entry);
102 set_pte_at(mm, addr, pte, 103 newpte = swp_entry_to_pte(entry);
103 swp_entry_to_pte(entry)); 104 if (pte_swp_soft_dirty(oldpte))
105 newpte = pte_swp_mksoft_dirty(newpte);
106 set_pte_at(mm, addr, pte, newpte);
104 } 107 }
105 pages++; 108 pages++;
106 } 109 }
diff --git a/mm/mremap.c b/mm/mremap.c
index 91b13d6a16d4..0843feb66f3d 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -25,7 +25,6 @@
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <asm/cacheflush.h> 26#include <asm/cacheflush.h>
27#include <asm/tlbflush.h> 27#include <asm/tlbflush.h>
28#include <asm/pgalloc.h>
29 28
30#include "internal.h" 29#include "internal.h"
31 30
@@ -63,10 +62,8 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
63 return NULL; 62 return NULL;
64 63
65 pmd = pmd_alloc(mm, pud, addr); 64 pmd = pmd_alloc(mm, pud, addr);
66 if (!pmd) { 65 if (!pmd)
67 pud_free(mm, pud);
68 return NULL; 66 return NULL;
69 }
70 67
71 VM_BUG_ON(pmd_trans_huge(*pmd)); 68 VM_BUG_ON(pmd_trans_huge(*pmd));
72 69
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 314e9d274381..6738c47f1f72 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -680,7 +680,7 @@ void pagefault_out_of_memory(void)
680{ 680{
681 struct zonelist *zonelist; 681 struct zonelist *zonelist;
682 682
683 if (mem_cgroup_oom_synchronize()) 683 if (mem_cgroup_oom_synchronize(true))
684 return; 684 return;
685 685
686 zonelist = node_zonelist(first_online_node, GFP_KERNEL); 686 zonelist = node_zonelist(first_online_node, GFP_KERNEL);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index f5236f804aa6..63807583d8e8 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1210,11 +1210,11 @@ static unsigned long dirty_poll_interval(unsigned long dirty,
1210 return 1; 1210 return 1;
1211} 1211}
1212 1212
1213static long bdi_max_pause(struct backing_dev_info *bdi, 1213static unsigned long bdi_max_pause(struct backing_dev_info *bdi,
1214 unsigned long bdi_dirty) 1214 unsigned long bdi_dirty)
1215{ 1215{
1216 long bw = bdi->avg_write_bandwidth; 1216 unsigned long bw = bdi->avg_write_bandwidth;
1217 long t; 1217 unsigned long t;
1218 1218
1219 /* 1219 /*
1220 * Limit pause time for small memory systems. If sleeping for too long 1220 * Limit pause time for small memory systems. If sleeping for too long
@@ -1226,7 +1226,7 @@ static long bdi_max_pause(struct backing_dev_info *bdi,
1226 t = bdi_dirty / (1 + bw / roundup_pow_of_two(1 + HZ / 8)); 1226 t = bdi_dirty / (1 + bw / roundup_pow_of_two(1 + HZ / 8));
1227 t++; 1227 t++;
1228 1228
1229 return min_t(long, t, MAX_PAUSE); 1229 return min_t(unsigned long, t, MAX_PAUSE);
1230} 1230}
1231 1231
1232static long bdi_min_pause(struct backing_dev_info *bdi, 1232static long bdi_min_pause(struct backing_dev_info *bdi,
diff --git a/mm/slab_common.c b/mm/slab_common.c
index a3443278ce3a..e2e98af703ea 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -56,6 +56,7 @@ static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
56 continue; 56 continue;
57 } 57 }
58 58
59#if !defined(CONFIG_SLUB) || !defined(CONFIG_SLUB_DEBUG_ON)
59 /* 60 /*
60 * For simplicity, we won't check this in the list of memcg 61 * For simplicity, we won't check this in the list of memcg
61 * caches. We have control over memcg naming, and if there 62 * caches. We have control over memcg naming, and if there
@@ -69,6 +70,7 @@ static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
69 s = NULL; 70 s = NULL;
70 return -EINVAL; 71 return -EINVAL;
71 } 72 }
73#endif
72 } 74 }
73 75
74 WARN_ON(strchr(name, ' ')); /* It confuses parsers */ 76 WARN_ON(strchr(name, ' ')); /* It confuses parsers */
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 3963fc24fcc1..de7c904e52e5 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1824,6 +1824,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1824 struct filename *pathname; 1824 struct filename *pathname;
1825 int i, type, prev; 1825 int i, type, prev;
1826 int err; 1826 int err;
1827 unsigned int old_block_size;
1827 1828
1828 if (!capable(CAP_SYS_ADMIN)) 1829 if (!capable(CAP_SYS_ADMIN))
1829 return -EPERM; 1830 return -EPERM;
@@ -1914,6 +1915,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1914 } 1915 }
1915 1916
1916 swap_file = p->swap_file; 1917 swap_file = p->swap_file;
1918 old_block_size = p->old_block_size;
1917 p->swap_file = NULL; 1919 p->swap_file = NULL;
1918 p->max = 0; 1920 p->max = 0;
1919 swap_map = p->swap_map; 1921 swap_map = p->swap_map;
@@ -1938,7 +1940,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1938 inode = mapping->host; 1940 inode = mapping->host;
1939 if (S_ISBLK(inode->i_mode)) { 1941 if (S_ISBLK(inode->i_mode)) {
1940 struct block_device *bdev = I_BDEV(inode); 1942 struct block_device *bdev = I_BDEV(inode);
1941 set_blocksize(bdev, p->old_block_size); 1943 set_blocksize(bdev, old_block_size);
1942 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); 1944 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
1943 } else { 1945 } else {
1944 mutex_lock(&inode->i_mutex); 1946 mutex_lock(&inode->i_mutex);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 53f2f82f83ae..eea668d9cff6 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -211,6 +211,7 @@ void unregister_shrinker(struct shrinker *shrinker)
211 down_write(&shrinker_rwsem); 211 down_write(&shrinker_rwsem);
212 list_del(&shrinker->list); 212 list_del(&shrinker->list);
213 up_write(&shrinker_rwsem); 213 up_write(&shrinker_rwsem);
214 kfree(shrinker->nr_deferred);
214} 215}
215EXPORT_SYMBOL(unregister_shrinker); 216EXPORT_SYMBOL(unregister_shrinker);
216 217
diff --git a/mm/zswap.c b/mm/zswap.c
index 841e35f1db22..d93510c6aa2d 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -804,6 +804,10 @@ static void zswap_frontswap_invalidate_area(unsigned type)
804 } 804 }
805 tree->rbroot = RB_ROOT; 805 tree->rbroot = RB_ROOT;
806 spin_unlock(&tree->lock); 806 spin_unlock(&tree->lock);
807
808 zbud_destroy_pool(tree->pool);
809 kfree(tree);
810 zswap_trees[type] = NULL;
807} 811}
808 812
809static struct zbud_ops zswap_zbud_ops = { 813static struct zbud_ops zswap_zbud_ops = {
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 95c2b2689a03..7db9954f1af2 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -580,15 +580,13 @@ static struct aa_namespace *__next_namespace(struct aa_namespace *root,
580 580
581 /* check if the next ns is a sibling, parent, gp, .. */ 581 /* check if the next ns is a sibling, parent, gp, .. */
582 parent = ns->parent; 582 parent = ns->parent;
583 while (parent) { 583 while (ns != root) {
584 mutex_unlock(&ns->lock); 584 mutex_unlock(&ns->lock);
585 next = list_entry_next(ns, base.list); 585 next = list_entry_next(ns, base.list);
586 if (!list_entry_is_head(next, &parent->sub_ns, base.list)) { 586 if (!list_entry_is_head(next, &parent->sub_ns, base.list)) {
587 mutex_lock(&next->lock); 587 mutex_lock(&next->lock);
588 return next; 588 return next;
589 } 589 }
590 if (parent == root)
591 return NULL;
592 ns = parent; 590 ns = parent;
593 parent = parent->parent; 591 parent = parent->parent;
594 } 592 }
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 345bec07a27d..705c2879d3a9 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -610,6 +610,7 @@ void aa_free_profile(struct aa_profile *profile)
610 aa_put_dfa(profile->policy.dfa); 610 aa_put_dfa(profile->policy.dfa);
611 aa_put_replacedby(profile->replacedby); 611 aa_put_replacedby(profile->replacedby);
612 612
613 kzfree(profile->hash);
613 kzfree(profile); 614 kzfree(profile);
614} 615}
615 616
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index ac41e9cdc976..26ad4f0aade3 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -3531,7 +3531,7 @@ static int create_capture_mixers(struct hda_codec *codec)
3531 if (!multi) 3531 if (!multi)
3532 err = create_single_cap_vol_ctl(codec, n, vol, sw, 3532 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3533 inv_dmic); 3533 inv_dmic);
3534 else if (!multi_cap_vol) 3534 else if (!multi_cap_vol && !inv_dmic)
3535 err = create_bind_cap_vol_ctl(codec, n, vol, sw); 3535 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3536 else 3536 else
3537 err = create_multi_cap_vol_ctl(codec); 3537 err = create_multi_cap_vol_ctl(codec);
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 4f255dfee450..f59a321a6d6a 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -4845,6 +4845,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4845 if ((err = hdsp_get_iobox_version(hdsp)) < 0) 4845 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4846 return err; 4846 return err;
4847 } 4847 }
4848 memset(&hdsp_version, 0, sizeof(hdsp_version));
4848 hdsp_version.io_type = hdsp->io_type; 4849 hdsp_version.io_type = hdsp->io_type;
4849 hdsp_version.firmware_rev = hdsp->firmware_rev; 4850 hdsp_version.firmware_rev = hdsp->firmware_rev;
4850 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) 4851 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index d0323a693ba2..999550bbad40 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -262,7 +262,9 @@ static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,
262 } 262 }
263 263
264 area->vm_ops = &usb_stream_hwdep_vm_ops; 264 area->vm_ops = &usb_stream_hwdep_vm_ops;
265 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 265 area->vm_flags |= VM_DONTDUMP;
266 if (!read)
267 area->vm_flags |= VM_DONTEXPAND;
266 area->vm_private_data = us122l; 268 area->vm_private_data = us122l;
267 atomic_inc(&us122l->mmap_count); 269 atomic_inc(&us122l->mmap_count);
268out: 270out:
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 4fa655d68a81..41bd85559d4b 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -151,7 +151,7 @@ static int check_timer_create(int which)
151 fflush(stdout); 151 fflush(stdout);
152 152
153 done = 0; 153 done = 0;
154 timer_create(which, NULL, &id); 154 err = timer_create(which, NULL, &id);
155 if (err < 0) { 155 if (err < 0) {
156 perror("Can't create timer\n"); 156 perror("Can't create timer\n");
157 return -1; 157 return -1;